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"
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 <cstdint>
35#include <memory>
36#include <string>
37
38namespace rawspeed {
39
40class CameraMetaData;
41
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
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
64 return mRaw;
65}
66
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
83
84 const ByteStream bs(
85 DataBuffer(mFile.getSubView(off, count), Endianness::little));
86
88 2 * mRaw->dim.x, 16, BitOrder::MSB);
89 mRaw->createData();
90 u.readUncompressedRaw();
91}
92
94 setMetaData(meta, "", 0);
95}
96
97} // namespace rawspeed
#define ThrowRDE(...)
void setMetaData(const CameraMetaData *meta, const TiffID &id, const std::string &mode, int iso_speed)
void DecodeUncompressed(const TiffIFD *raw) const
RawImage decodeRawInternal() override
static bool isAppropriateDecoder(const TiffRootIFD *rootIFD, Buffer file)
void decodeMetaDataInternal(const CameraMetaData *meta) override
uint32_t getU32(uint32_t index=0) const
TiffEntry * getEntry(TiffTag tag) const
Definition TiffIFD.cpp:313
TiffID getID() const
Definition TiffIFD.cpp:325
std::string make
Definition TiffIFD.h:134