[libpng16] Added png_set_itxt() (work in progress)

This commit is contained in:
Glenn Randers-Pehrson 2012-03-16 13:53:25 -05:00
parent d9d7a7e8f0
commit 31d66245ea
6 changed files with 88 additions and 1 deletions

View File

@ -319,6 +319,7 @@ Version 1.6.0beta18 [March 16, 2012]
this is disabled in which case the simplified API can't be built.) this is disabled in which case the simplified API can't be built.)
Version 1.6.0beta19 [March 16, 2012] Version 1.6.0beta19 [March 16, 2012]
Added png_set_itxt() (work in progress)
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

@ -4070,6 +4070,7 @@ Version 1.6.0beta18 [March 16, 2012]
this is disabled in which case the simplified API can't be built.) this is disabled in which case the simplified API can't be built.)
Version 1.6.0beta19 [March 16, 2012] Version 1.6.0beta19 [March 16, 2012]
Added png_set_itxt() (work in progress)
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

@ -863,6 +863,13 @@ 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);
#if PNG_LIBPNG_VER >= 1.6.0
png_set_itxt(png_ptr, info_ptr, 0, 0, "Title", "Mona Lisa", NULL, NULL);
png_set_itxt(png_ptr, info_ptr, 0, 0, "Author", "Leonardo da Vinci", NULL,
NULL);
png_set_itxt(png_ptr, info_ptr, 3, 0, "Description", "<long text>", NULL,
NULL);
#else
/* Optionally write comments into the image */ /* Optionally write comments into the image */
{ {
png_text text_ptr[3]; png_text text_ptr[3];
@ -896,6 +903,7 @@ void write_png(char *file_name /* , ... other image information ... */)
png_set_text(write_ptr, write_info_ptr, text_ptr, 3); png_set_text(write_ptr, write_info_ptr, text_ptr, 3);
} }
#endif
/* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */ /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */

9
png.h
View File

@ -2263,6 +2263,13 @@ PNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr,
png_inforp info_ptr, png_const_textp text_ptr, int num_text)); png_inforp info_ptr, png_const_textp text_ptr, int num_text));
#endif #endif
#ifdef PNG_WRITE_TEXT_SUPPORTED
PNG_EXPORT(243, void, png_set_itxt, (png_const_structrp png_ptr,
png_inforp info_ptr, const int in_flag, const int in_method,
png_const_charp in_key, png_const_charp in_text, png_const_charp in_lang,
png_const_charp in_lang_key));
#endif
#ifdef PNG_tIME_SUPPORTED #ifdef PNG_tIME_SUPPORTED
PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr, PNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr,
png_inforp info_ptr, png_timep *mod_time)); png_inforp info_ptr, png_timep *mod_time));
@ -3081,7 +3088,7 @@ PNG_EXPORT(242, void, png_set_check_for_invalid_index,
* scripts/symbols.def as well. * scripts/symbols.def as well.
*/ */
#ifdef PNG_EXPORT_LAST_ORDINAL #ifdef PNG_EXPORT_LAST_ORDINAL
PNG_EXPORT_LAST_ORDINAL(242); PNG_EXPORT_LAST_ORDINAL(243);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1410,6 +1410,75 @@ png_set_text_compression_method(png_structrp png_ptr, int method)
#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */ #endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
/* end of API added to libpng-1.5.4 */ /* end of API added to libpng-1.5.4 */
#ifdef PNG_WRITE_TEXT_SUPPORTED
/* TO DO: synopsis in libpng.3
* revise example.c
* set up some macros to use instead of 0,1,2,3
* test, test, test
*/
/* API added to libpng-1.6.0 */
void PNGAPI
png_set_itxt(png_const_structrp png_ptr, png_inforp info_ptr,
const int in_flag, const int in_method, png_const_charp in_key,
png_const_charp in_text, png_const_charp in_lang,
png_const_charp in_lang_key)
{
if (png_ptr != NULL && info_ptr != NULL)
{
png_text text_ptr[1];
char *key = (png_charp) in_key;
char *text = (png_charp) in_text;
#ifdef PNG_WRITE_iTXt_SUPPORTED
char *lang = (png_charp) in_lang;
char *lang_key = (png_charp) in_lang_key;
#endif
text_ptr[0].key = key;
text_ptr[0].text = text;
#ifdef PNG_WRITE_iTXt_SUPPORTED
text_ptr[0].lang = lang;
text_ptr[0].lang_key = lang_key;
#endif
/*
TO DO: use macros for these.
-1: tEXt, none
0: zTXt, deflate
1: iTXt, none
2: iTXt, deflate
*/
if (in_method != 0)
png_benign_error(png_ptr,
"Only text compression method 0 is supported, using 0.");
if (in_flag == 0)
text_ptr[0].compression = -1;
else if (in_flag == 1)
text_ptr[0].compression = 0;
else if (in_flag == 2)
text_ptr[0].compression = 1;
else if (in_flag == 3)
text_ptr[0].compression = 2;
else
{
png_benign_error(png_ptr,
"Unrecognized text compression flag, using (compressed iTXt).");
text_ptr[0].compression = 2;
}
png_debug(1, "in png_set_itxt");
/* TO DO: fix compiler warning about discarding qualifier here */
png_set_text(png_ptr, info_ptr, text_ptr, 1);
}
}
#endif
void PNGAPI void PNGAPI
png_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn) png_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn)
{ {

View File

@ -248,3 +248,4 @@ EXPORTS
png_image_write_to_stdio @240 png_image_write_to_stdio @240
png_convert_to_rfc1123_buffer @241 png_convert_to_rfc1123_buffer @241
png_set_check_for_invalid_index @242 png_set_check_for_invalid_index @242
png_set_itxt @243