55 TagTree(uint32_t leavesWidth, uint32_t leavesHeight)
58 uint32_t resLeavesWidth[32];
59 uint32_t resLeavesHeight[32];
64 uint64_t nodesPerLevel;
69 grklog.error(
"TagTree constructor: num level overflow");
70 throw std::exception();
72 nodesPerLevel = (uint64_t)resLeavesWidth[numLevels] * resLeavesHeight[numLevels];
73 resLeavesWidth[numLevels + 1] = (uint32_t)(((uint64_t)resLeavesWidth[numLevels] + 1) >> 1);
74 resLeavesHeight[numLevels + 1] = (uint32_t)(((uint64_t)resLeavesHeight[numLevels] + 1) >> 1);
77 }
while(nodesPerLevel > 1);
81 grklog.warn(
"tgt_create numnodes == 0, no tree created.");
82 throw std::runtime_error(
"tgt_create numnodes == 0, no tree created");
86 auto currentNode =
nodes;
88 auto parentNodeNext = parentNode;
90 for(int8_t i = 0; i < numLevels - 1; ++i)
92 for(uint32_t j = 0; j < resLeavesHeight[i]; ++j)
94 int64_t k = resLeavesWidth[i];
97 currentNode->parent = parentNode;
101 currentNode->parent = parentNode;
106 if((j & 1) || j == resLeavesHeight[i] - 1)
108 parentNodeNext = parentNode;
112 parentNode = parentNodeNext;
113 parentNodeNext += resLeavesWidth[i];
117 currentNode->parent =
nullptr;
127 return (std::numeric_limits<T>::max)();
136 auto current_node =
nodes + i;
138 current_node->low = 0;
139 current_node->known =
false;
149 auto node =
nodes + leafno;
150 while(node && node->value > value)
166 auto nodeStackPtr = nodeStack;
167 auto node =
nodes + leafno;
170 *nodeStackPtr++ = node;
181 while(low < threshold)
183 if(low >= node->value)
198 if(nodeStackPtr == nodeStack)
200 node = *--nodeStackPtr;
215 auto nodeStackPtr = nodeStack;
216 auto node =
nodes + leafno;
220 *nodeStackPtr++ = node;
231 while(low < threshold && low < node->value)
241 if(nodeStackPtr == nodeStack)
243 node = *--nodeStackPtr;
245 *value = node->value;
void read(uint32_t *bits, uint8_t n) override
Read bits.
Definition BitIO.cpp:132
bool write(uint32_t v, uint32_t n) override
Write bits.
Definition BitIO.cpp:111
Tag tree.
Definition TagTree.h:47
uint64_t nodeCount
Definition TagTree.h:251
bool compress(BitIO *bio, uint64_t leafno, T threshold)
Encode the value of a leaf of the tag tree up to a given threshold.
Definition TagTree.h:163
TagTreeNode< uint8_t > * nodes
Definition TagTree.h:252
TagTree(uint32_t leavesWidth, uint32_t leavesHeight)
Create a tag tree.
Definition TagTree.h:55
void reset()
Reset a tag tree (set all leaves to 0)
Definition TagTree.h:132
void setvalue(uint64_t leafno, T value)
Set the value of a leaf of a tag tree.
Definition TagTree.h:147
~TagTree()
Definition TagTree.h:120
void decodeValue(BitIO *bio, uint64_t leafno, T threshold, T *value)
Decompress the value of a leaf of the tag tree up to a given threshold.
Definition TagTree.h:211
uint32_t leavesHeight_
Definition TagTree.h:250
uint32_t leavesWidth_
Definition TagTree.h:249
constexpr T getUninitializedValue(void)
Definition TagTree.h:125
Copyright (C) 2016-2025 Grok Image Compression Inc.
Definition ICacheable.h:20
TagTree< uint16_t > TagTreeU16
Definition TagTree.h:256
TagTree< uint8_t > TagTreeU8
Definition TagTree.h:255
Logger & grklog
Definition Logger.cpp:20
Tag node.
Definition TagTree.h:33
bool known
Definition TagTree.h:39
T low
Definition TagTree.h:38
TagTreeNode * parent
Definition TagTree.h:36
TagTreeNode()
Definition TagTree.h:34
T value
Definition TagTree.h:37