Bug 139313 - utf-8 image comments are mangled when input from image editor
Summary: utf-8 image comments are mangled when input from image editor
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Tags-Captions (show other bugs)
Version: 0.9.0
Platform: Ubuntu Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-28 12:48 UTC by Andras HORVATH
Modified: 2017-08-13 21:59 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 0.9.1
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andras HORVATH 2006-12-28 12:48:24 UTC
Version:           0.9.0 (using KDE KDE 3.5.2)
Installed from:    Ubuntu Packages
Compiler:          gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu5) 
OS:                Linux

When adding image comments from the main digikam "view", everything is fine. However, when adding utf-8 characters from the Image Editor, they somehow become doubly/wrongly encoded (e.g. the result is three bytes per accented char) before written into the image.

otherwise, I love 0.9.0 :-)
cheers
Comment 1 Marcel Wiesweg 2006-12-31 14:45:53 UTC
I cannot reproduce this.

Do you change the comment from the "Comments/Tags" sidebar in the Image Editor?

Where is the wrong encoding visible:
Comments/Tags sidebar in main view? Metadata Sidebar, Exif, "UserComment"? Metadata Sidebar, IPTC, "Caption"? Properties Sidebar?

What does a test string like "éèöäüßç" look like?
Comment 2 Andras HORVATH 2007-01-01 15:26:55 UTC
Okay, I've found a way to reproduce this reliably (although I was wrong about the double encoding, it's plain old UTF-8 displayed as ASCII/Latin-1):

1. open up pic with existing comment (set by Digikam or anything else) in Image Editor
2. select a region, click on Crop, click on Save
3. close the IE window
4. run 'exiv2 -p c' (or jhead) on the picture file and observe the mangled comment

After point 3, the Metadata sidebar shows that the Exif UserComment field is empty and that the comment field is removed from the IPTC header.

In addition, I've observed the following: 

1. open up pic with existing comment (set by Digikam or anything else) in Image Editor
2. delete the comment using the Comments/Tags sidebar (by clearing the Comments field).
3. Close Image Editor
4. run 'exiv2 -p c' (or jhead) on the picture file and observe that it still has the old comment. The Metadata sidebar agrees.

I hope this helps. Thanks for the quick reply and please let me know if you need any more data.
Comment 3 Marcel Wiesweg 2007-01-01 21:25:41 UTC
SVN commit 618621 by mwiesweg:

DMetadata getComments and setComments must be symmetric.
Loading a QString from a QByteArray means interpreting the data
as classic C String, but the data may be UTF8.

BUG: 139313


 M  +3 -7      dmetadata.cpp  


--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.cpp #618620:618621
@@ -120,9 +120,7 @@
 
 QByteArray DMetadata::getComments() const
 {
-    QByteArray data(d->imageComments.size());
-    memcpy(data.data(), d->imageComments.c_str(), d->imageComments.size());
-    return data;
+    return QByteArray().duplicate(d->imageComments.data(), d->imageComments.size());
 }
 
 QByteArray DMetadata::getExif() const
@@ -196,11 +194,9 @@
 
 void DMetadata::setComments(const QByteArray& data)
 {
-    QString string(data);
-    const std::string str(string.utf8());
-    d->imageComments = str;
+    d->imageComments = std::string(data.data(), data.size());
 }
-    
+
 bool DMetadata::setExif(const QByteArray& data)
 {
     try