Grok 10.0.5
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 {
133 !tileCompAtLowerRes.numTileBandWindows);
134
135 // dummy LL band window
137 {
138 bandWindowsBuffersPadded_.push_back(new Buf2dAligned(0, 0));
139 bandWindowsBuffersPaddedREL_.push_back(new Buf2dAligned(0, 0));
141 {
143
144 auto band = grk_rect32(tileCompBand);
145 bandWindowsBuffersPadded_.push_back(new Buf2dAligned(band));
146 bandWindowsBuffersPaddedREL_.push_back(new Buf2dAligned(band.toRelative()));
147 }
148 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; i++)
149 {
151 split.y0 = (resWindowBuffer_->y0 == 0
152 ? 0
154 split.y1 = (resWindowBuffer_->y1 == 0
155 ? 0
159 }
160 }
161 }
162 }
164 {
165 delete resWindowBufferREL_;
167 delete b;
168 for(uint32_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
170
171 delete resWindowBuffer_;
172 for(auto& b : bandWindowsBuffersPadded_)
173 delete b;
174 for(uint32_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
175 delete resWindowBufferSplit_[i];
176 }
205 bool alloc(bool clear)
206 {
207 if(allocated_)
208 return true;
209
210 // if top level window is present, then all buffers attach to this window
212 {
213 // ensure that top level window is allocated
215 return false;
216
217 // don't allocate bandWindows for windowed decompression
218 if(filterWidth_)
219 return true;
220
221 // attach to top level window
224
225 // tileCompResLower_ is null for lowest resolution
227 {
228 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
229 ++orientation)
230 {
231 switch(orientation)
232 {
233 case BAND_ORIENT_HL:
234 bandWindowsBuffersPaddedREL_[orientation]->attach(
236 break;
237 case BAND_ORIENT_LH:
238 bandWindowsBuffersPaddedREL_[orientation]->attach(
240 break;
241 case BAND_ORIENT_HH:
242 bandWindowsBuffersPaddedREL_[orientation]->attach(
245 break;
246 default:
247 break;
248 }
249 }
253 }
254
255 // attach canvas windows to relative windows
256 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
257 ++orientation)
258 {
259 bandWindowsBuffersPadded_[orientation]->attach(
260 bandWindowsBuffersPaddedREL_[orientation]);
261 }
263 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
264 {
267 }
268 }
269 else
270 {
271 // 1. allocate resolution window
272 // resolution window is always allocated
273 if(!resWindowBufferREL_->alloc2d(clear))
274 return false;
276
277 // 2, allocate padded band windows
278 // band windows are allocated if present
279 for(auto& b : bandWindowsBuffersPadded_)
280 {
281 if(!b->alloc2d(clear))
282 return false;
283 }
284 for(uint8_t orientation = 0; orientation < bandWindowsBuffersPaddedREL_.size();
285 ++orientation)
286 {
287 bandWindowsBuffersPaddedREL_[orientation]->attach(
288 bandWindowsBuffersPaddedREL_[orientation]);
289 }
290
291 // 3. allocate split windows
293 {
295 {
299 }
300 else
301 {
304 }
305 for(uint8_t i = 0; i < SPLIT_NUM_ORIENTATIONS; ++i)
306 {
309 }
310 }
311 }
312
313 allocated_ = true;
314
315 return true;
316 }
317
348
362 {
363 return resWindowBufferSplitREL_[orientation];
364 }
366 {
367 return &bandWindowsBoundsPadded_[orientation];
368 }
370 {
371 return bandWindowsBuffersPaddedREL_[orientation];
372 }
375 {
376 return bandWindowsBuffersPadded_[orientation]->simple();
377 }
380 {
381 return bandWindowsBuffersPadded_[orientation]->simpleF();
382 }
384 {
385 return resWindowBufferREL_;
386 }
389
390 ResSimple tileCompAtRes_; // numTileBandWindows> 0 will trigger creation of band window buffers
391 ResSimple tileCompAtLowerRes_; // numTileBandWindows==0 for lowest resolution
392
395 std::vector<Buf2dAligned*> bandWindowsBuffersPadded_;
396
397 /*
398 bandWindowsBoundsPadded_ is used for determining which precincts and code blocks overlap
399 the window of interest, in each respective resolution
400 */
401 std::vector<grk_rect32> bandWindowsBoundsPadded_;
402
406 std::vector<Buf2dAligned*> bandWindowsBuffersPaddedREL_;
407};
408
409} // namespace grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
eSplitOrientation
Definition ResWindow.h:45
@ SPLIT_H
Definition ResWindow.h:47
@ SPLIT_L
Definition ResWindow.h:46
@ SPLIT_NUM_ORIENTATIONS
Definition ResWindow.h:48
grk_rect< uint32_t > grk_rect32
Definition geometry.h:61
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:177
uint32_t filterWidth_
Definition ResWindow.h:388
grk_buf2d_simple< float > getResWindowBufferSimpleF(void) const
Definition ResWindow.h:353
ResSimple tileCompAtRes_
Definition ResWindow.h:390
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:365
Buf2dAligned * resWindowBufferSplit_[SPLIT_NUM_ORIENTATIONS]
Definition ResWindow.h:394
bool allocated_
Definition ResWindow.h:387
Buf2dAligned * resWindowBufferHighestResREL_
Definition ResWindow.h:403
std::vector< Buf2dAligned * > bandWindowsBuffersPadded_
Definition ResWindow.h:395
const grk_buf2d_simple< float > getBandWindowBufferPaddedSimpleF(eBandOrientation orientation) const
Definition ResWindow.h:379
~ResWindow()
Definition ResWindow.h:163
const grk_buf2d_simple< int32_t > getBandWindowBufferPaddedSimple(eBandOrientation orientation) const
Definition ResWindow.h:374
Buf2dAligned * resWindowBufferSplitREL_[SPLIT_NUM_ORIENTATIONS]
Definition ResWindow.h:405
grk_buf2d_simple< int32_t > getResWindowBufferSimple(void) const
Definition ResWindow.h:349
Buf2dAligned * getResWindowBufferSplitREL(eSplitOrientation orientation) const
Definition ResWindow.h:361
Buf2dAligned * resWindowBufferREL_
Definition ResWindow.h:404
void disableBandWindowAllocation(void)
Definition ResWindow.h:357
std::vector< grk_rect32 > bandWindowsBoundsPadded_
Definition ResWindow.h:401
ResSimple tileCompAtLowerRes_
Definition ResWindow.h:391
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:325
Buf2dAligned * resWindowBuffer_
Definition ResWindow.h:393
bool alloc(bool clear)
Definition ResWindow.h:205
Buf2dAligned * getResWindowBufferREL(void) const
Definition ResWindow.h:383
grk_buf2d< T, AllocatorAligned > Buf2dAligned
Definition ResWindow.h:73
const Buf2dAligned * getBandWindowBufferPaddedREL(eBandOrientation orientation) const
Definition ResWindow.h:369
std::vector< Buf2dAligned * > bandWindowsBuffersPaddedREL_
Definition ResWindow.h:406
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