Added XMP sample (incomplete), bugfixes.

v0.27.3
Andreas Huggel 18 years ago
parent 4d3c398ee1
commit 9beec8880d

@ -122,7 +122,8 @@ BINSRC = addmoddel.cpp \
tiffparse.cpp
ifdef ENABLE_XMP
BINSRC += xmpparse.cpp \
xmpparser-test.cpp
xmpparser-test.cpp \
xmpsample.cpp
endif
# Main source file of the Exiv2 application

@ -90,7 +90,6 @@ namespace Exiv2 {
ErrMsg( 45, N_("Schema namespace %1 is not registered with the XMP Toolkit")), // %1=namespace
ErrMsg( 46, N_("No namespace registered for prefix `%1'")), // %1=prefix
ErrMsg( 47, N_("No prefix registered for namespace `%1'")), // %1=namespace
ErrMsg( 48, N_("Invalid type `%1' to create an XmpArrayValue")), // %1=typeName
// Last error message (message is not used)
ErrMsg( -2, N_("(Unknown Error)"))

@ -447,9 +447,7 @@ namespace Exiv2 {
case xmpAlt: xa = xaAlt; break;
case xmpBag: xa = xaBag; break;
case xmpSeq: xa = xaSeq; break;
default:
throw Error(48, TypeInfo::typeName(typeId));
break;
default: break;
}
return xa;
}

@ -673,7 +673,10 @@ namespace Exiv2 {
virtual int read(const std::string& buf) =0;
//@}
//! Return XMP array type for an array Value TypeId
/*!
@brief Return XMP array type for an array Value TypeId, xaNone if
\em typeId is not an XMP array value type.
*/
static XmpArrayType xmpArrayType(TypeId typeId);
protected:

@ -565,12 +565,22 @@ namespace Exiv2 {
const LangAltValue* la = dynamic_cast<const LangAltValue*>(&i->value());
if (la == 0) throw Error(43, i->key());
int idx = 1;
for (LangAltValue::ValueType::const_iterator k = la->value_.begin();
k != la->value_.end(); ++k) {
// write the default first
LangAltValue::ValueType::const_iterator k = la->value_.find("x-default");
if (k != la->value_.end()) {
#ifdef DEBUG
printNode(ns, i->tagName(), k->second, 0);
#endif
meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAltText, k->second.c_str());
meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAlternate, k->second.c_str());
const std::string item = i->tagName() + "[" + toString(idx++) + "]";
meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k->first.c_str());
}
for (k = la->value_.begin(); k != la->value_.end(); ++k) {
if (k->first == "x-default") continue;
#ifdef DEBUG
printNode(ns, i->tagName(), k->second, 0);
#endif
meta.AppendArrayItem(ns.c_str(), i->tagName().c_str(), kXMP_PropArrayIsAlternate, k->second.c_str());
const std::string item = i->tagName() + "[" + toString(idx++) + "]";
meta.SetQualifier(ns.c_str(), item.c_str(), kXMP_NS_XML, "lang", k->first.c_str());
}

@ -0,0 +1,67 @@
// ***************************************************************** -*- C++ -*-
// xmpsample.cpp, $Rev$
// Sample/test for high level XMP classes
#include "value.hpp"
#include "xmp.hpp"
#include "error.hpp"
#include <string>
#include <iostream>
#include <iomanip>
using namespace Exiv2;
int main()
try {
// The XMP property container
Exiv2::XmpData xmpData;
// Add a simple XMP property in a known namespace
Exiv2::Value::AutoPtr v = Exiv2::Value::create(xmpText);
v->read("image/jpeg");
xmpData.add(Exiv2::XmpKey("Xmp.dc.format"), v.get());
// Add an ordered array of text values
v = Exiv2::Value::create(xmpSeq);
v->read("1) The first creator"); // the sequence in which the array elements
v->read("2) The second creator"); // are added is relevant
v->read("3) And another one");
xmpData.add(Exiv2::XmpKey("Xmp.dc.creator"), v.get());
// Add a language alternative property
v = Exiv2::Value::create(langAlt);
v->read("lang=de-DE Hallo, Welt"); // the default doesn't need a qualifier
v->read("Hello, World"); // and it will become the first element
xmpData.add(Exiv2::XmpKey("Xmp.dc.description"), v.get());
// Output XMP properties
for (Exiv2::XmpData::const_iterator md = xmpData.begin();
md != xmpData.end(); ++md) {
std::cout << std::setfill(' ') << std::left
<< std::setw(44)
<< md->key() << " "
<< std::setw(9) << std::setfill(' ') << std::left
<< md->typeName() << " "
<< std::dec << std::setw(3)
<< std::setfill(' ') << std::right
<< md->count() << " "
<< std::dec << md->value()
<< std::endl;
}
// Serialize the XMP data and output the XMP packet
std::string xmpPacket;
if (0 != Exiv2::XmpParser::encode(xmpPacket, xmpData)) {
throw Exiv2::Error(1, "Failed to serialize XMP data");
}
std::cout << xmpPacket << "\n";
// Cleanup
Exiv2::XmpParser::terminate();
return 0;
}
catch (Exiv2::AnyError& e) {
std::cout << "Caught Exiv2 exception '" << e << "'\n";
return -1;
}

