Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deimplementing complications in libpng18 #659

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pnglibconf.c: scripts/pnglibconf/pnglibconf.dfa scripts/pnglibconf/options.awk p
mv $*.tf5 $@

# Symbol checks (.def and .out files should match)
scripts/pnglibconf/symbols.chk: scripts/pnglibconf/checksym.awk scripts/pnglibconf/symbols.def \
scripts/pnglibconf/symbols.chk: scripts/pnglibconf/checksym.awk scripts/symbols.def \
scripts/pnglibconf/symbols.out

.out.chk:
Expand Down
10 changes: 5 additions & 5 deletions contrib/examples/pngpixel.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ int main(int argc, const char **argv)
compression_method, filter_method;
png_bytep row_tmp;

/* Now associate the recently opened (FILE*) with the default
* libpng initialization functions. Sometimes libpng is
* compiled without stdio support (it can be difficult to do
* in some environments); in that case you will have to write
* your own read callback to read data from the (FILE*).
/* Now associate the recently opened FILE object with the
* default libpng initialization functions. Sometimes libpng
* is compiled without stdio support (it can be difficult to
* do in some environments); in that case you will have to
* write your own read callback to read data from the stream.
*/
png_init_io(png_ptr, f);

Expand Down
4 changes: 2 additions & 2 deletions contrib/libtests/makepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ generate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,
}


static void PNGCBAPI
static void
makepng_warning(png_structp png_ptr, png_const_charp message)
{
const char **ep = png_get_error_ptr(png_ptr);
Expand All @@ -760,7 +760,7 @@ makepng_warning(png_structp png_ptr, png_const_charp message)
fprintf(stderr, "%s: warning: %s\n", name, message);
}

static void PNGCBAPI
static void
makepng_error(png_structp png_ptr, png_const_charp message)
{
makepng_warning(png_ptr, message);
Expand Down
8 changes: 4 additions & 4 deletions contrib/libtests/pngimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,13 @@ display_log(struct display *dp, error_level level, const char *fmt, ...)
}

/* error handler callbacks for libpng */
static void PNGCBAPI
static void
display_warning(png_structp pp, png_const_charp warning)
{
display_log(get_dp(pp), LIBPNG_WARNING, "%s", warning);
}

static void PNGCBAPI
static void
display_error(png_structp pp, png_const_charp error)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -858,7 +858,7 @@ buffer_read(struct display *dp, struct buffer *bp, png_bytep data,
bp->read_count = read_count;
}

static void PNGCBAPI
static void
read_function(png_structp pp, png_bytep data, size_t size)
{
buffer_read(get_dp(pp), get_buffer(pp), data, size);
Expand Down Expand Up @@ -1325,7 +1325,7 @@ buffer_write(struct display *dp, struct buffer *buffer, png_bytep data,
buffer->end_count = end_count;
}

static void PNGCBAPI
static void
write_function(png_structp pp, png_bytep data, size_t size)
{
buffer_write(get_dp(pp), get_buffer(pp), data, size);
Expand Down
3 changes: 2 additions & 1 deletion contrib/libtests/pngstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,8 @@ newimage(Image *image)
memset(image, 0, sizeof *image);
}

/* Reset the image to be read again - only needs to rewind the FILE* at present.
/* Reset the image to be read again - only needs to rewind the FILE object at
* present.
*/
static void
resetimage(Image *image)
Expand Down
11 changes: 6 additions & 5 deletions contrib/libtests/pngunknown.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ clean_display(display *d)
}
}

PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
static PNG_NORETURN void
display_exit(display *d)
{
++(d->error_count);

Expand All @@ -480,16 +481,16 @@ display_rc(const display *d, int strict)
}

/* libpng error and warning callbacks */
PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
static PNG_NORETURN)
static PNG_NORETURN void
error(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);

fprintf(stderr, "%s(%s): libpng error: %s\n", d->file, d->test, message);
display_exit(d);
}

static void PNGCBAPI
static void
warning(png_structp png_ptr, const char *message)
{
display *d = (display*)png_get_error_ptr(png_ptr);
Expand Down Expand Up @@ -531,7 +532,7 @@ get_valid(display *d, png_infop info_ptr)
}

