Precinct.h
Go to the documentation of this file.
/*
* Copyright (C) 2016-2023 Grok Image Compression Inc.
*
* This source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "grk_includes.h"
namespace grk
{
template<typename T, typename P>
class BlockCache : public SparseCache<T>
{
public:
BlockCache(uint16_t numLayers, uint64_t maxChunkSize, P* blockInitializer)
: SparseCache<T>(maxChunkSize), blockInitializer_(blockInitializer), numLayers_(numLayers)
{}
virtual ~BlockCache() = default;
protected:
virtual T* create(uint64_t index) override
{
auto item = new T(numLayers_);
blockInitializer_->initCodeBlock(item, index);
return item;
}
private:
P* blockInitializer_;
uint16_t numLayers_;
};
struct PrecinctImpl
{
PrecinctImpl(bool isCompressor, grk_rect32* bounds, grk_pt32 cblk_expn);
~PrecinctImpl(void);
grk_rect32 getCodeBlockBounds(uint64_t cblkno);
bool initCodeBlocks(uint16_t numLayers, grk_rect32* bounds);
template<typename T>
bool initCodeBlock(T* block, uint64_t cblkno);
void deleteTagTrees();
TagTreeU16* getIncludeTagTree(void);
TagTreeU8* getIMsbTagTree(void);
BlockCache<CompressCodeblock, PrecinctImpl>* enc;
BlockCache<DecompressCodeblock, PrecinctImpl>* dec;
grk_rect32 cblk_grid_;
grk_rect32 bounds_;
grk_pt32 cblk_expn_;
bool isCompressor_;
private:
TagTreeU16* incltree; /* inclusion tree */
TagTreeU8* imsbtree; /* IMSB tree */
};
struct Precinct : public grk_rect32
{
Precinct(TileProcessor* tileProcessor, const grk_rect32& bounds, grk_pt32 cblk_expn);
virtual ~Precinct();
void deleteTagTrees();
grk_rect32 getCodeBlockBounds(uint64_t cblkno);
TagTreeU16* getInclTree(void);
TagTreeU8* getImsbTree(void);
uint32_t getCblkGridwidth(void);
uint32_t getCblkGridHeight(void);
uint32_t getNominalBlockSize(void);
uint64_t getNumCblks(void);
CompressCodeblock* getCompressedBlockPtr(uint64_t cblkno);
DecompressCodeblock* getDecompressedBlockPtr(uint64_t cblkno);
DecompressCodeblock* tryGetDecompressedBlockPtr(uint64_t cblkno);
grk_pt32 getCblkExpn(void);
grk_rect32 getCblkGrid(void);
uint64_t precinctIndex;
uint16_t numLayers_;
private:
PrecinctImpl* impl;
grk_pt32 cblk_expn_;
PrecinctImpl* getImpl(void)
{
impl->initCodeBlocks(numLayers_, this);
return impl;
}
};
} // namespace grk
grk::BlockCache
Definition Precinct.h:23
grk::BlockCache::create
virtual T * create(uint64_t index) override
Definition Precinct.h:31
grk::BlockCache::BlockCache
BlockCache(uint16_t numLayers, uint64_t maxChunkSize, P *blockInitializer)
Definition Precinct.h:25
grk::BlockCache::numLayers_
uint16_t numLayers_
Definition Precinct.h:40
grk::BlockCache::~BlockCache
virtual ~BlockCache()=default
grk::BlockCache::blockInitializer_
P * blockInitializer_
Definition Precinct.h:39
grk::SparseCache
Definition SparseCache.h:25
grk::TagTree
Tag tree.
Definition TagTree.h:47
grk_includes.h
grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk::CompressCodeblock
Definition Codeblock.h:142
grk::DecompressCodeblock
Definition Codeblock.h:201
grk::Precinct
Definition Precinct.h:66
grk::Precinct::cblk_expn_
grk_pt32 cblk_expn_
Definition Precinct.h:87
grk::Precinct::getCblkGridHeight
uint32_t getCblkGridHeight(void)
Definition Precinct.cpp:165
grk::Precinct::numLayers_
uint16_t numLayers_
Definition Precinct.h:83
grk::Precinct::getNumCblks
uint64_t getNumCblks(void)
Definition Precinct.cpp:173
grk::Precinct::getInclTree
TagTreeU16 * getInclTree(void)
Definition Precinct.cpp:153
grk::Precinct::impl
PrecinctImpl * impl
Definition Precinct.h:86
grk::Precinct::getImsbTree
TagTreeU8 * getImsbTree(void)
Definition Precinct.cpp:157
grk::Precinct::getNominalBlockSize
uint32_t getNominalBlockSize(void)
Definition Precinct.cpp:169
grk::Precinct::~Precinct
virtual ~Precinct()
Definition Precinct.cpp:141
grk::Precinct::getDecompressedBlockPtr
DecompressCodeblock * getDecompressedBlockPtr(uint64_t cblkno)
Definition Precinct.cpp:181
grk::Precinct::getCompressedBlockPtr
CompressCodeblock * getCompressedBlockPtr(uint64_t cblkno)
Definition Precinct.cpp:177
grk::Precinct::tryGetDecompressedBlockPtr
DecompressCodeblock * tryGetDecompressedBlockPtr(uint64_t cblkno)
Definition Precinct.cpp:185
grk::Precinct::precinctIndex
uint64_t precinctIndex
Definition Precinct.h:82
grk::Precinct::getCblkGrid
grk_rect32 getCblkGrid(void)
Definition Precinct.cpp:193
grk::Precinct::deleteTagTrees
void deleteTagTrees()
Definition Precinct.cpp:145
grk::Precinct::getCblkGridwidth
uint32_t getCblkGridwidth(void)
Definition Precinct.cpp:161
grk::Precinct::getCblkExpn
grk_pt32 getCblkExpn(void)
Definition Precinct.cpp:189
grk::Precinct::getCodeBlockBounds
grk_rect32 getCodeBlockBounds(uint64_t cblkno)
Definition Precinct.cpp:149
grk::Precinct::getImpl
PrecinctImpl * getImpl(void)
Definition Precinct.h:88
grk::PrecinctImpl
Definition Precinct.h:44
grk::PrecinctImpl::getIncludeTagTree
TagTreeU16 * getIncludeTagTree(void)
Definition Precinct.cpp:84
grk::PrecinctImpl::bounds_
grk_rect32 bounds_
Definition Precinct.h:57
grk::PrecinctImpl::cblk_expn_
grk_pt32 cblk_expn_
Definition Precinct.h:58
grk::PrecinctImpl::imsbtree
TagTreeU8 * imsbtree
Definition Precinct.h:63
grk::PrecinctImpl::initCodeBlocks
bool initCodeBlocks(uint16_t numLayers, grk_rect32 *bounds)
Definition Precinct.cpp:51
grk::PrecinctImpl::isCompressor_
bool isCompressor_
Definition Precinct.h:59
grk::PrecinctImpl::cblk_grid_
grk_rect32 cblk_grid_
Definition Precinct.h:56
grk::PrecinctImpl::getCodeBlockBounds
grk_rect32 getCodeBlockBounds(uint64_t cblkno)
Definition Precinct.cpp:41
grk::PrecinctImpl::enc
BlockCache< CompressCodeblock, PrecinctImpl > * enc
Definition Precinct.h:54
grk::PrecinctImpl::initCodeBlock
bool initCodeBlock(T *block, uint64_t cblkno)
Definition Precinct.cpp:67
grk::PrecinctImpl::deleteTagTrees
void deleteTagTrees()
Definition Precinct.cpp:77
grk::PrecinctImpl::incltree
TagTreeU16 * incltree
Definition Precinct.h:62
grk::PrecinctImpl::dec
BlockCache< DecompressCodeblock, PrecinctImpl > * dec
Definition Precinct.h:55
grk::PrecinctImpl::~PrecinctImpl
~PrecinctImpl(void)
Definition Precinct.cpp:35
grk::PrecinctImpl::getIMsbTagTree
TagTreeU8 * getIMsbTagTree(void)
Definition Precinct.cpp:109
grk::TileProcessor
Definition TileProcessor.h:78
grk::grk_pt< uint32_t >
grk::grk_rect< uint32_t >