23 #include <boost/shared_ptr.hpp>
25 #include <libopenraw/types.h>
28 #include "ciffcontainer.h"
31 using namespace Debug;
43 file->
seek(offset, SEEK_SET);
45 ret = container->
readUInt32(file, imageHeight);
46 ret = container->
readUInt32(file, pixelAspectRatio);
47 ret = container->
readInt32(file, rotationAngle);
48 ret = container->
readUInt32(file, componentBitDepth);
49 ret = container->
readUInt32(file, colorBitDepth);
54 int32_t ImageSpec::exifOrientation()
const
56 int32_t orientation = 0;
57 switch(rotationAngle) {
74 RecordEntry::RecordEntry()
75 : typeCode(0), length(0), offset(0)
92 offset + heap->
offset(), size);
99 m_container(_container),
102 Debug::Trace(DEBUG2) <<
"Heap @ " << start <<
" length = "
106 std::vector<RecordEntry> & Heap::records()
108 if (m_records.size() == 0) {
115 bool Heap::_loadRecords()
118 file->
seek(m_start + m_length - 4, SEEK_SET);
119 int32_t record_offset;
120 bool ret = m_container->
readInt32(file, record_offset);
126 file->
seek(m_start + record_offset, SEEK_SET);
127 ret = m_container->
readInt16(file, numRecords);
130 Trace(DEBUG1) <<
"read failed: " << ret <<
"\n";
132 Trace(DEBUG2) <<
"numRecords " << numRecords <<
"\n";
134 m_records.reserve(numRecords);
135 for (i = 0; i < numRecords; i++) {
136 m_records.push_back(RecordEntry());
137 m_records.back().readFrom(m_container);
147 RecordEntry tblArray[1];
152 bool HeapFileHeader::readFrom(CIFFContainer *container)
154 endian = RawContainer::ENDIAN_NULL;
156 IO::Stream *file = container->file();
157 int s = file->
read(byteOrder, 2);
159 if((byteOrder[0] ==
'I') && (byteOrder[1] ==
'I')) {
162 else if((byteOrder[0] ==
'M') && (byteOrder[1] ==
'M')) {
165 container->setEndian(endian);
166 ret = container->readUInt32(file, headerLength);
168 ret = (file->read(type, 4) == 4);
171 ret = (file->read(subType, 4) == 4);
174 ret = container->readUInt32(file, version);
181 CIFFContainer::CIFFContainer(IO::Stream *_file)
182 : RawContainer(_file, 0),
184 m_heap((CIFF::Heap*)NULL),
185 m_hasImageSpec(false)
187 m_endian = _readHeader();
190 CIFFContainer::~CIFFContainer()
194 CIFF::Heap::Ref CIFFContainer::heap()
196 if (m_heap == NULL) {
202 bool CIFFContainer::_loadHeap()
205 if (m_heap == NULL) {
206 if(m_endian != ENDIAN_NULL) {
207 off_t heapLength = m_file->filesize() - m_hdr.headerLength;
209 Trace(DEBUG1) <<
"heap len " << heapLength <<
"\n";
210 m_heap = CIFF::Heap::Ref(
new CIFF::Heap(m_hdr.headerLength,
216 Trace(DEBUG1) <<
"Unknown endian\n";
225 EndianType _endian = ENDIAN_NULL;
226 m_hdr.readFrom(
this);
227 if ((::strncmp(m_hdr.type,
"HEAP", 4) == 0)
228 && (::strncmp(m_hdr.subType,
"CCDR", 4) == 0)) {
229 _endian = m_hdr.endian;
234 CIFF::Heap::Ref CIFFContainer::getImageProps()
238 return CIFF::Heap::Ref();
241 const CIFF::RecordEntry::List & records = m_heap->records();
242 CIFF::RecordEntry::List::const_iterator iter;
245 iter = std::find_if(records.begin(), records.end(), boost::bind(
247 static_cast<uint16_t>(CIFF::TAG_IMAGEPROPS)));
248 if (iter == records.end()) {
249 Trace(ERROR) <<
"Couldn't find the image properties.\n";
250 return CIFF::Heap::Ref();
253 m_imageprops = CIFF::Heap::Ref(
new CIFF::Heap(iter->offset + m_heap->offset(), iter->length,
this));
258 const CIFF::ImageSpec * CIFFContainer::getImageSpec()
260 if(!m_hasImageSpec) {
261 CIFF::Heap::Ref props = getImageProps();
265 const CIFF::RecordEntry::List & propsRecs = props->records();
266 CIFF::RecordEntry::List::const_iterator iter;
267 iter = std::find_if(propsRecs.begin(), propsRecs.end(),
270 static_cast<uint16_t>(CIFF::TAG_IMAGEINFO)));
271 if (iter == propsRecs.end()) {
272 Trace(ERROR) <<
"Couldn't find the image info.\n";
275 m_imagespec.readFrom(iter->offset + props->offset(),
this);
276 m_hasImageSpec =
true;
282 const CIFF::Heap::Ref CIFFContainer::getCameraProps()
285 CIFF::Heap::Ref props = getImageProps();
288 return CIFF::Heap::Ref();
289 const CIFF::RecordEntry::List & propsRecs = props->records();
290 CIFF::RecordEntry::List::const_iterator iter;
291 iter = std::find_if(propsRecs.begin(), propsRecs.end(),
294 static_cast<uint16_t>(CIFF::TAG_CAMERAOBJECT)));
295 if (iter == propsRecs.end()) {
296 Trace(ERROR) <<
"Couldn't find the camera props.\n";
297 return CIFF::Heap::Ref();
299 m_cameraprops = CIFF::Heap::Ref(
new CIFF::Heap(iter->offset + props->offset(),
300 iter->length,
this));
302 return m_cameraprops;
305 const CIFF::RecordEntry * CIFFContainer::getRawDataRecord()
const
310 const CIFF::RecordEntry::List & records = m_heap->records();
311 CIFF::RecordEntry::List::const_iterator iter;
313 iter = std::find_if(records.begin(), records.end(), boost::bind(
315 static_cast<uint16_t>(CIFF::TAG_RAWIMAGEDATA)));
317 if (iter != records.end()) {