RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
AbstractDngDecompressor.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2009-2014 Klaus Post
5 Copyright (C) 2017-2018 Roman Lebeedv
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/Casts.h"
25#include "adt/Invariant.h"
26#include "adt/Point.h"
27#include "common/Common.h"
28#include "common/RawImage.h"
30#include "io/ByteStream.h"
31#include <cstdint>
32#include <utility>
33#include <vector>
34
35namespace rawspeed {
36
38 // The dimensions of the whole image.
39 const iPoint2D& dim;
40
41 // How many horizontal pixels does one tile represent?
43
44 // How many vertical pixels does one tile represent?
46
47 // How many tiles per row is there?
49
50 // How many rows is there?
52
53 // How many tiles are there total?
54 const unsigned numTiles;
55
56 DngTilingDescription(const iPoint2D& dim_, uint32_t tileW_, uint32_t tileH_)
57 : dim(dim_), tileW(tileW_), tileH(tileH_),
61 invariant(dim.area() > 0);
62 invariant(tileW > 0);
63 invariant(tileH > 0);
64 invariant(tilesX > 0);
65 invariant(tilesY > 0);
66 invariant(tileW * tilesX >= static_cast<unsigned>(dim.x));
67 invariant(tileH * tilesY >= static_cast<unsigned>(dim.y));
68 invariant(tileW * (tilesX - 1) < static_cast<unsigned>(dim.x));
69 invariant(tileH * (tilesY - 1) < static_cast<unsigned>(dim.y));
71 }
72};
73
74struct DngSliceElement final {
76
77 // Which slice is this?
78 const unsigned n;
79
80 // The actual data of the tile.
82
83 // Which tile is this?
84 const unsigned column;
85 const unsigned row;
86
87 const bool lastColumn;
88 const bool lastRow;
89
90 // Where does it start?
91 const unsigned offX;
92 const unsigned offY;
93
94 // What's it's actual size?
95 const unsigned width;
96 const unsigned height;
97
98 DngSliceElement() = delete;
100 DngSliceElement(DngSliceElement&&) noexcept = default;
101 DngSliceElement& operator=(const DngSliceElement&) noexcept = delete;
102 DngSliceElement& operator=(DngSliceElement&&) noexcept = delete;
103
104 DngSliceElement(const DngTilingDescription& dsc_, unsigned n_, ByteStream bs_)
105 : dsc(dsc_), n(n_), bs(bs_), column(n % dsc.tilesX), row(n / dsc.tilesX),
106 lastColumn((column + 1) == dsc.tilesX),
107 lastRow((row + 1) == dsc.tilesY), offX(dsc.tileW * column),
108 offY(dsc.tileH * row),
109 width(!lastColumn ? dsc.tileW : dsc.dim.x - offX),
110 height(!lastRow ? dsc.tileH : dsc.dim.y - offY) {
111 invariant(n < dsc.numTiles);
112 invariant(bs.getRemainSize() > 0);
113 invariant(column < dsc.tilesX);
114 invariant(row < dsc.tilesY);
115 invariant(offX < static_cast<unsigned>(dsc.dim.x));
116 invariant(offY < static_cast<unsigned>(dsc.dim.y));
117 invariant(width > 0);
118 invariant(height > 0);
119 invariant(offX + width <= static_cast<unsigned>(dsc.dim.x));
120 invariant(offY + height <= static_cast<unsigned>(dsc.dim.y));
122 (offX + width == static_cast<unsigned>(dsc.dim.x)));
123 invariant(!lastRow || (offY + height == static_cast<unsigned>(dsc.dim.y)));
124 }
125};
126
129
130 template <int compression> void decompressThread() const noexcept;
131
132 void decompressThread() const noexcept;
133
134public:
136 int compression_, bool mFixLjpeg_, uint32_t mBps_,
137 uint32_t mPredictor_)
138 : mRaw(std::move(img)), dsc(dsc_), compression(compression_),
139 mFixLjpeg(mFixLjpeg_), mBps(mBps_), mPredictor(mPredictor_) {}
140
141 void decompress() const;
142
144
145 std::vector<DngSliceElement> slices;
146
147 const int compression;
148 const bool mFixLjpeg = false;
151};
152
153} // namespace rawspeed
#define invariant(expr)
Definition Invariant.h:27
iPoint2D dim(rawspeed::implicit_cast< int >(ceil(sqSide *sqARatio)), rawspeed::implicit_cast< int >(ceil(sqSide/sqARatio)))
Definition Common.cpp:55
dim y
Definition Common.cpp:51
dim x
Definition Common.cpp:50
std::vector< DngSliceElement > slices
AbstractDngDecompressor(RawImage img, const DngTilingDescription &dsc_, int compression_, bool mFixLjpeg_, uint32_t mBps_, uint32_t mPredictor_)
void decompressThread() const noexcept
constexpr uint64_t RAWSPEED_READNONE roundUpDivisionSafe(uint64_t value, uint64_t div)
Definition Common.h:145
constexpr RAWSPEED_READNONE Ttgt implicit_cast(Tsrc value)
Definition Casts.h:32
const DngTilingDescription & dsc
DngSliceElement(DngSliceElement &&) noexcept=default
DngSliceElement(const DngSliceElement &)=default
DngTilingDescription(const iPoint2D &dim_, uint32_t tileW_, uint32_t tileH_)