From a11cd84160b20c25b8916e8229bec8523bbde31c Mon Sep 17 00:00:00 2001 From: Glenn Randers-Pehrson Date: Sun, 5 Oct 2014 13:45:38 -0500 Subject: [PATCH] [libpng16] Only mark text chunks as written after successfully writing them. --- ANNOUNCE | 4 ++++ CHANGES | 4 ++++ example.c | 2 +- pngread.c | 2 ++ pngwrite.c | 13 ++++++++----- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index 5350aa20d..e66f1bd45 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -61,8 +61,12 @@ Version 1.6.14beta06 [October 5, 2014] Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL. Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT" to pnglibconf.dfa. + Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa, + to make it possible to configure a libpng that supports iCCP but not TEXT. Version 1.6.14beta07 [October 5, 2014] + Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa + Only mark text chunks as written after successfully writing them. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index d8cda8bcc..329da13bb 100644 --- a/CHANGES +++ b/CHANGES @@ -5014,8 +5014,12 @@ Version 1.6.14beta06 [October 5, 2014] Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL. Added "chunk iTXt enables TEXT" and "chunk zTXt enables TEXT" to pnglibconf.dfa. + Removed "option READ_COMPRESSED_TEXT enables READ_TEXT" from pnglibconf.dfa, + to make it possible to configure a libpng that supports iCCP but not TEXT. Version 1.6.14beta07 [October 5, 2014] + Removed "option WRITE_COMPRESSED_TEXT enables WRITE_TEXT" from pnglibconf.dfa + Only mark text chunks as written after successfully writing them. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/example.c b/example.c index ad5fc70ca..9075e5726 100644 --- a/example.c +++ b/example.c @@ -932,7 +932,7 @@ void write_png(char *file_name /* , ... other image information ... */) */ /* Once we write out the header, the compression type on the text - * chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or + * chunk gets changed to PNG_TEXT_COMPRESSION_NONE_WR or * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again * at the end. */ diff --git a/pngread.c b/pngread.c index 845ff7b15..53b9c3b9b 100644 --- a/pngread.c +++ b/pngread.c @@ -396,6 +396,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row) row_info.pixel_depth = png_ptr->pixel_depth; row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); +#ifdef PNG_WARNINGS_SUPPORTED if (png_ptr->row_number == 0 && png_ptr->pass == 0) { /* Check for transforms that have been set but were defined out */ @@ -435,6 +436,7 @@ png_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row) png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); #endif } +#endif /* PNG_WARNINGS_SUPPORTED */ #ifdef PNG_READ_INTERLACING_SUPPORTED /* If interlaced and we do not need a new row, combine row and return. diff --git a/pngwrite.c b/pngwrite.c index ee78afcde..b0948b3b2 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -292,11 +292,14 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) info_ptr->text[i].lang, info_ptr->text[i].lang_key, info_ptr->text[i].text); + /* Mark this chunk as written */ + if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; + else + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else - png_warning(png_ptr, "Unable to write international text"); + png_warning(png_ptr, "Unable to write international text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; } /* If we want a compressed text chunk */ @@ -306,11 +309,11 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) /* Write compressed chunk */ png_write_zTXt(png_ptr, info_ptr->text[i].key, info_ptr->text[i].text, info_ptr->text[i].compression); + /* Mark this chunk as written */ + info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; #else png_warning(png_ptr, "Unable to write compressed text"); #endif - /* Mark this chunk as written */ - info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; } else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)