RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
TiffEntry.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2009-2014 Klaus Post
5 Copyright (C) 2015 Pedro CĂ´rte-Real
6 Copyright (C) 2017 Axel Waggershauser
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
23#pragma once
24
25#include "rawspeedconfig.h"
26#include "adt/NotARational.h"
27#include "io/ByteStream.h"
28#include "tiff/TiffTag.h"
29#include <array>
30#include <cstdint>
31#include <string>
32#include <vector>
33
34namespace rawspeed {
35
36class DataBuffer;
37class TiffIFD;
38class Buffer;
39
40/*
41 * Tag data type information.
42 *
43 * Note: RATIONALs are the ratio of two 32-bit integer values.
44 */
45enum class TiffDataType : uint8_t {
46 NOTYPE = 0, /* placeholder */
47 BYTE = 1, /* 8-bit unsigned integer */
48 ASCII = 2, /* 8-bit bytes w/ last byte null */
49 SHORT = 3, /* 16-bit unsigned integer */
50 LONG = 4, /* 32-bit unsigned integer */
51 RATIONAL = 5, /* 2x32-bit unsigned fraction */
52 SBYTE = 6, /* !8-bit signed integer */
53 UNDEFINED = 7, /* !8-bit untyped data */
54 SSHORT = 8, /* !16-bit signed integer */
55 SLONG = 9, /* !32-bit signed integer */
56 SRATIONAL = 10, /* !2x32-bit signed fraction */
57 FLOAT = 11, /* !32-bit IEEE floating point */
58 DOUBLE = 12, /* !64-bit IEEE floating point */
59 OFFSET = 13, /* 32-bit unsigned offset used for IFD and other offsets */
60};
61
62class TiffEntry {
65
66 virtual void anchor() const;
67
68 friend class TiffIFD;
69
70 template <typename T, T (TiffEntry::*getter)(uint32_t index) const>
71 [[nodiscard]] std::vector<T> getArray(uint32_t count_) const {
72 std::vector<T> res(count_);
73 for (uint32_t i = 0; i < count_; ++i)
74 res[i] = (this->*getter)(i);
75 return res;
76 }
77
78protected:
79 void setData(ByteStream data_);
80
81public:
85
89
90 virtual ~TiffEntry() = default;
91
92 [[nodiscard]] bool RAWSPEED_READONLY isFloat() const;
93 [[nodiscard]] bool RAWSPEED_READONLY isRational() const;
94 [[nodiscard]] bool RAWSPEED_READONLY isSRational() const;
95 [[nodiscard]] bool RAWSPEED_READONLY isInt() const;
96 [[nodiscard]] bool RAWSPEED_READONLY isString() const;
97 [[nodiscard]] uint8_t getByte(uint32_t index = 0) const;
98 [[nodiscard]] uint32_t getU32(uint32_t index = 0) const;
99 [[nodiscard]] int32_t getI32(uint32_t index = 0) const;
100 [[nodiscard]] uint16_t getU16(uint32_t index = 0) const;
101 [[nodiscard]] int16_t getI16(uint32_t index = 0) const;
102 [[nodiscard]] NotARational<uint32_t> getRational(uint32_t index = 0) const;
103 [[nodiscard]] NotARational<int32_t> getSRational(uint32_t index = 0) const;
104 [[nodiscard]] float getFloat(uint32_t index = 0) const;
105 [[nodiscard]] std::string getString() const;
106
107 [[nodiscard]] std::vector<uint16_t> getU16Array(uint32_t count_) const {
109 }
110
111 [[nodiscard]] std::vector<uint32_t> getU32Array(uint32_t count_) const {
113 }
114
115 [[nodiscard]] std::vector<float> getFloatArray(uint32_t count_) const {
117 }
118
119 [[nodiscard]] std::vector<NotARational<uint32_t>>
123
124 [[nodiscard]] std::vector<NotARational<int32_t>>
128
129 [[nodiscard]] ByteStream getData() const { return data; }
130
131 [[nodiscard]] DataBuffer getRootIfdData() const;
132
133protected:
134 static const std::array<uint32_t, 14> datashifts;
135};
136
137class TiffEntryWithData final : public TiffEntry {
138 const std::vector<uint8_t> data;
139
140 void anchor() const override;
141
142public:
144 uint32_t count, Buffer mirror);
145};
146
147} // namespace rawspeed
DataBuffer getRootIfdData() const
std::vector< uint32_t > getU32Array(uint32_t count_) const
Definition TiffEntry.h:111
std::vector< NotARational< int32_t > > getSRationalArray(uint32_t count_) const
Definition TiffEntry.h:125
TiffTag tag
Definition TiffEntry.h:82
int16_t getI16(uint32_t index=0) const
bool RAWSPEED_READONLY isSRational() const
NotARational< uint32_t > getRational(uint32_t index=0) const
std::vector< uint16_t > getU16Array(uint32_t count_) const
Definition TiffEntry.h:107
float getFloat(uint32_t index=0) const
uint32_t getU32(uint32_t index=0) const
bool RAWSPEED_READONLY isInt() const
std::vector< NotARational< uint32_t > > getRationalArray(uint32_t count_) const
Definition TiffEntry.h:120
bool RAWSPEED_READONLY isString() const
ByteStream getData() const
Definition TiffEntry.h:129
std::string getString() const
bool RAWSPEED_READONLY isFloat() const
uint32_t count
Definition TiffEntry.h:84
NotARational< int32_t > getSRational(uint32_t index=0) const
std::vector< T > getArray(uint32_t count_) const
Definition TiffEntry.h:71
ByteStream data
Definition TiffEntry.h:64
TiffIFD * parent
Definition TiffEntry.h:63
uint16_t getU16(uint32_t index=0) const
TiffDataType type
Definition TiffEntry.h:83
uint8_t getByte(uint32_t index=0) const
TiffEntry(TiffIFD *parent, TiffTag tag, TiffDataType type, uint32_t count, ByteStream data)
static const std::array< uint32_t, 14 > datashifts
Definition TiffEntry.h:134
void setData(ByteStream data_)
bool RAWSPEED_READONLY isRational() const
int32_t getI32(uint32_t index=0) const
virtual void anchor() const
Definition TiffEntry.cpp:47
friend class TiffIFD
Definition TiffEntry.h:68
std::vector< float > getFloatArray(uint32_t count_) const
Definition TiffEntry.h:115
virtual ~TiffEntry()=default
const std::vector< uint8_t > data
Definition TiffEntry.h:138
void anchor() const override
Definition TiffEntry.cpp:52
TiffEntryWithData(TiffIFD *parent, TiffTag tag, TiffDataType type, uint32_t count, Buffer mirror)