RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
StiDecoder.cpp
Go to the documentation of this file.
1
/*
2
RawSpeed - RAW file decoder.
3
4
Copyright (C) 2023 Roman Lebedev
5
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
10
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
15
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#include "
decoders/StiDecoder.h
"
22
#include "
adt/Point.h
"
23
#include "
bitstreams/BitStreams.h
"
24
#include "
common/RawImage.h
"
25
#include "
decoders/RawDecoderException.h
"
26
#include "
decompressors/HasselbladLJpegDecoder.h
"
27
#include "
decompressors/UncompressedDecompressor.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 <cstdint>
35
#include <memory>
36
#include <string>
37
38
namespace
rawspeed
{
39
40
class
CameraMetaData
;
41
42
bool
StiDecoder::isAppropriateDecoder
(
const
TiffRootIFD
* rootIFD,
43
[[maybe_unused]]
Buffer
file) {
44
const
auto
id
= rootIFD->
getID
();
45
const
std::string& make =
id
.
make
;
46
47
// FIXME: magic
48
49
return
make ==
"Sinar AG"
;
50
}
51
52
RawImage
StiDecoder::decodeRawInternal
() {
53
const
auto
* raw =
mRootIFD
->getIFDWithTag(
TiffTag::TILEOFFSETS
, 0);
54
uint32_t
width = raw->getEntry(
TiffTag::IMAGEWIDTH
)->getU32();
55
uint32_t
height = raw->getEntry(
TiffTag::IMAGELENGTH
)->getU32();
56
uint32_t
compression = raw->getEntry(
TiffTag::COMPRESSION
)->getU32();
57
58
mRaw
->dim =
iPoint2D
(width, height);
59
60
if
(1 != compression)
61
ThrowRDE
(
"Unexpected compression type."
);
62
63
DecodeUncompressed
(raw);
64
return
mRaw
;
65
}
66
67
void
StiDecoder::DecodeUncompressed
(
const
TiffIFD
* raw)
const
{
68
if
(
mRaw
->getDataType() !=
RawImageType::UINT16
)
69
ThrowRDE
(
"Unexpected data type"
);
70
71
if
(
mRaw
->getCpp() != 1 ||
mRaw
->getBpp() !=
sizeof
(
uint16_t
))
72
ThrowRDE
(
"Unexpected cpp: %u"
,
mRaw
->getCpp());
73
74
// FIXME: could be wrong.
75
if
(!
mRaw
->dim.hasPositiveArea() ||
mRaw
->dim.x % 2 != 0 ||
76
mRaw
->dim.y % 2 != 0 ||
mRaw
->dim.x > 4992 ||
mRaw
->dim.y > 6668) {
77
ThrowRDE
(
"Unexpected image dimensions found: (%d; %d)"
,
mRaw
->dim.x,
78
mRaw
->dim.y);
79
}
80
81
uint32_t
off = raw->
getEntry
(
TiffTag::TILEOFFSETS
)->
getU32
();
82
uint32_t
count = raw->
getEntry
(
TiffTag::TILEBYTECOUNTS
)->
getU32
();
83
84
const
ByteStream
bs(
85
DataBuffer
(
mFile
.getSubView(off, count),
Endianness::little
));
86
87
UncompressedDecompressor
u(bs,
mRaw
,
iRectangle2D
({0, 0},
mRaw
->dim),
88
2 *
mRaw
->dim.x, 16,
BitOrder::MSB
);
89
mRaw
->createData();
90
u.readUncompressedRaw();
91
}
92
93
void
StiDecoder::decodeMetaDataInternal
(
const
CameraMetaData
* meta) {
94
setMetaData
(meta,
""
, 0);
95
}
96
97
}
// namespace rawspeed
BitStreams.h
Buffer.h
ByteStream.h
Endianness.h
HasselbladLJpegDecoder.h
Point.h
RawDecoderException.h
ThrowRDE
#define ThrowRDE(...)
Definition
RawDecoderException.h:37
RawImage.h
StiDecoder.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::RawDecoder::mFile
Buffer mFile
Definition
RawDecoder.h:154
rawspeed::RawDecoder::mRaw
RawImage mRaw
Definition
RawDecoder.h:74
rawspeed::RawImage
Definition
RawImage.h:247
rawspeed::StiDecoder::DecodeUncompressed
void DecodeUncompressed(const TiffIFD *raw) const
Definition
StiDecoder.cpp:67
rawspeed::StiDecoder::decodeRawInternal
RawImage decodeRawInternal() override
Definition
StiDecoder.cpp:52
rawspeed::StiDecoder::isAppropriateDecoder
static bool isAppropriateDecoder(const TiffRootIFD *rootIFD, Buffer file)
Definition
StiDecoder.cpp:42
rawspeed::StiDecoder::decodeMetaDataInternal
void decodeMetaDataInternal(const CameraMetaData *meta) override
Definition
StiDecoder.cpp:93
rawspeed::TiffEntry::getU32
uint32_t getU32(uint32_t index=0) const
Definition
TiffEntry.cpp:203
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::BitOrder::MSB
@ MSB
Definition
BitStreams.h:30
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::TILEOFFSETS
@ TILEOFFSETS
Definition
TiffTag.h:82
rawspeed::TiffTag::COMPRESSION
@ COMPRESSION
Definition
TiffTag.h:45
rawspeed::TiffTag::TILEBYTECOUNTS
@ TILEBYTECOUNTS
Definition
TiffTag.h:83
rawspeed::Endianness::little
@ little
Definition
Endianness.h:32
rawspeed::TiffID::make
std::string make
Definition
TiffIFD.h:134
librawspeed
decoders
StiDecoder.cpp
Generated by
1.15.0