chore: Clean up the return statements and update example.c accordingly

libpng16
Cosmin Truta 2024-01-23 21:25:03 +02:00
parent 92b2128a75
commit 27e548af25
11 changed files with 159 additions and 159 deletions

View File

@ -3,7 +3,7 @@
/* example.c - an example of using libpng
*
* Maintained 2018 Cosmin Truta
* Maintained 2018-2024 Cosmin Truta
* Maintained 1998-2016 Glenn Randers-Pehrson
* Maintained 1996-1997 Andreas Dilger
* Written 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@ -259,9 +259,9 @@ int check_if_png(char *file_name, FILE **fp)
return 0;
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
* Return nonzero (true) if they match.
* Return true if they match.
*/
return(!png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK));
return png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK) == 0;
}
/* Read a PNG file. You may want to return an error code if the read
@ -281,7 +281,7 @@ void read_png(char *file_name) /* We need to open the file */
FILE *fp;
if ((fp = fopen(file_name, "rb")) == NULL)
return (ERROR);
return ERROR;
#else no_open_file /* prototype 2 */
void read_png(FILE *fp, int sig_read) /* File is already open */
@ -304,7 +304,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
if (png_ptr == NULL)
{
fclose(fp);
return (ERROR);
return ERROR;
}
/* Allocate/initialize the memory for image information. REQUIRED. */
@ -313,7 +313,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
{
fclose(fp);
png_destroy_read_struct(&png_ptr, NULL, NULL);
return (ERROR);
return ERROR;
}
/* Set error handling if you are using the setjmp/longjmp method (this is
@ -326,7 +326,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
fclose(fp);
/* If we get here, we had a problem reading the file. */
return (ERROR);
return ERROR;
}
/* One of the following I/O initialization methods is REQUIRED. */
@ -585,7 +585,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
fclose(fp);
/* That's it! */
return (OK);
return OK;
}
/* Progressively read a file */
@ -604,18 +604,18 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
if (*png_ptr == NULL)
{
*info_ptr = NULL;
return (ERROR);
return ERROR;
}
*info_ptr = png_create_info_struct(png_ptr);
if (*info_ptr == NULL)
{
png_destroy_read_struct(png_ptr, info_ptr, NULL);
return (ERROR);
return ERROR;
}
if (setjmp(png_jmpbuf((*png_ptr))))
{
png_destroy_read_struct(png_ptr, info_ptr, NULL);
return (ERROR);
return ERROR;
}
/* You will need to provide all three function callbacks,
@ -632,7 +632,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
*/
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
info_callback, row_callback, end_callback);
return (OK);
return OK;
}
int
@ -643,7 +643,7 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
{
/* Free the png_ptr and info_ptr memory on error. */
png_destroy_read_struct(png_ptr, info_ptr, NULL);
return (ERROR);
return ERROR;
}
/* Give chunks of data as they arrive from the data stream
@ -657,7 +657,7 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
* callback, if you aren't already displaying them there.
*/
png_process_data(*png_ptr, *info_ptr, buffer, length);
return (OK);
return OK;
}
info_callback(png_structp png_ptr, png_infop info)
@ -747,7 +747,7 @@ void write_png(char *file_name /* , ... other image information ... */)
/* Open the file */
fp = fopen(file_name, "wb");
if (fp == NULL)
return (ERROR);
return ERROR;
/* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method,
@ -760,7 +760,7 @@ void write_png(char *file_name /* , ... other image information ... */)
if (png_ptr == NULL)
{
fclose(fp);
return (ERROR);
return ERROR;
}
/* Allocate/initialize the image information data. REQUIRED. */
@ -769,7 +769,7 @@ void write_png(char *file_name /* , ... other image information ... */)
{
fclose(fp);
png_destroy_write_struct(&png_ptr, NULL);
return (ERROR);
return ERROR;
}
/* Set up error handling. REQUIRED if you aren't supplying your own
@ -780,7 +780,7 @@ void write_png(char *file_name /* , ... other image information ... */)
/* If we get here, we had a problem writing the file. */
fclose(fp);
png_destroy_write_struct(&png_ptr, &info_ptr);
return (ERROR);
return ERROR;
}
/* One of the following I/O initialization functions is REQUIRED. */
@ -1035,7 +1035,7 @@ void write_png(char *file_name /* , ... other image information ... */)
fclose(fp);
/* That's it! */
return (OK);
return OK;
}
#endif /* if 0 */

