From 155047ca9ef2a5b05377cf35048216d1a6b3773a Mon Sep 17 00:00:00 2001 From: Jason Hearne-McGuiness Date: Wed, 4 Sep 2013 15:38:12 +0100 Subject: [PATCH] Add support for more chunks. --- plugins/thunar-apr/thunar-apr-png-read-data.c | 66 +++++++++++++++++++++++---- plugins/thunar-apr/thunar-apr-png-read-data.h | 10 ++-- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.c b/plugins/thunar-apr/thunar-apr-png-read-data.c index 73e55d5..3404dc2 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.c +++ b/plugins/thunar-apr/thunar-apr-png-read-data.c @@ -121,26 +121,26 @@ static const png_chunk_fmt_t png_chunk_details[number_of_png_chunks]={ {{"tIME", "Modification time:"}, "%hu/%hhu/%hhu %02hhu:%02hhu:%02hhu"}, ///< In ISO format, because Linux is international. {{"PLTE", "Palette entries:"}, "%i, RGB=(%hhu, %hhu, %hhu)"}, {{"bKGD", "Palette index:"}, "%hhu, RGB=(%hu, %hu, %hu), gray=%hu"}, - {{"cHRM", ""}, ""}, ///< TODO Need to complete representing this. + {{"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", ""}, ""}, ///< TODO Need to complete representing this. + {{"gIFt", ""}, ""}, ///< vDeprecated, so not supported. {{"gIFx", ""}, ""}, ///< TODO Need to complete representing this. {{"hIST", "Histogram:"}, "%hu"}, - {{"iCCP", ""}, ""}, ///< TODO Need to complete representing this. - {{"iTXt", ""}, ""}, ///< TODO Need to complete representing this. + {{"iCCP", "iCCP Embedded ICC profile:"}, ""}, ///< TODO Need to complete representing this. + {{"iTXt", "Text:"}, ""}, ///< TODO Need to complete representing this. {{"oFFs", "Offset:"}, "(%i, %i) %s"}, {{"pCAL", ""}, ""}, ///< TODO Need to complete representing this. {{"pHYs", "Resolution:"}, "(%u, %u) %s"}, - {{"sBIT", ""}, ""}, ///< TODO Need to complete representing this. + {{"sBIT", "Significant bits:"}, "RGB=(%hhu, %hhu, %hhu), gray=%hhu, alpha=%hhu"}, {{"sCAL", ""}, ""}, ///< TODO Need to complete representing this. - {{"sPLT", ""}, ""}, ///< TODO Need to complete representing this. - {{"sRGB", "Intent:"}, "%s"}, + {{"sPLT", "Suggested palette:"}, "names=%s, depth=%hhu, no. entries=%i"}, + {{"sRGB", "ICC Colour space:"}, "%s"}, {{"sTER", ""}, ""}, ///< TODO Need to complete representing this. {{"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", ""}, ""}, ///< TODO Need to complete representing this. - {{"zTXt", ""}, ""} ///< TODO Need to complete representing this. + {{"tRNS", "Transparency:"}, "alpha=%hhu, number=%i, index=%hhu, RGB=(%hu, %hu, %hu), gray=%hu"}, + {{"zTXt", "Text:"}, ""} ///< TODO Need to complete representing this. }; // Mr.compiler you are a liar: see this is constant. @@ -307,6 +307,19 @@ read_png_data_from_file(FILE *fp) } } + if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_cHRM)) + { + double white_x=0.0, white_y=0.0, red_x=0.0, red_y=0.0, green_x=0.0, green_y=0.0, blue_x=0.0, blue_y=0.0; + if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y)) + { + const int error=asprintf(&png_data_read[png_chunk_names_cHRM].data, png_chunk_details[png_chunk_names_cHRM].fmt_str, white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); + if (error<0) + { + png_data_read[png_chunk_names_cHRM].data=0; + } + } + } + { int intent=0; if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_sRGB) && png_get_sRGB(read_ptr, read_info_ptr, &intent)) @@ -395,6 +408,28 @@ read_png_data_from_file(FILE *fp) } } { + png_color_8p sig_bit=NULL; + if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_sBIT) && png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) + { + const int error=asprintf(&png_data_read[png_chunk_names_sBIT].data, png_chunk_details[png_chunk_names_sBIT].fmt_str, sig_bit->red, sig_bit->green, sig_bit->blue, sig_bit->gray, sig_bit->alpha); + if (error<0) + { + png_data_read[png_chunk_names_sBIT].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)) + { + const int error=asprintf(&png_data_read[png_chunk_names_sPLT].data, png_chunk_details[png_chunk_names_sPLT].fmt_str, entries->name, entries->depth, entries->nentries); + if (error<0) + { + png_data_read[png_chunk_names_sPLT].data=0; + } + } + } + { png_int_32 offset_x=0, offset_y=0; int unit_type=PNG_OFFSET_LAST; if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_oFFs) && png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y, &unit_type)) @@ -442,6 +477,19 @@ read_png_data_from_file(FILE *fp) } } } + { + png_bytep trans_alpha=NULL; + int num_trans=0; + png_color_16p trans_color=NULL; + if (png_get_valid(read_ptr, read_info_ptr, PNG_INFO_tRNS) && png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans, &trans_color)) + { + const int error=asprintf(&png_data_read[png_chunk_names_tRNS].data, png_chunk_details[png_chunk_names_tRNS].fmt_str, *trans_alpha, num_trans, trans_color->index, trans_color->red, trans_color->green, trans_color->blue, trans_color->gray); + if (error<0) + { + png_data_read[png_chunk_names_tRNS].data=0; + } + } + } // Don't read rest of file, in case there are corruptions in it, ignore the advice on the libpng website that it is required. // Clean up after the read, and free any memory allocated - REQUIRED. png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL); diff --git a/plugins/thunar-apr/thunar-apr-png-read-data.h b/plugins/thunar-apr/thunar-apr-png-read-data.h index 81a636f..9158b8d 100644 --- a/plugins/thunar-apr/thunar-apr-png-read-data.h +++ b/plugins/thunar-apr/thunar-apr-png-read-data.h @@ -31,11 +31,11 @@ extern char const * const png_chunk_names[]; "tIME", "PLTE", "bKGD", - "cHRM", // Not yet implemented. + "cHRM", "fRAc", // No specification in PNG spec. "gAMA", "gIFg", // Not yet implemented. - "gIFt", // Not yet implemented. + "gIFt", // Deprecated, so not supported. "gIFx", // Not yet implemented. "hIST", "iCCP", // Not yet implemented. @@ -43,13 +43,13 @@ extern char const * const png_chunk_names[]; "oFFs", "pCAL", // Not yet implemented. "pHYs", - "sBIT", // Not yet implemented. + "sBIT", "sCAL", // Not yet implemented. - "sPLT", // Not yet implemented. + "sPLT", "sRGB", "sTER", // Not yet implemented. "tEXt", - "tRNS", // Not yet implemented. + "tRNS", "zTXt" // Not yet implemented. };*/ -- 1.8.1.5