RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
PanasonicV5Decompressor.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2018 Roman Lebedev
5 Copyright (C) 2018 Stefan Hoffmeister
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#pragma once
23
24#include "adt/Point.h"
26#include "common/RawImage.h"
28#include "io/ByteStream.h"
29#include <cstdint>
30#include <vector>
31
32namespace rawspeed {
33
35 // The RW2 raw image buffer consists of individual blocks,
36 // each one BlockSize bytes in size.
37 static constexpr uint32_t BlockSize = 0x4000;
38
39 // These blocks themselves comprise of two sections,
40 // split and swapped at section_split_offset:
41 // bytes: [0..sectionSplitOffset-1][sectionSplitOffset..BlockSize-1]
42 // pixels: [a..b][0..a-1]
43 // When reading, these two sections need to be swapped to enable linear
44 // processing..
45 static constexpr uint32_t sectionSplitOffset = 0x1FF8;
46
47 // The blocks themselves consist of packets with fixed size of bytesPerPacket,
48 // and each packet decodes to pixelsPerPacket pixels, which depends on bps.
49 static constexpr uint32_t bytesPerPacket = 16;
50 static constexpr uint32_t bitsPerPacket = 8 * bytesPerPacket;
51 static_assert(BlockSize % bytesPerPacket == 0);
53
54 // Contains the decoding recepie for the packet,
55 struct PacketDsc;
56
57 // There are two variants. Which one is to be used depends on image's bps.
60
61 // Takes care of unsplitting&swapping back the block at sectionSplitOffset.
62 class ProxyStream;
63
65
66 // The full input buffer, containing all the blocks.
68
70
72
73 struct Block final {
76 // The rectangle is an incorrect representation. All the rows
77 // between the first and last one span the entire width of the image.
79
80 Block() = default;
81 Block(ByteStream bs_, iPoint2D beginCoord_, iPoint2D endCoord_)
82 : bs(bs_), beginCoord(beginCoord_), endCoord(endCoord_) {}
83 };
84
85 // If really wanted, this vector could be avoided,
86 // and each Block computed on-the-fly
87 std::vector<Block> blocks;
88
89 void chopInputIntoBlocks(const PacketDsc& dsc);
90
91 template <const PacketDsc& dsc>
92 inline void processPixelPacket(BitStreamerLSB& bs, int row, int col) const;
93
94 template <const PacketDsc& dsc> void processBlock(const Block& block) const;
95
96 template <const PacketDsc& dsc> void decompressInternal() const noexcept;
97
98public:
100
101 void decompress() const noexcept;
102};
103
104} // namespace rawspeed
void processBlock(const Block &block) const
static constexpr uint32_t sectionSplitOffset
static constexpr uint32_t PacketsPerBlock
void chopInputIntoBlocks(const PacketDsc &dsc)
PanasonicV5Decompressor(RawImage img, ByteStream input_, uint32_t bps_)
void processPixelPacket(BitStreamerLSB &bs, int row, int col) const
Block(ByteStream bs_, iPoint2D beginCoord_, iPoint2D endCoord_)