RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
CiffIFD.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) 2014 Pedro CĂ´rte-Real
6 Copyright (C) 2018 Roman Lebedev
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/NORangesSet.h"
27#include "tiff/CiffEntry.h"
28#include "tiff/CiffTag.h"
29#include <cstdint>
30#include <map>
31#include <memory>
32#include <string>
33#include <vector>
34
35namespace rawspeed {
36
37class Buffer;
38class ByteStream;
39class CiffEntry;
40template <typename T> class NORangesSet;
41
42class CiffIFD final {
44
45 std::vector<std::unique_ptr<const CiffIFD>> mSubIFD;
46 std::map<CiffTag, std::unique_ptr<const CiffEntry>> mEntry;
47
48 int subIFDCount = 0;
50
52 void checkSubIFDs(int headroom) const;
53 void recursivelyCheckSubIFDs(int headroom) const;
54
55 // CIFF IFD are tree-like structure, with branches.
56 // A branch (IFD) can have branches (IFDs) of it's own.
57 // We must be careful to weed-out all the degenerative cases that
58 // can be produced e.g. via fuzzing, or other means.
59 struct Limits final {
60 // How many layers of IFD's can there be?
61 // All RPU samples (as of 2018-02-13) are ok with 3.
62 // However, let's be on the safe side, and pad it by one.
63 static constexpr int Depth = 3 + 1;
64
65 // How many sub-IFD's can this IFD have?
66 // NOTE: only for the given IFD, *NOT* recursively including all sub-IFD's!
67 // All RPU samples (as of 2018-02-13) are ok with 4.
68 // However, let's be on the safe side, and double it.
69 static constexpr int SubIFDCount = 4 * 2;
70
71 // How many sub-IFD's can this IFD have, recursively?
72 // All RPU samples (as of 2018-02-13) are ok with 6.
73 // However, let's be on the safe side, and double it.
74 static constexpr int RecursiveSubIFDCount = 6 * 2;
75 };
76
77 void add(std::unique_ptr<CiffIFD> subIFD);
78 void add(std::unique_ptr<CiffEntry> entry);
79
80 void parseIFDEntry(NORangesSet<Buffer>* valueDatas, ByteStream valueData,
81 ByteStream& dirEntries);
82
83 template <typename Lambda>
84 std::vector<const CiffIFD*>
85 RAWSPEED_READONLY getIFDsWithTagIf(CiffTag tag, const Lambda& f) const;
86
87 template <typename Lambda>
88 const CiffEntry* RAWSPEED_READONLY getEntryRecursiveIf(CiffTag tag,
89 const Lambda& f) const;
90
91public:
92 explicit CiffIFD(CiffIFD* parent);
93 CiffIFD(CiffIFD* parent, ByteStream directory);
94
95 [[nodiscard]] std::vector<const CiffIFD*>
96 RAWSPEED_READONLY getIFDsWithTag(CiffTag tag) const;
97 [[nodiscard]] std::vector<const CiffIFD*> RAWSPEED_READONLY
98 getIFDsWithTagWhere(CiffTag tag, uint32_t isValue) const;
99 [[nodiscard]] std::vector<const CiffIFD*> RAWSPEED_READONLY
100 getIFDsWithTagWhere(CiffTag tag, const std::string& isValue) const;
101
102 [[nodiscard]] bool RAWSPEED_READONLY hasEntry(CiffTag tag) const;
103 [[nodiscard]] bool RAWSPEED_READONLY hasEntryRecursive(CiffTag tag) const;
104
105 [[nodiscard]] const CiffEntry* RAWSPEED_READONLY getEntry(CiffTag tag) const;
106 [[nodiscard]] const CiffEntry* RAWSPEED_READONLY
107 getEntryRecursive(CiffTag tag) const;
108 [[nodiscard]] const CiffEntry* RAWSPEED_READONLY
109 getEntryRecursiveWhere(CiffTag tag, uint32_t isValue) const;
110 [[nodiscard]] const CiffEntry* RAWSPEED_READONLY
111 getEntryRecursiveWhere(CiffTag tag, const std::string& isValue) const;
112};
113
114} // namespace rawspeed
Definition CiffEntry.h:54
bool RAWSPEED_READONLY hasEntry(CiffTag tag) const
Definition CiffIFD.cpp:230
int subIFDCountRecursive
Definition CiffIFD.h:49
CiffIFD *const parent
Definition CiffIFD.h:43
const CiffEntry *RAWSPEED_READONLY getEntryRecursiveIf(CiffTag tag, const Lambda &f) const
void recursivelyCheckSubIFDs(int headroom) const
Definition CiffIFD.cpp:136
std::vector< const CiffIFD * > RAWSPEED_READONLY getIFDsWithTag(CiffTag tag) const
Definition CiffIFD.cpp:208
void recursivelyIncrementSubIFDCount()
Definition CiffIFD.cpp:111
CiffIFD(CiffIFD *parent)
Definition CiffIFD.cpp:68
void add(std::unique_ptr< CiffIFD > subIFD)
Definition CiffIFD.cpp:152
std::vector< const CiffIFD * > RAWSPEED_READONLY getIFDsWithTagIf(CiffTag tag, const Lambda &f) const
const CiffEntry *RAWSPEED_READONLY getEntryRecursiveWhere(CiffTag tag, uint32_t isValue) const
Definition CiffIFD.cpp:263
std::vector< const CiffIFD * > RAWSPEED_READONLY getIFDsWithTagWhere(CiffTag tag, uint32_t isValue) const
Definition CiffIFD.cpp:214
const CiffEntry *RAWSPEED_READONLY getEntryRecursive(CiffTag tag) const
Definition CiffIFD.cpp:257
const CiffEntry *RAWSPEED_READONLY getEntry(CiffTag tag) const
Definition CiffIFD.cpp:248
bool RAWSPEED_READONLY hasEntryRecursive(CiffTag tag) const
Definition CiffIFD.cpp:236
void parseIFDEntry(NORangesSet< Buffer > *valueDatas, ByteStream valueData, ByteStream &dirEntries)
Definition CiffIFD.cpp:45
std::map< CiffTag, std::unique_ptr< const CiffEntry > > mEntry
Definition CiffIFD.h:46
std::vector< std::unique_ptr< const CiffIFD > > mSubIFD
Definition CiffIFD.h:45
void checkSubIFDs(int headroom) const
Definition CiffIFD.cpp:122
static constexpr int SubIFDCount
Definition CiffIFD.h:69
static constexpr int RecursiveSubIFDCount
Definition CiffIFD.h:74
static constexpr int Depth
Definition CiffIFD.h:63