55 TagTree(uint32_t leavesWidth, uint32_t leavesHeight)
58 uint32_t resLeavesWidth[32];
59 uint32_t resLeavesHeight[32];
64 uint64_t nodesPerLevel;
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] =
75 (uint32_t)(((uint64_t)resLeavesHeight[numLevels] + 1) >> 1);
78 }
while(nodesPerLevel > 1);
83 throw std::runtime_error(
"tgt_create numnodes == 0, no tree created");
87 auto currentNode =
nodes;
89 auto parentNodeNext = parentNode;
91 for(int8_t i = 0; i < numLevels - 1; ++i)
93 for(uint32_t j = 0; j < resLeavesHeight[i]; ++j)
95 int64_t k = resLeavesWidth[i];
98 currentNode->parent = parentNode;
102 currentNode->parent = parentNode;
107 if((j & 1) || j == resLeavesHeight[i] - 1)
109 parentNodeNext = parentNode;
113 parentNode = parentNodeNext;
114 parentNodeNext += resLeavesWidth[i];
118 currentNode->
parent =
nullptr;
128 return (std::numeric_limits<T>::max)();
137 auto current_node =
nodes + i;
139 current_node->low = 0;
140 current_node->known =
false;
150 auto node =
nodes + leafno;
151 while(node && node->value > value)
167 auto nodeStackPtr = nodeStack;
168 auto node =
nodes + leafno;
171 *nodeStackPtr++ = node;
182 while(low < threshold)
184 if(low >= node->value)
199 if(nodeStackPtr == nodeStack)
201 node = *--nodeStackPtr;
216 auto nodeStackPtr = nodeStack;
217 auto node =
nodes + leafno;
221 *nodeStackPtr++ = node;
232 while(low < threshold && low < node->value)
242 if(nodeStackPtr == nodeStack)
244 node = *--nodeStackPtr;
246 *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:252
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:164
TagTreeNode< T > * nodes
Definition TagTree.h:253
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:133
void setvalue(uint64_t leafno, T value)
Set the value of a leaf of a tag tree.
Definition TagTree.h:148
~TagTree()
Definition TagTree.h:121
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:212
uint32_t leavesHeight_
Definition TagTree.h:251
uint32_t leavesWidth_
Definition TagTree.h:250
constexpr T getUninitializedValue(void)
Definition TagTree.h:126
Copyright (C) 2016-2024 Grok Image Compression Inc.
Definition ICacheable.h:20
TagTree< uint16_t > TagTreeU16
Definition TagTree.h:257
TagTree< uint8_t > TagTreeU8
Definition TagTree.h:256
void warn(const char *fmt,...) override
Definition Logger.h:44
void error(const char *fmt,...) override
Definition Logger.h:53
static Logger logger_
Definition Logger.h:70
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