RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
ThreefrDecoder.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/ThreefrDecoder.h
"
23
#include "
adt/Casts.h
"
24
#include "
adt/Point.h
"
25
#include "
bitstreams/BitStreams.h
"
26
#include "
common/RawImage.h
"
27
#include "
decoders/RawDecoderException.h
"
28
#include "
decompressors/HasselbladLJpegDecoder.h
"
29
#include "
decompressors/UncompressedDecompressor.h
"
30
#include "
io/Buffer.h
"
31
#include "
io/ByteStream.h
"
32
#include "
io/Endianness.h
"
33
#include "
metadata/ColorFilterArray.h
"
34
#include "
tiff/TiffEntry.h
"
35
#include "
tiff/TiffIFD.h
"
36
#include "
tiff/TiffTag.h
"
37
#include <array>
38
#include <cstdint>
39
#include <memory>
40
#include <string>
41
42
namespace
rawspeed
{
43
44
class
CameraMetaData
;
45
46
bool
ThreefrDecoder::isAppropriateDecoder
(
const
TiffRootIFD
* rootIFD,
47
[[maybe_unused]]
Buffer
file) {
48
const
auto
id
= rootIFD->
getID
();
49
const
std::string& make =
id
.
make
;
50
51
// FIXME: magic
52
53
return
make ==
"Hasselblad"
;
54
}
55
56
RawImage
ThreefrDecoder::decodeRawInternal
() {
57
const
auto
* raw =
mRootIFD
->getIFDWithTag(
TiffTag::STRIPOFFSETS
, 1);
58
uint32_t
width = raw->getEntry(
TiffTag::IMAGEWIDTH
)->getU32();
59
uint32_t
height = raw->getEntry(
TiffTag::IMAGELENGTH
)->getU32();
60
uint32_t
compression = raw->getEntry(
TiffTag::COMPRESSION
)->getU32();
61
62
mRaw
->dim =
iPoint2D
(width, height);
63
64
if
(1 == compression) {
65
DecodeUncompressed
(raw);
66
return
mRaw
;
67
}
68
69
if
(compression != 7)
// LJpeg
70
ThrowRDE
(
"Unexpected compression type."
);
71
72
uint32_t
off = raw->getEntry(
TiffTag::STRIPOFFSETS
)->getU32();
73
// STRIPBYTECOUNTS is strange/invalid for the existing (compressed?) 3FR
74
// samples...
75
76
const
ByteStream
bs(
DataBuffer
(
mFile
.getSubView(off),
Endianness::little
));
77
78
HasselbladLJpegDecoder
l(bs,
mRaw
);
79
mRaw
->createData();
80
81
l.
decode
();
82
83
return
mRaw
;
84
}
85
86
void
ThreefrDecoder::DecodeUncompressed
(
const
TiffIFD
* raw)
const
{
87
if
(
mRaw
->getDataType() !=
RawImageType::UINT16
)
88
ThrowRDE
(
"Unexpected data type"
);
89
90
if
(
mRaw
->getCpp() != 1 ||
mRaw
->getBpp() !=
sizeof
(
uint16_t
))
91
ThrowRDE
(
"Unexpected cpp: %u"
,
mRaw
->getCpp());
92
93
// FIXME: could be wrong. max "active pixels" - "100 MP"
94
if
(!
mRaw
->dim.hasPositiveArea() ||
mRaw
->dim.x % 2 != 0 ||
95
mRaw
->dim.x > 12000 ||
mRaw
->dim.y > 8842) {
96
ThrowRDE
(
"Unexpected image dimensions found: (%d; %d)"
,
mRaw
->dim.x,
97
mRaw
->dim.y);
98
}
99
100
uint32_t
off = raw->
getEntry
(
TiffTag::STRIPOFFSETS
)->
getU32
();
101
// STRIPBYTECOUNTS looks valid for the existing uncompressed 3FR samples
102
uint32_t
count = raw->
getEntry
(
TiffTag::STRIPBYTECOUNTS
)->
getU32
();
103
104
const
ByteStream
bs(
105
DataBuffer
(
mFile
.getSubView(off, count),
Endianness::little
));
106
107
UncompressedDecompressor
u(bs,
mRaw
,
iRectangle2D
({0, 0},
mRaw
->dim),
108
2 *
mRaw
->dim.x, 16,
BitOrder::LSB
);
109
mRaw
->createData();
110
u.readUncompressedRaw();
111
}
112
113
void
ThreefrDecoder::decodeMetaDataInternal
(
const
CameraMetaData
* meta) {
114
mRaw
->cfa.setCFA(
iPoint2D
(2, 2),
CFAColor::RED
,
CFAColor::GREEN
,
115
CFAColor::GREEN
,
CFAColor::BLUE
);
116
117
setMetaData
(meta,
""
, 0);
118
119
if
(
mRootIFD
->hasEntryRecursive(
TiffTag::BLACKLEVEL
)) {
120
const
TiffEntry
* bl =
mRootIFD
->getEntryRecursive(
TiffTag::BLACKLEVEL
);
121
if
(bl->
count
== 1)
122
mRaw
->blackLevel =
implicit_cast<int>
(bl->
getFloat
());
123
}
124
125
if
(
mRootIFD
->hasEntryRecursive(
TiffTag::WHITELEVEL
)) {
126
const
TiffEntry
* wl =
mRootIFD
->getEntryRecursive(
TiffTag::WHITELEVEL
);
127
if
(wl->
count
== 1)
128
mRaw
->whitePoint =
implicit_cast<int>
(wl->
getFloat
());
129
}
130
131
// Fetch the white balance
132
if
(
mRootIFD
->hasEntryRecursive(
TiffTag::ASSHOTNEUTRAL
)) {
133
const
TiffEntry
* wb =
mRootIFD
->getEntryRecursive(
TiffTag::ASSHOTNEUTRAL
);
134
if
(wb->
count
== 3) {
135
std::array<float, 4> wbCoeffs = {};
136
for
(
uint32_t
i = 0; i < 3; i++) {
137
const
float
div = wb->
getFloat
(i);
138
if
(div == 0.0F)
139
ThrowRDE
(
"Can not decode WB, multiplier is zero/"
);
140
141
wbCoeffs[i] = 1.0F / div;
142
}
143
mRaw
->metadata.wbCoeffs = wbCoeffs;
144
}
145
}
146
}
147
148
}
// namespace rawspeed
BitStreams.h
Buffer.h
ByteStream.h
Casts.h
ColorFilterArray.h
Endianness.h
HasselbladLJpegDecoder.h
Point.h
RawDecoderException.h
ThrowRDE
#define ThrowRDE(...)
Definition
RawDecoderException.h:37
RawImage.h
ThreefrDecoder.h
TiffEntry.h
TiffIFD.h
TiffTag.h
UncompressedDecompressor.h
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::HasselbladLJpegDecoder
Definition
HasselbladLJpegDecoder.h:31
rawspeed::HasselbladLJpegDecoder::decode
void decode()
Definition
HasselbladLJpegDecoder.cpp:68
rawspeed::RawDecoder::mFile
Buffer mFile
Definition
RawDecoder.h:154
rawspeed::RawDecoder::mRaw
RawImage mRaw
Definition
RawDecoder.h:74
rawspeed::RawImage
Definition
RawImage.h:247
rawspeed::ThreefrDecoder::DecodeUncompressed
void DecodeUncompressed(const TiffIFD *raw) const
Definition
ThreefrDecoder.cpp:86
rawspeed::ThreefrDecoder::decodeMetaDataInternal
void decodeMetaDataInternal(const CameraMetaData *meta) override
Definition
ThreefrDecoder.cpp:113
rawspeed::ThreefrDecoder::isAppropriateDecoder
static bool isAppropriateDecoder(const TiffRootIFD *rootIFD, Buffer file)
Definition
ThreefrDecoder.cpp:46
rawspeed::ThreefrDecoder::decodeRawInternal
RawImage decodeRawInternal() override
Definition
ThreefrDecoder.cpp:56
rawspeed::TiffEntry
Definition
TiffEntry.h:62
rawspeed::TiffEntry::getFloat
float getFloat(uint32_t index=0) const
Definition
TiffEntry.cpp:263
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::TiffIFD
Definition
TiffIFD.h:49
rawspeed::TiffIFD::getEntry
TiffEntry * getEntry(TiffTag tag) const
Definition
TiffIFD.cpp:313
rawspeed::TiffRootIFD
Definition
TiffIFD.h:138
rawspeed::TiffRootIFD::getID
TiffID getID() const
Definition
TiffIFD.cpp:325
rawspeed::UncompressedDecompressor
Definition
UncompressedDecompressor.h:37
rawspeed::iPoint2D
Definition
Point.h:35
rawspeed::iRectangle2D
Definition
Point.h:107
uint16_t
uint32_t
rawspeed
Definition
CoalescingOutputIteratorBenchmark.cpp:35
rawspeed::implicit_cast
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition
Casts.h:32
rawspeed::BitOrder::LSB
@ LSB
Definition
BitStreams.h:29
rawspeed::CFAColor::BLUE
@ BLUE
Definition
ColorFilterArray.h:35
rawspeed::CFAColor::GREEN
@ GREEN
Definition
ColorFilterArray.h:34
rawspeed::CFAColor::RED
@ RED
Definition
ColorFilterArray.h:33
rawspeed::RawImageType::UINT16
@ UINT16
Definition
RawImage.h:54
rawspeed::TiffTag::IMAGELENGTH
@ IMAGELENGTH
Definition
TiffTag.h:43
rawspeed::TiffTag::IMAGEWIDTH
@ IMAGEWIDTH
Definition
TiffTag.h:41
rawspeed::TiffTag::ASSHOTNEUTRAL
@ ASSHOTNEUTRAL
Definition
TiffTag.h:276
rawspeed::TiffTag::WHITELEVEL
@ WHITELEVEL
Definition
TiffTag.h:265
rawspeed::TiffTag::COMPRESSION
@ COMPRESSION
Definition
TiffTag.h:45
rawspeed::TiffTag::STRIPOFFSETS
@ STRIPOFFSETS
Definition
TiffTag.h:53
rawspeed::TiffTag::BLACKLEVEL
@ BLACKLEVEL
Definition
TiffTag.h:262
rawspeed::TiffTag::STRIPBYTECOUNTS
@ STRIPBYTECOUNTS
Definition
TiffTag.h:58
rawspeed::Endianness::little
@ little
Definition
Endianness.h:32
rawspeed::TiffID::make
std::string make
Definition
TiffIFD.h:134
librawspeed
decoders
ThreefrDecoder.cpp
Generated by
1.15.0