55 TagTree(uint32_t leavesWidth, uint32_t leavesHeight)
58 uint32_t resLeavesWidth[32];
59 uint32_t resLeavesHeight[32];
64 uint64_t nodesPerLevel;
69 GRK_ERROR(
"TagTree constructor: num level overflow");
70 throw std::exception();
72 nodesPerLevel = (uint64_t)resLeavesWidth[numLevels] * resLeavesHeight[numLevels];
73 resLeavesWidth[numLevels + 1] =
74 (uint32_t)(((uint64_t)resLeavesWidth[numLevels] + 1) >> 1);
75 resLeavesHeight[numLevels + 1] =
76 (uint32_t)(((uint64_t)resLeavesHeight[numLevels] + 1) >> 1);
79 }
while(nodesPerLevel > 1);
83 GRK_WARN(
"tgt_create numnodes == 0, no tree created.");
84 throw std::runtime_error(
"tgt_create numnodes == 0, no tree created");
88 auto currentNode =
nodes;
90 auto parentNodeNext = parentNode;
92 for(int8_t i = 0; i < numLevels - 1; ++i)
94 for(uint32_t j = 0; j < resLeavesHeight[i]; ++j)
96 int64_t k = resLeavesWidth[i];
99 currentNode->parent = parentNode;
103 currentNode->parent = parentNode;
108 if((j & 1) || j == resLeavesHeight[i] - 1)
110 parentNodeNext = parentNode;
114 parentNode = parentNodeNext;
115 parentNodeNext += resLeavesWidth[i];
119 currentNode->parent =
nullptr;
127 constexpr T getUninitializedValue(
void)
129 return (std::numeric_limits<T>::max)();
138 auto current_node =
nodes + i;
139 current_node->value = getUninitializedValue();
140 current_node->low = 0;
141 current_node->known =
false;
149 void setvalue(uint64_t leafno, T
value)
151 auto node =
nodes + leafno;
152 while(node && node->value >
value)
165 bool compress(BitIO* bio, uint64_t leafno, T threshold)
167 TagTreeNode<T>* nodeStack[31];
168 auto nodeStackPtr = nodeStack;
169 auto node =
nodes + leafno;
172 *nodeStackPtr++ = node;
183 while(
low < threshold)
185 if(
low >= node->value)
200 if(nodeStackPtr == nodeStack)
202 node = *--nodeStackPtr;
213 void decodeValue(BitIO* bio, uint64_t leafno, T threshold, T*
value)
215 TagTreeNode<T>* nodeStack[31];
216 *
value = getUninitializedValue();
217 auto nodeStackPtr = nodeStack;
218 auto node =
nodes + leafno;
222 *nodeStackPtr++ = node;
243 if(nodeStackPtr == nodeStack)
245 node = *--nodeStackPtr;
247 *
value = node->value;
uint64_t nodeCount
Definition TagTree.h:253
TagTreeNode * parent
Definition TagTree.h:36
T value
Definition TagTree.h:37
uint32_t leavesWidth_
Definition TagTree.h:251
uint32_t leavesHeight_
Definition TagTree.h:252
T low
Definition TagTree.h:38
bool known
Definition TagTree.h:39
TagTreeNode< T > * nodes
Definition TagTree.h:254
void GRK_WARN(const char *fmt,...)
void GRK_ERROR(const char *fmt,...)
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
TagTree< uint16_t > TagTreeU16
Definition TagTree.h:258
TagTree< uint8_t > TagTreeU8
Definition TagTree.h:257