summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libpng/example.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/libpng/example.c')
-rw-r--r--src/3rdparty/libpng/example.c62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/3rdparty/libpng/example.c b/src/3rdparty/libpng/example.c
index 8c5d87b668..cd3682f014 100644
--- a/src/3rdparty/libpng/example.c
+++ b/src/3rdparty/libpng/example.c
@@ -2,15 +2,15 @@
#if 0 /* in case someone actually tries to compile this */
/* example.c - an example of using libpng
- * Last changed in libpng 1.4.0 [January 3, 2010]
+ * Last changed in libpng 1.5.0 [January 6, 2011]
* This file has been placed in the public domain by the authors.
- * Maintained 1998-2010 Glenn Randers-Pehrson
+ * Maintained 1998-2011 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
+ * The file libpng-manual.txt is much more verbose then this. If you have not
* read it, do so first. This was designed to be a starting point of an
* implementation. This is not officially part of libpng, is hereby placed
* in the public domain, and therefore does not require a copyright notice.
@@ -31,7 +31,7 @@
*/
#ifndef png_jmpbuf
-# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
+# define png_jmpbuf(png_ptr) ((png_ptr)->png_jmpbuf)
#endif
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
@@ -160,7 +160,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
* If you have enough memory to read in the entire image at once,
* and you need to specify only transforms that can be controlled
* with one of the PNG_TRANSFORM_* bits (this presently excludes
- * dithering, filling, setting background, and doing gamma
+ * quantizing, filling, setting background, and doing gamma
* adjustment), then you can read the entire image (including
* pixels) into the info structure with this call:
*/
@@ -271,7 +271,8 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
png_set_gamma(png_ptr, screen_gamma, 0.45455);
}
- /* Dither RGB files down to 8 bit palette or reduce palettes
+#ifdef PNG_READ_QUANTIZE_SUPPORTED
+ /* Quantize RGB files down to 8 bit palette or reduce palettes
* to the number of colors available on your screen.
*/
if (color_type & PNG_COLOR_MASK_COLOR)
@@ -282,10 +283,10 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
/* This reduces the image to the application supplied palette */
if (/* We have our own palette */)
{
- /* An array of colors to which the image should be dithered */
+ /* An array of colors to which the image should be quantized */
png_color std_color_cube[MAX_SCREEN_COLORS];
- png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
+ png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
MAX_SCREEN_COLORS, NULL, 0);
}
/* This reduces the image to the palette supplied in the file */
@@ -295,10 +296,11 @@ void read_png(FILE *fp, unsigned int sig_read) /* File is already open */
png_get_hIST(png_ptr, info_ptr, &histogram);
- png_set_dither(png_ptr, palette, num_palette,
+ png_set_quantize(png_ptr, palette, num_palette,
max_screen_colors, histogram, 0);
}
}
+#endif /* PNG_READ_QUANTIZE_SUPPORTED */
/* Invert monochrome files to have 0 as white and 1 as black */
png_set_invert_mono(png_ptr);
@@ -509,20 +511,17 @@ row_callback(png_structp png_ptr, png_bytep new_row,
* shown below:
*/
- /* Check if row_num is in bounds. */
- if ((row_num >= 0) && (row_num < height))
- {
- /* Get pointer to corresponding row in our
- * PNG read buffer.
- */
- png_bytep old_row = ((png_bytep *)our_data)[row_num];
-
- /* If both rows are allocated then copy the new row
- * data to the corresponding row data.
- */
- if ((old_row != NULL) && (new_row != NULL))
- png_progressive_combine_row(png_ptr, old_row, new_row);
- }
+ /* Get pointer to corresponding row in our
+ * PNG read buffer.
+ */
+ png_bytep old_row = ((png_bytep *)our_data)[row_num];
+
+ /* If both rows are allocated then copy the new row
+ * data to the corresponding row data.
+ */
+ if ((old_row != NULL) && (new_row != NULL))
+ png_progressive_combine_row(png_ptr, old_row, new_row);
+
/*
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
@@ -656,14 +655,18 @@ void write_png(char *file_name /* , ... other image information ... */)
/* Optional significant bit (sBIT) chunk */
png_color_8 sig_bit;
+
/* If we are dealing with a grayscale image then */
sig_bit.gray = true_bit_depth;
+
/* Otherwise, if we are dealing with a color image then */
sig_bit.red = true_red_bit_depth;
sig_bit.green = true_green_bit_depth;
sig_bit.blue = true_blue_bit_depth;
+
/* If the image has an alpha channel then */
sig_bit.alpha = true_alpha_bit_depth;
+
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
@@ -676,17 +679,21 @@ void write_png(char *file_name /* , ... other image information ... */)
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;
-#ifdef PNG_iTXt_SUPPORTED
- text_ptr[0].lang = NULL;
- text_ptr[1].lang = NULL;
+ text_ptr[2].itxt_length = 0;
text_ptr[2].lang = NULL;
-#endif
+ 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 */
@@ -751,6 +758,7 @@ void write_png(char *file_name /* , ... other image information ... */)
/* Turn on interlace handling if you are not using png_write_image() */
if (interlacing)
number_passes = png_set_interlace_handling(png_ptr);
+
else
number_passes = 1;