[libpng16] Revised example.c to put text strings in a temporary character array

instead of directly assigning string constants to png_textp members.
This avoids compiler warnings when -Wwrite-strings is enabled.
This commit is contained in:
Glenn Randers-Pehrson 2012-03-15 19:52:03 -05:00
parent 845ee6af72
commit f2715a558a
4 changed files with 64 additions and 23 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.6.0beta18 - March 11, 2012 Libpng 1.6.0beta18 - March 15, 2012
This is not intended to be a public release. It will be replaced This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version. within a few weeks by a public version or by another test version.
@ -298,11 +298,14 @@ Version 1.6.0beta17 [March 10, 2012]
chunks could end up with a too-small windowBits value in the deflate chunks could end up with a too-small windowBits value in the deflate
header. header.
Version 1.6.0beta18 [March 11, 2012] Version 1.6.0beta18 [March 15, 2012]
Issue a png_benign_error() instead of png_warning() about bad palette index. Issue a png_benign_error() instead of png_warning() about bad palette index.
In pngtest, treat benign errors as errors if "-strict" is present. In pngtest, treat benign errors as errors if "-strict" is present.
Fixed an off-by-one error in the palette index checking function. Fixed an off-by-one error in the palette index checking function.
Fixed a compiler warning under Cygwin (Windows-7, 32-bit system) Fixed a compiler warning under Cygwin (Windows-7, 32-bit system)
Revised example.c to put text strings in a temporary character array
instead of directly assigning string constants to png_textp members.
This avoids compiler warnings when -Wwrite-strings is enabled.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -4049,11 +4049,14 @@ Version 1.6.0beta17 [March 10, 2012]
chunks could end up with a too-small windowBits value in the deflate chunks could end up with a too-small windowBits value in the deflate
header. header.
Version 1.6.0beta18 [March 11, 2012] Version 1.6.0beta18 [March 15, 2012]
Issue a png_benign_error() instead of png_warning() about bad palette index. Issue a png_benign_error() instead of png_warning() about bad palette index.
In pngtest, treat benign errors as errors if "-strict" is present. In pngtest, treat benign errors as errors if "-strict" is present.
Fixed an off-by-one error in the palette index checking function. Fixed an off-by-one error in the palette index checking function.
Fixed a compiler warning under Cygwin (Windows-7, 32-bit system) Fixed a compiler warning under Cygwin (Windows-7, 32-bit system)
Revised example.c to put text strings in a temporary character array
instead of directly assigning string constants to png_textp members.
This avoids compiler warnings when -Wwrite-strings is enabled.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -864,25 +864,38 @@ void write_png(char *file_name /* , ... other image information ... */)
png_set_gAMA(png_ptr, info_ptr, gamma); png_set_gAMA(png_ptr, info_ptr, gamma);
/* Optionally write comments into the image */ /* Optionally write comments into the image */
text_ptr[0].key = "Title"; {
text_ptr[0].text = "Mona Lisa"; png_text text_ptr[3];
text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[0].itxt_length = 0; char key0[]="Title";
text_ptr[0].lang = NULL; char text0[]="Mona Lisa";
text_ptr[0].lang_key = NULL; text_ptr[0].key = key0;
text_ptr[1].key = "Author"; text_ptr[0].text = text0;
text_ptr[1].text = "Leonardo DaVinci"; text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE; text_ptr[0].itxt_length = 0;
text_ptr[1].itxt_length = 0; text_ptr[0].lang = NULL;
text_ptr[1].lang = NULL; text_ptr[0].lang_key = NULL;
text_ptr[1].lang_key = NULL;
text_ptr[2].key = "Description"; char key1[]="Author";
text_ptr[2].text = "<long text>"; char text1[]="Leonardo DaVinci";
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt; text_ptr[1].key = key1;
text_ptr[2].itxt_length = 0; text_ptr[1].text = text1;
text_ptr[2].lang = NULL; text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr[2].lang_key = NULL; text_ptr[1].itxt_length = 0;
png_set_text(png_ptr, info_ptr, text_ptr, 3); text_ptr[1].lang = NULL;
text_ptr[1].lang_key = NULL;
char key2[]="Description";
char text2[]="<long text>";
text_ptr[2].key = key2;
text_ptr[2].text = text2;
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr[2].itxt_length = 0;
text_ptr[2].lang = NULL;
text_ptr[2].lang_key = NULL;
png_set_text(write_ptr, write_info_ptr, text_ptr, 3);
}
/* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */

View File

@ -1023,7 +1023,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
if (verbose) if (verbose)
printf("\n Text compression=%d\n", text_ptr->compression); {
int i;
printf("\n");
for (i=0; i<num_text; i++)
{
printf(" Text compression[%d]=%d\n",
i, text_ptr[i].compression);
}
}
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
} }
@ -1218,6 +1227,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
{ {
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text); pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
if (verbose)
{
int i;
printf("\n");
for (i=0; i<num_text; i++)
{
printf(" Text compression[%d]=%d\n",
i, text_ptr[i].compression);
}
}
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
} }
} }