#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
static int PNGCBAPI
static int
read_callback(png_structp pp, png_unknown_chunkp pc)
{
/* This function mimics the behavior of png_set_keep_unknown_chunks by
Expand Down
30 changes: 15 additions & 15 deletions contrib/libtests/pngvalid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ internal_error(png_store *ps, png_const_charp message)
#endif /* PNG_READ_SUPPORTED */

/* Functions to use as PNG callbacks. */
static void PNGCBAPI
static void
store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
{
png_const_structp pp = ppIn;
Expand All @@ -1109,7 +1109,7 @@ store_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */
}
}

static void PNGCBAPI
static void
store_warning(png_structp ppIn, png_const_charp message)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1281,7 +1281,7 @@ valid_chunktype(png_uint_32 chunktype)
return 1; /* It's valid */
}

static void PNGCBAPI
static void
store_write(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1375,7 +1375,7 @@ store_write(png_structp ppIn, png_bytep pb, size_t st)
ps->chunklen = chunklen;
}

static void PNGCBAPI
static void
store_flush(png_structp ppIn)
{
UNUSED(ppIn) /*DOES NOTHING*/
Expand Down Expand Up @@ -1700,7 +1700,7 @@ store_read_chunk(png_store *ps, png_bytep pb, size_t max, size_t min)
return st; /* space left */
}

static void PNGCBAPI
static void
store_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1903,7 +1903,7 @@ store_pool_delete(png_store *ps, store_pool *pool)
}

/* The memory callbacks: */
static png_voidp PNGCBAPI
static png_voidp
store_malloc(png_structp ppIn, png_alloc_size_t cb)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -1952,7 +1952,7 @@ store_malloc(png_structp ppIn, png_alloc_size_t cb)
return new;
}

static void PNGCBAPI
static void
store_free(png_structp ppIn, png_voidp memory)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -3198,7 +3198,7 @@ modifier_read_imp(png_modifier *pm, png_bytep pb, size_t st)
}

/* The callback: */
static void PNGCBAPI
static void
modifier_read(png_structp ppIn, png_bytep pb, size_t st)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -5391,7 +5391,7 @@ standard_info_imp(standard_display *dp, png_structp pp, png_infop pi,
standard_info_part2(dp, pp, pi, nImages);
}

static void PNGCBAPI
static void
standard_info(png_structp pp, png_infop pi)
{
standard_display *dp = voidcast(standard_display*,
Expand All @@ -5403,7 +5403,7 @@ standard_info(png_structp pp, png_infop pi)
standard_info_imp(dp, pp, pi, 1 /*only one image*/);
}

static void PNGCBAPI
static void
progressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -5703,7 +5703,7 @@ standard_image_validate(standard_display *dp, png_const_structp pp, int iImage,
dp->ps->validated = 1;
}

static void PNGCBAPI
static void
standard_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -6703,7 +6703,7 @@ transform_info_imp(transform_display *dp, png_structp pp, png_infop pi)
}
}

static void PNGCBAPI
static void
transform_info(png_structp pp, png_infop pi)
{
transform_info_imp(voidcast(transform_display*, png_get_progressive_ptr(pp)),
Expand Down Expand Up @@ -6919,7 +6919,7 @@ transform_image_validate(transform_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}

static void PNGCBAPI
static void
transform_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down Expand Up @@ -9385,7 +9385,7 @@ gamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)
standard_info_part2(&dp->this, pp, pi, 1 /*images*/);
}

static void PNGCBAPI
static void
gamma_info(png_structp pp, png_infop pi)
{
gamma_info_imp(voidcast(gamma_display*, png_get_progressive_ptr(pp)), pp,
Expand Down Expand Up @@ -10385,7 +10385,7 @@ gamma_image_validate(gamma_display *dp, png_const_structp pp,
dp->this.ps->validated = 1;
}

static void PNGCBAPI
static void
gamma_end(png_structp ppIn, png_infop pi)
{
png_const_structp pp = ppIn;
Expand Down
8 changes: 4 additions & 4 deletions contrib/tools/pngcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1674,7 +1674,7 @@ makename(struct display *dp, const char *dir, const char *infile)
}

/* error handler callbacks for libpng */
static void PNGCBAPI
static void
display_warning(png_structp pp, png_const_charp warning)
{
struct display *dp = get_dp(pp);
Expand All @@ -1684,7 +1684,7 @@ display_warning(png_structp pp, png_const_charp warning)
display_log(get_dp(pp), LIBPNG_WARNING, "%s", warning);
}

static void PNGCBAPI
static void
display_error(png_structp pp, png_const_charp error)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -1716,7 +1716,7 @@ display_start_read(struct display *dp, const char *filename)
display_log(dp, USER_ERROR, "file open failed (%s)", strerror(errno));
}

static void PNGCBAPI
static void
read_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
Expand Down Expand Up @@ -1896,7 +1896,7 @@ display_start_write(struct display *dp, const char *filename)
}
}

