|
33 | 33 | #include "bitstreams/BitStreamer.h" |
34 | 34 | #include "bitstreams/BitStreamerMSB.h" // IWYU pragma: keep |
35 | 35 | #include "bitstreams/BitStreams.h" |
| 36 | +#include "codes/AbstractPrefixCode.h" |
| 37 | +#include "codes/AbstractPrefixCodeDecoder.h" |
36 | 38 | #include "common/Common.h" |
37 | 39 | #include "common/RawImage.h" |
38 | 40 | #include "common/RawspeedException.h" |
@@ -340,30 +342,18 @@ int32_t inline PanasonicV8Decompressor::InternalHuffDecoder:: |
340 | 342 | // Retrieve the difference category, which indicates magnitude of the |
341 | 343 | // difference between the predicted and actual value. |
342 | 344 | const auto next16 = uint16_t(mBitPump.peekBits(16)); |
343 | | - const auto& [bits, diffCat] = mLUT(next16); |
344 | | - if (diffCat == 0 && bits == 7) |
| 345 | + const auto& [codeLen, codeValue] = mLUT(next16); |
| 346 | + if (codeValue == 0 && codeLen == 7) |
345 | 347 | ThrowRDE("Huffman decoding encountered an invalid value!"); |
346 | | - mBitPump.skipBits(bits); // Skip the bits that encoded the difference category |
347 | | - |
348 | | - if (diffCat > 0) { |
349 | | - // Decode difference value. The scheme here encodes signed integers in a |
350 | | - // manner similar to offset binary encoding. Here, the encoding is biased by |
351 | | - // the difference category such that abs(diff) is in the range |
352 | | - // [2^{diffCat-1}, 2^{diffCat}). |
353 | | - const uint32_t rawDiffBits = mBitPump.getBits(diffCat); |
354 | | - const uint32_t sign = rawDiffBits >> (diffCat - 1); |
355 | | - const uint32_t val = rawDiffBits << 0; |
356 | | - |
357 | | - // In comments below, n = diffCat |
358 | | - if (sign == 1) |
359 | | - // Positive value in range [2^{n-1}, 2^{n}) |
360 | | - return val; |
361 | | - // Negative value in interval (-2^{n}, -2^{n-1}] |
362 | | - return static_cast<int32_t>(val) + static_cast<int32_t>(~0U << diffCat) + 1; |
363 | | - } |
364 | | - // diffBitCount of zero indicates no difference (next pixel is same as |
365 | | - // predicted) |
366 | | - return 0; |
| 348 | + mBitPump.skipBits( |
| 349 | + codeLen); // Skip the bits that encoded the difference category |
| 350 | + int diffLen = codeValue; |
| 351 | + |
| 352 | + if (diffLen == 0) |
| 353 | + return 0; |
| 354 | + |
| 355 | + const uint32_t diff = mBitPump.getBits(diffLen); |
| 356 | + return AbstractPrefixCodeDecoder<BaselineCodeTag>::extend(diff, diffLen); |
367 | 357 | } |
368 | 358 |
|
369 | 359 | } // namespace rawspeed |
0 commit comments