diff options
author | Mavridis Philippe <[email protected]> | 2023-05-10 19:19:45 +0300 |
---|---|---|
committer | Mavridis Philippe <[email protected]> | 2023-05-10 19:19:45 +0300 |
commit | 5d5725effa1a9e1567b9226f49338e8fe00a3107 (patch) | |
tree | c01cdcfc75c7266a6458541fbde28b8612e09b97 | |
parent | 273530af4f44c3c9170cd92ec3f8e9e1b7c5507c (diff) | |
download | koffice-5d5725effa1a9e1567b9226f49338e8fe00a3107.tar.gz koffice-5d5725effa1a9e1567b9226f49338e8fe00a3107.zip |
Chalk: Fix loading of PNG files with iCCP
This commit makes some fixes to the way that iCCP profile data is read and
loaded, and adds an additional check to ensure that the PNG file does have
a profile.
It also introduces a shorter libpng version check of the form:
`#if PNG_LIBPNG_VER < 10500`
This commit fixes issue #20.
Signed-off-by: Mavridis Philippe <[email protected]>
-rw-r--r-- | filters/chalk/png/kis_png_converter.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/filters/chalk/png/kis_png_converter.cpp b/filters/chalk/png/kis_png_converter.cpp index 3956b640..511008b1 100644 --- a/filters/chalk/png/kis_png_converter.cpp +++ b/filters/chalk/png/kis_png_converter.cpp @@ -221,38 +221,38 @@ KisImageBuilder_Result KisPNGConverter::decode(const KURL& uri) return KisImageBuilder_RESULT_UNSUPPORTED_COLORSPACE; } bool hasalpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA || color_type == PNG_COLOR_TYPE_GRAY_ALPHA); - - // Read image profile - png_charp profile_name, profile_data; -#if PNG_LIBPNG_VER_MAJOR > 1 || ( PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5 ) - unsigned char* uprofile_data = reinterpret_cast<unsigned char*>(profile_data); -#endif - int compression_type; - png_uint_32 proflen; - int number_of_passes = 1; + int number_of_passes = 1; if (interlace_type == PNG_INTERLACE_ADAM7) number_of_passes = png_set_interlace_handling(png_ptr); + // Read image profile KisProfile* profile = 0; -#if PNG_LIBPNG_VER_MAJOR > 1 || ( PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5 ) - if(png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &uprofile_data, &proflen)) + if (png_get_valid(png_ptr, info_ptr, PNG_INFO_iCCP)) { + png_charp profile_name; +#if PNG_LIBPNG_VER < 10500 + png_charp profile_data; #else - if(png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &profile_data, &proflen)) + png_bytep profile_data; #endif - { - TQByteArray profile_rawdata; - // XXX: Hardcoded for icc type -- is that correct for us? - if (TQString::compare(profile_name, "icc") == 0) { - profile_rawdata.resize(proflen); - memcpy(profile_rawdata.data(), profile_data, proflen); - profile = new KisProfile(profile_rawdata); - TQ_CHECK_PTR(profile); - if (profile) { - kdDebug(41008) << "profile name: " << profile->productName() << " profile description: " << profile->productDescription() << " information sur le produit: " << profile->productInfo() << endl; - if(!profile->isSuitableForOutput()) - { - kdDebug(41008) << "the profile is not suitable for output and therefore cannot be used in chalk, we need to convert the image to a standard profile" << endl; // TODO: in ko2 popup a selection menu to inform the user + int compression_type; + png_uint_32 proflen; + + if (png_get_iCCP(png_ptr, info_ptr, &profile_name, &compression_type, &profile_data, &proflen)) + { + TQByteArray profile_rawdata; + // XXX: Hardcoded for icc type -- is that correct for us? + if (TQString::compare(profile_name, "icc") == 0) { + profile_rawdata.resize(proflen); + memcpy(profile_rawdata.data(), profile_data, proflen); + profile = new KisProfile(profile_rawdata); + TQ_CHECK_PTR(profile); + if (profile) { + kdDebug(41008) << "profile name: " << profile->productName() << " profile description: " << profile->productDescription() << " information sur le produit: " << profile->productInfo() << endl; + if(!profile->isSuitableForOutput()) + { + kdDebug(41008) << "the profile is not suitable for output and therefore cannot be used in chalk, we need to convert the image to a standard profile" << endl; // TODO: in ko2 popup a selection menu to inform the user + } } } } @@ -636,10 +636,10 @@ KisImageBuilder_Result KisPNGConverter::buildFile(const KURL& uri, KisPaintLayer } else { // Profile char* name = new char[(*it)->type().length()+1]; strcpy(name, (*it)->type().ascii()); -#if PNG_LIBPNG_VER_MAJOR > 1 || ( PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR >= 5 ) - png_set_iCCP(png_ptr, info_ptr, name, PNG_COMPRESSION_TYPE_BASE, (unsigned char*)(*it)->annotation().data(), (*it) -> annotation() . size()); +#if PNG_LIBPNG_VER < 10500 + png_set_iCCP(png_ptr, info_ptr, name, PNG_COMPRESSION_TYPE_BASE, (png_charp)(*it)->annotation().data(), (*it) -> annotation() . size()); #else - png_set_iCCP(png_ptr, info_ptr, name, PNG_COMPRESSION_TYPE_BASE, (char*)(*it)->annotation().data(), (*it) -> annotation() . size()); + png_set_iCCP(png_ptr, info_ptr, name, PNG_COMPRESSION_TYPE_BASE, (png_bytep)(*it)->annotation().data(), (*it) -> annotation() . size()); #endif } ++it; |