diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2012-02-02 23:11:45 -0600 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2013-03-01 21:38:03 -0600 |
commit | f3af706c2a489333f816843bc986a6bafe47719b (patch) | |
tree | 8fa3603462427abc8d9b3b349df899621975b72c /example.c | |
parent | 96cf4bde0e3c65012ba71c9b8dc930138a27ca96 (diff) | |
download | libpng-f3af706c2a489333f816843bc986a6bafe47719b.tar.gz |
[libpng16] Imported from libpng-1.6.0beta05.tarv1.6.1beta05
Diffstat (limited to 'example.c')
-rw-r--r-- | example.c | 86 |
1 files changed, 28 insertions, 58 deletions
@@ -2,8 +2,8 @@ #if 0 /* in case someone actually tries to compile this */ /* example.c - an example of using libpng - * Last changed in libpng 1.6.0 [February 14, 2013] - * Maintained 1998-2013 Glenn Randers-Pehrson + * Last changed in libpng 1.6.0 [(PENDING RELEASE)] + * Maintained 1998-2012 Glenn Randers-Pehrson * Maintained 1996, 1997 Andreas Dilger) * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * To the extent possible under law, the authors have waived @@ -48,8 +48,7 @@ int main(int argc, const char **argv) png_image image; /* The control structure used by libpng */ /* Initialize the 'png_image' structure. */ - memset(&image, 0, (sizeof image)); - image.version = PNG_IMAGE_VERSION; + memset(&image, 0, sizeof image); /* The first argument is the file to read: */ if (png_image_begin_read_from_file(&image, argv[1])) @@ -76,28 +75,16 @@ int main(int argc, const char **argv) * be supplied or the output buffer would have to be initialized to the * actual background of the image. * - * The fourth argument to png_image_finish_read is the 'row_stride' - + * The final argument to png_image_finish_read is the 'row_stride' - * this is the number of components allocated for the image in each * row. It has to be at least as big as the value returned by * PNG_IMAGE_ROW_STRIDE, but if you just allocate space for the * default, minimum, size using PNG_IMAGE_SIZE as above you can pass * zero. - * - * The final argument is a pointer to a buffer for the colormap; - * colormaps have exactly the same format as a row of image pixels (so - * you choose what format to make the colormap by setting - * image.format). A colormap is only returned if - * PNG_FORMAT_FLAG_COLORMAP is also set in image.format, so in this - * case NULL is passed as the final argument. If you do want to force - * all images into an index/color-mapped format then you can use: - * - * PNG_IMAGE_COLORMAP_SIZE(image) - * - * to find the maximum size of the colormap in bytes. */ if (buffer != NULL && png_image_finish_read(&image, NULL/*background*/, buffer, - 0/*row_stride*/, NULL/*colormap*/)) + 0/*row_stride*/)) { /* Now write the image out to the second argument. In the write * call 'convert_to_8bit' allows 16-bit data to be squashed down to @@ -105,7 +92,7 @@ int main(int argc, const char **argv) * to the 8-bit format. */ if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/, - buffer, 0/*row_stride*/, NULL/*colormap*/)) + buffer, 0/*row_stride*/)) { /* The image has been written successfully. */ exit(0); @@ -846,7 +833,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 @@ -877,38 +864,25 @@ void write_png(char *file_name /* , ... other image information ... */) png_set_gAMA(png_ptr, info_ptr, gamma); /* Optionally write comments into the image */ - { - png_text text_ptr[3]; - - char key0[]="Title"; - char text0[]="Mona Lisa"; - text_ptr[0].key = key0; - text_ptr[0].text = text0; - text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[0].itxt_length = 0; - text_ptr[0].lang = NULL; - text_ptr[0].lang_key = NULL; - - char key1[]="Author"; - char text1[]="Leonardo DaVinci"; - text_ptr[1].key = key1; - text_ptr[1].text = text1; - text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; - text_ptr[1].itxt_length = 0; - text_ptr[1].lang = NULL; - text_ptr[1].lang_key = NULL; - - char key2[]="Description"; - char text2[]="<long text>"; - text_ptr[2].key = key2; - text_ptr[2].text = text2; - text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; - text_ptr[2].itxt_length = 0; - text_ptr[2].lang = NULL; - text_ptr[2].lang_key = NULL; - - png_set_text(write_ptr, write_info_ptr, text_ptr, 3); - } + text_ptr[0].key = "Title"; + text_ptr[0].text = "Mona Lisa"; + text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[0].itxt_length = 0; + text_ptr[0].lang = NULL; + text_ptr[0].lang_key = NULL; + text_ptr[1].key = "Author"; + text_ptr[1].text = "Leonardo DaVinci"; + text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; + text_ptr[1].itxt_length = 0; + text_ptr[1].lang = NULL; + text_ptr[1].lang_key = NULL; + text_ptr[2].key = "Description"; + text_ptr[2].text = "<long text>"; + text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; + text_ptr[2].itxt_length = 0; + text_ptr[2].lang = NULL; + text_ptr[2].lang_key = NULL; + png_set_text(png_ptr, info_ptr, text_ptr, 3); /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ @@ -981,16 +955,12 @@ void write_png(char *file_name /* , ... other image information ... */) * use the first method if you aren't handling interlacing yourself. */ png_uint_32 k, height, width; - - /* In this example, "image" is a one-dimensional array of bytes */ - png_byte image[height*width*bytes_per_pixel]; - + png_byte image[height][width*bytes_per_pixel]; png_bytep row_pointers[height]; - if (height > PNG_UINT_32_MAX/(sizeof (png_bytep))) + if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) png_error (png_ptr, "Image is too tall to process in memory"); - /* Set up pointers into your "image" byte array */ for (k = 0; k < height; k++) row_pointers[k] = image + k*width*bytes_per_pixel; |