Bug 152210 - Metadata lost when converting from png to jpeg (IPTC thumbnail too big)
Summary: Metadata lost when converting from png to jpeg (IPTC thumbnail too big)
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Bqm-Convert (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-12 18:26 UTC by Paweł Marciniak
Modified: 2017-07-01 15:21 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.0.0


Attachments
The jpeg file that causes problems with svn exiv2 (890.18 KB, image/jpeg)
2007-11-24 16:58 UTC, Paweł Marciniak
Details
The difference in metadata before and after running convert (1.37 KB, text/plain)
2007-11-24 17:02 UTC, Paweł Marciniak
Details
The same picture as attachment 1 with fixed IPTC IRB sizes (890.18 KB, image/jpeg)
2007-12-08 12:14 UTC, Andreas Huggel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paweł Marciniak 2007-11-12 18:26:32 UTC
Version:           svn (using KDE KDE 3.5.8)
Installed from:    Unlisted Binary Package
OS:                Linux

A preview (an embeded and reduced JPEG image) that is set by digiKam in IPTC to speed up preview loading (F4) can be larger than 64Kb (see iptc/iim paper) and a jpeg section (used to embeded iptc in jpeg file) is limited to 64Kb. There is no size limitation with PNG (or TIFF). Therefore, when png files are created at the time of downloading images from camera, too big previews are generated.
After converting such pngs to jpegs with batch convert and trying to open new jpegs in digiKam, no metadata are shown (neither IPTC 
nor EXIF) and the console says:
Warning: IPTC dataset Iptc.Application2.Preview has invalid size 67904; skipped.

IPTC data should be stripped during conversion ('convert +profile iptc') so that at least EXIF is readable in the newly created jpegs.
Comment 1 Geoff King 2007-11-18 19:24:58 UTC
This looks similar to the bug reported last month.
http://bugs.kde.org/show_bug.cgi?id=150801  

See comment #1



Comment 2 Paweł Marciniak 2007-11-19 00:43:59 UTC
Geoff,

It is similar, but your report applies to digiKam core, while mine has to do with batch process plugin.

Anyway, the bug described here is rather an ImageMagick bug, so I'm not sure if on the side of KIPI we are able to do anything more than some ugly workaround.
Comment 3 caulier.gilles 2007-11-19 17:08:41 UTC
Pawel,

Look my commits #738759. In convertimagesdialog.cpp, i have add a new virtual method named processDone(). This one is called by main batch process loop when a conversion from a file to another one is done.

Code is commented in this method. Uncomment it and test.

Just update too libkexiv2. I have patched this one to report the Exiv2 error code on the console. 

Try to convert PNG files generated by digiKam image Editor (with IPTC preview data) to JPEG and look the result.

Here it doesn't properlly... sometimes. Sound like a race condition failure somewhere.

Gilles
Comment 4 caulier.gilles 2007-11-19 21:51:39 UTC
SVN commit 738840 by cgilles:

Kipi-plugins from KDE3 branch : Batch Process : restore metadata properlly with JPEG file during conversion.
Pawel, This patch sound like properlly under KDE3.5, but not under KDE 3.4. I suspect a bug in KProcess or something like that.
BUG: 152210


 M  +1 -2      convertimagesdialog.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=738840
Comment 5 caulier.gilles 2007-11-19 21:57:36 UTC
Pawel, 

Please test and give me your feedback. Thanks in advance

Gilles
Comment 6 Paweł Marciniak 2007-11-19 23:52:07 UTC
Unfortunately, there's still a problem when Exiv2 is supposed to load the metadata corrupted by convert program. The image->readMetadata() call in kexiv2.cpp:381 says:

Warning: IPTC dataset Iptc.Application2.Preview has invalid size 120301; skipped.
Warning: Failed to decode IPTC metadata.

It's happening during construction of the metaTgt object in convertimagesdialog.cpp. So the object is broken and further call to metaTgt.applyChanges() throws Exiv2 error 22: Input data does not contain a valid image.

The first solution that comes to my mind is to use source metadata as a base for removing the preview, but then we loose the changes to metadata that convert program probably does.
Comment 7 Paweł Marciniak 2007-11-19 23:59:49 UTC
As to the race condition you mentioned, I already reported one in bug #152208 . Perhaps that's the same beast...
Comment 8 Paweł Marciniak 2007-11-24 11:21:35 UTC
That's strange! The problem with metaTgt I described happens only with svn version of exiv2. With stable 0.15 it works fine...

Anyway, maybe we could just copy the source metadata after stripping the preview? Seems like convert doesn't change metadata much. I did a comparison and only few Canon-specific exif tags were changed.
Comment 9 caulier.gilles 2007-11-24 15:39:38 UTC
Pawel,

Yes, i can reproduce the problem here. With Exiv2 0.15 all is fine, and with 0.16-svn, something fail...

Andreas, What do you think about ?

Gilles
Comment 10 Andreas Huggel 2007-11-24 16:29:25 UTC
To the original bug report: Since Exiv2 v0.15, reading of Exif and IPTC metadata is decoupled, i.e., if reading IPTC fails, it will not affect reading of Exif.

Re comment #6: The Exiv2 error 22 in the svn version sounds like a bug, since it worked in 0.15. I'll look into this, can you please send me such a corrupted JPG?

Re comment #8: Can convert handle makernotes, what does "change a few canon-specific tags" mean? Are there any valid makernote tags left?
Comment 11 Paweł Marciniak 2007-11-24 16:58:18 UTC
Created attachment 22180 [details]
The jpeg file that causes problems with svn exiv2
Comment 12 Paweł Marciniak 2007-11-24 17:02:19 UTC
Created attachment 22181 [details]
The difference in metadata before and after running convert

This is a diff between exif dumps (exiv2 -v -b pr -p h) of png and jpeg file. I
rearranged some parts of the dumps in order to help the diff program exclude
identical (but relocated) sections.
Comment 13 Andreas Huggel 2007-11-28 17:06:49 UTC
Thanks for this image. I can reproduce an Exiv2 Error 22 exception with this image. The problem is rather fundamental: The image has its IPTC data split over two APP13 Photoshop 3.0 segments it seems (and thus answers this old question: http://bugs.kde.org/show_bug.cgi?id=130525#c32).

Exiv2 can only deal with one such segment in a JPEG. I've opened Exiv2 issue #533 (http://dev.robotbattle.com/bugs/view.php?id=533) to fix this.

However, I get exactly the same behaviour in 0.16-pre1 and 0.15 and none of the previous revisions can handle this case. So can you please elaborate what exactly is the situation which you only observe with 0.16-pre1 but not with 0.15, maybe there is another issue here?

-ahu.
Comment 14 Andreas Huggel 2007-12-08 12:14:30 UTC
Created attachment 22410 [details]
The same picture as attachment 1 [details] with fixed IPTC IRB sizes

The original image contains two APP13 Photoshop 3.0 segments, both contain an
IRB with IPTC data. However, both of these IRBs have wrong sizes (0x0adf for
both). The new attachment is the same image as the original but the IRB sizes
are fixed (0xffdc and 0x0b04). Using some new code (not checked-in yet) to
parse the JPEG segments, I can now get all the IPTC datasets out of this image
with exiv2, including the preview image (68198 bytes JPEG thumbnail). However,
exiftool doesn't like the way the IPTC data is split over the two IRBs, and I
have no specification which says how it is actually supposed to be done. So I'm
not sure yet what it should be.
Comment 15 Andreas Huggel 2007-12-08 12:16:57 UTC
That should read "same picture as attachment 22180 [details]", above. Nice feature :)
Comment 16 Andreas Huggel 2007-12-08 12:27:30 UTC
Paweł, if you still have it, could you please also send me the original PNG file which you converted to the JPEG posted as attachment 22180 [details]?

Thanks,
Andreas
 
Comment 17 caulier.gilles 2007-12-08 13:00:48 UTC
Andreas,

You is back... Welcome...

we suspect a little problem in Exiv2 0.16 against 0.15. Thanks to review it

Gilles
Comment 18 Andreas Huggel 2007-12-08 13:09:03 UTC
well, it looks like my comments didn't make it to the list because i wasn't registered with kde-imaging. i've fixed that now.

pls see my earlier comment 13 above (and comment 14 for a better explanation): i can reproduce the problem but it happens with all versions. need more input on the issue which happens only with the latest version.

andreas
Comment 19 Paweł Marciniak 2007-12-17 08:20:48 UTC
In response to Andreas' comment #16, I uploaded the png file at http://pandora.cs.put.poznan.pl/~pmarciniak/img_7469.png
The file is over 7 megs in size and B.K.O. doesn't accept such big attachments.

A little late (a LOT of work recently), sorry for that, but I hope this still helps.

Best,
Paweł
Comment 20 caulier.gilles 2008-12-07 21:33:42 UTC
Pawel,

This file still valid using kipi-plugins 0.1.6 and a recent version of Exiv2
library ?

Gilles Caulier
Comment 21 Paweł Marciniak 2009-01-21 04:57:39 UTC
Just repro'ed it with digikam 0.9.4, kipi-plugins 0.1.6 and libexiv2 0.17.1
Console output when opening the converted jpg image:
Warning: IFD0 tag 0x0001 has invalid Exif type 0; using 7 (undefined).
Warning: IPTC dataset Iptc.Application2.Preview has invalid size 68198; skipped.
Comment 22 caulier.gilles 2009-01-21 08:23:39 UTC
Marcel,

with jpeg, we don't create iptc preview, but in case of converting PNG to JPEG, and if PNG has already iptc preview, this one is not removed (in editor code). I think we need to always remove it with JPEG (to be sure)

Pawel, 

this warning come from Exiv2 which skip iptc preview when size is > to 64 Kb.

Andreas,

Can you confirm that all other iptc tags are not removed in this case ?

Gilles Caulier
Comment 23 Andreas Huggel 2009-01-23 04:38:08 UTC
>> Warning: IPTC dataset Iptc.Application2.Preview has invalid size 68198; skipped.

> Andreas, Can you confirm that all other iptc tags are not removed in this case ? 

Yes, all other IPTC tags are not affected by this.

-ahu.
Comment 24 caulier.gilles 2011-12-22 12:59:45 UTC
Pawel,

This file still valid using kipi-plugins 2.4 ?

Gilles Caulier
Comment 25 Paweł Marciniak 2012-01-05 18:16:52 UTC
Hi Gilles,

Unfortunately I don't have access to a system where I could test it. Feel free to resolve the bug if nobody else is able to repro it.

Thanks,
Pawel
Comment 26 caulier.gilles 2015-06-28 10:00:40 UTC
New Kipiplugins 4.11.0 is available :

https://www.digikam.org/node/740

Can you reproduce the problem with this release ?

Gilles Caulier
Comment 27 caulier.gilles 2015-07-04 10:11:12 UTC
BatchProcessImage is not maintained since a while and is obsolete now. It will
be removed with 5.0.0.

Use digiKam BQM instead...