libopenraw
rafmetacontainer.cpp
1 /* -*- tab-width:4; c-basic-offset:4 -*- */
2 /*
3  * libopenraw - rafcontainer.cpp
4  *
5  * Copyright (C) 2011-2016 Hubert Figuiere
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <stdlib.h>
23 
24 #include <cstdint>
25 #include <string>
26 #include <utility>
27 
28 #include "metavalue.hpp"
29 #include "rafmetacontainer.hpp"
30 #include "io/stream.hpp"
31 
32 namespace OpenRaw {
33 namespace Internals {
34 
35 RafMetaValue::RafMetaValue(uint16_t tag, uint16_t size, const MetaValue & v)
36  : m_tag(tag)
37  , m_size(size)
38  , m_value(v)
39 {
40 }
41 
42 RafMetaValue::~RafMetaValue()
43 {
44 }
45 
46 RafMetaContainer::RafMetaContainer(const IO::Stream::Ptr &_file)
47  : RawContainer(_file, 0)
48  , m_count(0)
49 {
50  setEndian(ENDIAN_BIG);
51 }
52 
53 uint32_t RafMetaContainer::count()
54 {
55  if(m_count == 0) {
56  _read();
57  }
58  return m_count;
59 }
60 
61 RafMetaValue::Ref RafMetaContainer::getValue(uint16_t tag)
62 {
63  if(m_tags.empty()) {
64  _read();
65  }
66  std::map<uint16_t, RafMetaValue::Ref>::const_iterator iter = m_tags.find(tag);
67  if(iter != m_tags.end()) {
68  return iter->second;
69  }
70  return RafMetaValue::Ref();
71 }
72 
73 void RafMetaContainer::_read()
74 {
75  readUInt32(m_file, m_count);
76  for(uint32_t i = 0; i < m_count; i++) {
77  uint16_t tag;
78  uint16_t size;
79  readUInt16(m_file, tag);
80  readUInt16(m_file, size);
81  MetaValue::value_t v;
82  if(size == 4) {
83  uint32_t intVal;
84  if(readUInt32(m_file, intVal)) {
85  v = MetaValue::value_t(intVal);
86  }
87  }
88  else {
89  char *content;
90  content = (char*)calloc(1, size + 1);
91  content[size] = 0;
92  m_file->read(content, size);
93  v = MetaValue::value_t(std::string(content));
94  free(content);
95  }
96 
97  RafMetaValue::Ref value(new RafMetaValue(tag, size, MetaValue(v)));
98  m_tags.insert(std::make_pair(tag, value));
99 
100 // printf("RAF: tag %x of size %u\n", tag, size);
101  }
102 }
103 
104 }
105 }
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30