X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2b5f62a0b2db198609b45dec622a018dae37008e..35524f615e56a566786b7621c4b1d16a9c7dd3c7:/src/png/example.c diff --git a/src/png/example.c b/src/png/example.c index 7956cf7abd..4388e46123 100644 --- a/src/png/example.c +++ b/src/png/example.c @@ -1,7 +1,13 @@ #if 0 /* in case someone actually tries to compile this */ -/* example.c - an example of using libpng */ +/* example.c - an example of using libpng + * Last changed in libpng 1.2.33 [December 18, 2008] + * This file has been placed in the public domain by the authors. + * Maintained 1998-2008 Glenn Randers-Pehrson + * Maintained 1996, 1997 Andreas Dilger) + * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) + */ /* This is an example of how to use libpng to read and write PNG files. * The file libpng.txt is much more verbose then this. If you have not @@ -194,11 +200,11 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */ /* Expand paletted colors into true RGB triplets */ if (color_type == PNG_COLOR_TYPE_PALETTE) - png_set_palette_rgb(png_ptr); + png_set_palette_to_rgb(png_ptr); /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */ if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) - png_set_gray_1_2_4_to_8(png_ptr); + png_set_expand_gray_1_2_4_to_8(png_ptr); /* Expand paletted or RGB images with transparency to full alpha channels * so the data will be available as RGBA quartets. @@ -490,16 +496,16 @@ row_callback(png_structp png_ptr, png_bytep new_row, * In this function you will receive a pointer to new row data from * libpng called new_row that is to replace a corresponding row (of * the same data format) in a buffer allocated by your application. - * + * * The new row data pointer new_row may be NULL, indicating there is * no new data to be replaced (in cases of interlace loading). - * + * * If new_row is not NULL then you need to call * png_progressive_combine_row() to replace the corresponding row as * shown below: */ /* Check if row_num is in bounds. */ - if((row_num >= 0) && (row_num < height)) + if ((row_num >= 0) && (row_num < height)) { /* Get pointer to corresponding row in our * PNG read buffer. @@ -509,7 +515,7 @@ row_callback(png_structp png_ptr, png_bytep new_row, /* If both rows are allocated then copy the new row * data to the corresponding row data. */ - if((old_row != NULL) && (new_row != NULL)) + if ((old_row != NULL) && (new_row != NULL)) png_progressive_combine_row(png_ptr, old_row, new_row); } /* @@ -602,7 +608,7 @@ void write_png(char *file_name /* , ... other image information ... */) /* set up the output control if you are using standard C streams */ png_init_io(png_ptr, fp); #else no_streams /* I/O initialization method 2 */ - /* If you are using replacement read functions, instead of calling + /* If you are using replacement write functions, instead of calling * png_init_io() here you would call */ png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn, user_IO_flush_function); @@ -631,7 +637,7 @@ void write_png(char *file_name /* , ... other image information ... */) /* set the palette if there is one. REQUIRED for indexed-color images */ palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH - * sizeof (png_color)); + * png_sizeof(png_color)); /* ... set palette colors ... */ png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH); /* You must not free palette here, because png_set_PLTE only makes a link to @@ -741,6 +747,10 @@ void write_png(char *file_name /* , ... other image information ... */) png_uint_32 k, height, width; png_byte image[height][width*bytes_per_pixel]; png_bytep row_pointers[height]; + + if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) + png_error (png_ptr, "Image is too tall to process in memory"); + for (k = 0; k < height; k++) row_pointers[k] = image + k*width*bytes_per_pixel; @@ -783,13 +793,13 @@ void write_png(char *file_name /* , ... other image information ... */) allocated it with malloc() instead of png_malloc(), use free() instead of png_free(). */ png_free(png_ptr, palette); - palette=NULL; + palette = NULL; /* Similarly, if you png_malloced any data that you passed in with png_set_something(), such as a hist or trans array, free it here, when you can be sure that libpng is through with it. */ png_free(png_ptr, trans); - trans=NULL; + trans = NULL; /* clean up after the write, and free any memory allocated */ png_destroy_write_struct(&png_ptr, &info_ptr);