From bb9ed3f7b28b89ff41e200f70838331ca8914b85 Mon Sep 17 00:00:00 2001 From: Jason Hearne-McGuiness Date: Wed, 4 Sep 2013 20:22:10 +0100 Subject: [PATCH] Added sCAL support. --- plugins/thunar-apr/thunar-apr-png-read-data.c | 33 +++++++++++++++++++++++---- plugins/thunar-apr/thunar-apr-png-read-data.h | 8 +++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.c b/plugins/thunar-apr/thunar-apr-png-read-data.c index 3404dc2..5e3570b 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.c +++ b/plugins/thunar-apr/thunar-apr-png-read-data.c @@ -124,9 +124,9 @@ static const png_chunk_fmt_t png_chunk_details[number_of_png_chunks]={ {{"cHRM", "CIE chromaticities:"}, "white x=%f, white y=%f, red x=%f, red y=%f, green x=%f, green y=%f, blue x=%f, blue y=%f"}, {{"fRAc", ""}, ""}, ///< No specification in PNG spec. {{"gAMA", "Gamma factor:"}, "%f"}, - {{"gIFg", ""}, ""}, ///< TODO Need to complete representing this. - {{"gIFt", ""}, ""}, ///< vDeprecated, so not supported. - {{"gIFx", ""}, ""}, ///< TODO Need to complete representing this. + {{"gIFg", ""}, ""}, ///< No specification in libpng headers. + {{"gIFt", ""}, ""}, ///< Deprecated, so not supported. + {{"gIFx", ""}, ""}, ///< No specification in libpng headers. {{"hIST", "Histogram:"}, "%hu"}, {{"iCCP", "iCCP Embedded ICC profile:"}, ""}, ///< TODO Need to complete representing this. {{"iTXt", "Text:"}, ""}, ///< TODO Need to complete representing this. @@ -134,10 +134,10 @@ static const png_chunk_fmt_t png_chunk_details[number_of_png_chunks]={ {{"pCAL", ""}, ""}, ///< TODO Need to complete representing this. {{"pHYs", "Resolution:"}, "(%u, %u) %s"}, {{"sBIT", "Significant bits:"}, "RGB=(%hhu, %hhu, %hhu), gray=%hhu, alpha=%hhu"}, - {{"sCAL", ""}, ""}, ///< TODO Need to complete representing this. + {{"sCAL", "Scale:"}, "width=%f, height=%f %s"}, {{"sPLT", "Suggested palette:"}, "names=%s, depth=%hhu, no. entries=%i"}, {{"sRGB", "ICC Colour space:"}, "%s"}, - {{"sTER", ""}, ""}, ///< TODO Need to complete representing this. + {{"sTER", ""}, ""}, ///< No specification in libpng headers. {{"tEXt", "Text:"}, "%s"}, ///< Format specifier not used, as the various components are concatenated in the code. Just here to symbolically indicate that this has been implemented. {{"tRNS", "Transparency:"}, "alpha=%hhu, number=%i, index=%hhu, RGB=(%hu, %hu, %hu), gray=%hu"}, {{"zTXt", "Text:"}, ""} ///< TODO Need to complete representing this. @@ -419,6 +419,29 @@ read_png_data_from_file(FILE *fp) } } { + int unit=PNG_SCALE_UNKNOWN; + double width=0.0, height=0.0; + if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_sCAL) && png_get_sCAL(read_ptr, read_info_ptr, &unit, &width, &height)) + { + int error; + switch (unit) + { + case PNG_SCALE_METER: + error=asprintf(&png_data_read[png_chunk_names_sCAL].data, png_chunk_details[png_chunk_names_sCAL].fmt_str, width, height, "meters"); + break; + case PNG_SCALE_RADIAN: + error=asprintf(&png_data_read[png_chunk_names_sCAL].data, png_chunk_details[png_chunk_names_sCAL].fmt_str, width, height, "radians"); + break; + default: + error=asprintf(&png_data_read[png_chunk_names_sCAL].data, png_chunk_details[png_chunk_names_sCAL].fmt_str, width, height, "unknown"); + } + if (error<0) + { + png_data_read[png_chunk_names_sCAL].data=0; + } + } + } + { png_sPLT_tp entries=NULL; if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_sPLT) && png_get_sPLT(read_ptr, read_info_ptr, &entries)) { diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.h b/plugins/thunar-apr/thunar-apr-png-read-data.h index 9158b8d..e348ad0 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.h +++ b/plugins/thunar-apr/thunar-apr-png-read-data.h @@ -34,9 +34,9 @@ extern char const * const png_chunk_names[]; "cHRM", "fRAc", // No specification in PNG spec. "gAMA", - "gIFg", // Not yet implemented. + "gIFg", // No specification in libpng headers. "gIFt", // Deprecated, so not supported. - "gIFx", // Not yet implemented. + "gIFx", // No specification in libpng headers. "hIST", "iCCP", // Not yet implemented. "iTXt", // Not yet implemented. @@ -44,10 +44,10 @@ extern char const * const png_chunk_names[]; "pCAL", // Not yet implemented. "pHYs", "sBIT", - "sCAL", // Not yet implemented. + "sCAL", "sPLT", "sRGB", - "sTER", // Not yet implemented. + "sTER", // No specification in libpng headers. "tEXt", "tRNS", "zTXt" // Not yet implemented. -- 1.8.1.5