14
png.c
View File

@ -59,15 +59,15 @@ png_sig_cmp(png_const_bytep sig, size_t start, size_t num_to_check)
num_to_check = 8;
else if (num_to_check < 1)
return (-1);
return -1;
if (start > 7)
return (-1);
return -1;
if (start + num_to_check > 8)
num_to_check = 8 - start;
return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check)));
return memcmp(&sig[start], &png_signature[start], num_to_check);
}
#endif /* READ */
@ -665,9 +665,9 @@ png_voidp PNGAPI
png_get_io_ptr(png_const_structrp png_ptr)
{
if (png_ptr == NULL)
return (NULL);
return NULL;
return (png_ptr->io_ptr);
return png_ptr->io_ptr;
}
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@ -956,7 +956,7 @@ png_reset_zstream(png_structrp png_ptr)
return Z_STREAM_ERROR;
/* WARNING: this resets the window bits to the maximum! */
return (inflateReset(&png_ptr->zstream));
return inflateReset(&png_ptr->zstream);
}
#endif /* READ */
@ -965,7 +965,7 @@ png_uint_32 PNGAPI
png_access_version_number(void)
{
/* Version of *.c files used when building libpng */
return((png_uint_32)PNG_LIBPNG_VER);
return (png_uint_32)PNG_LIBPNG_VER;
}
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)

6
png.h
View File

@ -908,15 +908,15 @@ PNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));
/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
* PNG file. Returns zero if the supplied bytes match the 8-byte PNG
* signature, and non-zero otherwise. Having num_to_check == 0 or
* start > 7 will always fail (ie return non-zero).
* start > 7 will always fail (i.e. return non-zero).
*/
PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, size_t start,
size_t num_to_check));
/* Simple signature checking function. This is the same as calling
* png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
* png_check_sig(sig, n) := (png_sig_cmp(sig, 0, n) != 0).
*/
#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
#define png_check_sig(sig, n) (png_sig_cmp((sig), 0, (n)) != 0)
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
PNG_EXPORTA(4, png_structp, png_create_read_struct,

View File

@ -1,7 +1,7 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2018-2024 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@ -858,7 +858,7 @@ png_get_error_ptr(png_const_structrp png_ptr)
if (png_ptr == NULL)
return NULL;
return ((png_voidp)png_ptr->error_ptr);
return (png_voidp)png_ptr->error_ptr;
}

164
pngget.c
View File

