mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[libpng16] refactor: Deduplicate the interlace arrays png_pass_*
Move the definitions of interlace arrays to the top of their respective translation units, to reduce their repeated copying in various places of the codebase. TODO: As they still exist in three copies, in pngpread.c, in pngrutil.c, and in pngwutil.c, they should all be further moved to a common place. This is a cherry-pick of commit 620a2b73b22df66ed099e1faacac2d92f48252b7 from branch 'libpng18'.
This commit is contained in:
parent
76e5ec217f
commit
d9d70e6506
36
pngpread.c
36
pngpread.c
@ -31,6 +31,21 @@ if (png_ptr->push_length + 4 > png_ptr->buffer_size) \
|
|||||||
if (png_ptr->buffer_size < N) \
|
if (png_ptr->buffer_size < N) \
|
||||||
{ png_push_save_buffer(png_ptr); return; }
|
{ png_push_save_buffer(png_ptr); return; }
|
||||||
|
|
||||||
|
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||||
|
/* Arrays to facilitate interlacing - use pass (0 - 6) as index. */
|
||||||
|
|
||||||
|
/* Start of interlace block */
|
||||||
|
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||||
|
/* Offset to next interlace block */
|
||||||
|
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||||
|
/* Start of interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||||
|
/* Offset to next interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||||
|
|
||||||
|
/* TODO: Move these arrays to a common utility module to avoid duplication. */
|
||||||
|
#endif
|
||||||
|
|
||||||
void PNGAPI
|
void PNGAPI
|
||||||
png_process_data(png_structrp png_ptr, png_inforp info_ptr,
|
png_process_data(png_structrp png_ptr, png_inforp info_ptr,
|
||||||
png_bytep buffer, size_t buffer_size)
|
png_bytep buffer, size_t buffer_size)
|
||||||
@ -975,27 +990,6 @@ png_push_process_row(png_structrp png_ptr)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_read_push_finish_row(png_structrp png_ptr)
|
png_read_push_finish_row(png_structrp png_ptr)
|
||||||
{
|
{
|
||||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
/* Start of interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
|
||||||
|
|
||||||
/* Offset to next interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
|
||||||
|
|
||||||
/* Height of interlace block. This is not currently used - if you need
|
|
||||||
* it, uncomment it here and in png.h
|
|
||||||
static const png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
*/
|
|
||||||
#endif
|
|
||||||
|
|
||||||
png_ptr->row_number++;
|
png_ptr->row_number++;
|
||||||
if (png_ptr->row_number < png_ptr->num_rows)
|
if (png_ptr->row_number < png_ptr->num_rows)
|
||||||
return;
|
return;
|
||||||
|
47
pngrutil.c
47
pngrutil.c
@ -17,6 +17,21 @@
|
|||||||
|
|
||||||
#ifdef PNG_READ_SUPPORTED
|
#ifdef PNG_READ_SUPPORTED
|
||||||
|
|
||||||
|
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||||
|
/* Arrays to facilitate interlacing - use pass (0 - 6) as index. */
|
||||||
|
|
||||||
|
/* Start of interlace block */
|
||||||
|
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||||
|
/* Offset to next interlace block */
|
||||||
|
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||||
|
/* Start of interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||||
|
/* Offset to next interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||||
|
|
||||||
|
/* TODO: Move these arrays to a common utility module to avoid duplication. */
|
||||||
|
#endif
|
||||||
|
|
||||||
png_uint_32 PNGAPI
|
png_uint_32 PNGAPI
|
||||||
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
|
png_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)
|
||||||
{
|
{
|
||||||
@ -3683,10 +3698,6 @@ void /* PRIVATE */
|
|||||||
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||||
png_uint_32 transformations /* Because these may affect the byte layout */)
|
png_uint_32 transformations /* Because these may affect the byte layout */)
|
||||||
{
|
{
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
png_debug(1, "in png_do_read_interlace");
|
png_debug(1, "in png_do_read_interlace");
|
||||||
if (row != NULL && row_info != NULL)
|
if (row != NULL && row_info != NULL)
|
||||||
{
|
{
|
||||||
@ -4324,20 +4335,6 @@ png_read_finish_IDAT(png_structrp png_ptr)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_read_finish_row(png_structrp png_ptr)
|
png_read_finish_row(png_structrp png_ptr)
|
||||||
{
|
{
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
/* Start of interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
|
||||||
|
|
||||||
/* Offset to next interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
|
||||||
|
|
||||||
png_debug(1, "in png_read_finish_row");
|
png_debug(1, "in png_read_finish_row");
|
||||||
png_ptr->row_number++;
|
png_ptr->row_number++;
|
||||||
if (png_ptr->row_number < png_ptr->num_rows)
|
if (png_ptr->row_number < png_ptr->num_rows)
|
||||||
@ -4389,20 +4386,6 @@ png_read_finish_row(png_structrp png_ptr)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_read_start_row(png_structrp png_ptr)
|
png_read_start_row(png_structrp png_ptr)
|
||||||
{
|
{
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
/* Start of interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
|
||||||
|
|
||||||
/* Offset to next interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
|
||||||
|
|
||||||
unsigned int max_pixel_depth;
|
unsigned int max_pixel_depth;
|
||||||
size_t row_bytes;
|
size_t row_bytes;
|
||||||
|
|
||||||
|
58
pngwutil.c
58
pngwutil.c
@ -8,12 +8,30 @@
|
|||||||
* This code is released under the libpng license.
|
* This code is released under the libpng license.
|
||||||
* For conditions of distribution and use, see the disclaimer
|
* For conditions of distribution and use, see the disclaimer
|
||||||
* and license in png.h
|
* and license in png.h
|
||||||
|
*
|
||||||
|
* This file contains routines that are only called from within
|
||||||
|
* libpng itself during the course of writing an image.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pngpriv.h"
|
#include "pngpriv.h"
|
||||||
|
|
||||||
#ifdef PNG_WRITE_SUPPORTED
|
#ifdef PNG_WRITE_SUPPORTED
|
||||||
|
|
||||||
|
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||||
|
/* Arrays to facilitate interlacing - use pass (0 - 6) as index. */
|
||||||
|
|
||||||
|
/* Start of interlace block */
|
||||||
|
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||||
|
/* Offset to next interlace block */
|
||||||
|
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||||
|
/* Start of interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||||
|
/* Offset to next interlace block in the y direction */
|
||||||
|
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||||
|
|
||||||
|
/* TODO: Move these arrays to a common utility module to avoid duplication. */
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
|
#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
|
||||||
/* Place a 32-bit number into a buffer in PNG byte order. We work
|
/* Place a 32-bit number into a buffer in PNG byte order. We work
|
||||||
* with unsigned numbers for convenience, although one supported
|
* with unsigned numbers for convenience, although one supported
|
||||||
@ -1888,22 +1906,6 @@ png_write_tIME(png_structrp png_ptr, png_const_timep mod_time)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_write_start_row(png_structrp png_ptr)
|
png_write_start_row(png_structrp png_ptr)
|
||||||
{
|
{
|
||||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
/* Start of interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
|
||||||
|
|
||||||
/* Offset to next interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
png_alloc_size_t buf_size;
|
png_alloc_size_t buf_size;
|
||||||
int usr_pixel_depth;
|
int usr_pixel_depth;
|
||||||
|
|
||||||
@ -2003,22 +2005,6 @@ png_write_start_row(png_structrp png_ptr)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_write_finish_row(png_structrp png_ptr)
|
png_write_finish_row(png_structrp png_ptr)
|
||||||
{
|
{
|
||||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
/* Start of interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
|
||||||
|
|
||||||
/* Offset to next interlace block in the y direction */
|
|
||||||
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
png_debug(1, "in png_write_finish_row");
|
png_debug(1, "in png_write_finish_row");
|
||||||
|
|
||||||
/* Next row */
|
/* Next row */
|
||||||
@ -2094,14 +2080,6 @@ png_write_finish_row(png_structrp png_ptr)
|
|||||||
void /* PRIVATE */
|
void /* PRIVATE */
|
||||||
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||||
{
|
{
|
||||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
|
||||||
|
|
||||||
/* Start of interlace block */
|
|
||||||
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
|
||||||
|
|
||||||
/* Offset to next interlace block */
|
|
||||||
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
|
||||||
|
|
||||||
png_debug(1, "in png_do_write_interlace");
|
png_debug(1, "in png_do_write_interlace");
|
||||||
|
|
||||||
/* We don't have to do anything on the last pass (6) */
|
/* We don't have to do anything on the last pass (6) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user