diff options
author | Christian Fetzer <fetzer.ch@googlemail.com> | 2012-09-12 16:46:56 +0200 |
---|---|---|
committer | Christian Fetzer <fetzer.ch@googlemail.com> | 2012-09-13 13:20:20 +0200 |
commit | 44ba8a2f05d240de364048cd52cb2ebca562cffd (patch) | |
tree | 91ab56445876bf75d51c36ba210b3f1621d971ac /lib/libexif/ExifParse.cpp | |
parent | 13e3ada783db4fc77cc13e3edb95ba8456ae6399 (diff) |
[libexif] Added character set conversion to UserComment
closes #12628
Diffstat (limited to 'lib/libexif/ExifParse.cpp')
-rw-r--r-- | lib/libexif/ExifParse.cpp | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/libexif/ExifParse.cpp b/lib/libexif/ExifParse.cpp index 4f39a51b51..635d82f600 100644 --- a/lib/libexif/ExifParse.cpp +++ b/lib/libexif/ExifParse.cpp @@ -451,11 +451,32 @@ void CExifParse::ProcessDir(const unsigned char* const DirStart, case TAG_USERCOMMENT: { - const int EXIF_COMMENT_HDR_LENGTH = 8; // All comment tags have 8 bytes of header info - int length = max(ByteCount - EXIF_COMMENT_HDR_LENGTH, 0); - length = min(length, MAX_COMMENT); - strncpy(m_ExifInfo->Comments, (char *)ValuePtr+EXIF_COMMENT_HDR_LENGTH, length); -// FixComment(comment); // Ensure comment is printable + // The UserComment allows comments without the charset limitations of ImageDescription. + // Therefore the UserComment field is prefixed by a CharacterCode field (8 Byte): + // - ASCII: 'ASCII\0\0\0' + // - Unicode: 'UNICODE\0' + // - JIS X208-1990: 'JIS\0\0\0\0\0' + // - Unknown: '\0\0\0\0\0\0\0\0' (application specific) + + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_UNKNOWN; + + const int EXIF_COMMENT_CHARSET_LENGTH = 8; + if (ByteCount >= EXIF_COMMENT_CHARSET_LENGTH) + { + // As some implementations use spaces instead of \0 for the padding, + // we're not so strict and check only the prefix. + if (memcmp(ValuePtr, "ASCII", 5) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_ASCII; + else if (memcmp(ValuePtr, "UNICODE", 7) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_UNICODE; + else if (memcmp(ValuePtr, "JIS", 3) == 0) + m_ExifInfo->CommentsCharset = EXIF_COMMENT_CHARSET_JIS; + + int length = ByteCount - EXIF_COMMENT_CHARSET_LENGTH; + length = min(length, MAX_COMMENT); + memcpy(m_ExifInfo->Comments, ValuePtr + EXIF_COMMENT_CHARSET_LENGTH, length); +// FixComment(comment); // Ensure comment is printable + } } break; |