Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: third_party/libpng/pngrtran.c

Issue 15041: Update libpng to 1.2.33. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 12 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libpng/pngrio.c ('k') | third_party/libpng/pngrutil.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngrtran.c - transforms the data in a row for PNG readers 2 /* pngrtran.c - transforms the data in a row for PNG readers
3 * 3 *
4 * Last changed in libpng 1.2.27 [April 29, 2008] 4 * Last changed in libpng 1.2.30 [August 15, 2008]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * 9 *
10 * This file contains functions optionally called by an application 10 * This file contains functions optionally called by an application
11 * in order to tell libpng how to handle data when reading a PNG. 11 * in order to tell libpng how to handle data when reading a PNG.
12 * Transformations that are used in both reading and writing are 12 * Transformations that are used in both reading and writing are
13 * in pngtrans.c. 13 * in pngtrans.c.
14 */ 14 */
15 15
16 #define PNG_INTERNAL 16 #define PNG_INTERNAL
17 #include "png.h" 17 #include "png.h"
18
19 #if defined(PNG_READ_SUPPORTED) 18 #if defined(PNG_READ_SUPPORTED)
20 19
21 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ 20 /* Set the action on getting a CRC error for an ancillary or critical chunk. */
22 void PNGAPI 21 void PNGAPI
23 png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) 22 png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
24 { 23 {
25 png_debug(1, "in png_set_crc_action\n"); 24 png_debug(1, "in png_set_crc_action\n");
26 /* Tell libpng how we react to CRC errors in critical chunks */ 25 /* Tell libpng how we react to CRC errors in critical chunks */
27 if(png_ptr == NULL) return; 26 if (png_ptr == NULL) return;
28 switch (crit_action) 27 switch (crit_action)
29 { 28 {
30 case PNG_CRC_NO_CHANGE: /* leave setting as is */ 29 case PNG_CRC_NO_CHANGE: /* leave setting as is */
31 break; 30 break;
32 case PNG_CRC_WARN_USE: /* warn/use data */ 31 case PNG_CRC_WARN_USE: /* warn/use data */
33 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; 32 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
34 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; 33 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
35 break; 34 break;
36 case PNG_CRC_QUIET_USE: /* quiet/use data */ 35 case PNG_CRC_QUIET_USE: /* quiet/use data */
37 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; 36 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
38 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | 37 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
39 PNG_FLAG_CRC_CRITICAL_IGNORE; 38 PNG_FLAG_CRC_CRITICAL_IGNORE;
40 break; 39 break;
41 case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */ 40 case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
42 png_warning(png_ptr, "Can't discard critical data on CRC error."); 41 png_warning(png_ptr,
42 "Can't discard critical data on CRC error.");
43 case PNG_CRC_ERROR_QUIT: /* error/quit */ 43 case PNG_CRC_ERROR_QUIT: /* error/quit */
44 case PNG_CRC_DEFAULT: 44 case PNG_CRC_DEFAULT:
45 default: 45 default:
46 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; 46 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
47 break; 47 break;
48 } 48 }
49 49
50 switch (ancil_action) 50 switch (ancil_action)
51 { 51 {
52 case PNG_CRC_NO_CHANGE: /* leave setting as is */ 52 case PNG_CRC_NO_CHANGE: /* leave setting as is */
(...skipping 21 matching lines...) Expand all
74 74
75 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ 75 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
76 defined(PNG_FLOATING_POINT_SUPPORTED) 76 defined(PNG_FLOATING_POINT_SUPPORTED)
77 /* handle alpha and tRNS via a background color */ 77 /* handle alpha and tRNS via a background color */
78 void PNGAPI 78 void PNGAPI
79 png_set_background(png_structp png_ptr, 79 png_set_background(png_structp png_ptr,
80 png_color_16p background_color, int background_gamma_code, 80 png_color_16p background_color, int background_gamma_code,
81 int need_expand, double background_gamma) 81 int need_expand, double background_gamma)
82 { 82 {
83 png_debug(1, "in png_set_background\n"); 83 png_debug(1, "in png_set_background\n");
84 if(png_ptr == NULL) return; 84 if (png_ptr == NULL) return;
85 if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) 85 if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
86 { 86 {
87 png_warning(png_ptr, "Application must supply a known background gamma"); 87 png_warning(png_ptr, "Application must supply a known background gamma");
88 return; 88 return;
89 } 89 }
90 90
91 png_ptr->transformations |= PNG_BACKGROUND; 91 png_ptr->transformations |= PNG_BACKGROUND;
92 png_memcpy(&(png_ptr->background), background_color, 92 png_memcpy(&(png_ptr->background), background_color,
93 png_sizeof(png_color_16)); 93 png_sizeof(png_color_16));
94 png_ptr->background_gamma = (float)background_gamma; 94 png_ptr->background_gamma = (float)background_gamma;
95 png_ptr->background_gamma_type = (png_byte)(background_gamma_code); 95 png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
96 png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); 96 png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
97 } 97 }
98 #endif 98 #endif
99 99
100 #if defined(PNG_READ_16_TO_8_SUPPORTED) 100 #if defined(PNG_READ_16_TO_8_SUPPORTED)
101 /* strip 16 bit depth files to 8 bit depth */ 101 /* strip 16 bit depth files to 8 bit depth */
102 void PNGAPI 102 void PNGAPI
103 png_set_strip_16(png_structp png_ptr) 103 png_set_strip_16(png_structp png_ptr)
104 { 104 {
105 png_debug(1, "in png_set_strip_16\n"); 105 png_debug(1, "in png_set_strip_16\n");
106 if(png_ptr == NULL) return; 106 if (png_ptr == NULL) return;
107 png_ptr->transformations |= PNG_16_TO_8; 107 png_ptr->transformations |= PNG_16_TO_8;
108 } 108 }
109 #endif 109 #endif
110 110
111 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) 111 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
112 void PNGAPI 112 void PNGAPI
113 png_set_strip_alpha(png_structp png_ptr) 113 png_set_strip_alpha(png_structp png_ptr)
114 { 114 {
115 png_debug(1, "in png_set_strip_alpha\n"); 115 png_debug(1, "in png_set_strip_alpha\n");
116 if(png_ptr == NULL) return; 116 if (png_ptr == NULL) return;
117 png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; 117 png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
118 } 118 }
119 #endif 119 #endif
120 120
121 #if defined(PNG_READ_DITHER_SUPPORTED) 121 #if defined(PNG_READ_DITHER_SUPPORTED)
122 /* Dither file to 8 bit. Supply a palette, the current number 122 /* Dither file to 8 bit. Supply a palette, the current number
123 * of elements in the palette, the maximum number of elements 123 * of elements in the palette, the maximum number of elements
124 * allowed, and a histogram if possible. If the current number 124 * allowed, and a histogram if possible. If the current number
125 * of colors is greater then the maximum number, the palette will be 125 * of colors is greater then the maximum number, the palette will be
126 * modified to fit in the maximum number. "full_dither" indicates 126 * modified to fit in the maximum number. "full_dither" indicates
127 * whether we need a dithering cube set up for RGB images, or if we 127 * whether we need a dithering cube set up for RGB images, or if we
128 * simply are reducing the number of colors in a paletted image. 128 * simply are reducing the number of colors in a paletted image.
129 */ 129 */
130 130
131 typedef struct png_dsort_struct 131 typedef struct png_dsort_struct
132 { 132 {
133 struct png_dsort_struct FAR * next; 133 struct png_dsort_struct FAR * next;
134 png_byte left; 134 png_byte left;
135 png_byte right; 135 png_byte right;
136 } png_dsort; 136 } png_dsort;
137 typedef png_dsort FAR * png_dsortp; 137 typedef png_dsort FAR * png_dsortp;
138 typedef png_dsort FAR * FAR * png_dsortpp; 138 typedef png_dsort FAR * FAR * png_dsortpp;
139 139
140 void PNGAPI 140 void PNGAPI
141 png_set_dither(png_structp png_ptr, png_colorp palette, 141 png_set_dither(png_structp png_ptr, png_colorp palette,
142 int num_palette, int maximum_colors, png_uint_16p histogram, 142 int num_palette, int maximum_colors, png_uint_16p histogram,
143 int full_dither) 143 int full_dither)
144 { 144 {
145 png_debug(1, "in png_set_dither\n"); 145 png_debug(1, "in png_set_dither\n");
146 if(png_ptr == NULL) return; 146 if (png_ptr == NULL) return;
147 png_ptr->transformations |= PNG_DITHER; 147 png_ptr->transformations |= PNG_DITHER;
148 148
149 if (!full_dither) 149 if (!full_dither)
150 { 150 {
151 int i; 151 int i;
152 152
153 png_ptr->dither_index = (png_bytep)png_malloc(png_ptr, 153 png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
154 (png_uint_32)(num_palette * png_sizeof (png_byte))); 154 (png_uint_32)(num_palette * png_sizeof(png_byte)));
155 for (i = 0; i < num_palette; i++) 155 for (i = 0; i < num_palette; i++)
156 png_ptr->dither_index[i] = (png_byte)i; 156 png_ptr->dither_index[i] = (png_byte)i;
157 } 157 }
158 158
159 if (num_palette > maximum_colors) 159 if (num_palette > maximum_colors)
160 { 160 {
161 if (histogram != NULL) 161 if (histogram != NULL)
162 { 162 {
163 /* This is easy enough, just throw out the least used colors. 163 /* This is easy enough, just throw out the least used colors.
164 Perhaps not the best solution, but good enough. */ 164 Perhaps not the best solution, but good enough. */
165 165
166 int i; 166 int i;
167 167
168 /* initialize an array to sort colors */ 168 /* initialize an array to sort colors */
169 png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr, 169 png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
170 (png_uint_32)(num_palette * png_sizeof (png_byte))); 170 (png_uint_32)(num_palette * png_sizeof(png_byte)));
171 171
172 /* initialize the dither_sort array */ 172 /* initialize the dither_sort array */
173 for (i = 0; i < num_palette; i++) 173 for (i = 0; i < num_palette; i++)
174 png_ptr->dither_sort[i] = (png_byte)i; 174 png_ptr->dither_sort[i] = (png_byte)i;
175 175
176 /* Find the least used palette entries by starting a 176 /* Find the least used palette entries by starting a
177 bubble sort, and running it until we have sorted 177 bubble sort, and running it until we have sorted
178 out enough colors. Note that we don't care about 178 out enough colors. Note that we don't care about
179 sorting all the colors, just finding which are 179 sorting all the colors, just finding which are
180 least used. */ 180 least used. */
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 min_d = d; 267 min_d = d;
268 min_k = k; 268 min_k = k;
269 } 269 }
270 } 270 }
271 /* point to closest color */ 271 /* point to closest color */
272 png_ptr->dither_index[i] = (png_byte)min_k; 272 png_ptr->dither_index[i] = (png_byte)min_k;
273 } 273 }
274 } 274 }
275 } 275 }
276 png_free(png_ptr, png_ptr->dither_sort); 276 png_free(png_ptr, png_ptr->dither_sort);
277 png_ptr->dither_sort=NULL; 277 png_ptr->dither_sort = NULL;
278 } 278 }
279 else 279 else
280 { 280 {
281 /* This is much harder to do simply (and quickly). Perhaps 281 /* This is much harder to do simply (and quickly). Perhaps
282 we need to go through a median cut routine, but those 282 we need to go through a median cut routine, but those
283 don't always behave themselves with only a few colors 283 don't always behave themselves with only a few colors
284 as input. So we will just find the closest two colors, 284 as input. So we will just find the closest two colors,
285 and throw out one of them (chosen somewhat randomly). 285 and throw out one of them (chosen somewhat randomly).
286 [We don't understand this at all, so if someone wants to 286 [We don't understand this at all, so if someone wants to
287 work on improving it, be our guest - AED, GRP] 287 work on improving it, be our guest - AED, GRP]
288 */ 288 */
289 int i; 289 int i;
290 int max_d; 290 int max_d;
291 int num_new_palette; 291 int num_new_palette;
292 png_dsortp t; 292 png_dsortp t;
293 png_dsortpp hash; 293 png_dsortpp hash;
294 294
295 t=NULL; 295 t = NULL;
296 296
297 /* initialize palette index arrays */ 297 /* initialize palette index arrays */
298 png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr, 298 png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
299 (png_uint_32)(num_palette * png_sizeof (png_byte))); 299 (png_uint_32)(num_palette * png_sizeof(png_byte)));
300 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, 300 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
301 (png_uint_32)(num_palette * png_sizeof (png_byte))); 301 (png_uint_32)(num_palette * png_sizeof(png_byte)));
302 302
303 /* initialize the sort array */ 303 /* initialize the sort array */
304 for (i = 0; i < num_palette; i++) 304 for (i = 0; i < num_palette; i++)
305 { 305 {
306 png_ptr->index_to_palette[i] = (png_byte)i; 306 png_ptr->index_to_palette[i] = (png_byte)i;
307 png_ptr->palette_to_index[i] = (png_byte)i; 307 png_ptr->palette_to_index[i] = (png_byte)i;
308 } 308 }
309 309
310 hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 * 310 hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
311 png_sizeof (png_dsortp))); 311 png_sizeof(png_dsortp)));
312 for (i = 0; i < 769; i++) 312 for (i = 0; i < 769; i++)
313 hash[i] = NULL; 313 hash[i] = NULL;
314 /* png_memset(hash, 0, 769 * png_sizeof (png_dsortp)); */ 314 /* png_memset(hash, 0, 769 * png_sizeof(png_dsortp)); */
315 315
316 num_new_palette = num_palette; 316 num_new_palette = num_palette;
317 317
318 /* initial wild guess at how far apart the farthest pixel 318 /* initial wild guess at how far apart the farthest pixel
319 pair we will be eliminating will be. Larger 319 pair we will be eliminating will be. Larger
320 numbers mean more areas will be allocated, Smaller 320 numbers mean more areas will be allocated, Smaller
321 numbers run the risk of not saving enough data, and 321 numbers run the risk of not saving enough data, and
322 having to do this all over again. 322 having to do this all over again.
323 323
324 I have not done extensive checking on this number. 324 I have not done extensive checking on this number.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 p = t; 429 p = t;
430 } 430 }
431 } 431 }
432 hash[i] = 0; 432 hash[i] = 0;
433 } 433 }
434 max_d += 96; 434 max_d += 96;
435 } 435 }
436 png_free(png_ptr, hash); 436 png_free(png_ptr, hash);
437 png_free(png_ptr, png_ptr->palette_to_index); 437 png_free(png_ptr, png_ptr->palette_to_index);
438 png_free(png_ptr, png_ptr->index_to_palette); 438 png_free(png_ptr, png_ptr->index_to_palette);
439 png_ptr->palette_to_index=NULL; 439 png_ptr->palette_to_index = NULL;
440 png_ptr->index_to_palette=NULL; 440 png_ptr->index_to_palette = NULL;
441 } 441 }
442 num_palette = maximum_colors; 442 num_palette = maximum_colors;
443 } 443 }
444 if (png_ptr->palette == NULL) 444 if (png_ptr->palette == NULL)
445 { 445 {
446 png_ptr->palette = palette; 446 png_ptr->palette = palette;
447 } 447 }
448 png_ptr->num_palette = (png_uint_16)num_palette; 448 png_ptr->num_palette = (png_uint_16)num_palette;
449 449
450 if (full_dither) 450 if (full_dither)
451 { 451 {
452 int i; 452 int i;
453 png_bytep distance; 453 png_bytep distance;
454 int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS + 454 int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
455 PNG_DITHER_BLUE_BITS; 455 PNG_DITHER_BLUE_BITS;
456 int num_red = (1 << PNG_DITHER_RED_BITS); 456 int num_red = (1 << PNG_DITHER_RED_BITS);
457 int num_green = (1 << PNG_DITHER_GREEN_BITS); 457 int num_green = (1 << PNG_DITHER_GREEN_BITS);
458 int num_blue = (1 << PNG_DITHER_BLUE_BITS); 458 int num_blue = (1 << PNG_DITHER_BLUE_BITS);
459 png_size_t num_entries = ((png_size_t)1 << total_bits); 459 png_size_t num_entries = ((png_size_t)1 << total_bits);
460 460
461 png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr, 461 png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
462 (png_uint_32)(num_entries * png_sizeof (png_byte))); 462 (png_uint_32)(num_entries * png_sizeof(png_byte)));
463 463
464 png_memset(png_ptr->palette_lookup, 0, num_entries * 464 png_memset(png_ptr->palette_lookup, 0, num_entries *
465 png_sizeof (png_byte)); 465 png_sizeof(png_byte));
466 466
467 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * 467 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
468 png_sizeof(png_byte))); 468 png_sizeof(png_byte)));
469 469
470 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); 470 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
471 471
472 for (i = 0; i < num_palette; i++) 472 for (i = 0; i < num_palette; i++)
473 { 473 {
474 int ir, ig, ib; 474 int ir, ig, ib;
475 int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); 475 int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 * also needlessly introduces small errors. 520 * also needlessly introduces small errors.
521 * 521 *
522 * We will turn off gamma transformation later if no semitransparent entries 522 * We will turn off gamma transformation later if no semitransparent entries
523 * are present in the tRNS array for palette images. We can't do it here 523 * are present in the tRNS array for palette images. We can't do it here
524 * because we don't necessarily have the tRNS chunk yet. 524 * because we don't necessarily have the tRNS chunk yet.
525 */ 525 */
526 void PNGAPI 526 void PNGAPI
527 png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) 527 png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
528 { 528 {
529 png_debug(1, "in png_set_gamma\n"); 529 png_debug(1, "in png_set_gamma\n");
530 if(png_ptr == NULL) return; 530 if (png_ptr == NULL) return;
531 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || 531 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
532 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || 532 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
533 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) 533 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
534 png_ptr->transformations |= PNG_GAMMA; 534 png_ptr->transformations |= PNG_GAMMA;
535 png_ptr->gamma = (float)file_gamma; 535 png_ptr->gamma = (float)file_gamma;
536 png_ptr->screen_gamma = (float)scrn_gamma; 536 png_ptr->screen_gamma = (float)scrn_gamma;
537 } 537 }
538 #endif 538 #endif
539 539
540 #if defined(PNG_READ_EXPAND_SUPPORTED) 540 #if defined(PNG_READ_EXPAND_SUPPORTED)
541 /* Expand paletted images to RGB, expand grayscale images of 541 /* Expand paletted images to RGB, expand grayscale images of
542 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks 542 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
543 * to alpha channels. 543 * to alpha channels.
544 */ 544 */
545 void PNGAPI 545 void PNGAPI
546 png_set_expand(png_structp png_ptr) 546 png_set_expand(png_structp png_ptr)
547 { 547 {
548 png_debug(1, "in png_set_expand\n"); 548 png_debug(1, "in png_set_expand\n");
549 if(png_ptr == NULL) return; 549 if (png_ptr == NULL) return;
550 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 550 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
551 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; 551 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
552 } 552 }
553 553
554 /* GRR 19990627: the following three functions currently are identical 554 /* GRR 19990627: the following three functions currently are identical
555 * to png_set_expand(). However, it is entirely reasonable that someone 555 * to png_set_expand(). However, it is entirely reasonable that someone
556 * might wish to expand an indexed image to RGB but *not* expand a single, 556 * might wish to expand an indexed image to RGB but *not* expand a single,
557 * fully transparent palette entry to a full alpha channel--perhaps instead 557 * fully transparent palette entry to a full alpha channel--perhaps instead
558 * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace 558 * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace
559 * the transparent color with a particular RGB value, or drop tRNS entirely. 559 * the transparent color with a particular RGB value, or drop tRNS entirely.
560 * IOW, a future version of the library may make the transformations flag 560 * IOW, a future version of the library may make the transformations flag
561 * a bit more fine-grained, with separate bits for each of these three 561 * a bit more fine-grained, with separate bits for each of these three
562 * functions. 562 * functions.
563 * 563 *
564 * More to the point, these functions make it obvious what libpng will be 564 * More to the point, these functions make it obvious what libpng will be
565 * doing, whereas "expand" can (and does) mean any number of things. 565 * doing, whereas "expand" can (and does) mean any number of things.
566 * 566 *
567 * GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified 567 * GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified
568 * to expand only the sample depth but not to expand the tRNS to alpha. 568 * to expand only the sample depth but not to expand the tRNS to alpha.
569 */ 569 */
570 570
571 /* Expand paletted images to RGB. */ 571 /* Expand paletted images to RGB. */
572 void PNGAPI 572 void PNGAPI
573 png_set_palette_to_rgb(png_structp png_ptr) 573 png_set_palette_to_rgb(png_structp png_ptr)
574 { 574 {
575 png_debug(1, "in png_set_palette_to_rgb\n"); 575 png_debug(1, "in png_set_palette_to_rgb\n");
576 if(png_ptr == NULL) return; 576 if (png_ptr == NULL) return;
577 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 577 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
578 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; 578 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
579 } 579 }
580 580
581 #if !defined(PNG_1_0_X) 581 #if !defined(PNG_1_0_X)
582 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ 582 /* Expand grayscale images of less than 8-bit depth to 8 bits. */
583 void PNGAPI 583 void PNGAPI
584 png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) 584 png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
585 { 585 {
586 png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n"); 586 png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
587 if(png_ptr == NULL) return; 587 if (png_ptr == NULL) return;
588 png_ptr->transformations |= PNG_EXPAND; 588 png_ptr->transformations |= PNG_EXPAND;
589 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; 589 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
590 } 590 }
591 #endif 591 #endif
592 592
593 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) 593 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
594 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ 594 /* Expand grayscale images of less than 8-bit depth to 8 bits. */
595 /* Deprecated as of libpng-1.2.9 */ 595 /* Deprecated as of libpng-1.2.9 */
596 void PNGAPI 596 void PNGAPI
597 png_set_gray_1_2_4_to_8(png_structp png_ptr) 597 png_set_gray_1_2_4_to_8(png_structp png_ptr)
598 { 598 {
599 png_debug(1, "in png_set_gray_1_2_4_to_8\n"); 599 png_debug(1, "in png_set_gray_1_2_4_to_8\n");
600 if(png_ptr == NULL) return; 600 if (png_ptr == NULL) return;
601 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); 601 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
602 } 602 }
603 #endif 603 #endif
604 604
605 605
606 /* Expand tRNS chunks to alpha channels. */ 606 /* Expand tRNS chunks to alpha channels. */
607 void PNGAPI 607 void PNGAPI
608 png_set_tRNS_to_alpha(png_structp png_ptr) 608 png_set_tRNS_to_alpha(png_structp png_ptr)
609 { 609 {
610 png_debug(1, "in png_set_tRNS_to_alpha\n"); 610 png_debug(1, "in png_set_tRNS_to_alpha\n");
(...skipping 17 matching lines...) Expand all
628 /* Convert a RGB image to a grayscale of the same width. This allows us, 628 /* Convert a RGB image to a grayscale of the same width. This allows us,
629 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. 629 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
630 */ 630 */
631 631
632 void PNGAPI 632 void PNGAPI
633 png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, 633 png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
634 double green) 634 double green)
635 { 635 {
636 int red_fixed = (int)((float)red*100000.0 + 0.5); 636 int red_fixed = (int)((float)red*100000.0 + 0.5);
637 int green_fixed = (int)((float)green*100000.0 + 0.5); 637 int green_fixed = (int)((float)green*100000.0 + 0.5);
638 if(png_ptr == NULL) return; 638 if (png_ptr == NULL) return;
639 png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); 639 png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
640 } 640 }
641 #endif 641 #endif
642 642
643 void PNGAPI 643 void PNGAPI
644 png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, 644 png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
645 png_fixed_point red, png_fixed_point green) 645 png_fixed_point red, png_fixed_point green)
646 { 646 {
647 png_debug(1, "in png_set_rgb_to_gray\n"); 647 png_debug(1, "in png_set_rgb_to_gray\n");
648 if(png_ptr == NULL) return; 648 if (png_ptr == NULL) return;
649 switch(error_action) 649 switch(error_action)
650 { 650 {
651 case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; 651 case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
652 break; 652 break;
653 case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; 653 case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
654 break; 654 break;
655 case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; 655 case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
656 } 656 }
657 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 657 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
658 #if defined(PNG_READ_EXPAND_SUPPORTED) 658 #if defined(PNG_READ_EXPAND_SUPPORTED)
659 png_ptr->transformations |= PNG_EXPAND; 659 png_ptr->transformations |= PNG_EXPAND;
660 #else 660 #else
661 { 661 {
662 png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); 662 png_warning(png_ptr,
663 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
663 png_ptr->transformations &= ~PNG_RGB_TO_GRAY; 664 png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
664 } 665 }
665 #endif 666 #endif
666 { 667 {
667 png_uint_16 red_int, green_int; 668 png_uint_16 red_int, green_int;
668 if(red < 0 || green < 0) 669 if (red < 0 || green < 0)
669 { 670 {
670 red_int = 6968; /* .212671 * 32768 + .5 */ 671 red_int = 6968; /* .212671 * 32768 + .5 */
671 green_int = 23434; /* .715160 * 32768 + .5 */ 672 green_int = 23434; /* .715160 * 32768 + .5 */
672 } 673 }
673 else if(red + green < 100000L) 674 else if (red + green < 100000L)
674 { 675 {
675 red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L); 676 red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
676 green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L); 677 green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
677 } 678 }
678 else 679 else
679 { 680 {
680 png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); 681 png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
681 red_int = 6968; 682 red_int = 6968;
682 green_int = 23434; 683 green_int = 23434;
683 } 684 }
684 png_ptr->rgb_to_gray_red_coeff = red_int; 685 png_ptr->rgb_to_gray_red_coeff = red_int;
685 png_ptr->rgb_to_gray_green_coeff = green_int; 686 png_ptr->rgb_to_gray_green_coeff = green_int;
686 png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int); 687 png_ptr->rgb_to_gray_blue_coeff =
688 (png_uint_16)(32768 - red_int - green_int);
687 } 689 }
688 } 690 }
689 #endif 691 #endif
690 692
691 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ 693 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
692 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ 694 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
693 defined(PNG_LEGACY_SUPPORTED) 695 defined(PNG_LEGACY_SUPPORTED)
694 void PNGAPI 696 void PNGAPI
695 png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr 697 png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
696 read_user_transform_fn) 698 read_user_transform_fn)
697 { 699 {
698 png_debug(1, "in png_set_read_user_transform_fn\n"); 700 png_debug(1, "in png_set_read_user_transform_fn\n");
699 if(png_ptr == NULL) return; 701 if (png_ptr == NULL) return;
700 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 702 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
701 png_ptr->transformations |= PNG_USER_TRANSFORM; 703 png_ptr->transformations |= PNG_USER_TRANSFORM;
702 png_ptr->read_user_transform_fn = read_user_transform_fn; 704 png_ptr->read_user_transform_fn = read_user_transform_fn;
703 #endif 705 #endif
704 #ifdef PNG_LEGACY_SUPPORTED 706 #ifdef PNG_LEGACY_SUPPORTED
705 if(read_user_transform_fn) 707 if (read_user_transform_fn)
706 png_warning(png_ptr, 708 png_warning(png_ptr,
707 "This version of libpng does not support user transforms"); 709 "This version of libpng does not support user transforms");
708 #endif 710 #endif
709 } 711 }
710 #endif 712 #endif
711 713
712 /* Initialize everything needed for the read. This includes modifying 714 /* Initialize everything needed for the read. This includes modifying
713 * the palette. 715 * the palette.
714 */ 716 */
715 void /* PRIVATE */ 717 void /* PRIVATE */
716 png_init_read_transformations(png_structp png_ptr) 718 png_init_read_transformations(png_structp png_ptr)
717 { 719 {
718 png_debug(1, "in png_init_read_transformations\n"); 720 png_debug(1, "in png_init_read_transformations\n");
719 #if defined(PNG_USELESS_TESTS_SUPPORTED) 721 #if defined(PNG_USELESS_TESTS_SUPPORTED)
720 if(png_ptr != NULL) 722 if (png_ptr != NULL)
721 #endif 723 #endif
722 { 724 {
723 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \ 725 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
724 || defined(PNG_READ_GAMMA_SUPPORTED) 726 || defined(PNG_READ_GAMMA_SUPPORTED)
725 int color_type = png_ptr->color_type; 727 int color_type = png_ptr->color_type;
726 #endif 728 #endif
727 729
728 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) 730 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
729 731
730 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 732 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 813
812 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) 814 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
813 if (png_ptr->transformations & PNG_INVERT_ALPHA) 815 if (png_ptr->transformations & PNG_INVERT_ALPHA)
814 { 816 {
815 #if defined(PNG_READ_EXPAND_SUPPORTED) 817 #if defined(PNG_READ_EXPAND_SUPPORTED)
816 if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) 818 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
817 #endif 819 #endif
818 { 820 {
819 /* invert the alpha channel (in tRNS) unless the pixels are 821 /* invert the alpha channel (in tRNS) unless the pixels are
820 going to be expanded, in which case leave it for later */ 822 going to be expanded, in which case leave it for later */
821 int i,istop; 823 int i, istop;
822 istop=(int)png_ptr->num_trans; 824 istop=(int)png_ptr->num_trans;
823 for (i=0; i<istop; i++) 825 for (i=0; i<istop; i++)
824 png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]); 826 png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
825 } 827 }
826 } 828 }
827 #endif 829 #endif
828 830
829 } 831 }
830 } 832 }
831 #endif 833 #endif
832 834
833 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) 835 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
834 png_ptr->background_1 = png_ptr->background; 836 png_ptr->background_1 = png_ptr->background;
835 #endif 837 #endif
836 #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) 838 #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
837 839
838 if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0) 840 if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
839 && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0) 841 && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
840 < PNG_GAMMA_THRESHOLD)) 842 < PNG_GAMMA_THRESHOLD))
841 { 843 {
842 int i,k; 844 int i, k;
843 k=0; 845 k=0;
844 for (i=0; i<png_ptr->num_trans; i++) 846 for (i=0; i<png_ptr->num_trans; i++)
845 { 847 {
846 if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff) 848 if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
847 k=1; /* partial transparency is present */ 849 k=1; /* partial transparency is present */
848 } 850 }
849 if (k == 0) 851 if (k == 0)
850 png_ptr->transformations &= ~PNG_GAMMA; 852 png_ptr->transformations &= ~PNG_GAMMA;
851 } 853 }
852 854
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 { 1105 {
1104 png_ptr->palette[i].red >>= sr; 1106 png_ptr->palette[i].red >>= sr;
1105 png_ptr->palette[i].green >>= sg; 1107 png_ptr->palette[i].green >>= sg;
1106 png_ptr->palette[i].blue >>= sb; 1108 png_ptr->palette[i].blue >>= sb;
1107 } 1109 }
1108 } 1110 }
1109 #endif /* PNG_READ_SHIFT_SUPPORTED */ 1111 #endif /* PNG_READ_SHIFT_SUPPORTED */
1110 } 1112 }
1111 #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \ 1113 #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
1112 && !defined(PNG_READ_BACKGROUND_SUPPORTED) 1114 && !defined(PNG_READ_BACKGROUND_SUPPORTED)
1113 if(png_ptr) 1115 if (png_ptr)
1114 return; 1116 return;
1115 #endif 1117 #endif
1116 } 1118 }
1117 1119
1118 /* Modify the info structure to reflect the transformations. The 1120 /* Modify the info structure to reflect the transformations. The
1119 * info should be updated so a PNG file could be written with it, 1121 * info should be updated so a PNG file could be written with it,
1120 * assuming the transformations result in valid PNG data. 1122 * assuming the transformations result in valid PNG data.
1121 */ 1123 */
1122 void /* PRIVATE */ 1124 void /* PRIVATE */
1123 png_read_transform_info(png_structp png_ptr, png_infop info_ptr) 1125 png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 /* if adding a true alpha channel not just filler */ 1234 /* if adding a true alpha channel not just filler */
1233 #if !defined(PNG_1_0_X) 1235 #if !defined(PNG_1_0_X)
1234 if (png_ptr->transformations & PNG_ADD_ALPHA) 1236 if (png_ptr->transformations & PNG_ADD_ALPHA)
1235 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; 1237 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
1236 #endif 1238 #endif
1237 } 1239 }
1238 #endif 1240 #endif
1239 1241
1240 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ 1242 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
1241 defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 1243 defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1242 if(png_ptr->transformations & PNG_USER_TRANSFORM) 1244 if (png_ptr->transformations & PNG_USER_TRANSFORM)
1243 { 1245 {
1244 if(info_ptr->bit_depth < png_ptr->user_transform_depth) 1246 if (info_ptr->bit_depth < png_ptr->user_transform_depth)
1245 info_ptr->bit_depth = png_ptr->user_transform_depth; 1247 info_ptr->bit_depth = png_ptr->user_transform_depth;
1246 if(info_ptr->channels < png_ptr->user_transform_channels) 1248 if (info_ptr->channels < png_ptr->user_transform_channels)
1247 info_ptr->channels = png_ptr->user_transform_channels; 1249 info_ptr->channels = png_ptr->user_transform_channels;
1248 } 1250 }
1249 #endif 1251 #endif
1250 1252
1251 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * 1253 info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
1252 info_ptr->bit_depth); 1254 info_ptr->bit_depth);
1253 1255
1254 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width); 1256 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
1255 1257
1256 #if !defined(PNG_READ_EXPAND_SUPPORTED) 1258 #if !defined(PNG_READ_EXPAND_SUPPORTED)
1257 if(png_ptr) 1259 if (png_ptr)
1258 return; 1260 return;
1259 #endif 1261 #endif
1260 } 1262 }
1261 1263
1262 /* Transform the row. The order of transformations is significant, 1264 /* Transform the row. The order of transformations is significant,
1263 * and is very touchy. If you add a transformation, take care to 1265 * and is very touchy. If you add a transformation, take care to
1264 * decide how it fits in with the other transformations here. 1266 * decide how it fits in with the other transformations here.
1265 */ 1267 */
1266 void /* PRIVATE */ 1268 void /* PRIVATE */
1267 png_do_read_transformations(png_structp png_ptr) 1269 png_do_read_transformations(png_structp png_ptr)
1268 { 1270 {
1269 png_debug(1, "in png_do_read_transformations\n"); 1271 png_debug(1, "in png_do_read_transformations\n");
1270 if (png_ptr->row_buf == NULL) 1272 if (png_ptr->row_buf == NULL)
1271 { 1273 {
1272 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 1274 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
1273 char msg[50]; 1275 char msg[50];
1274 1276
1275 png_snprintf2(msg, 50, 1277 png_snprintf2(msg, 50,
1276 "NULL row buffer for row %ld, pass %d", png_ptr->row_number, 1278 "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number,
1277 png_ptr->pass); 1279 png_ptr->pass);
1278 png_error(png_ptr, msg); 1280 png_error(png_ptr, msg);
1279 #else 1281 #else
1280 png_error(png_ptr, "NULL row buffer"); 1282 png_error(png_ptr, "NULL row buffer");
1281 #endif 1283 #endif
1282 } 1284 }
1283 #ifdef PNG_WARN_UNINITIALIZED_ROW 1285 #ifdef PNG_WARN_UNINITIALIZED_ROW
1284 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) 1286 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
1285 /* Application has failed to call either png_read_start_image() 1287 /* Application has failed to call either png_read_start_image()
1286 * or png_read_update_info() after setting transforms that expand 1288 * or png_read_update_info() after setting transforms that expand
(...skipping 30 matching lines...) Expand all
1317 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) 1319 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
1318 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, 1320 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
1319 PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)); 1321 PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
1320 #endif 1322 #endif
1321 1323
1322 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 1324 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
1323 if (png_ptr->transformations & PNG_RGB_TO_GRAY) 1325 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
1324 { 1326 {
1325 int rgb_error = 1327 int rgb_error =
1326 png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1) ; 1328 png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1) ;
1327 if(rgb_error) 1329 if (rgb_error)
1328 { 1330 {
1329 png_ptr->rgb_to_gray_status=1; 1331 png_ptr->rgb_to_gray_status=1;
1330 if((png_ptr->transformations & PNG_RGB_TO_GRAY) == 1332 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
1331 PNG_RGB_TO_GRAY_WARN) 1333 PNG_RGB_TO_GRAY_WARN)
1332 png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); 1334 png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
1333 if((png_ptr->transformations & PNG_RGB_TO_GRAY) == 1335 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
1334 PNG_RGB_TO_GRAY_ERR) 1336 PNG_RGB_TO_GRAY_ERR)
1335 png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); 1337 png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
1336 } 1338 }
1337 } 1339 }
1338 #endif 1340 #endif
1339 1341
1340 /* 1342 /*
1341 From Andreas Dilger e-mail to png-implement, 26 March 1998: 1343 From Andreas Dilger e-mail to png-implement, 26 March 1998:
1342 1344
1343 In most cases, the "simple transparency" should be done prior to doing 1345 In most cases, the "simple transparency" should be done prior to doing
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 #if defined(PNG_READ_16_TO_8_SUPPORTED) 1409 #if defined(PNG_READ_16_TO_8_SUPPORTED)
1408 if (png_ptr->transformations & PNG_16_TO_8) 1410 if (png_ptr->transformations & PNG_16_TO_8)
1409 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); 1411 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
1410 #endif 1412 #endif
1411 1413
1412 #if defined(PNG_READ_DITHER_SUPPORTED) 1414 #if defined(PNG_READ_DITHER_SUPPORTED)
1413 if (png_ptr->transformations & PNG_DITHER) 1415 if (png_ptr->transformations & PNG_DITHER)
1414 { 1416 {
1415 png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1, 1417 png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
1416 png_ptr->palette_lookup, png_ptr->dither_index); 1418 png_ptr->palette_lookup, png_ptr->dither_index);
1417 if(png_ptr->row_info.rowbytes == (png_uint_32)0) 1419 if (png_ptr->row_info.rowbytes == (png_uint_32)0)
1418 png_error(png_ptr, "png_do_dither returned rowbytes=0"); 1420 png_error(png_ptr, "png_do_dither returned rowbytes=0");
1419 } 1421 }
1420 #endif 1422 #endif
1421 1423
1422 #if defined(PNG_READ_INVERT_SUPPORTED) 1424 #if defined(PNG_READ_INVERT_SUPPORTED)
1423 if (png_ptr->transformations & PNG_INVERT_MONO) 1425 if (png_ptr->transformations & PNG_INVERT_MONO)
1424 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); 1426 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
1425 #endif 1427 #endif
1426 1428
1427 #if defined(PNG_READ_SHIFT_SUPPORTED) 1429 #if defined(PNG_READ_SHIFT_SUPPORTED)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 #endif 1471 #endif
1470 1472
1471 #if defined(PNG_READ_SWAP_SUPPORTED) 1473 #if defined(PNG_READ_SWAP_SUPPORTED)
1472 if (png_ptr->transformations & PNG_SWAP_BYTES) 1474 if (png_ptr->transformations & PNG_SWAP_BYTES)
1473 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); 1475 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
1474 #endif 1476 #endif
1475 1477
1476 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 1478 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1477 if (png_ptr->transformations & PNG_USER_TRANSFORM) 1479 if (png_ptr->transformations & PNG_USER_TRANSFORM)
1478 { 1480 {
1479 if(png_ptr->read_user_transform_fn != NULL) 1481 if (png_ptr->read_user_transform_fn != NULL)
1480 (*(png_ptr->read_user_transform_fn)) /* user read transform function */ 1482 (*(png_ptr->read_user_transform_fn)) /* user read transform function */
1481 (png_ptr, /* png_ptr */ 1483 (png_ptr, /* png_ptr */
1482 &(png_ptr->row_info), /* row_info: */ 1484 &(png_ptr->row_info), /* row_info: */
1483 /* png_uint_32 width; width of row */ 1485 /* png_uint_32 width; width of row */
1484 /* png_uint_32 rowbytes; number of bytes in row */ 1486 /* png_uint_32 rowbytes; number of bytes in row */
1485 /* png_byte color_type; color type of pixels */ 1487 /* png_byte color_type; color type of pixels */
1486 /* png_byte bit_depth; bit depth of samples */ 1488 /* png_byte bit_depth; bit depth of samples */
1487 /* png_byte channels; number of channels (1-4) */ 1489 /* png_byte channels; number of channels (1-4) */
1488 /* png_byte pixel_depth; bits per pixel (depth*channels) */ 1490 /* png_byte pixel_depth; bits per pixel (depth*channels) */
1489 png_ptr->row_buf + 1); /* start of pixel data for row */ 1491 png_ptr->row_buf + 1); /* start of pixel data for row */
1490 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) 1492 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
1491 if(png_ptr->user_transform_depth) 1493 if (png_ptr->user_transform_depth)
1492 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; 1494 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
1493 if(png_ptr->user_transform_channels) 1495 if (png_ptr->user_transform_channels)
1494 png_ptr->row_info.channels = png_ptr->user_transform_channels; 1496 png_ptr->row_info.channels = png_ptr->user_transform_channels;
1495 #endif 1497 #endif
1496 png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * 1498 png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
1497 png_ptr->row_info.channels); 1499 png_ptr->row_info.channels);
1498 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, 1500 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
1499 png_ptr->row_info.width); 1501 png_ptr->row_info.width);
1500 } 1502 }
1501 #endif 1503 #endif
1502 1504
1503 } 1505 }
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 png_byte hi_filler = (png_byte)((filler>>8) & 0xff); 1962 png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
1961 png_byte lo_filler = (png_byte)(filler & 0xff); 1963 png_byte lo_filler = (png_byte)(filler & 0xff);
1962 1964
1963 png_debug(1, "in png_do_read_filler\n"); 1965 png_debug(1, "in png_do_read_filler\n");
1964 if ( 1966 if (
1965 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1967 #if defined(PNG_USELESS_TESTS_SUPPORTED)
1966 row != NULL && row_info != NULL && 1968 row != NULL && row_info != NULL &&
1967 #endif 1969 #endif
1968 row_info->color_type == PNG_COLOR_TYPE_GRAY) 1970 row_info->color_type == PNG_COLOR_TYPE_GRAY)
1969 { 1971 {
1970 if(row_info->bit_depth == 8) 1972 if (row_info->bit_depth == 8)
1971 { 1973 {
1972 /* This changes the data from G to GX */ 1974 /* This changes the data from G to GX */
1973 if (flags & PNG_FLAG_FILLER_AFTER) 1975 if (flags & PNG_FLAG_FILLER_AFTER)
1974 { 1976 {
1975 png_bytep sp = row + (png_size_t)row_width; 1977 png_bytep sp = row + (png_size_t)row_width;
1976 png_bytep dp = sp + (png_size_t)row_width; 1978 png_bytep dp = sp + (png_size_t)row_width;
1977 for (i = 1; i < row_width; i++) 1979 for (i = 1; i < row_width; i++)
1978 { 1980 {
1979 *(--dp) = lo_filler; 1981 *(--dp) = lo_filler;
1980 *(--dp) = *(--sp); 1982 *(--dp) = *(--sp);
(...skipping 11 matching lines...) Expand all
1992 for (i = 0; i < row_width; i++) 1994 for (i = 0; i < row_width; i++)
1993 { 1995 {
1994 *(--dp) = *(--sp); 1996 *(--dp) = *(--sp);
1995 *(--dp) = lo_filler; 1997 *(--dp) = lo_filler;
1996 } 1998 }
1997 row_info->channels = 2; 1999 row_info->channels = 2;
1998 row_info->pixel_depth = 16; 2000 row_info->pixel_depth = 16;
1999 row_info->rowbytes = row_width * 2; 2001 row_info->rowbytes = row_width * 2;
2000 } 2002 }
2001 } 2003 }
2002 else if(row_info->bit_depth == 16) 2004 else if (row_info->bit_depth == 16)
2003 { 2005 {
2004 /* This changes the data from GG to GGXX */ 2006 /* This changes the data from GG to GGXX */
2005 if (flags & PNG_FLAG_FILLER_AFTER) 2007 if (flags & PNG_FLAG_FILLER_AFTER)
2006 { 2008 {
2007 png_bytep sp = row + (png_size_t)row_width * 2; 2009 png_bytep sp = row + (png_size_t)row_width * 2;
2008 png_bytep dp = sp + (png_size_t)row_width * 2; 2010 png_bytep dp = sp + (png_size_t)row_width * 2;
2009 for (i = 1; i < row_width; i++) 2011 for (i = 1; i < row_width; i++)
2010 { 2012 {
2011 *(--dp) = hi_filler; 2013 *(--dp) = hi_filler;
2012 *(--dp) = lo_filler; 2014 *(--dp) = lo_filler;
(...skipping 19 matching lines...) Expand all
2032 *(--dp) = lo_filler; 2034 *(--dp) = lo_filler;
2033 } 2035 }
2034 row_info->channels = 2; 2036 row_info->channels = 2;
2035 row_info->pixel_depth = 32; 2037 row_info->pixel_depth = 32;
2036 row_info->rowbytes = row_width * 4; 2038 row_info->rowbytes = row_width * 4;
2037 } 2039 }
2038 } 2040 }
2039 } /* COLOR_TYPE == GRAY */ 2041 } /* COLOR_TYPE == GRAY */
2040 else if (row_info->color_type == PNG_COLOR_TYPE_RGB) 2042 else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
2041 { 2043 {
2042 if(row_info->bit_depth == 8) 2044 if (row_info->bit_depth == 8)
2043 { 2045 {
2044 /* This changes the data from RGB to RGBX */ 2046 /* This changes the data from RGB to RGBX */
2045 if (flags & PNG_FLAG_FILLER_AFTER) 2047 if (flags & PNG_FLAG_FILLER_AFTER)
2046 { 2048 {
2047 png_bytep sp = row + (png_size_t)row_width * 3; 2049 png_bytep sp = row + (png_size_t)row_width * 3;
2048 png_bytep dp = sp + (png_size_t)row_width; 2050 png_bytep dp = sp + (png_size_t)row_width;
2049 for (i = 1; i < row_width; i++) 2051 for (i = 1; i < row_width; i++)
2050 { 2052 {
2051 *(--dp) = lo_filler; 2053 *(--dp) = lo_filler;
2052 *(--dp) = *(--sp); 2054 *(--dp) = *(--sp);
(...skipping 15 matching lines...) Expand all
2068 *(--dp) = *(--sp); 2070 *(--dp) = *(--sp);
2069 *(--dp) = *(--sp); 2071 *(--dp) = *(--sp);
2070 *(--dp) = *(--sp); 2072 *(--dp) = *(--sp);
2071 *(--dp) = lo_filler; 2073 *(--dp) = lo_filler;
2072 } 2074 }
2073 row_info->channels = 4; 2075 row_info->channels = 4;
2074 row_info->pixel_depth = 32; 2076 row_info->pixel_depth = 32;
2075 row_info->rowbytes = row_width * 4; 2077 row_info->rowbytes = row_width * 4;
2076 } 2078 }
2077 } 2079 }
2078 else if(row_info->bit_depth == 16) 2080 else if (row_info->bit_depth == 16)
2079 { 2081 {
2080 /* This changes the data from RRGGBB to RRGGBBXX */ 2082 /* This changes the data from RRGGBB to RRGGBBXX */
2081 if (flags & PNG_FLAG_FILLER_AFTER) 2083 if (flags & PNG_FLAG_FILLER_AFTER)
2082 { 2084 {
2083 png_bytep sp = row + (png_size_t)row_width * 6; 2085 png_bytep sp = row + (png_size_t)row_width * 6;
2084 png_bytep dp = sp + (png_size_t)row_width * 2; 2086 png_bytep dp = sp + (png_size_t)row_width * 2;
2085 for (i = 1; i < row_width; i++) 2087 for (i = 1; i < row_width; i++)
2086 { 2088 {
2087 *(--dp) = hi_filler; 2089 *(--dp) = hi_filler;
2088 *(--dp) = lo_filler; 2090 *(--dp) = lo_filler;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2195 *(dp--) = *(sp - 1); 2197 *(dp--) = *(sp - 1);
2196 *(dp--) = *(sp--); 2198 *(dp--) = *(sp--);
2197 *(dp--) = *(sp--); 2199 *(dp--) = *(sp--);
2198 } 2200 }
2199 } 2201 }
2200 } 2202 }
2201 row_info->channels += (png_byte)2; 2203 row_info->channels += (png_byte)2;
2202 row_info->color_type |= PNG_COLOR_MASK_COLOR; 2204 row_info->color_type |= PNG_COLOR_MASK_COLOR;
2203 row_info->pixel_depth = (png_byte)(row_info->channels * 2205 row_info->pixel_depth = (png_byte)(row_info->channels *
2204 row_info->bit_depth); 2206 row_info->bit_depth);
2205 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 2207 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2206 } 2208 }
2207 } 2209 }
2208 #endif 2210 #endif
2209 2211
2210 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 2212 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
2211 /* reduce RGB files to grayscale, with or without alpha 2213 /* reduce RGB files to grayscale, with or without alpha
2212 * using the equation given in Poynton's ColorFAQ at 2214 * using the equation given in Poynton's ColorFAQ at
2213 * <http://www.inforamp.net/~poynton/> 2215 * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008)
2214 * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net 2216 * New link:
2217 * <http://www.poynton.com/notes/colour_and_gamma/>
2218 * Charles Poynton poynton at poynton.com
2215 * 2219 *
2216 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B 2220 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
2217 * 2221 *
2218 * We approximate this with 2222 * We approximate this with
2219 * 2223 *
2220 * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B 2224 * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
2221 * 2225 *
2222 * which can be expressed with integers as 2226 * which can be expressed with integers as
2223 * 2227 *
2224 * Y = (6969 * R + 23434 * G + 2365 * B)/32768 2228 * Y = (6969 * R + 23434 * G + 2365 * B)/32768
(...skipping 30 matching lines...) Expand all
2255 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) 2259 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2256 { 2260 {
2257 png_bytep sp = row; 2261 png_bytep sp = row;
2258 png_bytep dp = row; 2262 png_bytep dp = row;
2259 2263
2260 for (i = 0; i < row_width; i++) 2264 for (i = 0; i < row_width; i++)
2261 { 2265 {
2262 png_byte red = png_ptr->gamma_to_1[*(sp++)]; 2266 png_byte red = png_ptr->gamma_to_1[*(sp++)];
2263 png_byte green = png_ptr->gamma_to_1[*(sp++)]; 2267 png_byte green = png_ptr->gamma_to_1[*(sp++)];
2264 png_byte blue = png_ptr->gamma_to_1[*(sp++)]; 2268 png_byte blue = png_ptr->gamma_to_1[*(sp++)];
2265 if(red != green || red != blue) 2269 if (red != green || red != blue)
2266 { 2270 {
2267 rgb_error |= 1; 2271 rgb_error |= 1;
2268 *(dp++) = png_ptr->gamma_from_1[ 2272 *(dp++) = png_ptr->gamma_from_1[
2269 (rc*red+gc*green+bc*blue)>>15]; 2273 (rc*red + gc*green + bc*blue)>>15];
2270 } 2274 }
2271 else 2275 else
2272 *(dp++) = *(sp-1); 2276 *(dp++) = *(sp - 1);
2273 } 2277 }
2274 } 2278 }
2275 else 2279 else
2276 #endif 2280 #endif
2277 { 2281 {
2278 png_bytep sp = row; 2282 png_bytep sp = row;
2279 png_bytep dp = row; 2283 png_bytep dp = row;
2280 for (i = 0; i < row_width; i++) 2284 for (i = 0; i < row_width; i++)
2281 { 2285 {
2282 png_byte red = *(sp++); 2286 png_byte red = *(sp++);
2283 png_byte green = *(sp++); 2287 png_byte green = *(sp++);
2284 png_byte blue = *(sp++); 2288 png_byte blue = *(sp++);
2285 if(red != green || red != blue) 2289 if (red != green || red != blue)
2286 { 2290 {
2287 rgb_error |= 1; 2291 rgb_error |= 1;
2288 *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15); 2292 *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
2289 } 2293 }
2290 else 2294 else
2291 *(dp++) = *(sp-1); 2295 *(dp++) = *(sp - 1);
2292 } 2296 }
2293 } 2297 }
2294 } 2298 }
2295 2299
2296 else /* RGB bit_depth == 16 */ 2300 else /* RGB bit_depth == 16 */
2297 { 2301 {
2298 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2302 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
2299 if (png_ptr->gamma_16_to_1 != NULL && 2303 if (png_ptr->gamma_16_to_1 != NULL &&
2300 png_ptr->gamma_16_from_1 != NULL) 2304 png_ptr->gamma_16_from_1 != NULL)
2301 { 2305 {
2302 png_bytep sp = row; 2306 png_bytep sp = row;
2303 png_bytep dp = row; 2307 png_bytep dp = row;
2304 for (i = 0; i < row_width; i++) 2308 for (i = 0; i < row_width; i++)
2305 { 2309 {
2306 png_uint_16 red, green, blue, w; 2310 png_uint_16 red, green, blue, w;
2307 2311
2308 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2312 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2309 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2313 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2310 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2314 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2311 2315
2312 if(red == green && red == blue) 2316 if (red == green && red == blue)
2313 w = red; 2317 w = red;
2314 else 2318 else
2315 { 2319 {
2316 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> 2320 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
2317 png_ptr->gamma_shift][red>>8]; 2321 png_ptr->gamma_shift][red>>8];
2318 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) > > 2322 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) > >
2319 png_ptr->gamma_shift][green>>8]; 2323 png_ptr->gamma_shift][green>>8];
2320 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> 2324 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
2321 png_ptr->gamma_shift][blue>>8]; 2325 png_ptr->gamma_shift][blue>>8];
2322 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 2326 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
(...skipping 13 matching lines...) Expand all
2336 png_bytep sp = row; 2340 png_bytep sp = row;
2337 png_bytep dp = row; 2341 png_bytep dp = row;
2338 for (i = 0; i < row_width; i++) 2342 for (i = 0; i < row_width; i++)
2339 { 2343 {
2340 png_uint_16 red, green, blue, gray16; 2344 png_uint_16 red, green, blue, gray16;
2341 2345
2342 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2346 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2343 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2347 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2344 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2348 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2345 2349
2346 if(red != green || red != blue) 2350 if (red != green || red != blue)
2347 rgb_error |= 1; 2351 rgb_error |= 1;
2348 gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); 2352 gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
2349 *(dp++) = (png_byte)((gray16>>8) & 0xff); 2353 *(dp++) = (png_byte)((gray16>>8) & 0xff);
2350 *(dp++) = (png_byte)(gray16 & 0xff); 2354 *(dp++) = (png_byte)(gray16 & 0xff);
2351 } 2355 }
2352 } 2356 }
2353 } 2357 }
2354 } 2358 }
2355 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) 2359 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
2356 { 2360 {
2357 if (row_info->bit_depth == 8) 2361 if (row_info->bit_depth == 8)
2358 { 2362 {
2359 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2363 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
2360 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL) 2364 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2361 { 2365 {
2362 png_bytep sp = row; 2366 png_bytep sp = row;
2363 png_bytep dp = row; 2367 png_bytep dp = row;
2364 for (i = 0; i < row_width; i++) 2368 for (i = 0; i < row_width; i++)
2365 { 2369 {
2366 png_byte red = png_ptr->gamma_to_1[*(sp++)]; 2370 png_byte red = png_ptr->gamma_to_1[*(sp++)];
2367 png_byte green = png_ptr->gamma_to_1[*(sp++)]; 2371 png_byte green = png_ptr->gamma_to_1[*(sp++)];
2368 png_byte blue = png_ptr->gamma_to_1[*(sp++)]; 2372 png_byte blue = png_ptr->gamma_to_1[*(sp++)];
2369 if(red != green || red != blue) 2373 if (red != green || red != blue)
2370 rgb_error |= 1; 2374 rgb_error |= 1;
2371 *(dp++) = png_ptr->gamma_from_1 2375 *(dp++) = png_ptr->gamma_from_1
2372 [(rc*red + gc*green + bc*blue)>>15]; 2376 [(rc*red + gc*green + bc*blue)>>15];
2373 *(dp++) = *(sp++); /* alpha */ 2377 *(dp++) = *(sp++); /* alpha */
2374 } 2378 }
2375 } 2379 }
2376 else 2380 else
2377 #endif 2381 #endif
2378 { 2382 {
2379 png_bytep sp = row; 2383 png_bytep sp = row;
2380 png_bytep dp = row; 2384 png_bytep dp = row;
2381 for (i = 0; i < row_width; i++) 2385 for (i = 0; i < row_width; i++)
2382 { 2386 {
2383 png_byte red = *(sp++); 2387 png_byte red = *(sp++);
2384 png_byte green = *(sp++); 2388 png_byte green = *(sp++);
2385 png_byte blue = *(sp++); 2389 png_byte blue = *(sp++);
2386 if(red != green || red != blue) 2390 if (red != green || red != blue)
2387 rgb_error |= 1; 2391 rgb_error |= 1;
2388 *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15); 2392 *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
2389 *(dp++) = *(sp++); /* alpha */ 2393 *(dp++) = *(sp++); /* alpha */
2390 } 2394 }
2391 } 2395 }
2392 } 2396 }
2393 else /* RGBA bit_depth == 16 */ 2397 else /* RGBA bit_depth == 16 */
2394 { 2398 {
2395 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2399 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
2396 if (png_ptr->gamma_16_to_1 != NULL && 2400 if (png_ptr->gamma_16_to_1 != NULL &&
2397 png_ptr->gamma_16_from_1 != NULL) 2401 png_ptr->gamma_16_from_1 != NULL)
2398 { 2402 {
2399 png_bytep sp = row; 2403 png_bytep sp = row;
2400 png_bytep dp = row; 2404 png_bytep dp = row;
2401 for (i = 0; i < row_width; i++) 2405 for (i = 0; i < row_width; i++)
2402 { 2406 {
2403 png_uint_16 red, green, blue, w; 2407 png_uint_16 red, green, blue, w;
2404 2408
2405 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2409 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2406 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2410 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2407 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; 2411 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2408 2412
2409 if(red == green && red == blue) 2413 if (red == green && red == blue)
2410 w = red; 2414 w = red;
2411 else 2415 else
2412 { 2416 {
2413 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> 2417 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
2414 png_ptr->gamma_shift][red>>8]; 2418 png_ptr->gamma_shift][red>>8];
2415 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) > > 2419 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) > >
2416 png_ptr->gamma_shift][green>>8]; 2420 png_ptr->gamma_shift][green>>8];
2417 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> 2421 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
2418 png_ptr->gamma_shift][blue>>8]; 2422 png_ptr->gamma_shift][blue>>8];
2419 png_uint_16 gray16 = (png_uint_16)((rc * red_1 2423 png_uint_16 gray16 = (png_uint_16)((rc * red_1
(...skipping 13 matching lines...) Expand all
2433 #endif 2437 #endif
2434 { 2438 {
2435 png_bytep sp = row; 2439 png_bytep sp = row;
2436 png_bytep dp = row; 2440 png_bytep dp = row;
2437 for (i = 0; i < row_width; i++) 2441 for (i = 0; i < row_width; i++)
2438 { 2442 {
2439 png_uint_16 red, green, blue, gray16; 2443 png_uint_16 red, green, blue, gray16;
2440 red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; 2444 red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
2441 green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; 2445 green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
2442 blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; 2446 blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
2443 if(red != green || red != blue) 2447 if (red != green || red != blue)
2444 rgb_error |= 1; 2448 rgb_error |= 1;
2445 gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15); 2449 gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
2446 *(dp++) = (png_byte)((gray16>>8) & 0xff); 2450 *(dp++) = (png_byte)((gray16>>8) & 0xff);
2447 *(dp++) = (png_byte)(gray16 & 0xff); 2451 *(dp++) = (png_byte)(gray16 & 0xff);
2448 *(dp++) = *(sp++); /* alpha */ 2452 *(dp++) = *(sp++); /* alpha */
2449 *(dp++) = *(sp++); 2453 *(dp++) = *(sp++);
2450 } 2454 }
2451 } 2455 }
2452 } 2456 }
2453 } 2457 }
2454 row_info->channels -= (png_byte)2; 2458 row_info->channels -= (png_byte)2;
2455 row_info->color_type &= ~PNG_COLOR_MASK_COLOR; 2459 row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
2456 row_info->pixel_depth = (png_byte)(row_info->channels * 2460 row_info->pixel_depth = (png_byte)(row_info->channels *
2457 row_info->bit_depth); 2461 row_info->bit_depth);
2458 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 2462 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2459 } 2463 }
2460 return rgb_error; 2464 return rgb_error;
2461 } 2465 }
2462 #endif 2466 #endif
2463 2467
2464 /* Build a grayscale palette. Palette is assumed to be 1 << bit_depth 2468 /* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
2465 * large of png_color. This lets grayscale images be treated as 2469 * large of png_color. This lets grayscale images be treated as
2466 * paletted. Most useful for gamma correction and simplification 2470 * paletted. Most useful for gamma correction and simplification
2467 * of code. 2471 * of code.
2468 */ 2472 */
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
3366 break; 3370 break;
3367 } 3371 }
3368 } 3372 }
3369 3373
3370 if (row_info->color_type & PNG_COLOR_MASK_ALPHA) 3374 if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
3371 { 3375 {
3372 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; 3376 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
3373 row_info->channels--; 3377 row_info->channels--;
3374 row_info->pixel_depth = (png_byte)(row_info->channels * 3378 row_info->pixel_depth = (png_byte)(row_info->channels *
3375 row_info->bit_depth); 3379 row_info->bit_depth);
3376 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 3380 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3377 } 3381 }
3378 } 3382 }
3379 } 3383 }
3380 #endif 3384 #endif
3381 3385
3382 #if defined(PNG_READ_GAMMA_SUPPORTED) 3386 #if defined(PNG_READ_GAMMA_SUPPORTED)
3383 /* Gamma correct the image, avoiding the alpha channel. Make sure 3387 /* Gamma correct the image, avoiding the alpha channel. Make sure
3384 * you do this after you deal with the transparency issue on grayscale 3388 * you do this after you deal with the transparency issue on grayscale
3385 * or RGB images. If your bit depth is 8, use gamma_table, if it 3389 * or RGB images. If your bit depth is 8, use gamma_table, if it
3386 * is 16, use gamma_16_table and gamma_shift. Build these with 3390 * is 16, use gamma_16_table and gamma_shift. Build these with
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3825 } 3829 }
3826 } 3830 }
3827 else if (row_info->bit_depth == 16) 3831 else if (row_info->bit_depth == 16)
3828 { 3832 {
3829 png_byte gray_high = (gray >> 8) & 0xff; 3833 png_byte gray_high = (gray >> 8) & 0xff;
3830 png_byte gray_low = gray & 0xff; 3834 png_byte gray_low = gray & 0xff;
3831 sp = row + row_info->rowbytes - 1; 3835 sp = row + row_info->rowbytes - 1;
3832 dp = row + (row_info->rowbytes << 1) - 1; 3836 dp = row + (row_info->rowbytes << 1) - 1;
3833 for (i = 0; i < row_width; i++) 3837 for (i = 0; i < row_width; i++)
3834 { 3838 {
3835 if (*(sp-1) == gray_high && *(sp) == gray_low) 3839 if (*(sp - 1) == gray_high && *(sp) == gray_low)
3836 { 3840 {
3837 *dp-- = 0; 3841 *dp-- = 0;
3838 *dp-- = 0; 3842 *dp-- = 0;
3839 } 3843 }
3840 else 3844 else
3841 { 3845 {
3842 *dp-- = 0xff; 3846 *dp-- = 0xff;
3843 *dp-- = 0xff; 3847 *dp-- = 0xff;
3844 } 3848 }
3845 *dp-- = *sp--; 3849 *dp-- = *sp--;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 *dp-- = *sp--; 3908 *dp-- = *sp--;
3905 *dp-- = *sp--; 3909 *dp-- = *sp--;
3906 *dp-- = *sp--; 3910 *dp-- = *sp--;
3907 *dp-- = *sp--; 3911 *dp-- = *sp--;
3908 *dp-- = *sp--; 3912 *dp-- = *sp--;
3909 } 3913 }
3910 } 3914 }
3911 row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; 3915 row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
3912 row_info->channels = 4; 3916 row_info->channels = 4;
3913 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); 3917 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
3914 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 3918 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3915 } 3919 }
3916 } 3920 }
3917 } 3921 }
3918 #endif 3922 #endif
3919 3923
3920 #if defined(PNG_READ_DITHER_SUPPORTED) 3924 #if defined(PNG_READ_DITHER_SUPPORTED)
3921 void /* PRIVATE */ 3925 void /* PRIVATE */
3922 png_do_dither(png_row_infop row_info, png_bytep row, 3926 png_do_dither(png_row_infop row_info, png_bytep row,
3923 png_bytep palette_lookup, png_bytep dither_lookup) 3927 png_bytep palette_lookup, png_bytep dither_lookup)
3924 { 3928 {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3957 ((1 << PNG_DITHER_GREEN_BITS) - 1)) << 3961 ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
3958 (PNG_DITHER_BLUE_BITS)) | 3962 (PNG_DITHER_BLUE_BITS)) |
3959 ((b >> (8 - PNG_DITHER_BLUE_BITS)) & 3963 ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
3960 ((1 << PNG_DITHER_BLUE_BITS) - 1)); 3964 ((1 << PNG_DITHER_BLUE_BITS) - 1));
3961 3965
3962 *dp++ = palette_lookup[p]; 3966 *dp++ = palette_lookup[p];
3963 } 3967 }
3964 row_info->color_type = PNG_COLOR_TYPE_PALETTE; 3968 row_info->color_type = PNG_COLOR_TYPE_PALETTE;
3965 row_info->channels = 1; 3969 row_info->channels = 1;
3966 row_info->pixel_depth = row_info->bit_depth; 3970 row_info->pixel_depth = row_info->bit_depth;
3967 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 3971 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3968 } 3972 }
3969 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA && 3973 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
3970 palette_lookup != NULL && row_info->bit_depth == 8) 3974 palette_lookup != NULL && row_info->bit_depth == 8)
3971 { 3975 {
3972 int r, g, b, p; 3976 int r, g, b, p;
3973 sp = row; 3977 sp = row;
3974 dp = row; 3978 dp = row;
3975 for (i = 0; i < row_width; i++) 3979 for (i = 0; i < row_width; i++)
3976 { 3980 {
3977 r = *sp++; 3981 r = *sp++;
3978 g = *sp++; 3982 g = *sp++;
3979 b = *sp++; 3983 b = *sp++;
3980 sp++; 3984 sp++;
3981 3985
3982 p = (((r >> (8 - PNG_DITHER_RED_BITS)) & 3986 p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
3983 ((1 << PNG_DITHER_RED_BITS) - 1)) << 3987 ((1 << PNG_DITHER_RED_BITS) - 1)) <<
3984 (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) | 3988 (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
3985 (((g >> (8 - PNG_DITHER_GREEN_BITS)) & 3989 (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
3986 ((1 << PNG_DITHER_GREEN_BITS) - 1)) << 3990 ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
3987 (PNG_DITHER_BLUE_BITS)) | 3991 (PNG_DITHER_BLUE_BITS)) |
3988 ((b >> (8 - PNG_DITHER_BLUE_BITS)) & 3992 ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
3989 ((1 << PNG_DITHER_BLUE_BITS) - 1)); 3993 ((1 << PNG_DITHER_BLUE_BITS) - 1));
3990 3994
3991 *dp++ = palette_lookup[p]; 3995 *dp++ = palette_lookup[p];
3992 } 3996 }
3993 row_info->color_type = PNG_COLOR_TYPE_PALETTE; 3997 row_info->color_type = PNG_COLOR_TYPE_PALETTE;
3994 row_info->channels = 1; 3998 row_info->channels = 1;
3995 row_info->pixel_depth = row_info->bit_depth; 3999 row_info->pixel_depth = row_info->bit_depth;
3996 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width); 4000 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3997 } 4001 }
3998 else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE && 4002 else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
3999 dither_lookup && row_info->bit_depth == 8) 4003 dither_lookup && row_info->bit_depth == 8)
4000 { 4004 {
4001 sp = row; 4005 sp = row;
4002 for (i = 0; i < row_width; i++, sp++) 4006 for (i = 0; i < row_width; i++, sp++)
4003 { 4007 {
4004 *sp = dither_lookup[*sp]; 4008 *sp = dither_lookup[*sp];
4005 } 4009 }
4006 } 4010 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
4055 for (i = 0; i < 256; i++) 4059 for (i = 0; i < 256; i++)
4056 { 4060 {
4057 png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0, 4061 png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
4058 g) * 255.0 + .5); 4062 g) * 255.0 + .5);
4059 } 4063 }
4060 4064
4061 4065
4062 png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr, 4066 png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
4063 (png_uint_32)256); 4067 (png_uint_32)256);
4064 4068
4065 if(png_ptr->screen_gamma > 0.000001) 4069 if (png_ptr->screen_gamma > 0.000001)
4066 g = 1.0 / png_ptr->screen_gamma; 4070 g = 1.0 / png_ptr->screen_gamma;
4067 else 4071 else
4068 g = png_ptr->gamma; /* probably doing rgb_to_gray */ 4072 g = png_ptr->gamma; /* probably doing rgb_to_gray */
4069 4073
4070 for (i = 0; i < 256; i++) 4074 for (i = 0; i < 256; i++)
4071 { 4075 {
4072 png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0, 4076 png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
4073 g) * 255.0 + .5); 4077 g) * 255.0 + .5);
4074 4078
4075 } 4079 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4115 png_ptr->gamma_shift = (png_byte)shift; 4119 png_ptr->gamma_shift = (png_byte)shift;
4116 4120
4117 num = (1 << (8 - shift)); 4121 num = (1 << (8 - shift));
4118 4122
4119 if (png_ptr->screen_gamma > .000001) 4123 if (png_ptr->screen_gamma > .000001)
4120 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); 4124 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
4121 else 4125 else
4122 g = 1.0; 4126 g = 1.0;
4123 4127
4124 png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr, 4128 png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
4125 (png_uint_32)(num * png_sizeof (png_uint_16p))); 4129 (png_uint_32)(num * png_sizeof(png_uint_16p)));
4126 4130
4127 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) 4131 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
4128 { 4132 {
4129 double fin, fout; 4133 double fin, fout;
4130 png_uint_32 last, max; 4134 png_uint_32 last, max;
4131 4135
4132 for (i = 0; i < num; i++) 4136 for (i = 0; i < num; i++)
4133 { 4137 {
4134 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, 4138 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
4135 (png_uint_32)(256 * png_sizeof (png_uint_16))); 4139 (png_uint_32)(256 * png_sizeof(png_uint_16)));
4136 } 4140 }
4137 4141
4138 g = 1.0 / g; 4142 g = 1.0 / g;
4139 last = 0; 4143 last = 0;
4140 for (i = 0; i < 256; i++) 4144 for (i = 0; i < 256; i++)
4141 { 4145 {
4142 fout = ((double)i + 0.5) / 256.0; 4146 fout = ((double)i + 0.5) / 256.0;
4143 fin = pow(fout, g); 4147 fin = pow(fout, g);
4144 max = (png_uint_32)(fin * (double)((png_uint_32)num << 8)); 4148 max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
4145 while (last <= max) 4149 while (last <= max)
4146 { 4150 {
4147 png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] 4151 png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
4148 [(int)(last >> (8 - shift))] = (png_uint_16)( 4152 [(int)(last >> (8 - shift))] = (png_uint_16)(
4149 (png_uint_16)i | ((png_uint_16)i << 8)); 4153 (png_uint_16)i | ((png_uint_16)i << 8));
4150 last++; 4154 last++;
4151 } 4155 }
4152 } 4156 }
4153 while (last < ((png_uint_32)num << 8)) 4157 while (last < ((png_uint_32)num << 8))
4154 { 4158 {
4155 png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] 4159 png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
4156 [(int)(last >> (8 - shift))] = (png_uint_16)65535L; 4160 [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
4157 last++; 4161 last++;
4158 } 4162 }
4159 } 4163 }
4160 else 4164 else
4161 { 4165 {
4162 for (i = 0; i < num; i++) 4166 for (i = 0; i < num; i++)
4163 { 4167 {
4164 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, 4168 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
4165 (png_uint_32)(256 * png_sizeof (png_uint_16))); 4169 (png_uint_32)(256 * png_sizeof(png_uint_16)));
4166 4170
4167 ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4); 4171 ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
4168 for (j = 0; j < 256; j++) 4172 for (j = 0; j < 256; j++)
4169 { 4173 {
4170 png_ptr->gamma_16_table[i][j] = 4174 png_ptr->gamma_16_table[i][j] =
4171 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / 4175 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
4172 65535.0, g) * 65535.0 + .5); 4176 65535.0, g) * 65535.0 + .5);
4173 } 4177 }
4174 } 4178 }
4175 } 4179 }
4176 4180
4177 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ 4181 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
4178 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 4182 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
4179 if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) 4183 if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
4180 { 4184 {
4181 4185
4182 g = 1.0 / (png_ptr->gamma); 4186 g = 1.0 / (png_ptr->gamma);
4183 4187
4184 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr, 4188 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
4185 (png_uint_32)(num * png_sizeof (png_uint_16p ))); 4189 (png_uint_32)(num * png_sizeof(png_uint_16p )));
4186 4190
4187 for (i = 0; i < num; i++) 4191 for (i = 0; i < num; i++)
4188 { 4192 {
4189 png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, 4193 png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
4190 (png_uint_32)(256 * png_sizeof (png_uint_16))); 4194 (png_uint_32)(256 * png_sizeof(png_uint_16)));
4191 4195
4192 ig = (((png_uint_32)i * 4196 ig = (((png_uint_32)i *
4193 (png_uint_32)png_gamma_shift[shift]) >> 4); 4197 (png_uint_32)png_gamma_shift[shift]) >> 4);
4194 for (j = 0; j < 256; j++) 4198 for (j = 0; j < 256; j++)
4195 { 4199 {
4196 png_ptr->gamma_16_to_1[i][j] = 4200 png_ptr->gamma_16_to_1[i][j] =
4197 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / 4201 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
4198 65535.0, g) * 65535.0 + .5); 4202 65535.0, g) * 65535.0 + .5);
4199 } 4203 }
4200 } 4204 }
4201 4205
4202 if(png_ptr->screen_gamma > 0.000001) 4206 if (png_ptr->screen_gamma > 0.000001)
4203 g = 1.0 / png_ptr->screen_gamma; 4207 g = 1.0 / png_ptr->screen_gamma;
4204 else 4208 else
4205 g = png_ptr->gamma; /* probably doing rgb_to_gray */ 4209 g = png_ptr->gamma; /* probably doing rgb_to_gray */
4206 4210
4207 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr, 4211 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
4208 (png_uint_32)(num * png_sizeof (png_uint_16p))); 4212 (png_uint_32)(num * png_sizeof(png_uint_16p)));
4209 4213
4210 for (i = 0; i < num; i++) 4214 for (i = 0; i < num; i++)
4211 { 4215 {
4212 png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, 4216 png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
4213 (png_uint_32)(256 * png_sizeof (png_uint_16))); 4217 (png_uint_32)(256 * png_sizeof(png_uint_16)));
4214 4218
4215 ig = (((png_uint_32)i * 4219 ig = (((png_uint_32)i *
4216 (png_uint_32)png_gamma_shift[shift]) >> 4); 4220 (png_uint_32)png_gamma_shift[shift]) >> 4);
4217 for (j = 0; j < 256; j++) 4221 for (j = 0; j < 256; j++)
4218 { 4222 {
4219 png_ptr->gamma_16_from_1[i][j] = 4223 png_ptr->gamma_16_from_1[i][j] =
4220 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / 4224 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
4221 65535.0, g) * 65535.0 + .5); 4225 65535.0, g) * 65535.0 + .5);
4222 } 4226 }
4223 } 4227 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4268 4272
4269 if (row_info->color_type == PNG_COLOR_TYPE_RGB) 4273 if (row_info->color_type == PNG_COLOR_TYPE_RGB)
4270 bytes_per_pixel = 6; 4274 bytes_per_pixel = 6;
4271 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) 4275 else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
4272 bytes_per_pixel = 8; 4276 bytes_per_pixel = 8;
4273 else 4277 else
4274 return; 4278 return;
4275 4279
4276 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel) 4280 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
4277 { 4281 {
4278 png_uint_32 s0 = (*(rp ) << 8) | *(rp+1); 4282 png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
4279 png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3); 4283 png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
4280 png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5); 4284 png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
4281 png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL); 4285 png_uint_32 red = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL);
4282 png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL); 4286 png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL);
4283 *(rp ) = (png_byte)((red >> 8) & 0xff); 4287 *(rp ) = (png_byte)((red >> 8) & 0xff);
4284 *(rp+1) = (png_byte)(red & 0xff); 4288 *(rp+1) = (png_byte)(red & 0xff);
4285 *(rp+4) = (png_byte)((blue >> 8) & 0xff); 4289 *(rp+4) = (png_byte)((blue >> 8) & 0xff);
4286 *(rp+5) = (png_byte)(blue & 0xff); 4290 *(rp+5) = (png_byte)(blue & 0xff);
4287 } 4291 }
4288 } 4292 }
4289 } 4293 }
4290 } 4294 }
4291 #endif /* PNG_MNG_FEATURES_SUPPORTED */ 4295 #endif /* PNG_MNG_FEATURES_SUPPORTED */
4292 #endif /* PNG_READ_SUPPORTED */ 4296 #endif /* PNG_READ_SUPPORTED */
OLDNEW
« no previous file with comments | « third_party/libpng/pngrio.c ('k') | third_party/libpng/pngrutil.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698