RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
AbstractPrefixCodeEncoder.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2024 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#pragma once
22
23#include "rawspeedconfig.h"
24#include "adt/Bit.h"
26#include <cstdint>
27#include <utility>
28
29namespace rawspeed {
30
31template <typename CodeTag>
33public:
35
36 using Tag = typename Base::Tag;
37 using Parent = typename Base::Parent;
38 using CodeSymbol = typename Base::CodeSymbol;
39 using Traits = typename Base::Traits;
40
41 using Base::Base;
42
43 void setup(bool fullDecode_, bool fixDNGBug16_) {
44 Base::setup(fullDecode_, fixDNGBug16_);
45 }
46
47 static std::pair<uint32_t, uint8_t>
48 RAWSPEED_READNONE reduce(int32_t extendedDiff) {
49 if (extendedDiff >= 0) {
50 auto diff = static_cast<uint32_t>(extendedDiff);
51 return {diff, numActiveBits(diff)};
52 }
53 --extendedDiff;
54 auto diff = static_cast<uint32_t>(extendedDiff);
55 int len = numSignificantBits(diff) - 1;
56 diff = extractLowBitsSafe(diff, len);
57 return {diff, len};
58 }
59};
60
61} // namespace rawspeed
AbstractPrefixCodeTranscoder< CodeTag > Base
void setup(bool fullDecode_, bool fixDNGBug16_)
static std::pair< uint32_t, uint8_t > RAWSPEED_READNONE reduce(int32_t extendedDiff)
typename AbstractPrefixCode< CodeTag >::Traits Traits
typename AbstractPrefixCode< CodeTag >::CodeSymbol CodeSymbol
AbstractPrefixCodeTranscoder(PrefixCode< CodeTag > code_)
void setup(bool fullDecode_, bool fixDNGBug16_)
constexpr RAWSPEED_READNONE T extractLowBitsSafe(T value, unsigned nBits)
Definition Bit.h:110
unsigned numSignificantBits(const T v)
Definition Bit.h:68
unsigned numActiveBits(const T v)
Definition Bit.h:56