RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
RawParser.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) 2017 Axel Waggershauser
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
9 License as published by the Free Software Foundation; either
10 version 2 of 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, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#include "parsers/RawParser.h"
23#include "decoders/MrwDecoder.h"
25#include "decoders/RafDecoder.h"
26#include "decoders/RawDecoder.h"
28#include "io/Buffer.h"
30#include "parsers/CiffParser.h"
32#include "parsers/FiffParser.h"
34#include "parsers/TiffParser.h"
36#include <memory>
37
38namespace rawspeed {
39
40class Camera;
41
42std::unique_ptr<RawDecoder> RawParser::getDecoder(const CameraMetaData* meta) {
43 // We need some data.
44 // For now it is 104 bytes for RAF/FUJIFIM images.
45 // FIXME: each decoder/parser should check it on their own.
46 if (mInput.getSize() <= 104)
47 ThrowRDE("File too small");
48
49 // MRW images are easy to check for, let's try that first
51 try {
52 return std::make_unique<MrwDecoder>(mInput);
53 } catch (const RawDecoderException&) { // NOLINT(bugprone-empty-catch)
54 // Yes, just ignore the exception.
55 }
56 }
57
58 // FUJI has pointers to IFD's at fixed byte offsets
59 // So if camera is FUJI, we cannot use ordinary TIFF parser
61 try {
63 return p.getDecoder(meta);
64 } catch (const FiffParserException&) { // NOLINT(bugprone-empty-catch)
65 // Yes, just ignore the exception.
66 }
67 }
68
69 // Ordinary TIFF images
70 try {
72 return p.getDecoder(meta);
73 } catch (const TiffParserException&) { // NOLINT(bugprone-empty-catch)
74 // Yes, just ignore the exception.
75 }
76
77 // CIFF images
78 try {
80 return p.getDecoder(meta);
81 } catch (const CiffParserException&) { // NOLINT(bugprone-empty-catch)
82 // Yes, just ignore the exception.
83 }
84
85 // Detect camera on filesize (CHDK).
86 if (meta != nullptr && meta->hasChdkCamera(mInput.getSize())) {
87 const Camera* c = meta->getChdkCamera(mInput.getSize());
88
89 try {
90 return std::make_unique<NakedDecoder>(mInput, c);
91 } catch (const RawDecoderException&) { // NOLINT(bugprone-empty-catch)
92 // Yes, just ignore the exception.
93 }
94 }
95
96 // File could not be decoded, so no further options for now.
97 ThrowRDE("No decoder found. Sorry.");
98}
99
100} // namespace rawspeed
#define ThrowRDE(...)
const Camera *RAWSPEED_READONLY getChdkCamera(uint32_t filesize) const
bool RAWSPEED_READONLY hasChdkCamera(uint32_t filesize) const
static int isMRW(Buffer input)
static bool isRAF(Buffer input)
virtual std::unique_ptr< RawDecoder > getDecoder(const CameraMetaData *meta=nullptr)
Definition RawParser.cpp:42