3
3
4
4
/* example.c - an example of using libpng
5
5
*
6
- * Maintained 2018 Cosmin Truta
6
+ * Maintained 2018-2024 Cosmin Truta
7
7
* Maintained 1998-2016 Glenn Randers-Pehrson
8
8
* Maintained 1996-1997 Andreas Dilger
9
9
* Written 1995-1996 Guy Eric Schalnat, Group 42, Inc.
@@ -259,9 +259,9 @@ int check_if_png(char *file_name, FILE **fp)
259
259
return 0 ;
260
260
261
261
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
262
- * Return nonzero ( true) if they match.
262
+ * Return true if they match.
263
263
*/
264
- return (! png_sig_cmp (buf , 0 , PNG_BYTES_TO_CHECK )) ;
264
+ return png_sig_cmp (buf , 0 , PNG_BYTES_TO_CHECK ) == 0 ;
265
265
}
266
266
267
267
/* 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 */
281
281
FILE * fp ;
282
282
283
283
if ((fp = fopen (file_name , "rb" )) == NULL )
284
- return ( ERROR ) ;
284
+ return ERROR ;
285
285
286
286
#else no_open_file /* prototype 2 */
287
287
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 */
304
304
if (png_ptr == NULL )
305
305
{
306
306
fclose (fp );
307
- return ( ERROR ) ;
307
+ return ERROR ;
308
308
}
309
309
310
310
/* Allocate/initialize the memory for image information. REQUIRED. */
@@ -313,7 +313,7 @@ void read_png(FILE *fp, int sig_read) /* File is already open */
313
313
{
314
314
fclose (fp );
315
315
png_destroy_read_struct (& png_ptr , NULL , NULL );
316
- return ( ERROR ) ;
316
+ return ERROR ;
317
317
}
318
318
319
319
/* 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 */
326
326
png_destroy_read_struct (& png_ptr , & info_ptr , NULL );
327
327
fclose (fp );
328
328
/* If we get here, we had a problem reading the file. */
329
- return ( ERROR ) ;
329
+ return ERROR ;
330
330
}
331
331
332
332
/* 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 */
585
585
fclose (fp );
586
586
587
587
/* That's it! */
588
- return ( OK ) ;
588
+ return OK ;
589
589
}
590
590
591
591
/* Progressively read a file */
@@ -604,18 +604,18 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
604
604
if (* png_ptr == NULL )
605
605
{
606
606
* info_ptr = NULL ;
607
- return ( ERROR ) ;
607
+ return ERROR ;
608
608
}
609
609
* info_ptr = png_create_info_struct (png_ptr );
610
610
if (* info_ptr == NULL )
611
611
{
612
612
png_destroy_read_struct (png_ptr , info_ptr , NULL );
613
- return ( ERROR ) ;
613
+ return ERROR ;
614
614
}
615
615
if (setjmp (png_jmpbuf ((* png_ptr ))))
616
616
{
617
617
png_destroy_read_struct (png_ptr , info_ptr , NULL );
618
- return ( ERROR ) ;
618
+ return ERROR ;
619
619
}
620
620
621
621
/* You will need to provide all three function callbacks,
@@ -632,7 +632,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
632
632
*/
633
633
png_set_progressive_read_fn (* png_ptr , (void * )stream_data ,
634
634
info_callback , row_callback , end_callback );
635
- return ( OK ) ;
635
+ return OK ;
636
636
}
637
637
638
638
int
@@ -643,7 +643,7 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
643
643
{
644
644
/* Free the png_ptr and info_ptr memory on error. */
645
645
png_destroy_read_struct (png_ptr , info_ptr , NULL );
646
- return ( ERROR ) ;
646
+ return ERROR ;
647
647
}
648
648
649
649
/* 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,
657
657
* callback, if you aren't already displaying them there.
658
658
*/
659
659
png_process_data (* png_ptr , * info_ptr , buffer , length );
660
- return ( OK ) ;
660
+ return OK ;
661
661
}
662
662
663
663
info_callback (png_structp png_ptr , png_infop info )
@@ -747,7 +747,7 @@ void write_png(char *file_name /* , ... other image information ... */)
747
747
/* Open the file */
748
748
fp = fopen (file_name , "wb" );
749
749
if (fp == NULL )
750
- return ( ERROR ) ;
750
+ return ERROR ;
751
751
752
752
/* Create and initialize the png_struct with the desired error handler
753
753
* 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 ... */)
760
760
if (png_ptr == NULL )
761
761
{
762
762
fclose (fp );
763
- return ( ERROR ) ;
763
+ return ERROR ;
764
764
}
765
765
766
766
/* Allocate/initialize the image information data. REQUIRED. */
@@ -769,7 +769,7 @@ void write_png(char *file_name /* , ... other image information ... */)
769
769
{
770
770
fclose (fp );
771
771
png_destroy_write_struct (& png_ptr , NULL );
772
- return ( ERROR ) ;
772
+ return ERROR ;
773
773
}
774
774
775
775
/* 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 ... */)
780
780
/* If we get here, we had a problem writing the file. */
781
781
fclose (fp );
782
782
png_destroy_write_struct (& png_ptr , & info_ptr );
783
- return ( ERROR ) ;
783
+ return ERROR ;
784
784
}
785
785
786
786
/* One of the following I/O initialization functions is REQUIRED. */
@@ -1035,7 +1035,7 @@ void write_png(char *file_name /* , ... other image information ... */)
1035
1035
fclose (fp );
1036
1036
1037
1037
/* That's it! */
1038
- return ( OK ) ;
1038
+ return OK ;
1039
1039
}
1040
1040
1041
1041
#endif /* if 0 */
0 commit comments