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
"
25
#include "
decoders/RawDecoderException.h
"
26
#include "
decoders/SimpleTiffDecoder.h
"
27
#include "
decompressors/KodakDecompressor.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
39
namespace
rawspeed
{
40
41
class
CameraMetaData
;
42
43
bool
DcrDecoder::isAppropriateDecoder
(
const
TiffRootIFD
* rootIFD,
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
53
void
DcrDecoder::checkImageDimensions
() {
54
if
(
width
> 4516 ||
height
> 3012)
55
ThrowRDE
(
"Unexpected image dimensions found: (%u; %u)"
,
width
,
height
);
56
}
57
58
RawImage
DcrDecoder::decodeRawInternal
() {
59
SimpleTiffDecoder::prepareForRawDecoding
();
60
61
ByteStream
input(
DataBuffer
(
mFile
.getSubView(
off
),
Endianness::little
));
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
71
NORangesSet<Buffer>
ifds;
72
73
assert
(ifdoffset !=
nullptr
);
74
TiffRootIFD
kodakifd(
nullptr
, &ifds, ifdoffset->
getRootIfdData
(),
75
ifdoffset->
getU32
());
76
77
const
TiffEntry
* linearization =
78
kodakifd.
getEntryRecursive
(
TiffTag::KODAK_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
117
KodakDecompressor
k(
mRaw
, input, bps,
uncorrectedRawValues
);
118
mRaw
->createData();
119
k.
decompress
();
120
121
return
mRaw
;
122
}
123
124
void
DcrDecoder::decodeMetaDataInternal
(
const
CameraMetaData
* meta) {
125
setMetaData
(meta,
""
, 0);
126
}
127
128
}
// namespace rawspeed
Buffer.h
ByteStream.h
DcrDecoder.h
Endianness.h
KodakDecompressor.h
NORangesSet.h
RawDecoderException.h
ThrowRDE
#define ThrowRDE(...)
Definition
RawDecoderException.h:37
RawImage.h
SimpleTiffDecoder.h
TiffEntry.h
TiffIFD.h
TiffTag.h
assert
assert(dim.area() >=area)
rawspeed::AbstractTiffDecoder::setMetaData
void setMetaData(const CameraMetaData *meta, const TiffID &id, const std::string &mode, int iso_speed)
Definition
AbstractTiffDecoder.h:55
rawspeed::AbstractTiffDecoder::mRootIFD
TiffRootIFDOwner mRootIFD
Definition
AbstractTiffDecoder.h:40
rawspeed::Buffer
Definition
Buffer.h:47
rawspeed::ByteStream
Definition
ByteStream.h:43
rawspeed::CameraMetaData
Definition
CameraMetaData.h:47
rawspeed::DataBuffer
Definition
Buffer.h:133
rawspeed::DcrDecoder::decodeRawInternal
RawImage decodeRawInternal() override
Definition
DcrDecoder.cpp:58
rawspeed::DcrDecoder::decodeMetaDataInternal
void decodeMetaDataInternal(const CameraMetaData *meta) override
Definition
DcrDecoder.cpp:124
rawspeed::DcrDecoder::isAppropriateDecoder
static bool isAppropriateDecoder(const TiffRootIFD *rootIFD, Buffer file)
Definition
DcrDecoder.cpp:43
rawspeed::DcrDecoder::checkImageDimensions
void checkImageDimensions() override
Definition
DcrDecoder.cpp:53
rawspeed::KodakDecompressor
Definition
KodakDecompressor.h:33
rawspeed::KodakDecompressor::decompress
void decompress()
Definition
KodakDecompressor.cpp:120
rawspeed::NORangesSet
Definition
NORangesSet.h:32
rawspeed::RawDecoder::uncorrectedRawValues
bool uncorrectedRawValues
Definition
RawDecoder.h:102
rawspeed::RawDecoder::mFile
Buffer mFile
Definition
RawDecoder.h:154
rawspeed::RawDecoder::mRaw
RawImage mRaw
Definition
RawDecoder.h:74
rawspeed::RawImageCurveGuard
Definition
RawImage.h:365
rawspeed::RawImage
Definition
RawImage.h:247
rawspeed::SimpleTiffDecoder::off
uint32_t off
Definition
SimpleTiffDecoder.h:50
rawspeed::SimpleTiffDecoder::raw
const TiffIFD * raw
Definition
SimpleTiffDecoder.h:47
rawspeed::SimpleTiffDecoder::prepareForRawDecoding
void prepareForRawDecoding()
Definition
SimpleTiffDecoder.cpp:39
rawspeed::SimpleTiffDecoder::height
uint32_t height
Definition
SimpleTiffDecoder.h:49
rawspeed::SimpleTiffDecoder::width
uint32_t width
Definition
SimpleTiffDecoder.h:48
rawspeed::TiffEntry
Definition
TiffEntry.h:62
rawspeed::TiffEntry::getRootIfdData
DataBuffer getRootIfdData() const
Definition
TiffEntry.cpp:308
rawspeed::TiffEntry::getU16Array
std::vector< uint16_t > getU16Array(uint32_t count_) const
Definition
TiffEntry.h:107
rawspeed::TiffEntry::getU32
uint32_t getU32(uint32_t index=0) const
Definition
TiffEntry.cpp:203
rawspeed::TiffEntry::count
uint32_t count
Definition
TiffEntry.h:84
rawspeed::TiffEntry::type
TiffDataType type
Definition
TiffEntry.h:83
rawspeed::TiffIFD::getEntryRecursive
TiffEntry *RAWSPEED_READONLY getEntryRecursive(TiffTag tag) const
Definition
TiffIFD.cpp:246
rawspeed::TiffRootIFD
Definition
TiffIFD.h:138
rawspeed::TiffRootIFD::getID
TiffID getID() const
Definition
TiffIFD.cpp:325
rawspeed
Definition
CoalescingOutputIteratorBenchmark.cpp:35
rawspeed::TiffDataType::SHORT
@ SHORT
Definition
TiffEntry.h:49
rawspeed::TiffTag
TiffTag
Definition
TiffTag.h:32
rawspeed::TiffTag::KODAK_IFD
@ KODAK_IFD
Definition
TiffTag.h:357
rawspeed::TiffTag::KODAK_LINEARIZATION
@ KODAK_LINEARIZATION
Definition
TiffTag.h:358
rawspeed::TiffTag::COMPRESSION
@ COMPRESSION
Definition
TiffTag.h:45
rawspeed::Endianness::little
@ little
Definition
Endianness.h:32
rawspeed::TiffID::make
std::string make
Definition
TiffIFD.h:134
librawspeed
decoders
DcrDecoder.cpp
Generated by
1.15.0