@ -28,22 +28,22 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
* valid tRNS chunk in this case.
*/
if (flag == PNG_INFO_tRNS && png_ptr->num_trans == 0)
return(0);
return 0;
#endif
return(info_ptr->valid & flag);
return info_ptr->valid & flag;
}
return(0);
return 0;
}
size_t PNGAPI
png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->rowbytes);
return info_ptr->rowbytes;
return(0);
return 0;
}
#ifdef PNG_INFO_IMAGE_SUPPORTED
@ -51,9 +51,9 @@ png_bytepp PNGAPI
png_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->row_pointers);
return info_ptr->row_pointers;
return(0);
return 0;
}
#endif
@ -65,7 +65,7 @@ png_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->width;
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -74,7 +74,7 @@ png_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->height;
return (0);
return 0;
}
png_byte PNGAPI
@ -83,7 +83,7 @@ png_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->bit_depth;
return (0);
return 0;
}
png_byte PNGAPI
@ -92,7 +92,7 @@ png_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->color_type;
return (0);
return 0;
}
png_byte PNGAPI
@ -101,7 +101,7 @@ png_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->filter_type;
return (0);
return 0;
}
png_byte PNGAPI
@ -110,7 +110,7 @@ png_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->interlace_type;
return (0);
return 0;
}
png_byte PNGAPI
@ -119,7 +119,7 @@ png_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return info_ptr->compression_type;
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -133,14 +133,14 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
return (info_ptr->x_pixels_per_unit);
return info_ptr->x_pixels_per_unit;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -154,14 +154,14 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
return (info_ptr->y_pixels_per_unit);
return info_ptr->y_pixels_per_unit;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -175,14 +175,14 @@ png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
return (info_ptr->x_pixels_per_unit);
return info_ptr->x_pixels_per_unit;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
#ifdef PNG_FLOATING_POINT_SUPPORTED
@ -197,15 +197,15 @@ png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
(info_ptr->valid & PNG_INFO_pHYs) != 0)
{
if (info_ptr->x_pixels_per_unit != 0)
return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit));
return (float)info_ptr->y_pixels_per_unit
/ (float)info_ptr->x_pixels_per_unit;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return ((float)0.0);
return (float)0.0;
}
#endif
@ -251,14 +251,14 @@ png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
return (info_ptr->x_offset);
return info_ptr->x_offset;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
png_int_32 PNGAPI
@ -271,14 +271,14 @@ png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
return (info_ptr->y_offset);
return info_ptr->y_offset;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
png_int_32 PNGAPI
@ -291,14 +291,14 @@ png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
return (info_ptr->x_offset);
return info_ptr->x_offset;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
png_int_32 PNGAPI
@ -311,14 +311,14 @@ png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
(info_ptr->valid & PNG_INFO_oFFs) != 0)
{
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
return (info_ptr->y_offset);
return info_ptr->y_offset;
}
#else
PNG_UNUSED(png_ptr)
PNG_UNUSED(info_ptr)
#endif
return (0);
return 0;
}
#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
@ -462,7 +462,7 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
}
}
return (retval);
return retval;
}
#endif /* pHYs */
#endif /* INCH_CONVERSIONS */
@ -476,9 +476,9 @@ png_byte PNGAPI
png_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->channels);
return info_ptr->channels;
return (0);
return 0;
}
#ifdef PNG_READ_SUPPORTED
@ -486,9 +486,9 @@ png_const_bytep PNGAPI
png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->signature);
return info_ptr->signature;
return (NULL);
return NULL;
}
#endif
@ -504,10 +504,10 @@ png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
background != NULL)
{
*background = &(info_ptr->background);
return (PNG_INFO_bKGD);
return PNG_INFO_bKGD;
}
return (0);
return 0;
}
#endif
@ -557,10 +557,10 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
if (blue_y != NULL)
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
"cHRM blue Y");
return (PNG_INFO_cHRM);
return PNG_INFO_cHRM;
}
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -601,10 +601,10 @@ png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
if (blue_Z != NULL)
*blue_Z = png_float(png_ptr,
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
return (PNG_INFO_cHRM);
return PNG_INFO_cHRM;
}
return (0);
return 0;
}
# endif
@ -640,10 +640,10 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
*int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;
if (int_blue_Z != NULL)
*int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;
return (PNG_INFO_cHRM);
return PNG_INFO_cHRM;
}
return (0);
return 0;
}
png_uint_32 PNGAPI
@ -673,10 +673,10 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
*blue_x = info_ptr->colorspace.end_points_xy.bluex;
if (blue_y != NULL)
*blue_y = info_ptr->colorspace.end_points_xy.bluey;
return (PNG_INFO_cHRM);
return PNG_INFO_cHRM;
}
return (0);
return 0;
}
# endif
#endif
@ -694,10 +694,10 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
file_gamma != NULL)
{
*file_gamma = info_ptr->colorspace.gamma;
return (PNG_INFO_gAMA);
return PNG_INFO_gAMA;
}
return (0);
return 0;
}
# endif
@ -714,10 +714,10 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
{
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
"png_get_gAMA");
return (PNG_INFO_gAMA);
return PNG_INFO_gAMA;
}
return (0);
return 0;
}
# endif
#endif
@ -733,10 +733,10 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
{
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
return (PNG_INFO_sRGB);
return PNG_INFO_sRGB;
}
return (0);
return 0;
}
#endif
@ -760,10 +760,10 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
*/
if (compression_type != NULL)
*compression_type = PNG_COMPRESSION_TYPE_BASE;
return (PNG_INFO_iCCP);
return PNG_INFO_iCCP;
}
return (0);
return 0;
}
#endif
@ -781,7 +781,7 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
return info_ptr->splt_palettes_num;
}
return (0);
return 0;
}
#endif
@ -807,10 +807,10 @@ png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
{
*num_exif = info_ptr->num_exif;
*exif = info_ptr->exif;
return (PNG_INFO_eXIf);
return PNG_INFO_eXIf;
}
return (0);
return 0;
}
#endif
@ -825,10 +825,10 @@ png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
{
*hist = info_ptr->hist;
return (PNG_INFO_hIST);
return PNG_INFO_hIST;
}
return (0);
return 0;
}
#endif
@ -841,7 +841,7 @@ png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
png_debug1(1, "in %s retrieval function", "IHDR");
if (png_ptr == NULL || info_ptr == NULL)
return (0);
return 0;
if (width != NULL)
*width = info_ptr->width;
@ -873,7 +873,7 @@ png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
info_ptr->compression_type, info_ptr->filter_type);
return (1);
return 1;
}
#ifdef PNG_oFFs_SUPPORTED
@ -890,10 +890,10 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
*offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset;
*unit_type = (int)info_ptr->offset_unit_type;
return (PNG_INFO_oFFs);
return PNG_INFO_oFFs;
}
return (0);
return 0;
}
#endif
@ -917,10 +917,10 @@ png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
*nparams = (int)info_ptr->pcal_nparams;
*units = info_ptr->pcal_units;
*params = info_ptr->pcal_params;
return (PNG_INFO_pCAL);
return PNG_INFO_pCAL;
}
return (0);
return 0;
}
#endif
@ -945,10 +945,10 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
"sCAL height");
return (PNG_INFO_sCAL);
return PNG_INFO_sCAL;
}
return(0);
return 0;
}
# endif /* FLOATING_ARITHMETIC */
# endif /* FIXED_POINT */
@ -965,10 +965,10 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
*unit = info_ptr->scal_unit;
*width = atof(info_ptr->scal_s_width);
*height = atof(info_ptr->scal_s_height);
return (PNG_INFO_sCAL);
return PNG_INFO_sCAL;
}
return(0);
return 0;
}
# endif /* FLOATING POINT */
png_uint_32 PNGAPI
@ -983,10 +983,10 @@ png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
*unit = info_ptr->scal_unit;
*width = info_ptr->scal_s_width;
*height = info_ptr->scal_s_height;
return (PNG_INFO_sCAL);
return PNG_INFO_sCAL;
}
return(0);
return 0;
}
#endif /* sCAL */
@ -1021,7 +1021,7 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
}
}
return (retval);
return retval;
}
#endif /* pHYs */
@ -1037,10 +1037,10 @@ png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
*palette = info_ptr->palette;
*num_palette = info_ptr->num_palette;
png_debug1(3, "num_palette = %d", *num_palette);
return (PNG_INFO_PLTE);
return PNG_INFO_PLTE;
}
return (0);
return 0;
}
#ifdef PNG_sBIT_SUPPORTED
@ -1054,10 +1054,10 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
{
*sig_bit = &(info_ptr->sig_bit);
return (PNG_INFO_sBIT);
return PNG_INFO_sBIT;
}
return (0);
return 0;
}
#endif
@ -1083,7 +1083,7 @@ png_get_text(png_const_structrp png_ptr, png_inforp info_ptr,
if (num_text != NULL)
*num_text = 0;
return(0);
return 0;
}
#endif
@ -1098,10 +1098,10 @@ png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
{
*mod_time = &(info_ptr->mod_time);
return (PNG_INFO_tIME);
return PNG_INFO_tIME;
}
return (0);
return 0;
}
#endif
@ -1148,7 +1148,7 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
}
}
return (retval);
return retval;
}
#endif
@ -1163,7 +1163,7 @@ png_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,
return info_ptr->unknown_chunks_num;
}
return (0);
return 0;
}
#endif
@ -1259,7 +1259,7 @@ png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
if (png_ptr != NULL && info_ptr != NULL)
return png_ptr->num_palette_max;
return (-1);
return -1;
}
# endif
#endif

