RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
PanasonicV8Decompressor.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2022-2024 LibRaw LLC (info@libraw.org)
5 Copyright (C) 2024 Daniel Vogelbacher
6 Copyright (C) 2025 Kolton Yager
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*/
22
23#pragma once
24
25#include "adt/Array1DRef.h"
27#include "adt/Array2DRef.h"
29#include "common/RawImage.h"
32#include "io/ByteStream.h"
33#include <array>
34#include <cstdint>
35#include <vector>
36
37namespace rawspeed {
38
49private:
51
52public:
54 using Bayer2x2 = std::array<uint16_t, 4>;
55
56 // Pre-cached decoded values for rapid lookup.
58 uint8_t bitcount = 7;
59 uint8_t diffCat = 0;
60
61 [[nodiscard]] bool isSentinel() const {
62 constexpr auto sentinel = DecoderLUTEntry();
63 return bitcount == sentinel.bitcount && diffCat == sentinel.diffCat;
64 }
65 };
66
69 struct DecompressorParamsBuilder;
70
91
94 const std::vector<PanasonicV8Decompressor::DecoderLUTEntry> mDecoderLUT;
97
98 const std::vector<iRectangle2D> mOutRects;
99
100 std::vector<PanasonicV8Decompressor::DecoderLUTEntry> static getDecoderLUT(
101 ByteStream bs);
102
103 std::vector<iRectangle2D> static getOutRects(
105 Array1DRef<const uint16_t> stripWidths,
106 Array1DRef<const uint16_t> stripHeights);
107
108 // NOLINTNEXTLINE(readability-function-size)
110 iPoint2D imgSize_, Bayer2x2 initialPrediction_,
112 Array1DRef<const uint32_t> stripLineOffsets,
113 Array1DRef<const uint16_t> stripWidths,
114 Array1DRef<const uint16_t> stripHeights, ByteStream defineCodes)
115 : imgSize(imgSize_), mDecoderLUT(getDecoderLUT(defineCodes)),
116 mStrips(mStrips_), initialPrediction(initialPrediction_),
117 mOutRects(getOutRects(imgSize, stripLineOffsets, stripWidths,
118 stripHeights)) {
119 if (mStrips.size() != implicit_cast<int>(mOutRects.size()))
120 ThrowRDE("Got different number of input strips vs output tiles");
121 for (const auto& strip : mStrips_) {
122 if (strip.size() == 0)
123 ThrowRDE("Got empty input strip");
124 }
125 }
126
131 };
132
133private:
135
137 class InternalDecoder;
138
142
143public:
145
147 void decompress() const;
148};
149
150} // namespace rawspeed
#define ThrowRDE(...)
Utility class for Panasonic V8 entropy decoding.
std::array< uint16_t, 4 > Bayer2x2
Four values, one for each component of the sensor's color filter array.
void decompressStrip(Array2DRef< uint16_t > out, InternalDecoder decoder) const
PanasonicV8Decompressor(RawImage outputImg, DecompressorParams mParams_)
void decompress() const
Run the decompressor on the provided raw image.
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32
Array1DRef< const T > getAsArray1DRef(const std::vector< T > &vec)
uint8_t diffCat
uint8_t bitcount
bool isSentinel() const
static std::vector< iRectangle2D > getOutRects(iPoint2D imgSize, Array1DRef< const uint32_t > stripLineOffsets, Array1DRef< const uint16_t > stripWidths, Array1DRef< const uint16_t > stripHeights)
static std::vector< PanasonicV8Decompressor::DecoderLUTEntry > getDecoderLUT(ByteStream bs)
DecompressorParamsBuilder(iPoint2D imgSize_, Bayer2x2 initialPrediction_, Array1DRef< const Array1DRef< const uint8_t > > mStrips_, Array1DRef< const uint32_t > stripLineOffsets, Array1DRef< const uint16_t > stripWidths, Array1DRef< const uint16_t > stripHeights, ByteStream defineCodes)
const std::vector< PanasonicV8Decompressor::DecoderLUTEntry > mDecoderLUT
const Array1DRef< const Array1DRef< const uint8_t > > mStrips
DecompressorParams(iPoint2D imgSize_, Array1DRef< const Array1DRef< const uint8_t > > mStrips_, Array1DRef< const iRectangle2D > mOutRect_, Array1DRef< const DecoderLUTEntry > mDecoderLUT_, Bayer2x2 initialPrediction_)
const Array1DRef< const DecoderLUTEntry > mDecoderLUT
const Array1DRef< const Array1DRef< const uint8_t > > mStrips