Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Sinarback eVolution decoder #531

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions data/cameras.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14359,6 +14359,24 @@
</ColorMatrix>
</ColorMatrices>
</Camera>
<Camera make="Sinar AG" model="Sinarback eVolution 75, Sinar p3 / f3">
<ID make="Sinar" model="eVolution 75">Sinar eVolution 75</ID>
<CFA width="2" height="2">
<Color x="0" y="0">GREEN</Color>
<Color x="1" y="0">RED</Color>
<Color x="0" y="1">BLUE</Color>
<Color x="1" y="1">GREEN</Color>
</CFA>
<Crop x="0" y="0" width="0" height="0"/>
<Sensor black="0" white="16383"/>
<ColorMatrices>
<ColorMatrix planes="3">
<ColorMatrixRow plane="0">16442 -2956 -2422</ColorMatrixRow>
<ColorMatrixRow plane="1">-2877 12128 750</ColorMatrixRow>
<ColorMatrixRow plane="2">-1136 6066 4559</ColorMatrixRow>
</ColorMatrix>
</ColorMatrices>
</Camera>
<Camera make="Sinar Photography AG" model="Sinar Hy6/ Sinarback eXact" mode="dng" supported="no-samples">
<ID make="Sinar" model="Hy6">Sinar Hy6</ID>
<CFA width="2" height="2">
Expand Down
1 change: 1 addition & 0 deletions data/cameras.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@
<xs:enumeration value="SONY"/>
<xs:enumeration value="ST Micro"/>
<xs:enumeration value="Samsung"/>
<xs:enumeration value="Sinar AG"/>
<xs:enumeration value="Sinar Photography AG"/>
<xs:enumeration value="Sinar"/>
<xs:enumeration value="Sjcam"/>
Expand Down
1 change: 1 addition & 0 deletions fuzz/all-fuzzers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ TiffDecoderFuzzer-OrfDecoder
TiffDecoderFuzzer-PefDecoder
TiffDecoderFuzzer-Rw2Decoder
TiffDecoderFuzzer-SrwDecoder
TiffDecoderFuzzer-StiDecoder
TiffDecoderFuzzer-ThreefrDecoder
TiffParserFuzzer-GetDecoder
TiffParserFuzzer-GetDecoder-Decode
Expand Down
1 change: 1 addition & 0 deletions fuzz/librawspeed/decoders/TiffDecoders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(DECODERS
"PefDecoder"
"Rw2Decoder"
"SrwDecoder"
"StiDecoder"
"ThreefrDecoder"
)

Expand Down
1 change: 1 addition & 0 deletions fuzz/librawspeed/decoders/TiffDecoders/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "decoders/RafDecoder.h" // IWYU pragma: keep
#include "decoders/Rw2Decoder.h" // IWYU pragma: keep
#include "decoders/SrwDecoder.h" // IWYU pragma: keep
#include "decoders/StiDecoder.h" // IWYU pragma: keep
#include "decoders/ThreefrDecoder.h" // IWYU pragma: keep
#include "io/Buffer.h" // for Buffer
#include "metadata/CameraMetaData.h" // for CameraMetaData
Expand Down
2 changes: 2 additions & 0 deletions src/librawspeed/decoders/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ FILE(GLOB SOURCES
"SimpleTiffDecoder.h"
"SrwDecoder.cpp"
"SrwDecoder.h"
"StiDecoder.cpp"
"StiDecoder.h"
"ThreefrDecoder.cpp"
"ThreefrDecoder.h"
)
Expand Down
97 changes: 97 additions & 0 deletions src/librawspeed/decoders/StiDecoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
RawSpeed - RAW file decoder.

Copyright (C) 2023 Roman Lebedev

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "decoders/StiDecoder.h"
#include "adt/Point.h" // for iPoint2D
#include "decoders/RawDecoderException.h" // for ThrowException
#include "decompressors/HasselbladLJpegDecoder.h" // for HasselbladLJpegDec...
#include "decompressors/UncompressedDecompressor.h" // for UncompressedDeco...
#include "io/Buffer.h" // for Buffer, DataBuffer
#include "io/ByteStream.h" // for ByteStream
#include "io/Endianness.h" // for Endianness, Endian...
#include "metadata/ColorFilterArray.h" // for CFAColor, CFAColor...
#include "tiff/TiffEntry.h" // for TiffEntry
#include "tiff/TiffIFD.h" // for TiffRootIFD, TiffIFD
#include "tiff/TiffTag.h" // for TiffTag, TiffTag::...
#include <array> // for array
#include <cstdint> // for uint32_t
#include <memory> // for unique_ptr, allocator
#include <string> // for operator==, string

