Grok 20.3.2
CoderPool.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#pragma once
19
20#include <mutex>
21#include "ICoder.h"
22
23namespace grk
24{
25
27{
28public:
29 CoderKey(uint8_t w, uint8_t h) : cbw(w), cbh(h) {}
30 CoderKey() : CoderKey(0, 0) {}
31
32 uint8_t cbw; // Code block width
33 uint8_t cbh; // Code block height
34
35 bool operator==(const CoderKey& other) const
36 {
37 return cbw == other.cbw && cbh == other.cbh;
38 }
39};
40
42{
43 size_t operator()(const CoderKey& key) const
44 {
45 return std::hash<uint8_t>()(key.cbw) ^ (std::hash<uint8_t>()(key.cbh) << 1);
46 }
47};
48
49typedef std::unordered_map<CoderKey, std::vector<std::shared_ptr<t1::ICoder>>, CoderKeyHash>
51
53{
54public:
55 CoderPool(void) = default;
56 ~CoderPool(void) = default;
57 void makeCoders(uint32_t numCoders, uint8_t maxCblkWExp, uint8_t maxCblkHExp,
58 std::function<std::shared_ptr<t1::ICoder>()> creator);
59 bool contains(uint8_t maxCblkWExp, uint8_t maxCblkHExp);
60 std::shared_ptr<t1::ICoder> getCoder(size_t worker, uint8_t maxCblkWExp, uint8_t maxCblkHExp);
61
62private:
63 std::mutex mutex_;
65};
66
67} // namespace grk
ResWindow.
Definition CompressedChunkCache.h:36
std::unordered_map< CoderKey, std::vector< std::shared_ptr< t1::ICoder > >, CoderKeyHash > CODERMAP
Definition CoderPool.h:50
Definition CoderPool.h:42
size_t operator()(const CoderKey &key) const
Definition CoderPool.h:43
Definition CoderPool.h:27
uint8_t cbh
Definition CoderPool.h:33
uint8_t cbw
Definition CoderPool.h:32
CoderKey()
Definition CoderPool.h:30
CoderKey(uint8_t w, uint8_t h)
Definition CoderPool.h:29
bool operator==(const CoderKey &other) const
Definition CoderPool.h:35
void makeCoders(uint32_t numCoders, uint8_t maxCblkWExp, uint8_t maxCblkHExp, std::function< std::shared_ptr< t1::ICoder >()> creator)
Definition CoderPool.cpp:35
CoderPool(void)=default
std::mutex mutex_
Definition CoderPool.h:63
bool contains(uint8_t maxCblkWExp, uint8_t maxCblkHExp)
Definition CoderPool.cpp:28
CODERMAP coderMap_
Definition CoderPool.h:64
~CoderPool(void)=default
std::shared_ptr< t1::ICoder > getCoder(size_t worker, uint8_t maxCblkWExp, uint8_t maxCblkHExp)
Definition CoderPool.cpp:46