#1108. Refactored the IPTC printStructure code from png/jpeg/tiff into iptc.cpp

v0.27.3
Robin Mills 9 years ago
parent 5182c06c22
commit 09c734fbcd

@ -273,6 +273,10 @@ namespace Exiv2 {
@brief Return the metadata charset name or 0
*/
const char *detectCharset() const;
/*!
@brief dump iptc formatted binary data (used by printStructure kpsRecursive)
*/
static void printStructure(std::ostream& out, const byte* bytes,const size_t size,uint32_t depth);
//@}
private:

@ -36,6 +36,7 @@ EXIV2_RCSID("@(#) $Id$")
#include "value.hpp"
#include "datasets.hpp"
#include "jpgimage.hpp"
#include "image_int.hpp"
// + standard includes
#include <iostream>
@ -352,6 +353,34 @@ namespace Exiv2 {
return iptcMetadata_.erase(pos);
}
static std::string indent(int d)
{
std::string result ;
if ( d > 0 )
while ( d--)
result += " ";
return result;
}
void IptcData::printStructure(std::ostream& out, const byte* bytes,const size_t size,uint32_t depth)
{
uint32_t i = 0 ;
while ( i < size-3 && bytes[i] != 0x1c ) i++;
depth++;
out << indent(depth) << "Record | DataSet | Name | Length | Data" << std::endl;
while ( bytes[i] == 0x1c && i < size-3 ) {
char buff[100];
uint16_t record = bytes[i+1];
uint16_t dataset = bytes[i+2];
uint16_t len = getUShort(bytes+i+3,bigEndian);
sprintf(buff," %6d | %7d | %-24s | %6d | ",record,dataset, Exiv2::IptcDataSets::dataSetName(dataset,record).c_str(), len);
out << buff << Internal::binaryToString(bytes,(len>40?40:len),i+5) << (len>40?"...":"") << std::endl;
i += 5 + len;
}
depth--;
}
const char *IptcData::detectCharset() const
{
const_iterator pos = findKey(IptcKey("Iptc.Envelope.CharacterSet"));

@ -719,25 +719,8 @@ namespace Exiv2 {
}
if ( bPS ) {
uint32_t i = 0 ;
byte* bytes = exif;
DataBuf dataBuf(bytes,size);
while ( i < size-3 && exif[i] != 0x1c ) i++;
depth++;
out << " Record | DataSet | Name | Length | Data" << std::endl;
while ( bytes[i] == 0x1c && i < size-3 ) {
char buff[100];
uint16_t record = bytes[i+1];
uint16_t dataset = bytes[i+2];
uint16_t len = getUShort(bytes+i+3,bigEndian);
sprintf(buff," %6d | %7d | %-24s | %6d | ",record,dataset, Exiv2::IptcDataSets::dataSetName(dataset,record).c_str(), len);
out << buff << Internal::binaryToString(dataBuf,len,i+5) << std::endl;
i += 5 + len;
}
depth--;
IptcData::printStructure(out,exif,size,depth);
} else {
// create a copy on write memio object with the data, then print the structure
BasicIo::AutoPtr p = BasicIo::AutoPtr(new MemIo(exif+start,size-start));
if ( start < max ) TiffImage::printTiffStructure(*p,out,option,depth);

@ -311,22 +311,7 @@ namespace Exiv2 {
}
if ( bIptc ) {
const byte* bytes = dataBuf.pData_;
uint32_t l = (uint32_t) dataBuf.size_ ; // std::strlen(bytes)+2;
uint32_t i = 0 ;
depth++;
out << indent(depth) << "Record | DataSet | Name | Length | Data" << std::endl;
while ( bytes[i] == 0x1c && i < l-3 ) {
char buff[100];
uint16_t record = bytes[i+1];
uint16_t dataset = bytes[i+2];
uint16_t len = getUShort(bytes+i+3,bigEndian);
sprintf(buff,"%6d | %7d | %-24s | %6d | ",record,dataset, Exiv2::IptcDataSets::dataSetName(dataset,record).c_str(), len);
out << indent(depth) << buff << Internal::binaryToString(dataBuf,len,i+5) << std::endl;
i += 5 + len;
}
depth--;
IptcData::printStructure(out,dataBuf.pData_,dataBuf.size_,depth);
}
}
delete [] data;

@ -584,21 +584,8 @@ namespace Exiv2 {
byte* bytes=new byte[count] ; // allocate memory
io.read(bytes,count) ; // read
io.seek(restore,BasicIo::beg); // restore
uint32_t i = 0 ;
while ( i < count-3 && bytes[i] != 0x1c ) i++;
out << " Record | DataSet | Name | Length | Data" << std::endl;
while ( bytes[i] == 0x1c && i < size-3 ) {
char buff[100];
uint16_t record = bytes[i+1];
uint16_t dataset = bytes[i+2];
uint16_t len = getUShort(bytes+i+3,bigEndian);
sprintf(buff," %6d | %7d | %-24s | %6d | ",record,dataset, Exiv2::IptcDataSets::dataSetName(dataset,record).c_str(), len);
out << buff << Internal::binaryToString(bytes,(len>40?40:len),i+5) << (len>40?"...":"") << std::endl;
i += 5 + len;
}
delete[] bytes;
IptcData::printStructure(out,bytes,count,depth);
delete[] bytes; // free
}
}

Loading…
Cancel
Save