Grok  10.0.3
Precinct.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 #pragma once
17 #include "grk_includes.h"
18 
19 namespace grk
20 {
21 template<typename T, typename P>
22 class BlockCache : public SparseCache<T>
23 {
24  public:
25  BlockCache(uint16_t numLayers, uint64_t maxChunkSize, P* blockInitializer)
26  : SparseCache<T>(maxChunkSize), blockInitializer_(blockInitializer), numLayers_(numLayers)
27  {}
28  virtual ~BlockCache() = default;
29 
30  protected:
31  virtual T* create(uint64_t index) override
32  {
33  auto item = new T(numLayers_);
34  blockInitializer_->initCodeBlock(item, index);
35  return item;
36  }
37 
38  private:
40  uint16_t numLayers_;
41 };
42 
44 {
45  PrecinctImpl(bool isCompressor, grk_rect32* bounds, grk_pt32 cblk_expn);
46  ~PrecinctImpl(void);
47  grk_rect32 getCodeBlockBounds(uint64_t cblkno);
48  bool initCodeBlocks(uint16_t numLayers, grk_rect32* bounds);
49  template<typename T>
50  bool initCodeBlock(T* block, uint64_t cblkno);
51  void deleteTagTrees();
60 
61  private:
62  TagTreeU16* incltree; /* inclusion tree */
63  TagTreeU8* imsbtree; /* IMSB tree */
64 };
65 struct Precinct : public grk_rect32
66 {
67  Precinct(TileProcessor* tileProcessor, const grk_rect32& bounds, grk_pt32 cblk_expn);
68  virtual ~Precinct();
69  void deleteTagTrees();
70  grk_rect32 getCodeBlockBounds(uint64_t cblkno);
71  TagTreeU16* getInclTree(void);
72  TagTreeU8* getImsbTree(void);
73  uint32_t getCblkGridwidth(void);
74  uint32_t getCblkGridHeight(void);
75  uint32_t getNominalBlockSize(void);
76  uint64_t getNumCblks(void);
77  CompressCodeblock* getCompressedBlockPtr(uint64_t cblkno);
80  grk_pt32 getCblkExpn(void);
81  grk_rect32 getCblkGrid(void);
82  uint64_t precinctIndex;
83  uint16_t numLayers_;
84 
85  private:
89  {
91  return impl;
92  }
93 };
94 
95 } // namespace grk
Definition: Precinct.h:23
BlockCache(uint16_t numLayers, uint64_t maxChunkSize, P *blockInitializer)
Definition: Precinct.h:25
uint16_t numLayers_
Definition: Precinct.h:40
virtual ~BlockCache()=default
P * blockInitializer_
Definition: Precinct.h:39
virtual T * create(uint64_t index) override
Definition: Precinct.h:31
Definition: SparseCache.h:25
Tag tree.
Definition: TagTree.h:47
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
Definition: Codeblock.h:142
Definition: Codeblock.h:201
Definition: Precinct.h:66
grk_pt32 cblk_expn_
Definition: Precinct.h:87
uint32_t getCblkGridHeight(void)
Definition: Precinct.cpp:165
uint16_t numLayers_
Definition: Precinct.h:83
uint64_t getNumCblks(void)
Definition: Precinct.cpp:173
TagTreeU16 * getInclTree(void)
Definition: Precinct.cpp:153
PrecinctImpl * impl
Definition: Precinct.h:86
Precinct(TileProcessor *tileProcessor, const grk_rect32 &bounds, grk_pt32 cblk_expn)
Definition: Precinct.cpp:135
TagTreeU8 * getImsbTree(void)
Definition: Precinct.cpp:157
uint32_t getNominalBlockSize(void)
Definition: Precinct.cpp:169
virtual ~Precinct()
Definition: Precinct.cpp:141
DecompressCodeblock * getDecompressedBlockPtr(uint64_t cblkno)
Definition: Precinct.cpp:181
CompressCodeblock * getCompressedBlockPtr(uint64_t cblkno)
Definition: Precinct.cpp:177
DecompressCodeblock * tryGetDecompressedBlockPtr(uint64_t cblkno)
Definition: Precinct.cpp:185
uint64_t precinctIndex
Definition: Precinct.h:82
grk_rect32 getCblkGrid(void)
Definition: Precinct.cpp:193
void deleteTagTrees()
Definition: Precinct.cpp:145
uint32_t getCblkGridwidth(void)
Definition: Precinct.cpp:161
grk_pt32 getCblkExpn(void)
Definition: Precinct.cpp:189
grk_rect32 getCodeBlockBounds(uint64_t cblkno)
Definition: Precinct.cpp:149
PrecinctImpl * getImpl(void)
Definition: Precinct.h:88
Definition: Precinct.h:44
PrecinctImpl(bool isCompressor, grk_rect32 *bounds, grk_pt32 cblk_expn)
Definition: Precinct.cpp:21
TagTreeU16 * getIncludeTagTree(void)
Definition: Precinct.cpp:84
grk_rect32 bounds_
Definition: Precinct.h:57
grk_pt32 cblk_expn_
Definition: Precinct.h:58
TagTreeU8 * imsbtree
Definition: Precinct.h:63
bool initCodeBlocks(uint16_t numLayers, grk_rect32 *bounds)
Definition: Precinct.cpp:51
bool isCompressor_
Definition: Precinct.h:59
grk_rect32 cblk_grid_
Definition: Precinct.h:56
grk_rect32 getCodeBlockBounds(uint64_t cblkno)
Definition: Precinct.cpp:41
BlockCache< CompressCodeblock, PrecinctImpl > * enc
Definition: Precinct.h:54
bool initCodeBlock(T *block, uint64_t cblkno)
Definition: Precinct.cpp:67
void deleteTagTrees()
Definition: Precinct.cpp:77
TagTreeU16 * incltree
Definition: Precinct.h:62
BlockCache< DecompressCodeblock, PrecinctImpl > * dec
Definition: Precinct.h:55
~PrecinctImpl(void)
Definition: Precinct.cpp:35
TagTreeU8 * getIMsbTagTree(void)
Definition: Precinct.cpp:109
Definition: TileProcessor.h:78