@ -22,7 +22,7 @@ Xmp.tiff.ImageWidth XmpText 3 360
Xmp.tiff.ImageLength XmpText 3 216
Xmp.tiff.NativeDigest XmpText 134 256,257,258,259,262,274,277,284,530,531,282,283,296,301,318,319,529,532,306,270,271,272,305,315,33432;D0485928256FC8D17D036C26919E106D
Xmp.tiff.Make XmpText 5 Nikon
Xmp.tiff.BitsPerSample XmpBag 3 8, 8, 8
Xmp.tiff.BitsPerSample XmpSeq 3 8, 8, 8
Xmp.exif.PixelXDimension XmpText 3 360
Xmp.exif.PixelYDimension XmpText 3 216
Xmp.exif.ColorSpace XmpText 1 1
@ -34,7 +34,7 @@ Xmp.exif.NativeDigest XmpText 414 36864,40960,40961,37
> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 4.1.1">
35d34
< <rdf:li xml:lang="en-US">Blue Square Test File - .jpg</rdf:li>
36a36
37a37
> <rdf:li xml:lang="en-US">Blue Square Test File - .jpg</rdf:li>
-----> Decoding XMP data read from StaffPhotographer-Example.xmp <-----
Xmp.iptc.IntellectualGenre XmpText 7 Profile
@ -75,7 +75,7 @@ Xmp.tiff.Orientation XmpText 1 1
Xmp.tiff.ImageWidth XmpText 3 432
Xmp.tiff.ImageLength XmpText 3 293
Xmp.tiff.NativeDigest XmpText 134 256,257,258,259,262,274,277,284,530,531,282,283,296,301,318,319,529,532,306,270,271,272,305,315,33432;24B61B075FA9960B09291337508795BF
Xmp.tiff.BitsPerSample XmpBag 3 8, 8, 8
Xmp.tiff.BitsPerSample XmpSeq 3 8, 8, 8
Xmp.xmp.CreateDate XmpText 25 2005-03-13T02:01:44-06:00
Xmp.xmp.ModifyDate XmpText 25 2005-03-13T02:01:44-06:00
Xmp.xmp.MetadataDate XmpText 25 2007-01-08T13:25:45+01:00
@ -93,7 +93,7 @@ Xmp.dc.format XmpText 10 image/jpeg
Xmp.dc.description LangAlt 1 lang="x-default" After digging the furrows another ten yards with the tractor, Jim Moore hops off to hand-set more leeks and onions.
Xmp.dc.title LangAlt 1 lang="x-default" 01661gdx
Xmp.dc.rights LangAlt 1 lang="x-default" ©2003 Big Newspaper, all rights reserved
Xmp.dc.creator XmpBag 1 John Doe
Xmp.dc.creator XmpSeq 1 John Doe
Xmp.dc.subject XmpBag 22 agriculture, farm laborer, farmer, field hand, field worker, humans, occupation, people, agricultural, agronomy, crops, onions, vegetable crops, plants, vegetables, outdoors, outside, agricultural equipment, tractor, gender, male, men
Xmp.wine.Recommend XmpText 5 False
-----> Encoding XMP data to write to StaffPhotographer-Example.xmp-new <-----

Loading…
Cancel
Save