Grok 20.3.2
StripPartitioner.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 <cstdint>
21#include <vector>
22#include <algorithm>
23
24namespace grk
25{
26
31{
32 uint32_t lo = 0;
33 uint32_t hi = 0;
34 uint32_t count() const
35 {
36 return hi - lo;
37 }
38};
39
47{
48 // Output rows in interleaved domain (no halo)
49 uint32_t outStart = 0;
50 uint32_t outCount = 0;
51
52 // Extended interleaved range (with halo, clamped to image bounds)
53 uint32_t extFirst = 0;
54 uint32_t extLast = 0;
55
56 // Sub-band row ranges needed (L = LL/HL, H = LH/HH)
59
60 // Local parity for V-DWT lifting
61 uint32_t localParity = 0;
62
63 // Output row offset within the extended stripe
64 uint32_t outputStartInStripe = 0;
65};
66
76{
77public:
89 static std::vector<StripGeometry> partition(uint32_t resHeight, uint32_t sn, uint32_t dn,
90 uint32_t parity, uint32_t stripeInterleaved = 64,
91 uint32_t halo = 4)
92 {
93 if(resHeight == 0)
94 return {};
95
96 uint32_t numStripes = (resHeight + stripeInterleaved - 1) / stripeInterleaved;
97 uint32_t haloInterleaved = 2 * halo;
98
99 std::vector<StripGeometry> strips;
100 strips.reserve(numStripes);
101
102 for(uint32_t s = 0; s < numStripes; ++s)
103 {
104 StripGeometry sg;
105 sg.outStart = s * stripeInterleaved;
106 sg.outCount = std::min(stripeInterleaved, resHeight - sg.outStart);
107
108 // Extended range with halo (clamped to image bounds)
109 sg.extFirst = (sg.outStart >= haloInterleaved) ? sg.outStart - haloInterleaved : 0;
110 sg.extLast = std::min(sg.outStart + sg.outCount - 1 + haloInterleaved, resHeight - 1);
111
112 // Map interleaved range to sub-band row ranges
113 if(parity == 0)
114 {
115 sg.rangeL.lo = (sg.extFirst + 1) / 2;
116 sg.rangeL.hi = sg.extLast / 2 + 1;
117 sg.rangeH.lo = sg.extFirst / 2;
118 sg.rangeH.hi = (sg.extLast + 1) / 2;
119 }
120 else
121 {
122 sg.rangeH.lo = (sg.extFirst + 1) / 2;
123 sg.rangeH.hi = sg.extLast / 2 + 1;
124 sg.rangeL.lo = sg.extFirst / 2;
125 sg.rangeL.hi = (sg.extLast + 1) / 2;
126 }
127
128 // Clamp to actual sub-band sizes
129 sg.rangeL.hi = std::min(sg.rangeL.hi, sn);
130 sg.rangeH.hi = std::min(sg.rangeH.hi, dn);
131
132 // Local parity
133 sg.localParity = (sg.extFirst & 1) ^ parity;
134
135 // Output offset within extended stripe
137
138 strips.push_back(sg);
139 }
140
141 return strips;
142 }
143
153 static void findOverlappingBlocks(uint32_t bandY0, const SubbandRange& range,
154 const std::vector<uint32_t>& blockY0s,
155 const std::vector<uint32_t>& blockHeights,
156 std::vector<uint32_t>& blockIndices)
157 {
158 blockIndices.clear();
159 for(uint32_t i = 0; i < blockY0s.size(); ++i)
160 {
161 uint32_t relY0 = blockY0s[i] - bandY0;
162 uint32_t relY1 = relY0 + blockHeights[i];
163 // Check overlap with [range.lo, range.hi)
164 if(relY1 > range.lo && relY0 < range.hi)
165 blockIndices.push_back(i);
166 }
167 }
168};
169
170} // namespace grk
Computes strip geometry for cascade DWT at a given resolution.
Definition StripPartitioner.h:76
static void findOverlappingBlocks(uint32_t bandY0, const SubbandRange &range, const std::vector< uint32_t > &blockY0s, const std::vector< uint32_t > &blockHeights, std::vector< uint32_t > &blockIndices)
Find code blocks (by sub-band-relative y range) that overlap a sub-band range.
Definition StripPartitioner.h:153
static std::vector< StripGeometry > partition(uint32_t resHeight, uint32_t sn, uint32_t dn, uint32_t parity, uint32_t stripeInterleaved=64, uint32_t halo=4)
Compute strip geometries for a resolution level.
Definition StripPartitioner.h:89
ResWindow.
Definition CompressedChunkCache.h:36
Geometry for a single cascade DWT strip at a given resolution.
Definition StripPartitioner.h:47
uint32_t extFirst
Definition StripPartitioner.h:53
SubbandRange rangeL
Definition StripPartitioner.h:57
uint32_t localParity
Definition StripPartitioner.h:61
uint32_t outStart
Definition StripPartitioner.h:49
uint32_t outputStartInStripe
Definition StripPartitioner.h:64
SubbandRange rangeH
Definition StripPartitioner.h:58
uint32_t extLast
Definition StripPartitioner.h:54
uint32_t outCount
Definition StripPartitioner.h:50
Sub-band row range needed by a strip (inclusive begin, exclusive end).
Definition StripPartitioner.h:31
uint32_t hi
Definition StripPartitioner.h:33
uint32_t count() const
Definition StripPartitioner.h:34
uint32_t lo
Definition StripPartitioner.h:32