12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 /* pngrtran.c - transforms the data in a row for PNG readers
26 *
27 * This file is available under and governed by the GNU General Public
28 * License version 2 only, as published by the Free Software Foundation.
29 * However, the following notice accompanied the original version of this
30 * file and, per its terms, should not be removed:
31 *
32 * Last changed in libpng 1.6.22 [May 26, 2016]
33 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
36 *
37 * This code is released under the libpng license.
38 * For conditions of distribution and use, see the disclaimer
39 * and license in png.h
40 *
41 * This file contains functions optionally called by an application
42 * in order to tell libpng how to handle data when reading a PNG.
43 * Transformations that are used in both reading and writing are
44 * in pngtrans.c.
45 */
46
47 #include "pngpriv.h"
48
49 #ifdef PNG_READ_SUPPORTED
50
51 /* Set the action on getting a CRC error for an ancillary or critical chunk. */
52 void PNGAPI
440 typedef png_dsort * png_dsortp;
441 typedef png_dsort * * png_dsortpp;
442
443 void PNGAPI
444 png_set_quantize(png_structrp png_ptr, png_colorp palette,
445 int num_palette, int maximum_colors, png_const_uint_16p histogram,
446 int full_quantize)
447 {
448 png_debug(1, "in png_set_quantize");
449
450 if (png_rtran_ok(png_ptr, 0) == 0)
451 return;
452
453 png_ptr->transformations |= PNG_QUANTIZE;
454
455 if (full_quantize == 0)
456 {
457 int i;
458
459 png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
460 (png_uint_32)(num_palette * (sizeof (png_byte))));
461 for (i = 0; i < num_palette; i++)
462 png_ptr->quantize_index[i] = (png_byte)i;
463 }
464
465 if (num_palette > maximum_colors)
466 {
467 if (histogram != NULL)
468 {
469 /* This is easy enough, just throw out the least used colors.
470 * Perhaps not the best solution, but good enough.
471 */
472
473 int i;
474
475 /* Initialize an array to sort colors */
476 png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
477 (png_uint_32)(num_palette * (sizeof (png_byte))));
478
479 /* Initialize the quantize_sort array */
480 for (i = 0; i < num_palette; i++)
481 png_ptr->quantize_sort[i] = (png_byte)i;
482
483 /* Find the least used palette entries by starting a
484 * bubble sort, and running it until we have sorted
485 * out enough colors. Note that we don't care about
486 * sorting all the colors, just finding which are
487 * least used.
488 */
489
490 for (i = num_palette - 1; i >= maximum_colors; i--)
491 {
492 int done; /* To stop early if the list is pre-sorted */
493 int j;
494
495 done = 1;
496 for (j = 0; j < i; j++)
497 {
591 else
592 {
593 /* This is much harder to do simply (and quickly). Perhaps
594 * we need to go through a median cut routine, but those
595 * don't always behave themselves with only a few colors
596 * as input. So we will just find the closest two colors,
597 * and throw out one of them (chosen somewhat randomly).
598 * [We don't understand this at all, so if someone wants to
599 * work on improving it, be our guest - AED, GRP]
600 */
601 int i;
602 int max_d;
603 int num_new_palette;
604 png_dsortp t;
605 png_dsortpp hash;
606
607 t = NULL;
608
609 /* Initialize palette index arrays */
610 png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
611 (png_uint_32)(num_palette * (sizeof (png_byte))));
612 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
613 (png_uint_32)(num_palette * (sizeof (png_byte))));
614
615 /* Initialize the sort array */
616 for (i = 0; i < num_palette; i++)
617 {
618 png_ptr->index_to_palette[i] = (png_byte)i;
619 png_ptr->palette_to_index[i] = (png_byte)i;
620 }
621
622 hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
623 (sizeof (png_dsortp))));
624
625 num_new_palette = num_palette;
626
627 /* Initial wild guess at how far apart the farthest pixel
628 * pair we will be eliminating will be. Larger
629 * numbers mean more areas will be allocated, Smaller
630 * numbers run the risk of not saving enough data, and
631 * having to do this all over again.
632 *
633 * I have not done extensive checking on this number.
2161 * a bit depth of 1, you would end up with bytes that only contained
2162 * the numbers 0 or 1. If you would rather they contain 0 and 255, use
2163 * png_do_shift() after this.
2164 */
2165 static void
2166 png_do_unpack(png_row_infop row_info, png_bytep row)
2167 {
2168 png_debug(1, "in png_do_unpack");
2169
2170 if (row_info->bit_depth < 8)
2171 {
2172 png_uint_32 i;
2173 png_uint_32 row_width=row_info->width;
2174
2175 switch (row_info->bit_depth)
2176 {
2177 case 1:
2178 {
2179 png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
2180 png_bytep dp = row + (png_size_t)row_width - 1;
2181 png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
2182 for (i = 0; i < row_width; i++)
2183 {
2184 *dp = (png_byte)((*sp >> shift) & 0x01);
2185
2186 if (shift == 7)
2187 {
2188 shift = 0;
2189 sp--;
2190 }
2191
2192 else
2193 shift++;
2194
2195 dp--;
2196 }
2197 break;
2198 }
2199
2200 case 2:
2201 {
2202
2203 png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
2204 png_bytep dp = row + (png_size_t)row_width - 1;
2205 png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
2206 for (i = 0; i < row_width; i++)
2207 {
2208 *dp = (png_byte)((*sp >> shift) & 0x03);
2209
2210 if (shift == 6)
2211 {
2212 shift = 0;
2213 sp--;
2214 }
2215
2216 else
2217 shift += 2;
2218
2219 dp--;
2220 }
2221 break;
2222 }
2223
2224 case 4:
2225 {
2226 png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
2227 png_bytep dp = row + (png_size_t)row_width - 1;
2228 png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
2229 for (i = 0; i < row_width; i++)
2230 {
2231 *dp = (png_byte)((*sp >> shift) & 0x0f);
2232
2233 if (shift == 4)
2234 {
2235 shift = 0;
2236 sp--;
2237 }
2238
2239 else
2240 shift = 4;
2241
2242 dp--;
2243 }
2244 break;
2245 }
2246
2247 default:
2248 break;
3234
3235 png_debug(1, "in png_do_compose");
3236
3237 {
3238 switch (row_info->color_type)
3239 {
3240 case PNG_COLOR_TYPE_GRAY:
3241 {
3242 switch (row_info->bit_depth)
3243 {
3244 case 1:
3245 {
3246 sp = row;
3247 shift = 7;
3248 for (i = 0; i < row_width; i++)
3249 {
3250 if ((png_uint_16)((*sp >> shift) & 0x01)
3251 == png_ptr->trans_color.gray)
3252 {
3253 unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
3254 tmp |= png_ptr->background.gray << shift;
3255 *sp = (png_byte)(tmp & 0xff);
3256 }
3257
3258 if (shift == 0)
3259 {
3260 shift = 7;
3261 sp++;
3262 }
3263
3264 else
3265 shift--;
3266 }
3267 break;
3268 }
3269
3270 case 2:
3271 {
3272 #ifdef PNG_READ_GAMMA_SUPPORTED
3273 if (gamma_table != NULL)
3274 {
3275 sp = row;
3276 shift = 6;
3277 for (i = 0; i < row_width; i++)
3278 {
3279 if ((png_uint_16)((*sp >> shift) & 0x03)
3280 == png_ptr->trans_color.gray)
3281 {
3282 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3283 tmp |= png_ptr->background.gray << shift;
3284 *sp = (png_byte)(tmp & 0xff);
3285 }
3286
3287 else
3288 {
3289 unsigned int p = (*sp >> shift) & 0x03;
3290 unsigned int g = (gamma_table [p | (p << 2) |
3291 (p << 4) | (p << 6)] >> 6) & 0x03;
3292 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3293 tmp |= g << shift;
3294 *sp = (png_byte)(tmp & 0xff);
3295 }
3296
3297 if (shift == 0)
3298 {
3299 shift = 6;
3300 sp++;
3301 }
3302
3303 else
3304 shift -= 2;
3305 }
3306 }
3307
3308 else
3309 #endif
3310 {
3311 sp = row;
3312 shift = 6;
3313 for (i = 0; i < row_width; i++)
3314 {
3315 if ((png_uint_16)((*sp >> shift) & 0x03)
3316 == png_ptr->trans_color.gray)
3317 {
3318 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3319 tmp |= png_ptr->background.gray << shift;
3320 *sp = (png_byte)(tmp & 0xff);
3321 }
3322
3323 if (shift == 0)
3324 {
3325 shift = 6;
3326 sp++;
3327 }
3328
3329 else
3330 shift -= 2;
3331 }
3332 }
3333 break;
3334 }
3335
3336 case 4:
3337 {
3338 #ifdef PNG_READ_GAMMA_SUPPORTED
3339 if (gamma_table != NULL)
3340 {
3341 sp = row;
3342 shift = 4;
3343 for (i = 0; i < row_width; i++)
3344 {
3345 if ((png_uint_16)((*sp >> shift) & 0x0f)
3346 == png_ptr->trans_color.gray)
3347 {
3348 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3349 tmp |= png_ptr->background.gray << shift;
3350 *sp = (png_byte)(tmp & 0xff);
3351 }
3352
3353 else
3354 {
3355 unsigned int p = (*sp >> shift) & 0x0f;
3356 unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
3357 0x0f;
3358 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3359 tmp |= g << shift;
3360 *sp = (png_byte)(tmp & 0xff);
3361 }
3362
3363 if (shift == 0)
3364 {
3365 shift = 4;
3366 sp++;
3367 }
3368
3369 else
3370 shift -= 4;
3371 }
3372 }
3373
3374 else
3375 #endif
3376 {
3377 sp = row;
3378 shift = 4;
3379 for (i = 0; i < row_width; i++)
3380 {
3381 if ((png_uint_16)((*sp >> shift) & 0x0f)
3382 == png_ptr->trans_color.gray)
3383 {
3384 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3385 tmp |= png_ptr->background.gray << shift;
3386 *sp = (png_byte)(tmp & 0xff);
3387 }
3388
3389 if (shift == 0)
3390 {
3391 shift = 4;
3392 sp++;
3393 }
3394
3395 else
3396 shift -= 4;
3397 }
3398 }
3399 break;
3400 }
3401
3402 case 8:
3403 {
3404 #ifdef PNG_READ_GAMMA_SUPPORTED
3405 if (gamma_table != NULL)
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 /* pngrtran.c - transforms the data in a row for PNG readers
26 *
27 * This file is available under and governed by the GNU General Public
28 * License version 2 only, as published by the Free Software Foundation.
29 * However, the following notice accompanied the original version of this
30 * file and, per its terms, should not be removed:
31 *
32 * Last changed in libpng 1.6.24 [August 4, 2016]
33 * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson
34 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
35 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
36 *
37 * This code is released under the libpng license.
38 * For conditions of distribution and use, see the disclaimer
39 * and license in png.h
40 *
41 * This file contains functions optionally called by an application
42 * in order to tell libpng how to handle data when reading a PNG.
43 * Transformations that are used in both reading and writing are
44 * in pngtrans.c.
45 */
46
47 #include "pngpriv.h"
48
49 #ifdef PNG_READ_SUPPORTED
50
51 /* Set the action on getting a CRC error for an ancillary or critical chunk. */
52 void PNGAPI
440 typedef png_dsort * png_dsortp;
441 typedef png_dsort * * png_dsortpp;
442
443 void PNGAPI
444 png_set_quantize(png_structrp png_ptr, png_colorp palette,
445 int num_palette, int maximum_colors, png_const_uint_16p histogram,
446 int full_quantize)
447 {
448 png_debug(1, "in png_set_quantize");
449
450 if (png_rtran_ok(png_ptr, 0) == 0)
451 return;
452
453 png_ptr->transformations |= PNG_QUANTIZE;
454
455 if (full_quantize == 0)
456 {
457 int i;
458
459 png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
460 (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
461 for (i = 0; i < num_palette; i++)
462 png_ptr->quantize_index[i] = (png_byte)i;
463 }
464
465 if (num_palette > maximum_colors)
466 {
467 if (histogram != NULL)
468 {
469 /* This is easy enough, just throw out the least used colors.
470 * Perhaps not the best solution, but good enough.
471 */
472
473 int i;
474
475 /* Initialize an array to sort colors */
476 png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
477 (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
478
479 /* Initialize the quantize_sort array */
480 for (i = 0; i < num_palette; i++)
481 png_ptr->quantize_sort[i] = (png_byte)i;
482
483 /* Find the least used palette entries by starting a
484 * bubble sort, and running it until we have sorted
485 * out enough colors. Note that we don't care about
486 * sorting all the colors, just finding which are
487 * least used.
488 */
489
490 for (i = num_palette - 1; i >= maximum_colors; i--)
491 {
492 int done; /* To stop early if the list is pre-sorted */
493 int j;
494
495 done = 1;
496 for (j = 0; j < i; j++)
497 {
591 else
592 {
593 /* This is much harder to do simply (and quickly). Perhaps
594 * we need to go through a median cut routine, but those
595 * don't always behave themselves with only a few colors
596 * as input. So we will just find the closest two colors,
597 * and throw out one of them (chosen somewhat randomly).
598 * [We don't understand this at all, so if someone wants to
599 * work on improving it, be our guest - AED, GRP]
600 */
601 int i;
602 int max_d;
603 int num_new_palette;
604 png_dsortp t;
605 png_dsortpp hash;
606
607 t = NULL;
608
609 /* Initialize palette index arrays */
610 png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
611 (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
612 png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
613 (png_uint_32)((png_uint_32)num_palette * (sizeof (png_byte))));
614
615 /* Initialize the sort array */
616 for (i = 0; i < num_palette; i++)
617 {
618 png_ptr->index_to_palette[i] = (png_byte)i;
619 png_ptr->palette_to_index[i] = (png_byte)i;
620 }
621
622 hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
623 (sizeof (png_dsortp))));
624
625 num_new_palette = num_palette;
626
627 /* Initial wild guess at how far apart the farthest pixel
628 * pair we will be eliminating will be. Larger
629 * numbers mean more areas will be allocated, Smaller
630 * numbers run the risk of not saving enough data, and
631 * having to do this all over again.
632 *
633 * I have not done extensive checking on this number.
2161 * a bit depth of 1, you would end up with bytes that only contained
2162 * the numbers 0 or 1. If you would rather they contain 0 and 255, use
2163 * png_do_shift() after this.
2164 */
2165 static void
2166 png_do_unpack(png_row_infop row_info, png_bytep row)
2167 {
2168 png_debug(1, "in png_do_unpack");
2169
2170 if (row_info->bit_depth < 8)
2171 {
2172 png_uint_32 i;
2173 png_uint_32 row_width=row_info->width;
2174
2175 switch (row_info->bit_depth)
2176 {
2177 case 1:
2178 {
2179 png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
2180 png_bytep dp = row + (png_size_t)row_width - 1;
2181 png_uint_32 shift = 7U - ((row_width + 7U) & 0x07);
2182 for (i = 0; i < row_width; i++)
2183 {
2184 *dp = (png_byte)((*sp >> shift) & 0x01);
2185
2186 if (shift == 7)
2187 {
2188 shift = 0;
2189 sp--;
2190 }
2191
2192 else
2193 shift++;
2194
2195 dp--;
2196 }
2197 break;
2198 }
2199
2200 case 2:
2201 {
2202
2203 png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
2204 png_bytep dp = row + (png_size_t)row_width - 1;
2205 png_uint_32 shift = ((3U - ((row_width + 3U) & 0x03)) << 1);
2206 for (i = 0; i < row_width; i++)
2207 {
2208 *dp = (png_byte)((*sp >> shift) & 0x03);
2209
2210 if (shift == 6)
2211 {
2212 shift = 0;
2213 sp--;
2214 }
2215
2216 else
2217 shift += 2;
2218
2219 dp--;
2220 }
2221 break;
2222 }
2223
2224 case 4:
2225 {
2226 png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
2227 png_bytep dp = row + (png_size_t)row_width - 1;
2228 png_uint_32 shift = ((1U - ((row_width + 1U) & 0x01)) << 2);
2229 for (i = 0; i < row_width; i++)
2230 {
2231 *dp = (png_byte)((*sp >> shift) & 0x0f);
2232
2233 if (shift == 4)
2234 {
2235 shift = 0;
2236 sp--;
2237 }
2238
2239 else
2240 shift = 4;
2241
2242 dp--;
2243 }
2244 break;
2245 }
2246
2247 default:
2248 break;
3234
3235 png_debug(1, "in png_do_compose");
3236
3237 {
3238 switch (row_info->color_type)
3239 {
3240 case PNG_COLOR_TYPE_GRAY:
3241 {
3242 switch (row_info->bit_depth)
3243 {
3244 case 1:
3245 {
3246 sp = row;
3247 shift = 7;
3248 for (i = 0; i < row_width; i++)
3249 {
3250 if ((png_uint_16)((*sp >> shift) & 0x01)
3251 == png_ptr->trans_color.gray)
3252 {
3253 unsigned int tmp = *sp & (0x7f7f >> (7 - shift));
3254 tmp |=
3255 (unsigned int)(png_ptr->background.gray << shift);
3256 *sp = (png_byte)(tmp & 0xff);
3257 }
3258
3259 if (shift == 0)
3260 {
3261 shift = 7;
3262 sp++;
3263 }
3264
3265 else
3266 shift--;
3267 }
3268 break;
3269 }
3270
3271 case 2:
3272 {
3273 #ifdef PNG_READ_GAMMA_SUPPORTED
3274 if (gamma_table != NULL)
3275 {
3276 sp = row;
3277 shift = 6;
3278 for (i = 0; i < row_width; i++)
3279 {
3280 if ((png_uint_16)((*sp >> shift) & 0x03)
3281 == png_ptr->trans_color.gray)
3282 {
3283 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3284 tmp |=
3285 (unsigned int)png_ptr->background.gray << shift;
3286 *sp = (png_byte)(tmp & 0xff);
3287 }
3288
3289 else
3290 {
3291 unsigned int p = (*sp >> shift) & 0x03;
3292 unsigned int g = (gamma_table [p | (p << 2) |
3293 (p << 4) | (p << 6)] >> 6) & 0x03;
3294 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3295 tmp |= (unsigned int)(g << shift);
3296 *sp = (png_byte)(tmp & 0xff);
3297 }
3298
3299 if (shift == 0)
3300 {
3301 shift = 6;
3302 sp++;
3303 }
3304
3305 else
3306 shift -= 2;
3307 }
3308 }
3309
3310 else
3311 #endif
3312 {
3313 sp = row;
3314 shift = 6;
3315 for (i = 0; i < row_width; i++)
3316 {
3317 if ((png_uint_16)((*sp >> shift) & 0x03)
3318 == png_ptr->trans_color.gray)
3319 {
3320 unsigned int tmp = *sp & (0x3f3f >> (6 - shift));
3321 tmp |=
3322 (unsigned int)png_ptr->background.gray << shift;
3323 *sp = (png_byte)(tmp & 0xff);
3324 }
3325
3326 if (shift == 0)
3327 {
3328 shift = 6;
3329 sp++;
3330 }
3331
3332 else
3333 shift -= 2;
3334 }
3335 }
3336 break;
3337 }
3338
3339 case 4:
3340 {
3341 #ifdef PNG_READ_GAMMA_SUPPORTED
3342 if (gamma_table != NULL)
3343 {
3344 sp = row;
3345 shift = 4;
3346 for (i = 0; i < row_width; i++)
3347 {
3348 if ((png_uint_16)((*sp >> shift) & 0x0f)
3349 == png_ptr->trans_color.gray)
3350 {
3351 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3352 tmp |=
3353 (unsigned int)(png_ptr->background.gray << shift);
3354 *sp = (png_byte)(tmp & 0xff);
3355 }
3356
3357 else
3358 {
3359 unsigned int p = (*sp >> shift) & 0x0f;
3360 unsigned int g = (gamma_table[p | (p << 4)] >> 4) &
3361 0x0f;
3362 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3363 tmp |= (unsigned int)(g << shift);
3364 *sp = (png_byte)(tmp & 0xff);
3365 }
3366
3367 if (shift == 0)
3368 {
3369 shift = 4;
3370 sp++;
3371 }
3372
3373 else
3374 shift -= 4;
3375 }
3376 }
3377
3378 else
3379 #endif
3380 {
3381 sp = row;
3382 shift = 4;
3383 for (i = 0; i < row_width; i++)
3384 {
3385 if ((png_uint_16)((*sp >> shift) & 0x0f)
3386 == png_ptr->trans_color.gray)
3387 {
3388 unsigned int tmp = *sp & (0x0f0f >> (4 - shift));
3389 tmp |=
3390 (unsigned int)(png_ptr->background.gray << shift);
3391 *sp = (png_byte)(tmp & 0xff);
3392 }
3393
3394 if (shift == 0)
3395 {
3396 shift = 4;
3397 sp++;
3398 }
3399
3400 else
3401 shift -= 4;
3402 }
3403 }
3404 break;
3405 }
3406
3407 case 8:
3408 {
3409 #ifdef PNG_READ_GAMMA_SUPPORTED
3410 if (gamma_table != NULL)
|