[libpng15] Fixed CMF optimization of non-IDAT compressed chunks,

which was added at libpng-1.5.4.  It sometimes produced too small of a window.
This commit is contained in:
John Bowler
2012-03-09 21:16:51 -06:00
committed by Glenn Randers-Pehrson
parent 0b8b358b98
commit c4c21f1c87
3 changed files with 14 additions and 19 deletions

View File

@@ -569,14 +569,15 @@ png_text_compress(png_structp png_ptr,
/* Ship the compressed text out via chunk writes */
static void /* PRIVATE */
png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
png_write_compressed_data_out(png_structp png_ptr, compression_state *comp,
png_size_t data_len)
{
int i;
/* Handle the no-compression case */
if (comp->input)
{
png_write_chunk_data(png_ptr, comp->input, comp->input_len);
png_write_chunk_data(png_ptr, comp->input, data_len);
return;
}
@@ -585,7 +586,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* The zbuf_size test is because the code below doesn't work if zbuf_size is
* '1'; simply skip it to avoid memory overwrite.
*/
if (comp->input_len >= 2 && comp->input_len < 16384 && png_ptr->zbuf_size > 1)
if (data_len >= 2 && comp->input_len < 16384 && png_ptr->zbuf_size > 1)
{
unsigned int z_cmf; /* zlib compression method and flags */
@@ -619,7 +620,6 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
if (comp->num_output_ptr)
{
#if 0 /* The following sometimes produces incorrect zlib datastreams */
if (comp->output_ptr[0][0] != z_cmf)
{
int tmp;
@@ -629,7 +629,6 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
comp->output_ptr[0][1] = (png_byte)tmp;
}
#endif /* 0 */
}
else
{
@@ -1166,8 +1165,7 @@ png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type,
if (profile_len)
{
comp.input_len = profile_len;
png_write_compressed_data_out(png_ptr, &comp);
png_write_compressed_data_out(png_ptr, &comp, profile_len);
}
png_write_chunk_end(png_ptr);
@@ -1737,8 +1735,7 @@ png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text,
png_write_chunk_data(png_ptr, &buf, (png_size_t)1);
/* Write the compressed data */
comp.input_len = text_len;
png_write_compressed_data_out(png_ptr, &comp);
png_write_compressed_data_out(png_ptr, &comp, text_len);
/* Close the chunk */
png_write_chunk_end(png_ptr);
@@ -1829,7 +1826,7 @@ png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key,
png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf),
(png_size_t)(lang_key_len + 1));
png_write_compressed_data_out(png_ptr, &comp);
png_write_compressed_data_out(png_ptr, &comp, text_len);
png_write_chunk_end(png_ptr);