#775: Sort IPTC data by record number when encoding (Matthias Baas).

v0.27.3
Andreas Huggel 14 years ago
parent b52e430f38
commit 3f478a2ca2

@ -469,13 +469,29 @@ namespace Exiv2 {
return 0;
} // IptcParser::decode
/*!
@brief Compare two iptc items by record. Return true if the record of
lhs is less than that of rhs.
This is a helper function for IptcParser::encode().
*/
bool cmpIptcdataByRecord(const Iptcdatum& lhs, const Iptcdatum& rhs)
{
return lhs.record() < rhs.record();
}
DataBuf IptcParser::encode(const IptcData& iptcData)
{
DataBuf buf(iptcData.size());
byte *pWrite = buf.pData_;
IptcData::const_iterator iter = iptcData.begin();
IptcData::const_iterator end = iptcData.end();
// Copy the iptc data sets and sort them by record but preserve the order of datasets
IptcMetadata sortedIptcData;
std::copy(iptcData.begin(), iptcData.end(), std::back_inserter(sortedIptcData));
std::stable_sort(sortedIptcData.begin(), sortedIptcData.end(), cmpIptcdataByRecord);
IptcData::const_iterator iter = sortedIptcData.begin();
IptcData::const_iterator end = sortedIptcData.end();
for ( ; iter != end; ++iter) {
// marker, record Id, dataset num
*pWrite++ = marker_;

@ -9,15 +9,15 @@ Testcase 2
==========
Xmp.dc.description LangAlt 1 lang="x-default" The Exif image description
Exif.Image.ImageDescription Ascii 27 The Exif image description
Iptc.Application2.Caption String 26 The Exif image description
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.Caption String 26 The Exif image description
Testcase 3
==========
Xmp.dc.description LangAlt 1 lang="de-DE" The Exif image description
Exif.Image.ImageDescription Ascii 27 The Exif image description
Iptc.Application2.Caption String 26 The Exif image description
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.Caption String 26 The Exif image description
Testcase 4
==========
@ -36,8 +36,8 @@ Warning: Failed to convert Xmp.dc.description to Exif.Image.ImageDescription
<rdf:li xml:lang="x-default">How to fix this mess</rdf:li>
Xmp.dc.description LangAlt 3 lang="x-default" How to fix this mess, lang="de-DE" The Exif image description, lang="it-IT" Ciao bella
Exif.Image.ImageDescription Ascii 21 How to fix this mess
Iptc.Application2.Caption String 20 How to fix this mess
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.Caption String 20 How to fix this mess
Testcase 6
==========
@ -74,10 +74,10 @@ Testcase 9
Xmp.dc.subject XmpBag 3 Sex, Drugs, Rock'n'roll
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
Iptc.Envelope.CharacterSet String 3 $%G
Testcase 10
===========
@ -108,8 +108,8 @@ Testcase 13
Xmp.iptc.Location XmpText 12 Kuala Lumpur
File 1/1: t.jpg
t.jpg: No Exif data found in the file
Iptc.Application2.SubLocation String 12 Kuala Lumpur
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.SubLocation String 12 Kuala Lumpur
Testcase 14
===========
@ -180,5 +180,5 @@ Exif.GPSInfo.GPSLatitudeRef Ascii 2 N
Exif.GPSInfo.GPSLatitude Rational 3 3/1 8/1 1858407/62500
Exif.GPSInfo.GPSTimeStamp Rational 3 1/1 2/1 999999999/1000000000
Exif.GPSInfo.GPSDateStamp Ascii 11 2003:12:14
Iptc.Application2.DateCreated Date 8 2007-05-09
Iptc.Envelope.CharacterSet String 3 $%G
Iptc.Application2.DateCreated Date 8 2007-05-09

@ -1,9 +1,9 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Caption 0x0078 String 33 A picture of a glider being built
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,8 +1,8 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,8 +1,8 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,8 +1,8 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 16 This is a credit
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 25 This is credit number one
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 16 This is a credit
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,8 +1,8 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,8 +1,8 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Headline 0x0069 String 17 The headline I am
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 16 This is a credit
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 16 This is a credit
Iptc.Application2.Byline 0x0050 String 17 This is a by-line
@ -6,6 +8,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 0
Iptc.Application2.Credit 0x006e String 16 This is a credit
Iptc.Application2.Byline 0x0050 String 17 This is a by-line
@ -6,6 +8,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 2
Iptc.Application2.Byline 0x0050 String 13 Jens TrŸbiger
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 2
Iptc.Application2.Byline 0x0050 String 13 Jens TrŸbiger
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 2
Iptc.Application2.Byline 0x0050 String 13 Jens TrŸbiger
Iptc.Application2.Headline 0x0069 String 17 The headline I am
@ -5,6 +7,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Caption 0x0078 String 38 yelimS green faced dude (iptc caption)
Iptc.Application2.Writer 0x007a String 6 Nobody
Iptc.Application2.Byline 0x0050 String 6 Its me
@ -15,6 +17,4 @@ Iptc.Application2.Headline 0x0069 String 17 The headline
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RecordVersion 0x0000 Short 1 2
Iptc.Application2.Caption 0x0078 String 18 A bunch of squares
Iptc.Application2.Byline 0x0050 String 4 Brad
@ -9,6 +11,4 @@ Iptc.Application2.Keywords 0x0019 String 19 Yet another k
Iptc.Application2.DateCreated 0x0037 Date 8 2004-08-03
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

@ -1,3 +1,5 @@
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.Caption 0x0078 String 38 Smiley green faced dude (iptc caption)
Iptc.Application2.Writer 0x007a String 6 Nobody
Iptc.Application2.Byline 0x0050 String 6 Its me
@ -15,6 +17,4 @@ Iptc.Application2.Headline 0x0069 String 17 The headline
Iptc.Application2.Keywords 0x0019 String 19 Yet another keyword
Iptc.Application2.Urgency 0x000a String 1 3
Iptc.Application2.SuppCategory 0x0014 String 10 bla bla ba
Iptc.Envelope.ModelVersion 0x0000 Short 1 2
Iptc.Envelope.TimeSent 0x0050 Time 11 14:41:00-05:00
Iptc.Application2.RasterizedCaption 0x007d Undefined 8 230 42 34 2 90 84 23 146

Loading…
Cancel
Save