namespace rawspeed {

class CameraMetaData;

bool StiDecoder::isAppropriateDecoder(const TiffRootIFD* rootIFD,
[[maybe_unused]] Buffer file) {
const auto id = rootIFD->getID();
const std::string& make = id.make;

// FIXME: magic

return make == "Sinar AG";
}

RawImage StiDecoder::decodeRawInternal() {
const auto* raw = mRootIFD->getIFDWithTag(TiffTag::TILEOFFSETS, 0);
uint32_t width = raw->getEntry(TiffTag::IMAGEWIDTH)->getU32();
uint32_t height = raw->getEntry(TiffTag::IMAGELENGTH)->getU32();
uint32_t compression = raw->getEntry(TiffTag::COMPRESSION)->getU32();

Check warning on line 56 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L52-L56

Added lines #L52 - L56 were not covered by tests

mRaw->dim = iPoint2D(width, height);

Check warning on line 58 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L58

Added line #L58 was not covered by tests

if (1 != compression)
ThrowRDE("Unexpected compression type.");

Check warning on line 61 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L61

Added line #L61 was not covered by tests

DecodeUncompressed(raw);
return mRaw;

Check warning on line 64 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L63-L64

Added lines #L63 - L64 were not covered by tests
}

void StiDecoder::DecodeUncompressed(const TiffIFD* raw) const {

Check warning on line 67 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L67

Added line #L67 was not covered by tests
if (mRaw->getDataType() != RawImageType::UINT16)
ThrowRDE("Unexpected data type");

Check warning on line 69 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L69

Added line #L69 was not covered by tests

if (mRaw->getCpp() != 1 || mRaw->getBpp() != sizeof(uint16_t))
ThrowRDE("Unexpected cpp: %u", mRaw->getCpp());

Check warning on line 72 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L72

Added line #L72 was not covered by tests

// FIXME: could be wrong.
if (!mRaw->dim.hasPositiveArea() || mRaw->dim.x % 2 != 0 ||
mRaw->dim.y % 2 != 0 || mRaw->dim.x > 4992 || mRaw->dim.y > 6668) {
LebedevRI marked this conversation as resolved.
Show resolved Hide resolved
ThrowRDE("Unexpected image dimensions found: (%u; %u)", mRaw->dim.x,

Check warning on line 77 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L76-L77

Added lines #L76 - L77 were not covered by tests
mRaw->dim.y);
}

uint32_t off = raw->getEntry(TiffTag::TILEOFFSETS)->getU32();
uint32_t count = raw->getEntry(TiffTag::TILEBYTECOUNTS)->getU32();

Check warning on line 82 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L81-L82

Added lines #L81 - L82 were not covered by tests

const ByteStream bs(
DataBuffer(mFile.getSubView(off, count), Endianness::little));

Check warning on line 85 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L84-L85

Added lines #L84 - L85 were not covered by tests

UncompressedDecompressor u(bs, mRaw, iRectangle2D({0, 0}, mRaw->dim),
2 * mRaw->dim.x, 16, BitOrder::MSB);
mRaw->createData();
u.readUncompressedRaw();

Check warning on line 90 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L87-L90

Added lines #L87 - L90 were not covered by tests
}

void StiDecoder::decodeMetaDataInternal(const CameraMetaData* meta) {
setMetaData(meta, "", 0);

Check warning on line 94 in src/librawspeed/decoders/StiDecoder.cpp

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.cpp#L93-L94

Added lines #L93 - L94 were not covered by tests
}

} // namespace rawspeed
48 changes: 48 additions & 0 deletions src/librawspeed/decoders/StiDecoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
RawSpeed - RAW file decoder.

Copyright (C) 2023 Roman Lebedev

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include "common/RawImage.h" // for RawImage
#include "decoders/AbstractTiffDecoder.h" // for AbstractTiffDecoder
#include "io/Buffer.h" // for Buffer
#include "tiff/TiffIFD.h" // for TiffRootIFD (ptr only)
#include <utility> // for move

namespace rawspeed {

class Buffer;
class CameraMetaData;

class StiDecoder final : public AbstractTiffDecoder {
public:
static bool isAppropriateDecoder(const TiffRootIFD* rootIFD, Buffer file);
StiDecoder(TiffRootIFDOwner&& root, Buffer file)
: AbstractTiffDecoder(std::move(root), file) {}

Check warning on line 38 in src/librawspeed/decoders/StiDecoder.h

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.h#L37-L38

Added lines #L37 - L38 were not covered by tests

RawImage decodeRawInternal() override;
void decodeMetaDataInternal(const CameraMetaData* meta) override;

private:
[[nodiscard]] int getDecoderVersion() const override { return 0; }

Check warning on line 44 in src/librawspeed/decoders/StiDecoder.h

View check run for this annotation

Codecov / codecov/patch

src/librawspeed/decoders/StiDecoder.h#L44

Added line #L44 was not covered by tests
void DecodeUncompressed(const TiffIFD* raw) const;
};

} // namespace rawspeed
4 changes: 3 additions & 1 deletion src/librawspeed/parsers/TiffParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "decoders/PefDecoder.h" // for PefDecoder
#include "decoders/Rw2Decoder.h" // for Rw2Decoder
#include "decoders/SrwDecoder.h" // for SrwDecoder
#include "decoders/StiDecoder.h" // for StiDecoder
#include "decoders/ThreefrDecoder.h" // for ThreefrDecoder
#include "io/Buffer.h" // for Buffer, DataBuffer
#include "io/ByteStream.h" // for ByteStream
Expand Down Expand Up @@ -120,7 +121,7 @@ std::unique_ptr<RawDecoder> TiffParser::constructor(TiffRootIFDOwner&& root,
}

const std::array<std::pair<TiffParser::checker_t, TiffParser::constructor_t>,
16>
17>
TiffParser::Map = {{
DECODER(DngDecoder),
DECODER(MosDecoder),
Expand All @@ -137,6 +138,7 @@ const std::array<std::pair<TiffParser::checker_t, TiffParser::constructor_t>,
DECODER(DcsDecoder),
DECODER(KdcDecoder),
DECODER(ErfDecoder),
DECODER(StiDecoder),
DECODER(ThreefrDecoder),

}};
Expand Down
2 changes: 1 addition & 1 deletion src/librawspeed/parsers/TiffParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TiffParser final : public RawParser {
using checker_t = bool (*)(const TiffRootIFD* root, Buffer data);
using constructor_t = std::unique_ptr<RawDecoder> (*)(TiffRootIFDOwner&& root,
Buffer data);
static const std::array<std::pair<checker_t, constructor_t>, 16> Map;
static const std::array<std::pair<checker_t, constructor_t>, 17> Map;
};

} // namespace rawspeed
Loading