21#ifdef PNG_ARM_NEON_IMPLEMENTATION
22# if PNG_ARM_NEON_IMPLEMENTATION == 1
23# define PNG_ARM_NEON_INTRINSICS_AVAILABLE
24# if defined(_MSC_VER) && !defined(__clang__) && defined(_M_ARM64)
25# include <arm64_neon.h>
32#ifdef PNG_READ_SUPPORTED
50 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
55 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
62 "Can't discard critical data on CRC error");
68 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
79 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
84 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
90 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
98 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
103#ifdef PNG_READ_TRANSFORMS_SUPPORTED
116 "invalid after png_start_read_image or png_read_update_info");
134#ifdef PNG_READ_BACKGROUND_SUPPORTED
141 png_debug(1,
"in png_set_background_fixed");
148 png_warning(
png_ptr,
"Application must supply a known background gamma");
153 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
154 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
157 png_ptr->background_gamma = background_gamma;
162 png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
165# ifdef PNG_FLOATING_POINT_SUPPORTED
181#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
187 if (png_rtran_ok(
png_ptr, 0) == 0)
194#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
201 if (png_rtran_ok(
png_ptr, 0) == 0)
208#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
214 if (png_rtran_ok(
png_ptr, 0) == 0)
221#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
237# ifdef PNG_READ_sRGB_SUPPORTED
260# ifdef PNG_FLOATING_POINT_SUPPORTED
271 if (output_gamma > 0 && output_gamma < 128)
275 output_gamma =
floor(output_gamma + .5);
285#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
295 if (png_rtran_ok(
png_ptr, 0) == 0)
298 output_gamma = translate_gamma_flags(
png_ptr, output_gamma, 1);
309 if (output_gamma < 1000 || output_gamma > 10000000)
310 png_error(
png_ptr,
"output gamma out of expected range");
315 file_gamma = png_reciprocal(output_gamma);
337 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
338 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
343 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
344 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
351 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
359 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
363 png_error(
png_ptr,
"invalid alpha mode");
370 if (
png_ptr->colorspace.gamma == 0)
372 png_ptr->colorspace.gamma = file_gamma;
373 png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
377 png_ptr->screen_gamma = output_gamma;
388 png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
392 "conflicting calls to set alpha mode and background");
398# ifdef PNG_FLOATING_POINT_SUPPORTED
408#ifdef PNG_READ_QUANTIZE_SUPPORTED
418typedef struct png_dsort_struct
420 struct png_dsort_struct *
next;
424typedef png_dsort * png_dsortp;
425typedef png_dsort * * png_dsortpp;
434 if (png_rtran_ok(
png_ptr, 0) == 0)
439 if (full_quantize == 0)
445 for (
i = 0;
i < num_palette;
i++)
446 png_ptr->quantize_index[
i] = (png_byte)
i;
449 if (num_palette > maximum_colors)
464 for (
i = 0;
i < num_palette;
i++)
474 for (
i = num_palette - 1;
i >= maximum_colors;
i--)
480 for (
j = 0;
j <
i;
j++)
499 if (full_quantize != 0)
506 for (
i = 0;
i < maximum_colors;
i++)
508 if ((
int)
png_ptr->quantize_sort[
i] >= maximum_colors)
512 while ((
int)
png_ptr->quantize_sort[
j] >= maximum_colors);
525 for (
i = 0;
i < maximum_colors;
i++)
528 if ((
int)
png_ptr->quantize_sort[
i] >= maximum_colors)
534 while ((
int)
png_ptr->quantize_sort[
j] >= maximum_colors);
540 png_ptr->quantize_index[
j] = (png_byte)
i;
541 png_ptr->quantize_index[
i] = (png_byte)
j;
546 for (
i = 0;
i < num_palette;
i++)
548 if ((
int)
png_ptr->quantize_index[
i] >= maximum_colors)
550 int min_d,
k, min_k, d_index;
553 d_index =
png_ptr->quantize_index[
i];
555 for (
k = 1, min_k = 0;
k < maximum_colors;
k++)
568 png_ptr->quantize_index[
i] = (png_byte)min_k;
596 (
sizeof (png_byte))));
599 (
sizeof (png_byte))));
602 for (
i = 0;
i < num_palette;
i++)
604 png_ptr->index_to_palette[
i] = (png_byte)
i;
605 png_ptr->palette_to_index[
i] = (png_byte)
i;
609 (
sizeof (png_dsortp))));
611 num_new_palette = num_palette;
623 while (num_new_palette > maximum_colors)
625 for (
i = 0;
i < num_new_palette - 1;
i++)
629 for (
j =
i + 1;
j < num_new_palette;
j++)
638 t = (png_dsortp)png_malloc_warn(
png_ptr,
645 t->left = (png_byte)
i;
646 t->right = (png_byte)
j;
655 for (
i = 0;
i <= max_d;
i++)
663 if ((
int)
png_ptr->index_to_palette[
p->left]
670 if (num_new_palette & 0x01)
684 if (full_quantize == 0)
688 for (
k = 0;
k < num_palette;
k++)
693 png_ptr->index_to_palette[next_j];
695 if ((
int)
png_ptr->quantize_index[
k] ==
703 [num_new_palette]] =
png_ptr->index_to_palette[
j];
706 =
png_ptr->palette_to_index[num_new_palette];
709 (png_byte)num_new_palette;
711 png_ptr->palette_to_index[num_new_palette] =
714 if (num_new_palette <= maximum_colors)
717 if (num_new_palette <= maximum_colors)
722 for (
i = 0;
i < 769;
i++)
744 num_palette = maximum_colors;
750 png_ptr->num_palette = (png_uint_16)num_palette;
752 if (full_quantize != 0)
761 size_t num_entries = ((
size_t)1 << total_bits);
767 (
sizeof (png_byte))));
771 for (
i = 0;
i < num_palette;
i++)
778 for (ir = 0; ir < num_red; ir++)
781 int dr = ((ir >
r) ? ir -
r :
r - ir);
785 for (ig = 0; ig < num_green; ig++)
788 int dg = ((ig >
g) ? ig -
g :
g - ig);
790 int dm = ((dr > dg) ? dr : dg);
793 for (ib = 0; ib < num_blue; ib++)
795 int d_index = index_g | ib;
797 int db = ((ib >
b) ? ib -
b :
b - ib);
798 int dmax = ((dm > db) ? dm : db);
799 int d = dmax + dt + db;
804 png_ptr->palette_lookup[d_index] = (png_byte)
i;
816#ifdef PNG_READ_GAMMA_SUPPORTED
823 if (png_rtran_ok(
png_ptr, 0) == 0)
827 scrn_gamma = translate_gamma_flags(
png_ptr, scrn_gamma, 1);
828 file_gamma = translate_gamma_flags(
png_ptr, file_gamma, 0);
842 png_error(
png_ptr,
"invalid file gamma in png_set_gamma");
845 png_error(
png_ptr,
"invalid screen gamma in png_set_gamma");
851 png_ptr->colorspace.gamma = file_gamma;
852 png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
853 png_ptr->screen_gamma = scrn_gamma;
856# ifdef PNG_FLOATING_POINT_SUPPORTED
861 convert_gamma_value(
png_ptr, file_gamma));
866#ifdef PNG_READ_EXPAND_SUPPORTED
876 if (png_rtran_ok(
png_ptr, 0) == 0)
904 png_debug(1,
"in png_set_palette_to_rgb");
906 if (png_rtran_ok(
png_ptr, 0) == 0)
916 png_debug(1,
"in png_set_expand_gray_1_2_4_to_8");
918 if (png_rtran_ok(
png_ptr, 0) == 0)
928 png_debug(1,
"in png_set_tRNS_to_alpha");
930 if (png_rtran_ok(
png_ptr, 0) == 0)
937#ifdef PNG_READ_EXPAND_16_SUPPORTED
946 if (png_rtran_ok(
png_ptr, 0) == 0)
953#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
959 if (png_rtran_ok(
png_ptr, 0) == 0)
963 png_set_expand_gray_1_2_4_to_8(
png_ptr);
968#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
977 if (png_rtran_ok(
png_ptr, 1) == 0)
995 png_error(
png_ptr,
"invalid error action to rgb_to_gray");
999#ifdef PNG_READ_EXPAND_SUPPORTED
1007 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
1015 png_uint_16 red_int, green_int;
1025 png_ptr->rgb_to_gray_red_coeff = red_int;
1026 png_ptr->rgb_to_gray_green_coeff = green_int;
1027 png_ptr->rgb_to_gray_coefficients_set = 1;
1034 "ignoring out of range rgb_to_gray coefficients");
1042 if (
png_ptr->rgb_to_gray_red_coeff == 0 &&
1043 png_ptr->rgb_to_gray_green_coeff == 0)
1045 png_ptr->rgb_to_gray_red_coeff = 6968;
1046 png_ptr->rgb_to_gray_green_coeff = 23434;
1053#ifdef PNG_FLOATING_POINT_SUPPORTED
1063 png_fixed(
png_ptr,
red,
"rgb to gray red coefficient"),
1064 png_fixed(
png_ptr,
green,
"rgb to gray green coefficient"));
1070#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
1071 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
1074 read_user_transform_fn)
1076 png_debug(1,
"in png_set_read_user_transform_fn");
1078#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1080 png_ptr->read_user_transform_fn = read_user_transform_fn;
1085#ifdef PNG_READ_TRANSFORMS_SUPPORTED
1086#ifdef PNG_READ_GAMMA_SUPPORTED
1103 png_gamma_significant(gtest);
1127 int input_has_alpha = 0;
1128 int input_has_transparency = 0;
1137 if (
png_ptr->trans_alpha[
i] == 255)
1139 else if (
png_ptr->trans_alpha[
i] == 0)
1140 input_has_transparency = 1;
1143 input_has_transparency = 1;
1144 input_has_alpha = 1;
1151 if (input_has_alpha == 0)
1157 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1158 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1160 if (input_has_transparency == 0)
1164#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
1184#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
1194 for (
i = 0;
i < istop;
i++)
1196 (png_byte)(255 -
png_ptr->trans_alpha[
i]);
1213 int input_has_transparency =
png_ptr->num_trans > 0;
1216 if (input_has_alpha == 0)
1222# ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1223 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1224 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1227 if (input_has_transparency == 0)
1231#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
1247 int gray =
png_ptr->background.gray;
1248 int trans_gray =
png_ptr->trans_color.gray;
1278 png_ptr->background.blue = (png_uint_16)gray;
1283 png_ptr->trans_color.blue = (png_uint_16)trans_gray;
1293 png_debug(1,
"in png_init_read_transformations");
1303#ifdef PNG_READ_GAMMA_SUPPORTED
1314 int gamma_correction = 0;
1316 if (
png_ptr->colorspace.gamma != 0)
1318 if (
png_ptr->screen_gamma != 0)
1319 gamma_correction = png_gamma_threshold(
png_ptr->colorspace.gamma,
1326 png_ptr->screen_gamma = png_reciprocal(
png_ptr->colorspace.gamma);
1329 else if (
png_ptr->screen_gamma != 0)
1335 png_ptr->colorspace.gamma = png_reciprocal(
png_ptr->screen_gamma);
1346 png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;
1356 if (gamma_correction != 0)
1360 png_ptr->transformations &= ~PNG_GAMMA;
1393#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
1404 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1417#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
1421 if (png_gamma_significant(
png_ptr->screen_gamma) == 0)
1423 png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
1424 png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
1428#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
1433 png_colorspace_set_rgb_coefficients(
png_ptr);
1436#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
1437#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
1494 png_init_palette_transformations(
png_ptr);
1497 png_init_rgb_transformations(
png_ptr);
1499#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
1500 defined(PNG_READ_EXPAND_16_SUPPORTED)
1516# define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x))
1517 CHOP(
png_ptr->background.red);
1518 CHOP(
png_ptr->background.green);
1519 CHOP(
png_ptr->background.blue);
1520 CHOP(
png_ptr->background.gray);
1525#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
1526 (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \
1527 defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))
1539 png_ptr->background.red = (png_uint_16)(
png_ptr->background.red * 257);
1541 (png_uint_16)(
png_ptr->background.green * 257);
1542 png_ptr->background.blue = (png_uint_16)(
png_ptr->background.blue * 257);
1543 png_ptr->background.gray = (png_uint_16)(
png_ptr->background.gray * 257);
1555#ifdef PNG_READ_GAMMA_SUPPORTED
1556# ifdef PNG_READ_BACKGROUND_SUPPORTED
1576 (png_gamma_significant(
png_ptr->colorspace.gamma) != 0 ||
1577 png_gamma_significant(
png_ptr->screen_gamma) != 0)) ||
1579 (png_gamma_significant(
png_ptr->colorspace.gamma) != 0 ||
1580 png_gamma_significant(
png_ptr->screen_gamma) != 0
1581# ifdef PNG_READ_BACKGROUND_SUPPORTED
1583 png_gamma_significant(
png_ptr->background_gamma) != 0)
1586 png_gamma_significant(
png_ptr->screen_gamma) != 0))
1590#ifdef PNG_READ_BACKGROUND_SUPPORTED
1601 "libpng does not support gamma+background+rgb_to_gray");
1610 int num_palette =
png_ptr->num_palette;
1627 switch (
png_ptr->background_gamma_type)
1635 g = png_reciprocal(
png_ptr->colorspace.gamma);
1636 gs = png_reciprocal2(
png_ptr->colorspace.gamma,
1641 g = png_reciprocal(
png_ptr->background_gamma);
1642 gs = png_reciprocal2(
png_ptr->background_gamma,
1651 if (png_gamma_significant(
gs) != 0)
1653 back.
red = png_gamma_8bit_correct(
png_ptr->background.red,
1655 back.
green = png_gamma_8bit_correct(
png_ptr->background.green,
1657 back.
blue = png_gamma_8bit_correct(
png_ptr->background.blue,
1663 back.
red = (png_byte)
png_ptr->background.red;
1668 if (png_gamma_significant(
g) != 0)
1670 back_1.
red = png_gamma_8bit_correct(
png_ptr->background.red,
1672 back_1.
green = png_gamma_8bit_correct(
1674 back_1.
blue = png_gamma_8bit_correct(
png_ptr->background.blue,
1680 back_1.
red = (png_byte)
png_ptr->background.red;
1686 for (
i = 0;
i < num_palette;
i++)
1736 switch (
png_ptr->background_gamma_type)
1744 g = png_reciprocal(
png_ptr->colorspace.gamma);
1745 gs = png_reciprocal2(
png_ptr->colorspace.gamma,
1750 g = png_reciprocal(
png_ptr->background_gamma);
1751 gs = png_reciprocal2(
png_ptr->background_gamma,
1756 png_error(
png_ptr,
"invalid background gamma type");
1759 g_sig = png_gamma_significant(
g);
1760 gs_sig = png_gamma_significant(
gs);
1827 int num_palette =
png_ptr->num_palette;
1833 for (
i = 0;
i < num_palette;
i++)
1841 png_ptr->transformations &= ~PNG_GAMMA;
1844#ifdef PNG_READ_BACKGROUND_SUPPORTED
1849#ifdef PNG_READ_BACKGROUND_SUPPORTED
1859 back.
red = (png_byte)
png_ptr->background.red;
1863 for (
i = 0;
i < istop;
i++)
1870 else if (
png_ptr->trans_alpha[
i] != 0xff)
1884 png_ptr->transformations &= ~PNG_COMPOSE;
1888#ifdef PNG_READ_SHIFT_SUPPORTED
1894 int istop =
png_ptr->num_palette;
1897 png_ptr->transformations &= ~PNG_SHIFT;
1904 for (
i=0;
i<istop; ++
i)
1906 int component =
png_ptr->palette[
i].red;
1908 component >>=
shift;
1909 png_ptr->palette[
i].red = (png_byte)component;
1914 for (
i=0;
i<istop; ++
i)
1916 int component =
png_ptr->palette[
i].green;
1918 component >>=
shift;
1919 png_ptr->palette[
i].green = (png_byte)component;
1924 for (
i=0;
i<istop; ++
i)
1926 int component =
png_ptr->palette[
i].blue;
1928 component >>=
shift;
1929 png_ptr->palette[
i].blue = (png_byte)component;
1942 png_debug(1,
"in png_read_transform_info");
1944#ifdef PNG_READ_EXPAND_SUPPORTED
1963 png_error (
png_ptr,
"Palette is NULL in indexed image");
1980#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
1981 defined(PNG_READ_ALPHA_MODE_SUPPORTED)
1989#ifdef PNG_READ_GAMMA_SUPPORTED
2004# ifdef PNG_READ_16BIT_SUPPORTED
2005# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
2010# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
2020# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
2029# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
2040#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2046#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
2049 ~PNG_COLOR_MASK_COLOR);
2052#ifdef PNG_READ_QUANTIZE_SUPPORTED
2064#ifdef PNG_READ_EXPAND_16_SUPPORTED
2073#ifdef PNG_READ_PACK_SUPPORTED
2113#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
2114defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
2117 if (
png_ptr->user_transform_depth != 0)
2120 if (
png_ptr->user_transform_channels != 0)
2138#ifndef PNG_READ_EXPAND_SUPPORTED
2144#ifdef PNG_READ_PACK_SUPPORTED
2168 for (
i = 0;
i < row_width;
i++)
2170 *dp = (png_byte)((*
sp >>
shift) & 0x01);
2192 for (
i = 0;
i < row_width;
i++)
2194 *dp = (png_byte)((*
sp >>
shift) & 0x03);
2215 for (
i = 0;
i < row_width;
i++)
2217 *dp = (png_byte)((*
sp >>
shift) & 0x0f);
2243#ifdef PNG_READ_SHIFT_SUPPORTED
2298 if (have_shift == 0)
2318 int b = (*bp >> 1) & 0x55;
2319 *bp++ = (png_byte)
b;
2330 int gray_shift =
shift[0];
2331 int mask = 0xf >> gray_shift;
2337 int b = (*bp >> gray_shift) &
mask;
2338 *bp++ = (png_byte)
b;
2352 int b = *bp >>
shift[channel];
2355 *bp++ = (png_byte)
b;
2360#ifdef PNG_READ_16BIT_SUPPORTED
2370 int value = (bp[0] << 8) + bp[1];
2375 *bp++ = (png_byte)(
value >> 8);
2376 *bp++ = (png_byte)
value;
2386#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
2391 png_debug(1,
"in png_do_scale_16_to_8");
2433 png_int_32 tmp = *
sp++;
2434 tmp += (((
int)*
sp++ - tmp + 128) * 65535) >> 24;
2435 *dp++ = (png_byte)tmp;
2445#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
2473#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
2479 png_debug(1,
"in png_do_read_swap_alpha");
2491 for (
i = 0;
i < row_width;
i++)
2501#ifdef PNG_READ_16BIT_SUPPORTED
2510 for (
i = 0;
i < row_width;
i++)
2537 for (
i = 0;
i < row_width;
i++)
2545#ifdef PNG_READ_16BIT_SUPPORTED
2554 for (
i = 0;
i < row_width;
i++)
2569#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
2574 png_debug(1,
"in png_do_read_invert_alpha");
2576 row_width = row_info->
width;
2586 for (
i = 0;
i < row_width;
i++)
2588 *(--dp) = (png_byte)(255 - *(--
sp));
2601#ifdef PNG_READ_16BIT_SUPPORTED
2609 for (
i = 0;
i < row_width;
i++)
2611 *(--dp) = (png_byte)(255 - *(--
sp));
2612 *(--dp) = (png_byte)(255 - *(--
sp));
2638 for (
i = 0;
i < row_width;
i++)
2640 *(--dp) = (png_byte)(255 - *(--
sp));
2645#ifdef PNG_READ_16BIT_SUPPORTED
2653 for (
i = 0;
i < row_width;
i++)
2655 *(--dp) = (png_byte)(255 - *(--
sp));
2656 *(--dp) = (png_byte)(255 - *(--
sp));
2670#ifdef PNG_READ_FILLER_SUPPORTED
2679#ifdef PNG_READ_16BIT_SUPPORTED
2680 png_byte hi_filler = (png_byte)(
filler>>8);
2682 png_byte lo_filler = (png_byte)
filler;
2696 for (
i = 1;
i < row_width;
i++)
2698 *(--dp) = lo_filler;
2701 *(--dp) = lo_filler;
2704 row_info->
rowbytes = row_width * 2;
2712 for (
i = 0;
i < row_width;
i++)
2715 *(--dp) = lo_filler;
2719 row_info->
rowbytes = row_width * 2;
2723#ifdef PNG_READ_16BIT_SUPPORTED
2731 for (
i = 1;
i < row_width;
i++)
2733 *(--dp) = lo_filler;
2734 *(--dp) = hi_filler;
2738 *(--dp) = lo_filler;
2739 *(--dp) = hi_filler;
2742 row_info->
rowbytes = row_width * 4;
2750 for (
i = 0;
i < row_width;
i++)
2754 *(--dp) = lo_filler;
2755 *(--dp) = hi_filler;
2759 row_info->
rowbytes = row_width * 4;
2773 for (
i = 1;
i < row_width;
i++)
2775 *(--dp) = lo_filler;
2780 *(--dp) = lo_filler;
2783 row_info->
rowbytes = row_width * 4;
2791 for (
i = 0;
i < row_width;
i++)
2796 *(--dp) = lo_filler;
2800 row_info->
rowbytes = row_width * 4;
2804#ifdef PNG_READ_16BIT_SUPPORTED
2812 for (
i = 1;
i < row_width;
i++)
2814 *(--dp) = lo_filler;
2815 *(--dp) = hi_filler;
2823 *(--dp) = lo_filler;
2824 *(--dp) = hi_filler;
2827 row_info->
rowbytes = row_width * 8;
2835 for (
i = 0;
i < row_width;
i++)
2843 *(--dp) = lo_filler;
2844 *(--dp) = hi_filler;
2849 row_info->
rowbytes = row_width * 8;
2857#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
2877 for (
i = 0;
i < row_width;
i++)
2890 for (
i = 0;
i < row_width;
i++)
2893 *(dp--) = *(
sp - 1);
2895 *(dp--) = *(
sp - 1);
2909 for (
i = 0;
i < row_width;
i++)
2923 for (
i = 0;
i < row_width;
i++)
2928 *(dp--) = *(
sp - 1);
2930 *(dp--) = *(
sp - 1);
2945#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
3016#ifdef PNG_READ_GAMMA_SUPPORTED
3028 for (
i = 0;
i < row_width;
i++)
3030 png_byte
red = *(
sp++);
3041 *(dp++) =
png_ptr->gamma_from_1[
3056 if (have_alpha != 0)
3067 for (
i = 0;
i < row_width;
i++)
3069 png_byte
red = *(
sp++);
3085 if (have_alpha != 0)
3093#ifdef PNG_READ_GAMMA_SUPPORTED
3100 for (
i = 0;
i < row_width;
i++)
3105 hi=*(
sp)++; lo=*(
sp)++;
red = (png_uint_16)((hi << 8) | (lo));
3106 hi=*(
sp)++; lo=*(
sp)++;
green = (png_uint_16)((hi << 8) | (lo));
3107 hi=*(
sp)++; lo=*(
sp)++;
blue = (png_uint_16)((hi << 8) | (lo));
3121 png_uint_16 red_1 =
png_ptr->gamma_16_to_1[(
red & 0xff)
3123 png_uint_16 green_1 =
3126 png_uint_16 blue_1 =
png_ptr->gamma_16_to_1[(
blue & 0xff)
3128 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
3129 +
bc*blue_1 + 16384)>>15);
3130 w =
png_ptr->gamma_16_from_1[(gray16 & 0xff) >>
3131 png_ptr->gamma_shift][gray16 >> 8];
3135 *(dp++) = (png_byte)((
w>>8) & 0xff);
3136 *(dp++) = (png_byte)(
w & 0xff);
3138 if (have_alpha != 0)
3152 for (
i = 0;
i < row_width;
i++)
3157 hi=*(
sp)++; lo=*(
sp)++;
red = (png_uint_16)((hi << 8) | (lo));
3158 hi=*(
sp)++; lo=*(
sp)++;
green = (png_uint_16)((hi << 8) | (lo));
3159 hi=*(
sp)++; lo=*(
sp)++;
blue = (png_uint_16)((hi << 8) | (lo));
3170 *(dp++) = (png_byte)((gray16 >> 8) & 0xff);
3171 *(dp++) = (png_byte)(gray16 & 0xff);
3173 if (have_alpha != 0)
3193#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
3194 defined(PNG_READ_ALPHA_MODE_SUPPORTED)
3202#ifdef PNG_READ_GAMMA_SUPPORTED
3209 int gamma_shift =
png_ptr->gamma_shift;
3230 for (
i = 0;
i < row_width;
i++)
3232 if ((png_uint_16)((*
sp >>
shift) & 0x01)
3235 unsigned int tmp = *
sp & (0x7f7f >> (7 -
shift));
3238 *
sp = (png_byte)(tmp & 0xff);
3255#ifdef PNG_READ_GAMMA_SUPPORTED
3256 if (gamma_table !=
NULL)
3260 for (
i = 0;
i < row_width;
i++)
3262 if ((png_uint_16)((*
sp >>
shift) & 0x03)
3265 unsigned int tmp = *
sp & (0x3f3f >> (6 -
shift));
3268 *
sp = (png_byte)(tmp & 0xff);
3273 unsigned int p = (*
sp >>
shift) & 0x03;
3274 unsigned int g = (gamma_table [
p | (
p << 2) |
3275 (
p << 4) | (p << 6)] >> 6) & 0x03;
3276 unsigned int tmp = *
sp & (0x3f3f >> (6 -
shift));
3278 *
sp = (png_byte)(tmp & 0xff);
3297 for (
i = 0;
i < row_width;
i++)
3299 if ((png_uint_16)((*
sp >>
shift) & 0x03)
3302 unsigned int tmp = *
sp & (0x3f3f >> (6 -
shift));
3305 *
sp = (png_byte)(tmp & 0xff);
3323#ifdef PNG_READ_GAMMA_SUPPORTED
3324 if (gamma_table !=
NULL)
3328 for (
i = 0;
i < row_width;
i++)
3330 if ((png_uint_16)((*
sp >>
shift) & 0x0f)
3333 unsigned int tmp = *
sp & (0x0f0f >> (4 -
shift));
3336 *
sp = (png_byte)(tmp & 0xff);
3341 unsigned int p = (*
sp >>
shift) & 0x0f;
3342 unsigned int g = (gamma_table[
p | (p << 4)] >> 4) &
3344 unsigned int tmp = *
sp & (0x0f0f >> (4 -
shift));
3346 *
sp = (png_byte)(tmp & 0xff);
3365 for (
i = 0;
i < row_width;
i++)
3367 if ((png_uint_16)((*
sp >>
shift) & 0x0f)
3370 unsigned int tmp = *
sp & (0x0f0f >> (4 -
shift));
3373 *
sp = (png_byte)(tmp & 0xff);
3391#ifdef PNG_READ_GAMMA_SUPPORTED
3392 if (gamma_table !=
NULL)
3395 for (
i = 0;
i < row_width;
i++,
sp++)
3398 *
sp = (png_byte)
png_ptr->background.gray;
3401 *
sp = gamma_table[*
sp];
3408 for (
i = 0;
i < row_width;
i++,
sp++)
3411 *
sp = (png_byte)
png_ptr->background.gray;
3419#ifdef PNG_READ_GAMMA_SUPPORTED
3420 if (gamma_16 !=
NULL)
3423 for (
i = 0;
i < row_width;
i++,
sp += 2)
3427 v = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3429 if (
v ==
png_ptr->trans_color.gray)
3432 *
sp = (png_byte)((
png_ptr->background.gray >> 8)
3434 *(
sp + 1) = (png_byte)(
png_ptr->background.gray
3440 v = gamma_16[*(
sp + 1) >> gamma_shift][*
sp];
3441 *
sp = (png_byte)((
v >> 8) & 0xff);
3442 *(
sp + 1) = (png_byte)(
v & 0xff);
3450 for (
i = 0;
i < row_width;
i++,
sp += 2)
3454 v = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3456 if (
v ==
png_ptr->trans_color.gray)
3458 *
sp = (png_byte)((
png_ptr->background.gray >> 8)
3460 *(
sp + 1) = (png_byte)(
png_ptr->background.gray
3478#ifdef PNG_READ_GAMMA_SUPPORTED
3479 if (gamma_table !=
NULL)
3482 for (
i = 0;
i < row_width;
i++,
sp += 3)
3485 *(
sp + 1) ==
png_ptr->trans_color.green &&
3488 *
sp = (png_byte)
png_ptr->background.red;
3489 *(
sp + 1) = (png_byte)
png_ptr->background.green;
3490 *(
sp + 2) = (png_byte)
png_ptr->background.blue;
3495 *
sp = gamma_table[*
sp];
3496 *(
sp + 1) = gamma_table[*(
sp + 1)];
3497 *(
sp + 2) = gamma_table[*(
sp + 2)];
3505 for (
i = 0;
i < row_width;
i++,
sp += 3)
3508 *(
sp + 1) ==
png_ptr->trans_color.green &&
3511 *
sp = (png_byte)
png_ptr->background.red;
3512 *(
sp + 1) = (png_byte)
png_ptr->background.green;
3513 *(
sp + 2) = (png_byte)
png_ptr->background.blue;
3520#ifdef PNG_READ_GAMMA_SUPPORTED
3521 if (gamma_16 !=
NULL)
3524 for (
i = 0;
i < row_width;
i++,
sp += 6)
3526 png_uint_16
r = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3528 png_uint_16
g = (png_uint_16)(((*(
sp + 2)) << 8)
3531 png_uint_16
b = (png_uint_16)(((*(
sp + 4)) << 8)
3534 if (
r ==
png_ptr->trans_color.red &&
3539 *
sp = (png_byte)((
png_ptr->background.red >> 8) & 0xff);
3540 *(
sp + 1) = (png_byte)(
png_ptr->background.red & 0xff);
3541 *(
sp + 2) = (png_byte)((
png_ptr->background.green >> 8)
3543 *(
sp + 3) = (png_byte)(
png_ptr->background.green
3545 *(
sp + 4) = (png_byte)((
png_ptr->background.blue >> 8)
3547 *(
sp + 5) = (png_byte)(
png_ptr->background.blue & 0xff);
3552 png_uint_16
v = gamma_16[*(
sp + 1) >> gamma_shift][*
sp];
3553 *
sp = (png_byte)((
v >> 8) & 0xff);
3554 *(
sp + 1) = (png_byte)(
v & 0xff);
3556 v = gamma_16[*(
sp + 3) >> gamma_shift][*(
sp + 2)];
3557 *(
sp + 2) = (png_byte)((
v >> 8) & 0xff);
3558 *(
sp + 3) = (png_byte)(
v & 0xff);
3560 v = gamma_16[*(
sp + 5) >> gamma_shift][*(
sp + 4)];
3561 *(
sp + 4) = (png_byte)((
v >> 8) & 0xff);
3562 *(
sp + 5) = (png_byte)(
v & 0xff);
3571 for (
i = 0;
i < row_width;
i++,
sp += 6)
3573 png_uint_16
r = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3575 png_uint_16
g = (png_uint_16)(((*(
sp + 2)) << 8)
3578 png_uint_16
b = (png_uint_16)(((*(
sp + 4)) << 8)
3581 if (
r ==
png_ptr->trans_color.red &&
3585 *
sp = (png_byte)((
png_ptr->background.red >> 8) & 0xff);
3586 *(
sp + 1) = (png_byte)(
png_ptr->background.red & 0xff);
3587 *(
sp + 2) = (png_byte)((
png_ptr->background.green >> 8)
3589 *(
sp + 3) = (png_byte)(
png_ptr->background.green
3591 *(
sp + 4) = (png_byte)((
png_ptr->background.blue >> 8)
3593 *(
sp + 5) = (png_byte)(
png_ptr->background.blue & 0xff);
3605#ifdef PNG_READ_GAMMA_SUPPORTED
3606 if (gamma_to_1 !=
NULL && gamma_from_1 !=
NULL &&
3607 gamma_table !=
NULL)
3610 for (
i = 0;
i < row_width;
i++,
sp += 2)
3612 png_uint_16
a = *(
sp + 1);
3615 *
sp = gamma_table[*
sp];
3620 *
sp = (png_byte)
png_ptr->background.gray;
3627 v = gamma_to_1[*
sp];
3630 w = gamma_from_1[
w];
3639 for (
i = 0;
i < row_width;
i++,
sp += 2)
3641 png_byte
a = *(
sp + 1);
3644 *
sp = (png_byte)
png_ptr->background.gray;
3653#ifdef PNG_READ_GAMMA_SUPPORTED
3654 if (gamma_16 !=
NULL && gamma_16_from_1 !=
NULL &&
3655 gamma_16_to_1 !=
NULL)
3658 for (
i = 0;
i < row_width;
i++,
sp += 4)
3660 png_uint_16
a = (png_uint_16)(((*(
sp + 2)) << 8)
3663 if (
a == (png_uint_16)0xffff)
3667 v = gamma_16[*(
sp + 1) >> gamma_shift][*
sp];
3668 *
sp = (png_byte)((
v >> 8) & 0xff);
3669 *(
sp + 1) = (png_byte)(
v & 0xff);
3675 *
sp = (png_byte)((
png_ptr->background.gray >> 8)
3677 *(
sp + 1) = (png_byte)(
png_ptr->background.gray & 0xff);
3682 png_uint_16
g,
v,
w;
3684 g = gamma_16_to_1[*(
sp + 1) >> gamma_shift][*
sp];
3689 w = gamma_16_from_1[(
v & 0xff) >>
3690 gamma_shift][
v >> 8];
3691 *
sp = (png_byte)((
w >> 8) & 0xff);
3692 *(
sp + 1) = (png_byte)(
w & 0xff);
3700 for (
i = 0;
i < row_width;
i++,
sp += 4)
3702 png_uint_16
a = (png_uint_16)(((*(
sp + 2)) << 8)
3707 *
sp = (png_byte)((
png_ptr->background.gray >> 8)
3709 *(
sp + 1) = (png_byte)(
png_ptr->background.gray & 0xff);
3712 else if (
a < 0xffff)
3716 g = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3718 *
sp = (png_byte)((
v >> 8) & 0xff);
3719 *(
sp + 1) = (png_byte)(
v & 0xff);
3731#ifdef PNG_READ_GAMMA_SUPPORTED
3732 if (gamma_to_1 !=
NULL && gamma_from_1 !=
NULL &&
3733 gamma_table !=
NULL)
3736 for (
i = 0;
i < row_width;
i++,
sp += 4)
3738 png_byte
a = *(
sp + 3);
3742 *
sp = gamma_table[*
sp];
3743 *(
sp + 1) = gamma_table[*(
sp + 1)];
3744 *(
sp + 2) = gamma_table[*(
sp + 2)];
3750 *
sp = (png_byte)
png_ptr->background.red;
3751 *(
sp + 1) = (png_byte)
png_ptr->background.green;
3752 *(
sp + 2) = (png_byte)
png_ptr->background.blue;
3759 v = gamma_to_1[*
sp];
3761 if (optimize == 0)
w = gamma_from_1[
w];
3764 v = gamma_to_1[*(
sp + 1)];
3766 if (optimize == 0)
w = gamma_from_1[
w];
3769 v = gamma_to_1[*(
sp + 2)];
3771 if (optimize == 0)
w = gamma_from_1[
w];
3780 for (
i = 0;
i < row_width;
i++,
sp += 4)
3782 png_byte
a = *(
sp + 3);
3786 *
sp = (png_byte)
png_ptr->background.red;
3787 *(
sp + 1) = (png_byte)
png_ptr->background.green;
3788 *(
sp + 2) = (png_byte)
png_ptr->background.blue;
3806#ifdef PNG_READ_GAMMA_SUPPORTED
3807 if (gamma_16 !=
NULL && gamma_16_from_1 !=
NULL &&
3808 gamma_16_to_1 !=
NULL)
3811 for (
i = 0;
i < row_width;
i++,
sp += 8)
3813 png_uint_16
a = (png_uint_16)(((png_uint_16)(*(
sp + 6))
3814 << 8) + (png_uint_16)(*(
sp + 7)));
3816 if (
a == (png_uint_16)0xffff)
3820 v = gamma_16[*(
sp + 1) >> gamma_shift][*
sp];
3821 *
sp = (png_byte)((
v >> 8) & 0xff);
3822 *(
sp + 1) = (png_byte)(
v & 0xff);
3824 v = gamma_16[*(
sp + 3) >> gamma_shift][*(
sp + 2)];
3825 *(
sp + 2) = (png_byte)((
v >> 8) & 0xff);
3826 *(
sp + 3) = (png_byte)(
v & 0xff);
3828 v = gamma_16[*(
sp + 5) >> gamma_shift][*(
sp + 4)];
3829 *(
sp + 4) = (png_byte)((
v >> 8) & 0xff);
3830 *(
sp + 5) = (png_byte)(
v & 0xff);
3836 *
sp = (png_byte)((
png_ptr->background.red >> 8) & 0xff);
3837 *(
sp + 1) = (png_byte)(
png_ptr->background.red & 0xff);
3838 *(
sp + 2) = (png_byte)((
png_ptr->background.green >> 8)
3840 *(
sp + 3) = (png_byte)(
png_ptr->background.green
3842 *(
sp + 4) = (png_byte)((
png_ptr->background.blue >> 8)
3844 *(
sp + 5) = (png_byte)(
png_ptr->background.blue & 0xff);
3851 v = gamma_16_to_1[*(
sp + 1) >> gamma_shift][*
sp];
3854 w = gamma_16_from_1[((
w & 0xff) >> gamma_shift)][
w >>
3856 *
sp = (png_byte)((
w >> 8) & 0xff);
3857 *(
sp + 1) = (png_byte)(
w & 0xff);
3859 v = gamma_16_to_1[*(
sp + 3) >> gamma_shift][*(
sp + 2)];
3862 w = gamma_16_from_1[((
w & 0xff) >> gamma_shift)][
w >>
3865 *(
sp + 2) = (png_byte)((
w >> 8) & 0xff);
3866 *(
sp + 3) = (png_byte)(
w & 0xff);
3868 v = gamma_16_to_1[*(
sp + 5) >> gamma_shift][*(
sp + 4)];
3871 w = gamma_16_from_1[((
w & 0xff) >> gamma_shift)][
w >>
3874 *(
sp + 4) = (png_byte)((
w >> 8) & 0xff);
3875 *(
sp + 5) = (png_byte)(
w & 0xff);
3884 for (
i = 0;
i < row_width;
i++,
sp += 8)
3886 png_uint_16
a = (png_uint_16)(((png_uint_16)(*(
sp + 6))
3887 << 8) + (png_uint_16)(*(
sp + 7)));
3891 *
sp = (png_byte)((
png_ptr->background.red >> 8) & 0xff);
3892 *(
sp + 1) = (png_byte)(
png_ptr->background.red & 0xff);
3893 *(
sp + 2) = (png_byte)((
png_ptr->background.green >> 8)
3895 *(
sp + 3) = (png_byte)(
png_ptr->background.green
3897 *(
sp + 4) = (png_byte)((
png_ptr->background.blue >> 8)
3899 *(
sp + 5) = (png_byte)(
png_ptr->background.blue & 0xff);
3902 else if (
a < 0xffff)
3906 png_uint_16
r = (png_uint_16)(((*
sp) << 8) + *(
sp + 1));
3907 png_uint_16
g = (png_uint_16)(((*(
sp + 2)) << 8)
3909 png_uint_16
b = (png_uint_16)(((*(
sp + 4)) << 8)
3913 *
sp = (png_byte)((
v >> 8) & 0xff);
3914 *(
sp + 1) = (png_byte)(
v & 0xff);
3917 *(
sp + 2) = (png_byte)((
v >> 8) & 0xff);
3918 *(
sp + 3) = (png_byte)(
v & 0xff);
3921 *(
sp + 4) = (png_byte)((
v >> 8) & 0xff);
3922 *(
sp + 5) = (png_byte)(
v & 0xff);
3936#ifdef PNG_READ_GAMMA_SUPPORTED
3948 int gamma_shift =
png_ptr->gamma_shift;
3966 for (
i = 0;
i < row_width;
i++)
3968 *
sp = gamma_table[*
sp];
3970 *
sp = gamma_table[*
sp];
3972 *
sp = gamma_table[*
sp];
3980 for (
i = 0;
i < row_width;
i++)
3984 v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
3985 *
sp = (png_byte)((
v >> 8) & 0xff);
3986 *(
sp + 1) = (png_byte)(
v & 0xff);
3989 v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
3990 *
sp = (png_byte)((
v >> 8) & 0xff);
3991 *(
sp + 1) = (png_byte)(
v & 0xff);
3994 v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
3995 *
sp = (png_byte)((
v >> 8) & 0xff);
3996 *(
sp + 1) = (png_byte)(
v & 0xff);
4008 for (
i = 0;
i < row_width;
i++)
4010 *
sp = gamma_table[*
sp];
4013 *
sp = gamma_table[*
sp];
4016 *
sp = gamma_table[*
sp];
4026 for (
i = 0;
i < row_width;
i++)
4028 png_uint_16
v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
4029 *
sp = (png_byte)((
v >> 8) & 0xff);
4030 *(
sp + 1) = (png_byte)(
v & 0xff);
4033 v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
4034 *
sp = (png_byte)((
v >> 8) & 0xff);
4035 *(
sp + 1) = (png_byte)(
v & 0xff);
4038 v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
4039 *
sp = (png_byte)((
v >> 8) & 0xff);
4040 *(
sp + 1) = (png_byte)(
v & 0xff);
4052 for (
i = 0;
i < row_width;
i++)
4054 *
sp = gamma_table[*
sp];
4062 for (
i = 0;
i < row_width;
i++)
4064 png_uint_16
v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
4065 *
sp = (png_byte)((
v >> 8) & 0xff);
4066 *(
sp + 1) = (png_byte)(
v & 0xff);
4078 for (
i = 0;
i < row_width;
i += 4)
4086 ((((
int)gamma_table[
a|(
a>>2)|(
a>>4)|(
a>>6)]) ) & 0xc0)|
4087 ((((
int)gamma_table[(
b<<2)|
b|(
b>>2)|(
b>>4)])>>2) & 0x30)|
4088 ((((
int)gamma_table[(
c<<4)|(
c<<2)|
c|(
c>>2)])>>4) & 0x0c)|
4089 ((((
int)gamma_table[(
d<<6)|(
d<<4)|(
d<<2)|
d])>>6) ));
4097 for (
i = 0;
i < row_width;
i += 2)
4099 int msb = *
sp & 0xf0;
4100 int lsb = *
sp & 0x0f;
4102 *
sp = (png_byte)((((
int)gamma_table[msb | (msb >> 4)]) & 0xf0)
4103 | (((
int)gamma_table[(lsb << 4) | lsb]) >> 4));
4111 for (
i = 0;
i < row_width;
i++)
4113 *
sp = gamma_table[*
sp];
4121 for (
i = 0;
i < row_width;
i++)
4123 png_uint_16
v = gamma_16_table[*(
sp + 1) >> gamma_shift][*
sp];
4124 *
sp = (png_byte)((
v >> 8) & 0xff);
4125 *(
sp + 1) = (png_byte)(
v & 0xff);
4139#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
4164 for (; row_width > 0; --row_width,
row += step)
4174 int gamma_shift =
png_ptr->gamma_shift;
4183 for (; row_width > 0; --row_width,
row += step)
4188 *
row = (png_byte)((
v >> 8) & 0xff);
4189 *(
row + 1) = (png_byte)(
v & 0xff);
4200 png_warning(
png_ptr,
"png_do_encode_alpha: unexpected call");
4204#ifdef PNG_READ_EXPAND_SUPPORTED
4218 png_debug(1,
"in png_do_expand_palette");
4230 shift = 7 - (
int)((row_width + 7) & 0x07);
4231 for (
i = 0;
i < row_width;
i++)
4257 shift = (
int)((3 - ((row_width + 3) & 0x03)) << 1);
4258 for (
i = 0;
i < row_width;
i++)
4261 *dp = (png_byte)
value;
4280 shift = (
int)((row_width & 0x01) << 2);
4281 for (
i = 0;
i < row_width;
i++)
4284 *dp = (png_byte)
value;
4313 dp =
row + ((
size_t)row_width << 2) - 1;
4316#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
4323 i = png_do_expand_palette_rgba8_neon(
png_ptr, row_info,
row,
4330 for (;
i < row_width;
i++)
4332 if ((
int)(*
sp) >= num_trans)
4335 *dp-- = trans_alpha[*
sp];
4343 row_info->
rowbytes = row_width * 4;
4353#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
4354 i = png_do_expand_palette_rgb8_neon(
png_ptr, row_info,
row,
4360 for (;
i < row_width;
i++)
4370 row_info->
rowbytes = row_width * 3;
4395 unsigned int gray = trans_color !=
NULL ? trans_color->
gray : 0;
4403 gray = (gray & 0x01) * 0xff;
4406 shift = 7 - (
int)((row_width + 7) & 0x07);
4407 for (
i = 0;
i < row_width;
i++)
4431 gray = (gray & 0x03) * 0x55;
4434 shift = (
int)((3 - ((row_width + 3) & 0x03)) << 1);
4435 for (
i = 0;
i < row_width;
i++)
4456 gray = (gray & 0x0f) * 0x11;
4459 shift = (
int)((1 - ((row_width + 1) & 0x01)) << 2);
4460 for (
i = 0;
i < row_width;
i++)
4487 if (trans_color !=
NULL)
4493 dp =
row + ((
size_t)row_width << 1) - 1;
4495 for (
i = 0;
i < row_width;
i++)
4497 if ((*
sp & 0xffU) == gray)
4509 unsigned int gray_high = (gray >> 8) & 0xff;
4510 unsigned int gray_low = gray & 0xff;
4513 for (
i = 0;
i < row_width;
i++)
4515 if ((*(
sp - 1) & 0xffU) == gray_high &&
4516 (*(
sp) & 0xffU) == gray_low)
4541 trans_color !=
NULL)
4545 png_byte
red = (png_byte)(trans_color->
red & 0xff);
4546 png_byte
green = (png_byte)(trans_color->
green & 0xff);
4547 png_byte
blue = (png_byte)(trans_color->
blue & 0xff);
4549 dp =
row + ((
size_t)row_width << 2) - 1;
4550 for (
i = 0;
i < row_width;
i++)
4565 png_byte red_high = (png_byte)((trans_color->
red >> 8) & 0xff);
4566 png_byte green_high = (png_byte)((trans_color->
green >> 8) & 0xff);
4567 png_byte blue_high = (png_byte)((trans_color->
blue >> 8) & 0xff);
4568 png_byte red_low = (png_byte)(trans_color->
red & 0xff);
4569 png_byte green_low = (png_byte)(trans_color->
green & 0xff);
4570 png_byte blue_low = (png_byte)(trans_color->
blue & 0xff);
4572 dp =
row + ((
size_t)row_width << 3) - 1;
4573 for (
i = 0;
i < row_width;
i++)
4575 if (*(
sp - 5) == red_high &&
4576 *(
sp - 4) == red_low &&
4577 *(
sp - 3) == green_high &&
4578 *(
sp - 2) == green_low &&
4579 *(
sp - 1) == blue_high &&
4608#ifdef PNG_READ_EXPAND_16_SUPPORTED
4631 dp[-2] = dp[-1] = *--
sp; dp -= 2;
4641#ifdef PNG_READ_QUANTIZE_SUPPORTED
4659 for (
i = 0;
i < row_width;
i++)
4681 *dp++ = palette_lookup[
p];
4691 palette_lookup !=
NULL)
4696 for (
i = 0;
i < row_width;
i++)
4712 *dp++ = palette_lookup[
p];
4726 for (
i = 0;
i < row_width;
i++,
sp++)
4728 *
sp = quantize_lookup[*
sp];
4742 png_debug(1,
"in png_do_read_transformations");