Grok  9.5.0
Subband.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2021 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 #pragma once
18 
19 #include "grk_includes.h"
20 #include <map>
21 
22 namespace grk
23 {
25 {
31 };
32 // LL band index when resolution == 0
33 const uint32_t BAND_RES_ZERO_INDEX_LL = 0;
34 
35 // band indices when resolution > 0
37 {
42 };
43 
44 struct Subband : public grkRectU32
45 {
47  // note: don't copy precinct array
48  Subband(const Subband& rhs)
50  stepsize(rhs.stepsize)
51  {}
52  Subband& operator=(const Subband& rhs)
53  {
54  if(this != &rhs)
55  { // self-assignment check expected
56  *this = Subband(rhs);
57  }
58  return *this;
59  }
60  void print()
61  {
63  }
64  bool isEmpty()
65  {
66  return ((x1 - x0 == 0) || (y1 - y0 == 0));
67  }
68  Precinct* getPrecinct(uint64_t precinctIndex)
69  {
70  if(precinctMap.find(precinctIndex) == precinctMap.end())
71  return nullptr;
72  uint64_t index = precinctMap[precinctIndex];
73 
74  return precincts[index];
75  }
76  grkRectU32 generatePrecinctBounds(uint64_t precinctIndex, grkPointU32 precinctRegionStart,
77  grkPointU32 precinct_expn, uint32_t precinctGridWidth)
78  {
79  auto precinctStart =
80  grkPointU32(precinctRegionStart.x +
81  (uint32_t)((precinctIndex % precinctGridWidth) << precinct_expn.x),
82  precinctRegionStart.y +
83  (uint32_t)((precinctIndex / precinctGridWidth) << precinct_expn.y));
84  return grkRectU32(precinctStart.x, precinctStart.y,
85  precinctStart.x + (1U << precinct_expn.x),
86  precinctStart.y + (1U << precinct_expn.y))
87  .intersection(this);
88  }
89  Precinct* createPrecinct(bool isCompressor, uint64_t precinctIndex,
90  grkPointU32 precinctRegionStart, grkPointU32 precinct_expn,
91  uint32_t precinctGridWidth, grkPointU32 cblk_expn)
92  {
93  auto temp = precinctMap.find(precinctIndex);
94  if(temp != precinctMap.end())
95  return precincts[temp->second];
96 
97  auto bandPrecinctBounds = generatePrecinctBounds(precinctIndex, precinctRegionStart,
98  precinct_expn, precinctGridWidth);
99  auto currPrec = new Precinct(bandPrecinctBounds, isCompressor, cblk_expn);
100  currPrec->precinctIndex = precinctIndex;
101  precincts.push_back(currPrec);
102  precinctMap[precinctIndex] = precincts.size() - 1;
103 
104  return currPrec;
105  }
107  std::vector<Precinct*> precincts;
108  // maps global precinct index to vector index
109  std::map<uint64_t, uint64_t> precinctMap;
110  uint64_t numPrecincts;
111  uint8_t numbps;
112  float stepsize;
113 };
114 
115 } // namespace grk
Copyright (C) 2016-2021 Grok Image Compression Inc.
Definition: ICacheable.h:20
grkRect< uint32_t > grkRectU32
Definition: util.h:56
grkPoint< uint32_t > grkPointU32
Definition: util.h:37
eBandOrientation
Definition: Subband.h:25
@ BAND_ORIENT_HH
Definition: Subband.h:29
@ BAND_ORIENT_HL
Definition: Subband.h:27
@ BAND_NUM_ORIENTATIONS
Definition: Subband.h:30
@ BAND_ORIENT_LH
Definition: Subband.h:28
@ BAND_ORIENT_LL
Definition: Subband.h:26
eBandIndex
Definition: Subband.h:37
@ BAND_INDEX_HL
Definition: Subband.h:38
@ BAND_INDEX_LH
Definition: Subband.h:39
@ BAND_NUM_INDICES
Definition: Subband.h:41
@ BAND_INDEX_HH
Definition: Subband.h:40
const uint32_t BAND_RES_ZERO_INDEX_LL
Definition: Subband.h:33
Definition: Precinct.h:165
Definition: Subband.h:45
grkRectU32 generatePrecinctBounds(uint64_t precinctIndex, grkPointU32 precinctRegionStart, grkPointU32 precinct_expn, uint32_t precinctGridWidth)
Definition: Subband.h:76
eBandOrientation orientation
Definition: Subband.h:106
Precinct * createPrecinct(bool isCompressor, uint64_t precinctIndex, grkPointU32 precinctRegionStart, grkPointU32 precinct_expn, uint32_t precinctGridWidth, grkPointU32 cblk_expn)
Definition: Subband.h:89
Subband & operator=(const Subband &rhs)
Definition: Subband.h:52
Subband(const Subband &rhs)
Definition: Subband.h:48
void print()
Definition: Subband.h:60
float stepsize
Definition: Subband.h:112
uint8_t numbps
Definition: Subband.h:111
bool isEmpty()
Definition: Subband.h:64
std::vector< Precinct * > precincts
Definition: Subband.h:107
Precinct * getPrecinct(uint64_t precinctIndex)
Definition: Subband.h:68
std::map< uint64_t, uint64_t > precinctMap
Definition: Subband.h:109
Subband()
Definition: Subband.h:46
uint64_t numPrecincts
Definition: Subband.h:110
T x
Definition: util.h:34
T y
Definition: util.h:35
uint32_t x1
Definition: util.h:96
uint32_t y0
Definition: util.h:96
void print(void) const
Definition: util.h:107
grkRect< T > intersection(const grkRect< T > rhs) const
Definition: util.h:173
uint32_t y1
Definition: util.h:96
uint32_t x0
Definition: util.h:96