RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
NakedDecoder.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
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
23#include "adt/Optional.h"
24#include "adt/Point.h"
26#include "common/RawImage.h"
27#include "decoders/RawDecoder.h"
30#include "io/Buffer.h"
31#include "io/ByteStream.h"
32#include "io/Endianness.h"
33#include "metadata/Camera.h"
34#include <map>
35#include <string>
36#include <string_view>
37
38using std::map;
39
40namespace rawspeed {
41
42class CameraMetaData;
43
45 : RawDecoder(file), cam(c) {}
46
47namespace {
48
50 using enum BitOrder;
51 if (s == "plain")
52 return LSB;
53 if (s == "jpeg")
54 return MSB;
55 if (s == "jpeg16")
56 return MSB16;
57 if (s == "jpeg32")
58 return MSB32;
59 return std::nullopt;
60}
61
62} // namespace
63
65 const auto& cHints = cam->hints;
66 const auto& make = cam->make.c_str();
67 const auto& model = cam->model.c_str();
68
69 auto parseHint = [&cHints, &make, &model](const std::string& name) {
70 if (!cHints.contains(name))
71 ThrowRDE("%s %s: couldn't find %s", make, model, name.c_str());
72
73 return cHints.get(name, 0U);
74 };
75
76 width = parseHint("full_width");
77 height = parseHint("full_height");
78
79 if (width == 0 || height == 0)
80 ThrowRDE("%s %s: image is of zero size?", make, model);
81
82 filesize = parseHint("filesize");
83 offset = cHints.get("offset", 0);
84 if (filesize == 0 || offset >= filesize)
85 ThrowRDE("%s %s: no image data found", make, model);
86
87 bits = cHints.get("bits", (filesize - offset) * 8 / width / height);
88 if (bits == 0)
89 ThrowRDE("%s %s: image bpp is invalid: %u", make, model, bits);
90
91 auto order = cHints.get("order", std::string());
92 if (!order.empty()) {
93 auto bo_ = getAsBitOrder(order);
94 if (!bo_)
95 ThrowRDE("%s %s: unknown order: %s", make, model, order.c_str());
96 bo = *bo_;
97 }
98}
99
101 parseHints();
102
103 mRaw->dim = iPoint2D(width, height);
104
105 iPoint2D pos(0, 0);
108 mRaw, iRectangle2D(pos, mRaw->dim), width * bits / 8, bits, bo);
109 mRaw->createData();
110
111 u.readUncompressedRaw();
112
113 return mRaw;
114}
115
117 this->checkCameraSupported(meta, cam->make, cam->model, cam->mode);
118}
119
121 setMetaData(meta, cam->make, cam->model, cam->mode, 0);
122}
123
124} // namespace rawspeed
#define s
#define ThrowRDE(...)
RawImage decodeRawInternal() override
NakedDecoder(Buffer file, const Camera *c)
void decodeMetaDataInternal(const CameraMetaData *meta) override
void checkSupportInternal(const CameraMetaData *meta) override
virtual void setMetaData(const CameraMetaData *meta, const std::string &make, const std::string &model, const std::string &mode, int iso_speed=0)
RawDecoder(Buffer file)
bool checkCameraSupported(const CameraMetaData *meta, const std::string &make, const std::string &model, const std::string &mode)
Optional< BitOrder > getAsBitOrder(std::string_view s)