RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
CiffParser.cpp
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) 2017 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#include "parsers/CiffParser.h"
24#include "common/Common.h"
25#include "decoders/CrwDecoder.h"
26#include "io/Buffer.h"
27#include "io/ByteStream.h"
28#include "io/Endianness.h"
30#include "parsers/RawParser.h"
31#include "tiff/CiffEntry.h"
32#include "tiff/CiffIFD.h"
33#include "tiff/CiffTag.h"
34#include <cstdint>
35#include <memory>
36#include <string>
37#include <utility>
38
39namespace rawspeed {
40
41CiffParser::CiffParser(Buffer inputData) : RawParser(inputData) {}
42
45
46 if (const uint16_t byteOrder = bs.getU16();
47 byteOrder != 0x4949) // "II" / little-endian
48 ThrowCPE("Not a CIFF file (endianness)");
49
50 // Offset to the beginning of the CIFF
51 const uint32_t headerLength = bs.getU32();
52
53 // 8 bytes of Signature
55 ThrowCPE("Not a CIFF file (ID)");
56
57 // *Everything* after the header is the root CIFF Directory
58 ByteStream CIFFRootDirectory(bs.getSubStream(headerLength));
59 mRootIFD = std::make_unique<CiffIFD>(nullptr, CIFFRootDirectory);
60}
61
62std::unique_ptr<RawDecoder> CiffParser::getDecoder(const CameraMetaData* meta) {
63 if (!mRootIFD)
64 parseData();
65
66 for (const auto potentials(mRootIFD->getIFDsWithTag(CiffTag::MAKEMODEL));
67 const auto& potential : potentials) {
68 const auto* const mm = potential->getEntry(CiffTag::MAKEMODEL);
69 const std::string make = trimSpaces(mm->getString());
70
71 if (make == "Canon")
72 return std::make_unique<CrwDecoder>(std::move(mRootIFD), mInput);
73 }
74
75 ThrowCPE("No decoder found. Sorry.");
76}
77
78} // namespace rawspeed
#define ThrowCPE(...)
ByteStream getSubStream(size_type offset, size_type size_) const
Definition ByteStream.h:54
std::unique_ptr< const CiffIFD > mRootIFD
Definition CiffParser.h:35
CiffParser(Buffer input)
std::unique_ptr< RawDecoder > getDecoder(const CameraMetaData *meta=nullptr) override
static bool isCRW(Buffer input)
RawParser(Buffer inputData)
Definition RawParser.h:33
std::string trimSpaces(std::string_view str)
Definition Common.h:163