| OLD | NEW |
| 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.37 [June 4, 2009] | 4 * Last changed in libpng 1.2.43 [February 25, 2010] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
| 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
| 9 * | 8 * |
| 9 * This code is released under the libpng license. |
| 10 * For conditions of distribution and use, see the disclaimer |
| 11 * and license in png.h |
| 12 * |
| 10 * This file contains functions optionally called by an application | 13 * This file contains functions optionally called by an application |
| 11 * in order to tell libpng how to handle data when reading a PNG. | 14 * in order to tell libpng how to handle data when reading a PNG. |
| 12 * Transformations that are used in both reading and writing are | 15 * Transformations that are used in both reading and writing are |
| 13 * in pngtrans.c. | 16 * in pngtrans.c. |
| 14 */ | 17 */ |
| 15 | 18 |
| 16 #define PNG_INTERNAL | 19 #define PNG_INTERNAL |
| 20 #define PNG_NO_PEDANTIC_WARNINGS |
| 17 #include "png.h" | 21 #include "png.h" |
| 18 #if defined(PNG_READ_SUPPORTED) | 22 #ifdef PNG_READ_SUPPORTED |
| 19 | 23 |
| 20 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ | 24 /* Set the action on getting a CRC error for an ancillary or critical chunk. */ |
| 21 void PNGAPI | 25 void PNGAPI |
| 22 png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) | 26 png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) |
| 23 { | 27 { |
| 24 png_debug(1, "in png_set_crc_action"); | 28 png_debug(1, "in png_set_crc_action"); |
| 25 /* Tell libpng how we react to CRC errors in critical chunks */ | 29 |
| 26 if (png_ptr == NULL) | 30 if (png_ptr == NULL) |
| 27 return; | 31 return; |
| 32 |
| 33 /* Tell libpng how we react to CRC errors in critical chunks */ |
| 28 switch (crit_action) | 34 switch (crit_action) |
| 29 { | 35 { |
| 30 case PNG_CRC_NO_CHANGE: /* Leave setting as is */ | 36 case PNG_CRC_NO_CHANGE: /* Leave setting as is */ |
| 31 break; | 37 break; |
| 32 | 38 |
| 33 case PNG_CRC_WARN_USE: /* Warn/use data */ | 39 case PNG_CRC_WARN_USE: /* Warn/use data */ |
| 34 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; | 40 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; |
| 35 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; | 41 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE; |
| 36 break; | 42 break; |
| 37 | 43 |
| 38 case PNG_CRC_QUIET_USE: /* Quiet/use data */ | 44 case PNG_CRC_QUIET_USE: /* Quiet/use data */ |
| 39 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; | 45 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; |
| 40 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | | 46 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE | |
| 41 PNG_FLAG_CRC_CRITICAL_IGNORE; | 47 PNG_FLAG_CRC_CRITICAL_IGNORE; |
| 42 break; | 48 break; |
| 43 | 49 |
| 44 case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ | 50 case PNG_CRC_WARN_DISCARD: /* Not a valid action for critical data */ |
| 45 png_warning(png_ptr, | 51 png_warning(png_ptr, |
| 46 "Can't discard critical data on CRC error."); | 52 "Can't discard critical data on CRC error."); |
| 47 case PNG_CRC_ERROR_QUIT: /* Error/quit */ | 53 case PNG_CRC_ERROR_QUIT: /* Error/quit */ |
| 48 | 54 |
| 49 case PNG_CRC_DEFAULT: | 55 case PNG_CRC_DEFAULT: |
| 50 default: | 56 default: |
| 51 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; | 57 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK; |
| 52 break; | 58 break; |
| 53 } | 59 } |
| 54 | 60 |
| 61 /* Tell libpng how we react to CRC errors in ancillary chunks */ |
| 55 switch (ancil_action) | 62 switch (ancil_action) |
| 56 { | 63 { |
| 57 case PNG_CRC_NO_CHANGE: /* Leave setting as is */ | 64 case PNG_CRC_NO_CHANGE: /* Leave setting as is */ |
| 58 break; | 65 break; |
| 59 | 66 |
| 60 case PNG_CRC_WARN_USE: /* Warn/use data */ | 67 case PNG_CRC_WARN_USE: /* Warn/use data */ |
| 61 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; | 68 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK; |
| 62 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; | 69 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE; |
| 63 break; | 70 break; |
| 64 | 71 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 | 91 |
| 85 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ | 92 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ |
| 86 defined(PNG_FLOATING_POINT_SUPPORTED) | 93 defined(PNG_FLOATING_POINT_SUPPORTED) |
| 87 /* Handle alpha and tRNS via a background color */ | 94 /* Handle alpha and tRNS via a background color */ |
| 88 void PNGAPI | 95 void PNGAPI |
| 89 png_set_background(png_structp png_ptr, | 96 png_set_background(png_structp png_ptr, |
| 90 png_color_16p background_color, int background_gamma_code, | 97 png_color_16p background_color, int background_gamma_code, |
| 91 int need_expand, double background_gamma) | 98 int need_expand, double background_gamma) |
| 92 { | 99 { |
| 93 png_debug(1, "in png_set_background"); | 100 png_debug(1, "in png_set_background"); |
| 101 |
| 94 if (png_ptr == NULL) | 102 if (png_ptr == NULL) |
| 95 return; | 103 return; |
| 96 if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) | 104 if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN) |
| 97 { | 105 { |
| 98 png_warning(png_ptr, "Application must supply a known background gamma"); | 106 png_warning(png_ptr, "Application must supply a known background gamma"); |
| 99 return; | 107 return; |
| 100 } | 108 } |
| 101 | 109 |
| 102 png_ptr->transformations |= PNG_BACKGROUND; | 110 png_ptr->transformations |= PNG_BACKGROUND; |
| 103 png_memcpy(&(png_ptr->background), background_color, | 111 png_memcpy(&(png_ptr->background), background_color, |
| 104 png_sizeof(png_color_16)); | 112 png_sizeof(png_color_16)); |
| 105 png_ptr->background_gamma = (float)background_gamma; | 113 png_ptr->background_gamma = (float)background_gamma; |
| 106 png_ptr->background_gamma_type = (png_byte)(background_gamma_code); | 114 png_ptr->background_gamma_type = (png_byte)(background_gamma_code); |
| 107 png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); | 115 png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0); |
| 108 } | 116 } |
| 109 #endif | 117 #endif |
| 110 | 118 |
| 111 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 119 #ifdef PNG_READ_16_TO_8_SUPPORTED |
| 112 /* Strip 16 bit depth files to 8 bit depth */ | 120 /* Strip 16 bit depth files to 8 bit depth */ |
| 113 void PNGAPI | 121 void PNGAPI |
| 114 png_set_strip_16(png_structp png_ptr) | 122 png_set_strip_16(png_structp png_ptr) |
| 115 { | 123 { |
| 116 png_debug(1, "in png_set_strip_16"); | 124 png_debug(1, "in png_set_strip_16"); |
| 125 |
| 117 if (png_ptr == NULL) | 126 if (png_ptr == NULL) |
| 118 return; | 127 return; |
| 119 png_ptr->transformations |= PNG_16_TO_8; | 128 png_ptr->transformations |= PNG_16_TO_8; |
| 120 } | 129 } |
| 121 #endif | 130 #endif |
| 122 | 131 |
| 123 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 132 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
| 124 void PNGAPI | 133 void PNGAPI |
| 125 png_set_strip_alpha(png_structp png_ptr) | 134 png_set_strip_alpha(png_structp png_ptr) |
| 126 { | 135 { |
| 127 png_debug(1, "in png_set_strip_alpha"); | 136 png_debug(1, "in png_set_strip_alpha"); |
| 137 |
| 128 if (png_ptr == NULL) | 138 if (png_ptr == NULL) |
| 129 return; | 139 return; |
| 130 png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; | 140 png_ptr->flags |= PNG_FLAG_STRIP_ALPHA; |
| 131 } | 141 } |
| 132 #endif | 142 #endif |
| 133 | 143 |
| 134 #if defined(PNG_READ_DITHER_SUPPORTED) | 144 #ifdef PNG_READ_DITHER_SUPPORTED |
| 135 /* Dither file to 8 bit. Supply a palette, the current number | 145 /* Dither file to 8 bit. Supply a palette, the current number |
| 136 * of elements in the palette, the maximum number of elements | 146 * of elements in the palette, the maximum number of elements |
| 137 * allowed, and a histogram if possible. If the current number | 147 * allowed, and a histogram if possible. If the current number |
| 138 * of colors is greater then the maximum number, the palette will be | 148 * of colors is greater then the maximum number, the palette will be |
| 139 * modified to fit in the maximum number. "full_dither" indicates | 149 * modified to fit in the maximum number. "full_dither" indicates |
| 140 * whether we need a dithering cube set up for RGB images, or if we | 150 * whether we need a dithering cube set up for RGB images, or if we |
| 141 * simply are reducing the number of colors in a paletted image. | 151 * simply are reducing the number of colors in a paletted image. |
| 142 */ | 152 */ |
| 143 | 153 |
| 144 typedef struct png_dsort_struct | 154 typedef struct png_dsort_struct |
| 145 { | 155 { |
| 146 struct png_dsort_struct FAR * next; | 156 struct png_dsort_struct FAR * next; |
| 147 png_byte left; | 157 png_byte left; |
| 148 png_byte right; | 158 png_byte right; |
| 149 } png_dsort; | 159 } png_dsort; |
| 150 typedef png_dsort FAR * png_dsortp; | 160 typedef png_dsort FAR * png_dsortp; |
| 151 typedef png_dsort FAR * FAR * png_dsortpp; | 161 typedef png_dsort FAR * FAR * png_dsortpp; |
| 152 | 162 |
| 153 void PNGAPI | 163 void PNGAPI |
| 154 png_set_dither(png_structp png_ptr, png_colorp palette, | 164 png_set_dither(png_structp png_ptr, png_colorp palette, |
| 155 int num_palette, int maximum_colors, png_uint_16p histogram, | 165 int num_palette, int maximum_colors, png_uint_16p histogram, |
| 156 int full_dither) | 166 int full_dither) |
| 157 { | 167 { |
| 158 png_debug(1, "in png_set_dither"); | 168 png_debug(1, "in png_set_dither"); |
| 169 |
| 159 if (png_ptr == NULL) | 170 if (png_ptr == NULL) |
| 160 return; | 171 return; |
| 161 png_ptr->transformations |= PNG_DITHER; | 172 png_ptr->transformations |= PNG_DITHER; |
| 162 | 173 |
| 163 if (!full_dither) | 174 if (!full_dither) |
| 164 { | 175 { |
| 165 int i; | 176 int i; |
| 166 | 177 |
| 167 png_ptr->dither_index = (png_bytep)png_malloc(png_ptr, | 178 png_ptr->dither_index = (png_bytep)png_malloc(png_ptr, |
| 168 (png_uint_32)(num_palette * png_sizeof(png_byte))); | 179 (png_uint_32)(num_palette * png_sizeof(png_byte))); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, | 329 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr, |
| 319 (png_uint_32)(num_palette * png_sizeof(png_byte))); | 330 (png_uint_32)(num_palette * png_sizeof(png_byte))); |
| 320 | 331 |
| 321 /* Initialize the sort array */ | 332 /* Initialize the sort array */ |
| 322 for (i = 0; i < num_palette; i++) | 333 for (i = 0; i < num_palette; i++) |
| 323 { | 334 { |
| 324 png_ptr->index_to_palette[i] = (png_byte)i; | 335 png_ptr->index_to_palette[i] = (png_byte)i; |
| 325 png_ptr->palette_to_index[i] = (png_byte)i; | 336 png_ptr->palette_to_index[i] = (png_byte)i; |
| 326 } | 337 } |
| 327 | 338 |
| 328 hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 * | 339 hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 * |
| 329 png_sizeof(png_dsortp))); | 340 png_sizeof(png_dsortp))); |
| 330 png_memset(hash, 0, 769 * png_sizeof(png_dsortp)); | |
| 331 | 341 |
| 332 num_new_palette = num_palette; | 342 num_new_palette = num_palette; |
| 333 | 343 |
| 334 /* Initial wild guess at how far apart the farthest pixel | 344 /* Initial wild guess at how far apart the farthest pixel |
| 335 * pair we will be eliminating will be. Larger | 345 * pair we will be eliminating will be. Larger |
| 336 * numbers mean more areas will be allocated, Smaller | 346 * numbers mean more areas will be allocated, Smaller |
| 337 * numbers run the risk of not saving enough data, and | 347 * numbers run the risk of not saving enough data, and |
| 338 * having to do this all over again. | 348 * having to do this all over again. |
| 339 * | 349 * |
| 340 * I have not done extensive checking on this number. | 350 * I have not done extensive checking on this number. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 png_ptr->dither_index[k] = | 425 png_ptr->dither_index[k] = |
| 416 png_ptr->index_to_palette[j]; | 426 png_ptr->index_to_palette[j]; |
| 417 } | 427 } |
| 418 } | 428 } |
| 419 | 429 |
| 420 png_ptr->index_to_palette[png_ptr->palette_to_index | 430 png_ptr->index_to_palette[png_ptr->palette_to_index |
| 421 [num_new_palette]] = png_ptr->index_to_palette[j]; | 431 [num_new_palette]] = png_ptr->index_to_palette[j]; |
| 422 png_ptr->palette_to_index[png_ptr->index_to_palette[j]] | 432 png_ptr->palette_to_index[png_ptr->index_to_palette[j]] |
| 423 = png_ptr->palette_to_index[num_new_palette]; | 433 = png_ptr->palette_to_index[num_new_palette]; |
| 424 | 434 |
| 425 png_ptr->index_to_palette[j] = (png_byte)num_new_palette
; | 435 png_ptr->index_to_palette[j] = |
| 426 png_ptr->palette_to_index[num_new_palette] = (png_byte)j
; | 436 (png_byte)num_new_palette; |
| 437 png_ptr->palette_to_index[num_new_palette] = |
| 438 (png_byte)j; |
| 427 } | 439 } |
| 428 if (num_new_palette <= maximum_colors) | 440 if (num_new_palette <= maximum_colors) |
| 429 break; | 441 break; |
| 430 } | 442 } |
| 431 if (num_new_palette <= maximum_colors) | 443 if (num_new_palette <= maximum_colors) |
| 432 break; | 444 break; |
| 433 } | 445 } |
| 434 } | 446 } |
| 435 | 447 |
| 436 for (i = 0; i < 769; i++) | 448 for (i = 0; i < 769; i++) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 466 if (full_dither) | 478 if (full_dither) |
| 467 { | 479 { |
| 468 int i; | 480 int i; |
| 469 png_bytep distance; | 481 png_bytep distance; |
| 470 int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS + | 482 int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS + |
| 471 PNG_DITHER_BLUE_BITS; | 483 PNG_DITHER_BLUE_BITS; |
| 472 int num_red = (1 << PNG_DITHER_RED_BITS); | 484 int num_red = (1 << PNG_DITHER_RED_BITS); |
| 473 int num_green = (1 << PNG_DITHER_GREEN_BITS); | 485 int num_green = (1 << PNG_DITHER_GREEN_BITS); |
| 474 int num_blue = (1 << PNG_DITHER_BLUE_BITS); | 486 int num_blue = (1 << PNG_DITHER_BLUE_BITS); |
| 475 png_size_t num_entries = ((png_size_t)1 << total_bits); | 487 png_size_t num_entries = ((png_size_t)1 << total_bits); |
| 476 png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr, | 488 |
| 489 png_ptr->palette_lookup = (png_bytep )png_calloc(png_ptr, |
| 477 (png_uint_32)(num_entries * png_sizeof(png_byte))); | 490 (png_uint_32)(num_entries * png_sizeof(png_byte))); |
| 478 png_memset(png_ptr->palette_lookup, 0, num_entries * | |
| 479 png_sizeof(png_byte)); | |
| 480 | 491 |
| 481 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * | 492 distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries * |
| 482 png_sizeof(png_byte))); | 493 png_sizeof(png_byte))); |
| 483 | |
| 484 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); | 494 png_memset(distance, 0xff, num_entries * png_sizeof(png_byte)); |
| 485 | 495 |
| 486 for (i = 0; i < num_palette; i++) | 496 for (i = 0; i < num_palette; i++) |
| 487 { | 497 { |
| 488 int ir, ig, ib; | 498 int ir, ig, ib; |
| 489 int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); | 499 int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS)); |
| 490 int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS)); | 500 int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS)); |
| 491 int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS)); | 501 int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS)); |
| 492 | 502 |
| 493 for (ir = 0; ir < num_red; ir++) | 503 for (ir = 0; ir < num_red; ir++) |
| 494 { | 504 { |
| 495 /* int dr = abs(ir - r); */ | 505 /* int dr = abs(ir - r); */ |
| 496 int dr = ((ir > r) ? ir - r : r - ir); | 506 int dr = ((ir > r) ? ir - r : r - ir); |
| 497 int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS))
; | 507 int index_r = (ir << (PNG_DITHER_BLUE_BITS + |
| 508 PNG_DITHER_GREEN_BITS)); |
| 498 | 509 |
| 499 for (ig = 0; ig < num_green; ig++) | 510 for (ig = 0; ig < num_green; ig++) |
| 500 { | 511 { |
| 501 /* int dg = abs(ig - g); */ | 512 /* int dg = abs(ig - g); */ |
| 502 int dg = ((ig > g) ? ig - g : g - ig); | 513 int dg = ((ig > g) ? ig - g : g - ig); |
| 503 int dt = dr + dg; | 514 int dt = dr + dg; |
| 504 int dm = ((dr > dg) ? dr : dg); | 515 int dm = ((dr > dg) ? dr : dg); |
| 505 int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS); | 516 int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS); |
| 506 | 517 |
| 507 for (ib = 0; ib < num_blue; ib++) | 518 for (ib = 0; ib < num_blue; ib++) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 534 * also needlessly introduces small errors. | 545 * also needlessly introduces small errors. |
| 535 * | 546 * |
| 536 * We will turn off gamma transformation later if no semitransparent entries | 547 * We will turn off gamma transformation later if no semitransparent entries |
| 537 * are present in the tRNS array for palette images. We can't do it here | 548 * are present in the tRNS array for palette images. We can't do it here |
| 538 * because we don't necessarily have the tRNS chunk yet. | 549 * because we don't necessarily have the tRNS chunk yet. |
| 539 */ | 550 */ |
| 540 void PNGAPI | 551 void PNGAPI |
| 541 png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) | 552 png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) |
| 542 { | 553 { |
| 543 png_debug(1, "in png_set_gamma"); | 554 png_debug(1, "in png_set_gamma"); |
| 555 |
| 544 if (png_ptr == NULL) | 556 if (png_ptr == NULL) |
| 545 return; | 557 return; |
| 558 |
| 546 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || | 559 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) || |
| 547 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || | 560 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) || |
| 548 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) | 561 (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)) |
| 549 png_ptr->transformations |= PNG_GAMMA; | 562 png_ptr->transformations |= PNG_GAMMA; |
| 550 png_ptr->gamma = (float)file_gamma; | 563 png_ptr->gamma = (float)file_gamma; |
| 551 png_ptr->screen_gamma = (float)scrn_gamma; | 564 png_ptr->screen_gamma = (float)scrn_gamma; |
| 552 } | 565 } |
| 553 #endif | 566 #endif |
| 554 | 567 |
| 555 #if defined(PNG_READ_EXPAND_SUPPORTED) | 568 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 556 /* Expand paletted images to RGB, expand grayscale images of | 569 /* Expand paletted images to RGB, expand grayscale images of |
| 557 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks | 570 * less than 8-bit depth to 8-bit depth, and expand tRNS chunks |
| 558 * to alpha channels. | 571 * to alpha channels. |
| 559 */ | 572 */ |
| 560 void PNGAPI | 573 void PNGAPI |
| 561 png_set_expand(png_structp png_ptr) | 574 png_set_expand(png_structp png_ptr) |
| 562 { | 575 { |
| 563 png_debug(1, "in png_set_expand"); | 576 png_debug(1, "in png_set_expand"); |
| 577 |
| 564 if (png_ptr == NULL) | 578 if (png_ptr == NULL) |
| 565 return; | 579 return; |
| 580 |
| 566 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); | 581 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); |
| 567 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; | 582 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; |
| 568 } | 583 } |
| 569 | 584 |
| 570 /* GRR 19990627: the following three functions currently are identical | 585 /* GRR 19990627: the following three functions currently are identical |
| 571 * to png_set_expand(). However, it is entirely reasonable that someone | 586 * to png_set_expand(). However, it is entirely reasonable that someone |
| 572 * might wish to expand an indexed image to RGB but *not* expand a single, | 587 * might wish to expand an indexed image to RGB but *not* expand a single, |
| 573 * fully transparent palette entry to a full alpha channel--perhaps instead | 588 * fully transparent palette entry to a full alpha channel--perhaps instead |
| 574 * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace | 589 * convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace |
| 575 * the transparent color with a particular RGB value, or drop tRNS entirely. | 590 * the transparent color with a particular RGB value, or drop tRNS entirely. |
| 576 * IOW, a future version of the library may make the transformations flag | 591 * IOW, a future version of the library may make the transformations flag |
| 577 * a bit more fine-grained, with separate bits for each of these three | 592 * a bit more fine-grained, with separate bits for each of these three |
| 578 * functions. | 593 * functions. |
| 579 * | 594 * |
| 580 * More to the point, these functions make it obvious what libpng will be | 595 * More to the point, these functions make it obvious what libpng will be |
| 581 * doing, whereas "expand" can (and does) mean any number of things. | 596 * doing, whereas "expand" can (and does) mean any number of things. |
| 582 * | 597 * |
| 583 * GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified | 598 * GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified |
| 584 * to expand only the sample depth but not to expand the tRNS to alpha. | 599 * to expand only the sample depth but not to expand the tRNS to alpha |
| 600 * and its name was changed to png_set_expand_gray_1_2_4_to_8(). |
| 585 */ | 601 */ |
| 586 | 602 |
| 587 /* Expand paletted images to RGB. */ | 603 /* Expand paletted images to RGB. */ |
| 588 void PNGAPI | 604 void PNGAPI |
| 589 png_set_palette_to_rgb(png_structp png_ptr) | 605 png_set_palette_to_rgb(png_structp png_ptr) |
| 590 { | 606 { |
| 591 png_debug(1, "in png_set_palette_to_rgb"); | 607 png_debug(1, "in png_set_palette_to_rgb"); |
| 608 |
| 592 if (png_ptr == NULL) | 609 if (png_ptr == NULL) |
| 593 return; | 610 return; |
| 611 |
| 594 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); | 612 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); |
| 595 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; | 613 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; |
| 596 } | 614 } |
| 597 | 615 |
| 598 #if !defined(PNG_1_0_X) | 616 #ifndef PNG_1_0_X |
| 599 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ | 617 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ |
| 600 void PNGAPI | 618 void PNGAPI |
| 601 png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) | 619 png_set_expand_gray_1_2_4_to_8(png_structp png_ptr) |
| 602 { | 620 { |
| 603 png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); | 621 png_debug(1, "in png_set_expand_gray_1_2_4_to_8"); |
| 622 |
| 604 if (png_ptr == NULL) | 623 if (png_ptr == NULL) |
| 605 return; | 624 return; |
| 625 |
| 606 png_ptr->transformations |= PNG_EXPAND; | 626 png_ptr->transformations |= PNG_EXPAND; |
| 607 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; | 627 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; |
| 608 } | 628 } |
| 609 #endif | 629 #endif |
| 610 | 630 |
| 611 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) | 631 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
| 612 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ | 632 /* Expand grayscale images of less than 8-bit depth to 8 bits. */ |
| 613 /* Deprecated as of libpng-1.2.9 */ | 633 /* Deprecated as of libpng-1.2.9 */ |
| 614 void PNGAPI | 634 void PNGAPI |
| 615 png_set_gray_1_2_4_to_8(png_structp png_ptr) | 635 png_set_gray_1_2_4_to_8(png_structp png_ptr) |
| 616 { | 636 { |
| 617 png_debug(1, "in png_set_gray_1_2_4_to_8"); | 637 png_debug(1, "in png_set_gray_1_2_4_to_8"); |
| 638 |
| 618 if (png_ptr == NULL) | 639 if (png_ptr == NULL) |
| 619 return; | 640 return; |
| 641 |
| 620 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); | 642 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); |
| 621 } | 643 } |
| 622 #endif | 644 #endif |
| 623 | 645 |
| 624 | 646 |
| 625 /* Expand tRNS chunks to alpha channels. */ | 647 /* Expand tRNS chunks to alpha channels. */ |
| 626 void PNGAPI | 648 void PNGAPI |
| 627 png_set_tRNS_to_alpha(png_structp png_ptr) | 649 png_set_tRNS_to_alpha(png_structp png_ptr) |
| 628 { | 650 { |
| 629 png_debug(1, "in png_set_tRNS_to_alpha"); | 651 png_debug(1, "in png_set_tRNS_to_alpha"); |
| 652 |
| 630 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); | 653 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS); |
| 631 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; | 654 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; |
| 632 } | 655 } |
| 633 #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ | 656 #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ |
| 634 | 657 |
| 635 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 658 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 636 void PNGAPI | 659 void PNGAPI |
| 637 png_set_gray_to_rgb(png_structp png_ptr) | 660 png_set_gray_to_rgb(png_structp png_ptr) |
| 638 { | 661 { |
| 639 png_debug(1, "in png_set_gray_to_rgb"); | 662 png_debug(1, "in png_set_gray_to_rgb"); |
| 663 |
| 640 png_ptr->transformations |= PNG_GRAY_TO_RGB; | 664 png_ptr->transformations |= PNG_GRAY_TO_RGB; |
| 641 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; | 665 png_ptr->flags &= ~PNG_FLAG_ROW_INIT; |
| 642 } | 666 } |
| 643 #endif | 667 #endif |
| 644 | 668 |
| 645 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | 669 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
| 646 #if defined(PNG_FLOATING_POINT_SUPPORTED) | 670 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 647 /* Convert a RGB image to a grayscale of the same width. This allows us, | 671 /* Convert a RGB image to a grayscale of the same width. This allows us, |
| 648 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. | 672 * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. |
| 649 */ | 673 */ |
| 650 | 674 |
| 651 void PNGAPI | 675 void PNGAPI |
| 652 png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, | 676 png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, |
| 653 double green) | 677 double green) |
| 654 { | 678 { |
| 655 int red_fixed = (int)((float)red*100000.0 + 0.5); | 679 int red_fixed = (int)((float)red*100000.0 + 0.5); |
| 656 int green_fixed = (int)((float)green*100000.0 + 0.5); | 680 int green_fixed = (int)((float)green*100000.0 + 0.5); |
| 657 if (png_ptr == NULL) | 681 if (png_ptr == NULL) |
| 658 return; | 682 return; |
| 659 png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); | 683 png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed); |
| 660 } | 684 } |
| 661 #endif | 685 #endif |
| 662 | 686 |
| 663 void PNGAPI | 687 void PNGAPI |
| 664 png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, | 688 png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, |
| 665 png_fixed_point red, png_fixed_point green) | 689 png_fixed_point red, png_fixed_point green) |
| 666 { | 690 { |
| 667 png_debug(1, "in png_set_rgb_to_gray"); | 691 png_debug(1, "in png_set_rgb_to_gray"); |
| 692 |
| 668 if (png_ptr == NULL) | 693 if (png_ptr == NULL) |
| 669 return; | 694 return; |
| 695 |
| 670 switch(error_action) | 696 switch(error_action) |
| 671 { | 697 { |
| 672 case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; | 698 case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY; |
| 673 break; | 699 break; |
| 674 | 700 |
| 675 case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; | 701 case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN; |
| 676 break; | 702 break; |
| 677 | 703 |
| 678 case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; | 704 case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR; |
| 679 } | 705 } |
| 680 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 706 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 681 #if defined(PNG_READ_EXPAND_SUPPORTED) | 707 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 682 png_ptr->transformations |= PNG_EXPAND; | 708 png_ptr->transformations |= PNG_EXPAND; |
| 683 #else | 709 #else |
| 684 { | 710 { |
| 685 png_warning(png_ptr, | 711 png_warning(png_ptr, |
| 686 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); | 712 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED."); |
| 687 png_ptr->transformations &= ~PNG_RGB_TO_GRAY; | 713 png_ptr->transformations &= ~PNG_RGB_TO_GRAY; |
| 688 } | 714 } |
| 689 #endif | 715 #endif |
| 690 { | 716 { |
| 691 png_uint_16 red_int, green_int; | 717 png_uint_16 red_int, green_int; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 707 } | 733 } |
| 708 png_ptr->rgb_to_gray_red_coeff = red_int; | 734 png_ptr->rgb_to_gray_red_coeff = red_int; |
| 709 png_ptr->rgb_to_gray_green_coeff = green_int; | 735 png_ptr->rgb_to_gray_green_coeff = green_int; |
| 710 png_ptr->rgb_to_gray_blue_coeff = | 736 png_ptr->rgb_to_gray_blue_coeff = |
| 711 (png_uint_16)(32768 - red_int - green_int); | 737 (png_uint_16)(32768 - red_int - green_int); |
| 712 } | 738 } |
| 713 } | 739 } |
| 714 #endif | 740 #endif |
| 715 | 741 |
| 716 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | 742 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ |
| 717 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ | 743 defined(PNG_LEGACY_SUPPORTED) || \ |
| 718 defined(PNG_LEGACY_SUPPORTED) | 744 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 719 void PNGAPI | 745 void PNGAPI |
| 720 png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr | 746 png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr |
| 721 read_user_transform_fn) | 747 read_user_transform_fn) |
| 722 { | 748 { |
| 723 png_debug(1, "in png_set_read_user_transform_fn"); | 749 png_debug(1, "in png_set_read_user_transform_fn"); |
| 750 |
| 724 if (png_ptr == NULL) | 751 if (png_ptr == NULL) |
| 725 return; | 752 return; |
| 726 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) | 753 |
| 754 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED |
| 727 png_ptr->transformations |= PNG_USER_TRANSFORM; | 755 png_ptr->transformations |= PNG_USER_TRANSFORM; |
| 728 png_ptr->read_user_transform_fn = read_user_transform_fn; | 756 png_ptr->read_user_transform_fn = read_user_transform_fn; |
| 729 #endif | 757 #endif |
| 730 #ifdef PNG_LEGACY_SUPPORTED | 758 #ifdef PNG_LEGACY_SUPPORTED |
| 731 if (read_user_transform_fn) | 759 if (read_user_transform_fn) |
| 732 png_warning(png_ptr, | 760 png_warning(png_ptr, |
| 733 "This version of libpng does not support user transforms"); | 761 "This version of libpng does not support user transforms"); |
| 734 #endif | 762 #endif |
| 735 } | 763 } |
| 736 #endif | 764 #endif |
| 737 | 765 |
| 738 /* Initialize everything needed for the read. This includes modifying | 766 /* Initialize everything needed for the read. This includes modifying |
| 739 * the palette. | 767 * the palette. |
| 740 */ | 768 */ |
| 741 void /* PRIVATE */ | 769 void /* PRIVATE */ |
| 742 png_init_read_transformations(png_structp png_ptr) | 770 png_init_read_transformations(png_structp png_ptr) |
| 743 { | 771 { |
| 744 png_debug(1, "in png_init_read_transformations"); | 772 png_debug(1, "in png_init_read_transformations"); |
| 745 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 773 |
| 746 if (png_ptr != NULL) | 774 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 775 if (png_ptr != NULL) |
| 747 #endif | 776 #endif |
| 748 { | 777 { |
| 749 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED)
\ | 778 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ |
| 750 || defined(PNG_READ_GAMMA_SUPPORTED) | 779 defined(PNG_READ_SHIFT_SUPPORTED) || \ |
| 780 defined(PNG_READ_GAMMA_SUPPORTED) |
| 751 int color_type = png_ptr->color_type; | 781 int color_type = png_ptr->color_type; |
| 752 #endif | 782 #endif |
| 753 | 783 |
| 754 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) | 784 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) |
| 755 | 785 |
| 756 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 786 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 757 /* Detect gray background and attempt to enable optimization | 787 /* Detect gray background and attempt to enable optimization |
| 758 * for gray --> RGB case | 788 * for gray --> RGB case |
| 759 * | 789 * |
| 760 * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or | 790 * Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or |
| 761 * RGB_ALPHA (in which case need_expand is superfluous anyway), the | 791 * RGB_ALPHA (in which case need_expand is superfluous anyway), the |
| 762 * background color might actually be gray yet not be flagged as such. | 792 * background color might actually be gray yet not be flagged as such. |
| 763 * This is not a problem for the current code, which uses | 793 * This is not a problem for the current code, which uses |
| 764 * PNG_BACKGROUND_IS_GRAY only to decide when to do the | 794 * PNG_BACKGROUND_IS_GRAY only to decide when to do the |
| 765 * png_do_gray_to_rgb() transformation. | 795 * png_do_gray_to_rgb() transformation. |
| 766 */ | 796 */ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 863 } |
| 834 else if (color_type == PNG_COLOR_TYPE_PALETTE) | 864 else if (color_type == PNG_COLOR_TYPE_PALETTE) |
| 835 { | 865 { |
| 836 png_ptr->background.red = | 866 png_ptr->background.red = |
| 837 png_ptr->palette[png_ptr->background.index].red; | 867 png_ptr->palette[png_ptr->background.index].red; |
| 838 png_ptr->background.green = | 868 png_ptr->background.green = |
| 839 png_ptr->palette[png_ptr->background.index].green; | 869 png_ptr->palette[png_ptr->background.index].green; |
| 840 png_ptr->background.blue = | 870 png_ptr->background.blue = |
| 841 png_ptr->palette[png_ptr->background.index].blue; | 871 png_ptr->palette[png_ptr->background.index].blue; |
| 842 | 872 |
| 843 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) | 873 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
| 844 if (png_ptr->transformations & PNG_INVERT_ALPHA) | 874 if (png_ptr->transformations & PNG_INVERT_ALPHA) |
| 845 { | 875 { |
| 846 #if defined(PNG_READ_EXPAND_SUPPORTED) | 876 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 847 if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) | 877 if (!(png_ptr->transformations & PNG_EXPAND_tRNS)) |
| 848 #endif | 878 #endif |
| 849 { | 879 { |
| 850 /* Invert the alpha channel (in tRNS) unless the pixels are | 880 /* Invert the alpha channel (in tRNS) unless the pixels are |
| 851 * going to be expanded, in which case leave it for later | 881 * going to be expanded, in which case leave it for later |
| 852 */ | 882 */ |
| 853 int i, istop; | 883 int i, istop; |
| 854 istop=(int)png_ptr->num_trans; | 884 istop=(int)png_ptr->num_trans; |
| 855 for (i=0; i<istop; i++) | 885 for (i=0; i<istop; i++) |
| 856 png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]); | 886 png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 879 k=1; /* Partial transparency is present */ | 909 k=1; /* Partial transparency is present */ |
| 880 } | 910 } |
| 881 if (k == 0) | 911 if (k == 0) |
| 882 png_ptr->transformations &= ~PNG_GAMMA; | 912 png_ptr->transformations &= ~PNG_GAMMA; |
| 883 } | 913 } |
| 884 | 914 |
| 885 if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) && | 915 if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) && |
| 886 png_ptr->gamma != 0.0) | 916 png_ptr->gamma != 0.0) |
| 887 { | 917 { |
| 888 png_build_gamma_table(png_ptr); | 918 png_build_gamma_table(png_ptr); |
| 889 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 919 |
| 920 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 890 if (png_ptr->transformations & PNG_BACKGROUND) | 921 if (png_ptr->transformations & PNG_BACKGROUND) |
| 891 { | 922 { |
| 892 if (color_type == PNG_COLOR_TYPE_PALETTE) | 923 if (color_type == PNG_COLOR_TYPE_PALETTE) |
| 893 { | 924 { |
| 894 /* Could skip if no transparency */ | 925 /* Could skip if no transparency */ |
| 895 png_color back, back_1; | 926 png_color back, back_1; |
| 896 png_colorp palette = png_ptr->palette; | 927 png_colorp palette = png_ptr->palette; |
| 897 int num_palette = png_ptr->num_palette; | 928 int num_palette = png_ptr->num_palette; |
| 898 int i; | 929 int i; |
| 899 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) | 930 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 { | 967 { |
| 937 back.red = (png_byte)png_ptr->background.red; | 968 back.red = (png_byte)png_ptr->background.red; |
| 938 back.green = (png_byte)png_ptr->background.green; | 969 back.green = (png_byte)png_ptr->background.green; |
| 939 back.blue = (png_byte)png_ptr->background.blue; | 970 back.blue = (png_byte)png_ptr->background.blue; |
| 940 } | 971 } |
| 941 else | 972 else |
| 942 { | 973 { |
| 943 back.red = (png_byte)(pow( | 974 back.red = (png_byte)(pow( |
| 944 (double)png_ptr->background.red/255, gs) * 255.0 + .5); | 975 (double)png_ptr->background.red/255, gs) * 255.0 + .5); |
| 945 back.green = (png_byte)(pow( | 976 back.green = (png_byte)(pow( |
| 946 (double)png_ptr->background.green/255, gs) * 255.0 + .5); | 977 (double)png_ptr->background.green/255, gs) * 255.0 |
| 978 + .5); |
| 947 back.blue = (png_byte)(pow( | 979 back.blue = (png_byte)(pow( |
| 948 (double)png_ptr->background.blue/255, gs) * 255.0 + .5); | 980 (double)png_ptr->background.blue/255, gs) * 255.0 + .5); |
| 949 } | 981 } |
| 950 | 982 |
| 951 back_1.red = (png_byte)(pow( | 983 back_1.red = (png_byte)(pow( |
| 952 (double)png_ptr->background.red/255, g) * 255.0 + .5); | 984 (double)png_ptr->background.red/255, g) * 255.0 + .5); |
| 953 back_1.green = (png_byte)(pow( | 985 back_1.green = (png_byte)(pow( |
| 954 (double)png_ptr->background.green/255, g) * 255.0 + .5); | 986 (double)png_ptr->background.green/255, g) * 255.0 + .5); |
| 955 back_1.blue = (png_byte)(pow( | 987 back_1.blue = (png_byte)(pow( |
| 956 (double)png_ptr->background.blue/255, g) * 255.0 + .5); | 988 (double)png_ptr->background.blue/255, g) * 255.0 + .5); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 980 palette[i].blue = png_ptr->gamma_from_1[w]; | 1012 palette[i].blue = png_ptr->gamma_from_1[w]; |
| 981 } | 1013 } |
| 982 } | 1014 } |
| 983 else | 1015 else |
| 984 { | 1016 { |
| 985 palette[i].red = png_ptr->gamma_table[palette[i].red]; | 1017 palette[i].red = png_ptr->gamma_table[palette[i].red]; |
| 986 palette[i].green = png_ptr->gamma_table[palette[i].green]; | 1018 palette[i].green = png_ptr->gamma_table[palette[i].green]; |
| 987 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; | 1019 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; |
| 988 } | 1020 } |
| 989 } | 1021 } |
| 990 » /* Prevent the transformations being done again, and make sure | 1022 /* Prevent the transformations being done again, and make sure |
| 991 » * that the now spurious alpha channel is stripped - the code | 1023 * that the now spurious alpha channel is stripped - the code |
| 992 » * has just reduced background composition and gamma correction | 1024 * has just reduced background composition and gamma correction |
| 993 » * to a simple alpha channel strip. | 1025 * to a simple alpha channel strip. |
| 994 » */ | 1026 */ |
| 995 » png_ptr->transformations &= ~PNG_BACKGROUND; | 1027 png_ptr->transformations &= ~PNG_BACKGROUND; |
| 996 » png_ptr->transformations &= ~PNG_GAMMA; | 1028 png_ptr->transformations &= ~PNG_GAMMA; |
| 997 » png_ptr->transformations |= PNG_STRIP_ALPHA; | 1029 png_ptr->transformations |= PNG_STRIP_ALPHA; |
| 998 } | 1030 } |
| 999 /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ | 1031 /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */ |
| 1000 else | 1032 else |
| 1001 /* color_type != PNG_COLOR_TYPE_PALETTE */ | 1033 /* color_type != PNG_COLOR_TYPE_PALETTE */ |
| 1002 { | 1034 { |
| 1003 double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1); | 1035 double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1); |
| 1004 double g = 1.0; | 1036 double g = 1.0; |
| 1005 double gs = 1.0; | 1037 double gs = 1.0; |
| 1006 | 1038 |
| 1007 switch (png_ptr->background_gamma_type) | 1039 switch (png_ptr->background_gamma_type) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 int num_palette = png_ptr->num_palette; | 1097 int num_palette = png_ptr->num_palette; |
| 1066 int i; | 1098 int i; |
| 1067 | 1099 |
| 1068 for (i = 0; i < num_palette; i++) | 1100 for (i = 0; i < num_palette; i++) |
| 1069 { | 1101 { |
| 1070 palette[i].red = png_ptr->gamma_table[palette[i].red]; | 1102 palette[i].red = png_ptr->gamma_table[palette[i].red]; |
| 1071 palette[i].green = png_ptr->gamma_table[palette[i].green]; | 1103 palette[i].green = png_ptr->gamma_table[palette[i].green]; |
| 1072 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; | 1104 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; |
| 1073 } | 1105 } |
| 1074 | 1106 |
| 1075 » /* Done the gamma correction. */ | 1107 /* Done the gamma correction. */ |
| 1076 » png_ptr->transformations &= ~PNG_GAMMA; | 1108 png_ptr->transformations &= ~PNG_GAMMA; |
| 1077 } | 1109 } |
| 1078 } | 1110 } |
| 1079 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1111 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 1080 else | 1112 else |
| 1081 #endif | 1113 #endif |
| 1082 #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */ | 1114 #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */ |
| 1083 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1115 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 1084 /* No GAMMA transformation */ | 1116 /* No GAMMA transformation */ |
| 1085 if ((png_ptr->transformations & PNG_BACKGROUND) && | 1117 if ((png_ptr->transformations & PNG_BACKGROUND) && |
| 1086 (color_type == PNG_COLOR_TYPE_PALETTE)) | 1118 (color_type == PNG_COLOR_TYPE_PALETTE)) |
| 1087 { | 1119 { |
| 1088 int i; | 1120 int i; |
| 1089 int istop = (int)png_ptr->num_trans; | 1121 int istop = (int)png_ptr->num_trans; |
| 1090 png_color back; | 1122 png_color back; |
| 1091 png_colorp palette = png_ptr->palette; | 1123 png_colorp palette = png_ptr->palette; |
| 1092 | 1124 |
| 1093 back.red = (png_byte)png_ptr->background.red; | 1125 back.red = (png_byte)png_ptr->background.red; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1111 png_ptr->trans[i], back.blue); | 1143 png_ptr->trans[i], back.blue); |
| 1112 } | 1144 } |
| 1113 } | 1145 } |
| 1114 | 1146 |
| 1115 /* Handled alpha, still need to strip the channel. */ | 1147 /* Handled alpha, still need to strip the channel. */ |
| 1116 png_ptr->transformations &= ~PNG_BACKGROUND; | 1148 png_ptr->transformations &= ~PNG_BACKGROUND; |
| 1117 png_ptr->transformations |= PNG_STRIP_ALPHA; | 1149 png_ptr->transformations |= PNG_STRIP_ALPHA; |
| 1118 } | 1150 } |
| 1119 #endif /* PNG_READ_BACKGROUND_SUPPORTED */ | 1151 #endif /* PNG_READ_BACKGROUND_SUPPORTED */ |
| 1120 | 1152 |
| 1121 #if defined(PNG_READ_SHIFT_SUPPORTED) | 1153 #ifdef PNG_READ_SHIFT_SUPPORTED |
| 1122 if ((png_ptr->transformations & PNG_SHIFT) && | 1154 if ((png_ptr->transformations & PNG_SHIFT) && |
| 1123 (color_type == PNG_COLOR_TYPE_PALETTE)) | 1155 (color_type == PNG_COLOR_TYPE_PALETTE)) |
| 1124 { | 1156 { |
| 1125 png_uint_16 i; | 1157 png_uint_16 i; |
| 1126 png_uint_16 istop = png_ptr->num_palette; | 1158 png_uint_16 istop = png_ptr->num_palette; |
| 1127 int sr = 8 - png_ptr->sig_bit.red; | 1159 int sr = 8 - png_ptr->sig_bit.red; |
| 1128 int sg = 8 - png_ptr->sig_bit.green; | 1160 int sg = 8 - png_ptr->sig_bit.green; |
| 1129 int sb = 8 - png_ptr->sig_bit.blue; | 1161 int sb = 8 - png_ptr->sig_bit.blue; |
| 1130 | 1162 |
| 1131 if (sr < 0 || sr > 8) | 1163 if (sr < 0 || sr > 8) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1151 } | 1183 } |
| 1152 | 1184 |
| 1153 /* Modify the info structure to reflect the transformations. The | 1185 /* Modify the info structure to reflect the transformations. The |
| 1154 * info should be updated so a PNG file could be written with it, | 1186 * info should be updated so a PNG file could be written with it, |
| 1155 * assuming the transformations result in valid PNG data. | 1187 * assuming the transformations result in valid PNG data. |
| 1156 */ | 1188 */ |
| 1157 void /* PRIVATE */ | 1189 void /* PRIVATE */ |
| 1158 png_read_transform_info(png_structp png_ptr, png_infop info_ptr) | 1190 png_read_transform_info(png_structp png_ptr, png_infop info_ptr) |
| 1159 { | 1191 { |
| 1160 png_debug(1, "in png_read_transform_info"); | 1192 png_debug(1, "in png_read_transform_info"); |
| 1161 #if defined(PNG_READ_EXPAND_SUPPORTED) | 1193 |
| 1194 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 1162 if (png_ptr->transformations & PNG_EXPAND) | 1195 if (png_ptr->transformations & PNG_EXPAND) |
| 1163 { | 1196 { |
| 1164 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 1197 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 1165 { | 1198 { |
| 1166 if (png_ptr->num_trans && | 1199 if (png_ptr->num_trans && |
| 1167 (png_ptr->transformations & PNG_EXPAND_tRNS)) | 1200 (png_ptr->transformations & PNG_EXPAND_tRNS)) |
| 1168 info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; | 1201 info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
| 1169 else | 1202 else |
| 1170 info_ptr->color_type = PNG_COLOR_TYPE_RGB; | 1203 info_ptr->color_type = PNG_COLOR_TYPE_RGB; |
| 1171 info_ptr->bit_depth = 8; | 1204 info_ptr->bit_depth = 8; |
| 1172 info_ptr->num_trans = 0; | 1205 info_ptr->num_trans = 0; |
| 1173 } | 1206 } |
| 1174 else | 1207 else |
| 1175 { | 1208 { |
| 1176 if (png_ptr->num_trans) | 1209 if (png_ptr->num_trans) |
| 1177 { | 1210 { |
| 1178 if (png_ptr->transformations & PNG_EXPAND_tRNS) | 1211 if (png_ptr->transformations & PNG_EXPAND_tRNS) |
| 1179 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; | 1212 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; |
| 1180 #if 0 /* Removed from libpng-1.2.27 */ | |
| 1181 else | |
| 1182 info_ptr->color_type |= PNG_COLOR_MASK_COLOR; | |
| 1183 #endif | |
| 1184 } | 1213 } |
| 1185 if (info_ptr->bit_depth < 8) | 1214 if (info_ptr->bit_depth < 8) |
| 1186 info_ptr->bit_depth = 8; | 1215 info_ptr->bit_depth = 8; |
| 1187 info_ptr->num_trans = 0; | 1216 info_ptr->num_trans = 0; |
| 1188 } | 1217 } |
| 1189 } | 1218 } |
| 1190 #endif | 1219 #endif |
| 1191 | 1220 |
| 1192 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1221 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 1193 if (png_ptr->transformations & PNG_BACKGROUND) | 1222 if (png_ptr->transformations & PNG_BACKGROUND) |
| 1194 { | 1223 { |
| 1195 info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; | 1224 info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; |
| 1196 info_ptr->num_trans = 0; | 1225 info_ptr->num_trans = 0; |
| 1197 info_ptr->background = png_ptr->background; | 1226 info_ptr->background = png_ptr->background; |
| 1198 } | 1227 } |
| 1199 #endif | 1228 #endif |
| 1200 | 1229 |
| 1201 #if defined(PNG_READ_GAMMA_SUPPORTED) | 1230 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 1202 if (png_ptr->transformations & PNG_GAMMA) | 1231 if (png_ptr->transformations & PNG_GAMMA) |
| 1203 { | 1232 { |
| 1204 #ifdef PNG_FLOATING_POINT_SUPPORTED | 1233 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 1205 info_ptr->gamma = png_ptr->gamma; | 1234 info_ptr->gamma = png_ptr->gamma; |
| 1206 #endif | 1235 #endif |
| 1207 #ifdef PNG_FIXED_POINT_SUPPORTED | 1236 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 1208 info_ptr->int_gamma = png_ptr->int_gamma; | 1237 info_ptr->int_gamma = png_ptr->int_gamma; |
| 1209 #endif | 1238 #endif |
| 1210 } | 1239 } |
| 1211 #endif | 1240 #endif |
| 1212 | 1241 |
| 1213 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 1242 #ifdef PNG_READ_16_TO_8_SUPPORTED |
| 1214 if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) | 1243 if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16)) |
| 1215 info_ptr->bit_depth = 8; | 1244 info_ptr->bit_depth = 8; |
| 1216 #endif | 1245 #endif |
| 1217 | 1246 |
| 1218 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 1247 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 1219 if (png_ptr->transformations & PNG_GRAY_TO_RGB) | 1248 if (png_ptr->transformations & PNG_GRAY_TO_RGB) |
| 1220 info_ptr->color_type |= PNG_COLOR_MASK_COLOR; | 1249 info_ptr->color_type |= PNG_COLOR_MASK_COLOR; |
| 1221 #endif | 1250 #endif |
| 1222 | 1251 |
| 1223 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | 1252 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
| 1224 if (png_ptr->transformations & PNG_RGB_TO_GRAY) | 1253 if (png_ptr->transformations & PNG_RGB_TO_GRAY) |
| 1225 info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; | 1254 info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR; |
| 1226 #endif | 1255 #endif |
| 1227 | 1256 |
| 1228 #if defined(PNG_READ_DITHER_SUPPORTED) | 1257 #ifdef PNG_READ_DITHER_SUPPORTED |
| 1229 if (png_ptr->transformations & PNG_DITHER) | 1258 if (png_ptr->transformations & PNG_DITHER) |
| 1230 { | 1259 { |
| 1231 if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || | 1260 if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || |
| 1232 (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && | 1261 (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) && |
| 1233 png_ptr->palette_lookup && info_ptr->bit_depth == 8) | 1262 png_ptr->palette_lookup && info_ptr->bit_depth == 8) |
| 1234 { | 1263 { |
| 1235 info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; | 1264 info_ptr->color_type = PNG_COLOR_TYPE_PALETTE; |
| 1236 } | 1265 } |
| 1237 } | 1266 } |
| 1238 #endif | 1267 #endif |
| 1239 | 1268 |
| 1240 #if defined(PNG_READ_PACK_SUPPORTED) | 1269 #ifdef PNG_READ_PACK_SUPPORTED |
| 1241 if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) | 1270 if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8)) |
| 1242 info_ptr->bit_depth = 8; | 1271 info_ptr->bit_depth = 8; |
| 1243 #endif | 1272 #endif |
| 1244 | 1273 |
| 1245 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 1274 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 1246 info_ptr->channels = 1; | 1275 info_ptr->channels = 1; |
| 1247 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) | 1276 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) |
| 1248 info_ptr->channels = 3; | 1277 info_ptr->channels = 3; |
| 1249 else | 1278 else |
| 1250 info_ptr->channels = 1; | 1279 info_ptr->channels = 1; |
| 1251 | 1280 |
| 1252 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 1281 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
| 1253 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) | 1282 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) |
| 1254 info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; | 1283 info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA; |
| 1255 #endif | 1284 #endif |
| 1256 | 1285 |
| 1257 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) | 1286 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
| 1258 info_ptr->channels++; | 1287 info_ptr->channels++; |
| 1259 | 1288 |
| 1260 #if defined(PNG_READ_FILLER_SUPPORTED) | 1289 #ifdef PNG_READ_FILLER_SUPPORTED |
| 1261 /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ | 1290 /* STRIP_ALPHA and FILLER allowed: MASK_ALPHA bit stripped above */ |
| 1262 if ((png_ptr->transformations & PNG_FILLER) && | 1291 if ((png_ptr->transformations & PNG_FILLER) && |
| 1263 ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || | 1292 ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || |
| 1264 (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) | 1293 (info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) |
| 1265 { | 1294 { |
| 1266 info_ptr->channels++; | 1295 info_ptr->channels++; |
| 1267 /* If adding a true alpha channel not just filler */ | 1296 /* If adding a true alpha channel not just filler */ |
| 1268 #if !defined(PNG_1_0_X) | 1297 #ifndef PNG_1_0_X |
| 1269 if (png_ptr->transformations & PNG_ADD_ALPHA) | 1298 if (png_ptr->transformations & PNG_ADD_ALPHA) |
| 1270 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; | 1299 info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; |
| 1271 #endif | 1300 #endif |
| 1272 } | 1301 } |
| 1273 #endif | 1302 #endif |
| 1274 | 1303 |
| 1275 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ | 1304 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ |
| 1276 defined(PNG_READ_USER_TRANSFORM_SUPPORTED) | 1305 defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1277 if (png_ptr->transformations & PNG_USER_TRANSFORM) | 1306 if (png_ptr->transformations & PNG_USER_TRANSFORM) |
| 1278 { | 1307 { |
| 1279 if (info_ptr->bit_depth < png_ptr->user_transform_depth) | 1308 if (info_ptr->bit_depth < png_ptr->user_transform_depth) |
| 1280 info_ptr->bit_depth = png_ptr->user_transform_depth; | 1309 info_ptr->bit_depth = png_ptr->user_transform_depth; |
| 1281 if (info_ptr->channels < png_ptr->user_transform_channels) | 1310 if (info_ptr->channels < png_ptr->user_transform_channels) |
| 1282 info_ptr->channels = png_ptr->user_transform_channels; | 1311 info_ptr->channels = png_ptr->user_transform_channels; |
| 1283 } | 1312 } |
| 1284 #endif | 1313 #endif |
| 1285 | 1314 |
| 1286 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * | 1315 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * |
| 1287 info_ptr->bit_depth); | 1316 info_ptr->bit_depth); |
| 1288 | 1317 |
| 1289 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); | 1318 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width); |
| 1290 | 1319 |
| 1291 #if !defined(PNG_READ_EXPAND_SUPPORTED) | 1320 #ifndef PNG_READ_EXPAND_SUPPORTED |
| 1292 if (png_ptr) | 1321 if (png_ptr) |
| 1293 return; | 1322 return; |
| 1294 #endif | 1323 #endif |
| 1295 } | 1324 } |
| 1296 | 1325 |
| 1297 /* Transform the row. The order of transformations is significant, | 1326 /* Transform the row. The order of transformations is significant, |
| 1298 * and is very touchy. If you add a transformation, take care to | 1327 * and is very touchy. If you add a transformation, take care to |
| 1299 * decide how it fits in with the other transformations here. | 1328 * decide how it fits in with the other transformations here. |
| 1300 */ | 1329 */ |
| 1301 void /* PRIVATE */ | 1330 void /* PRIVATE */ |
| 1302 png_do_read_transformations(png_structp png_ptr) | 1331 png_do_read_transformations(png_structp png_ptr) |
| 1303 { | 1332 { |
| 1304 png_debug(1, "in png_do_read_transformations"); | 1333 png_debug(1, "in png_do_read_transformations"); |
| 1334 |
| 1305 if (png_ptr->row_buf == NULL) | 1335 if (png_ptr->row_buf == NULL) |
| 1306 { | 1336 { |
| 1307 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) | 1337 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE) |
| 1308 char msg[50]; | 1338 char msg[50]; |
| 1309 | 1339 |
| 1310 png_snprintf2(msg, 50, | 1340 png_snprintf2(msg, 50, |
| 1311 "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number, | 1341 "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number, |
| 1312 png_ptr->pass); | 1342 png_ptr->pass); |
| 1313 png_error(png_ptr, msg); | 1343 png_error(png_ptr, msg); |
| 1314 #else | 1344 #else |
| 1315 png_error(png_ptr, "NULL row buffer"); | 1345 png_error(png_ptr, "NULL row buffer"); |
| 1316 #endif | 1346 #endif |
| 1317 } | 1347 } |
| 1318 #ifdef PNG_WARN_UNINITIALIZED_ROW | 1348 #ifdef PNG_WARN_UNINITIALIZED_ROW |
| 1319 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) | 1349 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
| 1320 /* Application has failed to call either png_read_start_image() | 1350 /* Application has failed to call either png_read_start_image() |
| 1321 * or png_read_update_info() after setting transforms that expand | 1351 * or png_read_update_info() after setting transforms that expand |
| 1322 * pixels. This check added to libpng-1.2.19 | 1352 * pixels. This check added to libpng-1.2.19 |
| 1323 */ | 1353 */ |
| 1324 #if (PNG_WARN_UNINITIALIZED_ROW==1) | 1354 #if (PNG_WARN_UNINITIALIZED_ROW==1) |
| 1325 png_error(png_ptr, "Uninitialized row"); | 1355 png_error(png_ptr, "Uninitialized row"); |
| 1326 #else | 1356 #else |
| 1327 png_warning(png_ptr, "Uninitialized row"); | 1357 png_warning(png_ptr, "Uninitialized row"); |
| 1328 #endif | 1358 #endif |
| 1329 #endif | 1359 #endif |
| 1330 | 1360 |
| 1331 #if defined(PNG_READ_EXPAND_SUPPORTED) | 1361 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 1332 if (png_ptr->transformations & PNG_EXPAND) | 1362 if (png_ptr->transformations & PNG_EXPAND) |
| 1333 { | 1363 { |
| 1334 if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) | 1364 if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE) |
| 1335 { | 1365 { |
| 1336 png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1366 png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1337 png_ptr->palette, png_ptr->trans, png_ptr->num_trans); | 1367 png_ptr->palette, png_ptr->trans, png_ptr->num_trans); |
| 1338 } | 1368 } |
| 1339 else | 1369 else |
| 1340 { | 1370 { |
| 1341 if (png_ptr->num_trans && | 1371 if (png_ptr->num_trans && |
| 1342 (png_ptr->transformations & PNG_EXPAND_tRNS)) | 1372 (png_ptr->transformations & PNG_EXPAND_tRNS)) |
| 1343 png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1373 png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1344 &(png_ptr->trans_values)); | 1374 &(png_ptr->trans_values)); |
| 1345 else | 1375 else |
| 1346 png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1376 png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1347 NULL); | 1377 NULL); |
| 1348 } | 1378 } |
| 1349 } | 1379 } |
| 1350 #endif | 1380 #endif |
| 1351 | 1381 |
| 1352 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 1382 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
| 1353 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) | 1383 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA) |
| 1354 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1384 png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1355 PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)); | 1385 PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)); |
| 1356 #endif | 1386 #endif |
| 1357 | 1387 |
| 1358 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | 1388 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
| 1359 if (png_ptr->transformations & PNG_RGB_TO_GRAY) | 1389 if (png_ptr->transformations & PNG_RGB_TO_GRAY) |
| 1360 { | 1390 { |
| 1361 int rgb_error = | 1391 int rgb_error = |
| 1362 png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1)
; | 1392 png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), |
| 1393 png_ptr->row_buf + 1); |
| 1363 if (rgb_error) | 1394 if (rgb_error) |
| 1364 { | 1395 { |
| 1365 png_ptr->rgb_to_gray_status=1; | 1396 png_ptr->rgb_to_gray_status=1; |
| 1366 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == | 1397 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == |
| 1367 PNG_RGB_TO_GRAY_WARN) | 1398 PNG_RGB_TO_GRAY_WARN) |
| 1368 png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); | 1399 png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel"); |
| 1369 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == | 1400 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == |
| 1370 PNG_RGB_TO_GRAY_ERR) | 1401 PNG_RGB_TO_GRAY_ERR) |
| 1371 png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); | 1402 png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel"); |
| 1372 } | 1403 } |
| 1373 } | 1404 } |
| 1374 #endif | 1405 #endif |
| 1375 | 1406 |
| 1376 /* From Andreas Dilger e-mail to png-implement, 26 March 1998: | 1407 /* From Andreas Dilger e-mail to png-implement, 26 March 1998: |
| 1377 * | 1408 * |
| 1378 * In most cases, the "simple transparency" should be done prior to doing | 1409 * In most cases, the "simple transparency" should be done prior to doing |
| 1379 * gray-to-RGB, or you will have to test 3x as many bytes to check if a | 1410 * gray-to-RGB, or you will have to test 3x as many bytes to check if a |
| 1380 * pixel is transparent. You would also need to make sure that the | 1411 * pixel is transparent. You would also need to make sure that the |
| 1381 * transparency information is upgraded to RGB. | 1412 * transparency information is upgraded to RGB. |
| 1382 * | 1413 * |
| 1383 * To summarize, the current flow is: | 1414 * To summarize, the current flow is: |
| 1384 * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite | 1415 * - Gray + simple transparency -> compare 1 or 2 gray bytes and composite |
| 1385 * with background "in place" if transparent, | 1416 * with background "in place" if transparent, |
| 1386 * convert to RGB if necessary | 1417 * convert to RGB if necessary |
| 1387 * - Gray + alpha -> composite with gray background and remove alpha bytes, | 1418 * - Gray + alpha -> composite with gray background and remove alpha bytes, |
| 1388 * convert to RGB if necessary | 1419 * convert to RGB if necessary |
| 1389 * | 1420 * |
| 1390 * To support RGB backgrounds for gray images we need: | 1421 * To support RGB backgrounds for gray images we need: |
| 1391 * - Gray + simple transparency -> convert to RGB + simple transparency, | 1422 * - Gray + simple transparency -> convert to RGB + simple transparency, |
| 1392 * compare 3 or 6 bytes and composite with | 1423 * compare 3 or 6 bytes and composite with |
| 1393 * background "in place" if transparent | 1424 * background "in place" if transparent |
| 1394 * (3x compare/pixel compared to doing | 1425 * (3x compare/pixel compared to doing |
| 1395 * composite with gray bkgrnd) | 1426 * composite with gray bkgrnd) |
| 1396 * - Gray + alpha -> convert to RGB + alpha, composite with background and | 1427 * - Gray + alpha -> convert to RGB + alpha, composite with background and |
| 1397 * remove alpha bytes (3x float | 1428 * remove alpha bytes (3x float |
| 1398 * operations/pixel compared with composite | 1429 * operations/pixel compared with composite |
| 1399 * on gray background) | 1430 * on gray background) |
| 1400 * | 1431 * |
| 1401 * Greg's change will do this. The reason it wasn't done before is for | 1432 * Greg's change will do this. The reason it wasn't done before is for |
| 1402 * performance, as this increases the per-pixel operations. If we would check | 1433 * performance, as this increases the per-pixel operations. If we would check |
| 1403 * in advance if the background was gray or RGB, and position the gray-to-RGB | 1434 * in advance if the background was gray or RGB, and position the gray-to-RGB |
| 1404 * transform appropriately, then it would save a lot of work/time. | 1435 * transform appropriately, then it would save a lot of work/time. |
| 1405 */ | 1436 */ |
| 1406 | 1437 |
| 1407 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 1438 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 1408 /* If gray -> RGB, do so now only if background is non-gray; else do later | 1439 /* If gray -> RGB, do so now only if background is non-gray; else do later |
| 1409 * for performance reasons | 1440 * for performance reasons |
| 1410 */ | 1441 */ |
| 1411 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && | 1442 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && |
| 1412 !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) | 1443 !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) |
| 1413 png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1444 png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1414 #endif | 1445 #endif |
| 1415 | 1446 |
| 1416 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1447 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 1417 if ((png_ptr->transformations & PNG_BACKGROUND) && | 1448 if ((png_ptr->transformations & PNG_BACKGROUND) && |
| 1418 ((png_ptr->num_trans != 0 ) || | 1449 ((png_ptr->num_trans != 0 ) || |
| 1419 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) | 1450 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) |
| 1420 png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1451 png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1421 &(png_ptr->trans_values), &(png_ptr->background) | 1452 &(png_ptr->trans_values), &(png_ptr->background) |
| 1422 #if defined(PNG_READ_GAMMA_SUPPORTED) | 1453 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 1423 , &(png_ptr->background_1), | 1454 , &(png_ptr->background_1), |
| 1424 png_ptr->gamma_table, png_ptr->gamma_from_1, | 1455 png_ptr->gamma_table, png_ptr->gamma_from_1, |
| 1425 png_ptr->gamma_to_1, png_ptr->gamma_16_table, | 1456 png_ptr->gamma_to_1, png_ptr->gamma_16_table, |
| 1426 png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1, | 1457 png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1, |
| 1427 png_ptr->gamma_shift | 1458 png_ptr->gamma_shift |
| 1428 #endif | 1459 #endif |
| 1429 ); | 1460 ); |
| 1430 #endif | 1461 #endif |
| 1431 | 1462 |
| 1432 #if defined(PNG_READ_GAMMA_SUPPORTED) | 1463 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 1433 if ((png_ptr->transformations & PNG_GAMMA) && | 1464 if ((png_ptr->transformations & PNG_GAMMA) && |
| 1434 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 1465 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 1435 !((png_ptr->transformations & PNG_BACKGROUND) && | 1466 !((png_ptr->transformations & PNG_BACKGROUND) && |
| 1436 ((png_ptr->num_trans != 0) || | 1467 ((png_ptr->num_trans != 0) || |
| 1437 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && | 1468 (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) && |
| 1438 #endif | 1469 #endif |
| 1439 (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) | 1470 (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)) |
| 1440 png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1471 png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1441 png_ptr->gamma_table, png_ptr->gamma_16_table, | 1472 png_ptr->gamma_table, png_ptr->gamma_16_table, |
| 1442 png_ptr->gamma_shift); | 1473 png_ptr->gamma_shift); |
| 1443 #endif | 1474 #endif |
| 1444 | 1475 |
| 1445 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 1476 #ifdef PNG_READ_16_TO_8_SUPPORTED |
| 1446 if (png_ptr->transformations & PNG_16_TO_8) | 1477 if (png_ptr->transformations & PNG_16_TO_8) |
| 1447 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1478 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1448 #endif | 1479 #endif |
| 1449 | 1480 |
| 1450 #if defined(PNG_READ_DITHER_SUPPORTED) | 1481 #ifdef PNG_READ_DITHER_SUPPORTED |
| 1451 if (png_ptr->transformations & PNG_DITHER) | 1482 if (png_ptr->transformations & PNG_DITHER) |
| 1452 { | 1483 { |
| 1453 png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1, | 1484 png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1454 png_ptr->palette_lookup, png_ptr->dither_index); | 1485 png_ptr->palette_lookup, png_ptr->dither_index); |
| 1455 if (png_ptr->row_info.rowbytes == (png_uint_32)0) | 1486 if (png_ptr->row_info.rowbytes == (png_uint_32)0) |
| 1456 png_error(png_ptr, "png_do_dither returned rowbytes=0"); | 1487 png_error(png_ptr, "png_do_dither returned rowbytes=0"); |
| 1457 } | 1488 } |
| 1458 #endif | 1489 #endif |
| 1459 | 1490 |
| 1460 #if defined(PNG_READ_INVERT_SUPPORTED) | 1491 #ifdef PNG_READ_INVERT_SUPPORTED |
| 1461 if (png_ptr->transformations & PNG_INVERT_MONO) | 1492 if (png_ptr->transformations & PNG_INVERT_MONO) |
| 1462 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1493 png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1463 #endif | 1494 #endif |
| 1464 | 1495 |
| 1465 #if defined(PNG_READ_SHIFT_SUPPORTED) | 1496 #ifdef PNG_READ_SHIFT_SUPPORTED |
| 1466 if (png_ptr->transformations & PNG_SHIFT) | 1497 if (png_ptr->transformations & PNG_SHIFT) |
| 1467 png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1498 png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1468 &(png_ptr->shift)); | 1499 &(png_ptr->shift)); |
| 1469 #endif | 1500 #endif |
| 1470 | 1501 |
| 1471 #if defined(PNG_READ_PACK_SUPPORTED) | 1502 #ifdef PNG_READ_PACK_SUPPORTED |
| 1472 if (png_ptr->transformations & PNG_PACK) | 1503 if (png_ptr->transformations & PNG_PACK) |
| 1473 png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1504 png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1474 #endif | 1505 #endif |
| 1475 | 1506 |
| 1476 #if defined(PNG_READ_BGR_SUPPORTED) | 1507 #ifdef PNG_READ_BGR_SUPPORTED |
| 1477 if (png_ptr->transformations & PNG_BGR) | 1508 if (png_ptr->transformations & PNG_BGR) |
| 1478 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1509 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1479 #endif | 1510 #endif |
| 1480 | 1511 |
| 1481 #if defined(PNG_READ_PACKSWAP_SUPPORTED) | 1512 #ifdef PNG_READ_PACKSWAP_SUPPORTED |
| 1482 if (png_ptr->transformations & PNG_PACKSWAP) | 1513 if (png_ptr->transformations & PNG_PACKSWAP) |
| 1483 png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1514 png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1484 #endif | 1515 #endif |
| 1485 | 1516 |
| 1486 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 1517 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 1487 /* If gray -> RGB, do so now only if we did not do so above */ | 1518 /* If gray -> RGB, do so now only if we did not do so above */ |
| 1488 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && | 1519 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) && |
| 1489 (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) | 1520 (png_ptr->mode & PNG_BACKGROUND_IS_GRAY)) |
| 1490 png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1521 png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1491 #endif | 1522 #endif |
| 1492 | 1523 |
| 1493 #if defined(PNG_READ_FILLER_SUPPORTED) | 1524 #ifdef PNG_READ_FILLER_SUPPORTED |
| 1494 if (png_ptr->transformations & PNG_FILLER) | 1525 if (png_ptr->transformations & PNG_FILLER) |
| 1495 png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, | 1526 png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1, |
| 1496 (png_uint_32)png_ptr->filler, png_ptr->flags); | 1527 (png_uint_32)png_ptr->filler, png_ptr->flags); |
| 1497 #endif | 1528 #endif |
| 1498 | 1529 |
| 1499 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) | 1530 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
| 1500 if (png_ptr->transformations & PNG_INVERT_ALPHA) | 1531 if (png_ptr->transformations & PNG_INVERT_ALPHA) |
| 1501 png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1532 png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1502 #endif | 1533 #endif |
| 1503 | 1534 |
| 1504 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) | 1535 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED |
| 1505 if (png_ptr->transformations & PNG_SWAP_ALPHA) | 1536 if (png_ptr->transformations & PNG_SWAP_ALPHA) |
| 1506 png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1537 png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1507 #endif | 1538 #endif |
| 1508 | 1539 |
| 1509 #if defined(PNG_READ_SWAP_SUPPORTED) | 1540 #ifdef PNG_READ_SWAP_SUPPORTED |
| 1510 if (png_ptr->transformations & PNG_SWAP_BYTES) | 1541 if (png_ptr->transformations & PNG_SWAP_BYTES) |
| 1511 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); | 1542 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1); |
| 1512 #endif | 1543 #endif |
| 1513 | 1544 |
| 1514 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) | 1545 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED |
| 1515 if (png_ptr->transformations & PNG_USER_TRANSFORM) | 1546 if (png_ptr->transformations & PNG_USER_TRANSFORM) |
| 1516 { | 1547 { |
| 1517 if (png_ptr->read_user_transform_fn != NULL) | 1548 if (png_ptr->read_user_transform_fn != NULL) |
| 1518 (*(png_ptr->read_user_transform_fn)) /* User read transform function */ | 1549 (*(png_ptr->read_user_transform_fn)) /* User read transform function */ |
| 1519 (png_ptr, /* png_ptr */ | 1550 (png_ptr, /* png_ptr */ |
| 1520 &(png_ptr->row_info), /* row_info: */ | 1551 &(png_ptr->row_info), /* row_info: */ |
| 1521 /* png_uint_32 width; width of row */ | 1552 /* png_uint_32 width; width of row */ |
| 1522 /* png_uint_32 rowbytes; number of bytes in row */ | 1553 /* png_uint_32 rowbytes; number of bytes in row */ |
| 1523 /* png_byte color_type; color type of pixels */ | 1554 /* png_byte color_type; color type of pixels */ |
| 1524 /* png_byte bit_depth; bit depth of samples */ | 1555 /* png_byte bit_depth; bit depth of samples */ |
| 1525 /* png_byte channels; number of channels (1-4) */ | 1556 /* png_byte channels; number of channels (1-4) */ |
| 1526 /* png_byte pixel_depth; bits per pixel (depth*channels) */ | 1557 /* png_byte pixel_depth; bits per pixel (depth*channels) */ |
| 1527 png_ptr->row_buf + 1); /* start of pixel data for row */ | 1558 png_ptr->row_buf + 1); /* start of pixel data for row */ |
| 1528 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) | 1559 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
| 1529 if (png_ptr->user_transform_depth) | 1560 if (png_ptr->user_transform_depth) |
| 1530 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; | 1561 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; |
| 1531 if (png_ptr->user_transform_channels) | 1562 if (png_ptr->user_transform_channels) |
| 1532 png_ptr->row_info.channels = png_ptr->user_transform_channels; | 1563 png_ptr->row_info.channels = png_ptr->user_transform_channels; |
| 1533 #endif | 1564 #endif |
| 1534 png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * | 1565 png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * |
| 1535 png_ptr->row_info.channels); | 1566 png_ptr->row_info.channels); |
| 1536 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, | 1567 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
| 1537 png_ptr->row_info.width); | 1568 png_ptr->row_info.width); |
| 1538 } | 1569 } |
| 1539 #endif | 1570 #endif |
| 1540 | 1571 |
| 1541 } | 1572 } |
| 1542 | 1573 |
| 1543 #if defined(PNG_READ_PACK_SUPPORTED) | 1574 #ifdef PNG_READ_PACK_SUPPORTED |
| 1544 /* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, | 1575 /* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel, |
| 1545 * without changing the actual values. Thus, if you had a row with | 1576 * without changing the actual values. Thus, if you had a row with |
| 1546 * a bit depth of 1, you would end up with bytes that only contained | 1577 * a bit depth of 1, you would end up with bytes that only contained |
| 1547 * the numbers 0 or 1. If you would rather they contain 0 and 255, use | 1578 * the numbers 0 or 1. If you would rather they contain 0 and 255, use |
| 1548 * png_do_shift() after this. | 1579 * png_do_shift() after this. |
| 1549 */ | 1580 */ |
| 1550 void /* PRIVATE */ | 1581 void /* PRIVATE */ |
| 1551 png_do_unpack(png_row_infop row_info, png_bytep row) | 1582 png_do_unpack(png_row_infop row_info, png_bytep row) |
| 1552 { | 1583 { |
| 1553 png_debug(1, "in png_do_unpack"); | 1584 png_debug(1, "in png_do_unpack"); |
| 1554 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 1585 |
| 1586 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 1555 if (row != NULL && row_info != NULL && row_info->bit_depth < 8) | 1587 if (row != NULL && row_info != NULL && row_info->bit_depth < 8) |
| 1556 #else | 1588 #else |
| 1557 if (row_info->bit_depth < 8) | 1589 if (row_info->bit_depth < 8) |
| 1558 #endif | 1590 #endif |
| 1559 { | 1591 { |
| 1560 png_uint_32 i; | 1592 png_uint_32 i; |
| 1561 png_uint_32 row_width=row_info->width; | 1593 png_uint_32 row_width=row_info->width; |
| 1562 | 1594 |
| 1563 switch (row_info->bit_depth) | 1595 switch (row_info->bit_depth) |
| 1564 { | 1596 { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1626 break; | 1658 break; |
| 1627 } | 1659 } |
| 1628 } | 1660 } |
| 1629 row_info->bit_depth = 8; | 1661 row_info->bit_depth = 8; |
| 1630 row_info->pixel_depth = (png_byte)(8 * row_info->channels); | 1662 row_info->pixel_depth = (png_byte)(8 * row_info->channels); |
| 1631 row_info->rowbytes = row_width * row_info->channels; | 1663 row_info->rowbytes = row_width * row_info->channels; |
| 1632 } | 1664 } |
| 1633 } | 1665 } |
| 1634 #endif | 1666 #endif |
| 1635 | 1667 |
| 1636 #if defined(PNG_READ_SHIFT_SUPPORTED) | 1668 #ifdef PNG_READ_SHIFT_SUPPORTED |
| 1637 /* Reverse the effects of png_do_shift. This routine merely shifts the | 1669 /* Reverse the effects of png_do_shift. This routine merely shifts the |
| 1638 * pixels back to their significant bits values. Thus, if you have | 1670 * pixels back to their significant bits values. Thus, if you have |
| 1639 * a row of bit depth 8, but only 5 are significant, this will shift | 1671 * a row of bit depth 8, but only 5 are significant, this will shift |
| 1640 * the values back to 0 through 31. | 1672 * the values back to 0 through 31. |
| 1641 */ | 1673 */ |
| 1642 void /* PRIVATE */ | 1674 void /* PRIVATE */ |
| 1643 png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) | 1675 png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) |
| 1644 { | 1676 { |
| 1645 png_debug(1, "in png_do_unshift"); | 1677 png_debug(1, "in png_do_unshift"); |
| 1678 |
| 1646 if ( | 1679 if ( |
| 1647 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 1680 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 1648 row != NULL && row_info != NULL && sig_bits != NULL && | 1681 row != NULL && row_info != NULL && sig_bits != NULL && |
| 1649 #endif | 1682 #endif |
| 1650 row_info->color_type != PNG_COLOR_TYPE_PALETTE) | 1683 row_info->color_type != PNG_COLOR_TYPE_PALETTE) |
| 1651 { | 1684 { |
| 1652 int shift[4]; | 1685 int shift[4]; |
| 1653 int channels = 0; | 1686 int channels = 0; |
| 1654 int c; | 1687 int c; |
| 1655 png_uint_16 value = 0; | 1688 png_uint_16 value = 0; |
| 1656 png_uint_32 row_width = row_info->width; | 1689 png_uint_32 row_width = row_info->width; |
| 1657 | 1690 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 *bp++ = (png_byte)(value >> 8); | 1772 *bp++ = (png_byte)(value >> 8); |
| 1740 *bp++ = (png_byte)(value & 0xff); | 1773 *bp++ = (png_byte)(value & 0xff); |
| 1741 } | 1774 } |
| 1742 break; | 1775 break; |
| 1743 } | 1776 } |
| 1744 } | 1777 } |
| 1745 } | 1778 } |
| 1746 } | 1779 } |
| 1747 #endif | 1780 #endif |
| 1748 | 1781 |
| 1749 #if defined(PNG_READ_16_TO_8_SUPPORTED) | 1782 #ifdef PNG_READ_16_TO_8_SUPPORTED |
| 1750 /* Chop rows of bit depth 16 down to 8 */ | 1783 /* Chop rows of bit depth 16 down to 8 */ |
| 1751 void /* PRIVATE */ | 1784 void /* PRIVATE */ |
| 1752 png_do_chop(png_row_infop row_info, png_bytep row) | 1785 png_do_chop(png_row_infop row_info, png_bytep row) |
| 1753 { | 1786 { |
| 1754 png_debug(1, "in png_do_chop"); | 1787 png_debug(1, "in png_do_chop"); |
| 1755 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 1788 |
| 1789 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 1756 if (row != NULL && row_info != NULL && row_info->bit_depth == 16) | 1790 if (row != NULL && row_info != NULL && row_info->bit_depth == 16) |
| 1757 #else | 1791 #else |
| 1758 if (row_info->bit_depth == 16) | 1792 if (row_info->bit_depth == 16) |
| 1759 #endif | 1793 #endif |
| 1760 { | 1794 { |
| 1761 png_bytep sp = row; | 1795 png_bytep sp = row; |
| 1762 png_bytep dp = row; | 1796 png_bytep dp = row; |
| 1763 png_uint_32 i; | 1797 png_uint_32 i; |
| 1764 png_uint_32 istop = row_info->width * row_info->channels; | 1798 png_uint_32 istop = row_info->width * row_info->channels; |
| 1765 | 1799 |
| 1766 for (i = 0; i<istop; i++, sp += 2, dp++) | 1800 for (i = 0; i<istop; i++, sp += 2, dp++) |
| 1767 { | 1801 { |
| 1768 #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED) | 1802 #ifdef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED |
| 1769 /* This does a more accurate scaling of the 16-bit color | 1803 /* This does a more accurate scaling of the 16-bit color |
| 1770 * value, rather than a simple low-byte truncation. | 1804 * value, rather than a simple low-byte truncation. |
| 1771 * | 1805 * |
| 1772 * What the ideal calculation should be: | 1806 * What the ideal calculation should be: |
| 1773 * *dp = (((((png_uint_32)(*sp) << 8) | | 1807 * *dp = (((((png_uint_32)(*sp) << 8) | |
| 1774 * (png_uint_32)(*(sp + 1))) * 255 + 127) | 1808 * (png_uint_32)(*(sp + 1))) * 255 + 127) |
| 1775 * / (png_uint_32)65535L; | 1809 * / (png_uint_32)65535L; |
| 1776 * | 1810 * |
| 1777 * GRR: no, I think this is what it really should be: | 1811 * GRR: no, I think this is what it really should be: |
| 1778 * *dp = (((((png_uint_32)(*sp) << 8) | | 1812 * *dp = (((((png_uint_32)(*sp) << 8) | |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1797 *dp = *sp; | 1831 *dp = *sp; |
| 1798 #endif | 1832 #endif |
| 1799 } | 1833 } |
| 1800 row_info->bit_depth = 8; | 1834 row_info->bit_depth = 8; |
| 1801 row_info->pixel_depth = (png_byte)(8 * row_info->channels); | 1835 row_info->pixel_depth = (png_byte)(8 * row_info->channels); |
| 1802 row_info->rowbytes = row_info->width * row_info->channels; | 1836 row_info->rowbytes = row_info->width * row_info->channels; |
| 1803 } | 1837 } |
| 1804 } | 1838 } |
| 1805 #endif | 1839 #endif |
| 1806 | 1840 |
| 1807 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) | 1841 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED |
| 1808 void /* PRIVATE */ | 1842 void /* PRIVATE */ |
| 1809 png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) | 1843 png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) |
| 1810 { | 1844 { |
| 1811 png_debug(1, "in png_do_read_swap_alpha"); | 1845 png_debug(1, "in png_do_read_swap_alpha"); |
| 1812 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 1846 |
| 1847 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 1813 if (row != NULL && row_info != NULL) | 1848 if (row != NULL && row_info != NULL) |
| 1814 #endif | 1849 #endif |
| 1815 { | 1850 { |
| 1816 png_uint_32 row_width = row_info->width; | 1851 png_uint_32 row_width = row_info->width; |
| 1817 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 1852 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
| 1818 { | 1853 { |
| 1819 /* This converts from RGBA to ARGB */ | 1854 /* This converts from RGBA to ARGB */ |
| 1820 if (row_info->bit_depth == 8) | 1855 if (row_info->bit_depth == 8) |
| 1821 { | 1856 { |
| 1822 png_bytep sp = row + row_info->rowbytes; | 1857 png_bytep sp = row + row_info->rowbytes; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1889 *(--dp) = *(--sp); | 1924 *(--dp) = *(--sp); |
| 1890 *(--dp) = save[0]; | 1925 *(--dp) = save[0]; |
| 1891 *(--dp) = save[1]; | 1926 *(--dp) = save[1]; |
| 1892 } | 1927 } |
| 1893 } | 1928 } |
| 1894 } | 1929 } |
| 1895 } | 1930 } |
| 1896 } | 1931 } |
| 1897 #endif | 1932 #endif |
| 1898 | 1933 |
| 1899 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) | 1934 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
| 1900 void /* PRIVATE */ | 1935 void /* PRIVATE */ |
| 1901 png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) | 1936 png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) |
| 1902 { | 1937 { |
| 1903 png_debug(1, "in png_do_read_invert_alpha"); | 1938 png_debug(1, "in png_do_read_invert_alpha"); |
| 1904 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 1939 |
| 1940 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 1905 if (row != NULL && row_info != NULL) | 1941 if (row != NULL && row_info != NULL) |
| 1906 #endif | 1942 #endif |
| 1907 { | 1943 { |
| 1908 png_uint_32 row_width = row_info->width; | 1944 png_uint_32 row_width = row_info->width; |
| 1909 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) | 1945 if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA) |
| 1910 { | 1946 { |
| 1911 /* This inverts the alpha channel in RGBA */ | 1947 /* This inverts the alpha channel in RGBA */ |
| 1912 if (row_info->bit_depth == 8) | 1948 if (row_info->bit_depth == 8) |
| 1913 { | 1949 { |
| 1914 png_bytep sp = row + row_info->rowbytes; | 1950 png_bytep sp = row + row_info->rowbytes; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 */ | 2023 */ |
| 1988 sp-=2; | 2024 sp-=2; |
| 1989 dp=sp; | 2025 dp=sp; |
| 1990 } | 2026 } |
| 1991 } | 2027 } |
| 1992 } | 2028 } |
| 1993 } | 2029 } |
| 1994 } | 2030 } |
| 1995 #endif | 2031 #endif |
| 1996 | 2032 |
| 1997 #if defined(PNG_READ_FILLER_SUPPORTED) | 2033 #ifdef PNG_READ_FILLER_SUPPORTED |
| 1998 /* Add filler channel if we have RGB color */ | 2034 /* Add filler channel if we have RGB color */ |
| 1999 void /* PRIVATE */ | 2035 void /* PRIVATE */ |
| 2000 png_do_read_filler(png_row_infop row_info, png_bytep row, | 2036 png_do_read_filler(png_row_infop row_info, png_bytep row, |
| 2001 png_uint_32 filler, png_uint_32 flags) | 2037 png_uint_32 filler, png_uint_32 flags) |
| 2002 { | 2038 { |
| 2003 png_uint_32 i; | 2039 png_uint_32 i; |
| 2004 png_uint_32 row_width = row_info->width; | 2040 png_uint_32 row_width = row_info->width; |
| 2005 | 2041 |
| 2006 png_byte hi_filler = (png_byte)((filler>>8) & 0xff); | 2042 png_byte hi_filler = (png_byte)((filler>>8) & 0xff); |
| 2007 png_byte lo_filler = (png_byte)(filler & 0xff); | 2043 png_byte lo_filler = (png_byte)(filler & 0xff); |
| 2008 | 2044 |
| 2009 png_debug(1, "in png_do_read_filler"); | 2045 png_debug(1, "in png_do_read_filler"); |
| 2046 |
| 2010 if ( | 2047 if ( |
| 2011 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 2048 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 2012 row != NULL && row_info != NULL && | 2049 row != NULL && row_info != NULL && |
| 2013 #endif | 2050 #endif |
| 2014 row_info->color_type == PNG_COLOR_TYPE_GRAY) | 2051 row_info->color_type == PNG_COLOR_TYPE_GRAY) |
| 2015 { | 2052 { |
| 2016 if (row_info->bit_depth == 8) | 2053 if (row_info->bit_depth == 8) |
| 2017 { | 2054 { |
| 2018 /* This changes the data from G to GX */ | 2055 /* This changes the data from G to GX */ |
| 2019 if (flags & PNG_FLAG_FILLER_AFTER) | 2056 if (flags & PNG_FLAG_FILLER_AFTER) |
| 2020 { | 2057 { |
| 2021 png_bytep sp = row + (png_size_t)row_width; | 2058 png_bytep sp = row + (png_size_t)row_width; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 } | 2200 } |
| 2164 row_info->channels = 4; | 2201 row_info->channels = 4; |
| 2165 row_info->pixel_depth = 64; | 2202 row_info->pixel_depth = 64; |
| 2166 row_info->rowbytes = row_width * 8; | 2203 row_info->rowbytes = row_width * 8; |
| 2167 } | 2204 } |
| 2168 } | 2205 } |
| 2169 } /* COLOR_TYPE == RGB */ | 2206 } /* COLOR_TYPE == RGB */ |
| 2170 } | 2207 } |
| 2171 #endif | 2208 #endif |
| 2172 | 2209 |
| 2173 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) | 2210 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
| 2174 /* Expand grayscale files to RGB, with or without alpha */ | 2211 /* Expand grayscale files to RGB, with or without alpha */ |
| 2175 void /* PRIVATE */ | 2212 void /* PRIVATE */ |
| 2176 png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) | 2213 png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) |
| 2177 { | 2214 { |
| 2178 png_uint_32 i; | 2215 png_uint_32 i; |
| 2179 png_uint_32 row_width = row_info->width; | 2216 png_uint_32 row_width = row_info->width; |
| 2180 | 2217 |
| 2181 png_debug(1, "in png_do_gray_to_rgb"); | 2218 png_debug(1, "in png_do_gray_to_rgb"); |
| 2219 |
| 2182 if (row_info->bit_depth >= 8 && | 2220 if (row_info->bit_depth >= 8 && |
| 2183 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 2221 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 2184 row != NULL && row_info != NULL && | 2222 row != NULL && row_info != NULL && |
| 2185 #endif | 2223 #endif |
| 2186 !(row_info->color_type & PNG_COLOR_MASK_COLOR)) | 2224 !(row_info->color_type & PNG_COLOR_MASK_COLOR)) |
| 2187 { | 2225 { |
| 2188 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) | 2226 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) |
| 2189 { | 2227 { |
| 2190 if (row_info->bit_depth == 8) | 2228 if (row_info->bit_depth == 8) |
| 2191 { | 2229 { |
| 2192 png_bytep sp = row + (png_size_t)row_width - 1; | 2230 png_bytep sp = row + (png_size_t)row_width - 1; |
| 2193 png_bytep dp = sp + (png_size_t)row_width * 2; | 2231 png_bytep dp = sp + (png_size_t)row_width * 2; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2246 } | 2284 } |
| 2247 row_info->channels += (png_byte)2; | 2285 row_info->channels += (png_byte)2; |
| 2248 row_info->color_type |= PNG_COLOR_MASK_COLOR; | 2286 row_info->color_type |= PNG_COLOR_MASK_COLOR; |
| 2249 row_info->pixel_depth = (png_byte)(row_info->channels * | 2287 row_info->pixel_depth = (png_byte)(row_info->channels * |
| 2250 row_info->bit_depth); | 2288 row_info->bit_depth); |
| 2251 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); | 2289 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); |
| 2252 } | 2290 } |
| 2253 } | 2291 } |
| 2254 #endif | 2292 #endif |
| 2255 | 2293 |
| 2256 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | 2294 #ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED |
| 2257 /* Reduce RGB files to grayscale, with or without alpha | 2295 /* Reduce RGB files to grayscale, with or without alpha |
| 2258 * using the equation given in Poynton's ColorFAQ at | 2296 * using the equation given in Poynton's ColorFAQ at |
| 2259 * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008) | 2297 * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008) |
| 2260 * New link: | 2298 * New link: |
| 2261 * <http://www.poynton.com/notes/colour_and_gamma/> | 2299 * <http://www.poynton.com/notes/colour_and_gamma/> |
| 2262 * Charles Poynton poynton at poynton.com | 2300 * Charles Poynton poynton at poynton.com |
| 2263 * | 2301 * |
| 2264 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B | 2302 * Y = 0.212671 * R + 0.715160 * G + 0.072169 * B |
| 2265 * | 2303 * |
| 2266 * We approximate this with | 2304 * We approximate this with |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2278 int /* PRIVATE */ | 2316 int /* PRIVATE */ |
| 2279 png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) | 2317 png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) |
| 2280 | 2318 |
| 2281 { | 2319 { |
| 2282 png_uint_32 i; | 2320 png_uint_32 i; |
| 2283 | 2321 |
| 2284 png_uint_32 row_width = row_info->width; | 2322 png_uint_32 row_width = row_info->width; |
| 2285 int rgb_error = 0; | 2323 int rgb_error = 0; |
| 2286 | 2324 |
| 2287 png_debug(1, "in png_do_rgb_to_gray"); | 2325 png_debug(1, "in png_do_rgb_to_gray"); |
| 2326 |
| 2288 if ( | 2327 if ( |
| 2289 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 2328 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 2290 row != NULL && row_info != NULL && | 2329 row != NULL && row_info != NULL && |
| 2291 #endif | 2330 #endif |
| 2292 (row_info->color_type & PNG_COLOR_MASK_COLOR)) | 2331 (row_info->color_type & PNG_COLOR_MASK_COLOR)) |
| 2293 { | 2332 { |
| 2294 png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; | 2333 png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff; |
| 2295 png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; | 2334 png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff; |
| 2296 png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff; | 2335 png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff; |
| 2297 | 2336 |
| 2298 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 2337 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
| 2299 { | 2338 { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2356 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2395 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2357 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2396 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2358 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2397 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2359 | 2398 |
| 2360 if (red == green && red == blue) | 2399 if (red == green && red == blue) |
| 2361 w = red; | 2400 w = red; |
| 2362 else | 2401 else |
| 2363 { | 2402 { |
| 2364 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> | 2403 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> |
| 2365 png_ptr->gamma_shift][red>>8]; | 2404 png_ptr->gamma_shift][red>>8]; |
| 2366 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >
> | 2405 png_uint_16 green_1 = |
| 2406 png_ptr->gamma_16_to_1[(green&0xff) >> |
| 2367 png_ptr->gamma_shift][green>>8]; | 2407 png_ptr->gamma_shift][green>>8]; |
| 2368 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> | 2408 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> |
| 2369 png_ptr->gamma_shift][blue>>8]; | 2409 png_ptr->gamma_shift][blue>>8]; |
| 2370 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 | 2410 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 |
| 2371 + bc*blue_1)>>15); | 2411 + bc*blue_1)>>15); |
| 2372 w = png_ptr->gamma_16_from_1[(gray16&0xff) >> | 2412 w = png_ptr->gamma_16_from_1[(gray16&0xff) >> |
| 2373 png_ptr->gamma_shift][gray16 >> 8]; | 2413 png_ptr->gamma_shift][gray16 >> 8]; |
| 2374 rgb_error |= 1; | 2414 rgb_error |= 1; |
| 2375 } | 2415 } |
| 2376 | 2416 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2452 | 2492 |
| 2453 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2493 red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2454 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2494 green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2455 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; | 2495 blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2; |
| 2456 | 2496 |
| 2457 if (red == green && red == blue) | 2497 if (red == green && red == blue) |
| 2458 w = red; | 2498 w = red; |
| 2459 else | 2499 else |
| 2460 { | 2500 { |
| 2461 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> | 2501 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >> |
| 2462 png_ptr->gamma_shift][red>>8]; | 2502 png_ptr->gamma_shift][red>>8]; |
| 2463 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >
> | 2503 png_uint_16 green_1 = |
| 2464 png_ptr->gamma_shift][green>>8]; | 2504 png_ptr->gamma_16_to_1[(green&0xff) >> |
| 2505 png_ptr->gamma_shift][green>>8]; |
| 2465 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> | 2506 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> |
| 2466 png_ptr->gamma_shift][blue>>8]; | 2507 png_ptr->gamma_shift][blue>>8]; |
| 2467 png_uint_16 gray16 = (png_uint_16)((rc * red_1 | 2508 png_uint_16 gray16 = (png_uint_16)((rc * red_1 |
| 2468 + gc * green_1 + bc * blue_1)>>15); | 2509 + gc * green_1 + bc * blue_1)>>15); |
| 2469 w = png_ptr->gamma_16_from_1[(gray16&0xff) >> | 2510 w = png_ptr->gamma_16_from_1[(gray16&0xff) >> |
| 2470 png_ptr->gamma_shift][gray16 >> 8]; | 2511 png_ptr->gamma_shift][gray16 >> 8]; |
| 2471 rgb_error |= 1; | 2512 rgb_error |= 1; |
| 2472 } | 2513 } |
| 2473 | 2514 |
| 2474 *(dp++) = (png_byte)((w>>8) & 0xff); | 2515 *(dp++) = (png_byte)((w>>8) & 0xff); |
| 2475 *(dp++) = (png_byte)(w & 0xff); | 2516 *(dp++) = (png_byte)(w & 0xff); |
| 2476 *(dp++) = *(sp++); /* alpha */ | 2517 *(dp++) = *(sp++); /* alpha */ |
| 2477 *(dp++) = *(sp++); | 2518 *(dp++) = *(sp++); |
| 2478 } | 2519 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 */ | 2557 */ |
| 2517 void PNGAPI | 2558 void PNGAPI |
| 2518 png_build_grayscale_palette(int bit_depth, png_colorp palette) | 2559 png_build_grayscale_palette(int bit_depth, png_colorp palette) |
| 2519 { | 2560 { |
| 2520 int num_palette; | 2561 int num_palette; |
| 2521 int color_inc; | 2562 int color_inc; |
| 2522 int i; | 2563 int i; |
| 2523 int v; | 2564 int v; |
| 2524 | 2565 |
| 2525 png_debug(1, "in png_do_build_grayscale_palette"); | 2566 png_debug(1, "in png_do_build_grayscale_palette"); |
| 2567 |
| 2526 if (palette == NULL) | 2568 if (palette == NULL) |
| 2527 return; | 2569 return; |
| 2528 | 2570 |
| 2529 switch (bit_depth) | 2571 switch (bit_depth) |
| 2530 { | 2572 { |
| 2531 case 1: | 2573 case 1: |
| 2532 num_palette = 2; | 2574 num_palette = 2; |
| 2533 color_inc = 0xff; | 2575 color_inc = 0xff; |
| 2534 break; | 2576 break; |
| 2535 | 2577 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2556 | 2598 |
| 2557 for (i = 0, v = 0; i < num_palette; i++, v += color_inc) | 2599 for (i = 0, v = 0; i < num_palette; i++, v += color_inc) |
| 2558 { | 2600 { |
| 2559 palette[i].red = (png_byte)v; | 2601 palette[i].red = (png_byte)v; |
| 2560 palette[i].green = (png_byte)v; | 2602 palette[i].green = (png_byte)v; |
| 2561 palette[i].blue = (png_byte)v; | 2603 palette[i].blue = (png_byte)v; |
| 2562 } | 2604 } |
| 2563 } | 2605 } |
| 2564 | 2606 |
| 2565 /* This function is currently unused. Do we really need it? */ | 2607 /* This function is currently unused. Do we really need it? */ |
| 2566 #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED) | 2608 #if defined(PNG_READ_DITHER_SUPPORTED) && \ |
| 2609 defined(PNG_CORRECT_PALETTE_SUPPORTED) |
| 2567 void /* PRIVATE */ | 2610 void /* PRIVATE */ |
| 2568 png_correct_palette(png_structp png_ptr, png_colorp palette, | 2611 png_correct_palette(png_structp png_ptr, png_colorp palette, |
| 2569 int num_palette) | 2612 int num_palette) |
| 2570 { | 2613 { |
| 2571 png_debug(1, "in png_correct_palette"); | 2614 png_debug(1, "in png_correct_palette"); |
| 2615 |
| 2572 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ | 2616 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ |
| 2573 defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) | 2617 defined(PNG_READ_GAMMA_SUPPORTED) && \ |
| 2618 defined(PNG_FLOATING_POINT_SUPPORTED) |
| 2574 if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND)) | 2619 if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND)) |
| 2575 { | 2620 { |
| 2576 png_color back, back_1; | 2621 png_color back, back_1; |
| 2577 | 2622 |
| 2578 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) | 2623 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE) |
| 2579 { | 2624 { |
| 2580 back.red = png_ptr->gamma_table[png_ptr->background.red]; | 2625 back.red = png_ptr->gamma_table[png_ptr->background.red]; |
| 2581 back.green = png_ptr->gamma_table[png_ptr->background.green]; | 2626 back.green = png_ptr->gamma_table[png_ptr->background.green]; |
| 2582 back.blue = png_ptr->gamma_table[png_ptr->background.blue]; | 2627 back.blue = png_ptr->gamma_table[png_ptr->background.blue]; |
| 2583 | 2628 |
| 2584 back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; | 2629 back_1.red = png_ptr->gamma_to_1[png_ptr->background.red]; |
| 2585 back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; | 2630 back_1.green = png_ptr->gamma_to_1[png_ptr->background.green]; |
| 2586 back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; | 2631 back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue]; |
| 2587 } | 2632 } |
| 2588 else | 2633 else |
| 2589 { | 2634 { |
| 2590 double g; | 2635 double g; |
| 2591 | 2636 |
| 2592 g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); | 2637 g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma); |
| 2593 | 2638 |
| 2594 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN || | 2639 if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN |
| 2595 fabs(g - 1.0) < PNG_GAMMA_THRESHOLD) | 2640 || fabs(g - 1.0) < PNG_GAMMA_THRESHOLD) |
| 2596 { | 2641 { |
| 2597 back.red = png_ptr->background.red; | 2642 back.red = png_ptr->background.red; |
| 2598 back.green = png_ptr->background.green; | 2643 back.green = png_ptr->background.green; |
| 2599 back.blue = png_ptr->background.blue; | 2644 back.blue = png_ptr->background.blue; |
| 2600 } | 2645 } |
| 2601 else | 2646 else |
| 2602 { | 2647 { |
| 2603 back.red = | 2648 back.red = |
| 2604 (png_byte)(pow((double)png_ptr->background.red/255, g) * | 2649 (png_byte)(pow((double)png_ptr->background.red/255, g) * |
| 2605 255.0 + 0.5); | 2650 255.0 + 0.5); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2672 { | 2717 { |
| 2673 palette[i].red = png_ptr->gamma_table[palette[i].red]; | 2718 palette[i].red = png_ptr->gamma_table[palette[i].red]; |
| 2674 palette[i].green = png_ptr->gamma_table[palette[i].green]; | 2719 palette[i].green = png_ptr->gamma_table[palette[i].green]; |
| 2675 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; | 2720 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; |
| 2676 } | 2721 } |
| 2677 } | 2722 } |
| 2678 } | 2723 } |
| 2679 } | 2724 } |
| 2680 else | 2725 else |
| 2681 #endif | 2726 #endif |
| 2682 #if defined(PNG_READ_GAMMA_SUPPORTED) | 2727 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2683 if (png_ptr->transformations & PNG_GAMMA) | 2728 if (png_ptr->transformations & PNG_GAMMA) |
| 2684 { | 2729 { |
| 2685 int i; | 2730 int i; |
| 2686 | 2731 |
| 2687 for (i = 0; i < num_palette; i++) | 2732 for (i = 0; i < num_palette; i++) |
| 2688 { | 2733 { |
| 2689 palette[i].red = png_ptr->gamma_table[palette[i].red]; | 2734 palette[i].red = png_ptr->gamma_table[palette[i].red]; |
| 2690 palette[i].green = png_ptr->gamma_table[palette[i].green]; | 2735 palette[i].green = png_ptr->gamma_table[palette[i].green]; |
| 2691 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; | 2736 palette[i].blue = png_ptr->gamma_table[palette[i].blue]; |
| 2692 } | 2737 } |
| 2693 } | 2738 } |
| 2694 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 2739 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 2695 else | 2740 else |
| 2696 #endif | 2741 #endif |
| 2697 #endif | 2742 #endif |
| 2698 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 2743 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 2699 if (png_ptr->transformations & PNG_BACKGROUND) | 2744 if (png_ptr->transformations & PNG_BACKGROUND) |
| 2700 { | 2745 { |
| 2701 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 2746 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 2702 { | 2747 { |
| 2703 png_color back; | 2748 png_color back; |
| 2704 | 2749 |
| 2705 back.red = (png_byte)png_ptr->background.red; | 2750 back.red = (png_byte)png_ptr->background.red; |
| 2706 back.green = (png_byte)png_ptr->background.green; | 2751 back.green = (png_byte)png_ptr->background.green; |
| 2707 back.blue = (png_byte)png_ptr->background.blue; | 2752 back.blue = (png_byte)png_ptr->background.blue; |
| 2708 | 2753 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2737 palette[i].green = (png_byte)png_ptr->background.green; | 2782 palette[i].green = (png_byte)png_ptr->background.green; |
| 2738 palette[i].blue = (png_byte)png_ptr->background.blue; | 2783 palette[i].blue = (png_byte)png_ptr->background.blue; |
| 2739 } | 2784 } |
| 2740 } | 2785 } |
| 2741 } | 2786 } |
| 2742 } | 2787 } |
| 2743 #endif | 2788 #endif |
| 2744 } | 2789 } |
| 2745 #endif | 2790 #endif |
| 2746 | 2791 |
| 2747 #if defined(PNG_READ_BACKGROUND_SUPPORTED) | 2792 #ifdef PNG_READ_BACKGROUND_SUPPORTED |
| 2748 /* Replace any alpha or transparency with the supplied background color. | 2793 /* Replace any alpha or transparency with the supplied background color. |
| 2749 * "background" is already in the screen gamma, while "background_1" is | 2794 * "background" is already in the screen gamma, while "background_1" is |
| 2750 * at a gamma of 1.0. Paletted files have already been taken care of. | 2795 * at a gamma of 1.0. Paletted files have already been taken care of. |
| 2751 */ | 2796 */ |
| 2752 void /* PRIVATE */ | 2797 void /* PRIVATE */ |
| 2753 png_do_background(png_row_infop row_info, png_bytep row, | 2798 png_do_background(png_row_infop row_info, png_bytep row, |
| 2754 png_color_16p trans_values, png_color_16p background | 2799 png_color_16p trans_values, png_color_16p background |
| 2755 #if defined(PNG_READ_GAMMA_SUPPORTED) | 2800 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2756 , png_color_16p background_1, | 2801 , png_color_16p background_1, |
| 2757 png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, | 2802 png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, |
| 2758 png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, | 2803 png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, |
| 2759 png_uint_16pp gamma_16_to_1, int gamma_shift | 2804 png_uint_16pp gamma_16_to_1, int gamma_shift |
| 2760 #endif | 2805 #endif |
| 2761 ) | 2806 ) |
| 2762 { | 2807 { |
| 2763 png_bytep sp, dp; | 2808 png_bytep sp, dp; |
| 2764 png_uint_32 i; | 2809 png_uint_32 i; |
| 2765 png_uint_32 row_width=row_info->width; | 2810 png_uint_32 row_width=row_info->width; |
| 2766 int shift; | 2811 int shift; |
| 2767 | 2812 |
| 2768 png_debug(1, "in png_do_background"); | 2813 png_debug(1, "in png_do_background"); |
| 2814 |
| 2769 if (background != NULL && | 2815 if (background != NULL && |
| 2770 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 2816 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 2771 row != NULL && row_info != NULL && | 2817 row != NULL && row_info != NULL && |
| 2772 #endif | 2818 #endif |
| 2773 (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) || | 2819 (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) || |
| 2774 (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values))) | 2820 (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values))) |
| 2775 { | 2821 { |
| 2776 switch (row_info->color_type) | 2822 switch (row_info->color_type) |
| 2777 { | 2823 { |
| 2778 case PNG_COLOR_TYPE_GRAY: | 2824 case PNG_COLOR_TYPE_GRAY: |
| 2779 { | 2825 { |
| 2780 switch (row_info->bit_depth) | 2826 switch (row_info->bit_depth) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2797 sp++; | 2843 sp++; |
| 2798 } | 2844 } |
| 2799 else | 2845 else |
| 2800 shift--; | 2846 shift--; |
| 2801 } | 2847 } |
| 2802 break; | 2848 break; |
| 2803 } | 2849 } |
| 2804 | 2850 |
| 2805 case 2: | 2851 case 2: |
| 2806 { | 2852 { |
| 2807 #if defined(PNG_READ_GAMMA_SUPPORTED) | 2853 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2808 if (gamma_table != NULL) | 2854 if (gamma_table != NULL) |
| 2809 { | 2855 { |
| 2810 sp = row; | 2856 sp = row; |
| 2811 shift = 6; | 2857 shift = 6; |
| 2812 for (i = 0; i < row_width; i++) | 2858 for (i = 0; i < row_width; i++) |
| 2813 { | 2859 { |
| 2814 if ((png_uint_16)((*sp >> shift) & 0x03) | 2860 if ((png_uint_16)((*sp >> shift) & 0x03) |
| 2815 == trans_values->gray) | 2861 == trans_values->gray) |
| 2816 { | 2862 { |
| 2817 *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); | 2863 *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2854 } | 2900 } |
| 2855 else | 2901 else |
| 2856 shift -= 2; | 2902 shift -= 2; |
| 2857 } | 2903 } |
| 2858 } | 2904 } |
| 2859 break; | 2905 break; |
| 2860 } | 2906 } |
| 2861 | 2907 |
| 2862 case 4: | 2908 case 4: |
| 2863 { | 2909 { |
| 2864 #if defined(PNG_READ_GAMMA_SUPPORTED) | 2910 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2865 if (gamma_table != NULL) | 2911 if (gamma_table != NULL) |
| 2866 { | 2912 { |
| 2867 sp = row; | 2913 sp = row; |
| 2868 shift = 4; | 2914 shift = 4; |
| 2869 for (i = 0; i < row_width; i++) | 2915 for (i = 0; i < row_width; i++) |
| 2870 { | 2916 { |
| 2871 if ((png_uint_16)((*sp >> shift) & 0x0f) | 2917 if ((png_uint_16)((*sp >> shift) & 0x0f) |
| 2872 == trans_values->gray) | 2918 == trans_values->gray) |
| 2873 { | 2919 { |
| 2874 *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); | 2920 *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2911 } | 2957 } |
| 2912 else | 2958 else |
| 2913 shift -= 4; | 2959 shift -= 4; |
| 2914 } | 2960 } |
| 2915 } | 2961 } |
| 2916 break; | 2962 break; |
| 2917 } | 2963 } |
| 2918 | 2964 |
| 2919 case 8: | 2965 case 8: |
| 2920 { | 2966 { |
| 2921 #if defined(PNG_READ_GAMMA_SUPPORTED) | 2967 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2922 if (gamma_table != NULL) | 2968 if (gamma_table != NULL) |
| 2923 { | 2969 { |
| 2924 sp = row; | 2970 sp = row; |
| 2925 for (i = 0; i < row_width; i++, sp++) | 2971 for (i = 0; i < row_width; i++, sp++) |
| 2926 { | 2972 { |
| 2927 if (*sp == trans_values->gray) | 2973 if (*sp == trans_values->gray) |
| 2928 { | 2974 { |
| 2929 *sp = (png_byte)background->gray; | 2975 *sp = (png_byte)background->gray; |
| 2930 } | 2976 } |
| 2931 else | 2977 else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2944 { | 2990 { |
| 2945 *sp = (png_byte)background->gray; | 2991 *sp = (png_byte)background->gray; |
| 2946 } | 2992 } |
| 2947 } | 2993 } |
| 2948 } | 2994 } |
| 2949 break; | 2995 break; |
| 2950 } | 2996 } |
| 2951 | 2997 |
| 2952 case 16: | 2998 case 16: |
| 2953 { | 2999 { |
| 2954 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3000 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 2955 if (gamma_16 != NULL) | 3001 if (gamma_16 != NULL) |
| 2956 { | 3002 { |
| 2957 sp = row; | 3003 sp = row; |
| 2958 for (i = 0; i < row_width; i++, sp += 2) | 3004 for (i = 0; i < row_width; i++, sp += 2) |
| 2959 { | 3005 { |
| 2960 png_uint_16 v; | 3006 png_uint_16 v; |
| 2961 | 3007 |
| 2962 v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); | 3008 v = (png_uint_16)(((*sp) << 8) + *(sp + 1)); |
| 2963 if (v == trans_values->gray) | 3009 if (v == trans_values->gray) |
| 2964 { | 3010 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2993 break; | 3039 break; |
| 2994 } | 3040 } |
| 2995 } | 3041 } |
| 2996 break; | 3042 break; |
| 2997 } | 3043 } |
| 2998 | 3044 |
| 2999 case PNG_COLOR_TYPE_RGB: | 3045 case PNG_COLOR_TYPE_RGB: |
| 3000 { | 3046 { |
| 3001 if (row_info->bit_depth == 8) | 3047 if (row_info->bit_depth == 8) |
| 3002 { | 3048 { |
| 3003 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3049 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3004 if (gamma_table != NULL) | 3050 if (gamma_table != NULL) |
| 3005 { | 3051 { |
| 3006 sp = row; | 3052 sp = row; |
| 3007 for (i = 0; i < row_width; i++, sp += 3) | 3053 for (i = 0; i < row_width; i++, sp += 3) |
| 3008 { | 3054 { |
| 3009 if (*sp == trans_values->red && | 3055 if (*sp == trans_values->red && |
| 3010 *(sp + 1) == trans_values->green && | 3056 *(sp + 1) == trans_values->green && |
| 3011 *(sp + 2) == trans_values->blue) | 3057 *(sp + 2) == trans_values->blue) |
| 3012 { | 3058 { |
| 3013 *sp = (png_byte)background->red; | 3059 *sp = (png_byte)background->red; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 3034 { | 3080 { |
| 3035 *sp = (png_byte)background->red; | 3081 *sp = (png_byte)background->red; |
| 3036 *(sp + 1) = (png_byte)background->green; | 3082 *(sp + 1) = (png_byte)background->green; |
| 3037 *(sp + 2) = (png_byte)background->blue; | 3083 *(sp + 2) = (png_byte)background->blue; |
| 3038 } | 3084 } |
| 3039 } | 3085 } |
| 3040 } | 3086 } |
| 3041 } | 3087 } |
| 3042 else /* if (row_info->bit_depth == 16) */ | 3088 else /* if (row_info->bit_depth == 16) */ |
| 3043 { | 3089 { |
| 3044 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3090 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3045 if (gamma_16 != NULL) | 3091 if (gamma_16 != NULL) |
| 3046 { | 3092 { |
| 3047 sp = row; | 3093 sp = row; |
| 3048 for (i = 0; i < row_width; i++, sp += 6) | 3094 for (i = 0; i < row_width; i++, sp += 6) |
| 3049 { | 3095 { |
| 3050 png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); | 3096 png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1)); |
| 3051 png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); | 3097 png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); |
| 3052 png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); | 3098 png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5)); |
| 3053 if (r == trans_values->red && g == trans_values->green && | 3099 if (r == trans_values->red && g == trans_values->green && |
| 3054 b == trans_values->blue) | 3100 b == trans_values->blue) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3098 } | 3144 } |
| 3099 } | 3145 } |
| 3100 } | 3146 } |
| 3101 break; | 3147 break; |
| 3102 } | 3148 } |
| 3103 | 3149 |
| 3104 case PNG_COLOR_TYPE_GRAY_ALPHA: | 3150 case PNG_COLOR_TYPE_GRAY_ALPHA: |
| 3105 { | 3151 { |
| 3106 if (row_info->bit_depth == 8) | 3152 if (row_info->bit_depth == 8) |
| 3107 { | 3153 { |
| 3108 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3154 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3109 if (gamma_to_1 != NULL && gamma_from_1 != NULL && | 3155 if (gamma_to_1 != NULL && gamma_from_1 != NULL && |
| 3110 gamma_table != NULL) | 3156 gamma_table != NULL) |
| 3111 { | 3157 { |
| 3112 sp = row; | 3158 sp = row; |
| 3113 dp = row; | 3159 dp = row; |
| 3114 for (i = 0; i < row_width; i++, sp += 2, dp++) | 3160 for (i = 0; i < row_width; i++, sp += 2, dp++) |
| 3115 { | 3161 { |
| 3116 png_uint_16 a = *(sp + 1); | 3162 png_uint_16 a = *(sp + 1); |
| 3117 | 3163 |
| 3118 if (a == 0xff) | 3164 if (a == 0xff) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3140 sp = row; | 3186 sp = row; |
| 3141 dp = row; | 3187 dp = row; |
| 3142 for (i = 0; i < row_width; i++, sp += 2, dp++) | 3188 for (i = 0; i < row_width; i++, sp += 2, dp++) |
| 3143 { | 3189 { |
| 3144 png_byte a = *(sp + 1); | 3190 png_byte a = *(sp + 1); |
| 3145 | 3191 |
| 3146 if (a == 0xff) | 3192 if (a == 0xff) |
| 3147 { | 3193 { |
| 3148 *dp = *sp; | 3194 *dp = *sp; |
| 3149 } | 3195 } |
| 3150 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3196 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3151 else if (a == 0) | 3197 else if (a == 0) |
| 3152 { | 3198 { |
| 3153 *dp = (png_byte)background->gray; | 3199 *dp = (png_byte)background->gray; |
| 3154 } | 3200 } |
| 3155 else | 3201 else |
| 3156 { | 3202 { |
| 3157 png_composite(*dp, *sp, a, background_1->gray); | 3203 png_composite(*dp, *sp, a, background_1->gray); |
| 3158 } | 3204 } |
| 3159 #else | 3205 #else |
| 3160 *dp = (png_byte)background->gray; | 3206 *dp = (png_byte)background->gray; |
| 3161 #endif | 3207 #endif |
| 3162 } | 3208 } |
| 3163 } | 3209 } |
| 3164 } | 3210 } |
| 3165 else /* if (png_ptr->bit_depth == 16) */ | 3211 else /* if (png_ptr->bit_depth == 16) */ |
| 3166 { | 3212 { |
| 3167 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3213 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3168 if (gamma_16 != NULL && gamma_16_from_1 != NULL && | 3214 if (gamma_16 != NULL && gamma_16_from_1 != NULL && |
| 3169 gamma_16_to_1 != NULL) | 3215 gamma_16_to_1 != NULL) |
| 3170 { | 3216 { |
| 3171 sp = row; | 3217 sp = row; |
| 3172 dp = row; | 3218 dp = row; |
| 3173 for (i = 0; i < row_width; i++, sp += 4, dp += 2) | 3219 for (i = 0; i < row_width; i++, sp += 4, dp += 2) |
| 3174 { | 3220 { |
| 3175 png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); | 3221 png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); |
| 3176 | 3222 |
| 3177 if (a == (png_uint_16)0xffff) | 3223 if (a == (png_uint_16)0xffff) |
| 3178 { | 3224 { |
| 3179 png_uint_16 v; | 3225 png_uint_16 v; |
| 3180 | 3226 |
| 3181 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; | 3227 v = gamma_16[*(sp + 1) >> gamma_shift][*sp]; |
| 3182 *dp = (png_byte)((v >> 8) & 0xff); | 3228 *dp = (png_byte)((v >> 8) & 0xff); |
| 3183 *(dp + 1) = (png_byte)(v & 0xff); | 3229 *(dp + 1) = (png_byte)(v & 0xff); |
| 3184 } | 3230 } |
| 3185 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3231 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3186 else if (a == 0) | 3232 else if (a == 0) |
| 3187 #else | 3233 #else |
| 3188 else | 3234 else |
| 3189 #endif | 3235 #endif |
| 3190 { | 3236 { |
| 3191 /* Background is already in screen gamma */ | 3237 /* Background is already in screen gamma */ |
| 3192 *dp = (png_byte)((background->gray >> 8) & 0xff); | 3238 *dp = (png_byte)((background->gray >> 8) & 0xff); |
| 3193 *(dp + 1) = (png_byte)(background->gray & 0xff); | 3239 *(dp + 1) = (png_byte)(background->gray & 0xff); |
| 3194 } | 3240 } |
| 3195 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3241 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3196 else | 3242 else |
| 3197 { | 3243 { |
| 3198 png_uint_16 g, v, w; | 3244 png_uint_16 g, v, w; |
| 3199 | 3245 |
| 3200 g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; | 3246 g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp]; |
| 3201 png_composite_16(v, g, a, background_1->gray); | 3247 png_composite_16(v, g, a, background_1->gray); |
| 3202 w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; | 3248 w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8]; |
| 3203 *dp = (png_byte)((w >> 8) & 0xff); | 3249 *dp = (png_byte)((w >> 8) & 0xff); |
| 3204 *(dp + 1) = (png_byte)(w & 0xff); | 3250 *(dp + 1) = (png_byte)(w & 0xff); |
| 3205 } | 3251 } |
| 3206 #endif | 3252 #endif |
| 3207 } | 3253 } |
| 3208 } | 3254 } |
| 3209 else | 3255 else |
| 3210 #endif | 3256 #endif |
| 3211 { | 3257 { |
| 3212 sp = row; | 3258 sp = row; |
| 3213 dp = row; | 3259 dp = row; |
| 3214 for (i = 0; i < row_width; i++, sp += 4, dp += 2) | 3260 for (i = 0; i < row_width; i++, sp += 4, dp += 2) |
| 3215 { | 3261 { |
| 3216 png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); | 3262 png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3)); |
| 3217 if (a == (png_uint_16)0xffff) | 3263 if (a == (png_uint_16)0xffff) |
| 3218 { | 3264 { |
| 3219 png_memcpy(dp, sp, 2); | 3265 png_memcpy(dp, sp, 2); |
| 3220 } | 3266 } |
| 3221 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3267 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3222 else if (a == 0) | 3268 else if (a == 0) |
| 3223 #else | 3269 #else |
| 3224 else | 3270 else |
| 3225 #endif | 3271 #endif |
| 3226 { | 3272 { |
| 3227 *dp = (png_byte)((background->gray >> 8) & 0xff); | 3273 *dp = (png_byte)((background->gray >> 8) & 0xff); |
| 3228 *(dp + 1) = (png_byte)(background->gray & 0xff); | 3274 *(dp + 1) = (png_byte)(background->gray & 0xff); |
| 3229 } | 3275 } |
| 3230 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3276 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3231 else | 3277 else |
| 3232 { | 3278 { |
| 3233 png_uint_16 g, v; | 3279 png_uint_16 g, v; |
| 3234 | 3280 |
| 3235 g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); | 3281 g = (png_uint_16)(((*sp) << 8) + *(sp + 1)); |
| 3236 png_composite_16(v, g, a, background_1->gray); | 3282 png_composite_16(v, g, a, background_1->gray); |
| 3237 *dp = (png_byte)((v >> 8) & 0xff); | 3283 *dp = (png_byte)((v >> 8) & 0xff); |
| 3238 *(dp + 1) = (png_byte)(v & 0xff); | 3284 *(dp + 1) = (png_byte)(v & 0xff); |
| 3239 } | 3285 } |
| 3240 #endif | 3286 #endif |
| 3241 } | 3287 } |
| 3242 } | 3288 } |
| 3243 } | 3289 } |
| 3244 break; | 3290 break; |
| 3245 } | 3291 } |
| 3246 | 3292 |
| 3247 case PNG_COLOR_TYPE_RGB_ALPHA: | 3293 case PNG_COLOR_TYPE_RGB_ALPHA: |
| 3248 { | 3294 { |
| 3249 if (row_info->bit_depth == 8) | 3295 if (row_info->bit_depth == 8) |
| 3250 { | 3296 { |
| 3251 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3297 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3252 if (gamma_to_1 != NULL && gamma_from_1 != NULL && | 3298 if (gamma_to_1 != NULL && gamma_from_1 != NULL && |
| 3253 gamma_table != NULL) | 3299 gamma_table != NULL) |
| 3254 { | 3300 { |
| 3255 sp = row; | 3301 sp = row; |
| 3256 dp = row; | 3302 dp = row; |
| 3257 for (i = 0; i < row_width; i++, sp += 4, dp += 3) | 3303 for (i = 0; i < row_width; i++, sp += 4, dp += 3) |
| 3258 { | 3304 { |
| 3259 png_byte a = *(sp + 3); | 3305 png_byte a = *(sp + 3); |
| 3260 | 3306 |
| 3261 if (a == 0xff) | 3307 if (a == 0xff) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3314 png_composite(*(dp + 1), *(sp + 1), a, | 3360 png_composite(*(dp + 1), *(sp + 1), a, |
| 3315 background->green); | 3361 background->green); |
| 3316 png_composite(*(dp + 2), *(sp + 2), a, | 3362 png_composite(*(dp + 2), *(sp + 2), a, |
| 3317 background->blue); | 3363 background->blue); |
| 3318 } | 3364 } |
| 3319 } | 3365 } |
| 3320 } | 3366 } |
| 3321 } | 3367 } |
| 3322 else /* if (row_info->bit_depth == 16) */ | 3368 else /* if (row_info->bit_depth == 16) */ |
| 3323 { | 3369 { |
| 3324 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3370 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3325 if (gamma_16 != NULL && gamma_16_from_1 != NULL && | 3371 if (gamma_16 != NULL && gamma_16_from_1 != NULL && |
| 3326 gamma_16_to_1 != NULL) | 3372 gamma_16_to_1 != NULL) |
| 3327 { | 3373 { |
| 3328 sp = row; | 3374 sp = row; |
| 3329 dp = row; | 3375 dp = row; |
| 3330 for (i = 0; i < row_width; i++, sp += 8, dp += 6) | 3376 for (i = 0; i < row_width; i++, sp += 8, dp += 6) |
| 3331 { | 3377 { |
| 3332 png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) | 3378 png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6)) |
| 3333 << 8) + (png_uint_16)(*(sp + 7))); | 3379 << 8) + (png_uint_16)(*(sp + 7))); |
| 3334 if (a == (png_uint_16)0xffff) | 3380 if (a == (png_uint_16)0xffff) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3431 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; | 3477 row_info->color_type &= ~PNG_COLOR_MASK_ALPHA; |
| 3432 row_info->channels--; | 3478 row_info->channels--; |
| 3433 row_info->pixel_depth = (png_byte)(row_info->channels * | 3479 row_info->pixel_depth = (png_byte)(row_info->channels * |
| 3434 row_info->bit_depth); | 3480 row_info->bit_depth); |
| 3435 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); | 3481 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); |
| 3436 } | 3482 } |
| 3437 } | 3483 } |
| 3438 } | 3484 } |
| 3439 #endif | 3485 #endif |
| 3440 | 3486 |
| 3441 #if defined(PNG_READ_GAMMA_SUPPORTED) | 3487 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 3442 /* Gamma correct the image, avoiding the alpha channel. Make sure | 3488 /* Gamma correct the image, avoiding the alpha channel. Make sure |
| 3443 * you do this after you deal with the transparency issue on grayscale | 3489 * you do this after you deal with the transparency issue on grayscale |
| 3444 * or RGB images. If your bit depth is 8, use gamma_table, if it | 3490 * or RGB images. If your bit depth is 8, use gamma_table, if it |
| 3445 * is 16, use gamma_16_table and gamma_shift. Build these with | 3491 * is 16, use gamma_16_table and gamma_shift. Build these with |
| 3446 * build_gamma_table(). | 3492 * build_gamma_table(). |
| 3447 */ | 3493 */ |
| 3448 void /* PRIVATE */ | 3494 void /* PRIVATE */ |
| 3449 png_do_gamma(png_row_infop row_info, png_bytep row, | 3495 png_do_gamma(png_row_infop row_info, png_bytep row, |
| 3450 png_bytep gamma_table, png_uint_16pp gamma_16_table, | 3496 png_bytep gamma_table, png_uint_16pp gamma_16_table, |
| 3451 int gamma_shift) | 3497 int gamma_shift) |
| 3452 { | 3498 { |
| 3453 png_bytep sp; | 3499 png_bytep sp; |
| 3454 png_uint_32 i; | 3500 png_uint_32 i; |
| 3455 png_uint_32 row_width=row_info->width; | 3501 png_uint_32 row_width=row_info->width; |
| 3456 | 3502 |
| 3457 png_debug(1, "in png_do_gamma"); | 3503 png_debug(1, "in png_do_gamma"); |
| 3504 |
| 3458 if ( | 3505 if ( |
| 3459 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 3506 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 3460 row != NULL && row_info != NULL && | 3507 row != NULL && row_info != NULL && |
| 3461 #endif | 3508 #endif |
| 3462 ((row_info->bit_depth <= 8 && gamma_table != NULL) || | 3509 ((row_info->bit_depth <= 8 && gamma_table != NULL) || |
| 3463 (row_info->bit_depth == 16 && gamma_16_table != NULL))) | 3510 (row_info->bit_depth == 16 && gamma_16_table != NULL))) |
| 3464 { | 3511 { |
| 3465 switch (row_info->color_type) | 3512 switch (row_info->color_type) |
| 3466 { | 3513 { |
| 3467 case PNG_COLOR_TYPE_RGB: | 3514 case PNG_COLOR_TYPE_RGB: |
| 3468 { | 3515 { |
| 3469 if (row_info->bit_depth == 8) | 3516 if (row_info->bit_depth == 8) |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3572 { | 3619 { |
| 3573 sp = row; | 3620 sp = row; |
| 3574 for (i = 0; i < row_width; i += 4) | 3621 for (i = 0; i < row_width; i += 4) |
| 3575 { | 3622 { |
| 3576 int a = *sp & 0xc0; | 3623 int a = *sp & 0xc0; |
| 3577 int b = *sp & 0x30; | 3624 int b = *sp & 0x30; |
| 3578 int c = *sp & 0x0c; | 3625 int c = *sp & 0x0c; |
| 3579 int d = *sp & 0x03; | 3626 int d = *sp & 0x03; |
| 3580 | 3627 |
| 3581 *sp = (png_byte)( | 3628 *sp = (png_byte)( |
| 3582 ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)
| | 3629 ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)| |
| 3583 ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)
| | 3630 ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)| |
| 3584 ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)
| | 3631 ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)| |
| 3585 ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); | 3632 ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) )); |
| 3586 sp++; | 3633 sp++; |
| 3587 } | 3634 } |
| 3588 } | 3635 } |
| 3589 | 3636 |
| 3590 if (row_info->bit_depth == 4) | 3637 if (row_info->bit_depth == 4) |
| 3591 { | 3638 { |
| 3592 sp = row; | 3639 sp = row; |
| 3593 for (i = 0; i < row_width; i += 2) | 3640 for (i = 0; i < row_width; i += 2) |
| 3594 { | 3641 { |
| 3595 int msb = *sp & 0xf0; | 3642 int msb = *sp & 0xf0; |
| 3596 int lsb = *sp & 0x0f; | 3643 int lsb = *sp & 0x0f; |
| 3597 | 3644 |
| 3598 *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) | 3645 *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0) |
| 3599 | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); | 3646 | (((int)gamma_table[(lsb << 4) | lsb]) >> 4)); |
| 3600 sp++; | 3647 sp++; |
| 3601 } | 3648 } |
| 3602 } | 3649 } |
| 3603 | 3650 |
| 3604 else if (row_info->bit_depth == 8) | 3651 else if (row_info->bit_depth == 8) |
| 3605 { | 3652 { |
| 3606 sp = row; | 3653 sp = row; |
| 3607 for (i = 0; i < row_width; i++) | 3654 for (i = 0; i < row_width; i++) |
| 3608 { | 3655 { |
| 3609 *sp = gamma_table[*sp]; | 3656 *sp = gamma_table[*sp]; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3622 sp += 2; | 3669 sp += 2; |
| 3623 } | 3670 } |
| 3624 } | 3671 } |
| 3625 break; | 3672 break; |
| 3626 } | 3673 } |
| 3627 } | 3674 } |
| 3628 } | 3675 } |
| 3629 } | 3676 } |
| 3630 #endif | 3677 #endif |
| 3631 | 3678 |
| 3632 #if defined(PNG_READ_EXPAND_SUPPORTED) | 3679 #ifdef PNG_READ_EXPAND_SUPPORTED |
| 3633 /* Expands a palette row to an RGB or RGBA row depending | 3680 /* Expands a palette row to an RGB or RGBA row depending |
| 3634 * upon whether you supply trans and num_trans. | 3681 * upon whether you supply trans and num_trans. |
| 3635 */ | 3682 */ |
| 3636 void /* PRIVATE */ | 3683 void /* PRIVATE */ |
| 3637 png_do_expand_palette(png_row_infop row_info, png_bytep row, | 3684 png_do_expand_palette(png_row_infop row_info, png_bytep row, |
| 3638 png_colorp palette, png_bytep trans, int num_trans) | 3685 png_colorp palette, png_bytep trans, int num_trans) |
| 3639 { | 3686 { |
| 3640 int shift, value; | 3687 int shift, value; |
| 3641 png_bytep sp, dp; | 3688 png_bytep sp, dp; |
| 3642 png_uint_32 i; | 3689 png_uint_32 i; |
| 3643 png_uint_32 row_width=row_info->width; | 3690 png_uint_32 row_width=row_info->width; |
| 3644 | 3691 |
| 3645 png_debug(1, "in png_do_expand_palette"); | 3692 png_debug(1, "in png_do_expand_palette"); |
| 3693 |
| 3646 if ( | 3694 if ( |
| 3647 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 3695 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 3648 row != NULL && row_info != NULL && | 3696 row != NULL && row_info != NULL && |
| 3649 #endif | 3697 #endif |
| 3650 row_info->color_type == PNG_COLOR_TYPE_PALETTE) | 3698 row_info->color_type == PNG_COLOR_TYPE_PALETTE) |
| 3651 { | 3699 { |
| 3652 if (row_info->bit_depth < 8) | 3700 if (row_info->bit_depth < 8) |
| 3653 { | 3701 { |
| 3654 switch (row_info->bit_depth) | 3702 switch (row_info->bit_depth) |
| 3655 { | 3703 { |
| 3656 case 1: | 3704 case 1: |
| 3657 { | 3705 { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3782 void /* PRIVATE */ | 3830 void /* PRIVATE */ |
| 3783 png_do_expand(png_row_infop row_info, png_bytep row, | 3831 png_do_expand(png_row_infop row_info, png_bytep row, |
| 3784 png_color_16p trans_value) | 3832 png_color_16p trans_value) |
| 3785 { | 3833 { |
| 3786 int shift, value; | 3834 int shift, value; |
| 3787 png_bytep sp, dp; | 3835 png_bytep sp, dp; |
| 3788 png_uint_32 i; | 3836 png_uint_32 i; |
| 3789 png_uint_32 row_width=row_info->width; | 3837 png_uint_32 row_width=row_info->width; |
| 3790 | 3838 |
| 3791 png_debug(1, "in png_do_expand"); | 3839 png_debug(1, "in png_do_expand"); |
| 3792 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 3840 |
| 3841 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 3793 if (row != NULL && row_info != NULL) | 3842 if (row != NULL && row_info != NULL) |
| 3794 #endif | 3843 #endif |
| 3795 { | 3844 { |
| 3796 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) | 3845 if (row_info->color_type == PNG_COLOR_TYPE_GRAY) |
| 3797 { | 3846 { |
| 3798 png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0); | 3847 png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0); |
| 3799 | 3848 |
| 3800 if (row_info->bit_depth < 8) | 3849 if (row_info->bit_depth < 8) |
| 3801 { | 3850 { |
| 3802 switch (row_info->bit_depth) | 3851 switch (row_info->bit_depth) |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3983 } | 4032 } |
| 3984 row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; | 4033 row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
| 3985 row_info->channels = 4; | 4034 row_info->channels = 4; |
| 3986 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); | 4035 row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2); |
| 3987 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); | 4036 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width); |
| 3988 } | 4037 } |
| 3989 } | 4038 } |
| 3990 } | 4039 } |
| 3991 #endif | 4040 #endif |
| 3992 | 4041 |
| 3993 #if defined(PNG_READ_DITHER_SUPPORTED) | 4042 #ifdef PNG_READ_DITHER_SUPPORTED |
| 3994 void /* PRIVATE */ | 4043 void /* PRIVATE */ |
| 3995 png_do_dither(png_row_infop row_info, png_bytep row, | 4044 png_do_dither(png_row_infop row_info, png_bytep row, |
| 3996 png_bytep palette_lookup, png_bytep dither_lookup) | 4045 png_bytep palette_lookup, png_bytep dither_lookup) |
| 3997 { | 4046 { |
| 3998 png_bytep sp, dp; | 4047 png_bytep sp, dp; |
| 3999 png_uint_32 i; | 4048 png_uint_32 i; |
| 4000 png_uint_32 row_width=row_info->width; | 4049 png_uint_32 row_width=row_info->width; |
| 4001 | 4050 |
| 4002 png_debug(1, "in png_do_dither"); | 4051 png_debug(1, "in png_do_dither"); |
| 4003 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 4052 |
| 4053 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 4004 if (row != NULL && row_info != NULL) | 4054 if (row != NULL && row_info != NULL) |
| 4005 #endif | 4055 #endif |
| 4006 { | 4056 { |
| 4007 if (row_info->color_type == PNG_COLOR_TYPE_RGB && | 4057 if (row_info->color_type == PNG_COLOR_TYPE_RGB && |
| 4008 palette_lookup && row_info->bit_depth == 8) | 4058 palette_lookup && row_info->bit_depth == 8) |
| 4009 { | 4059 { |
| 4010 int r, g, b, p; | 4060 int r, g, b, p; |
| 4011 sp = row; | 4061 sp = row; |
| 4012 dp = row; | 4062 dp = row; |
| 4013 for (i = 0; i < row_width; i++) | 4063 for (i = 0; i < row_width; i++) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4075 for (i = 0; i < row_width; i++, sp++) | 4125 for (i = 0; i < row_width; i++, sp++) |
| 4076 { | 4126 { |
| 4077 *sp = dither_lookup[*sp]; | 4127 *sp = dither_lookup[*sp]; |
| 4078 } | 4128 } |
| 4079 } | 4129 } |
| 4080 } | 4130 } |
| 4081 } | 4131 } |
| 4082 #endif | 4132 #endif |
| 4083 | 4133 |
| 4084 #ifdef PNG_FLOATING_POINT_SUPPORTED | 4134 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 4085 #if defined(PNG_READ_GAMMA_SUPPORTED) | 4135 #ifdef PNG_READ_GAMMA_SUPPORTED |
| 4086 static PNG_CONST int png_gamma_shift[] = | 4136 static PNG_CONST int png_gamma_shift[] = |
| 4087 {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00}; | 4137 {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00}; |
| 4088 | 4138 |
| 4089 /* We build the 8- or 16-bit gamma tables here. Note that for 16-bit | 4139 /* We build the 8- or 16-bit gamma tables here. Note that for 16-bit |
| 4090 * tables, we don't make a full table if we are reducing to 8-bit in | 4140 * tables, we don't make a full table if we are reducing to 8-bit in |
| 4091 * the future. Note also how the gamma_16 tables are segmented so that | 4141 * the future. Note also how the gamma_16 tables are segmented so that |
| 4092 * we don't need to allocate > 64K chunks for a full 16-bit table. | 4142 * we don't need to allocate > 64K chunks for a full 16-bit table. |
| 4143 * |
| 4144 * See the PNG extensions document for an integer algorithm for creating |
| 4145 * the gamma tables. Maybe we will implement that here someday. |
| 4146 * |
| 4147 * We should only reach this point if |
| 4148 * |
| 4149 * the file_gamma is known (i.e., the gAMA or sRGB chunk is present, |
| 4150 * or the application has provided a file_gamma) |
| 4151 * |
| 4152 * AND |
| 4153 * { |
| 4154 * the screen_gamma is known |
| 4155 * OR |
| 4156 * |
| 4157 * RGB_to_gray transformation is being performed |
| 4158 * } |
| 4159 * |
| 4160 * AND |
| 4161 * { |
| 4162 * the screen_gamma is different from the reciprocal of the |
| 4163 * file_gamma by more than the specified threshold |
| 4164 * |
| 4165 * OR |
| 4166 * |
| 4167 * a background color has been specified and the file_gamma |
| 4168 * and screen_gamma are not 1.0, within the specified threshold. |
| 4169 * } |
| 4093 */ | 4170 */ |
| 4171 |
| 4094 void /* PRIVATE */ | 4172 void /* PRIVATE */ |
| 4095 png_build_gamma_table(png_structp png_ptr) | 4173 png_build_gamma_table(png_structp png_ptr) |
| 4096 { | 4174 { |
| 4097 png_debug(1, "in png_build_gamma_table"); | 4175 png_debug(1, "in png_build_gamma_table"); |
| 4098 | 4176 |
| 4099 if (png_ptr->bit_depth <= 8) | 4177 if (png_ptr->bit_depth <= 8) |
| 4100 { | 4178 { |
| 4101 int i; | 4179 int i; |
| 4102 double g; | 4180 double g; |
| 4103 | 4181 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4193 | 4271 |
| 4194 png_ptr->gamma_shift = (png_byte)shift; | 4272 png_ptr->gamma_shift = (png_byte)shift; |
| 4195 | 4273 |
| 4196 num = (1 << (8 - shift)); | 4274 num = (1 << (8 - shift)); |
| 4197 | 4275 |
| 4198 if (png_ptr->screen_gamma > .000001) | 4276 if (png_ptr->screen_gamma > .000001) |
| 4199 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); | 4277 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); |
| 4200 else | 4278 else |
| 4201 g = 1.0; | 4279 g = 1.0; |
| 4202 | 4280 |
| 4203 png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr, | 4281 png_ptr->gamma_16_table = (png_uint_16pp)png_calloc(png_ptr, |
| 4204 (png_uint_32)(num * png_sizeof(png_uint_16p))); | 4282 (png_uint_32)(num * png_sizeof(png_uint_16p))); |
| 4205 png_memset(png_ptr->gamma_16_table, 0, num * png_sizeof(png_uint_16p)); | |
| 4206 | 4283 |
| 4207 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) | 4284 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) |
| 4208 { | 4285 { |
| 4209 double fin, fout; | 4286 double fin, fout; |
| 4210 png_uint_32 last, max; | 4287 png_uint_32 last, max; |
| 4211 | 4288 |
| 4212 for (i = 0; i < num; i++) | 4289 for (i = 0; i < num; i++) |
| 4213 { | 4290 { |
| 4214 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, | 4291 png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, |
| 4215 (png_uint_32)(256 * png_sizeof(png_uint_16))); | 4292 (png_uint_32)(256 * png_sizeof(png_uint_16))); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4255 } | 4332 } |
| 4256 } | 4333 } |
| 4257 | 4334 |
| 4258 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ | 4335 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ |
| 4259 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) | 4336 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) |
| 4260 if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) | 4337 if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) |
| 4261 { | 4338 { |
| 4262 | 4339 |
| 4263 g = 1.0 / (png_ptr->gamma); | 4340 g = 1.0 / (png_ptr->gamma); |
| 4264 | 4341 |
| 4265 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr, | 4342 png_ptr->gamma_16_to_1 = (png_uint_16pp)png_calloc(png_ptr, |
| 4266 (png_uint_32)(num * png_sizeof(png_uint_16p ))); | 4343 (png_uint_32)(num * png_sizeof(png_uint_16p ))); |
| 4267 png_memset(png_ptr->gamma_16_to_1, 0, num * png_sizeof(png_uint_16p)); | |
| 4268 | 4344 |
| 4269 for (i = 0; i < num; i++) | 4345 for (i = 0; i < num; i++) |
| 4270 { | 4346 { |
| 4271 png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, | 4347 png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, |
| 4272 (png_uint_32)(256 * png_sizeof(png_uint_16))); | 4348 (png_uint_32)(256 * png_sizeof(png_uint_16))); |
| 4273 | 4349 |
| 4274 ig = (((png_uint_32)i * | 4350 ig = (((png_uint_32)i * |
| 4275 (png_uint_32)png_gamma_shift[shift]) >> 4); | 4351 (png_uint_32)png_gamma_shift[shift]) >> 4); |
| 4276 for (j = 0; j < 256; j++) | 4352 for (j = 0; j < 256; j++) |
| 4277 { | 4353 { |
| 4278 png_ptr->gamma_16_to_1[i][j] = | 4354 png_ptr->gamma_16_to_1[i][j] = |
| 4279 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / | 4355 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / |
| 4280 65535.0, g) * 65535.0 + .5); | 4356 65535.0, g) * 65535.0 + .5); |
| 4281 } | 4357 } |
| 4282 } | 4358 } |
| 4283 | 4359 |
| 4284 if (png_ptr->screen_gamma > 0.000001) | 4360 if (png_ptr->screen_gamma > 0.000001) |
| 4285 g = 1.0 / png_ptr->screen_gamma; | 4361 g = 1.0 / png_ptr->screen_gamma; |
| 4286 | 4362 |
| 4287 else | 4363 else |
| 4288 g = png_ptr->gamma; /* Probably doing rgb_to_gray */ | 4364 g = png_ptr->gamma; /* Probably doing rgb_to_gray */ |
| 4289 | 4365 |
| 4290 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr, | 4366 png_ptr->gamma_16_from_1 = (png_uint_16pp)png_calloc(png_ptr, |
| 4291 (png_uint_32)(num * png_sizeof(png_uint_16p))); | 4367 (png_uint_32)(num * png_sizeof(png_uint_16p))); |
| 4292 png_memset(png_ptr->gamma_16_from_1, 0, | |
| 4293 num * png_sizeof(png_uint_16p)); | |
| 4294 | 4368 |
| 4295 for (i = 0; i < num; i++) | 4369 for (i = 0; i < num; i++) |
| 4296 { | 4370 { |
| 4297 png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, | 4371 png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, |
| 4298 (png_uint_32)(256 * png_sizeof(png_uint_16))); | 4372 (png_uint_32)(256 * png_sizeof(png_uint_16))); |
| 4299 | 4373 |
| 4300 ig = (((png_uint_32)i * | 4374 ig = (((png_uint_32)i * |
| 4301 (png_uint_32)png_gamma_shift[shift]) >> 4); | 4375 (png_uint_32)png_gamma_shift[shift]) >> 4); |
| 4302 | 4376 |
| 4303 for (j = 0; j < 256; j++) | 4377 for (j = 0; j < 256; j++) |
| 4304 { | 4378 { |
| 4305 png_ptr->gamma_16_from_1[i][j] = | 4379 png_ptr->gamma_16_from_1[i][j] = |
| 4306 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / | 4380 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / |
| 4307 65535.0, g) * 65535.0 + .5); | 4381 65535.0, g) * 65535.0 + .5); |
| 4308 } | 4382 } |
| 4309 } | 4383 } |
| 4310 } | 4384 } |
| 4311 #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ | 4385 #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ |
| 4312 } | 4386 } |
| 4313 } | 4387 } |
| 4314 #endif | 4388 #endif |
| 4315 /* To do: install integer version of png_build_gamma_table here */ | 4389 /* To do: install integer version of png_build_gamma_table here */ |
| 4316 #endif | 4390 #endif |
| 4317 | 4391 |
| 4318 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 4392 #ifdef PNG_MNG_FEATURES_SUPPORTED |
| 4319 /* Undoes intrapixel differencing */ | 4393 /* Undoes intrapixel differencing */ |
| 4320 void /* PRIVATE */ | 4394 void /* PRIVATE */ |
| 4321 png_do_read_intrapixel(png_row_infop row_info, png_bytep row) | 4395 png_do_read_intrapixel(png_row_infop row_info, png_bytep row) |
| 4322 { | 4396 { |
| 4323 png_debug(1, "in png_do_read_intrapixel"); | 4397 png_debug(1, "in png_do_read_intrapixel"); |
| 4398 |
| 4324 if ( | 4399 if ( |
| 4325 #if defined(PNG_USELESS_TESTS_SUPPORTED) | 4400 #ifdef PNG_USELESS_TESTS_SUPPORTED |
| 4326 row != NULL && row_info != NULL && | 4401 row != NULL && row_info != NULL && |
| 4327 #endif | 4402 #endif |
| 4328 (row_info->color_type & PNG_COLOR_MASK_COLOR)) | 4403 (row_info->color_type & PNG_COLOR_MASK_COLOR)) |
| 4329 { | 4404 { |
| 4330 int bytes_per_pixel; | 4405 int bytes_per_pixel; |
| 4331 png_uint_32 row_width = row_info->width; | 4406 png_uint_32 row_width = row_info->width; |
| 4332 if (row_info->bit_depth == 8) | 4407 if (row_info->bit_depth == 8) |
| 4333 { | 4408 { |
| 4334 png_bytep rp; | 4409 png_bytep rp; |
| 4335 png_uint_32 i; | 4410 png_uint_32 i; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4373 *(rp ) = (png_byte)((red >> 8) & 0xff); | 4448 *(rp ) = (png_byte)((red >> 8) & 0xff); |
| 4374 *(rp+1) = (png_byte)(red & 0xff); | 4449 *(rp+1) = (png_byte)(red & 0xff); |
| 4375 *(rp+4) = (png_byte)((blue >> 8) & 0xff); | 4450 *(rp+4) = (png_byte)((blue >> 8) & 0xff); |
| 4376 *(rp+5) = (png_byte)(blue & 0xff); | 4451 *(rp+5) = (png_byte)(blue & 0xff); |
| 4377 } | 4452 } |
| 4378 } | 4453 } |
| 4379 } | 4454 } |
| 4380 } | 4455 } |
| 4381 #endif /* PNG_MNG_FEATURES_SUPPORTED */ | 4456 #endif /* PNG_MNG_FEATURES_SUPPORTED */ |
| 4382 #endif /* PNG_READ_SUPPORTED */ | 4457 #endif /* PNG_READ_SUPPORTED */ |
| OLD | NEW |