Grok  9.7.5
Subband.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2022 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 grk_rect32
45 {
47  // note: don't copy precinct array
48  Subband(const Subband& rhs)
50  stepsize(rhs.stepsize)
51  {}
52  virtual ~Subband() = default;
53  Subband& operator=(const Subband& rhs)
54  {
55  if(this != &rhs)
56  { // self-assignment check expected
57  *this = Subband(rhs);
58  }
59  return *this;
60  }
61  void print() const override
62  {
64  }
65  bool empty()
66  {
67  return ((x1 - x0 == 0) || (y1 - y0 == 0));
68  }
69  Precinct* getPrecinct(uint64_t precinctIndex)
70  {
71  if(precinctMap.find(precinctIndex) == precinctMap.end())
72  return nullptr;
73  uint64_t index = precinctMap[precinctIndex];
74 
75  return precincts[index];
76  }
77  grk_rect32 generatePrecinctBounds(uint64_t precinctIndex, grk_pt32 precinctPartitionTopLeft,
78  grk_pt32 precinctExpn, uint32_t precinctGridWidth)
79  {
80  auto precinctTopLeft =
81  grk_pt32(precinctPartitionTopLeft.x +
82  (uint32_t)((precinctIndex % precinctGridWidth) << precinctExpn.x),
83  precinctPartitionTopLeft.y +
84  (uint32_t)((precinctIndex / precinctGridWidth) << precinctExpn.y));
85  return grk_rect32(precinctTopLeft.x, precinctTopLeft.y,
86  precinctTopLeft.x + (1U << precinctExpn.x),
87  precinctTopLeft.y + (1U << precinctExpn.y))
88  .intersection(this);
89  }
90  Precinct* createPrecinct(bool isCompressor, uint64_t precinctIndex,
91  grk_pt32 precinctPartitionTopLeft, grk_pt32 precinctExpn,
92  uint32_t precinctGridWidth, grk_pt32 cblk_expn)
93  {
94  auto temp = precinctMap.find(precinctIndex);
95  if(temp != precinctMap.end())
96  return precincts[temp->second];
97 
98  auto bounds = generatePrecinctBounds(precinctIndex, precinctPartitionTopLeft, precinctExpn,
99  precinctGridWidth);
100  if(!bounds.valid())
101  {
102  GRK_ERROR("createPrecinct: invalid precinct bounds.");
103  return nullptr;
104  }
105  auto currPrec = new Precinct(bounds, isCompressor, cblk_expn);
106  currPrec->precinctIndex = precinctIndex;
107  precincts.push_back(currPrec);
108  precinctMap[precinctIndex] = precincts.size() - 1;
109 
110  return currPrec;
111  }
113  std::vector<Precinct*> precincts;
114  // maps global precinct index to precincts vector index
115  std::map<uint64_t, uint64_t> precinctMap;
116  uint64_t numPrecincts;
117  uint8_t numbps;
118  float stepsize;
119 };
120 
121 } // namespace grk
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
grk_pt< uint32_t > grk_pt32
Definition: util.h:37
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:58
grk_rect< uint32_t > grk_rect32
Definition: util.h:57
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:172
Definition: Subband.h:45
void print() const override
Definition: Subband.h:61
Precinct * createPrecinct(bool isCompressor, uint64_t precinctIndex, grk_pt32 precinctPartitionTopLeft, grk_pt32 precinctExpn, uint32_t precinctGridWidth, grk_pt32 cblk_expn)
Definition: Subband.h:90
eBandOrientation orientation
Definition: Subband.h:112
bool empty()
Definition: Subband.h:65
virtual ~Subband()=default
Subband & operator=(const Subband &rhs)
Definition: Subband.h:53
Subband(const Subband &rhs)
Definition: Subband.h:48
float stepsize
Definition: Subband.h:118
grk_rect32 generatePrecinctBounds(uint64_t precinctIndex, grk_pt32 precinctPartitionTopLeft, grk_pt32 precinctExpn, uint32_t precinctGridWidth)
Definition: Subband.h:77
uint8_t numbps
Definition: Subband.h:117
std::vector< Precinct * > precincts
Definition: Subband.h:113
Precinct * getPrecinct(uint64_t precinctIndex)
Definition: Subband.h:69
std::map< uint64_t, uint64_t > precinctMap
Definition: Subband.h:115
Subband()
Definition: Subband.h:46
uint64_t numPrecincts
Definition: Subband.h:116
T x
Definition: util.h:34
T y
Definition: util.h:35
uint32_t y1
Definition: util.h:109
uint32_t x0
Definition: util.h:109
uint32_t x1
Definition: util.h:109
grk_rect< T > intersection(const grk_rect< T > rhs) const
Definition: util.h:200
virtual void print(void) const
Definition: util.h:111
uint32_t y0
Definition: util.h:109