Grok 12.0.1
ResWindow.h
Go to the documentation of this file.
17#pragma once
18
19#include "grk_includes.h"
20#include <stdexcept>
21#include <algorithm>
22
23/*
24 Various coordinate systems are used to describe regions in the tile component buffer.
25
26 1) Canvas coordinates: JPEG 2000 global image coordinates.
27
28 2) Tile component coordinates: canvas coordinates with sub-sampling applied
29
30 3) Band coordinates: coordinates relative to a specified sub-band's origin
31
32 4) Buffer coordinates: coordinate system where all resolutions are translated
33 to common origin (0,0). If each code block is translated relative to the origin of the
34 resolution that **it belongs to**, the blocks are then all in buffer coordinate system
35
36 Note: the name of any method or variable returning non canvas coordinates is appended
37 with "REL", to signify relative coordinates.
38
39 */
40
41namespace grk
42{
43
50
51template<typename T>
52struct TileComponentWindow;
53template<typename T>
54struct TileComponentWindowBase;
55
68template<typename T>
70{
71 friend struct TileComponentWindowBase<T>;
72 friend struct TileComponentWindow<T>;
74
75 private:
86 {
89 (resno == 0) ? (uint8_t)(numresolutions - 1U) : (uint8_t)(numresolutions - resno);
91 for(uint8_t orient = 0; orient < ((resno) > 0 ? BAND_NUM_ORIENTATIONS : 1); orient++)
92 {
93 // todo: should only need padding equal to FILTER_WIDTH, not 2*FILTER_WIDTH
94 auto bandWindow =
98 if(resno > 0)
101 bandWindow.setOrigin(band, true);
102 assert(bandWindow.intersection(band).setOrigin(bandWindow, true) == bandWindow);
104 }
105 // windowed decompression
106 if(FILTER_WIDTH)
107 {
109 {
110 assert(resno > 0);
114
116 {
120 new Buf2dAligned(bandWindow.toRelative(), true));
121 }
128 }
129 }
130 else
131 {
132 assert(tileCompAtRes_.numTileBandWindows == 3 || !tileCompAtLowerRes.numTileBandWindows);
133
134 // dummy LL band window
136 {
137 bandWindowsBuffersPadded_.push_back(new Buf2dAligned(0, 0));
138 bandWindowsBuffersPaddedREL_.push_back(new Buf2dAligned(0, 0));
140 {
142
143 auto band = grk_rect32(tileCompBand);
144 bandWindowsBuffersPadded_.push_back(new Buf2dAligned(band));
145 bandWindowsBuffersPaddedREL_.push_back(new Buf2dAligned(band.toRelative()));
146 }
147 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; i++)
148 {
150 split.y0 =
151 (resWindowBuffer_->y0 == 0 ? 0
153 split.y1 =
154 (resWindowBuffer_->y1 == 0 ? 0
158 }
159 }
160 }
161 }
163 {
164 delete resWindowBufferREL_;
166 delete b;
167 for(uint32_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
169
170 delete resWindowBuffer_;
171 for(auto& b : bandWindowsBuffersPadded_)
172 delete b;
173 for(uint32_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
174 delete resWindowBufferSplit_[i];
175 }
204 bool alloc(bool clear)
205 {
206 if(allocated_)
207 return true;
208
209 // if top level window is present, then all buffers attach to this window
211 {
212 // ensure that top level window is allocated
214 return false;
215
216 // don't allocate bandWindows for windowed decompression
217 if(filterWidth_)
218 return true;
219
220 // attach to top level window
223
224 // tileCompResLower_ is null for lowest resolution
226 {
227 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
228 ++orientation)
229 {
230 switch(orientation)
231 {
232 case BAND_ORIENT_HL:
233 bandWindowsBuffersPaddedREL_[orientation]->attach(
235 break;
236 case BAND_ORIENT_LH:
237 bandWindowsBuffersPaddedREL_[orientation]->attach(
239 break;
240 case BAND_ORIENT_HH:
241 bandWindowsBuffersPaddedREL_[orientation]->attach(
244 break;
245 default:
246 break;
247 }
248 }
252 }
253
254 // attach canvas windows to relative windows
255 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
256 ++orientation)
257 {
258 bandWindowsBuffersPadded_[orientation]->attach(
259 bandWindowsBuffersPaddedREL_[orientation]);
260 }
262 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
263 {
266 }
267 }
268 else
269 {
270 // 1. allocate resolution window
271 // resolution window is always allocated
272 if(!resWindowBufferREL_->alloc2d(clear))
273 return false;
275
276 // 2, allocate padded band windows
277 // band windows are allocated if present
278 for(auto& b : bandWindowsBuffersPadded_)
279 {
280 if(!b->alloc2d(clear))
281 return false;
282 }
283 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
284 ++orientation)
285 {
286 bandWindowsBuffersPaddedREL_[orientation]->attach(
287 bandWindowsBuffersPaddedREL_[orientation]);
288 }
289
290 // 3. allocate split windows
292 {
294 {
298 }
299 else
300 {
303 }
304 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
305 {
308 }
309 }
310 }
311
312 allocated_ = true;
313
314 return true;
315 }
316
328 {
329 assert(orientation < BAND_NUM_ORIENTATIONS);
330 if(numDecomps == 0)
331 {
332 assert(orientation == 0);
333 return unreducedTileCompWindow.grow_IN_PLACE(padding).intersection(&unreducedTileComp);
334 }
337 if(numDecomps > 1)
338 {
341 }
342 paddedResWindow.grow_IN_PLACE(2 * padding).clip_IN_PLACE(&oneLessDecompTile);
343 paddedResWindow.setOrigin(oneLessDecompTile, true);
344
345 return ResSimple::getBandWindow(1, orientation, paddedResWindow);
346 }
347
361 {
362 return resWindowBufferSplitREL_[orientation];
363 }
365 {
366 return &bandWindowsBoundsPadded_[orientation];
367 }
369 {
370 return bandWindowsBuffersPaddedREL_[orientation];
371 }
374 {
375 return bandWindowsBuffersPadded_[orientation]->simple();
376 }
379 {
380 return bandWindowsBuffersPadded_[orientation]->simpleF();
381 }
383 {
384 return resWindowBufferREL_;
385 }
388
389 ResSimple tileCompAtRes_; // numTileBandWindows> 0 will trigger creation of band window buffers
390 ResSimple tileCompAtLowerRes_; // numTileBandWindows==0 for lowest resolution
391
394 std::vector<Buf2dAligned*> bandWindowsBuffersPadded_;
395
396 /*
397 bandWindowsBoundsPadded_ is used for determining which precincts and code blocks overlap
398 the window of interest, in each respective resolution
399 */
400 std::vector<grk_rect32> bandWindowsBoundsPadded_;
401
405 std::vector<Buf2dAligned*> bandWindowsBuffersPaddedREL_;
406};
407
408} // namespace grk
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition ICacheable.h:20
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk_rect< uint32_t > grk_rect32
Definition geometry.h:61
eSplitOrientation
Definition ResWindow.h:45
@ SPLIT_H
Definition ResWindow.h:47
@ SPLIT_L
Definition ResWindow.h:46
@ SPLIT_NUM_ORIENTATIONS
Definition ResWindow.h:48
eBandOrientation
Definition ResSimple.h:23
@ BAND_ORIENT_HH
Definition ResSimple.h:27
@ BAND_ORIENT_HL
Definition ResSimple.h:25
@ BAND_NUM_ORIENTATIONS
Definition ResSimple.h:28
@ BAND_ORIENT_LH
Definition ResSimple.h:26
@ BAND_ORIENT_LL
Definition ResSimple.h:24
Definition ResSimple.h:43
grk_rect32 tileBand[BAND_NUM_INDICES]
Definition ResSimple.h:110
uint8_t numTileBandWindows
Definition ResSimple.h:111
static grk_rect32 getBandWindow(uint8_t numDecomps, uint8_t orientation, grk_rect32 tileCompWindowUnreduced)
Get band window (in tile component coordinates) for specified number of decompositions.
Definition ResSimple.h:77
ResWindow.
Definition ResWindow.h:70
void genSplitWindowBuffers(Buf2dAligned **resWindowBufferSplit, Buf2dAligned *resWindowBuffer, Buf2dAligned *bandWindowsBuffersPaddedXL, Buf2dAligned *bandWindowsBuffersPaddedXH, bool absolute)
Definition ResWindow.h:176
uint32_t filterWidth_
Definition ResWindow.h:387
grk_buf2d_simple< float > getResWindowBufferSimpleF(void) const
Definition ResWindow.h:352
ResSimple tileCompAtRes_
Definition ResWindow.h:389
ResWindow(uint8_t numresolutions, uint8_t resno, Buf2dAligned *resWindowHighestResREL, ResSimple tileCompAtRes, ResSimple tileCompAtLowerRes, grk_rect32 resWindow, grk_rect32 tileCompWindowUnreduced, grk_rect32 tileCompUnreduced, uint32_t FILTER_WIDTH)
Definition ResWindow.h:76
const grk_rect32 * getBandWindowPadded(eBandOrientation orientation) const
Definition ResWindow.h:364
Buf2dAligned * resWindowBufferSplit_[SPLIT_NUM_ORIENTATIONS]
Definition ResWindow.h:393
bool allocated_
Definition ResWindow.h:386
Buf2dAligned * resWindowBufferHighestResREL_
Definition ResWindow.h:402
std::vector< Buf2dAligned * > bandWindowsBuffersPadded_
Definition ResWindow.h:394
const grk_buf2d_simple< float > getBandWindowBufferPaddedSimpleF(eBandOrientation orientation) const
Definition ResWindow.h:378
~ResWindow()
Definition ResWindow.h:162
const grk_buf2d_simple< int32_t > getBandWindowBufferPaddedSimple(eBandOrientation orientation) const
Definition ResWindow.h:373
Buf2dAligned * resWindowBufferSplitREL_[SPLIT_NUM_ORIENTATIONS]
Definition ResWindow.h:404
grk_buf2d_simple< int32_t > getResWindowBufferSimple(void) const
Definition ResWindow.h:348
Buf2dAligned * getResWindowBufferSplitREL(eSplitOrientation orientation) const
Definition ResWindow.h:360
Buf2dAligned * resWindowBufferREL_
Definition ResWindow.h:403
void disableBandWindowAllocation(void)
Definition ResWindow.h:356
std::vector< grk_rect32 > bandWindowsBoundsPadded_
Definition ResWindow.h:400
ResSimple tileCompAtLowerRes_
Definition ResWindow.h:390
static grk_rect32 getPaddedBandWindow(uint8_t numDecomps, uint8_t orientation, grk_rect32 unreducedTileCompWindow, grk_rect32 unreducedTileComp, uint32_t padding, grk_rect32 &paddedResWindow)
Get band window (in tile component coordinates) for specified number of decompositions (with padding)
Definition ResWindow.h:324
Buf2dAligned * resWindowBuffer_
Definition ResWindow.h:392
bool alloc(bool clear)
Definition ResWindow.h:204
Buf2dAligned * getResWindowBufferREL(void) const
Definition ResWindow.h:382
grk_buf2d< T, AllocatorAligned > Buf2dAligned
Definition ResWindow.h:73
const Buf2dAligned * getBandWindowBufferPaddedREL(eBandOrientation orientation) const
Definition ResWindow.h:368
std::vector< Buf2dAligned * > bandWindowsBuffersPaddedREL_
Definition ResWindow.h:405
Definition TileComponentWindow.h:54
Definition TileComponentWindow.h:160
Definition buffer.h:206
Definition buffer.h:230
void attach(T *buffer, uint32_t strd)
Definition buffer.h:293
bool alloc2d(bool clear)
Definition buffer.h:271
grk_buf2d_simple< float > simpleF(void) const
Definition buffer.h:252
grk_buf2d_simple< T > simple(void) const
Definition buffer.h:248
T width() const
Definition geometry.h:335
T y1
Definition geometry.h:124
grk_rect< T > & setOrigin(T origx, T origy, bool absolute)
Definition geometry.h:126
grk_rect< T > & toRelative(void)
Definition geometry.h:156
T height() const
Definition geometry.h:339
bool valid(void) const
Definition geometry.h:185
grk_rect< T > & toAbsolute(void)
Definition geometry.h:166
void setRect(grk_rect< T > *rhs)
Definition geometry.h:228
T y0
Definition geometry.h:124