diff options
author | Hubert Figuiere <hub@figuiere.net> | 2008-05-13 22:40:05 -0400 |
---|---|---|
committer | Hubert Figuiere <hub@figuiere.net> | 2008-05-13 22:40:05 -0400 |
commit | 4a22051cabcb353dfce5b894e72b847303155a2b (patch) | |
tree | 0cfacf082e6d63f51fa83fcf5124cc7d981c956a | |
parent | 137119e758dd93af52dad5d0267cae54bd1dfa0c (diff) |
* lib/crwfile.{cpp,h}, include/libopenraw/consts.h,
lib/ciffcontainer.{cpp,h}, testsuite/testsuite.xml:
support type id for CRW.
* lib/metavalue.{cpp,h}: support string properties.
* lib/arwfile.cpp, lib/cr2file.cpp, lib/dngfile.cpp,
lib/erffile.cpp, lib/ifdfile.{cpp,h}, lib/mrwfile.cpp,
lib/neffile.cpp, lib/orffile.cpp, lib/peffile.cpp,
lib/rawfile.cpp, include/libopenraw++/rawfile.h:
refactor the camera ids one more.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | README | 16 | ||||
-rw-r--r-- | include/libopenraw++/rawfile.h | 9 | ||||
-rw-r--r-- | include/libopenraw/consts.h | 3 | ||||
-rw-r--r-- | lib/arwfile.cpp | 4 | ||||
-rw-r--r-- | lib/ciffcontainer.cpp | 26 | ||||
-rw-r--r-- | lib/ciffcontainer.h | 5 | ||||
-rw-r--r-- | lib/cr2file.cpp | 4 | ||||
-rw-r--r-- | lib/crwfile.cpp | 101 | ||||
-rw-r--r-- | lib/crwfile.h | 4 | ||||
-rw-r--r-- | lib/dngfile.cpp | 2 | ||||
-rw-r--r-- | lib/erffile.cpp | 2 | ||||
-rw-r--r-- | lib/ifdfile.cpp | 19 | ||||
-rw-r--r-- | lib/ifdfile.h | 7 | ||||
-rw-r--r-- | lib/metavalue.cpp | 20 | ||||
-rw-r--r-- | lib/metavalue.h | 6 | ||||
-rw-r--r-- | lib/mrwfile.cpp | 2 | ||||
-rw-r--r-- | lib/neffile.cpp | 2 | ||||
-rw-r--r-- | lib/orffile.cpp | 2 | ||||
-rw-r--r-- | lib/peffile.cpp | 2 | ||||
-rw-r--r-- | lib/rawfile.cpp | 24 | ||||
-rw-r--r-- | testsuite/testsuite.xml | 2 |
22 files changed, 217 insertions, 57 deletions
@@ -1,3 +1,15 @@ +2008-05-13 Hubert Figuiere <hub@figuiere.net> + + * lib/crwfile.{cpp,h}, include/libopenraw/consts.h, + lib/ciffcontainer.{cpp,h}, testsuite/testsuite.xml: + support type id for CRW. + * lib/metavalue.{cpp,h}: support string properties. + * lib/arwfile.cpp, lib/cr2file.cpp, lib/dngfile.cpp, + lib/erffile.cpp, lib/ifdfile.{cpp,h}, lib/mrwfile.cpp, + lib/neffile.cpp, lib/orffile.cpp, lib/peffile.cpp, + lib/rawfile.cpp, include/libopenraw++/rawfile.h: + refactor the camera ids one more. + 2008-05-11 Hubert Figuiere <hub@figuiere.net> * lib/arwfile.{cpp,h}, include/libopenraw/consts.h, @@ -79,14 +79,14 @@ Canon CR2 Y Y Y Y Y Y 5D T T T T 1DMarkII T T T T -Canon CRW Y Y Y Y Y N - 300D T T T T T - 10D T T T T - D60 T T T T - G1 T T T T - G2 T T T T - G5 T T T T - Pro1 T T T T +Canon CRW Y Y Y Y Y Y + 300D T T T T T T + 10D T T T T T + D60 T T T T T + G1 T T T T T + G2 T T T T T + G5 T T T T T + Pro1 T T T T T Canon CRW CHDK N N N N N N (unofficial firmware) diff --git a/include/libopenraw++/rawfile.h b/include/libopenraw++/rawfile.h index cfa94d6..b137453 100644 --- a/include/libopenraw++/rawfile.h +++ b/include/libopenraw++/rawfile.h @@ -97,6 +97,10 @@ namespace OpenRaw { const MetaValue *getMetaValue(int32_t meta_index); protected: + struct camera_ids_t { + const char * model; + const uint32_t type_id; + }; /** * Construct a raw file * @param s the stream to load from. Take ownership. @@ -131,8 +135,9 @@ namespace OpenRaw { virtual MetaValue *_getMetaValue(int32_t /*meta_index*/) = 0; - virtual void _identifyId() {} // = 0; - + TypeId _typeIdFromModel(const std::string & model); + void _setIdMap(const camera_ids_t *map); + virtual void _identifyId() = 0; private: static Type identify(const char*_filename); static Type identifyBuffer(const uint8_t* buff, size_t len); diff --git a/include/libopenraw/consts.h b/include/libopenraw/consts.h index 167fdc6..006a8e0 100644 --- a/include/libopenraw/consts.h +++ b/include/libopenraw/consts.h @@ -155,7 +155,10 @@ extern "C" { OR_TYPEID_CANON_PRO1, OR_TYPEID_CANON_G1, OR_TYPEID_CANON_G2, + OR_TYPEID_CANON_G3, OR_TYPEID_CANON_G5, + OR_TYPEID_CANON_G6, + OR_TYPEID_CANON_G7, OR_TYPEID_CANON_G9, OR_TYPEID_CANON_A610, OR_TYPEID_CANON_20DA diff --git a/lib/arwfile.cpp b/lib/arwfile.cpp index 7bf1c0e..9f373c6 100644 --- a/lib/arwfile.cpp +++ b/lib/arwfile.cpp @@ -1,7 +1,7 @@ /* * libopenraw - arwfile.cpp * - * Copyright (C) 2006 Hubert Figuiere + * Copyright (C) 2006,2008 Hubert Figuiere * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -54,7 +54,7 @@ namespace OpenRaw { ARWFile::ARWFile(IO::Stream *s) : IFDFile(s, OR_RAWFILE_TYPE_ARW) { - m_cam_ids = s_def; + _setIdMap(s_def); } ARWFile::~ARWFile() diff --git a/lib/ciffcontainer.cpp b/lib/ciffcontainer.cpp index 0bc22fe..410c4bb 100644 --- a/lib/ciffcontainer.cpp +++ b/lib/ciffcontainer.cpp @@ -260,6 +260,8 @@ namespace OpenRaw { if(!m_hasImageSpec) { CIFF::Heap::Ref props = getImageProps(); + if(!props) + return NULL; const CIFF::RecordEntry::List & propsRecs = props->records(); CIFF::RecordEntry::List::const_iterator iter; iter = std::find_if(propsRecs.begin(), propsRecs.end(), @@ -271,11 +273,35 @@ namespace OpenRaw { return NULL; } m_imagespec.readFrom(iter->offset + props->offset(), this); + m_hasImageSpec = true; } return &m_imagespec; } + const CIFF::Heap::Ref CIFFContainer::getCameraProps() + { + if(!m_cameraprops) { + CIFF::Heap::Ref props = getImageProps(); + + if(!props) + return CIFF::Heap::Ref(); + const CIFF::RecordEntry::List & propsRecs = props->records(); + CIFF::RecordEntry::List::const_iterator iter; + iter = std::find_if(propsRecs.begin(), propsRecs.end(), + boost::bind( + &CIFF::RecordEntry::isA, _1, + static_cast<uint16_t>(CIFF::TAG_CAMERAOBJECT))); + if (iter == propsRecs.end()) { + Trace(ERROR) << "Couldn't find the camera props.\n"; + return CIFF::Heap::Ref(); + } + m_cameraprops = CIFF::Heap::Ref(new CIFF::Heap(iter->offset + props->offset(), + iter->length, this)); + } + return m_cameraprops; + } + const CIFF::RecordEntry * CIFFContainer::getRawDataRecord() const { if(!m_heap) { diff --git a/lib/ciffcontainer.h b/lib/ciffcontainer.h index ea43b9b..9312342 100644 --- a/lib/ciffcontainer.h +++ b/lib/ciffcontainer.h @@ -1,7 +1,7 @@ /* * libopenraw - ciffcontainer.h * - * Copyright (C) 2006 Hubert Figuiere + * Copyright (C) 2006,2008 Hubert Figuiere * * This library is free software: you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -137,6 +137,7 @@ namespace OpenRaw { uint32_t colorBW; }; + class RecordEntry { public: @@ -242,6 +243,7 @@ namespace OpenRaw { CIFF::Heap::Ref getImageProps(); const CIFF::RecordEntry * getRawDataRecord() const; const CIFF::ImageSpec * getImageSpec(); + const CIFF::Heap::Ref getCameraProps(); private: bool _loadHeap(); EndianType _readHeader(); @@ -256,6 +258,7 @@ namespace OpenRaw { CIFF::Heap::Ref m_imageprops; bool m_hasImageSpec; CIFF::ImageSpec m_imagespec; + CIFF::Heap::Ref m_cameraprops; }; diff --git a/lib/cr2file.cpp b/lib/cr2file.cpp index f43eaf9..7123ef8 100644 --- a/lib/cr2file.cpp +++ b/lib/cr2file.cpp @@ -49,8 +49,6 @@ namespace OpenRaw { OR_TYPEID_CANON_1DSMKII) }, { "Canon EOS-1Ds Mark III", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, OR_TYPEID_CANON_1DSMKIII) }, - { "Canon EOS 20D", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, - OR_TYPEID_CANON_20D) }, { "Canon EOS 20D" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, OR_TYPEID_CANON_20D) }, { "Canon EOS 20Da", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, @@ -80,7 +78,7 @@ namespace OpenRaw { Cr2File::Cr2File(IO::Stream * s) : IFDFile(s, OR_RAWFILE_TYPE_CR2) { - m_cam_ids = s_def; + _setIdMap(s_def); } Cr2File::~Cr2File() diff --git a/lib/crwfile.cpp b/lib/crwfile.cpp index 3edd7b1..e7dcfd7 100644 --- a/lib/crwfile.cpp +++ b/lib/crwfile.cpp @@ -20,6 +20,7 @@ */ #include <algorithm> +#include <utility> #include <boost/bind.hpp> #include <boost/scoped_ptr.hpp> @@ -48,6 +49,32 @@ namespace OpenRaw { using namespace CIFF; + const RawFile::camera_ids_t CRWFile::s_def[] = { + { "Canon EOS D30" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_D30) }, + { "Canon EOS D60" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_D60) }, + { "Canon EOS 10D" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_10D) }, + { "Canon EOS 300D DIGITAL", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_300D) }, + { "Canon PowerShot G1", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G1) }, + { "Canon PowerShot G2", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G2) }, + { "Canon PowerShot G3", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G3) }, + { "Canon PowerShot G5", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G5) }, + { "Canon PowerShot G6", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G6) }, + { "Canon PowerShot G7", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_G7) }, + { "Canon PowerShot Pro1", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_CANON, + OR_TYPEID_CANON_PRO1) }, + { 0, 0 } + }; + RawFile *CRWFile::factory(IO::Stream *s) { return new CRWFile(s); @@ -59,7 +86,7 @@ namespace OpenRaw { m_container(new CIFFContainer(m_io)), m_x(0), m_y(0) { - + _setIdMap(s_def); } CRWFile::~CRWFile() @@ -135,6 +162,9 @@ namespace OpenRaw { ::or_error err = OR_ERROR_NOT_FOUND; Heap::Ref props = m_container->getImageProps(); + if(!props) { + return OR_ERROR_NOT_FOUND; + } const ImageSpec * img_spec = m_container->getImageSpec(); uint32_t x, y; x = y = 0; @@ -242,11 +272,53 @@ namespace OpenRaw { switch(META_INDEX_MASKOUT(meta_index)) { case META_NS_TIFF: { - const ImageSpec * img_spec = m_container->getImageSpec(); - if(img_spec) { - val = new MetaValue(boost::any( - static_cast<int32_t>( - img_spec->exifOrientation()))); + switch(META_NS_MASKOUT(meta_index)) { + case EXIF_TAG_ORIENTATION: + { + const ImageSpec * img_spec = m_container->getImageSpec(); + if(img_spec) { + val = new MetaValue(boost::any( + static_cast<int32_t>( + img_spec->exifOrientation()))); + } + break; + } + case EXIF_TAG_MODEL: + { + CIFF::Heap::Ref heap = m_container->getCameraProps(); + if(heap) { + const CIFF::RecordEntry::List & propsRecs = heap->records(); + CIFF::RecordEntry::List::const_iterator iter; + iter = std::find_if(propsRecs.begin(), propsRecs.end(), + boost::bind( + &CIFF::RecordEntry::isA, _1, + static_cast<uint16_t>(CIFF::TAG_RAWMAKEMODEL))); + if (iter == propsRecs.end()) { + Trace(ERROR) << "Couldn't find the image info.\n"; + } + else { + char buf[256]; + size_t sz = iter->length; + if(sz > 256) { + sz = 256; + } + size_t sz2; + std::string model; + sz2 = iter->fetchData(heap.get(), (void*)buf, sz); + char *p = buf; + while(*p) { + p++; + } + p++; + model = p; + val = new MetaValue(boost::any(model)); + Trace(DEBUG1) << "Model " << model << "\n"; + } + } + + + break; + } } break; } @@ -259,5 +331,22 @@ namespace OpenRaw { return val; } + + void CRWFile::_identifyId() + { + MetaValue * v = _getMetaValue(META_NS_TIFF | EXIF_TAG_MODEL); + if(v) { + std::string model; + try { + model = v->getString(); + _setTypeId(_typeIdFromModel(model)); + } + catch(...) + { + } + delete v; + } + } + } } diff --git a/lib/crwfile.h b/lib/crwfile.h index 5629a09..0457971 100644 --- a/lib/crwfile.h +++ b/lib/crwfile.h @@ -56,6 +56,8 @@ namespace OpenRaw { virtual ::or_error _getRawData(RawData & data, uint32_t options); virtual MetaValue *_getMetaValue(int32_t meta_index); + + virtual void _identifyId(); private: CRWFile(const CRWFile&); CRWFile & operator=(const CRWFile&); @@ -64,6 +66,8 @@ namespace OpenRaw { CIFFContainer *m_container; /**< the real container */ uint32_t m_x; uint32_t m_y; + + static const RawFile::camera_ids_t s_def[]; }; } diff --git a/lib/dngfile.cpp b/lib/dngfile.cpp index 90693f0..ed4bbd6 100644 --- a/lib/dngfile.cpp +++ b/lib/dngfile.cpp @@ -67,7 +67,7 @@ namespace OpenRaw { DNGFile::DNGFile(IO::Stream *s) : TiffEpFile(s, OR_RAWFILE_TYPE_DNG) { - m_cam_ids = s_def; + _setIdMap(s_def); } DNGFile::~DNGFile() diff --git a/lib/erffile.cpp b/lib/erffile.cpp index c13b218..ab5eab1 100644 --- a/lib/erffile.cpp +++ b/lib/erffile.cpp @@ -53,7 +53,7 @@ namespace OpenRaw { ERFFile::ERFFile(IO::Stream *s) : TiffEpFile(s, OR_RAWFILE_TYPE_ERF) { - m_cam_ids = s_def; + _setIdMap(s_def); } diff --git a/lib/ifdfile.cpp b/lib/ifdfile.cpp index 550e3ac..7cdf81a 100644 --- a/lib/ifdfile.cpp +++ b/lib/ifdfile.cpp @@ -52,8 +52,7 @@ namespace OpenRaw { : RawFile(s, _type), m_thumbLocations(), m_io(s), - m_container(NULL), - m_cam_ids(NULL) + m_container(NULL) { if(instantiateContainer) { m_container = new IFDFileContainer(m_io, 0); @@ -80,22 +79,6 @@ namespace OpenRaw { } - RawFile::TypeId IFDFile::_typeIdFromModel(const std::string & model) - { - const struct camera_ids_t * p = m_cam_ids; - if(!p) { - return 0; - } - while(p->model) { - if(model == p->model) { - break; - } - p++; - } - return p->type_id; - } - - void IFDFile::_identifyId() { if(!m_mainIfd) { diff --git a/lib/ifdfile.h b/lib/ifdfile.h index 81409f5..98df4aa 100644 --- a/lib/ifdfile.h +++ b/lib/ifdfile.h @@ -64,11 +64,6 @@ namespace OpenRaw { { protected: - struct camera_ids_t { - const char * model; - const uint32_t type_id; - }; - IFDFile(IO::Stream * s, Type _type, bool instantiateContainer = true); virtual ~IFDFile(); @@ -103,7 +98,6 @@ namespace OpenRaw { virtual IFDDir::Ref _locateMainIfd() = 0; virtual IFDDir::Ref _locateExifIfd(); - TypeId _typeIdFromModel(const std::string & model); virtual void _identifyId(); virtual MetaValue *_getMetaValue(int32_t meta_index); @@ -114,7 +108,6 @@ namespace OpenRaw { * the CFA */ IFDDir::Ref m_exifIfd; /**< the Exif IFD */ - const camera_ids_t *m_cam_ids; private: IFDFile(const IFDFile&); diff --git a/lib/metavalue.cpp b/lib/metavalue.cpp index 8818d58..3db9f9d 100644 --- a/lib/metavalue.cpp +++ b/lib/metavalue.cpp @@ -35,12 +35,13 @@ namespace OpenRaw { } - int32_t MetaValue::getInteger() const + template<typename T> + inline T MetaValue::get() const throw(Internals::BadTypeException) { - int32_t v = 0; + T v; try { - v = boost::any_cast<int32_t>(m_value); + v = boost::any_cast<T>(m_value); } catch(const boost::bad_any_cast &) { throw Internals::BadTypeException(); @@ -48,4 +49,17 @@ namespace OpenRaw { return v; } + + int32_t MetaValue::getInteger() const + throw(Internals::BadTypeException) + { + return get<int32_t>(); + } + + std::string MetaValue::getString() const + throw(Internals::BadTypeException) + { + return get<std::string>(); + } + } diff --git a/lib/metavalue.h b/lib/metavalue.h index c2cbc9d..24edc0b 100644 --- a/lib/metavalue.h +++ b/lib/metavalue.h @@ -34,7 +34,13 @@ namespace OpenRaw { MetaValue(const boost::any &v); int32_t getInteger() const throw(Internals::BadTypeException); + std::string getString() const + throw(Internals::BadTypeException); + private: + template<typename T> T get() const + throw(Internals::BadTypeException); + boost::any m_value; }; diff --git a/lib/mrwfile.cpp b/lib/mrwfile.cpp index e62b4f6..e1d75bf 100644 --- a/lib/mrwfile.cpp +++ b/lib/mrwfile.cpp @@ -71,7 +71,7 @@ namespace OpenRaw { MRWFile::MRWFile(IO::Stream* _f) : IFDFile(_f, OR_RAWFILE_TYPE_MRW, false) { - m_cam_ids = s_def; + _setIdMap(s_def); m_container = new MRWContainer (m_io, 0); } diff --git a/lib/neffile.cpp b/lib/neffile.cpp index dc7adcd..dc7b84f 100644 --- a/lib/neffile.cpp +++ b/lib/neffile.cpp @@ -78,7 +78,7 @@ namespace OpenRaw { NEFFile::NEFFile(IO::Stream* _filename) : TiffEpFile(_filename, OR_RAWFILE_TYPE_NEF) { - m_cam_ids = s_def; + _setIdMap(s_def); } diff --git a/lib/orffile.cpp b/lib/orffile.cpp index 02d83a1..c9f0181 100644 --- a/lib/orffile.cpp +++ b/lib/orffile.cpp @@ -67,7 +67,7 @@ namespace OpenRaw { ORFFile::ORFFile(IO::Stream *s) : IFDFile(s, OR_RAWFILE_TYPE_ORF, false) { - m_cam_ids = s_def; + _setIdMap(s_def); m_container = new ORFContainer(m_io, 0); } diff --git a/lib/peffile.cpp b/lib/peffile.cpp index 9409187..d8849fb 100644 --- a/lib/peffile.cpp +++ b/lib/peffile.cpp @@ -60,7 +60,7 @@ namespace OpenRaw { PEFFile::PEFFile(IO::Stream *s) : IFDFile(s, OR_RAWFILE_TYPE_PEF) { - m_cam_ids = s_def; + _setIdMap(s_def); } diff --git a/lib/rawfile.cpp b/lib/rawfile.cpp index 3bd6da3..f181f1a 100644 --- a/lib/rawfile.cpp +++ b/lib/rawfile.cpp @@ -94,7 +94,8 @@ namespace OpenRaw { Private(Type t) : m_type(t), m_type_id(OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_NONE, OR_TYPEID_UNKNOWN)), - m_sizes() + m_sizes(), + m_cam_ids(NULL) { } ~Private() @@ -115,6 +116,7 @@ namespace OpenRaw { /** list of thumbnail sizes */ std::vector<uint32_t> m_sizes; std::map<int32_t, MetaValue*> m_metadata; + const camera_ids_t *m_cam_ids; }; @@ -358,6 +360,26 @@ namespace OpenRaw { return val; } + + RawFile::TypeId RawFile::_typeIdFromModel(const std::string & model) + { + const struct camera_ids_t * p = d->m_cam_ids; + if(!p) { + return 0; + } + while(p->model) { + if(model == p->model) { + break; + } + p++; + } + return p->type_id; + } + + void RawFile::_setIdMap(const camera_ids_t *map) + { + d->m_cam_ids = map; + } } diff --git a/testsuite/testsuite.xml b/testsuite/testsuite.xml index 1e9d714..30b6c65 100644 --- a/testsuite/testsuite.xml +++ b/testsuite/testsuite.xml @@ -37,6 +37,7 @@ <source>http://launchpadlibrarian.net/4704665/CRW_1852.CRW</source> <results> <rawType>CRW</rawType> + <rawTypeId>65550</rawTypeId> <thumbNum>1</thumbNum> <thumbSizes>2048</thumbSizes> <thumbFormats>JPEG</thumbFormats> @@ -55,6 +56,7 @@ <source>http://digikam3rdparty.free.fr/TEST_IMAGES/RAW/HORIZONTAL/CANON-EOS10.CRW</source> <results> <rawType>CRW</rawType> + <rawTypeId>65553</rawTypeId> <thumbNum>1</thumbNum> <thumbSizes>1536</thumbSizes> <thumbFormats>JPEG</thumbFormats> |