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
"
29
#include "
parsers/CiffParserException.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
39
namespace
rawspeed
{
40
41
CiffParser::CiffParser
(
Buffer
inputData) :
RawParser
(inputData) {}
42
43
void
CiffParser::parseData
() {
44
ByteStream
bs(
DataBuffer
(
mInput
,
Endianness::little
));
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
54
if
(!
CrwDecoder::isCRW
(
mInput
))
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
62
std::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
Buffer.h
ByteStream.h
CiffEntry.h
CiffIFD.h
CiffParser.h
CiffParserException.h
ThrowCPE
#define ThrowCPE(...)
Definition
CiffParserException.h:39
CiffTag.h
CrwDecoder.h
Endianness.h
RawParser.h
rawspeed::Buffer
Definition
Buffer.h:47
rawspeed::ByteStream
Definition
ByteStream.h:43
rawspeed::ByteStream::getU16
uint16_t getU16()
Definition
ByteStream.h:194
rawspeed::ByteStream::getSubStream
ByteStream getSubStream(size_type offset, size_type size_) const
Definition
ByteStream.h:54
rawspeed::ByteStream::getU32
uint32_t getU32()
Definition
ByteStream.h:196
rawspeed::CameraMetaData
Definition
CameraMetaData.h:47
rawspeed::CiffParser::mRootIFD
std::unique_ptr< const CiffIFD > mRootIFD
Definition
CiffParser.h:35
rawspeed::CiffParser::CiffParser
CiffParser(Buffer input)
Definition
CiffParser.cpp:41
rawspeed::CiffParser::getDecoder
std::unique_ptr< RawDecoder > getDecoder(const CameraMetaData *meta=nullptr) override
Definition
CiffParser.cpp:62
rawspeed::CiffParser::parseData
void parseData()
Definition
CiffParser.cpp:43
rawspeed::CrwDecoder::isCRW
static bool isCRW(Buffer input)
Definition
CrwDecoder.cpp:60
rawspeed::DataBuffer
Definition
Buffer.h:133
rawspeed::RawParser::RawParser
RawParser(Buffer inputData)
Definition
RawParser.h:33
rawspeed::RawParser::mInput
Buffer mInput
Definition
RawParser.h:40
uint16_t
uint32_t
rawspeed
Definition
CoalescingOutputIteratorBenchmark.cpp:35
rawspeed::trimSpaces
std::string trimSpaces(std::string_view str)
Definition
Common.h:163
rawspeed::CiffTag::MAKEMODEL
@ MAKEMODEL
Definition
CiffTag.h:31
rawspeed::Endianness::little
@ little
Definition
Endianness.h:32
Common.h
librawspeed
parsers
CiffParser.cpp
Generated by
1.15.0