mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Squashed commit of the following:
commit fc4b42b1d56f95efeb1b9fe42dc35b7d98d246bb Merge: 74516c79eb1413Author: John Bowler <jbowler@acm.org> Date: Sun Nov 22 19:37:54 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 74516c7257f1a28a69985684c5673caa390c700a Author: John Bowler <jbowler@acm.org> Date: Sun Nov 22 19:32:43 2015 -0800 Make check full pass on gcc/g++ x86_64 Signed-off-by: John Bowler <jbowler@acm.org> commit e891e34737fc0bc9ee873a5d56b83c1e777b990c Author: John Bowler <jbowler@acm.org> Date: Sun Nov 22 12:01:37 2015 -0800 Checkpoint: write buffering changes This version fails in pngvalid --size because of an error handling very narrow images, otherwise a standard build passes make check. Signed-off-by: John Bowler <jbowler@acm.org> commit 457a046ebdab737eefb477126cf855e49df6de50 Author: John Bowler <jbowler@acm.org> Date: Sun Nov 22 06:39:36 2015 -0800 Fix previous bad merge commit b4f426c97267317637d43f41fe0b05d1659bc63d Merge: 07b9b90a3458a6Author: John Bowler <jbowler@acm.org> Date: Sun Nov 22 06:32:34 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 07b9b90dfd653b744dbc3710b096facf6b4605f6 Merge: ed433065592e0bAuthor: John Bowler <jbowler@acm.org> Date: Sat Nov 21 17:07:23 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit ed43306599f7039a90187862db82273fca3a4c3d Merge: 772aed7d3c0359Author: John Bowler <jbowler@acm.org> Date: Tue Nov 17 17:47:26 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 772aed72378df9c8fccc5a4594b095d02d410a9c Merge: 73ae431801608fAuthor: John Bowler <jbowler@acm.org> Date: Mon Nov 16 14:26:38 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 73ae4316cb6db7d7f6756583a1c213c35ca4e3f4 Merge: 687e6e3c09b3abAuthor: John Bowler <jbowler@acm.org> Date: Sun Nov 15 09:31:30 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 687e6e393e9d0220c2a12ec474aa01b83c5e9f25 Merge: fedd6dae916d9bAuthor: John Bowler <jbowler@acm.org> Date: Thu Nov 5 08:45:14 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit fedd6da8798a14b2e002b0bc1379f5a09a03598a Merge: 2e2fc5fea41fd2Author: John Bowler <jbowler@acm.org> Date: Tue Nov 3 21:05:01 2015 -0800 Merge branch 'libpng17' into libpng17-filter-enhancements commit 2e2fc5f6d7678b710c52b7ea081ac4add677d8d5 Merge: 990d5f85b05197Author: John Bowler <jbowler@acm.org> Date: Mon Oct 12 08:28:30 2015 -0700 Merge branch 'libpng17' into libpng17-filter-enhancements commit 990d5f88688635dc0888657b689e30ffe7e7a7b3 Author: John Bowler <jbowler@acm.org> Date: Sun Oct 4 17:04:53 2015 -0700 Read row buffer changes The read code now allocates one row buffer of the size of the input PNG row and, only if required, one buffer of the size of the output. The output buffer is required for the progressive reader (always) and for the sequential reader if libpng is de-interlacing an image (because the output row is used multiple times if png_read_row is called with a display row parameter.) This should reduce memory utilization by libpng significantly, but it has no detectable effect on overall performance figures of the test programs, these are probably dominated by memory allocations for the whole image within the test programs. Signed-off-by: John Bowler <jbowler@acm.org> commit 527bf989bf0e30440f9e07a5544a6ebb1d6fd039 Merge: 50ebbc29099254Author: John Bowler <jbowler@acm.org> Date: Sat Oct 3 13:39:17 2015 -0700 Merge branch 'libpng17' into libpng17-filter-enhancements commit 50ebbc2c9a24cf1a6b428db53d55fbd5af4d6be6 Merge: 21a7f402cd6d56Author: John Bowler <jbowler@acm.org> Date: Sat Oct 3 11:16:32 2015 -0700 Merge branch 'libpng17' into libpng17-filter-enhancements commit 21a7f401ab40c79ead9e35882a8066e2cf1d6902 Merge: b512e1c15a143eAuthor: John Bowler <jbowler@acm.org> Date: Wed Sep 30 19:01:23 2015 -0700 Merge branch 'libpng17' into libpng17-filter-enhancements commit b512e1c2c5bfe6df8b6dca32f862d325ec22115e Author: John Bowler <jbowler@acm.org> Date: Wed Sep 30 17:33:34 2015 -0700 Transform rewrite: perform transforms in small chunks The intent of this change is to reduce the memory footprint during transform sequences by performing transforms in fixed (small) sized blocks of pixels. The change is incomplete; the filter code still works row-by-row, so the whole tranform also works row-by-row, the intent is to fix this so that everything works in small(ish) chunks. At present the change has no discernable effect on pngvalid --speed or pngstest with (e.g.) rgb-8-1.8.png; user time and (minor) page faults are the same in old and new versions. The same applies to real-world 15MP PNG images; even on these the presence of the filter code causes a cyclical progress through memory which will interfere with any caching otherwise possible (useful word, 'otherwise'.) Signed-off-by: John Bowler <jbowler@acm.org> commit 781cb3699b92beb0e6bc5e03cef8fba820267082 Author: John Bowler <jbowler@acm.org> Date: Wed Sep 30 17:12:53 2015 -0700 Fix NO_WRITE_INTERLACE in pngvalid.c The support for writing interlaced images directly from libpng 1.7 was unintentionally disabled (INTERLACE_LAST was defined incorrectly, excluding the interlaced images). This obscured the fact that the transform and error test case generators lacked the support for writing interlaced images from libpng. Signed-off-by: John Bowler <jbowler@acm.org> commit 406ee2fd7946a384f1d7713712dc646080c5c52c Author: John Bowler <jbowler@acm.org> Date: Wed Sep 30 17:11:40 2015 -0700 Add pngvalid --transform --interlace test This increases code coverage by generating test cases with smaller length rows as a result of the interlacing. Without this packswap handling was incompletely tested. Signed-off-by: John Bowler <jbowler@acm.org> Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
106
png.c
106
png.c
@@ -237,6 +237,19 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
jmp_buf create_jmp_buf;
|
||||
# endif
|
||||
|
||||
/* This is a compile-type only test to ensure that the build satisifies the
|
||||
* contraints for the row buffer stack allocations. A 'duplicate case
|
||||
* statements' style of error means that one of the tests below failed:
|
||||
*/
|
||||
switch (0)
|
||||
{
|
||||
case 0:
|
||||
case PNG_ROW_BUFFER_SIZE >= PNG_MIN_ROW_BUFFER_SIZE: /*1*/
|
||||
case 2*(PNG_ROW_BUFFER_SIZE <= PNG_MAX_ROW_BUFFER_SIZE): /*2*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* This temporary stack-allocated structure is used to provide a place to
|
||||
* build enough context to allow the user provided memory allocator (if any)
|
||||
* to be called.
|
||||
@@ -2362,6 +2375,99 @@ png_calc_rowbytes(png_const_structrp png_ptr, unsigned int pixel_depth,
|
||||
return rowbytes;
|
||||
}
|
||||
|
||||
unsigned int /*PRIVATE*/
|
||||
png_max_pixel_block(png_const_structrp png_ptr)
|
||||
{
|
||||
/* Need the *smallest* pixel size that must occur in alignment units. On
|
||||
* read this is the PNG pixel depth because the read transforms cannot reduce
|
||||
* the pixel size below the input size or 8-bits, whichever is smaller.
|
||||
*
|
||||
* On write the 'pack' transform can pack 8-bit pixels back to a lower bit
|
||||
* depth, but the lowest bit depth is still given by the PNG pixel size.
|
||||
*/
|
||||
const unsigned int pixel_depth = PNG_PIXEL_DEPTH(*png_ptr);
|
||||
const unsigned int pixel_block = /* count of pixels in a block */
|
||||
pixel_depth < 8U ?
|
||||
PNG_ROW_BUFFER_BYTE_ALIGN * (8U/pixel_depth) :
|
||||
PNG_ROW_BUFFER_BYTE_ALIGN; /* pixels may be any whole byte size */
|
||||
/* The maximum block size in bits is MAX_PIXEL_DEPTH*pixel_block so work out
|
||||
* the minimum number of pixel blocks that can fit in PNG_ROW_BUFFER_SIZE
|
||||
* bytes and use this to calculate the maximum number of pixels:
|
||||
*/
|
||||
return pixel_block *
|
||||
((8U*PNG_ROW_BUFFER_SIZE) / (png_ptr->row_max_pixel_depth*pixel_block));
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_copy_row(png_const_structrp png_ptr, png_bytep dp, png_const_bytep sp,
|
||||
png_uint_32 x/*in INPUT*/, png_uint_32 width/*of INPUT*/,
|
||||
unsigned int pixel_depth, int clear/*clear the final byte*/)
|
||||
/* Copy the row in row_buffer; this is the non-interlaced copy used in both
|
||||
* the read and write code.
|
||||
*/
|
||||
{
|
||||
png_alloc_size_t cb;
|
||||
unsigned int remaining; /* remaining bits in a partial byte */
|
||||
|
||||
/* Copy 'cb' pixels, but take care with the last byte because it may
|
||||
* be partially written. 'x' must correspond to the start of a byte, check
|
||||
* that too:
|
||||
*/
|
||||
switch (pixel_depth)
|
||||
{
|
||||
case 1U: remaining = width & 7U;
|
||||
debug((x & 7U) == 0U);
|
||||
cb = width >> 3;
|
||||
dp += x >> 3;
|
||||
break;
|
||||
case 2U: remaining = (width << 1) & 6U;
|
||||
debug((x & 3U) == 0U);
|
||||
cb = width >> 2;
|
||||
dp += x >> 2;
|
||||
break;
|
||||
case 4U: remaining = (width << 2) & 4U;
|
||||
debug((x & 1U) == 0U);
|
||||
cb = width >> 1;
|
||||
dp += x >> 1;
|
||||
break;
|
||||
case 8U: remaining = 0U;
|
||||
cb = width;
|
||||
dp += x;
|
||||
break;
|
||||
default: remaining = 0U;
|
||||
cb = png_calc_rowbytes(png_ptr, pixel_depth, width);
|
||||
dp += png_calc_rowbytes(png_ptr, pixel_depth, x);
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(dp, sp, cb);
|
||||
|
||||
if (remaining > 0U)
|
||||
{
|
||||
/* 'remaining' is the number of bits still to be copied. Format may be
|
||||
* little endian; bits to copy in the bottom of 's'. Make 'remaining'
|
||||
* into a mask of the bits to *preserve* in dp.
|
||||
*/
|
||||
if ((png_ptr->row_format & PNG_FORMAT_FLAG_SWAPPED) == 0U)
|
||||
remaining = 0xffU >> remaining;
|
||||
|
||||
else
|
||||
remaining = 0xffU << remaining;
|
||||
|
||||
/* remaining is now the bits to *keep* from the destination byte, if
|
||||
* 'clear' is true the source bytes aren't copied - this is for security
|
||||
* reasons to avoid copying undefined bits at the end of a row. If
|
||||
* 'clear' is set the destination bits are not preserved, they are just
|
||||
* set to 0.
|
||||
*/
|
||||
if (clear)
|
||||
dp[cb] = PNG_BYTE(sp[cb] & ~remaining);
|
||||
|
||||
else
|
||||
dp[cb] = PNG_BYTE((sp[cb] & ~remaining) | (dp[cb] & remaining));
|
||||
}
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_check_IHDR(png_const_structrp png_ptr,
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
|
||||
Reference in New Issue
Block a user