Grok 20.3.2
ResSimple.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#pragma once
19
20#include "t1_common.h"
21
22namespace grk
23{
24
25struct ResSimple : public Rect32
26{
29 {
30 setRect(res);
31 this->numTileBandWindows = numTileBandWindows;
32 for(uint8_t i = 0; i < numTileBandWindows; i++)
33 this->tileBand[i] = tileBand[i];
34 }
35 ResSimple(Rect32 currentRes, bool finalResolution)
36 {
37 setRect(currentRes);
38 if(finalResolution)
39 {
41 tileBand[0] = currentRes;
42 }
43 else
44 {
46 for(uint8_t j = 0; j < numTileBandWindows; ++j)
47 tileBand[j] = getBandWindow(1, j + 1, currentRes);
48 }
49 }
50
60 static Rect32 getBandWindow(uint8_t numDecomps, uint8_t orientation,
61 Rect32 tileCompWindowUnreduced)
62 {
63 assert(orientation < t1::BAND_NUM_ORIENTATIONS);
64 if(numDecomps == 0)
65 return tileCompWindowUnreduced;
66
67 /* project window onto sub-band generated by `numDecomps` decompositions */
68 /* See equation B-15 of the standard. */
69 uint32_t bx0 = orientation & 1;
70 uint32_t by0 = (uint32_t)(orientation >> 1U);
71
72 uint32_t bx0Offset = (1U << (numDecomps - 1)) * bx0;
73 uint32_t by0Offset = (1U << (numDecomps - 1)) * by0;
74
75 uint32_t tc_originx0 = tileCompWindowUnreduced.origin_x0;
76 uint32_t tc_originy0 = tileCompWindowUnreduced.origin_y0;
77 uint32_t tcx0 = tileCompWindowUnreduced.x0;
78 uint32_t tcy0 = tileCompWindowUnreduced.y0;
79 uint32_t tcx1 = tileCompWindowUnreduced.x1;
80 uint32_t tcy1 = tileCompWindowUnreduced.y1;
81
82 return Rect32(
83 (tc_originx0 <= bx0Offset) ? 0 : ceildivpow2<uint32_t>(tc_originx0 - bx0Offset, numDecomps),
84 (tc_originy0 <= by0Offset) ? 0 : ceildivpow2<uint32_t>(tc_originy0 - by0Offset, numDecomps),
85 (tcx0 <= bx0Offset) ? 0 : ceildivpow2<uint32_t>(tcx0 - bx0Offset, numDecomps),
86 (tcy0 <= by0Offset) ? 0 : ceildivpow2<uint32_t>(tcy0 - by0Offset, numDecomps),
87 (tcx1 <= bx0Offset) ? 0 : ceildivpow2<uint32_t>(tcx1 - bx0Offset, numDecomps),
88 (tcy1 <= by0Offset) ? 0 : ceildivpow2<uint32_t>(tcy1 - by0Offset, numDecomps));
89 }
90
91 Rect32 tileBand[t1::BAND_NUM_INDICES]; // unreduced tile component bands in canvas coordinates
92 uint8_t numTileBandWindows; // 1 or 3
93};
94
95} // namespace grk
@ BAND_NUM_ORIENTATIONS
Definition t1_common.h:33
@ BAND_NUM_INDICES
Definition t1_common.h:44
ResWindow.
Definition CompressedChunkCache.h:36
Rect< uint32_t > Rect32
Definition geometry.h:64
T ceildivpow2(T a, uint8_t b)
Definition intmath.h:39
T x1
Definition geometry.h:192
T origin_x0
Definition geometry.h:191
void setRect(const Rect *rhs)
Definition geometry.h:297
T origin_y0
Definition geometry.h:191
T x0
Definition geometry.h:192
T y0
Definition geometry.h:192
T y1
Definition geometry.h:192
static Rect32 getBandWindow(uint8_t numDecomps, uint8_t orientation, Rect32 tileCompWindowUnreduced)
Get band window (in tile component coordinates) for specified number of decompositions.
Definition ResSimple.h:60
ResSimple(Rect32 *res, uint8_t numTileBandWindows, Rect32(&tileBand)[t1::BAND_NUM_INDICES])
Definition ResSimple.h:28
ResSimple(Rect32 currentRes, bool finalResolution)
Definition ResSimple.h:35
Rect32 tileBand[t1::BAND_NUM_INDICES]
Definition ResSimple.h:91
ResSimple(void)
Definition ResSimple.h:27
uint8_t numTileBandWindows
Definition ResSimple.h:92