[libpng17] Fixed more indentation to comply with our coding style.

This commit is contained in:
Glenn Randers-Pehrson
2016-07-15 14:43:19 -05:00
parent 9743d58bc0
commit 096dbf8335
17 changed files with 547 additions and 544 deletions

168
pngread.c
View File

@@ -28,10 +28,10 @@ png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
{
#ifndef PNG_USER_MEM_SUPPORTED
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
error_fn, warn_fn, NULL, NULL, NULL);
error_fn, warn_fn, NULL, NULL, NULL);
#else
return png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL);
warn_fn, NULL, NULL, NULL);
}
/* Alternate create PNG structure for reading, and allocate any memory
@@ -43,7 +43,7 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
{
png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
#endif /* USER_MEM */
if (png_ptr != NULL)
@@ -245,7 +245,7 @@ png_start_read_image(png_structrp png_ptr)
*/
else
png_app_error(png_ptr,
"png_start_read_image/png_read_update_info: duplicate call");
"png_start_read_image/png_read_update_info: duplicate call");
}
}
@@ -779,7 +779,7 @@ png_gt(size_t a, size_t b)
void PNGAPI
png_read_png(png_structrp png_ptr, png_inforp info_ptr, int transforms,
voidp params)
voidp params)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
@@ -1055,7 +1055,7 @@ png_image_read_init(png_imagep image)
if (info_ptr != NULL)
{
png_controlp control = png_voidcast(png_controlp,
png_malloc_warn(png_ptr, (sizeof *control)));
png_malloc_warn(png_ptr, (sizeof *control)));
if (control != NULL)
{
@@ -1242,12 +1242,12 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
else
return png_image_error(image,
"png_image_begin_read_from_stdio: invalid argument");
"png_image_begin_read_from_stdio: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1280,12 +1280,12 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name)
else
return png_image_error(image,
"png_image_begin_read_from_file: invalid argument");
"png_image_begin_read_from_file: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1334,7 +1334,7 @@ image_init_memory_io(png_voidp param)
int PNGAPI
png_image_begin_read_from_memory(png_imagep image, png_const_voidp memory,
png_size_t size)
png_size_t size)
{
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
@@ -1356,12 +1356,12 @@ png_image_begin_read_from_memory(png_imagep image, png_const_voidp memory,
else
return png_image_error(image,
"png_image_begin_read_from_memory: invalid argument");
"png_image_begin_read_from_memory: invalid argument");
}
else if (image != NULL)
return png_image_error(image,
"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION");
return 0;
}
@@ -1407,11 +1407,11 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
* IHDR, PLTE, tRNS, IDAT, and IEND chunks.
*/
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER,
NULL, -1);
NULL, -1);
/* But do not ignore image data handling chunks */
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,
chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);
}
}
@@ -1614,7 +1614,7 @@ decode_gamma(png_image_read_control *display, png_uint_32 value,
default:
png_impossiblepp(display->image->opaque->png_ptr,
"unexpected encoding");
"unexpected encoding");
break;
}
@@ -1623,9 +1623,9 @@ decode_gamma(png_image_read_control *display, png_uint_32 value,
static png_uint_32
png_colormap_compose(png_image_read_control *display,
png_uint_32 foreground, unsigned int foreground_significant_bits,
int foreground_encoding, png_uint_32 alpha,
png_uint_32 background, int encoding)
png_uint_32 foreground, unsigned int foreground_significant_bits,
int foreground_encoding, png_uint_32 alpha,
png_uint_32 background, int encoding)
{
/* The file value is composed on the background, the background has the given
* encoding and so does the result, the file is encoded with P_FILE and the
@@ -1662,21 +1662,21 @@ png_colormap_compose(png_image_read_control *display,
*/
static void
png_create_colormap_entry(png_image_read_control *display,
png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
png_uint_32 alpha, int encoding)
png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,
png_uint_32 alpha, int encoding)
{
png_imagep image = display->image;
# define png_ptr image->opaque->png_ptr /* for error messages */
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
(red != green || green != blue);
(red != green || green != blue);
int use_sBIT = encoding == P_FILE;
affirm(ip <= 255);
implies(encoding != P_LINEAR, red <= 255U && green <= 255U && blue <= 255U
&& display->sBIT[0] <= 8U && display->sBIT[1] <= 8U
&& display->sBIT[2] <= 8U && display->sBIT[3] <= 8U);
&& display->sBIT[0] <= 8U && display->sBIT[1] <= 8U
&& display->sBIT[2] <= 8U && display->sBIT[3] <= 8U);
/* This is a hack for the grayscale colormap below. */
if (encoding == P_FILE8)
@@ -1701,11 +1701,11 @@ png_create_colormap_entry(png_image_read_control *display,
if (convert_to_Y != 0 || output_encoding == P_LINEAR)
{
red = convert_to_linear(display, red,
use_sBIT ? display->sBIT[0] : 8U);
use_sBIT ? display->sBIT[0] : 8U);
green = convert_to_linear(display, green,
use_sBIT ? display->sBIT[1] : 8U);
use_sBIT ? display->sBIT[1] : 8U);
blue = convert_to_linear(display, blue,
use_sBIT ? display->sBIT[2] : 8U);
use_sBIT ? display->sBIT[2] : 8U);
alpha *= 257U;
if (use_sBIT)
alpha = update_for_sBIT(alpha, display->sBIT[3], 16U);
@@ -1717,11 +1717,11 @@ png_create_colormap_entry(png_image_read_control *display,
else
{
red = convert_to_sRGB(display, red,
use_sBIT ? display->sBIT[0] : 8U);
use_sBIT ? display->sBIT[0] : 8U);
green = convert_to_sRGB(display, green,
use_sBIT ? display->sBIT[1] : 8U);
use_sBIT ? display->sBIT[1] : 8U);
blue = convert_to_sRGB(display, blue,
use_sBIT ? display->sBIT[2] : 8U);
use_sBIT ? display->sBIT[2] : 8U);
if (use_sBIT)
alpha = update_for_sBIT(alpha, display->sBIT[3], 8U);
encoding = P_sRGB;
@@ -1830,7 +1830,7 @@ png_create_colormap_entry(png_image_read_control *display,
{
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
# define afirst 0
# endif
@@ -2007,7 +2007,7 @@ make_ga_colormap(png_image_read_control *display)
for (g=0; g<6; ++g)
png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,
P_sRGB);
P_sRGB);
}
return i;
@@ -2031,7 +2031,7 @@ make_rgb_colormap(png_image_read_control *display)
for (b=0; b<6; ++b)
png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,
P_sRGB);
P_sRGB);
}
}
@@ -2084,7 +2084,7 @@ png_image_read_colormap(png_voidp argument)
else if (display->background == NULL /* no way to remove it */)
png_error(png_ptr,
"a background color must be supplied to remove alpha/transparency");
"background color must be supplied to remove alpha/transparency");
/* Get a copy of the background color (this avoids repeating the checks
* below.) The encoding is 8-bit sRGB or 16-bit linear, depending on the
@@ -2184,7 +2184,7 @@ png_image_read_colormap(png_voidp argument)
*/
if (i != trans)
png_create_colormap_entry(display, i, val, val, val, 255,
P_FILE/*8-bit with file gamma*/);
P_FILE/*8-bit with file gamma*/);
/* Else this entry is transparent. The colors don't matter if
* there is an alpha channel (back_alpha == 0), but it does no
@@ -2199,10 +2199,10 @@ png_image_read_colormap(png_voidp argument)
#ifdef __COVERITY__
/* Coverity says back_r|g|b might be 16-bit values */
png_affirmpp(png_ptr, back_r < 256 && back_g < 256 &&
back_b < 256);
back_b < 256);
#endif
png_create_colormap_entry(display, i, back_r, back_g, back_b,
back_alpha, output_encoding);
back_alpha, output_encoding);
}
}
@@ -2268,7 +2268,7 @@ png_image_read_colormap(png_voidp argument)
* matches.
*/
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, P_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the
@@ -2276,15 +2276,15 @@ png_image_read_colormap(png_voidp argument)
*/
c.index = 0; /*unused*/
c.gray = c.red = c.green = c.blue =
png_check_u16(png_ptr, gray);
png_check_u16(png_ptr, gray);
/* NOTE: does this work without expanding tRNS to alpha?
* It should be the color->gray case below apparently
* doesn't.
*/
png_set_background_fixed(png_ptr, &c,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
output_processing = PNG_CMAP_NONE;
break;
@@ -2316,7 +2316,7 @@ png_image_read_colormap(png_voidp argument)
back_b < 256);
#endif
png_create_colormap_entry(display, 254, back_r, back_g, back_b,
back_alpha, output_encoding);
back_alpha, output_encoding);
}
else
@@ -2384,7 +2384,7 @@ png_image_read_colormap(png_voidp argument)
/* And make sure the corresponding palette entry matches. */
png_create_colormap_entry(display, gray, back_g, back_g,
back_g, 65535, P_LINEAR);
back_g, 65535, P_LINEAR);
}
/* The background passed to libpng, however, must be the sRGB
@@ -2394,8 +2394,8 @@ png_image_read_colormap(png_voidp argument)
c.gray = c.red = c.green = c.blue = png_check_u16(png_ptr, gray);
png_set_background_fixed(png_ptr, &c,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
output_processing = PNG_CMAP_NONE;
}
@@ -2415,7 +2415,7 @@ png_image_read_colormap(png_voidp argument)
{
png_uint_32 gray = (i * 256 + 115) / 231;
png_create_colormap_entry(display, i++, gray, gray, gray,
255, P_sRGB);
255, P_sRGB);
}
/* NOTE: this preserves the full precision of the application
@@ -2493,7 +2493,7 @@ png_image_read_colormap(png_voidp argument)
* png_set_tRNS_to_alpha before png_set_background_fixed.
*/
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,
-1);
-1);
data_encoding = P_sRGB;
/* The output will now be one or two 8-bit gray or gray+alpha
@@ -2601,8 +2601,8 @@ png_image_read_colormap(png_voidp argument)
*/
expand_tRNS = 1;
png_set_background_fixed(png_ptr, &c,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
}
output_processing = PNG_CMAP_NONE;
@@ -2636,7 +2636,7 @@ png_image_read_colormap(png_voidp argument)
/* Add a transparent entry. */
png_create_colormap_entry(display, cmap_entries, 255, 255,
255, 0, P_sRGB);
255, 0, P_sRGB);
/* This is stored as the background index for the processing
* algorithm.
@@ -2657,7 +2657,7 @@ png_image_read_colormap(png_voidp argument)
*/
for (b=0; b<256; b = (b << 1) | 0x7f)
png_create_colormap_entry(display, cmap_entries++,
r, g, b, 128, P_sRGB);
r, g, b, 128, P_sRGB);
}
}
@@ -2684,7 +2684,7 @@ png_image_read_colormap(png_voidp argument)
cmap_entries = make_rgb_colormap(display);
png_create_colormap_entry(display, cmap_entries, back_r,
back_g, back_b, 0/*unused*/, output_encoding);
back_g, back_b, 0/*unused*/, output_encoding);
if (output_encoding == P_LINEAR)
{
@@ -2706,9 +2706,9 @@ png_image_read_colormap(png_voidp argument)
* index.
*/
if (memcmp((png_const_bytep)display->colormap +
sample_size * cmap_entries,
(png_const_bytep)display->colormap +
sample_size * PNG_RGB_INDEX(r,g,b),
sample_size * cmap_entries,
(png_const_bytep)display->colormap +
sample_size * PNG_RGB_INDEX(r,g,b),
sample_size) != 0)
{
/* The background color must be added. */
@@ -2750,8 +2750,8 @@ png_image_read_colormap(png_voidp argument)
c.blue = png_check_u16(png_ptr, back_b);
png_set_background_fixed(png_ptr, &c,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
output_processing = PNG_CMAP_RGB;
}
@@ -2803,7 +2803,7 @@ png_image_read_colormap(png_voidp argument)
{
if (trans[i] == 0)
png_create_colormap_entry(display, i, back_r, back_g,
back_b, 0, output_encoding);
back_b, 0, output_encoding);
else
{
@@ -2928,7 +2928,7 @@ static int
png_image_read_and_map(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
argument);
argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
int passes;
@@ -3065,7 +3065,7 @@ png_image_read_and_map(png_voidp argument)
if (alpha >= 196)
*outrow = PNG_RGB_INDEX(inrow[0], inrow[1],
inrow[2]);
inrow[2]);
else if (alpha < 64)
*outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND;
@@ -3117,7 +3117,7 @@ static int
png_image_read_colormapped(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
argument);
argument);
png_imagep image = display->image;
png_controlp control = image->opaque;
png_structrp png_ptr = control->png_ptr;
@@ -3255,7 +3255,7 @@ static int
png_image_read_composite(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
argument);
argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
int passes;
@@ -3383,7 +3383,7 @@ static int
png_image_read_background(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
argument);
argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
@@ -3442,8 +3442,7 @@ png_image_read_background(png_voidp argument)
for (pass = 0; pass < passes; ++pass)
{
png_bytep row = png_voidcast(png_bytep,
display->first_row);
png_bytep row = png_voidcast(png_bytep, display->first_row);
unsigned int startx, stepx, stepy;
png_uint_32 y;
@@ -3471,7 +3470,7 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
display->local_row);
display->local_row);
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3517,7 +3516,7 @@ png_image_read_background(png_voidp argument)
for (; y<height; y += stepy)
{
png_bytep inrow = png_voidcast(png_bytep,
display->local_row);
display->local_row);
png_bytep outrow = first_row + y * step_row;
png_const_bytep end_row = outrow + width;
@@ -3565,7 +3564,7 @@ png_image_read_background(png_voidp argument)
*/
{
png_uint_16p first_row = png_voidcast(png_uint_16p,
display->first_row);
display->first_row);
/* The division by two is safe because the caller passed in a
* stride which was multiplied by 2 (below) to get row_bytes.
*/
@@ -3615,7 +3614,7 @@ png_image_read_background(png_voidp argument)
/* Read the row, which is packed: */
png_read_row(png_ptr, png_voidcast(png_bytep,
display->local_row), NULL);
display->local_row), NULL);
inrow = png_voidcast(png_const_uint_16p, display->local_row);
/* Now do the pre-multiplication on each pixel in this row.
@@ -3660,7 +3659,7 @@ static int
png_image_read_direct(png_voidp argument)
{
png_image_read_control *display = png_voidcast(png_image_read_control*,
argument);
argument);
png_imagep image = display->image;
png_structrp png_ptr = image->opaque->png_ptr;
png_inforp info_ptr = image->opaque->info_ptr;
@@ -3711,7 +3710,7 @@ png_image_read_direct(png_voidp argument)
do_local_background = 1/*maybe*/;
png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,
PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);
}
change &= PNG_BIC_MASK(PNG_FORMAT_FLAG_COLOR);
@@ -3830,8 +3829,8 @@ png_image_read_direct(png_voidp argument)
* pixels.
*/
png_set_background_fixed(png_ptr, &c,
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,
0/*gamma: not used*/);
}
else /* compose on row: implemented below. */
@@ -4073,7 +4072,7 @@ png_image_read_direct(png_voidp argument)
int PNGAPI
png_image_finish_read(png_imagep image, png_const_colorp background,
void *buffer, ptrdiff_t row_stride, void *colormap)
void *buffer, ptrdiff_t row_stride, void *colormap)
{
if (image != NULL && image->version == PNG_IMAGE_VERSION)
{
@@ -4138,15 +4137,16 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
* all the setup has already been done.
*/
if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0)
result = png_safe_execute(image,
png_image_read_colormap, &display) &&
png_safe_execute(image,
png_image_read_colormapped, &display);
result =
png_safe_execute(image,
png_image_read_colormap, &display) &&
png_safe_execute(image,
png_image_read_colormapped, &display);
else
result =
png_safe_execute(image,
png_image_read_direct, &display);
png_image_read_direct, &display);
png_image_free(image);
return result;
@@ -4154,27 +4154,27 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
else
return png_image_error(image,
"png_image_finish_read[color-map]: no color-map");
"png_image_finish_read[color-map]: no color-map");
}
else
return png_image_error(image,
"png_image_finish_read: image too large");
"png_image_finish_read: image too large");
}
else
return png_image_error(image,
"png_image_finish_read: invalid argument");
"png_image_finish_read: invalid argument");
}
else
return png_image_error(image,
"png_image_finish_read: row_stride too large");
"png_image_finish_read: row_stride too large");
}
else if (image != NULL)
return png_image_error(image,
"png_image_finish_read: damaged PNG_IMAGE_VERSION");
"png_image_finish_read: damaged PNG_IMAGE_VERSION");
return 0;
}