static void PNGCBAPI
static void
write_function(png_structp pp, png_bytep data, size_t size)
{
struct display *dp = get_dp(pp);
Expand Down
6 changes: 3 additions & 3 deletions contrib/tools/pngfix.c
Original file line number Diff line number Diff line change
Expand Up @@ -3149,13 +3149,13 @@ read_chunk(struct file *file)
/* This returns a file* from a png_struct in an implementation specific way. */
static struct file *get_control(png_const_structrp png_ptr);

static void PNGCBAPI
static void
error_handler(png_structp png_ptr, png_const_charp message)
{
stop(get_control(png_ptr), LIBPNG_ERROR_CODE, message);
}

static void PNGCBAPI
static void
warning_handler(png_structp png_ptr, png_const_charp message)
{
struct file *file = get_control(png_ptr);
Expand All @@ -3167,7 +3167,7 @@ warning_handler(png_structp png_ptr, png_const_charp message)
/* Read callback - this is where the work gets done to check the stream before
* passing it to libpng
*/
static void PNGCBAPI
static void
read_callback(png_structp png_ptr, png_bytep buffer, size_t count)
/* Return 'count' bytes to libpng in 'buffer' */
{
Expand Down
12 changes: 6 additions & 6 deletions example.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* example.c - an example of using libpng
*
* Maintained 2018-2024 Cosmin Truta
* Maintained 2018-2025 Cosmin Truta
* Maintained 1998-2016 Glenn Randers-Pehrson
* Maintained 1996-1997 Andreas Dilger
* Written 1995-1996 Guy Eric Schalnat, Group 42, Inc.
Expand Down Expand Up @@ -179,11 +179,11 @@ int main(int argc, const char **argv)
* components.
*
* You do not have to read directly from a file. You can read from memory or,
* on systems that support it, from a <stdio.h> FILE*. This is controlled by
* the particular png_image_read_from_ function you call at the start.
* Likewise, on write, you can write to a FILE* if your system supports it.
* Check the macro PNG_STDIO_SUPPORTED to see if stdio support has been
* included in your libpng build.
* on systems that support <stdio.h>, from a FILE object. This is controlled
* by the particular png_image_read_from_ function you call at the start.
* Likewise, on write, you can write to a FILE object if your system supports
* <stdio.h>. The macro PNG_STDIO_SUPPORTED indicates if stdio is available
* and accessible from your libpng build.
*
* If you read 16-bit (PNG_FORMAT_FLAG_LINEAR) data, you may need to write it
* in the 8-bit format for display. You do this by setting the convert_to_8bit
Expand Down
29 changes: 5 additions & 24 deletions manuals/libpng-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,11 @@ way pngusr.h is used in the build has been changed; however, library
builders will probably want to examine the changes to take advantage of
new capabilities and to simplify their build system.

A. Specific changes to library configuration capabilities

The exact mechanism used to control attributes of API functions has
changed. A single set of operating system independent macro definitions
is used and operating system specific directives are defined in
pnglibconf.h

As part of this the mechanism used to choose procedure call standards on
those systems that allow a choice has been changed. At present this only
affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
running on Intel processors. As before, PNGAPI is defined where required
to control the exported API functions; however, two new macros, PNGCBAPI
and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
(PNGCAPI) for functions that must match a C library prototype (currently
only png_longjmp_ptr, which must match the C longjmp function.) The new
approach is documented in pngconf.h

Despite these changes, libpng 1.5.0 only supports the native C function
calling standard on those platforms tested so far ("__cdecl" on Microsoft
Windows). This is because the support requirements for alternative
calling conventions seem to no longer exist. Developers who find it
necessary to set PNG_API_RULE to 1 should advise the mailing list
(png-mng-implement) of this and library builders who use Openwatcom and
therefore set PNG_API_RULE to 2 should also contact the mailing list.
A. Changes to the library configuration capabilities

A new mechanism to control attributes of API functions was introduced in
libpng-1.5.0. A single set of system-independent macro definitions and
directives is defined in pnglibconf.h

B. Changes to the configuration mechanism

Expand Down
Loading