#1064 Fix -iX to merge (not replace) metadata from source to destination.

This commit is contained in:
Robin Mills 2016-08-23 19:40:56 +00:00
parent fa24a8a614
commit 8b9265b80d
4 changed files with 46 additions and 26 deletions

View File

@ -1264,7 +1264,7 @@ namespace Action {
rc = metacopy(exvPath, path, Exiv2::ImageType::none, true);
}
if (0 == rc && (Params::instance().target_ & (Params::ctXmpSidecar|Params::ctXmpRaw)) ) {
std::string xmpPath = newFilePath(path,".xmp");
std::string xmpPath = newFilePath(path,".xmp");
rc = insertXmpPacket(xmpPath,path);
}
if (0 == rc && Params::instance().target_ & Params::ctIccProfile) {
@ -1310,34 +1310,34 @@ namespace Action {
int Insert::insertIccProfile(const std::string& path) const
{
int rc = 0;
// for path "foo.XXX", do a binary copy of "foo.icc"
int rc = 0;
// for path "foo.XXX", do a binary copy of "foo.icc"
std::string iccProfilePath = newFilePath(path, ".icc");
if (!Exiv2::fileExists(iccProfilePath, true)) {
std::cerr << iccProfilePath
<< ": " << _("Failed to open the file\n");
rc = -1;
std::cerr << iccProfilePath
<< ": " << _("Failed to open the file\n");
rc = -1;
}
Exiv2::DataBuf iccProfileBlob = Exiv2::readFile(iccProfilePath);
// test path exists
if (rc==0 && !Exiv2::fileExists(path, true)) {
std::cerr << path
<< ": " << _("Failed to open the file\n");
rc=-1;
std::cerr << path
<< ": " << _("Failed to open the file\n");
rc=-1;
}
// read in the metadata
if ( rc == 0 ) {
if ( rc == 0 ) {
Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(path);
assert(image.get() != 0);
image->readMetadata();
// clear existing profile, assign the blob and rewrite image
image->clearIccProfile();
if ( iccProfileBlob.size_ ) {
image->setIccProfile(iccProfileBlob);
}
image->writeMetadata();
// clear existing profile, assign the blob and rewrite image
image->clearIccProfile();
if ( iccProfileBlob.size_ ) {
image->setIccProfile(iccProfileBlob);
}
image->writeMetadata();
}
return rc;
@ -2020,7 +2020,7 @@ namespace {
if (Exiv2::fileExists(target)) {
targetImage = Exiv2::ImageFactory::open(target);
assert(targetImage.get() != 0);
if (preserve) targetImage->readMetadata();
targetImage->readMetadata();
}
else {
targetImage = Exiv2::ImageFactory::create(targetType, target);
@ -2034,7 +2034,14 @@ namespace {
std::cout << _("Writing Exif data from") << " " << source
<< " " << _("to") << " " << target << std::endl;
}
targetImage->setExifData(sourceImage->exifData());
if ( preserve ) {
Exiv2::ExifData::const_iterator end = sourceImage->exifData().end();
for (Exiv2::ExifData::const_iterator i = sourceImage->exifData().begin(); i != end; ++i) {
targetImage->exifData()[i->key()] = i->value();
}
} else {
targetImage->setExifData(sourceImage->exifData());
}
}
if ( Params::instance().target_ & Params::ctIptc
&& !sourceImage->iptcData().empty()) {
@ -2042,7 +2049,14 @@ namespace {
std::cout << _("Writing IPTC data from") << " " << source
<< " " << _("to") << " " << target << std::endl;
}
targetImage->setIptcData(sourceImage->iptcData());
if ( preserve ) {
Exiv2::IptcData::const_iterator end = sourceImage->iptcData().end();
for (Exiv2::IptcData::const_iterator i = sourceImage->iptcData().begin(); i != end; ++i) {
targetImage->iptcData()[i->key()] = i->value();
}
} else {
targetImage->setIptcData(sourceImage->iptcData());
}
}
if ( Params::instance().target_ & (Params::ctXmp|Params::ctXmpRaw)
&& !sourceImage->xmpData().empty()) {
@ -2064,6 +2078,11 @@ namespace {
sourceImage->printStructure(os,Exiv2::kpsXMP);
os.close();
rc = 0;
} else if ( preserve ) {
Exiv2::XmpData::const_iterator end = sourceImage->xmpData().end();
for (Exiv2::XmpData::const_iterator i = sourceImage->xmpData().begin(); i != end; ++i) {
targetImage->xmpData()[i->key()] = i->value();
}
} else {
// std::cout << "long cut" << std::endl;
targetImage->setXmpData(sourceImage->xmpData());

Binary file not shown.

View File

@ -75,8 +75,6 @@ Xmp.dc.subject XmpBag 3 Sex, Drugs, Rock'n'r
File 1/1: p.jpg
p.jpg: No Exif data found in the file
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.Keywords String 3 Sex
Iptc.Application2.Keywords String 5 Drugs
Iptc.Application2.Keywords String 11 Rock'n'roll
Testcase 10

View File

@ -289,6 +289,7 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
VP8 | 172008 | 3184 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 175200 | II*........................... .
XMP | 2864 | 187248 | <?xpacket begin="..." id="W5M0Mp
Warning: Unsupported time format
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 187526 | 0 | WEBP
@ -305,6 +306,7 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 172614 | II*........................... .
XMP | 2864 | 184662 | <?xpacket begin="..." id="W5M0Mp
Warning: Unsupported time format
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 187526 | 0 | WEBP
@ -332,12 +334,12 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Warning: Unsupported time format
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 197608 | 0 | WEBP
RIFF | 197870 | 0 | WEBP
VP8X | 10 | 12 | ,........
ICCP | 560 | 30 | ...0ADBE....mntrRGB XYZ ........
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 12040 | 172614 | II*........................... .
XMP | 12945 | 184662 | <?xpacket begin="..." id="W5M0Mp
XMP | 13207 | 184662 | <?xpacket begin="..." id="W5M0Mp
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 200568 | 0 | WEBP
@ -347,6 +349,7 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
EXIF | 12040 | 172614 | II*........................... .
XMP | 15905 | 184662 | <?xpacket begin="..." id="W5M0Mp
Warning: Unsupported time format
Warning: Unsupported time format
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 187526 | 0 | WEBP
@ -358,9 +361,9 @@ STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Warning: Unsupported time format
STRUCTURE OF WEBP FILE: exiv2-bug1199.webp
Chunk | Length | Offset | Payload
RIFF | 177494 | 0 | WEBP
RIFF | 182354 | 0 | WEBP
VP8X | 10 | 12 | ,........
ICCP | 560 | 30 | ...0ADBE....mntrRGB XYZ ........
VP8 | 172008 | 598 | .G...*.. .>1..B.!..o.. ......]..
EXIF | 2008 | 172614 | II*............................
XMP | 2864 | 174630 | <?xpacket begin="..." id="W5M0Mp
EXIF | 6868 | 172614 | II*........................... .
XMP | 2864 | 179490 | <?xpacket begin="..." id="W5M0Mp