Housecleaning: revise identation and comments to meet libpng coding style.

This commit is contained in:
Glenn Randers-Pehrson glennrp@comcast.net
2009-05-15 20:39:34 -05:00
parent 9a692c0769
commit b1c0d33128
19 changed files with 1845 additions and 1390 deletions

View File

@@ -23,24 +23,29 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
{
png_debug(1, "in png_set_crc_action");
/* Tell libpng how we react to CRC errors in critical chunks */
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
switch (crit_action)
{
case PNG_CRC_NO_CHANGE: /* leave setting as is */
break;
case PNG_CRC_WARN_USE: /* warn/use data */
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
break;
case PNG_CRC_QUIET_USE: /* quiet/use data */
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
PNG_FLAG_CRC_CRITICAL_IGNORE;
break;
case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
png_warning(png_ptr,
"Can't discard critical data on CRC error");
case PNG_CRC_ERROR_QUIT: /* error/quit */
case PNG_CRC_DEFAULT:
default:
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
@@ -51,20 +56,25 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
{
case PNG_CRC_NO_CHANGE: /* leave setting as is */
break;
case PNG_CRC_WARN_USE: /* warn/use data */
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
break;
case PNG_CRC_QUIET_USE: /* quiet/use data */
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
PNG_FLAG_CRC_ANCILLARY_NOWARN;
break;
case PNG_CRC_ERROR_QUIT: /* error/quit */
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
break;
case PNG_CRC_WARN_DISCARD: /* warn/discard data */
case PNG_CRC_DEFAULT:
default:
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
@@ -81,7 +91,8 @@ png_set_background(png_structp png_ptr,
int need_expand, double background_gamma)
{
png_debug(1, "in png_set_background");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
{
png_warning(png_ptr, "Application must supply a known background gamma");
@@ -98,12 +109,13 @@ png_set_background(png_structp png_ptr,
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* strip 16 bit depth files to 8 bit depth */
/* Strip 16 bit depth files to 8 bit depth */
void PNGAPI
png_set_strip_16(png_structp png_ptr)
{
png_debug(1, "in png_set_strip_16");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->transformations |= PNG_16_TO_8;
}
#endif
@@ -113,7 +125,8 @@ void PNGAPI
png_set_strip_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_strip_alpha");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
}
#endif
@@ -123,7 +136,8 @@ void PNGAPI
png_set_premultiply_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_premultiply_alpha");
if(png_ptr == NULL) return;
if(png_ptr == NULL)
return;
png_ptr->transformations |=
(PNG_PREMULTIPLY_ALPHA | PNG_EXPAND_tRNS);
png_ptr->transformations |=
@@ -157,7 +171,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int full_dither)
{
png_debug(1, "in png_set_dither");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->transformations |= PNG_DITHER;
if (!full_dither)
@@ -175,7 +190,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
if (histogram != NULL)
{
/* This is easy enough, just throw out the least used colors.
Perhaps not the best solution, but good enough. */
* Perhaps not the best solution, but good enough.
*/
int i;
@@ -188,10 +204,11 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_ptr->dither_sort[i] = (png_byte)i;
/* Find the least used palette entries by starting a
bubble sort, and running it until we have sorted
out enough colors. Note that we don't care about
sorting all the colors, just finding which are
least used. */
* bubble sort, and running it until we have sorted
* out enough colors. Note that we don't care about
* sorting all the colors, just finding which are
* least used.
*/
for (i = num_palette - 1; i >= maximum_colors; i--)
{
@@ -216,13 +233,14 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
break;
}
/* swap the palette around, and set up a table, if necessary */
/* Swap the palette around, and set up a table, if necessary */
if (full_dither)
{
int j = num_palette;
/* put all the useful colors within the max, but don't
move the others */
/* Put all the useful colors within the max, but don't
* move the others.
*/
for (i = 0; i < maximum_colors; i++)
{
if ((int)png_ptr->dither_sort[i] >= maximum_colors)
@@ -238,11 +256,12 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
int j = num_palette;
/* move all the used colors inside the max limit, and
develop a translation table */
/* Move all the used colors inside the max limit, and
* develop a translation table.
*/
for (i = 0; i < maximum_colors; i++)
{
/* only move the colors we need to */
/* Only move the colors we need to */
if ((int)png_ptr->dither_sort[i] >= maximum_colors)
{
png_color tmp_color;
@@ -254,20 +273,20 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
tmp_color = palette[j];
palette[j] = palette[i];
palette[i] = tmp_color;
/* indicate where the color went */
/* Indicate where the color went */
png_ptr->dither_index[j] = (png_byte)i;
png_ptr->dither_index[i] = (png_byte)j;
}
}
/* find closest color for those colors we are not using */
/* Find closest color for those colors we are not using */
for (i = 0; i < num_palette; i++)
{
if ((int)png_ptr->dither_index[i] >= maximum_colors)
{
int min_d, k, min_k, d_index;
/* find the closest color to one we threw out */
/* Find the closest color to one we threw out */
d_index = png_ptr->dither_index[i];
min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
for (k = 1, min_k = 0; k < maximum_colors; k++)
@@ -282,7 +301,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
min_k = k;
}
}
/* point to closest color */
/* Point to closest color */
png_ptr->dither_index[i] = (png_byte)min_k;
}
}
@@ -293,13 +312,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
else
{
/* This is much harder to do simply (and quickly). Perhaps
we need to go through a median cut routine, but those
don't always behave themselves with only a few colors
as input. So we will just find the closest two colors,
and throw out one of them (chosen somewhat randomly).
[We don't understand this at all, so if someone wants to
work on improving it, be our guest - AED, GRP]
*/
* we need to go through a median cut routine, but those
* don't always behave themselves with only a few colors
* as input. So we will just find the closest two colors,
* and throw out one of them (chosen somewhat randomly).
* [We don't understand this at all, so if someone wants to
* work on improving it, be our guest - AED, GRP]
*/
int i;
int max_d;
int num_new_palette;
@@ -308,13 +327,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
t = NULL;
/* initialize palette index arrays */
/* Initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * png_sizeof(png_byte)));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * png_sizeof(png_byte)));
/* initialize the sort array */
/* Initialize the sort array */
for (i = 0; i < num_palette; i++)
{
png_ptr->index_to_palette[i] = (png_byte)i;
@@ -332,14 +351,14 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
num_new_palette = num_palette;
/* initial wild guess at how far apart the farthest pixel
pair we will be eliminating will be. Larger
numbers mean more areas will be allocated, Smaller
numbers run the risk of not saving enough data, and
having to do this all over again.
I have not done extensive checking on this number.
*/
/* Initial wild guess at how far apart the farthest pixel
* pair we will be eliminating will be. Larger
* numbers mean more areas will be allocated, Smaller
* numbers run the risk of not saving enough data, and
* having to do this all over again.
*
* I have not done extensive checking on this number.
*/
max_d = 96;
while (num_new_palette > maximum_colors)
@@ -548,7 +567,8 @@ void PNGAPI
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{
png_debug(1, "in png_set_gamma");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
@@ -567,7 +587,8 @@ void PNGAPI
png_set_expand(png_structp png_ptr)
{
png_debug(1, "in png_set_expand");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
@@ -594,7 +615,8 @@ void PNGAPI
png_set_palette_to_rgb(png_structp png_ptr)
{
png_debug(1, "in png_set_palette_to_rgb");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
@@ -604,7 +626,8 @@ void PNGAPI
png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
{
png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
png_ptr->transformations |= PNG_EXPAND;
png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
@@ -641,10 +664,11 @@ void PNGAPI
png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
double green)
{
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
if (png_ptr == NULL) return;
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
if (png_ptr == NULL)
return;
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
}
#endif
@@ -653,13 +677,16 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_fixed_point red, png_fixed_point green)
{
png_debug(1, "in png_set_rgb_to_gray");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
switch(error_action)
{
case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
break;
case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
break;
case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
}
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
@@ -681,8 +708,8 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
}
else if (red + green < 100000L)
{
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
}
else
{
@@ -706,7 +733,8 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
read_user_transform_fn)
{
png_debug(1, "in png_set_read_user_transform_fn");
if (png_ptr == NULL) return;
if (png_ptr == NULL)
return;
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->read_user_transform_fn = read_user_transform_fn;
@@ -736,8 +764,9 @@ png_init_read_transformations(png_structp png_ptr)
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* Detect gray background and attempt to enable optimization
* for gray --> RGB case */
/* Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
* for gray --> RGB case
*
* Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
* RGB_ALPHA (in which case need_expand is superfluous anyway), the
* background color might actually be gray yet not be flagged as such.
* This is not a problem for the current code, which uses
@@ -764,7 +793,7 @@ png_init_read_transformations(png_structp png_ptr)
{
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{
/* expand background and tRNS chunks */
/* Expand background and tRNS chunks */
switch (png_ptr->bit_depth)
{
case 1:
@@ -778,6 +807,7 @@ png_init_read_transformations(png_structp png_ptr)
= png_ptr->trans_color.blue = png_ptr->trans_color.gray;
}
break;
case 2:
png_ptr->background.gray *= (png_uint_16)0x55;
png_ptr->background.red = png_ptr->background.green
@@ -789,6 +819,7 @@ png_init_read_transformations(png_structp png_ptr)
= png_ptr->trans_color.blue = png_ptr->trans_color.gray;
}
break;
case 4:
png_ptr->background.gray *= (png_uint_16)0x11;
png_ptr->background.red = png_ptr->background.green
@@ -800,7 +831,9 @@ png_init_read_transformations(png_structp png_ptr)
= png_ptr->trans_color.blue = png_ptr->trans_color.gray;
}
break;
case 8:
case 16:
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
@@ -823,8 +856,9 @@ png_init_read_transformations(png_structp png_ptr)
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
#endif
{
/* invert the alpha channel (in tRNS) unless the pixels are
going to be expanded, in which case leave it for later */
/* Invert the alpha channel (in tRNS) unless the pixels are
* going to be expanded, in which case leave it for later
*/
int i, istop;
istop=(int)png_ptr->num_trans;
for (i=0; i<istop; i++)
@@ -866,8 +900,7 @@ png_init_read_transformations(png_structp png_ptr)
{
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
/* could skip if no transparency and
*/
/* Could skip if no transparency */
png_color back, back_1;
png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette;
@@ -892,10 +925,12 @@ png_init_read_transformations(png_structp png_ptr)
g = (png_ptr->screen_gamma);
gs = 1.0;
break;
case PNG_BACKGROUND_GAMMA_FILE:
g = 1.0 / (png_ptr->gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
g = 1.0 / (png_ptr->background_gamma);
gs = 1.0 / (png_ptr->background_gamma *
@@ -984,10 +1019,12 @@ png_init_read_transformations(png_structp png_ptr)
g = (png_ptr->screen_gamma);
gs = 1.0;
break;
case PNG_BACKGROUND_GAMMA_FILE:
g = 1.0 / (png_ptr->gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
g = 1.0 / (png_ptr->background_gamma);
gs = 1.0 / (png_ptr->background_gamma *
@@ -1201,8 +1238,8 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
if (png_ptr->transformations & PNG_DITHER)
{
if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
png_ptr->palette_lookup && info_ptr->bit_depth == 8)
(info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
png_ptr->palette_lookup && info_ptr->bit_depth == 8)
{
info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
}
@@ -1236,7 +1273,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
{
info_ptr->channels++;
/* if adding a true alpha channel not just filler */
/* If adding a true alpha channel not just filler */
if (png_ptr->transformations & PNG_ADD_ALPHA)
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
}
@@ -1289,7 +1326,8 @@ png_do_read_transformations(png_structp png_ptr)
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
/* Application has failed to call either png_read_start_image()
* or png_read_update_info() after setting transforms that expand
* pixels. This check added to libpng-1.2.19 */
* pixels. This check added to libpng-1.2.19
*/
#if (PNG_WARN_UNINITIALIZED_ROW==1)
png_error(png_ptr, "Uninitialized row");
#else
@@ -1342,39 +1380,41 @@ png_do_read_transformations(png_structp png_ptr)
}
#endif
/*
From Andreas Dilger e-mail to png-implement, 26 March 1998:
In most cases, the "simple transparency" should be done prior to doing
gray-to-RGB, or you will have to test 3x as many bytes to check if a
pixel is transparent. You would also need to make sure that the
transparency information is upgraded to RGB.
To summarize, the current flow is:
- Gray + simple transparency -> compare 1 or 2 gray bytes and composite
with background "in place" if transparent,
convert to RGB if necessary
- Gray + alpha -> composite with gray background and remove alpha bytes,
convert to RGB if necessary
To support RGB backgrounds for gray images we need:
- Gray + simple transparency -> convert to RGB + simple transparency, compare
3 or 6 bytes and composite with background
"in place" if transparent (3x compare/pixel
compared to doing composite with gray bkgrnd)
- Gray + alpha -> convert to RGB + alpha, composite with background and
remove alpha bytes (3x float operations/pixel
compared with composite on gray background)
Greg's change will do this. The reason it wasn't done before is for
performance, as this increases the per-pixel operations. If we would check
in advance if the background was gray or RGB, and position the gray-to-RGB
transform appropriately, then it would save a lot of work/time.
/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
*
* In most cases, the "simple transparency" should be done prior to doing
* gray-to-RGB, or you will have to test 3x as many bytes to check if a
* pixel is transparent. You would also need to make sure that the
* transparency information is upgraded to RGB.
*
* To summarize, the current flow is:
* - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
* with background "in place" if transparent,
* convert to RGB if necessary
* - Gray + alpha -> composite with gray background and remove alpha bytes,
* convert to RGB if necessary
*
* To support RGB backgrounds for gray images we need:
* - Gray + simple transparency -> convert to RGB + simple transparency,
* compare 3 or 6 bytes and composite with
* background "in place" if transparent
* (3x compare/pixel compared to doing
* composite with gray bkgrnd)
* - Gray + alpha -> convert to RGB + alpha, composite with background and
* remove alpha bytes (3x float
* operations/pixel compared with composite
* on gray background)
*
* Greg's change will do this. The reason it wasn't done before is for
* performance, as this increases the per-pixel operations. If we would check
* in advance if the background was gray or RGB, and position the gray-to-RGB
* transform appropriately, then it would save a lot of work/time.
*/
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* if gray -> RGB, do so now only if background is non-gray; else do later
* for performance reasons */
/* If gray -> RGB, do so now only if background is non-gray; else do later
* for performance reasons
*/
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
!(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -1404,14 +1444,14 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#if defined(PNG_READ_GAMMA_SUPPORTED)
if ((png_ptr->transformations & PNG_GAMMA) &&
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
!((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
!((png_ptr->transformations & PNG_BACKGROUND) &&
((png_ptr->num_trans != 0) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
#endif
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->gamma_table, png_ptr->gamma_16_table,
png_ptr->gamma_shift);
png_ptr->gamma_table, png_ptr->gamma_16_table,
png_ptr->gamma_shift);
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
@@ -1451,7 +1491,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* if gray -> RGB, do so now only if we did not do so above */
/* If gray -> RGB, do so now only if we did not do so above */
if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -1488,16 +1528,16 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
if (png_ptr->read_user_transform_fn != NULL)
(*(png_ptr->read_user_transform_fn)) /* user read transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
(*(png_ptr->read_user_transform_fn)) /* user read transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (png_ptr->user_transform_depth)
png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
@@ -1551,6 +1591,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
break;
}
case 2:
{
@@ -1572,6 +1613,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
break;
}
case 4:
{
png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
@@ -1660,6 +1702,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
}
break;
}
case 4:
{
png_bytep bp = row;
@@ -1675,6 +1718,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
}
break;
}
case 8:
{
png_bytep bp = row;
@@ -1687,6 +1731,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
}
break;
}
case 16:
{
png_bytep bp = row;
@@ -1708,7 +1753,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* chop rows of bit depth 16 down to 8 */
/* Chop rows of bit depth 16 down to 8 */
void /* PRIVATE */
png_do_chop(png_row_infop row_info, png_bytep row)
{
@@ -1728,14 +1773,17 @@ png_do_chop(png_row_infop row_info, png_bytep row)
*
* What the ideal calculation should be:
* *dp = (((((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
* (png_uint_32)(*(sp + 1))) * 255 + 127)
* / (png_uint_32)65535L;
*
* GRR: no, I think this is what it really should be:
* *dp = (((((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
* (png_uint_32)(*(sp + 1))) + 128L)
* / (png_uint_32)257L;
*
* GRR: here's the exact calculation with shifts:
* temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
* temp = (((png_uint_32)(*sp) << 8) |
* (png_uint_32)(*(sp + 1))) + 128L;
* *dp = (temp - (temp >> 8)) >> 8;
*
* Approximate calculation with shift/add instead of multiply/divide:
@@ -2549,18 +2597,22 @@ png_build_grayscale_palette(int bit_depth, png_colorp palette)
num_palette = 2;
color_inc = 0xff;
break;
case 2:
num_palette = 4;
color_inc = 0x55;
break;
case 4:
num_palette = 16;
color_inc = 0x11;
break;
case 8:
num_palette = 256;
color_inc = 1;
break;
default:
num_palette = 0;
color_inc = 0;
@@ -2630,6 +2682,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case 2:
{
#if defined(PNG_READ_GAMMA_SUPPORTED)
@@ -2686,6 +2739,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case 4:
{
#if defined(PNG_READ_GAMMA_SUPPORTED)
@@ -2742,6 +2796,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case 8:
{
#if defined(PNG_READ_GAMMA_SUPPORTED)
@@ -2774,6 +2829,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case 16:
{
#if defined(PNG_READ_GAMMA_SUPPORTED)
@@ -2787,7 +2843,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
if (v == trans_color->gray)
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*sp = (png_byte)((background->gray >> 8) & 0xff);
*(sp + 1) = (png_byte)(background->gray & 0xff);
}
@@ -2820,6 +2876,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_RGB:
{
if (row_info->bit_depth == 8)
@@ -2877,7 +2934,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
if (r == trans_color->red && g == trans_color->green &&
b == trans_color->blue)
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*sp = (png_byte)((background->red >> 8) & 0xff);
*(sp + 1) = (png_byte)(background->red & 0xff);
*(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
@@ -2924,6 +2981,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_GRAY_ALPHA:
{
if (row_info->bit_depth == 8)
@@ -2944,7 +3002,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else if (a == 0)
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*dp = (png_byte)background->gray;
}
else
@@ -3011,7 +3069,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
else
#endif
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*dp = (png_byte)((background->gray >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->gray & 0xff);
}
@@ -3066,6 +3124,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_RGB_ALPHA:
{
if (row_info->bit_depth == 8)
@@ -3088,7 +3147,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else if (a == 0)
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*dp = (png_byte)background->red;
*(dp + 1) = (png_byte)background->green;
*(dp + 2) = (png_byte)background->blue;
@@ -3169,7 +3228,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
}
else if (a == 0)
{
/* background is already in screen gamma */
/* Background is already in screen gamma */
*dp = (png_byte)((background->red >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->red & 0xff);
*(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
@@ -3321,6 +3380,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_RGB_ALPHA:
{
if (row_info->bit_depth == 8)
@@ -3358,6 +3418,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_GRAY_ALPHA:
{
if (row_info->bit_depth == 8)
@@ -3382,6 +3443,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
}
break;
}
case PNG_COLOR_TYPE_GRAY:
{
if (row_info->bit_depth == 2)
@@ -3402,6 +3464,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp++;
}
}
if (row_info->bit_depth == 4)
{
sp = row;
@@ -3415,6 +3478,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp++;
}
}
else if (row_info->bit_depth == 8)
{
sp = row;
@@ -3424,6 +3488,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
sp++;
}
}
else if (row_info->bit_depth == 16)
{
sp = row;
@@ -3486,6 +3551,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
break;
}
case 2:
{
sp = row + (png_size_t)((row_width - 1) >> 2);
@@ -3507,6 +3573,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
break;
}
case 4:
{
sp = row + (png_size_t)((row_width - 1) >> 1);
@@ -3571,6 +3638,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
*dp-- = palette[*sp].red;
sp--;
}
row_info->bit_depth = 8;
row_info->pixel_depth = 24;
row_info->rowbytes = row_width * 3;
@@ -3629,6 +3697,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
break;
}
case 2:
{
gray = (png_uint_16)((gray&0x03)*0x55);
@@ -3652,6 +3721,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
break;
}
case 4:
{
gray = (png_uint_16)((gray&0x0f)*0x11);
@@ -3675,6 +3745,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
break;
}
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = row_width;
@@ -3696,6 +3767,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
*dp-- = *sp--;
}
}
else if (row_info->bit_depth == 16)
{
png_byte gray_high = (gray >> 8) & 0xff;
@@ -3718,6 +3790,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
*dp-- = *sp--;
}
}
row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
@@ -3812,13 +3885,13 @@ png_do_dither(png_row_infop row_info, png_bytep row,
g = *sp++;
b = *sp++;
/* this looks real messy, but the compiler will reduce
it down to a reasonable formula. For example, with
5 bits per color, we get:
p = (((r >> 3) & 0x1f) << 10) |
(((g >> 3) & 0x1f) << 5) |
((b >> 3) & 0x1f);
*/
/* This looks real messy, but the compiler will reduce
* it down to a reasonable formula. For example, with
* 5 bits per color, we get:
* p = (((r >> 3) & 0x1f) << 10) |
* (((g >> 3) & 0x1f) << 5) |
* ((b >> 3) & 0x1f);
*/
p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
((1 << PNG_DITHER_RED_BITS) - 1)) <<
(PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
@@ -3899,6 +3972,7 @@ png_build_gamma_table(png_structp png_ptr)
if (png_ptr->screen_gamma > .000001)
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
else
g = 1.0;
@@ -3933,6 +4007,7 @@ png_build_gamma_table(png_structp png_ptr)
if (png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma;
else
g = png_ptr->gamma; /* probably doing rgb_to_gray */
@@ -3955,8 +4030,10 @@ png_build_gamma_table(png_structp png_ptr)
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
{
sig_bit = (int)png_ptr->sig_bit.red;
if ((int)png_ptr->sig_bit.green > sig_bit)
sig_bit = png_ptr->sig_bit.green;
if ((int)png_ptr->sig_bit.blue > sig_bit)
sig_bit = png_ptr->sig_bit.blue;
}
@@ -3967,6 +4044,7 @@ png_build_gamma_table(png_structp png_ptr)
if (sig_bit > 0)
shift = 16 - sig_bit;
else
shift = 0;
@@ -3978,6 +4056,7 @@ png_build_gamma_table(png_structp png_ptr)
if (shift > 8)
shift = 8;
if (shift < 0)
shift = 0;
@@ -4040,6 +4119,7 @@ png_build_gamma_table(png_structp png_ptr)
(png_uint_32)(256 * png_sizeof(png_uint_16)));
ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++)
{
png_ptr->gamma_16_table[i][j] =
@@ -4082,6 +4162,7 @@ png_build_gamma_table(png_structp png_ptr)
if (png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma;
else
g = png_ptr->gamma; /* probably doing rgb_to_gray */
@@ -4102,6 +4183,7 @@ png_build_gamma_table(png_structp png_ptr)
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++)
{
png_ptr->gamma_16_from_1[i][j] =
@@ -4135,8 +4217,10 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
@@ -4153,8 +4237,10 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;