View File

@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2018-2024 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@ -145,10 +145,10 @@ png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
num_to_check);
png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
{
if (num_checked < 4 &&
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4) != 0)
png_error(png_ptr, "Not a PNG file");
else
@ -1089,7 +1089,7 @@ png_voidp PNGAPI
png_get_progressive_ptr(png_const_structrp png_ptr)
{
if (png_ptr == NULL)
return (NULL);
return NULL;
return png_ptr->io_ptr;
}

View File

@ -26,7 +26,7 @@ png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
if (uval > PNG_UINT_31_MAX)
png_error(png_ptr, "PNG unsigned integer out of range");
return (uval);
return uval;
}
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
@ -140,7 +140,7 @@ png_read_sig(png_structrp png_ptr, png_inforp info_ptr)
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)
{
if (num_checked < 4 &&
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4) != 0)
png_error(png_ptr, "Not a PNG file");
else
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
@ -238,10 +238,10 @@ png_crc_finish(png_structrp png_ptr, png_uint_32 skip)
else
png_chunk_error(png_ptr, "CRC error");
return (1);
return 1;
}
return (0);
return 0;
}
/* Compare the CRC stored in the PNG file with that calculated by libpng from
@ -277,11 +277,11 @@ png_crc_error(png_structrp png_ptr)
if (need_crc != 0)
{
crc = png_get_uint_32(crc_bytes);
return ((int)(crc != png_ptr->crc));
return crc != png_ptr->crc;
}
else
return (0);
return 0;
}
#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\

View File

@ -767,7 +767,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
png_ptr == NULL ? 0xabadca11UL : (unsigned long)png_ptr->chunk_name);
if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)
return(0);
return 0;
/* Make sure we have enough space in the "text" array in info_struct
* to hold all of the incoming text_ptr objects. This compare can't overflow
@ -947,7 +947,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,
png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
}
return(0);
return 0;
}
#endif

View File

@ -524,7 +524,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
*/
if (size == 0)
return (NULL);
return NULL;
/* This calls the library allocator twice, once to get the requested
buffer and once to get a new free list entry. */
@ -565,7 +565,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
pinfo->pointer);
return (png_voidp)(pinfo->pointer);
return (png_voidp)pinfo->pointer;
}
}
@ -698,9 +698,9 @@ read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
png_error(png_ptr, "lost user chunk pointer");
/* Return one of the following:
* return (-n); chunk had an error
* return (0); did not recognize
* return (n); success
* return -n; chunk had an error
* return 0; did not recognize
* return n; success
*
* The unknown chunk structure contains the chunk data:
* png_byte name[5];
@ -715,38 +715,38 @@ read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
{
/* Found sTER chunk */
if (chunk->size != 1)
return (-1); /* Error return */
return -1; /* Error return */
if (chunk->data[0] != 0 && chunk->data[0] != 1)
return (-1); /* Invalid mode */
return -1; /* Invalid mode */
if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0)
{
my_user_chunk_data->sTER_mode=chunk->data[0];
return (1);
return 1;
}
else
return (0); /* duplicate sTER - give it to libpng */
return 0; /* duplicate sTER - give it to libpng */
}
if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */
return (0); /* Did not recognize */
return 0; /* Did not recognize */
/* Found ImageMagick vpAg chunk */
if (chunk->size != 9)
return (-1); /* Error return */
return -1; /* Error return */
if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0)
return (0); /* duplicate vpAg */
return 0; /* duplicate vpAg */
my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);
my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4);
my_user_chunk_data->vpAg_units = chunk->data[8];
return (1);
return 1;
}
#ifdef PNG_WRITE_SUPPORTED
@ -882,14 +882,14 @@ test_one_file(const char *inname, const char *outname)
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find input file %s\n", inname);
return (1);
return 1;
}
if ((fpout = fopen(outname, "wb")) == NULL)
{
fprintf(STDERR, "Could not open output file %s\n", outname);
FCLOSE(fpin);
return (1);
return 1;
}
pngtest_debug("Allocating read and write structures");
@ -948,7 +948,7 @@ test_one_file(const char *inname, const char *outname)
#endif
FCLOSE(fpin);
FCLOSE(fpout);
return (1);
return 1;
}
#ifdef PNG_WRITE_SUPPORTED
@ -968,7 +968,7 @@ test_one_file(const char *inname, const char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
FCLOSE(fpin);
FCLOSE(fpout);
return (1);
return 1;
}
#endif
#endif
@ -1686,7 +1686,7 @@ test_one_file(const char *inname, const char *outname)
inname, error_count, warning_count);
if (strict != 0)
return (1);
return 1;
}
# ifdef PNG_WRITE_SUPPORTED
@ -1704,21 +1704,21 @@ test_one_file(const char *inname, const char *outname)
inname, warning_count);
if (strict != 0)
return (1);
return 1;
}
pngtest_debug("Opening files for comparison");
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", inname);
return (1);
return 1;
}
if ((fpout = fopen(outname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", outname);
FCLOSE(fpin);
return (1);
return 1;
}
#if defined (PNG_WRITE_SUPPORTED) /* else nothing was written */ &&\
@ -1757,10 +1757,10 @@ test_one_file(const char *inname, const char *outname)
FCLOSE(fpout);
if (strict != 0 && unsupported_chunks == 0)
return (1);
return 1;
else
return (0);
return 0;
}
if (num_in == 0)
@ -1794,10 +1794,10 @@ test_one_file(const char *inname, const char *outname)
* can be exactly the same size!
*/
if (strict != 0 && unsupported_chunks == 0)
return (1);
return 1;
else
return (0);
return 0;
}
}
}
@ -1806,7 +1806,7 @@ test_one_file(const char *inname, const char *outname)
FCLOSE(fpin);
FCLOSE(fpout);
return (0);
return 0;
}
/* Input and output filenames */

