#665: Added write-support for ORF files.

v0.27.3
Andreas Huggel 16 years ago
parent 259a4bb2bf
commit fab4603d70

@ -106,7 +106,7 @@ namespace {
{ ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amNone, amReadWrite }, { ImageType::crw, newCrwInstance, isCrwType, amReadWrite, amNone, amNone, amReadWrite },
{ ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amRead, amNone }, { ImageType::mrw, newMrwInstance, isMrwType, amRead, amRead, amRead, amNone },
{ ImageType::tiff, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone }, { ImageType::tiff, newTiffInstance, isTiffType, amReadWrite, amReadWrite, amReadWrite, amNone },
{ ImageType::orf, newOrfInstance, isOrfType, amRead, amRead, amRead, amNone }, { ImageType::orf, newOrfInstance, isOrfType, amReadWrite, amReadWrite, amReadWrite, amNone },
#ifdef EXV_HAVE_LIBZ #ifdef EXV_HAVE_LIBZ
{ ImageType::png, newPngInstance, isPngType, amReadWrite, amReadWrite, amReadWrite, amReadWrite }, { ImageType::png, newPngInstance, isPngType, amReadWrite, amReadWrite, amReadWrite, amReadWrite },
#endif // EXV_HAVE_LIBZ #endif // EXV_HAVE_LIBZ

@ -86,18 +86,6 @@ namespace Exiv2 {
return 0; return 0;
} }
void OrfImage::setExifData(const ExifData& /*exifData*/)
{
// Todo: implement me!
throw(Error(32, "Exif metadata", "ORF"));
}
void OrfImage::setIptcData(const IptcData& /*iptcData*/)
{
// Todo: implement me!
throw(Error(32, "IPTC metadata", "ORF"));
}
void OrfImage::setComment(const std::string& /*comment*/) void OrfImage::setComment(const std::string& /*comment*/)
{ {
// not supported // not supported
@ -129,8 +117,29 @@ namespace Exiv2 {
void OrfImage::writeMetadata() void OrfImage::writeMetadata()
{ {
// Todo: implement me! #ifdef DEBUG
throw(Error(31, "ORF")); std::cerr << "Writing ORF file " << io_->path() << "\n";
#endif
ByteOrder bo = byteOrder();
byte* pData = 0;
long size = 0;
IoCloser closer(*io_);
if (io_->open() == 0) {
// Ensure that this is the correct image type
if (isOrfType(*io_, false)) {
pData = io_->mmap(true);
size = io_->size();
OrfHeader orfHeader;
if (0 == orfHeader.read(pData, 8)) {
bo = orfHeader.byteOrder();
}
}
}
if (bo == invalidByteOrder) {
bo = littleEndian;
}
setByteOrder(bo);
OrfParser::encode(*io_, pData, size, bo, exifData_, iptcData_, xmpData_); // may throw
} // OrfImage::writeMetadata } // OrfImage::writeMetadata
ByteOrder OrfParser::decode( ByteOrder OrfParser::decode(
@ -153,27 +162,42 @@ namespace Exiv2 {
} }
WriteMethod OrfParser::encode( WriteMethod OrfParser::encode(
Blob& blob, BasicIo& io,
const byte* pData, const byte* pData,
uint32_t size, uint32_t size,
ByteOrder byteOrder,
const ExifData& exifData, const ExifData& exifData,
const IptcData& iptcData, const IptcData& iptcData,
const XmpData& xmpData const XmpData& xmpData
) )
{ {
/* Todo: Implement me! // Copy to be able to modify the Exif data
ExifData ed = exifData;
return TiffParserWorker::encode(blob, // Delete IFDs which do not occur in TIFF images
static const IfdId filteredIfds[] = {
panaRawIfdId
};
for (unsigned int i = 0; i < EXV_COUNTOF(filteredIfds); ++i) {
#ifdef DEBUG
std::cerr << "Warning: Exif IFD " << filteredIfds[i] << " not encoded\n";
#endif
ed.erase(std::remove_if(ed.begin(),
ed.end(),
FindExifdatum(filteredIfds[i])),
ed.end());
}
std::auto_ptr<TiffHeaderBase> header(new OrfHeader(byteOrder));
return TiffParserWorker::encode(io,
pData, pData,
size, size,
exifData, ed,
iptcData, iptcData,
xmpData, xmpData,
TiffCreator::create, Tag::root,
TiffMapping::findEncoder); TiffMapping::findEncoder,
*/ header.get());
blob.clear();
return wmIntrusive;
} }
// ************************************************************************* // *************************************************************************
@ -208,8 +232,9 @@ namespace Exiv2 {
namespace Exiv2 { namespace Exiv2 {
namespace Internal { namespace Internal {
OrfHeader::OrfHeader() OrfHeader::OrfHeader(ByteOrder byteOrder)
: TiffHeaderBase(0x4f52, 8, littleEndian, 0x00000008) : TiffHeaderBase(0x4f52, 8, byteOrder, 0x00000008),
sig_(0x4f52)
{ {
} }
@ -232,6 +257,7 @@ namespace Exiv2 {
} }
uint16_t sig = getUShort(pData + 2, byteOrder()); uint16_t sig = getUShort(pData + 2, byteOrder());
if (tag() != sig && 0x5352 != sig) return false; // #658: Added 0x5352 for SP-560UZ if (tag() != sig && 0x5352 != sig) return false; // #658: Added 0x5352 for SP-560UZ
sig_ = sig;
setOffset(getULong(pData + 4, byteOrder())); setOffset(getULong(pData + 4, byteOrder()));
if (offset() != 0x00000008) return false; if (offset() != 0x00000008) return false;
@ -240,8 +266,23 @@ namespace Exiv2 {
DataBuf OrfHeader::write() const DataBuf OrfHeader::write() const
{ {
// Todo: Implement me! DataBuf buf(8);
return DataBuf(); switch (byteOrder()) {
case littleEndian:
buf.pData_[0] = 0x49;
buf.pData_[1] = 0x49;
break;
case bigEndian:
buf.pData_[0] = 0x4d;
buf.pData_[1] = 0x4d;
break;
case invalidByteOrder:
assert(false);
break;
}
us2Data(buf.pData_ + 2, sig_, byteOrder());
ul2Data(buf.pData_ + 4, 0x00000008, byteOrder());
return buf;
} }
}} // namespace Internal, Exiv2 }} // namespace Internal, Exiv2

@ -79,21 +79,7 @@ namespace Exiv2 {
//! @name Manipulators //! @name Manipulators
//@{ //@{
void readMetadata(); void readMetadata();
/*!
@brief Todo: Write metadata back to the image. This method is not
yet implemented. Calling it will throw an Error(31).
*/
void writeMetadata(); void writeMetadata();
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(32).
*/
void setExifData(const ExifData& exifData);
/*!
@brief Todo: Not supported yet, requires writeMetadata(). Calling
this function will throw an Error(32).
*/
void setIptcData(const IptcData& iptcData);
/*! /*!
@brief Not supported. ORF format does not contain a comment. @brief Not supported. ORF format does not contain a comment.
Calling this function will throw an Error(32). Calling this function will throw an Error(32).
@ -143,14 +129,14 @@ namespace Exiv2 {
See TiffParser::encode(). See TiffParser::encode().
*/ */
static WriteMethod encode( static WriteMethod encode(
Blob& blob, BasicIo& io,
const byte* pData, const byte* pData,
uint32_t size, uint32_t size,
ByteOrder byteOrder,
const ExifData& exifData, const ExifData& exifData,
const IptcData& iptcData, const IptcData& iptcData,
const XmpData& xmpData const XmpData& xmpData
); );
}; // class OrfParser }; // class OrfParser
// ***************************************************************************** // *****************************************************************************

@ -51,7 +51,7 @@ namespace Exiv2 {
//! @name Creators //! @name Creators
//@{ //@{
//! Default constructor //! Default constructor
OrfHeader(); OrfHeader(ByteOrder byteOrder =littleEndian);
//! Destructor. //! Destructor.
~OrfHeader(); ~OrfHeader();
//@} //@}
@ -65,6 +65,9 @@ namespace Exiv2 {
//@{ //@{
DataBuf write() const; DataBuf write() const;
//@} //@}
private:
// DATA
uint16_t sig_; //<! The actual magic number
}; // class OrfHeader }; // class OrfHeader
}} // namespace Internal, Exiv2 }} // namespace Internal, Exiv2

Loading…
Cancel
Save