libopenraw  0.3.7
recordentry.hpp
1 /* -*- Mode: C++; c-basic-offset:4; tab-width:4; indent-tabs-mode:nil; -*- */
2 /*
3  * libopenraw - ciff/recordentry.hpp
4  *
5  * Copyright (C) 2006-2020 Hubert Figuière
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 #pragma once
23 
24 #include <stdint.h>
25 #include <map>
26 
27 #include <boost/array.hpp>
28 #include <boost/variant.hpp>
29 
30 #include "trace.hpp"
31 
32 namespace OpenRaw {
33 namespace Internals {
34 
35 class CIFFContainer;
36 
37 namespace CIFF {
38 
39 class Heap;
40 class RecordEntry;
41 
43 enum {
44  STORAGELOC_MASK = 0xc000,
45  FORMAT_MASK = 0x3800,
46  TAGCODE_MASK = 0x3fff
48 };
49 
51 #define TAGCODE(x) ((x) & TAGCODE_MASK)
52 
54 typedef enum {
55  TYPE_BYTE = 0x0000,
56  TYPE_ASCII = 0x0800,
57  TYPE_WORD = 0x1000, // 16-bits?
58  TYPE_DWORD = 0x1800, // 32-bits?
59  TYPE_BYTE2 = 0x2000, // arbitrary structure
60  TYPE_HEAP1 = 0x2800,
61  TYPE_HEAP2 = 0x3000,
62 } CIFFType;
63 
65 typedef std::map<uint16_t, RecordEntry> RecordEntries;
66 
69 {
70 public:
71 
72  RecordEntry();
73 
78  bool readFrom(const CIFFContainer* container);
85  size_t fetchData(Heap* heap, void* buf, size_t size) const;
86 
88  bool isHeap() const
89  {
90  auto t = type();
91  return (t == TYPE_HEAP1 || t == TYPE_HEAP2);
92  }
94  CIFFType type() const
95  {
96  return (CIFFType)(typeCode & (uint16_t)FORMAT_MASK);
97  }
98 
100  Heap heap(Heap& h, const CIFFContainer* container) const;
102  uint32_t count() const;
104  uint16_t exifType() const;
106  uint32_t containerOffset(const Heap& heap) const;
107 
109  std::string getString(Heap& heap) const;
110 
112  typedef boost::array<uint8_t, 8> InRec;
114  struct InHeap
115  {
117  InHeap();
119  InHeap(uint32_t _length, uint32_t _offset);
121  uint32_t length;
123  uint32_t offset;
124  };
125 
127  bool inRecord() const
128  {
129  return (typeCode & STORAGELOC_MASK) != 0;
130  }
134  uint32_t length() const
135  {
136  if (!inRecord()) {
137  return boost::get<InHeap>(data).length;
138  }
139  LOGERR("length failed\n");
140  return 0;
141  }
145  uint32_t offset() const
146  {
147  if (!inRecord()) {
148  return boost::get<InHeap>(data).offset;
149  }
150  LOGERR("offset failed\n");
151  return 0;
152  }
153  uint16_t typeCode;
155  boost::variant<InRec, InHeap> data;
156 };
157 
158 }
159 }
160 }
A record entry from a CIFF Heap.
Definition: recordentry.hpp:69
boost::array< uint8_t, 8 > InRec
boost::variant< InRec, InHeap > data
uint32_t containerOffset(const Heap &heap) const
bool readFrom(const CIFFContainer *container)
Definition: recordentry.cpp:46
size_t fetchData(Heap *heap, void *buf, size_t size) const
Definition: recordentry.cpp:76
std::string getString(Heap &heap) const
Heap heap(Heap &h, const CIFFContainer *container) const
Definition: recordentry.cpp:82
std::map< uint16_t, RecordEntry > RecordEntries
Definition: recordentry.hpp:65
Global namespace for libopenraw.
Definition: arwfile.cpp:29