SVN commit 535843 by cgilles:
digikam from trunk : bug fix in DImg::pngLoader : if exif metadata are created from scratch (from RAW file for example), add Exif header at start of Exif byte array to please Exiv2 for future metadata parsing. If metadata come from a PNG file do nothing because Exif header is already available. CCMAIL: [hidden email] M +22 -83 pngloader.cpp M +0 -1 pngloader.h --- trunk/extragear/graphics/digikam/libs/dimg/loaders/pngloader.cpp #535842:535843 @@ -648,7 +648,25 @@ } case(DImg::EXIF): { - writeRawProfile(png_ptr, info_ptr, "exif", ba.data(), (png_uint_32) ba.size()); + const uchar ExifHeader[] = {0x45, 0x78, 0x69, 0x66, 0x00, 0x00}; + QByteArray profile; + + // If bytes array do not start with ImageMagick header, Exif metadata have been created from + // scratch using Exiv2. In this case, we need to add Exif header from start. + if (memcmp(ba.data(), "exif", 4) != 0 && + memcmp(ba.data(), "iptc", 4) != 0 && + memcmp(ba.data(), "profile", 7) != 0) + { + profile = QByteArray(ba.size() + sizeof(ExifHeader)); + memcpy(profile.data(), ExifHeader, sizeof(ExifHeader)); + memcpy(profile.data()+sizeof(ExifHeader), ba.data(), ba.size()); + } + else + { + profile = ba; + } + + writeRawProfile(png_ptr, info_ptr, "exif", profile.data(), (png_uint_32) profile.size()); break; } case(DImg::IPTC): @@ -768,85 +786,6 @@ return m_sixteenBit; } -uchar* PNGLoader::readRawProfile(png_textp text, png_uint_32 *length, int ii) -{ - uchar *info = 0; - - register long i; - - register uchar *dp; - - register png_charp sp; - - png_uint_32 nibbles; - - unsigned char unhex[103]={0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,1, 2,3,4,5,6,7,8,9,0,0, - 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,10,11,12, - 13,14,15}; - - sp = text[ii].text+1; - - // Look for newline - - while (*sp != '\n') - sp++; - - // Look for length - - while (*sp == '\0' || *sp == ' ' || *sp == '\n') - sp++; - - *length = (png_uint_32) atol(sp); - - while (*sp != ' ' && *sp != '\n') - sp++; - - // Allocate space - - if (*length == 0) - { - kdDebug() << "Unable To Copy Raw Profile: invalid profile length" << endl; - return (false); - } - - info = new uchar[*length]; - - if (!info) - { - kdDebug() << "Unable To Copy Raw Profile: cannot allocate memory" << endl; - return (false); - } - - // Copy profile, skipping white space and column 1 "=" signs - - dp = info; - nibbles = *length * 2; - - for (i = 0; i < (long) nibbles; i++) - { - while (*sp < '0' || (*sp > '9' && *sp < 'a') || *sp > 'f') - { - if (*sp == '\0') - { - kdDebug() << "Unable To Copy Raw Profile: ran out of data" << endl; - return (false); - } - - sp++; - } - - if (i%2 == 0) - *dp = (uchar) (16*unhex[(int) *sp++]); - else - (*dp++) += unhex[(int) *sp++]; - } - - return info; -} - void PNGLoader::writeRawProfile(png_struct *ping, png_info *ping_info, char *profile_type, char *profile_data, png_uint_32 length) { @@ -859,16 +798,16 @@ png_charp dp; png_uint_32 allocated_length, description_length; + + const uchar hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; - uchar hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'}; - kdDebug() << "Writing Raw profile: type=" << profile_type << ", length=" << length << endl; text = (png_textp) png_malloc(ping, (png_uint_32) sizeof(png_text)); description_length = strlen((const char *) profile_type); allocated_length = (png_uint_32) (length*2 + (length >> 5) + 20 + description_length); - text[0].text = (png_charp) png_malloc(ping,allocated_length); + text[0].text = (png_charp) png_malloc(ping, allocated_length); text[0].key = (png_charp) png_malloc(ping, (png_uint_32) 80); text[0].key[0] = '\0'; --- trunk/extragear/graphics/digikam/libs/dimg/loaders/pngloader.h #535842:535843 @@ -50,7 +50,6 @@ private: - uchar* readRawProfile(png_textp text, png_uint_32 *length, int ii); void writeRawProfile(png_struct *ping, png_info *ping_info, char *profile_type, char *profile_data, png_uint_32 length); _______________________________________________ Digikam-devel mailing list [hidden email] https://mail.kde.org/mailman/listinfo/digikam-devel |
Free forum by Nabble | Edit this page |