21#include "rawspeedconfig.h"
49DeflateDecompressor::DeflateDecompressor(
Buffer bs,
RawImage img,
int predictor,
51 : input(bs), mRaw(std::move(img)), bps(bps_) {
63 ThrowRDE(
"Unsupported predictor %i", predictor);
65 predFactor *= mRaw->getCpp();
73 int bytesps,
int factor) {
74 for (
int col = factor; col < realTileWidth * bytesps; ++col) {
78 src(col) =
static_cast<unsigned char>(src(col) + src(col - factor));
84template <
typename T>
struct StorageType final {};
85template <>
struct StorageType<ieee_754_2008::Binary16> {
86 using type = uint16_t;
87 static constexpr int padding_bytes = 0;
89template <>
struct StorageType<ieee_754_2008::Binary24> {
90 using type = uint32_t;
91 static constexpr int padding_bytes = 1;
93template <>
struct StorageType<ieee_754_2008::Binary32> {
94 using type = uint32_t;
95 static constexpr int padding_bytes = 0;
102 int realTileWidth, CroppedArray1DRef<float> out) {
103 using storage_type =
typename StorageType<T>::type;
104 constexpr unsigned storage_bytes =
sizeof(storage_type);
105 constexpr unsigned bytesps = T::StorageWidth / 8;
107 for (
int col = 0; col < out.size(); ++col) {
108 std::array<unsigned char, storage_bytes> bytes;
109 for (
int c = 0; c != bytesps; ++c)
110 bytes[c] = src(col + (c * realTileWidth));
113 tmp >>= CHAR_BIT * StorageType<T>::padding_bytes;
119 tmp_expanded = extendBinaryFloatingPoint<T, ieee_754_2008::Binary32>(tmp);
125 __builtin_unreachable();
128 out(col) = std::bit_cast<float>(tmp_expanded);
135void DeflateDecompressor::decode(std::unique_ptr<
unsigned char[]>* uBuffer,
137 int bytesps = bps / 8;
144 *uBuffer = std::unique_ptr<unsigned char[]>(
new unsigned char[dstLen]);
147 Array2DRef<unsigned char> tmp(uBuffer->get(), bytesps * maxDim.
x, maxDim.
y);
150 uncompress(uBuffer->get(), &dstLen, input.begin(), input.getSize());
152 ThrowRDE(
"failed to uncompress tile: %d (%s)", err, zError(err));
156 mRaw->getF32DataAsUncroppedArray2DRef(), off.
x,
159 for (
int row = 0; row < out.croppedHeight; ++row) {
160 decodeDeltaBytes(tmp[row], maxDim.
x, bytesps, predFactor);
164 decodeFPDeltaRow<ieee_754_2008::Binary16>(tmp[row], maxDim.
x, out[row]);
167 decodeFPDeltaRow<ieee_754_2008::Binary24>(tmp[row], maxDim.
x, out[row]);
170 decodeFPDeltaRow<ieee_754_2008::Binary32>(tmp[row], maxDim.
x, out[row]);
173 __builtin_unreachable();
183 "ZLIB is not present! Deflate compression will not be supported!"
T getBE(const void *data)
iPoint2D dim(rawspeed::implicit_cast< int >(ceil(sqSide *sqARatio)), rawspeed::implicit_cast< int >(ceil(sqSide/sqARatio)))
area_type RAWSPEED_READONLY area() const
CroppedArray2DRef(Array2DRef< T > base_, int offsetCols_, int offsetRows_, int croppedWidth_, int croppedHeight_) -> CroppedArray2DRef< typename Array2DRef< T >::value_type >
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)