TileProcessor.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/>.
*
*
* This source code incorporates work covered by the BSD 2-clause license.
* Please see the LICENSE file in the root directory for details.
*
*/
#pragma once
#include "grk_includes.h"
#include <queue>
#include <mutex>
namespace grk
{
/*
* Tile structure.
*
* Tile bounds are in canvas coordinates, and are equal to the
* full, non-windowed, unreduced tile dimensions,
* while the component dimensions are reduced
* if there is a resolution reduction.
*
*/
struct Tile : public grk_rect32
{
Tile();
explicit Tile(uint16_t numcomps);
virtual ~Tile();
uint16_t numcomps_;
TileComponent* comps;
double distortion;
double layerDistoration[maxCompressLayersGRK];
};
struct PacketTracker
{
PacketTracker();
~PacketTracker();
void init(uint32_t numcomps, uint32_t numres, uint64_t numprec, uint32_t numlayers);
void clear(void);
void packet_encoded(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer);
bool is_packet_encoded(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer);
private:
uint8_t* bits;
uint32_t numcomps_;
uint32_t numres_;
uint64_t numprec_;
uint32_t numlayers_;
uint64_t get_buffer_len(uint32_t numcomps, uint32_t numres, uint64_t numprec,
uint32_t numlayers);
uint64_t index(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer);
};
class mct;
struct TileProcessor
{
explicit TileProcessor(uint16_t index, CodeStream* codeStream, BufferedStream* stream,
bool isCompressor, StripCache* stripCache);
~TileProcessor();
bool init(void);
bool createWindowBuffers(const GrkImage* outputImage);
void deallocBuffers();
bool preCompressTile(void);
bool canWritePocMarker(void);
bool writeTilePartT2(uint32_t* tileBytesWritten);
bool doCompress(void);
bool decompressT2T1(GrkImage* outputImage);
bool ingestUncompressedData(uint8_t* p_src, uint64_t src_length);
bool needsRateControl();
void ingestImage();
bool cacheTilePartPackets(CodeStreamDecompress* codeStream);
void generateImage(GrkImage* src_image, Tile* src_tile);
GrkImage* getImage(void);
void release(GRK_TILE_CACHE_STRATEGY strategy);
void setCorruptPacket(void);
PacketTracker* getPacketTracker(void);
grk_rect32 getUnreducedTileWindow(void);
TileCodingParams* getTileCodingParams(void);
uint8_t getMaxNumDecompressResolutions(void);
BufferedStream* getStream(void);
uint32_t getPreCalculatedTileLen(void);
bool canPreCalculateTileLen(void);
uint16_t getIndex(void) const;
void incrementIndex(void);
Tile* getTile(void);
Scheduler* getScheduler(void);
bool isCompressor(void);
bool first_poc_tile_part_;
uint8_t tilePartCounter_;
uint32_t pino;
GrkImage* headerImage;
grk_plugin_tile* current_plugin_tile;
CodingParams* cp_;
PLCache packetLengthCache;
uint64_t getTilePartDataLength(void);
bool subtractMarkerSegmentLength(uint16_t markerLen);
bool setTilePartDataLength(uint16_t tilePart, uint32_t tilePartLength,
bool lastTilePartInCodeStream);
uint64_t getNumProcessedPackets(void);
void incNumProcessedPackets(void);
void incNumProcessedPackets(uint64_t numPackets);
uint64_t getNumDecompressedPackets(void);
void incNumDecompressedPackets(void);
private:
bool isWholeTileDecompress(uint16_t compno);
bool needsMctDecompress(uint16_t compno);
bool needsMctDecompress(void);
bool mctDecompress(FlowComponent* flow);
bool dcLevelShiftCompress();
bool mct_encode();
bool dwt_encode();
void t1_encode();
bool encodeT2(uint32_t* packet_bytes_written);
bool rateAllocate(uint32_t* allPacketBytes);
bool layerNeedsRateControl(uint32_t layno);
bool makeSingleLosslessLayer();
void makeLayerFinal(uint32_t layno);
bool pcrdBisectSimple(uint32_t* p_data_written);
void makeLayerSimple(uint32_t layno, double thresh, bool finalAttempt);
bool pcrdBisectFeasible(uint32_t* p_data_written);
void makeLayerFeasible(uint32_t layno, uint16_t thresh, bool finalAttempt);
Tile* tile;
Scheduler* scheduler_;
uint64_t numProcessedPackets;
std::atomic<uint64_t> numDecompressedPackets;
// Decompressing Only
uint64_t tilePartDataLength;
uint16_t tileIndex_;
// Compressing only - track which packets have already been written
// to the code stream
PacketTracker packetTracker_;
BufferedStream* stream_;
bool corrupt_packet_;
uint32_t newTilePartProgressionPosition;
// coding/decoding parameters for this tile
TileCodingParams* tcp_;
bool truncated;
GrkImage* image_;
bool isCompressor_;
grk_rect32 unreducedImageWindow;
uint32_t preCalculatedTileLen;
mct* mct_;
};
} // namespace grk
FlowComponent
Definition FlowComponent.h:21
grk::CodeStreamDecompress
Definition CodeStreamDecompress.h:38
grk::CodeStream
Definition CodeStream.h:133
grk::GrkImage
Definition GrkImage.h:25
grk::PLCache
Definition PLCache.h:26
grk::Scheduler
Definition Scheduler.h:22
grk::StripCache
Definition StripCache.h:110
grk::mct
Definition mct.h:53
grk_includes.h
GRK_TILE_CACHE_STRATEGY
enum _GRK_TILE_CACHE_STRATEGY GRK_TILE_CACHE_STRATEGY
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::maxCompressLayersGRK
const uint16_t maxCompressLayersGRK
Definition CodeStreamLimits.h:43
_grk_plugin_tile
Plugin tile.
Definition grok.h:739
grk::BufferedStream
Definition BufferedStream.h:35
grk::CodingParams
Coding parameters.
Definition CodingParams.h:245
grk::PacketTracker
Definition TileProcessor.h:50
grk::PacketTracker::bits
uint8_t * bits
Definition TileProcessor.h:59
grk::PacketTracker::init
void init(uint32_t numcomps, uint32_t numres, uint64_t numprec, uint32_t numlayers)
Definition TileProcessor.cpp:1707
grk::PacketTracker::numres_
uint32_t numres_
Definition TileProcessor.h:62
grk::PacketTracker::is_packet_encoded
bool is_packet_encoded(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer)
Definition TileProcessor.cpp:1752
grk::PacketTracker::PacketTracker
PacketTracker()
Definition TileProcessor.cpp:1701
grk::PacketTracker::get_buffer_len
uint64_t get_buffer_len(uint32_t numcomps, uint32_t numres, uint64_t numprec, uint32_t numlayers)
Definition TileProcessor.cpp:1734
grk::PacketTracker::clear
void clear(void)
Definition TileProcessor.cpp:1729
grk::PacketTracker::index
uint64_t index(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer)
Definition TileProcessor.cpp:1763
grk::PacketTracker::numprec_
uint64_t numprec_
Definition TileProcessor.h:63
grk::PacketTracker::numcomps_
uint32_t numcomps_
Definition TileProcessor.h:61
grk::PacketTracker::packet_encoded
void packet_encoded(uint32_t comps, uint32_t res, uint64_t prec, uint32_t layer)
Definition TileProcessor.cpp:1741
grk::PacketTracker::~PacketTracker
~PacketTracker()
Definition TileProcessor.cpp:1703
grk::PacketTracker::numlayers_
uint32_t numlayers_
Definition TileProcessor.h:64
grk::TileCodingParams
Tile coding parameters : this structure is used to store coding/decoding parameters common to all til...
Definition CodingParams.h:122
grk::TileComponent
Definition TileComponent.h:28
grk::Tile
Definition TileProcessor.h:39
grk::Tile::Tile
Tile()
Definition TileProcessor.cpp:1685
grk::Tile::~Tile
virtual ~Tile()
Definition TileProcessor.cpp:1697
grk::Tile::comps
TileComponent * comps
Definition TileProcessor.h:44
grk::Tile::layerDistoration
double layerDistoration[maxCompressLayersGRK]
Definition TileProcessor.h:46
grk::Tile::numcomps_
uint16_t numcomps_
Definition TileProcessor.h:43
grk::Tile::distortion
double distortion
Definition TileProcessor.h:45
grk::TileProcessor
Definition TileProcessor.h:78
grk::TileProcessor::rateAllocate
bool rateAllocate(uint32_t *allPacketBytes)
Definition TileProcessor.cpp:1121
grk::TileProcessor::~TileProcessor
~TileProcessor()
Definition TileProcessor.cpp:36
grk::TileProcessor::getImage
GrkImage * getImage(void)
Definition TileProcessor.cpp:158
grk::TileProcessor::image_
GrkImage * image_
Definition TileProcessor.h:173
grk::TileProcessor::getPreCalculatedTileLen
uint32_t getPreCalculatedTileLen(void)
Definition TileProcessor.cpp:123
grk::TileProcessor::corrupt_packet_
bool corrupt_packet_
Definition TileProcessor.h:167
grk::TileProcessor::t1_encode
void t1_encode()
Definition TileProcessor.cpp:789
grk::TileProcessor::mct_encode
bool mct_encode()
Definition TileProcessor.cpp:746
grk::TileProcessor::pcrdBisectFeasible
bool pcrdBisectFeasible(uint32_t *p_data_written)
Definition TileProcessor.cpp:1238
grk::TileProcessor::getNumDecompressedPackets
uint64_t getNumDecompressedPackets(void)
Definition TileProcessor.cpp:111
grk::TileProcessor::packetTracker_
PacketTracker packetTracker_
Definition TileProcessor.h:165
grk::TileProcessor::needsRateControl
bool needsRateControl()
Definition TileProcessor.cpp:1138
grk::TileProcessor::tile
Tile * tile
Definition TileProcessor.h:155
grk::TileProcessor::getTileCodingParams
TileCodingParams * getTileCodingParams(void)
Definition TileProcessor.cpp:180
grk::TileProcessor::first_poc_tile_part_
bool first_poc_tile_part_
Compression Only true for first POC tile part, otherwise false.
Definition TileProcessor.h:113
grk::TileProcessor::makeLayerSimple
void makeLayerSimple(uint32_t layno, double thresh, bool finalAttempt)
Definition TileProcessor.cpp:1536
grk::TileProcessor::getPacketTracker
PacketTracker * getPacketTracker(void)
Definition TileProcessor.cpp:176
grk::TileProcessor::headerImage
GrkImage * headerImage
Definition TileProcessor.h:122
grk::TileProcessor::dcLevelShiftCompress
bool dcLevelShiftCompress()
Definition TileProcessor.cpp:703
grk::TileProcessor::pino
uint32_t pino
Compression Only Current packet iterator number.
Definition TileProcessor.h:121
grk::TileProcessor::isWholeTileDecompress
bool isWholeTileDecompress(uint16_t compno)
Returns whether a tile component should be fully decompressed, taking into account win_* members.
Definition TileProcessor.cpp:404
grk::TileProcessor::getScheduler
Scheduler * getScheduler(void)
Definition TileProcessor.cpp:144
grk::TileProcessor::truncated
bool truncated
Definition TileProcessor.h:172
grk::TileProcessor::makeLayerFinal
void makeLayerFinal(uint32_t layno)
Definition TileProcessor.cpp:1629
grk::TileProcessor::setTilePartDataLength
bool setTilePartDataLength(uint16_t tilePart, uint32_t tilePartLength, bool lastTilePartInCodeStream)
Definition TileProcessor.cpp:62
grk::TileProcessor::generateImage
void generateImage(GrkImage *src_image, Tile *src_tile)
Definition TileProcessor.cpp:152
grk::TileProcessor::incNumProcessedPackets
void incNumProcessedPackets(void)
Definition TileProcessor.cpp:103
grk::TileProcessor::stream_
BufferedStream * stream_
Definition TileProcessor.h:166
grk::TileProcessor::preCompressTile
bool preCompressTile(void)
Definition TileProcessor.cpp:917
grk::TileProcessor::subtractMarkerSegmentLength
bool subtractMarkerSegmentLength(uint16_t markerLen)
Definition TileProcessor.cpp:46
grk::TileProcessor::getIndex
uint16_t getIndex(void) const
Definition TileProcessor.cpp:132
grk::TileProcessor::deallocBuffers
void deallocBuffers()
Definition TileProcessor.cpp:302
grk::TileProcessor::tilePartCounter_
uint8_t tilePartCounter_
Compressing Only index of tile part being currently coding.
Definition TileProcessor.h:118
grk::TileProcessor::canWritePocMarker
bool canWritePocMarker(void)
Definition TileProcessor.cpp:373
grk::TileProcessor::preCalculatedTileLen
uint32_t preCalculatedTileLen
Definition TileProcessor.h:176
grk::TileProcessor::getNumProcessedPackets
uint64_t getNumProcessedPackets(void)
Definition TileProcessor.cpp:99
grk::TileProcessor::getTile
Tile * getTile(void)
Definition TileProcessor.cpp:140
grk::TileProcessor::isCompressor_
bool isCompressor_
Definition TileProcessor.h:174
grk::TileProcessor::createWindowBuffers
bool createWindowBuffers(const GrkImage *outputImage)
Definition TileProcessor.cpp:267
grk::TileProcessor::scheduler_
Scheduler * scheduler_
Definition TileProcessor.h:156
grk::TileProcessor::setCorruptPacket
void setCorruptPacket(void)
grk::TileProcessor::mctDecompress
bool mctDecompress(FlowComponent *flow)
Definition TileProcessor.cpp:677
grk::TileProcessor::encodeT2
bool encodeT2(uint32_t *packet_bytes_written)
Definition TileProcessor.cpp:813
grk::TileProcessor::release
void release(GRK_TILE_CACHE_STRATEGY strategy)
Definition TileProcessor.cpp:162
grk::TileProcessor::doCompress
bool doCompress(void)
Definition TileProcessor.cpp:310
grk::TileProcessor::getTilePartDataLength
uint64_t getTilePartDataLength(void)
Definition TileProcessor.cpp:42
grk::TileProcessor::getUnreducedTileWindow
grk_rect32 getUnreducedTileWindow(void)
Definition TileProcessor.cpp:297
grk::TileProcessor::isCompressor
bool isCompressor(void)
Definition TileProcessor.cpp:148
grk::TileProcessor::getMaxNumDecompressResolutions
uint8_t getMaxNumDecompressResolutions(void)
Definition TileProcessor.cpp:184
grk::TileProcessor::layerNeedsRateControl
bool layerNeedsRateControl(uint32_t layno)
Definition TileProcessor.cpp:1132
grk::TileProcessor::makeLayerFeasible
void makeLayerFeasible(uint32_t layno, uint16_t thresh, bool finalAttempt)
Definition TileProcessor.cpp:1160
grk::TileProcessor::mct_
mct * mct_
Definition TileProcessor.h:177
grk::TileProcessor::ingestUncompressedData
bool ingestUncompressedData(uint8_t *p_src, uint64_t src_length)
Definition TileProcessor.cpp:966
grk::TileProcessor::numDecompressedPackets
std::atomic< uint64_t > numDecompressedPackets
Definition TileProcessor.h:158
grk::TileProcessor::init
bool init(void)
Definition TileProcessor.cpp:201
grk::TileProcessor::current_plugin_tile
grk_plugin_tile * current_plugin_tile
Definition TileProcessor.h:123
grk::TileProcessor::dwt_encode
bool dwt_encode()
Definition TileProcessor.cpp:773
grk::TileProcessor::writeTilePartT2
bool writeTilePartT2(uint32_t *tileBytesWritten)
Definition TileProcessor.cpp:380
grk::TileProcessor::tilePartDataLength
uint64_t tilePartDataLength
Definition TileProcessor.h:160
grk::TileProcessor::makeSingleLosslessLayer
bool makeSingleLosslessLayer()
Definition TileProcessor.cpp:1149
grk::TileProcessor::tcp_
TileCodingParams * tcp_
Definition TileProcessor.h:171
grk::TileProcessor::unreducedImageWindow
grk_rect32 unreducedImageWindow
Definition TileProcessor.h:175
grk::TileProcessor::cacheTilePartPackets
bool cacheTilePartPackets(CodeStreamDecompress *codeStream)
Definition TileProcessor.cpp:1024
grk::TileProcessor::decompressT2T1
bool decompressT2T1(GrkImage *outputImage)
Definition TileProcessor.cpp:420
grk::TileProcessor::pcrdBisectSimple
bool pcrdBisectSimple(uint32_t *p_data_written)
Definition TileProcessor.cpp:1373
grk::TileProcessor::tileIndex_
uint16_t tileIndex_
index of tile being currently compressed/decompressed
Definition TileProcessor.h:162
grk::TileProcessor::incrementIndex
void incrementIndex(void)
Definition TileProcessor.cpp:136
grk::TileProcessor::numProcessedPackets
uint64_t numProcessedPackets
Definition TileProcessor.h:157
grk::TileProcessor::getStream
BufferedStream * getStream(void)
Definition TileProcessor.cpp:119
grk::TileProcessor::ingestImage
void ingestImage()
Definition TileProcessor.cpp:629
grk::TileProcessor::needsMctDecompress
bool needsMctDecompress(void)
Definition TileProcessor.cpp:651
grk::TileProcessor::cp_
CodingParams * cp_
Definition TileProcessor.h:124
grk::TileProcessor::canPreCalculateTileLen
bool canPreCalculateTileLen(void)
Definition TileProcessor.cpp:127
grk::TileProcessor::packetLengthCache
PLCache packetLengthCache
Definition TileProcessor.h:125
grk::TileProcessor::newTilePartProgressionPosition
uint32_t newTilePartProgressionPosition
position of the tile part flag in progression order
Definition TileProcessor.h:169
grk::TileProcessor::incNumDecompressedPackets
void incNumDecompressedPackets(void)
Definition TileProcessor.cpp:115
grk::grk_rect< uint32_t >