18 #if defined(PNG_READ_SUPPORTED) 26 if (png_ptr == NULL)
return;
32 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
33 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
36 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
37 png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
38 PNG_FLAG_CRC_CRITICAL_IGNORE;
42 "Can't discard critical data on CRC error.");
46 png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
55 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
56 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
59 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
60 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
61 PNG_FLAG_CRC_ANCILLARY_NOWARN;
64 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
65 png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
70 png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
75 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ 76 defined(PNG_FLOATING_POINT_SUPPORTED) 84 if (png_ptr == NULL)
return;
87 png_warning(png_ptr,
"Application must supply a known background gamma");
91 png_ptr->transformations |= PNG_BACKGROUND;
92 png_memcpy(&(png_ptr->background), background_color,
94 png_ptr->background_gamma = (float)background_gamma;
95 png_ptr->background_gamma_type = (
png_byte)(background_gamma_code);
96 png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
100 #if defined(PNG_READ_16_TO_8_SUPPORTED) 106 if (png_ptr == NULL)
return;
107 png_ptr->transformations |= PNG_16_TO_8;
111 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) 115 png_debug(1,
"in png_set_strip_alpha\n");
116 if (png_ptr == NULL)
return;
117 png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
121 #if defined(PNG_READ_DITHER_SUPPORTED) 146 if (png_ptr == NULL)
return;
147 png_ptr->transformations |= PNG_DITHER;
159 if (num_palette > maximum_colors)
161 if (histogram != NULL)
188 for (j = 0; j <
i; j++)
190 if (histogram[png_ptr->dither_sort[j]]
191 < histogram[png_ptr->dither_sort[j + 1]])
195 t = png_ptr->dither_sort[j];
196 png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
197 png_ptr->dither_sort[j + 1] = t;
219 palette[
i] = palette[j];
240 tmp_color = palette[j];
241 palette[j] = palette[
i];
242 palette[
i] = tmp_color;
244 png_ptr->dither_index[j] = (
png_byte)i;
254 int min_d, k, min_k, d_index;
257 d_index = png_ptr->dither_index[
i];
258 min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
263 d = PNG_COLOR_DIST(palette[d_index], palette[k]);
272 png_ptr->dither_index[
i] = (
png_byte)min_k;
276 png_free(png_ptr, png_ptr->dither_sort);
277 png_ptr->dither_sort = NULL;
306 png_ptr->index_to_palette[
i] = (
png_byte)i;
307 png_ptr->palette_to_index[
i] = (
png_byte)i;
312 for (i = 0; i < 769; i++)
328 while (num_new_palette > maximum_colors)
330 for (i = 0; i < num_new_palette - 1; i++)
334 for (j = i + 1; j < num_new_palette; j++)
338 d = PNG_COLOR_DIST(palette[i], palette[j]);
358 for (i = 0; i <= max_d; i++)
364 for (p = hash[i]; p; p = p->next)
366 if ((
int)png_ptr->index_to_palette[p->left]
368 (
int)png_ptr->index_to_palette[p->right]
373 if (num_new_palette & 0x01)
385 palette[png_ptr->index_to_palette[j]]
386 = palette[num_new_palette];
393 if (png_ptr->dither_index[k] ==
394 png_ptr->index_to_palette[j])
395 png_ptr->dither_index[k] =
396 png_ptr->index_to_palette[next_j];
397 if ((
int)png_ptr->dither_index[k] ==
399 png_ptr->dither_index[k] =
400 png_ptr->index_to_palette[j];
404 png_ptr->index_to_palette[png_ptr->palette_to_index
405 [num_new_palette]] = png_ptr->index_to_palette[j];
406 png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
407 = png_ptr->palette_to_index[num_new_palette];
409 png_ptr->index_to_palette[j] = (
png_byte)num_new_palette;
410 png_ptr->palette_to_index[num_new_palette] = (
png_byte)j;
412 if (num_new_palette <= maximum_colors)
415 if (num_new_palette <= maximum_colors)
420 for (i = 0; i < 769; i++)
437 png_free(png_ptr, png_ptr->palette_to_index);
438 png_free(png_ptr, png_ptr->index_to_palette);
439 png_ptr->palette_to_index = NULL;
440 png_ptr->index_to_palette = NULL;
444 if (png_ptr->palette == NULL)
454 int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
455 PNG_DITHER_BLUE_BITS;
456 int num_red = (1 << PNG_DITHER_RED_BITS);
457 int num_green = (1 << PNG_DITHER_GREEN_BITS);
458 int num_blue = (1 << PNG_DITHER_BLUE_BITS);
464 png_memset(png_ptr->palette_lookup, 0, num_entries *
475 int r = (palette[
i].red >> (8 - PNG_DITHER_RED_BITS));
476 int g = (palette[
i].green >> (8 - PNG_DITHER_GREEN_BITS));
477 int b = (palette[
i].blue >> (8 - PNG_DITHER_BLUE_BITS));
479 for (ir = 0; ir < num_red; ir++)
482 int dr = ((ir > r) ? ir - r : r - ir);
483 int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
485 for (ig = 0; ig < num_green; ig++)
488 int dg = ((ig > g) ? ig - g : g - ig);
490 int dm = ((dr > dg) ? dr : dg);
491 int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
493 for (ib = 0; ib < num_blue; ib++)
495 int d_index = index_g | ib;
497 int db = ((ib >
b) ? ib - b : b - ib);
498 int dmax = ((dm > db) ? dm : db);
499 int d = dmax + dt + db;
501 if (d < (
int)distance[d_index])
504 png_ptr->palette_lookup[d_index] = (
png_byte)i;
516 #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) 530 if (png_ptr == NULL)
return;
531 if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
534 png_ptr->transformations |= PNG_GAMMA;
535 png_ptr->gamma = (float)file_gamma;
536 png_ptr->screen_gamma = (float)scrn_gamma;
540 #if defined(PNG_READ_EXPAND_SUPPORTED) 549 if (png_ptr == NULL)
return;
550 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
551 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
575 png_debug(1,
"in png_set_palette_to_rgb\n");
576 if (png_ptr == NULL)
return;
577 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
578 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
581 #if !defined(PNG_1_0_X) 586 png_debug(1,
"in png_set_expand_gray_1_2_4_to_8\n");
587 if (png_ptr == NULL)
return;
588 png_ptr->transformations |= PNG_EXPAND;
589 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
593 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) 599 png_debug(1,
"in png_set_gray_1_2_4_to_8\n");
600 if (png_ptr == NULL)
return;
601 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
610 png_debug(1,
"in png_set_tRNS_to_alpha\n");
611 png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
612 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
616 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 620 png_debug(1,
"in png_set_gray_to_rgb\n");
621 png_ptr->transformations |= PNG_GRAY_TO_RGB;
622 png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
626 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 627 #if defined(PNG_FLOATING_POINT_SUPPORTED) 636 int red_fixed = (
int)((
float)red*100000.0 + 0.5);
637 int green_fixed = (
int)((
float)green*100000.0 + 0.5);
638 if (png_ptr == NULL)
return;
647 png_debug(1,
"in png_set_rgb_to_gray\n");
648 if (png_ptr == NULL)
return;
651 case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
653 case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
655 case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
658 #if defined(PNG_READ_EXPAND_SUPPORTED) 659 png_ptr->transformations |= PNG_EXPAND;
663 "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
664 png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
669 if (red < 0 || green < 0)
674 else if (red + green < 100000L)
681 png_warning(png_ptr,
"ignoring out of range rgb_to_gray coefficients");
685 png_ptr->rgb_to_gray_red_coeff = red_int;
686 png_ptr->rgb_to_gray_green_coeff = green_int;
687 png_ptr->rgb_to_gray_blue_coeff =
693 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ 694 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ 695 defined(PNG_LEGACY_SUPPORTED) 700 png_debug(1,
"in png_set_read_user_transform_fn\n");
701 if (png_ptr == NULL)
return;
702 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 703 png_ptr->transformations |= PNG_USER_TRANSFORM;
706 #ifdef PNG_LEGACY_SUPPORTED 707 if (read_user_transform_fn)
709 "This version of libpng does not support user transforms");
720 png_debug(1,
"in png_init_read_transformations\n");
721 #if defined(PNG_USELESS_TESTS_SUPPORTED) 725 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \ 726 || defined(PNG_READ_GAMMA_SUPPORTED) 730 #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) 732 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 742 if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
745 png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
746 }
else if ((png_ptr->transformations & PNG_BACKGROUND) &&
747 !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
748 (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
749 png_ptr->background.red == png_ptr->background.green &&
750 png_ptr->background.red == png_ptr->background.blue)
752 png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
753 png_ptr->background.gray = png_ptr->background.red;
757 if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
758 (png_ptr->transformations & PNG_EXPAND))
760 if (!(color_type & PNG_COLOR_MASK_COLOR))
763 switch (png_ptr->bit_depth)
767 png_ptr->background.red = png_ptr->background.green
768 = png_ptr->background.blue = png_ptr->background.gray;
769 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
772 png_ptr->trans_values.red = png_ptr->trans_values.green
773 = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
778 png_ptr->background.red = png_ptr->background.green
779 = png_ptr->background.blue = png_ptr->background.gray;
780 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
783 png_ptr->trans_values.red = png_ptr->trans_values.green
784 = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
789 png_ptr->background.red = png_ptr->background.green
790 = png_ptr->background.blue = png_ptr->background.gray;
791 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
794 png_ptr->trans_values.red = png_ptr->trans_values.green
795 = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
800 png_ptr->background.red = png_ptr->background.green
801 = png_ptr->background.blue = png_ptr->background.gray;
807 png_ptr->background.red =
808 png_ptr->palette[png_ptr->background.index].red;
809 png_ptr->background.green =
810 png_ptr->palette[png_ptr->background.index].green;
811 png_ptr->background.blue =
812 png_ptr->palette[png_ptr->background.index].blue;
814 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) 815 if (png_ptr->transformations & PNG_INVERT_ALPHA)
817 #if defined(PNG_READ_EXPAND_SUPPORTED) 818 if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
824 istop=(
int)png_ptr->num_trans;
825 for (i=0; i<istop; i++)
826 png_ptr->trans[i] = (
png_byte)(255 - png_ptr->trans[
i]);
835 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) 836 png_ptr->background_1 = png_ptr->background;
838 #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) 841 && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
842 < PNG_GAMMA_THRESHOLD))
846 for (i=0; i<png_ptr->num_trans; i++)
848 if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
852 png_ptr->transformations &= ~PNG_GAMMA;
855 if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
856 png_ptr->gamma != 0.0)
859 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 860 if (png_ptr->transformations & PNG_BACKGROUND)
872 back.
red = png_ptr->gamma_table[png_ptr->background.red];
873 back.
green = png_ptr->gamma_table[png_ptr->background.green];
874 back.
blue = png_ptr->gamma_table[png_ptr->background.blue];
876 back_1.
red = png_ptr->gamma_to_1[png_ptr->background.red];
877 back_1.
green = png_ptr->gamma_to_1[png_ptr->background.green];
878 back_1.
blue = png_ptr->gamma_to_1[png_ptr->background.blue];
884 switch (png_ptr->background_gamma_type)
887 g = (png_ptr->screen_gamma);
891 g = 1.0 / (png_ptr->gamma);
892 gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
895 g = 1.0 / (png_ptr->background_gamma);
896 gs = 1.0 / (png_ptr->background_gamma *
897 png_ptr->screen_gamma);
904 if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
913 (
double)png_ptr->background.red/255, gs) * 255.0 + .5);
915 (
double)png_ptr->background.green/255, gs) * 255.0 + .5);
917 (
double)png_ptr->background.blue/255, gs) * 255.0 + .5);
921 (
double)png_ptr->background.red/255, g) * 255.0 + .5);
923 (
double)png_ptr->background.green/255, g) * 255.0 + .5);
925 (
double)png_ptr->background.blue/255, g) * 255.0 + .5);
929 if (i < (
int)png_ptr->num_trans && png_ptr->trans[
i] != 0xff)
931 if (png_ptr->trans[i] == 0)
939 v = png_ptr->gamma_to_1[palette[
i].red];
941 palette[
i].red = png_ptr->gamma_from_1[w];
943 v = png_ptr->gamma_to_1[palette[
i].green];
945 palette[
i].green = png_ptr->gamma_from_1[w];
947 v = png_ptr->gamma_to_1[palette[
i].blue];
949 palette[
i].blue = png_ptr->gamma_from_1[w];
954 palette[
i].red = png_ptr->gamma_table[palette[
i].red];
955 palette[
i].green = png_ptr->gamma_table[palette[
i].green];
956 palette[
i].blue = png_ptr->gamma_table[palette[
i].blue];
964 png_ptr->transformations &= ~PNG_BACKGROUND;
965 png_ptr->transformations &= ~PNG_GAMMA;
966 png_ptr->transformations |= PNG_STRIP_ALPHA;
972 double m = (double)(((
png_uint_32)1 << png_ptr->bit_depth) - 1);
976 switch (png_ptr->background_gamma_type)
979 g = (png_ptr->screen_gamma);
983 g = 1.0 / (png_ptr->gamma);
984 gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
987 g = 1.0 / (png_ptr->background_gamma);
988 gs = 1.0 / (png_ptr->background_gamma *
989 png_ptr->screen_gamma);
994 (
double)png_ptr->background.gray / m, g) * m + .5);
996 (
double)png_ptr->background.gray / m, gs) * m + .5);
998 if ((png_ptr->background.red != png_ptr->background.green) ||
999 (png_ptr->background.red != png_ptr->background.blue) ||
1000 (png_ptr->background.red != png_ptr->background.gray))
1004 (
double)png_ptr->background.red / m, g) * m + .5);
1006 (
double)png_ptr->background.green / m, g) * m + .5);
1008 (
double)png_ptr->background.blue / m, g) * m + .5);
1010 (
double)png_ptr->background.red / m, gs) * m + .5);
1012 (
double)png_ptr->background.green / m, gs) * m + .5);
1014 (
double)png_ptr->background.blue / m, gs) * m + .5);
1019 png_ptr->background_1.red = png_ptr->background_1.green
1020 = png_ptr->background_1.blue = png_ptr->background_1.gray;
1021 png_ptr->background.red = png_ptr->background.green
1022 = png_ptr->background.blue = png_ptr->background.gray;
1037 palette[
i].red = png_ptr->gamma_table[palette[
i].red];
1038 palette[
i].green = png_ptr->gamma_table[palette[
i].green];
1039 palette[
i].blue = png_ptr->gamma_table[palette[
i].blue];
1043 png_ptr->transformations &= ~PNG_GAMMA;
1046 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 1050 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 1052 if ((png_ptr->transformations & PNG_BACKGROUND) &&
1056 int istop = (
int)png_ptr->num_trans;
1064 for (i = 0; i < istop; i++)
1066 if (png_ptr->trans[i] == 0)
1070 else if (png_ptr->trans[i] != 0xff)
1074 png_ptr->trans[i],
back.red);
1076 png_ptr->trans[i],
back.green);
1078 png_ptr->trans[i],
back.blue);
1083 png_ptr->transformations &= ~PNG_BACKGROUND;
1084 png_ptr->transformations |= PNG_STRIP_ALPHA;
1088 #if defined(PNG_READ_SHIFT_SUPPORTED) 1089 if ((png_ptr->transformations & PNG_SHIFT) &&
1094 int sr = 8 - png_ptr->sig_bit.red;
1095 int sg = 8 - png_ptr->sig_bit.green;
1096 int sb = 8 - png_ptr->sig_bit.blue;
1098 if (sr < 0 || sr > 8)
1100 if (sg < 0 || sg > 8)
1102 if (sb < 0 || sb > 8)
1104 for (i = 0; i < istop; i++)
1106 png_ptr->palette[
i].red >>= sr;
1107 png_ptr->palette[
i].green >>= sg;
1108 png_ptr->palette[
i].blue >>= sb;
1113 #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \ 1114 && !defined(PNG_READ_BACKGROUND_SUPPORTED) 1127 png_debug(1,
"in png_read_transform_info\n");
1128 #if defined(PNG_READ_EXPAND_SUPPORTED) 1129 if (png_ptr->transformations & PNG_EXPAND)
1133 if (png_ptr->num_trans &&
1134 (png_ptr->transformations & PNG_EXPAND_tRNS))
1138 info_ptr->bit_depth = 8;
1139 info_ptr->num_trans = 0;
1143 if (png_ptr->num_trans)
1145 if (png_ptr->transformations & PNG_EXPAND_tRNS)
1152 if (info_ptr->bit_depth < 8)
1153 info_ptr->bit_depth = 8;
1154 info_ptr->num_trans = 0;
1159 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 1160 if (png_ptr->transformations & PNG_BACKGROUND)
1163 info_ptr->num_trans = 0;
1164 info_ptr->background = png_ptr->background;
1168 #if defined(PNG_READ_GAMMA_SUPPORTED) 1169 if (png_ptr->transformations & PNG_GAMMA)
1171 #ifdef PNG_FLOATING_POINT_SUPPORTED 1172 info_ptr->gamma = png_ptr->gamma;
1174 #ifdef PNG_FIXED_POINT_SUPPORTED 1175 info_ptr->int_gamma = png_ptr->int_gamma;
1180 #if defined(PNG_READ_16_TO_8_SUPPORTED) 1181 if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
1182 info_ptr->bit_depth = 8;
1185 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 1186 if (png_ptr->transformations & PNG_GRAY_TO_RGB)
1190 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 1191 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
1195 #if defined(PNG_READ_DITHER_SUPPORTED) 1196 if (png_ptr->transformations & PNG_DITHER)
1200 png_ptr->palette_lookup && info_ptr->bit_depth == 8)
1207 #if defined(PNG_READ_PACK_SUPPORTED) 1208 if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
1209 info_ptr->bit_depth = 8;
1213 info_ptr->channels = 1;
1215 info_ptr->channels = 3;
1217 info_ptr->channels = 1;
1219 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) 1220 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
1225 info_ptr->channels++;
1227 #if defined(PNG_READ_FILLER_SUPPORTED) 1229 if ((png_ptr->transformations & PNG_FILLER) &&
1233 info_ptr->channels++;
1235 #if !defined(PNG_1_0_X) 1236 if (png_ptr->transformations & PNG_ADD_ALPHA)
1242 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \ 1243 defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 1244 if (png_ptr->transformations & PNG_USER_TRANSFORM)
1246 if (info_ptr->bit_depth < png_ptr->user_transform_depth)
1247 info_ptr->bit_depth = png_ptr->user_transform_depth;
1248 if (info_ptr->channels < png_ptr->user_transform_channels)
1249 info_ptr->channels = png_ptr->user_transform_channels;
1253 info_ptr->pixel_depth = (
png_byte)(info_ptr->channels *
1254 info_ptr->bit_depth);
1256 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
1258 #if !defined(PNG_READ_EXPAND_SUPPORTED) 1271 png_debug(1,
"in png_do_read_transformations\n");
1272 if (png_ptr->row_buf == NULL)
1274 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 1278 "NULL row buffer for row %ld, pass %d", (
long)png_ptr->row_number,
1285 #ifdef PNG_WARN_UNINITIALIZED_ROW 1286 if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
1290 #if (PNG_WARN_UNINITIALIZED_ROW==1) 1291 png_error(png_ptr,
"Uninitialized row");
1297 #if defined(PNG_READ_EXPAND_SUPPORTED) 1298 if (png_ptr->transformations & PNG_EXPAND)
1303 png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
1307 if (png_ptr->num_trans &&
1308 (png_ptr->transformations & PNG_EXPAND_tRNS))
1310 &(png_ptr->trans_values));
1318 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) 1319 if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
1321 PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
1324 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 1325 if (png_ptr->transformations & PNG_RGB_TO_GRAY)
1331 png_ptr->rgb_to_gray_status=1;
1332 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
1333 PNG_RGB_TO_GRAY_WARN)
1334 png_warning(png_ptr,
"png_do_rgb_to_gray found nongray pixel");
1335 if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
1336 PNG_RGB_TO_GRAY_ERR)
1337 png_error(png_ptr,
"png_do_rgb_to_gray found nongray pixel");
1372 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 1375 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
1376 !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
1380 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 1381 if ((png_ptr->transformations & PNG_BACKGROUND) &&
1382 ((png_ptr->num_trans != 0 ) ||
1385 &(png_ptr->trans_values), &(png_ptr->background)
1387 , &(png_ptr->background_1),
1388 png_ptr->gamma_table, png_ptr->gamma_from_1,
1389 png_ptr->gamma_to_1, png_ptr->gamma_16_table,
1390 png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
1391 png_ptr->gamma_shift
1396 #if defined(PNG_READ_GAMMA_SUPPORTED) 1397 if ((png_ptr->transformations & PNG_GAMMA) &&
1399 !((png_ptr->transformations & PNG_BACKGROUND) &&
1400 ((png_ptr->num_trans != 0) ||
1404 png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
1405 png_ptr->gamma_table, png_ptr->gamma_16_table,
1406 png_ptr->gamma_shift);
1409 #if defined(PNG_READ_16_TO_8_SUPPORTED) 1410 if (png_ptr->transformations & PNG_16_TO_8)
1411 png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
1414 #if defined(PNG_READ_DITHER_SUPPORTED) 1415 if (png_ptr->transformations & PNG_DITHER)
1418 png_ptr->palette_lookup, png_ptr->dither_index);
1420 png_error(png_ptr,
"png_do_dither returned rowbytes=0");
1424 #if defined(PNG_READ_INVERT_SUPPORTED) 1425 if (png_ptr->transformations & PNG_INVERT_MONO)
1429 #if defined(PNG_READ_SHIFT_SUPPORTED) 1430 if (png_ptr->transformations & PNG_SHIFT)
1435 #if defined(PNG_READ_PACK_SUPPORTED) 1436 if (png_ptr->transformations & PNG_PACK)
1440 #if defined(PNG_READ_BGR_SUPPORTED) 1441 if (png_ptr->transformations & PNG_BGR)
1442 png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
1445 #if defined(PNG_READ_PACKSWAP_SUPPORTED) 1446 if (png_ptr->transformations & PNG_PACKSWAP)
1450 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 1452 if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
1453 (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
1457 #if defined(PNG_READ_FILLER_SUPPORTED) 1458 if (png_ptr->transformations & PNG_FILLER)
1463 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) 1464 if (png_ptr->transformations & PNG_INVERT_ALPHA)
1468 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) 1469 if (png_ptr->transformations & PNG_SWAP_ALPHA)
1473 #if defined(PNG_READ_SWAP_SUPPORTED) 1474 if (png_ptr->transformations & PNG_SWAP_BYTES)
1475 png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
1478 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) 1479 if (png_ptr->transformations & PNG_USER_TRANSFORM)
1481 if (png_ptr->read_user_transform_fn != NULL)
1482 (*(png_ptr->read_user_transform_fn))
1484 &(png_ptr->row_info),
1491 png_ptr->row_buf + 1);
1492 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) 1493 if (png_ptr->user_transform_depth)
1494 png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
1495 if (png_ptr->user_transform_channels)
1496 png_ptr->row_info.channels = png_ptr->user_transform_channels;
1498 png_ptr->row_info.pixel_depth = (
png_byte)(png_ptr->row_info.bit_depth *
1499 png_ptr->row_info.channels);
1500 png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
1501 png_ptr->row_info.width);
1507 #if defined(PNG_READ_PACK_SUPPORTED) 1518 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1519 if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
1521 if (row_info->bit_depth < 8)
1527 switch (row_info->bit_depth)
1534 for (i = 0; i < row_width; i++)
1536 *dp = (
png_byte)((*sp >> shift) & 0x01);
1555 for (i = 0; i < row_width; i++)
1557 *dp = (
png_byte)((*sp >> shift) & 0x03);
1575 for (i = 0; i < row_width; i++)
1577 *dp = (
png_byte)((*sp >> shift) & 0x0f);
1591 row_info->bit_depth = 8;
1592 row_info->pixel_depth = (
png_byte)(8 * row_info->channels);
1593 row_info->rowbytes = row_width * row_info->channels;
1598 #if defined(PNG_READ_SHIFT_SUPPORTED) 1609 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
1610 row != NULL && row_info != NULL && sig_bits != NULL &&
1622 shift[channels++] = row_info->bit_depth - sig_bits->red;
1623 shift[channels++] = row_info->bit_depth - sig_bits->green;
1624 shift[channels++] = row_info->bit_depth - sig_bits->blue;
1628 shift[channels++] = row_info->bit_depth - sig_bits->gray;
1632 shift[channels++] = row_info->bit_depth - sig_bits->alpha;
1635 for (c = 0; c < channels; c++)
1646 switch (row_info->bit_depth)
1654 for (bp = row, i = 0; i < istop; i++)
1669 for (i = 0; i < istop; i++)
1682 for (i = 0; i < istop; i++)
1684 *bp++ >>= shift[i%channels];
1694 for (i = 0; i < istop; i++)
1697 value >>= shift[i%channels];
1708 #if defined(PNG_READ_16_TO_8_SUPPORTED) 1714 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1715 if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
1717 if (row_info->bit_depth == 16)
1723 png_uint_32 istop = row_info->width * row_info->channels;
1725 for (i = 0; i<istop; i++, sp += 2, dp++)
1727 #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED) 1750 *dp = *sp + ((((
int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
1756 row_info->bit_depth = 8;
1757 row_info->pixel_depth = (
png_byte)(8 * row_info->channels);
1758 row_info->rowbytes = row_info->width * row_info->channels;
1763 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) 1767 png_debug(1,
"in png_do_read_swap_alpha\n");
1768 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1769 if (row != NULL && row_info != NULL)
1776 if (row_info->bit_depth == 8)
1778 png_bytep sp = row + row_info->rowbytes;
1783 for (i = 0; i < row_width; i++)
1795 png_bytep sp = row + row_info->rowbytes;
1800 for (i = 0; i < row_width; i++)
1818 if (row_info->bit_depth == 8)
1820 png_bytep sp = row + row_info->rowbytes;
1825 for (i = 0; i < row_width; i++)
1835 png_bytep sp = row + row_info->rowbytes;
1840 for (i = 0; i < row_width; i++)
1855 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) 1859 png_debug(1,
"in png_do_read_invert_alpha\n");
1860 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1861 if (row != NULL && row_info != NULL)
1868 if (row_info->bit_depth == 8)
1870 png_bytep sp = row + row_info->rowbytes;
1874 for (i = 0; i < row_width; i++)
1876 *(--dp) = (
png_byte)(255 - *(--sp));
1891 png_bytep sp = row + row_info->rowbytes;
1895 for (i = 0; i < row_width; i++)
1897 *(--dp) = (
png_byte)(255 - *(--sp));
1898 *(--dp) = (
png_byte)(255 - *(--sp));
1917 if (row_info->bit_depth == 8)
1919 png_bytep sp = row + row_info->rowbytes;
1923 for (i = 0; i < row_width; i++)
1925 *(--dp) = (
png_byte)(255 - *(--sp));
1932 png_bytep sp = row + row_info->rowbytes;
1936 for (i = 0; i < row_width; i++)
1938 *(--dp) = (
png_byte)(255 - *(--sp));
1939 *(--dp) = (
png_byte)(255 - *(--sp));
1953 #if defined(PNG_READ_FILLER_SUPPORTED) 1965 png_debug(1,
"in png_do_read_filler\n");
1967 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
1968 row != NULL && row_info != NULL &&
1972 if (row_info->bit_depth == 8)
1975 if (flags & PNG_FLAG_FILLER_AFTER)
1979 for (i = 1; i < row_width; i++)
1981 *(--dp) = lo_filler;
1984 *(--dp) = lo_filler;
1985 row_info->channels = 2;
1986 row_info->pixel_depth = 16;
1987 row_info->rowbytes = row_width * 2;
1994 for (i = 0; i < row_width; i++)
1997 *(--dp) = lo_filler;
1999 row_info->channels = 2;
2000 row_info->pixel_depth = 16;
2001 row_info->rowbytes = row_width * 2;
2004 else if (row_info->bit_depth == 16)
2007 if (flags & PNG_FLAG_FILLER_AFTER)
2011 for (i = 1; i < row_width; i++)
2013 *(--dp) = hi_filler;
2014 *(--dp) = lo_filler;
2018 *(--dp) = hi_filler;
2019 *(--dp) = lo_filler;
2020 row_info->channels = 2;
2021 row_info->pixel_depth = 32;
2022 row_info->rowbytes = row_width * 4;
2029 for (i = 0; i < row_width; i++)
2033 *(--dp) = hi_filler;
2034 *(--dp) = lo_filler;
2036 row_info->channels = 2;
2037 row_info->pixel_depth = 32;
2038 row_info->rowbytes = row_width * 4;
2044 if (row_info->bit_depth == 8)
2047 if (flags & PNG_FLAG_FILLER_AFTER)
2051 for (i = 1; i < row_width; i++)
2053 *(--dp) = lo_filler;
2058 *(--dp) = lo_filler;
2059 row_info->channels = 4;
2060 row_info->pixel_depth = 32;
2061 row_info->rowbytes = row_width * 4;
2068 for (i = 0; i < row_width; i++)
2073 *(--dp) = lo_filler;
2075 row_info->channels = 4;
2076 row_info->pixel_depth = 32;
2077 row_info->rowbytes = row_width * 4;
2080 else if (row_info->bit_depth == 16)
2083 if (flags & PNG_FLAG_FILLER_AFTER)
2087 for (i = 1; i < row_width; i++)
2089 *(--dp) = hi_filler;
2090 *(--dp) = lo_filler;
2098 *(--dp) = hi_filler;
2099 *(--dp) = lo_filler;
2100 row_info->channels = 4;
2101 row_info->pixel_depth = 64;
2102 row_info->rowbytes = row_width * 8;
2109 for (i = 0; i < row_width; i++)
2117 *(--dp) = hi_filler;
2118 *(--dp) = lo_filler;
2120 row_info->channels = 4;
2121 row_info->pixel_depth = 64;
2122 row_info->rowbytes = row_width * 8;
2129 #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) 2137 png_debug(1,
"in png_do_gray_to_rgb\n");
2138 if (row_info->bit_depth >= 8 &&
2139 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
2140 row != NULL && row_info != NULL &&
2146 if (row_info->bit_depth == 8)
2150 for (i = 0; i < row_width; i++)
2161 for (i = 0; i < row_width; i++)
2164 *(dp--) = *(sp - 1);
2166 *(dp--) = *(sp - 1);
2174 if (row_info->bit_depth == 8)
2178 for (i = 0; i < row_width; i++)
2190 for (i = 0; i < row_width; i++)
2195 *(dp--) = *(sp - 1);
2197 *(dp--) = *(sp - 1);
2205 row_info->pixel_depth = (
png_byte)(row_info->channels *
2206 row_info->bit_depth);
2207 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2212 #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 2243 png_debug(1,
"in png_do_rgb_to_gray\n");
2245 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
2246 row != NULL && row_info != NULL &&
2251 png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
2256 if (row_info->bit_depth == 8)
2258 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2259 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2264 for (i = 0; i < row_width; i++)
2268 png_byte blue = png_ptr->gamma_to_1[*(sp++)];
2269 if (red != green || red != blue)
2272 *(dp++) = png_ptr->gamma_from_1[
2273 (rc*red + gc*green + bc*blue)>>15];
2276 *(dp++) = *(sp - 1);
2284 for (i = 0; i < row_width; i++)
2289 if (red != green || red != blue)
2292 *(dp++) = (
png_byte)((rc*red + gc*green + bc*blue)>>15);
2295 *(dp++) = *(sp - 1);
2302 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2303 if (png_ptr->gamma_16_to_1 != NULL &&
2304 png_ptr->gamma_16_from_1 != NULL)
2308 for (i = 0; i < row_width; i++)
2312 red = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2313 green = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2314 blue = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2316 if (red == green && red == blue)
2320 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
2321 png_ptr->gamma_shift][red>>8];
2322 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
2323 png_ptr->gamma_shift][green>>8];
2324 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
2325 png_ptr->gamma_shift][blue>>8];
2328 w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
2329 png_ptr->gamma_shift][gray16 >> 8];
2333 *(dp++) = (
png_byte)((w>>8) & 0xff);
2342 for (i = 0; i < row_width; i++)
2346 red = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2347 green = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2348 blue = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2350 if (red != green || red != blue)
2352 gray16 = (
png_uint_16)((rc*red + gc*green + bc*blue)>>15);
2353 *(dp++) = (
png_byte)((gray16>>8) & 0xff);
2354 *(dp++) = (
png_byte)(gray16 & 0xff);
2361 if (row_info->bit_depth == 8)
2363 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2364 if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
2368 for (i = 0; i < row_width; i++)
2372 png_byte blue = png_ptr->gamma_to_1[*(sp++)];
2373 if (red != green || red != blue)
2375 *(dp++) = png_ptr->gamma_from_1
2376 [(rc*red + gc*green + bc*blue)>>15];
2385 for (i = 0; i < row_width; i++)
2390 if (red != green || red != blue)
2392 *(dp++) = (
png_byte)((rc*red + gc*green + bc*blue)>>15);
2399 #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) 2400 if (png_ptr->gamma_16_to_1 != NULL &&
2401 png_ptr->gamma_16_from_1 != NULL)
2405 for (i = 0; i < row_width; i++)
2409 red = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2410 green = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2411 blue = (
png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
2413 if (red == green && red == blue)
2417 png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
2418 png_ptr->gamma_shift][red>>8];
2419 png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
2420 png_ptr->gamma_shift][green>>8];
2421 png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
2422 png_ptr->gamma_shift][blue>>8];
2424 + gc * green_1 + bc * blue_1)>>15);
2425 w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
2426 png_ptr->gamma_shift][gray16 >> 8];
2430 *(dp++) = (
png_byte)((w>>8) & 0xff);
2441 for (i = 0; i < row_width; i++)
2445 green = (
png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
2446 blue = (
png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
2447 if (red != green || red != blue)
2449 gray16 = (
png_uint_16)((rc*red + gc*green + bc*blue)>>15);
2450 *(dp++) = (
png_byte)((gray16>>8) & 0xff);
2451 *(dp++) = (
png_byte)(gray16 & 0xff);
2460 row_info->pixel_depth = (
png_byte)(row_info->channels *
2461 row_info->bit_depth);
2462 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
2481 png_debug(1,
"in png_do_build_grayscale_palette\n");
2482 if (palette == NULL)
2509 for (i = 0, v = 0; i <
num_palette; i++, v += color_inc)
2518 #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED) 2523 png_debug(1,
"in png_correct_palette\n");
2524 #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ 2525 defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) 2526 if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
2532 back.
red = png_ptr->gamma_table[png_ptr->background.red];
2533 back.
green = png_ptr->gamma_table[png_ptr->background.green];
2534 back.
blue = png_ptr->gamma_table[png_ptr->background.blue];
2536 back_1.
red = png_ptr->gamma_to_1[png_ptr->background.red];
2537 back_1.
green = png_ptr->gamma_to_1[png_ptr->background.green];
2538 back_1.
blue = png_ptr->gamma_to_1[png_ptr->background.blue];
2544 g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
2547 fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
2549 back.
red = png_ptr->background.red;
2550 back.
green = png_ptr->background.green;
2551 back.
blue = png_ptr->background.blue;
2556 (
png_byte)(pow((
double)png_ptr->background.red/255, g) *
2559 (
png_byte)(pow((
double)png_ptr->background.green/255, g) *
2562 (
png_byte)(pow((
double)png_ptr->background.blue/255, g) *
2566 g = 1.0 / png_ptr->background_gamma;
2569 (
png_byte)(pow((
double)png_ptr->background.red/255, g) *
2572 (
png_byte)(pow((
double)png_ptr->background.green/255, g) *
2575 (
png_byte)(pow((
double)png_ptr->background.blue/255, g) *
2585 if (i < png_ptr->
num_trans && png_ptr->trans[i] == 0)
2589 else if (i < png_ptr->
num_trans && png_ptr->trans[i] != 0xff)
2593 v = png_ptr->gamma_to_1[png_ptr->palette[
i].red];
2595 palette[
i].red = png_ptr->gamma_from_1[w];
2597 v = png_ptr->gamma_to_1[png_ptr->palette[
i].green];
2599 palette[
i].green = png_ptr->gamma_from_1[w];
2601 v = png_ptr->gamma_to_1[png_ptr->palette[
i].blue];
2603 palette[
i].blue = png_ptr->gamma_from_1[w];
2634 #if defined(PNG_READ_GAMMA_SUPPORTED) 2635 if (png_ptr->transformations & PNG_GAMMA)
2646 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 2650 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 2651 if (png_ptr->transformations & PNG_BACKGROUND)
2661 for (
i = 0;
i < (
int)png_ptr->num_trans;
i++)
2663 if (png_ptr->trans[
i] == 0)
2669 else if (png_ptr->trans[
i] != 0xff)
2672 png_ptr->trans[
i], back.
red);
2674 png_ptr->trans[
i], back.
green);
2676 png_ptr->trans[
i], back.
blue);
2686 if (i == (
png_byte)png_ptr->trans_values.gray)
2699 #if defined(PNG_READ_BACKGROUND_SUPPORTED) 2722 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
2723 row != NULL && row_info != NULL &&
2728 switch (row_info->color_type)
2732 switch (row_info->bit_depth)
2738 for (i = 0; i < row_width; i++)
2741 == trans_values->gray)
2743 *sp &= (
png_byte)((0x7f7f >> (7 - shift)) & 0xff);
2758 #if defined(PNG_READ_GAMMA_SUPPORTED) 2759 if (gamma_table != NULL)
2763 for (i = 0; i < row_width; i++)
2766 == trans_values->gray)
2768 *sp &= (
png_byte)((0x3f3f >> (6 - shift)) & 0xff);
2775 (p << 4) | (p << 6)] >> 6) & 0x03);
2776 *sp &= (
png_byte)((0x3f3f >> (6 - shift)) & 0xff);
2793 for (i = 0; i < row_width; i++)
2796 == trans_values->gray)
2798 *sp &= (
png_byte)((0x3f3f >> (6 - shift)) & 0xff);
2814 #if defined(PNG_READ_GAMMA_SUPPORTED) 2815 if (gamma_table != NULL)
2819 for (i = 0; i < row_width; i++)
2822 == trans_values->gray)
2824 *sp &= (
png_byte)((0xf0f >> (4 - shift)) & 0xff);
2831 (p << 4)] >> 4) & 0x0f);
2832 *sp &= (
png_byte)((0xf0f >> (4 - shift)) & 0xff);
2849 for (i = 0; i < row_width; i++)
2852 == trans_values->gray)
2854 *sp &= (
png_byte)((0xf0f >> (4 - shift)) & 0xff);
2870 #if defined(PNG_READ_GAMMA_SUPPORTED) 2871 if (gamma_table != NULL)
2874 for (i = 0; i < row_width; i++, sp++)
2876 if (*sp == trans_values->gray)
2882 *sp = gamma_table[*sp];
2890 for (i = 0; i < row_width; i++, sp++)
2892 if (*sp == trans_values->gray)
2902 #if defined(PNG_READ_GAMMA_SUPPORTED) 2903 if (gamma_16 != NULL)
2906 for (i = 0; i < row_width; i++, sp += 2)
2911 if (v == trans_values->gray)
2919 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
2929 for (i = 0; i < row_width; i++, sp += 2)
2934 if (v == trans_values->gray)
2948 if (row_info->bit_depth == 8)
2950 #if defined(PNG_READ_GAMMA_SUPPORTED) 2951 if (gamma_table != NULL)
2954 for (i = 0; i < row_width; i++, sp += 3)
2956 if (*sp == trans_values->red &&
2957 *(sp + 1) == trans_values->green &&
2958 *(sp + 2) == trans_values->blue)
2966 *sp = gamma_table[*sp];
2967 *(sp + 1) = gamma_table[*(sp + 1)];
2968 *(sp + 2) = gamma_table[*(sp + 2)];
2976 for (i = 0; i < row_width; i++, sp += 3)
2978 if (*sp == trans_values->red &&
2979 *(sp + 1) == trans_values->green &&
2980 *(sp + 2) == trans_values->blue)
2991 #if defined(PNG_READ_GAMMA_SUPPORTED) 2992 if (gamma_16 != NULL)
2995 for (i = 0; i < row_width; i++, sp += 6)
3000 if (r == trans_values->red && g == trans_values->green &&
3001 b == trans_values->blue)
3013 png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3016 v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
3017 *(sp + 2) = (
png_byte)((v >> 8) & 0xff);
3019 v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
3020 *(sp + 4) = (
png_byte)((v >> 8) & 0xff);
3029 for (i = 0; i < row_width; i++, sp += 6)
3035 if (r == trans_values->red && g == trans_values->green &&
3036 b == trans_values->blue)
3052 if (row_info->bit_depth == 8)
3054 #if defined(PNG_READ_GAMMA_SUPPORTED) 3055 if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
3056 gamma_table != NULL)
3060 for (i = 0; i < row_width; i++, sp += 2, dp++)
3066 *dp = gamma_table[*sp];
3077 v = gamma_to_1[*sp];
3079 *dp = gamma_from_1[w];
3088 for (i = 0; i < row_width; i++, sp += 2, dp++)
3096 #if defined(PNG_READ_GAMMA_SUPPORTED) 3113 #if defined(PNG_READ_GAMMA_SUPPORTED) 3114 if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
3115 gamma_16_to_1 != NULL)
3119 for (i = 0; i < row_width; i++, sp += 4, dp += 2)
3127 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3131 #if defined(PNG_READ_GAMMA_SUPPORTED) 3141 #if defined(PNG_READ_GAMMA_SUPPORTED) 3146 g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
3148 w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
3160 for (i = 0; i < row_width; i++, sp += 4, dp += 2)
3167 #if defined(PNG_READ_GAMMA_SUPPORTED) 3176 #if defined(PNG_READ_GAMMA_SUPPORTED) 3194 if (row_info->bit_depth == 8)
3196 #if defined(PNG_READ_GAMMA_SUPPORTED) 3197 if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
3198 gamma_table != NULL)
3202 for (i = 0; i < row_width; i++, sp += 4, dp += 3)
3208 *dp = gamma_table[*sp];
3209 *(dp + 1) = gamma_table[*(sp + 1)];
3210 *(dp + 2) = gamma_table[*(sp + 2)];
3223 v = gamma_to_1[*sp];
3225 *dp = gamma_from_1[w];
3226 v = gamma_to_1[*(sp + 1)];
3228 *(dp + 1) = gamma_from_1[w];
3229 v = gamma_to_1[*(sp + 2)];
3231 *(dp + 2) = gamma_from_1[w];
3240 for (i = 0; i < row_width; i++, sp += 4, dp += 3)
3247 *(dp + 1) = *(sp + 1);
3248 *(dp + 2) = *(sp + 2);
3269 #if defined(PNG_READ_GAMMA_SUPPORTED) 3270 if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
3271 gamma_16_to_1 != NULL)
3275 for (i = 0; i < row_width; i++, sp += 8, dp += 6)
3283 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
3286 v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
3287 *(dp + 2) = (
png_byte)((v >> 8) & 0xff);
3289 v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
3290 *(dp + 4) = (
png_byte)((v >> 8) & 0xff);
3307 v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
3309 x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
3312 v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
3314 x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
3315 *(dp + 2) = (
png_byte)((x >> 8) & 0xff);
3317 v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
3319 x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
3320 *(dp + 4) = (
png_byte)((x >> 8) & 0xff);
3330 for (i = 0; i < row_width; i++, sp += 8, dp += 6)
3361 *(dp + 2) = (
png_byte)((v >> 8) & 0xff);
3364 *(dp + 4) = (
png_byte)((v >> 8) & 0xff);
3377 row_info->channels--;
3378 row_info->pixel_depth = (
png_byte)(row_info->channels *
3379 row_info->bit_depth);
3380 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3386 #if defined(PNG_READ_GAMMA_SUPPORTED) 3404 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
3405 row != NULL && row_info != NULL &&
3407 ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
3408 (row_info->bit_depth == 16 && gamma_16_table != NULL)))
3410 switch (row_info->color_type)
3414 if (row_info->bit_depth == 8)
3417 for (i = 0; i < row_width; i++)
3419 *sp = gamma_table[*sp];
3421 *sp = gamma_table[*sp];
3423 *sp = gamma_table[*sp];
3430 for (i = 0; i < row_width; i++)
3434 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3438 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3442 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3452 if (row_info->bit_depth == 8)
3455 for (i = 0; i < row_width; i++)
3457 *sp = gamma_table[*sp];
3459 *sp = gamma_table[*sp];
3461 *sp = gamma_table[*sp];
3469 for (i = 0; i < row_width; i++)
3471 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3475 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3479 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3489 if (row_info->bit_depth == 8)
3492 for (i = 0; i < row_width; i++)
3494 *sp = gamma_table[*sp];
3501 for (i = 0; i < row_width; i++)
3503 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3513 if (row_info->bit_depth == 2)
3516 for (i = 0; i < row_width; i += 4)
3524 ((((
int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
3525 ((((
int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
3526 ((((
int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
3527 ((((
int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
3531 if (row_info->bit_depth == 4)
3534 for (i = 0; i < row_width; i += 2)
3536 int msb = *sp & 0xf0;
3537 int lsb = *sp & 0x0f;
3539 *sp = (
png_byte)((((
int)gamma_table[msb | (msb >> 4)]) & 0xf0)
3540 | (((
int)gamma_table[(lsb << 4) | lsb]) >> 4));
3544 else if (row_info->bit_depth == 8)
3547 for (i = 0; i < row_width; i++)
3549 *sp = gamma_table[*sp];
3553 else if (row_info->bit_depth == 16)
3556 for (i = 0; i < row_width; i++)
3558 png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
3571 #if defined(PNG_READ_EXPAND_SUPPORTED) 3584 png_debug(1,
"in png_do_expand_palette\n");
3586 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
3587 row != NULL && row_info != NULL &&
3591 if (row_info->bit_depth < 8)
3593 switch (row_info->bit_depth)
3597 sp = row + (
png_size_t)((row_width - 1) >> 3);
3599 shift = 7 - (
int)((row_width + 7) & 0x07);
3600 for (i = 0; i < row_width; i++)
3602 if ((*sp >> shift) & 0x01)
3620 sp = row + (
png_size_t)((row_width - 1) >> 2);
3622 shift = (
int)((3 - ((row_width + 3) & 0x03)) << 1);
3623 for (i = 0; i < row_width; i++)
3625 value = (*sp >> shift) & 0x03;
3641 sp = row + (
png_size_t)((row_width - 1) >> 1);
3643 shift = (
int)((row_width & 0x01) << 2);
3644 for (i = 0; i < row_width; i++)
3646 value = (*sp >> shift) & 0x0f;
3661 row_info->bit_depth = 8;
3662 row_info->pixel_depth = 8;
3663 row_info->rowbytes = row_width;
3665 switch (row_info->bit_depth)
3674 for (i = 0; i < row_width; i++)
3680 *dp-- = palette[*sp].blue;
3681 *dp-- = palette[*sp].green;
3682 *dp-- = palette[*sp].red;
3685 row_info->bit_depth = 8;
3686 row_info->pixel_depth = 32;
3687 row_info->rowbytes = row_width * 4;
3688 row_info->color_type = 6;
3689 row_info->channels = 4;
3696 for (i = 0; i < row_width; i++)
3698 *dp-- = palette[*sp].blue;
3699 *dp-- = palette[*sp].green;
3700 *dp-- = palette[*sp].red;
3703 row_info->bit_depth = 8;
3704 row_info->pixel_depth = 24;
3705 row_info->rowbytes = row_width * 3;
3706 row_info->color_type = 2;
3707 row_info->channels = 3;
3728 #if defined(PNG_USELESS_TESTS_SUPPORTED) 3729 if (row != NULL && row_info != NULL)
3736 if (row_info->bit_depth < 8)
3738 switch (row_info->bit_depth)
3743 sp = row + (
png_size_t)((row_width - 1) >> 3);
3745 shift = 7 - (
int)((row_width + 7) & 0x07);
3746 for (i = 0; i < row_width; i++)
3748 if ((*sp >> shift) & 0x01)
3767 sp = row + (
png_size_t)((row_width - 1) >> 2);
3769 shift = (
int)((3 - ((row_width + 3) & 0x03)) << 1);
3770 for (i = 0; i < row_width; i++)
3772 value = (*sp >> shift) & 0x03;
3773 *dp = (
png_byte)(value | (value << 2) | (value << 4) |
3790 sp = row + (
png_size_t)((row_width - 1) >> 1);
3792 shift = (
int)((1 - ((row_width + 1) & 0x01)) << 2);
3793 for (i = 0; i < row_width; i++)
3795 value = (*sp >> shift) & 0x0f;
3796 *dp = (
png_byte)(value | (value << 4));
3810 row_info->bit_depth = 8;
3811 row_info->pixel_depth = 8;
3812 row_info->rowbytes = row_width;
3815 if (trans_value != NULL)
3817 if (row_info->bit_depth == 8)
3822 for (i = 0; i < row_width; i++)
3831 else if (row_info->bit_depth == 16)
3833 png_byte gray_high = (gray >> 8) & 0xff;
3835 sp = row + row_info->rowbytes - 1;
3836 dp = row + (row_info->rowbytes << 1) - 1;
3837 for (i = 0; i < row_width; i++)
3839 if (*(sp - 1) == gray_high && *(sp) == gray_low)
3854 row_info->channels = 2;
3855 row_info->pixel_depth = (
png_byte)(row_info->bit_depth << 1);
3856 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
3862 if (row_info->bit_depth == 8)
3866 png_byte blue = trans_value->blue & 0xff;
3867 sp = row + (
png_size_t)row_info->rowbytes - 1;
3869 for (i = 0; i < row_width; i++)
3871 if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
3880 else if (row_info->bit_depth == 16)
3882 png_byte red_high = (trans_value->red >> 8) & 0xff;
3883 png_byte green_high = (trans_value->green >> 8) & 0xff;
3884 png_byte blue_high = (trans_value->blue >> 8) & 0xff;
3885 png_byte red_low = trans_value->red & 0xff;
3886 png_byte green_low = trans_value->green & 0xff;
3887 png_byte blue_low = trans_value->blue & 0xff;
3888 sp = row + row_info->rowbytes - 1;
3890 for (i = 0; i < row_width; i++)
3892 if (*(sp - 5) == red_high &&
3893 *(sp - 4) == red_low &&
3894 *(sp - 3) == green_high &&
3895 *(sp - 2) == green_low &&
3896 *(sp - 1) == blue_high &&
3916 row_info->channels = 4;
3917 row_info->pixel_depth = (
png_byte)(row_info->bit_depth << 2);
3918 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3924 #if defined(PNG_READ_DITHER_SUPPORTED) 3934 #if defined(PNG_USELESS_TESTS_SUPPORTED) 3935 if (row != NULL && row_info != NULL)
3939 palette_lookup && row_info->bit_depth == 8)
3944 for (i = 0; i < row_width; i++)
3957 p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
3958 ((1 << PNG_DITHER_RED_BITS) - 1)) <<
3959 (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
3960 (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
3961 ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
3962 (PNG_DITHER_BLUE_BITS)) |
3963 ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
3964 ((1 << PNG_DITHER_BLUE_BITS) - 1));
3966 *dp++ = palette_lookup[p];
3969 row_info->channels = 1;
3970 row_info->pixel_depth = row_info->bit_depth;
3971 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
3974 palette_lookup != NULL && row_info->bit_depth == 8)
3979 for (i = 0; i < row_width; i++)
3986 p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
3987 ((1 << PNG_DITHER_RED_BITS) - 1)) <<
3988 (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
3989 (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
3990 ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
3991 (PNG_DITHER_BLUE_BITS)) |
3992 ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
3993 ((1 << PNG_DITHER_BLUE_BITS) - 1));
3995 *dp++ = palette_lookup[p];
3998 row_info->channels = 1;
3999 row_info->pixel_depth = row_info->bit_depth;
4000 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
4003 dither_lookup && row_info->bit_depth == 8)
4006 for (i = 0; i < row_width; i++, sp++)
4008 *sp = dither_lookup[*sp];
4015 #ifdef PNG_FLOATING_POINT_SUPPORTED 4016 #if defined(PNG_READ_GAMMA_SUPPORTED) 4018 {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
4028 png_debug(1,
"in png_build_gamma_table\n");
4030 if (png_ptr->bit_depth <= 8)
4035 if (png_ptr->screen_gamma > .000001)
4036 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
4043 for (i = 0; i < 256; i++)
4045 png_ptr->gamma_table[
i] = (
png_byte)(pow((
double)i / 255.0,
4049 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ 4050 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 4051 if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
4054 g = 1.0 / (png_ptr->gamma);
4059 for (i = 0; i < 256; i++)
4061 png_ptr->gamma_to_1[
i] = (
png_byte)(pow((
double)i / 255.0,
4069 if (png_ptr->screen_gamma > 0.000001)
4070 g = 1.0 / png_ptr->screen_gamma;
4074 for (i = 0; i < 256; i++)
4076 png_ptr->gamma_from_1[
i] = (
png_byte)(pow((
double)i / 255.0,
4086 int i,
j, shift,
num;
4092 sig_bit = (
int)png_ptr->sig_bit.red;
4093 if ((
int)png_ptr->sig_bit.green >
sig_bit)
4094 sig_bit = png_ptr->sig_bit.green;
4095 if ((
int)png_ptr->sig_bit.blue >
sig_bit)
4096 sig_bit = png_ptr->sig_bit.blue;
4100 sig_bit = (
int)png_ptr->sig_bit.gray;
4108 if (png_ptr->transformations & PNG_16_TO_8)
4110 if (shift < (16 - PNG_MAX_GAMMA_8))
4111 shift = (16 - PNG_MAX_GAMMA_8);
4119 png_ptr->gamma_shift = (
png_byte)shift;
4121 num = (1 << (8 - shift));
4123 if (png_ptr->screen_gamma > .000001)
4124 g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
4131 if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
4136 for (i = 0; i <
num; i++)
4144 for (i = 0; i < 256; i++)
4146 fout = ((double)i + 0.5) / 256.0;
4151 png_ptr->gamma_16_table[(
int)(last & (0xff >> shift))]
4159 png_ptr->gamma_16_table[(
int)(last & (0xff >> shift))]
4160 [(
int)(last >> (8 - shift))] = (
png_uint_16)65535L;
4166 for (i = 0; i <
num; i++)
4172 for (j = 0; j < 256; j++)
4174 png_ptr->gamma_16_table[
i][j] =
4176 65535.0, g) * 65535.0 + .5);
4181 #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ 4182 defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) 4183 if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
4186 g = 1.0 / (png_ptr->gamma);
4191 for (i = 0; i <
num; i++)
4198 for (j = 0; j < 256; j++)
4200 png_ptr->gamma_16_to_1[
i][j] =
4202 65535.0, g) * 65535.0 + .5);
4206 if (png_ptr->screen_gamma > 0.000001)
4207 g = 1.0 / png_ptr->screen_gamma;
4214 for (i = 0; i <
num; i++)
4221 for (j = 0; j < 256; j++)
4223 png_ptr->gamma_16_from_1[
i][j] =
4225 65535.0, g) * 65535.0 + .5);
4236 #if defined(PNG_MNG_FEATURES_SUPPORTED) 4241 png_debug(1,
"in png_do_read_intrapixel\n");
4243 #
if defined(PNG_USELESS_TESTS_SUPPORTED)
4244 row != NULL && row_info != NULL &&
4248 int bytes_per_pixel;
4250 if (row_info->bit_depth == 8)
4256 bytes_per_pixel = 3;
4258 bytes_per_pixel = 4;
4262 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
4264 *(rp) = (
png_byte)((256 + *rp + *(rp+1))&0xff);
4265 *(rp+2) = (
png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
4268 else if (row_info->bit_depth == 16)
4274 bytes_per_pixel = 6;
4276 bytes_per_pixel = 8;
4280 for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
4287 *(rp ) = (
png_byte)((red >> 8) & 0xff);
4289 *(rp+4) = (
png_byte)((blue >> 8) & 0xff);
void png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
#define PNG_CRC_NO_CHANGE
struct png_dsort_struct png_dsort
#define PNG_BACKGROUND_GAMMA_UNIQUE
void png_do_packswap(png_row_infop row_info, png_bytep row)
void PNGAPI png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action, png_fixed_point red, png_fixed_point green)
png_color_16p int int double background_gamma
png_colorp int int png_uint_16p int full_dither
void PNGAPI png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
void png_do_background(png_row_infop row_info, png_bytep row, png_color_16p trans_values, png_color_16p background, png_color_16p background_1, png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, png_uint_16pp gamma_16_to_1, int gamma_shift)
void png_do_gamma(png_row_infop row_info, png_bytep row, png_bytep gamma_table, png_uint_16pp gamma_16_table, int gamma_shift)
void png_do_invert(png_row_infop row_info, png_bytep row)
void png_do_expand(png_row_infop row_info, png_bytep row, png_color_16p trans_value)
#define png_composite(composite, fg, alpha, bg)
void png_do_read_filler(png_row_infop row_info, png_bytep row, png_uint_32 filler, png_uint_32 flags)
png_colorp int num_palette
#define PNG_BACKGROUND_GAMMA_SCREEN
void PNGAPI png_set_palette_to_rgb(png_structp png_ptr)
png_color_16 FAR * png_color_16p
void png_build_gamma_table(png_structp png_ptr)
#define PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_GRAY_ALPHA
png_infop png_color_16p * background
void png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
#define PNG_COLOR_TYPE_PALETTE
png_colorp int int png_uint_16p histogram
void PNGAPI png_set_dither(png_structp png_ptr, png_colorp palette, int num_palette, int maximum_colors, png_uint_16p histogram, int full_dither)
#define PNG_CRC_WARN_DISCARD
void PNGAPI png_set_background(png_structp png_ptr, png_color_16p background_color, int background_gamma_code, int need_expand, double background_gamma)
void png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
#define PNG_COLOR_TYPE_RGB_ALPHA
void png_do_read_transformations(png_structp png_ptr)
png_color_16p int int need_expand
void PNGAPI png_set_strip_16(png_structp png_ptr)
void png_do_chop(png_row_infop row_info, png_bytep row)
#define PNG_BACKGROUND_GAMMA_FILE
int png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_infop png_bytep * trans
void PNGAPI png_set_gray_1_2_4_to_8(png_structp png_ptr)
png_infop png_bytep int png_color_16p * trans_values
void png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
void png_init_read_transformations(png_structp png_ptr)
void png_do_dither(png_row_infop row_info, png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup)
void PNGAPI png_build_grayscale_palette(int bit_depth, png_colorp palette)
void png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
SequenceElement & back(CorbaSequence &seq)
png_struct FAR * png_structp
#define PNG_READ_BACKGROUND_SUPPORTED
#define PNG_COLOR_MASK_COLOR
png_dsort FAR *FAR * png_dsortpp
void PNGAPI png_error(png_structp png_ptr, png_const_charp error_message)
void png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
unsigned short png_uint_16
png_infop int png_uint_32 mask
def j(str, encoding="cp932")
#define PNG_CRC_QUIET_USE
png_infop png_bytep int * num_trans
#define PNG_COLOR_TYPE_GRAY
struct png_dsort_struct FAR * next
void PNGAPI png_warning(png_structp png_ptr, png_const_charp warning_message)
png_dsort FAR * png_dsortp
void png_do_bgr(png_row_infop row_info, png_bytep row)
png_uint_16 FAR * png_uint_16p
void PNGAPI png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
void PNGAPI png_set_strip_alpha(png_structp png_ptr)
void png_do_expand_palette(png_row_infop row_info, png_bytep row, png_colorp palette, png_bytep trans, int num_trans)
png_infop png_uint_32 png_uint_32 int * bit_depth
png_infop double * file_gamma
#define PNG_CRC_ERROR_QUIT
void png_do_unpack(png_row_infop row_info, png_bytep row)
png_uint_16 FAR *FAR * png_uint_16pp
#define PNG_COLOR_MASK_ALPHA
void png_do_swap(png_row_infop row_info, png_bytep row)
png_infop png_uint_32 png_uint_32 int int * color_type
void PNGAPI png_set_expand(png_structp png_ptr)
png_color_8 FAR * png_color_8p
#define png_composite_16(composite, fg, alpha, bg)
void PNGAPI png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
void PNGAPI png_set_tRNS_to_alpha(png_structp png_ptr)
png_int_32 png_fixed_point
png_color_16p background_color
#define PNG_BACKGROUND_GAMMA_UNKNOWN
static PNG_CONST int png_gamma_shift[]
png_colorp int int maximum_colors
void PNGAPI png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr read_user_transform_fn)
unsigned long png_uint_32
png_row_info FAR * png_row_infop
void png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
void PNGAPI png_free(png_structp png_ptr, png_voidp ptr)
png_color_16p int background_gamma_code
void PNGAPI png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, double green)
static int max(int a, int b)
png_voidp PNGAPI png_malloc(png_structp png_ptr, png_uint_32 size)
png_voidp PNGAPI png_malloc_warn(png_structp png_ptr, png_uint_32 size)
void PNGAPI png_set_gray_to_rgb(png_structp png_ptr)
png_user_transform_ptr read_user_transform_fn
#define PNG_READ_GAMMA_SUPPORTED
png_infop png_color_8p * sig_bit
png_color FAR * png_colorp