Skip to content

Commit 42e7bbd

Browse files
author
Grok Compression
committed
block coder: use 16 bit dimensions
1 parent 4c740bf commit 42e7bbd

12 files changed

Lines changed: 82 additions & 77 deletions

File tree

src/lib/core/codestream/decompress/CodeStreamDecompress_ReadMarkers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ bool CodeStreamDecompress::readHeader(grk_header_info* headerInfo)
179179
headerImage_->copyHeaderTo(multiTileComposite_.get());
180180
multiTileComposite_->validateColourSpace();
181181
uint32_t num_threads = (uint32_t)ExecSingleton::num_threads();
182-
coderPool_.makeCoders(num_threads, 64, 64, [this]() -> std::shared_ptr<ICoder> {
182+
coderPool_.makeCoders(num_threads, 6, 6, [this]() -> std::shared_ptr<ICoder> {
183183
return std::shared_ptr<ICoder>(
184184
CoderFactory::makeCoder(isHT_, false, 64, 64, tileCache_->getStrategy()));
185185
});
186186

187-
coderPool_.makeCoders(num_threads, 32, 32, [this]() -> std::shared_ptr<ICoder> {
187+
coderPool_.makeCoders(num_threads, 5, 5, [this]() -> std::shared_ptr<ICoder> {
188188
return std::shared_ptr<ICoder>(
189189
CoderFactory::makeCoder(isHT_, false, 32, 32, tileCache_->getStrategy()));
190190
});

src/lib/core/scheduling/CoderPool.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020
namespace grk
2121
{
2222

23-
bool CoderPool::contains(uint8_t maxCblkW, uint8_t maxCblkH)
23+
bool CoderPool::contains(uint8_t maxCblkWExp, uint8_t maxCblkHExp)
2424
{
25-
auto key = CoderKey(maxCblkW, maxCblkH);
25+
auto key = CoderKey(maxCblkWExp, maxCblkHExp);
2626
return coderMap_.find(key) != coderMap_.end();
2727
}
2828

29-
void CoderPool::makeCoders(uint32_t numCoders, uint8_t maxCblkW, uint8_t maxCblkH,
29+
void CoderPool::makeCoders(uint32_t numCoders, uint8_t maxCblkWExp, uint8_t maxCblkHExp,
3030
std::function<std::shared_ptr<ICoder>()> creator)
3131
{
32-
if(contains(maxCblkW, maxCblkH))
32+
if(contains(maxCblkWExp, maxCblkHExp))
3333
return;
3434
std::vector<std::shared_ptr<ICoder>> coders;
3535
for(uint32_t i = 0; i < numCoders; ++i)
3636
coders.push_back(creator());
37-
coderMap_[{maxCblkW, maxCblkH}] = std::move(coders);
37+
coderMap_[{maxCblkWExp, maxCblkHExp}] = std::move(coders);
3838
}
39-
std::shared_ptr<ICoder> CoderPool::getCoder(size_t worker, uint8_t maxCblkW, uint8_t maxCblkH)
39+
std::shared_ptr<ICoder> CoderPool::getCoder(size_t worker, uint8_t maxCblkWExp, uint8_t maxCblkHExp)
4040
{
41-
auto it = coderMap_.find({maxCblkW, maxCblkH});
41+
auto it = coderMap_.find({maxCblkWExp, maxCblkHExp});
4242
if(it == coderMap_.end())
4343
{
4444
throw std::out_of_range("CoderKey not found in coderMap");

src/lib/core/scheduling/CoderPool.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ struct CoderPool
5050
public:
5151
CoderPool(void) = default;
5252
~CoderPool(void) = default;
53-
void makeCoders(uint32_t numCoders, uint8_t maxCblkW, uint8_t maxCblkH,
53+
void makeCoders(uint32_t numCoders, uint8_t maxCblkWExp, uint8_t maxCblkHExp,
5454
std::function<std::shared_ptr<ICoder>()> creator);
55-
bool contains(uint8_t maxCblkW, uint8_t maxCblkH);
56-
std::shared_ptr<ICoder> getCoder(size_t worker, uint8_t maxCblkW, uint8_t maxCblkH);
55+
bool contains(uint8_t maxCblkWExp, uint8_t maxCblkHExp);
56+
std::shared_ptr<ICoder> getCoder(size_t worker, uint8_t maxCblkWExp, uint8_t maxCblkHExp);
5757

5858
private:
5959
CODERMAP coderMap_;

src/lib/core/scheduling/whole_tile/DecompressScheduler.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,19 @@ bool DecompressScheduler::schedule(TileProcessor* tileProcessor)
8383
// schedule blocks
8484
auto tccp = tcp->tccps_ + compno;
8585
// nominal code block dimensions
86-
uint8_t cbw = (uint8_t)(tccp->cblkw_expn_ ? (uint8_t)1 << tccp->cblkw_expn_ : 0);
87-
uint8_t cbh = (uint8_t)(tccp->cblkh_expn_ ? (uint8_t)1 << tccp->cblkh_expn_ : 0);
86+
uint16_t cbw = tccp->cblkw_expn_ ? (uint16_t)1 << tccp->cblkw_expn_ : 0;
87+
uint16_t cbh = tccp->cblkh_expn_ ? (uint16_t)1 << tccp->cblkh_expn_ : 0;
8888
auto activePool = &coderPool_;
89-
if(streamPool_ && streamPool_->contains(cbw, cbh))
89+
if(streamPool_ && streamPool_->contains(tccp->cblkw_expn_, tccp->cblkh_expn_))
9090
activePool = streamPool_;
9191
if(!cacheAll)
9292
{
93-
activePool->makeCoders(
94-
num_threads, cbw, cbh, [tcp, cbw, cbh, tileProcessor]() -> std::shared_ptr<ICoder> {
95-
return std::shared_ptr<ICoder>(CoderFactory::makeCoder(
96-
tcp->isHT(), false, cbw, cbh, tileProcessor->getTileCacheStrategy()));
97-
});
93+
activePool->makeCoders(num_threads, tccp->cblkw_expn_, tccp->cblkh_expn_,
94+
[tcp, cbw, cbh, tileProcessor]() -> std::shared_ptr<ICoder> {
95+
return std::shared_ptr<ICoder>(
96+
CoderFactory::makeCoder(tcp->isHT(), false, cbw, cbh,
97+
tileProcessor->getTileCacheStrategy()));
98+
});
9899
}
99100
auto tilec = tileProcessor->getTile()->comps_ + compno;
100101
auto wholeTileDecoding = tilec->isWholeTileDecoding();
@@ -190,8 +191,8 @@ bool DecompressScheduler::schedule(TileProcessor* tileProcessor)
190191
resFlow = imageComponentFlow_[compno]->resFlows_ + resno;
191192
for(auto& block : rblocks.blocks_)
192193
{
193-
auto blockFunc = [this, activePool, singleThread, tileProcessor, &block, cbw, cbh, cacheAll,
194-
finalLayer] {
194+
auto blockFunc = [this, activePool, singleThread, tileProcessor, &block, tccp, cbw, cbh,
195+
cacheAll, finalLayer] {
195196
if(!success)
196197
{
197198
block.reset();
@@ -210,7 +211,8 @@ bool DecompressScheduler::schedule(TileProcessor* tileProcessor)
210211
{
211212
// get coder from pool
212213
auto threadnum = singleThread ? 0 : ExecSingleton::get().this_worker_id();
213-
coder = activePool->getCoder((size_t)threadnum, cbw, cbh).get();
214+
coder = activePool->getCoder((size_t)threadnum, tccp->cblkw_expn_, tccp->cblkh_expn_)
215+
.get();
214216
}
215217
try
216218
{

src/lib/core/scheduling/window/DecompressWindowScheduler.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,20 @@ bool DecompressWindowScheduler::schedule(TileProcessor* tileProcessor)
5858
// schedule blocks
5959
auto tccp = tcp->tccps_ + compno;
6060
// nominal code block dimensions
61-
uint8_t cbw = (uint8_t)(tccp->cblkw_expn_ ? (uint8_t)1 << tccp->cblkw_expn_ : 0);
62-
uint8_t cbh = (uint8_t)(tccp->cblkh_expn_ ? (uint8_t)1 << tccp->cblkh_expn_ : 0);
61+
uint16_t cbw = tccp->cblkw_expn_ ? (uint16_t)1 << tccp->cblkw_expn_ : 0;
62+
uint16_t cbh = tccp->cblkh_expn_ ? (uint16_t)1 << tccp->cblkh_expn_ : 0;
6363
auto activePool = &coderPool_;
64-
if(streamPool_ && streamPool_->contains(cbw, cbh))
64+
if(streamPool_ && streamPool_->contains(tccp->cblkw_expn_, tccp->cblkh_expn_))
6565
activePool = streamPool_;
6666

6767
if(!cacheAll)
6868
{
69-
activePool->makeCoders(
70-
num_threads, cbw, cbh, [tcp, cbw, cbh, tileProcessor]() -> std::shared_ptr<ICoder> {
71-
return std::shared_ptr<ICoder>(CoderFactory::makeCoder(
72-
tcp->isHT(), false, cbw, cbh, tileProcessor->getTileCacheStrategy()));
73-
});
69+
activePool->makeCoders(num_threads, tccp->cblkw_expn_, tccp->cblkh_expn_,
70+
[tcp, cbw, cbh, tileProcessor]() -> std::shared_ptr<ICoder> {
71+
return std::shared_ptr<ICoder>(
72+
CoderFactory::makeCoder(tcp->isHT(), false, cbw, cbh,
73+
tileProcessor->getTileCacheStrategy()));
74+
});
7475
}
7576

7677
auto tilec = tileProcessor->getTile()->comps_ + compno;
@@ -122,7 +123,7 @@ bool DecompressWindowScheduler::schedule(TileProcessor* tileProcessor)
122123

123124
auto t = placeholder();
124125
tileProcessor->blockTasks_.emplace_back(t);
125-
auto blockFunc = [this, activePool, singleThread, tileProcessor, block, cbw, cbh,
126+
auto blockFunc = [this, activePool, singleThread, tileProcessor, block, tccp, cbw, cbh,
126127
cacheAll] {
127128
if(success)
128129
{
@@ -135,7 +136,9 @@ bool DecompressWindowScheduler::schedule(TileProcessor* tileProcessor)
135136
else if(!cacheAll)
136137
{
137138
auto threadnum = singleThread ? 0 : ExecSingleton::get().this_worker_id();
138-
coder = activePool->getCoder((size_t)threadnum, cbw, cbh).get();
139+
coder =
140+
activePool->getCoder((size_t)threadnum, tccp->cblkw_expn_, tccp->cblkh_expn_)
141+
.get();
139142
}
140143
try
141144
{

src/lib/core/t1/CoderFactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
namespace grk
2424
{
25-
ICoder* CoderFactory::makeCoder(bool isHT, bool isCompressor, uint8_t maxCblkW, uint8_t maxCblkH,
25+
ICoder* CoderFactory::makeCoder(bool isHT, bool isCompressor, uint16_t maxCblkW, uint16_t maxCblkH,
2626
uint32_t cacheStrategy)
2727
{
2828
if(isHT)

src/lib/core/t1/CoderFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace grk
2424
class CoderFactory
2525
{
2626
public:
27-
static ICoder* makeCoder(bool isHT, bool isCompressor, uint8_t maxCblkW, uint8_t maxCblkH,
27+
static ICoder* makeCoder(bool isHT, bool isCompressor, uint16_t maxCblkW, uint16_t maxCblkH,
2828
uint32_t cacheStrategy);
2929
static Quantizer* makeQuantizer(bool ht, bool reversible, uint8_t guardBits);
3030
};

src/lib/core/t1/part1/Coder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace grk
2525
{
2626
namespace t1_part1
2727
{
28-
Coder::Coder(bool isCompressor, uint8_t maxCblkW, uint8_t maxCblkH, uint32_t cacheStrategy)
28+
Coder::Coder(bool isCompressor, uint16_t maxCblkW, uint16_t maxCblkH, uint32_t cacheStrategy)
2929
: blockCoder_(nullptr), cacheStrategy_(cacheStrategy)
3030
{
3131
blockCoder_ = new BlockCoder(isCompressor, maxCblkW, maxCblkH, cacheStrategy);

src/lib/core/t1/part1/Coder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace grk::t1_part1
2929
class Coder : public ICoder
3030
{
3131
public:
32-
Coder(bool isCompressor, uint8_t maxCblkW, uint8_t maxCblkH, uint32_t cacheStrategy);
32+
Coder(bool isCompressor, uint16_t maxCblkW, uint16_t maxCblkH, uint32_t cacheStrategy);
3333
virtual ~Coder();
3434

3535
bool compress(CompressBlockExec* block) override;

src/lib/core/t1/part1/block_coder/BlockCoder.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ namespace grk
2323
class BlockCoder
2424
{
2525
public:
26-
BlockCoder(bool isCompressor, uint8_t maxCblkW, uint8_t maxCblkH, uint32_t cacheStrategy);
26+
BlockCoder(bool isCompressor, uint16_t maxCblkW, uint16_t maxCblkH, uint32_t cacheStrategy);
2727
~BlockCoder();
2828

2929
void print(void);
30-
bool alloc(uint8_t w, uint8_t h);
30+
bool alloc(uint16_t w, uint16_t h);
3131

3232
void code_block_enc_deallocate(cblk_enc* p_code_block);
3333
double compress_cblk(cblk_enc* cblk, uint32_t max, uint8_t orientation, uint16_t compno,
@@ -51,24 +51,24 @@ class BlockCoder
5151

5252
private:
5353
void initFlags(void);
54-
uint8_t getFlagsStride(void);
55-
uint8_t getFlagsHeight(void);
54+
uint16_t getFlagsStride(void);
55+
uint16_t getFlagsHeight(void);
5656

5757
uint32_t cacheStrategy_;
5858
mqcoder coder;
5959

6060
/**
6161
* @brief cached block width
6262
*/
63-
uint8_t w_;
63+
uint16_t w_;
6464
/**
6565
* @brief cached block stride
6666
*/
6767
uint8_t stride_;
6868
/**
6969
* @brief cached block height
7070
*/
71-
uint8_t h_;
71+
uint16_t h_;
7272

7373
/**
7474
* @brief uncompressed data buffer
@@ -90,33 +90,33 @@ class BlockCoder
9090

9191
void checkSegSym(int32_t cblksty);
9292

93-
template<uint8_t w, uint8_t h, bool vsc>
93+
template<uint16_t w, uint16_t h, bool vsc>
9494
void dec_clnpass(int8_t bpno);
9595
void dec_clnpass(int8_t bpno, int32_t cblksty);
96-
template<uint8_t w, uint8_t h, bool vsc>
96+
template<uint16_t w, uint16_t h, bool vsc>
9797
void dec_clnpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype);
9898
void dec_clnpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype, int32_t cblksty);
99-
template<uint8_t w, uint8_t h, bool vsc>
99+
template<uint16_t w, uint16_t h, bool vsc>
100100
void dec_clnpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype);
101101
void dec_clnpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype, int32_t cblksty);
102102

103-
template<uint8_t w, uint8_t h, bool vsc>
103+
template<uint16_t w, uint16_t h, bool vsc>
104104
void dec_sigpass(int8_t bpno);
105105
void dec_sigpass(int8_t bpno, int32_t cblksty);
106-
template<uint8_t w, uint8_t h, bool vsc>
106+
template<uint16_t w, uint16_t h, bool vsc>
107107
void dec_sigpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype);
108108
void dec_sigpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype, int32_t cblksty);
109-
template<uint8_t w, uint8_t h, bool vsc>
109+
template<uint16_t w, uint16_t h, bool vsc>
110110
void dec_sigpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype);
111111
void dec_sigpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype, int32_t cblksty);
112112

113-
template<uint8_t w, uint8_t h>
113+
template<uint16_t w, uint16_t h>
114114
void dec_refpass(int8_t bpno);
115115
void dec_refpass(int8_t bpno);
116-
template<uint8_t w, uint8_t h>
116+
template<uint16_t w, uint16_t h>
117117
void dec_refpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype);
118118
void dec_refpass_diff(int8_t bpno, uint8_t passno, uint8_t passtype);
119-
template<uint8_t w, uint8_t h>
119+
template<uint16_t w, uint16_t h>
120120
void dec_refpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype);
121121
void dec_refpass_diff_final(int8_t bpno, uint8_t passno, uint8_t passtype);
122122

0 commit comments

Comments
 (0)