Grok  7.6.6
PacketIter.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  * This source code incorporates work covered by the BSD 2-clause license.
18  * Please see the LICENSE file in the root directory for details.
19  *
20  */
21 
22 #pragma once
23 namespace grk {
24 
34  FINAL_PASS = 1
35 };
36 
37 
38 /***
39  * Packet iterator resolution
40  */
42  uint32_t pdx, pdy;
43  uint32_t pw, ph;
44 };
45 
49 struct grk_pi_comp {
50  uint32_t dx, dy;
52  uint32_t numresolutions;
54 };
55 
56 struct ResBuf;
57 struct IncludeTracker;
58 struct PacketIter;
59 
62 /* ----------------------------------------------------------------------- */
75  CodingParams *cp,
76  uint16_t tileno,
77  J2K_T2_MODE t2_mode,
78  IncludeTracker *include);
79 
87 void pi_update_encoding_parameters(const GrkImage *p_image,
88  CodingParams *p_cp,
89  uint16_t tile_no);
90 
102  CodingParams *cp,
103  uint16_t tileno,
104  uint32_t pino,
105  bool first_poc_tile_part,
106  uint32_t tppos,
107  J2K_T2_MODE t2_mode);
108 
119  CodingParams *cp,
120  uint16_t tileno,
121  IncludeTracker *include);
127 void pi_destroy(PacketIter *p_pi);
128 
129 
130 struct ResBuf{
132  for (uint8_t i = 0; i < GRK_J2K_MAXRLVLS; ++i)
133  buffers[i]=nullptr;
134  }
136  for (uint8_t i = 0; i < GRK_J2K_MAXRLVLS; ++i)
137  delete[] buffers[i];
138  }
139 
140 
142 };
144 
145  IncludeTracker(uint16_t numcomponents) : numcomps(numcomponents),
146  currentLayer(0),
147  currentResBuf(nullptr),
148  include(new std::map<uint16_t, ResBuf*>())
149  {}
150 
152  clear();
153  delete include;
154  }
155 
156  uint8_t* get_include(uint16_t layerno, uint8_t resno){
157  ResBuf* resBuf = nullptr;
158  if (layerno == currentLayer && currentResBuf) {
159  resBuf = currentResBuf;
160  } else {
161  if (include->find(layerno) == include->end()){
162  resBuf = new ResBuf;
163  include->operator[](layerno) = resBuf;
164  } else {
165  resBuf = include->operator[](layerno);
166  }
167  currentResBuf = resBuf;
168  currentLayer = layerno;
169  }
170  auto buf = resBuf->buffers[resno];
171  if (!buf){
172  auto numprecs = precincts[resno];
173  auto len = (numprecs * numcomps + 7)/8;
174  buf = new uint8_t[len];
175  memset(buf, 0, len);
176  resBuf->buffers[resno] = buf;
177  }
178  return buf;
179  }
180 
181 
182  bool update(uint16_t layno, uint8_t resno, uint16_t compno, uint64_t precno) {
183  auto include = get_include(layno, resno);
184  auto numprecs = precincts[resno];
185  uint64_t index = compno * numprecs + precno;
186  uint64_t include_index = (index >> 3);
187  uint32_t shift = (index & 7);
188  bool rc = false;
189  uint8_t val = include[include_index];
190  if ( ((val >> shift)& 1) == 0 ) {
191  include[include_index] = (uint8_t)(val | (1 << shift));
192  rc = true;
193  }
194 
195  return rc;
196  }
197 
198  void clear() {
199  for (auto it = include->begin(); it != include->end(); ++it){
200  delete it->second;
201  }
202  include->clear();
203  }
204 
205  uint16_t numcomps;
206  uint16_t currentLayer;
209  std::map<uint16_t, ResBuf*> *include;
210 };
211 
212 
213 
217 struct PacketIter {
218  PacketIter();
219  ~PacketIter();
220 
221  uint8_t* get_include(uint16_t layerIndex);
222  bool update_include(void);
223  void destroy_include(void);
224 
229  bool next_cprl(void);
230 
231  bool generate_precinct_index(void);
232 
237  bool next_pcrl(void);
238 
243  bool next_lrcp(void);
248  bool next_rlcp(void);
253  bool next_rpcl(void);
254 
260  bool next(void);
261 
262  void update_dxy(void);
263  void update_dxy_for_comp(grk_pi_comp *comp);
264 
265 
267  bool tp_on;
268 
270 
272  uint64_t step_l;
274  uint64_t step_r;
276  uint64_t step_c;
278  uint32_t step_p;
280  uint16_t compno;
282  uint8_t resno;
284  uint64_t precinctIndex;
286  uint16_t layno;
288  bool first;
291  uint32_t numpocs;
293  uint16_t numcomps;
297  uint32_t tx0, ty0, tx1, ty1;
299  uint32_t x, y;
301  uint32_t dx, dy;
302 };
303 
304 
305 /* ----------------------------------------------------------------------- */
309 
310 }
Definition: GrkImage.h:11
#define GRK_J2K_MAXRLVLS
Maximum number of resolution levels authorized.
Definition: grok.h:82
Copyright (C) 2016-2021 Grok Image Compression Inc.
Definition: BitIO.cpp:23
PacketIter * pi_create_compress(const GrkImage *image, CodingParams *p_cp, uint16_t tile_no, J2K_T2_MODE p_t2_mode, IncludeTracker *include)
Creates a packet iterator for compressing.
Definition: PacketIter.cpp:455
const double shift
Definition: RateControl.cpp:154
J2K_T2_MODE
Definition: PacketIter.h:32
@ FINAL_PASS
Function called in rate allocation process.
Definition: PacketIter.h:34
@ THRESH_CALC
Definition: PacketIter.h:33
void pi_enable_tile_part_generation(PacketIter *pi, CodingParams *cp, uint16_t tileno, uint32_t pino, bool first_poc_tile_part, uint32_t tppos, J2K_T2_MODE t2_mode)
Modify the packet iterator for enabling tile part generation.
Definition: PacketIter.cpp:596
PacketIter * pi_create_decompress(GrkImage *image, CodingParams *p_cp, uint16_t tile_no, IncludeTracker *include)
Create a packet iterator for Decoder.
Definition: PacketIter.cpp:307
void pi_update_encoding_parameters(const GrkImage *image, CodingParams *p_cp, uint16_t tileno)
Updates the compressing parameters of the codec.
Definition: PacketIter.cpp:865
void pi_destroy(PacketIter *p_pi)
Destroys a packet iterator array.
Definition: PacketIter.cpp:858
Progression order change.
Definition: grok.h:377
Coding parameters.
Definition: CodingParams.h:238
Definition: PacketIter.h:143
uint8_t * get_include(uint16_t layerno, uint8_t resno)
Definition: PacketIter.h:156
~IncludeTracker()
Definition: PacketIter.h:151
uint64_t precincts[GRK_J2K_MAXRLVLS]
Definition: PacketIter.h:208
ResBuf * currentResBuf
Definition: PacketIter.h:207
uint16_t numcomps
Definition: PacketIter.h:205
std::map< uint16_t, ResBuf * > * include
Definition: PacketIter.h:209
bool update(uint16_t layno, uint8_t resno, uint16_t compno, uint64_t precno)
Definition: PacketIter.h:182
uint16_t currentLayer
Definition: PacketIter.h:206
void clear()
Definition: PacketIter.h:198
IncludeTracker(uint16_t numcomponents)
Definition: PacketIter.h:145
Packet iterator.
Definition: PacketIter.h:217
uint32_t tx1
Definition: PacketIter.h:297
bool tp_on
Enabling Tile part generation.
Definition: PacketIter.h:267
void destroy_include(void)
Definition: PacketIter.cpp:1314
uint32_t ty0
Definition: PacketIter.h:297
bool next_rlcp(void)
Get next packet in resolution-layer-component-precinct order.
Definition: PacketIter.cpp:1144
bool next_cprl(void)
Get next packet in component-precinct-resolution-layer order.
Definition: PacketIter.cpp:964
uint32_t ty1
Definition: PacketIter.h:297
uint8_t * get_include(uint16_t layerIndex)
Definition: PacketIter.cpp:1306
uint32_t step_p
precinct step used to localize the packet in the include vector
Definition: PacketIter.h:278
uint16_t layno
layer that identify the packet
Definition: PacketIter.h:286
bool next(void)
Modify the packet iterator to point to the next packet.
Definition: PacketIter.cpp:1268
uint32_t y
Definition: PacketIter.h:299
bool next_rpcl(void)
Get next packet in resolution-precinct-component-layer order.
Definition: PacketIter.cpp:1203
uint32_t dy
Definition: PacketIter.h:301
uint16_t compno
component that identify the packet
Definition: PacketIter.h:280
bool generate_precinct_index(void)
Definition: PacketIter.cpp:1003
bool update_include(void)
Definition: PacketIter.cpp:1310
uint32_t x
packet coordinates
Definition: PacketIter.h:299
grk_progression prog
progression order change information
Definition: PacketIter.h:290
IncludeTracker * includeTracker
Definition: PacketIter.h:269
bool first
true if the first packet
Definition: PacketIter.h:288
uint32_t tx0
tile coordinates
Definition: PacketIter.h:297
uint32_t numpocs
Definition: PacketIter.h:291
uint32_t dx
packet sub-sampling factors
Definition: PacketIter.h:301
void update_dxy_for_comp(grk_pi_comp *comp)
Definition: PacketIter.cpp:1294
bool next_lrcp(void)
Get next packet in layer-resolution-component-precinct order.
Definition: PacketIter.cpp:1089
uint64_t precinctIndex
precinct that identify the packet
Definition: PacketIter.h:284
grk_pi_comp * comps
Components.
Definition: PacketIter.h:295
bool next_pcrl(void)
Get next packet in precinct-component-resolution-layer order.
Definition: PacketIter.cpp:1053
uint8_t resno
resolution that identify the packet
Definition: PacketIter.h:282
uint64_t step_l
layer step used to localize the packet in the include vector
Definition: PacketIter.h:272
uint64_t step_r
resolution step used to localize the packet in the include vector
Definition: PacketIter.h:274
uint64_t step_c
component step used to localize the packet in the include vector
Definition: PacketIter.h:276
PacketIter()
Definition: PacketIter.cpp:930
void update_dxy(void)
Definition: PacketIter.cpp:1287
uint16_t numcomps
number of components in the image
Definition: PacketIter.h:293
~PacketIter()
Definition: PacketIter.cpp:956
Definition: PacketIter.h:130
~ResBuf()
Definition: PacketIter.h:135
ResBuf()
Definition: PacketIter.h:131
uint8_t * buffers[GRK_J2K_MAXRLVLS]
Definition: PacketIter.h:141
Packet iterator component.
Definition: PacketIter.h:49
uint32_t dx
Definition: PacketIter.h:50
uint32_t dy
Definition: PacketIter.h:50
grk_pi_resolution * resolutions
Definition: PacketIter.h:53
uint32_t numresolutions
number of resolution levels
Definition: PacketIter.h:52
Definition: PacketIter.h:41
uint32_t pdx
Definition: PacketIter.h:42
uint32_t pw
Definition: PacketIter.h:43
uint32_t ph
Definition: PacketIter.h:43
uint32_t pdy
Definition: PacketIter.h:42