RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
DcrDecoder.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
22#include "decoders/DcrDecoder.h"
23#include "adt/NORangesSet.h"
24#include "common/RawImage.h"
28#include "io/Buffer.h"
29#include "io/ByteStream.h"
30#include "io/Endianness.h"
31#include "tiff/TiffEntry.h"
32#include "tiff/TiffIFD.h"
33#include "tiff/TiffTag.h"
34#include <array>
35#include <cassert>
36#include <memory>
37#include <string>
38
39namespace rawspeed {
40
41class CameraMetaData;
42
44 [[maybe_unused]] Buffer file) {
45 const auto id = rootIFD->getID();
46 const std::string& make = id.make;
47
48 // FIXME: magic
49
50 return make == "Kodak";
51}
52
54 if (width > 4516 || height > 3012)
55 ThrowRDE("Unexpected image dimensions found: (%u; %u)", width, height);
56}
57
60
62
63 if (int compression = raw->getEntry(TiffTag::COMPRESSION)->getU32();
64 65000 != compression)
65 ThrowRDE("Unsupported compression %d", compression);
66
67 const TiffEntry* ifdoffset = mRootIFD->getEntryRecursive(TiffTag::KODAK_IFD);
68 if (!ifdoffset)
69 ThrowRDE("Couldn't find the Kodak IFD offset");
70
72
73 assert(ifdoffset != nullptr);
74 TiffRootIFD kodakifd(nullptr, &ifds, ifdoffset->getRootIfdData(),
75 ifdoffset->getU32());
76
77 const TiffEntry* linearization =
79 if (!linearization ||
80 (linearization->count != 1024 && linearization->count != 4096) ||
81 linearization->type != TiffDataType::SHORT)
82 ThrowRDE("Couldn't find the linearization table");
83
84 assert(linearization != nullptr);
85 auto linTable = linearization->getU16Array(linearization->count);
86
87 RawImageCurveGuard curveHandler(&mRaw, linTable, uncorrectedRawValues);
88
89 // FIXME: dcraw does all sorts of crazy things besides this to fetch
90 // WB from what appear to be presets and calculate it in weird ways
91 // The only file I have only uses this method, if anybody careas look
92 // in dcraw.c parse_kodak_ifd() for all that weirdness
93 if (const TiffEntry* blob =
94 kodakifd.getEntryRecursive(static_cast<TiffTag>(0x03fd));
95 blob && blob->count == 72) {
96 std::array<float, 4> wbCoeffs = {};
97 for (auto i = 0U; i < 3; i++) {
98 const auto mul = blob->getU16(20 + i);
99 if (0 == mul)
100 ThrowRDE("WB coefficient is zero!");
101 wbCoeffs[i] = 2048.0F / mul;
102 }
103 mRaw->metadata.wbCoeffs = wbCoeffs;
104 }
105
106 const int bps = [CurveSize = linearization->count]() {
107 switch (CurveSize) {
108 case 1024:
109 return 10;
110 case 4096:
111 return 12;
112 default:
113 __builtin_unreachable();
114 }
115 }();
116
118 mRaw->createData();
119 k.decompress();
120
121 return mRaw;
122}
123
125 setMetaData(meta, "", 0);
126}
127
128} // namespace rawspeed
#define ThrowRDE(...)
assert(dim.area() >=area)
void setMetaData(const CameraMetaData *meta, const TiffID &id, const std::string &mode, int iso_speed)
RawImage decodeRawInternal() override
void decodeMetaDataInternal(const CameraMetaData *meta) override
static bool isAppropriateDecoder(const TiffRootIFD *rootIFD, Buffer file)
void checkImageDimensions() override
Definition TiffEntry.h:62
DataBuffer getRootIfdData() const
std::vector< uint16_t > getU16Array(uint32_t count_) const
Definition TiffEntry.h:107
uint32_t getU32(uint32_t index=0) const
uint32_t count
Definition TiffEntry.h:84
TiffDataType type
Definition TiffEntry.h:83
TiffEntry *RAWSPEED_READONLY getEntryRecursive(TiffTag tag) const
Definition TiffIFD.cpp:246
TiffID getID() const
Definition TiffIFD.cpp:325
std::string make
Definition TiffIFD.h:134