View File

@ -103,10 +103,10 @@ png_set_interlace_handling(png_structrp png_ptr)
if (png_ptr != 0 && png_ptr->interlaced != 0)
{
png_ptr->transformations |= PNG_INTERLACE;
return (7);
return 7;
}
return (1);
return 1;
}
#endif
@ -837,7 +837,7 @@ png_voidp PNGAPI
png_get_user_transform_ptr(png_const_structrp png_ptr)
{
if (png_ptr == NULL)
return (NULL);
return NULL;
return png_ptr->user_transform_ptr;
}

View File

@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file
*
* Copyright (c) 2018-2022 Cosmin Truta
* Copyright (c) 2018-2024 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
* Copyright (c) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@ -2311,7 +2311,7 @@ png_setup_sub_row(png_structrp png_ptr, png_uint_32 bpp,
break;
}
return (sum);
return sum;
}
static void /* PRIVATE */
@ -2361,7 +2361,7 @@ png_setup_up_row(png_structrp png_ptr, size_t row_bytes, size_t lmins)
break;
}
return (sum);
return sum;
}
static void /* PRIVATE */
png_setup_up_row_only(png_structrp png_ptr, size_t row_bytes)
@ -2417,7 +2417,7 @@ png_setup_avg_row(png_structrp png_ptr, png_uint_32 bpp,
break;
}
return (sum);
return sum;
}
static void /* PRIVATE */
png_setup_avg_row_only(png_structrp png_ptr, png_uint_32 bpp,
@ -2500,7 +2500,7 @@ png_setup_paeth_row(png_structrp png_ptr, png_uint_32 bpp,
break;
}
return (sum);
return sum;
}
static void /* PRIVATE */
png_setup_paeth_row_only(png_structrp png_ptr, png_uint_32 bpp,