55 TagTree(uint32_t mynumleafsh, uint32_t mynumleafsv)
69 GRK_ERROR(
"TagTree constructor: num level overflow");
70 throw std::exception();
72 n = (uint64_t)nplh[numlvls] * nplv[numlvls];
73 nplh[numlvls + 1] = (uint32_t)(((uint64_t)nplh[numlvls] + 1) / 2);
74 nplv[numlvls + 1] = (uint32_t)(((uint64_t)nplv[numlvls] + 1) / 2);
81 GRK_WARN(
"tgt_create numnodes == 0, no tree created.");
82 throw std::runtime_error(
"tgt_create numnodes == 0, no tree created");
88 auto parent_node0 = parent_node;
90 for(int8_t i = 0; i < numlvls - 1; ++i)
92 for(uint32_t j = 0; j < nplv[i]; ++j)
97 node->parent = parent_node;
101 node->parent = parent_node;
106 if((j & 1) || j == nplv[i] - 1)
108 parent_node0 = parent_node;
112 parent_node = parent_node0;
113 parent_node0 += nplh[i];
127 return (std::numeric_limits<T>::max)();
134 for(uint64_t i = 0; i <
numnodes; ++i)
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)
167 auto node =
nodes + leafno;
181 while(low < threshold)
183 if(low >= node->value)
187 if(!bio->
write(1, 1))
193 if(!bio->
write(0, 1))
217 auto node =
nodes + leafno;
230 while(low < threshold && low < node->value)
236 node->value = T(low);
249 *value = node->value;
void read(uint32_t *bits, uint32_t n)
Read bits.
Definition: BitIO.cpp:114
bool write(uint32_t v, uint32_t n)
Write bits.
Definition: BitIO.cpp:103
Tag tree.
Definition: TagTree.h:47
uint64_t numnodes
Definition: TagTree.h:255
TagTree(uint32_t mynumleafsh, uint32_t mynumleafsv)
Create a tag tree.
Definition: TagTree.h:55
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< T > * nodes
Definition: TagTree.h:256
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:212
uint32_t numleafsv
Definition: TagTree.h:254
constexpr T getUninitializedValue(void)
Definition: TagTree.h:125
uint32_t numleafsh
Definition: TagTree.h:253
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:58
void GRK_WARN(const char *fmt,...)
Definition: logger.cpp:49
TagTree< uint16_t > TagTreeU16
Definition: TagTree.h:260
TagTree< uint8_t > TagTreeU8
Definition: TagTree.h:259
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