Grok 20.3.2
grk::CodeStreamDecompress Class Referencefinal

Manages decompression. More...

#include <CodeStreamDecompress.h>

Inheritance diagram for grk::CodeStreamDecompress:
grk::CodeStream grk::IDecompressor

Classes

struct  PendingBand_

Public Member Functions

 CodeStreamDecompress (IStream *stream)
 Constructs a CodeStreamDecompress.
 ~CodeStreamDecompress ()
 Destroys a CodeStreamDecompress.
void init (grk_decompress_parameters *param) override
 Initializes decompressor.
void setBandCallback (grk_io_band_callback callback, void *user_data) override
 Sets a band-completion callback for incremental writing.
grk_io_band_callback getBandCallback () const override
void * getBandUserData () const override
grk_progression_state getProgressionState (uint16_t tile_index) override
 Gets the grk_progression_state for a tile.
bool setProgressionState (grk_progression_state state) override
 Sets the grk_progression_state for a tile.
ITileProcessorgetTileProcessor (uint16_t tile_index)
 Gets tile processor for specified tile index.
void initTilesToDecompress (Rect16 region)
 Initializes tile completeness set.
void setNumComponents (uint16_t numComps)
bool initDefaultTCP ()
 Initializes default TileCodingParams.
bool readHeader (grk_header_info *header_info) override
 Reads header.
bool needsHeaderRead (void) const
 Checks if header needs to be read.
GrkImagegetImage (uint16_t tile_index, bool wait) override
 Gets GrkImage for specified tile.
GrkImagegetImage (void) override
 Gets composite GrkImage for all tiles in decompress region.
GrkImagegetCompositeNoWait (void)
GrkImagegetHeaderImage (void)
 Gets header GrkImage (where main and tile header information is stored).
bool decompress (grk_plugin_tile *tile) override
 Decompresses image / image region.
bool decompressTile (uint16_t tile_index) override
 Single Tile ////////////////////////////////////////////////////.
bool postProcess (GrkImage *img)
 Post processes decompressed image.
void dump (uint32_t flag, FILE *outputFileStream) override
 Dumps image tags to file.
void wait (grk_wait_swath *swath) override
 Wait for tile decompression to complete.
void scheduleSwathCopy (const grk_wait_swath *swath, grk_swath_buffer *buf) override
 Schedule SIMD-accelerated tile-to-swath copies for decoded tiles.
void waitSwathCopy () override
 Wait for all in-flight swath copy tasks to complete.
void setPostPostProcess (std::function< bool(GrkImage *)> func)
 Sets the Post Post Process object.
Public Member Functions inherited from grk::CodeStream
 CodeStream (IStream *stream)
virtual ~CodeStream ()
IStreamgetStream ()
GrkImagegetHeaderImage (void)
grk_plugin_tilegetCurrentPluginTile ()
CodingParamsgetCodingParams (void)
Public Member Functions inherited from grk::IDecompressor
virtual ~IDecompressor ()=default
 Destroys the IDecompressor object.
virtual uint32_t getNumSamples (void)
virtual bool decompressSample (uint32_t sampleIndex)
virtual GrkImagegetSampleImage (uint32_t sampleIndex)
virtual GrkImagegetSampleTileImage (uint32_t sampleIndex, uint16_t tileIndex)

Protected Member Functions

bool setDecompressRegion (RectD region)
 Sets the decompress region.
bool decompressImpl (std::set< uint16_t > pendingTiles)
 Decompresses all tiles.
bool decompressTileImpl (uint16_t tile_index)
void dumpMainHeader (FILE *outputFileStream)
 Dumps main header info to file.
void dumpImageHeader (GrkImage *image, bool dev_dump_flag, FILE *outputFileStream)
 Dumps an image header structure.
void dumpTileHeader (TileCodingParams *defaultTile, uint32_t numcomps, FILE *outputFileStream)
 Dumps tile info to file.
void dumpImageComponentHeader (grk_image_comp *comp, bool dev_dump_flag, FILE *outputFileStream)
 Dumps a component image header structure.
Protected Member Functions inherited from grk::CodeStream
bool exec (std::vector< PROCEDURE_FUNC > &procedureList)

Private Member Functions

void postReadHeader (void)
void onRowCompleted (uint16_t tileIndexBegin)
void scheduleTileBatch ()
void wait (uint16_t tile_index)
void decompressSequentialPrepare (void)
 Prepares to read first slated tile part.
bool schedule (ITileProcessor *tileProcessor, bool multiTile)
bool sequentialParseAndSchedule (bool multiTile)
 Parses next slated tile.
bool readUNK (void)
 Reads unknown marker.
void differentialUpdate (GrkImage *scratch)
 Updates differential decompress state.
bool readCBD (uint8_t *headerData, uint16_t headerSize)
 Reads a CBD marker (Component bit depth definition).
bool readHeaderProcedure (void)
 Reads header - all markers until first SOT.
bool readSOC ()
 Reads a SOC marker (Start of Codestream).
bool readSIZ (uint8_t *headerData, uint16_t headerSize)
 Reads a SIZ marker (image and tile size).
bool readCAP (uint8_t *headerData, uint16_t headerSize)
 Reads a CAP marker.
bool readCRG (uint8_t *headerData, uint16_t headerSize)
 Reads a CRG marker (Component registration).
bool readTLM (uint8_t *headerData, uint16_t headerSize)
 Reads a TLM marker (Tile Length Marker).
bool readPLM (uint8_t *headerData, uint16_t headerSize)
 Reads a PLM marker (Packet length, main header marker).
bool readPPM (uint8_t *headerData, uint16_t headerSize)
 Reads a PPM marker (Packed headers, main header).
bool readSOT (uint8_t *headerData, uint16_t headerSize)
 Read SOT (Start of tile part) marker.
bool mergePpm (CodingParams *p_cp)
 Merges all PPM markers read (Packed headers, main header).
bool activateScratch (bool singleTile, GrkImage *scratch)
 Activates scratch image.
std::function< void()> postMultiTile (ITileProcessor *tileProcessor)
 Creates a Post Task object.
std::function< void()> postMultiTile (void)
 Final post-processing lambda, executed by wait(nullptr) after all tiles complete.
std::function< void()> postSingleTile (ITileProcessor *tileProcessor)
std::function< bool()> genDecompressTileTLMTask (ITileProcessor *tileProcessor, const std::shared_ptr< TPFetchSeq > &tilePartFetchSeq, Rect32 unreducedImageBounds, std::function< std::function< void()>(ITileProcessor *)> postGenerator)
void decompressSequential (const std::set< uint16_t > &pendingTiles)
void decompressTLM (const std::set< uint16_t > &pendingTiles)
bool startTLMDecompress (std::set< uint16_t > &pendingTiles)
bool startSequentialDecompress (std::set< uint16_t > &pendingTiles)
bool doTileBatching (void)
bool fetchByTile (std::set< uint16_t > &slated, Rect32 unreducedImageBounds, std::function< std::function< void()>(ITileProcessor *)> postGenerator)
uint16_t batchTileHeadroomIncrement (uint16_t numRows, uint16_t tilesLeft)
void startDecompressConsumer (uint16_t maxInFlight)
bool batchDequeueSequential (void)

Private Attributes

MarkerParser markerParser_
 MarkerParser
TileWindow tilesToDecompress_
 TileWindow
std::unique_ptr< MarkerCachemarkerCache_
 MarkerCache
ITileProcessorcurrTileProcessor_ = nullptr
 Tile processor currently being parsed.
TilePartInfo currTilePartInfo_
int32_t currTileIndex_ = -1
std::unique_ptr< TileCodingParamsdefaultTcp_
 Default TileCodingParams.
bool headerError_ = false
 true if there was an error reading the main header
bool headerRead_ = false
 true if main header was successfully read
std::unique_ptr< GrkImage, RefCountedDeleter< GrkImage > > multiTileComposite_
 multi tile composite GrkImage Used to composite multiple tiles - subsampled and reduced for region decompression
Rect32 region_
 Holds unreduced unsubsampled decompress region , if set.
std::function< void()> postMulti_
std::unique_ptr< TileCachetileCache_
 TileCache
grk_io_pixels_callback ioBufferCallback_ = nullptr
 callback for io pixels
void * ioUserData_ = nullptr
 io user data
grk_io_band_callback ioBandCallback_ = nullptr
 callback invoked when a tile-row band is ready for incremental writing
void * ioBandUserData_ = nullptr
std::mutex bandOrderMutex_
std::condition_variable bandDrainCV_
uint16_t nextBandTileY_ = 0
std::map< uint16_t, PendingBand_pendingBands_
grk_io_register_reclaim_callback grkRegisterReclaimCallback_ = nullptr
 callback to reclaim io buffers
std::function< bool(GrkImage *)> postPostProcess_
 post post-decompress method
TileFutureManager decompressTileFutureManager_
 futures for scheduled tiles
TileFutureManager swathCopyFutureManager_
 futures for swath copy tasks scheduled via scheduleSwathCopy()
std::shared_ptr< TPFetchSeqtilePartFetchFlat_
std::shared_ptr< std::unordered_map< uint16_t, std::shared_ptr< TPFetchSeq > > > tilePartFetchByTile_
std::vector< std::future< bool > > fetchByTileFutures_
std::unique_ptr< GrkImage, RefCountedDeleter< GrkImage > > scratchImage_
 Scratch GrkImage for decompressor This image may composite multiple tiles, if needed.
std::unique_ptr< GrkImage, std::function< void(GrkImage *)> > activeImage_
std::atomic< bool > success_ {true}
 track success of scheduled tile decompression
std::atomic< uint32_t > numTilesDecompressed_ {0}
 number of decompressed tiles
CoderPool coderPool_
 pool of ICoder
std::vector< std::unique_ptr< MarkerParser > > tileMarkerParsers_
bool isHT_ = false
 global HT flag
std::unique_ptr< TileCompletiontileCompletion_
std::thread decompressWorker_
std::function< bool(std::set< uint16_t > &)> decompressStart_
std::shared_ptr< ChunkBuffer<> > chunkBuffer_
std::unique_ptr< CompressedChunkCachecompressedChunkCache_
std::mutex batchTileQueueMutex_
std::condition_variable batchTileQueueCondition_
uint16_t batchTileInitialRows_ = 2
uint16_t batchTileNextRows_ = 2
std::queue< uint16_t > batchTileQueueTLM_
std::unique_ptr< ConcurrentQueue< std::function< void()> > > decompressQueue_
std::thread decompressConsumer_
std::mutex decompressThrottleMutex_
std::condition_variable decompressThrottleCV_
uint16_t decompressInFlight_ = 0
uint16_t maxDecompressInFlight_ = 0
std::atomic< int32_t > maxFetchedTileRow_ {-1}
std::queue< ITileProcessor * > batchTileQueueSequential_
uint16_t batchTileScheduleHeadroomSequential_ = 0
uint16_t batchTileUnscheduledSequential_ = 0
int32_t batchTileScheduledRows_ = 0

Static Private Attributes

static constexpr int32_t maxRowsAhead_ = 2

Additional Inherited Members

Protected Attributes inherited from grk::CodeStream
CodingParams cp_
std::vector< PROCEDURE_FUNCprocedureList_
std::vector< PROCEDURE_FUNCvalidationList_
GrkImageheaderImage_
IStreamstream_
std::unordered_map< uint32_t, ITileProcessor * > processors_
grk_plugin_tilecurrent_plugin_tile

Detailed Description

Manages decompression.

See also
doc/IncrementalStripeCompositing.md for the incremental band-write pipeline.
doc/TileCache.md for tile caching and LRU eviction.

Constructor & Destructor Documentation

◆ CodeStreamDecompress()

◆ ~CodeStreamDecompress()

grk::CodeStreamDecompress::~CodeStreamDecompress ( )
inline

Member Function Documentation

◆ activateScratch()

bool grk::CodeStreamDecompress::activateScratch ( bool singleTile,
GrkImage * scratch )
private

◆ batchDequeueSequential()

bool grk::CodeStreamDecompress::batchDequeueSequential ( void )
private

◆ batchTileHeadroomIncrement()

uint16_t grk::CodeStreamDecompress::batchTileHeadroomIncrement ( uint16_t numRows,
uint16_t tilesLeft )
private

◆ decompress()

◆ decompressImpl()

bool grk::CodeStreamDecompress::decompressImpl ( std::set< uint16_t > pendingTiles)
protected

◆ decompressSequential()

◆ decompressSequentialPrepare()

void grk::CodeStreamDecompress::decompressSequentialPrepare ( void )
private

◆ decompressTile()

bool grk::CodeStreamDecompress::decompressTile ( uint16_t tile_index)
overridevirtual

Single Tile ////////////////////////////////////////////////////.

Implements grk::IDecompressor.

References grk::CodeStream::cp_, decompressTile(), decompressTileImpl(), grk::grklog, multiTileComposite_, tileCache_, and wait().

Referenced by decompressTile().

◆ decompressTileImpl()

◆ decompressTLM()

◆ differentialUpdate()

void grk::CodeStreamDecompress::differentialUpdate ( GrkImage * scratch)
private

◆ doTileBatching()

bool grk::CodeStreamDecompress::doTileBatching ( void )
private

◆ dump()

void grk::CodeStreamDecompress::dump ( uint32_t flag,
FILE * outputFileStream )
overridevirtual

Dumps image tags to file.

Parameters
flagflag indicating main header, tile header etc.
outputFileStreamFILE stream

Implements grk::IDecompressor.

References grk::CodeStream::cp_, dumpImageHeader(), dumpMainHeader(), dumpTileHeader(), getHeaderImage(), GRK_IMG_INFO, GRK_MH_IND, GRK_MH_INFO, GRK_TCH_INFO, grk::CodeStream::headerImage_, markerCache_, and tileCache_.

◆ dumpImageComponentHeader()

void grk::CodeStreamDecompress::dumpImageComponentHeader ( grk_image_comp * comp,
bool dev_dump_flag,
FILE * outputFileStream )
protected

Dumps a component image header structure.

Parameters
compthe component image header to dump.
dev_dump_flagflag to describe if we are in the case of this function is use outside dump function
outputFileStreamoutput stream where dump the elements.

Referenced by dumpImageHeader().

◆ dumpImageHeader()

void grk::CodeStreamDecompress::dumpImageHeader ( GrkImage * image,
bool dev_dump_flag,
FILE * outputFileStream )
protected

Dumps an image header structure.

Parameters
imageimage header to dump.
dev_dump_flagflag to describe if we are in the case of this function is use outside dump function
outputFileStreamoutput stream where dump the elements.

References dumpImageComponentHeader().

Referenced by dump().

◆ dumpMainHeader()

void grk::CodeStreamDecompress::dumpMainHeader ( FILE * outputFileStream)
protected

Dumps main header info to file.

Parameters
outputFileStreamoutput file stream

References grk::CodeStream::cp_, defaultTcp_, dumpTileHeader(), and getHeaderImage().

Referenced by dump().

◆ dumpTileHeader()

void grk::CodeStreamDecompress::dumpTileHeader ( TileCodingParams * defaultTile,
uint32_t numcomps,
FILE * outputFileStream )
protected

Dumps tile info to file.

Parameters
default_tile
numcomps
outputFileStream

References grk::CCP_QNTSTY_SIQNT, grk::TileCodingParams::csty_, grk::TileCodingParams::mct_, grk::TileCodingParams::numLayers_, grk::TileCodingParams::prg_, and grk::TileCodingParams::tccps_.

Referenced by dump(), and dumpMainHeader().

◆ fetchByTile()

bool grk::CodeStreamDecompress::fetchByTile ( std::set< uint16_t > & slated,
Rect32 unreducedImageBounds,
std::function< std::function< void()>(ITileProcessor *)> postGenerator )
private

◆ genDecompressTileTLMTask()

std::function< bool()> grk::CodeStreamDecompress::genDecompressTileTLMTask ( ITileProcessor * tileProcessor,
const std::shared_ptr< TPFetchSeq > & tilePartFetchSeq,
Rect32 unreducedImageBounds,
std::function< std::function< void()>(ITileProcessor *)> postGenerator )
private

◆ getBandCallback()

grk_io_band_callback grk::CodeStreamDecompress::getBandCallback ( ) const
inlineoverridevirtual

Reimplemented from grk::CodeStream.

References ioBandCallback_.

◆ getBandUserData()

void * grk::CodeStreamDecompress::getBandUserData ( ) const
inlineoverridevirtual

Reimplemented from grk::CodeStream.

References ioBandUserData_.

◆ getCompositeNoWait()

GrkImage * grk::CodeStreamDecompress::getCompositeNoWait ( void )

◆ getHeaderImage()

GrkImage * grk::CodeStreamDecompress::getHeaderImage ( void )

Gets header GrkImage (where main and tile header information is stored).

Returns
GrkImage

References grk::CodeStream::headerImage_.

Referenced by dump(), dumpMainHeader(), and grk::SIZMarker::read().

◆ getImage() [1/2]

GrkImage * grk::CodeStreamDecompress::getImage ( uint16_t tile_index,
bool wait )
overridevirtual

Gets GrkImage for specified tile.

Parameters
tile_indextile index
Returns
GrkImage

Implements grk::IDecompressor.

References getImage(), tileCache_, and wait().

Referenced by getImage(), and getImage().

◆ getImage() [2/2]

GrkImage * grk::CodeStreamDecompress::getImage ( void )
overridevirtual

Gets composite GrkImage for all tiles in decompress region.

Returns
GrkImage

Implements grk::IDecompressor.

References getImage(), multiTileComposite_, and wait().

◆ getProgressionState()

grk_progression_state grk::CodeStreamDecompress::getProgressionState ( uint16_t tile_index)
overridevirtual

Gets the grk_progression_state for a tile.

Parameters
tile_index
Returns
grk_progression_state

Implements grk::IDecompressor.

References getProgressionState(), and tileCache_.

Referenced by getProgressionState().

◆ getTileProcessor()

ITileProcessor * grk::CodeStreamDecompress::getTileProcessor ( uint16_t tile_index)

Gets tile processor for specified tile index.

Parameters
tile_indextile index
Returns
ITileProcessor

References grk::CodeStream::cp_, defaultTcp_, getTileProcessor(), grk::CodeStream::headerImage_, region_, grk::CodeStream::stream_, and tileCache_.

Referenced by decompressTileImpl(), decompressTLM(), getTileProcessor(), readSOT(), and scheduleTileBatch().

◆ init()

◆ initDefaultTCP()

bool grk::CodeStreamDecompress::initDefaultTCP ( )

Initializes default TileCodingParams.

Returns
true if initialization succeeded

References defaultTcp_, grk::CodeStream::headerImage_, and initDefaultTCP().

Referenced by initDefaultTCP(), and grk::SIZMarker::read().

◆ initTilesToDecompress()

void grk::CodeStreamDecompress::initTilesToDecompress ( Rect16 region)

Initializes tile completeness set.

Parameters
regionregion to decompress

References initTilesToDecompress(), and tilesToDecompress_.

Referenced by initTilesToDecompress(), and grk::SIZMarker::read().

◆ mergePpm()

bool grk::CodeStreamDecompress::mergePpm ( CodingParams * p_cp)
private

Merges all PPM markers read (Packed headers, main header).

Parameters
p_cpmain coding parameters.
Returns
true if successful

References grk::CodingParams::ppmMarkers_.

Referenced by readHeaderProcedure().

◆ needsHeaderRead()

bool grk::CodeStreamDecompress::needsHeaderRead ( void ) const

Checks if header needs to be read.

Returns
true if header needs to be read

References headerError_, and headerRead_.

◆ onRowCompleted()

void grk::CodeStreamDecompress::onRowCompleted ( uint16_t tileIndexBegin)
private

◆ postMultiTile() [1/2]

std::function< void()> grk::CodeStreamDecompress::postMultiTile ( ITileProcessor * tileProcessor)
private

Creates a Post Task object.

Per-tile post-processing lambda, executed when each tile's decompression future completes.

Parameters
tileProcessor
Returns
std::function<void()>

Calls post_decompressT2T1(scratchImage_) which:

  • Multi-tile (has_multiple_tiles=true): extracts tile data into a new image, sets image_ on the processor. getImage() will return this image.
  • Single-tile (has_multiple_tiles=false): transfers tile data INTO scratchImage_. image_ is NOT set, so getImage() returns null. Data stays in scratchImage_ until postMultiTile() (no-arg) transfers it to multiTileComposite_.

References grk::CodeStream::cp_, decompressInFlight_, decompressThrottleCV_, decompressThrottleMutex_, grk::ITileProcessor::getImage(), grk::ITileProcessor::getIndex(), ioBandCallback_, maxDecompressInFlight_, numTilesDecompressed_, grk::ITileProcessor::post_decompressT2T1(), postMultiTile(), grk::ITileProcessor::release(), scratchImage_, grk::ITileProcessor::setBestEffortDecompressed(), grk::CodeStream::stream_, success_, and tileCompletion_.

Referenced by decompressImpl(), postMultiTile(), postMultiTile(), schedule(), and startTLMDecompress().

◆ postMultiTile() [2/2]

std::function< void()> grk::CodeStreamDecompress::postMultiTile ( void )
private

Final post-processing lambda, executed by wait(nullptr) after all tiles complete.

For non-skipAllocateComposite mode: transfers pixel data from scratchImage_ to multiTileComposite_ and applies postProcess (colour space, ICC, precision). After this runs, scratchImage_ is empty and multiTileComposite_ has the final post-processed image. getImage() returns multiTileComposite_.

This lambda is stored in postMulti_ and only runs during a full wait (wait(nullptr)), NOT during the swath-based tileCompletion early-return path.

References grk::CodeStream::cp_, grk::grklog, ioBandCallback_, multiTileComposite_, numTilesDecompressed_, postMultiTile(), postProcess(), scratchImage_, success_, and tilesToDecompress_.

◆ postProcess()

bool grk::CodeStreamDecompress::postProcess ( GrkImage * img)

Post processes decompressed image.

Parameters
imgGrkImage
Returns
true if successful

References grk::CodeStream::cp_, grk::GrkImage::filterComponents(), postPostProcess_, postProcess(), and grk::GrkImage::postProcess().

Referenced by postMultiTile(), postProcess(), and postSingleTile().

◆ postReadHeader()

void grk::CodeStreamDecompress::postReadHeader ( void )
private

◆ postSingleTile()

◆ readCAP()

bool grk::CodeStreamDecompress::readCAP ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a CAP marker.

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_, grk_population_count(), grk::grk_read(), grk::grklog, and isHT_.

Referenced by CodeStreamDecompress().

◆ readCBD()

bool grk::CodeStreamDecompress::readCBD ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a CBD marker (Component bit depth definition).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References GRK_MAX_SUPPORTED_IMAGE_PRECISION, grk::grk_read(), grk::grklog, and grk::CodeStream::headerImage_.

Referenced by CodeStreamDecompress().

◆ readCRG()

bool grk::CodeStreamDecompress::readCRG ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a CRG marker (Component registration).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::grk_read(), grk::grklog, and grk::CodeStream::headerImage_.

Referenced by CodeStreamDecompress().

◆ readHeader()

◆ readHeaderProcedure()

◆ readPLM()

bool grk::CodeStreamDecompress::readPLM ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a PLM marker (Packet length, main header marker).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_.

Referenced by CodeStreamDecompress().

◆ readPPM()

bool grk::CodeStreamDecompress::readPPM ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a PPM marker (Packed headers, main header).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_.

Referenced by CodeStreamDecompress().

◆ readSIZ()

bool grk::CodeStreamDecompress::readSIZ ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a SIZ marker (image and tile size).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_, grk::CodeStream::headerImage_, and grk::SIZMarker::read().

Referenced by CodeStreamDecompress().

◆ readSOC()

bool grk::CodeStreamDecompress::readSOC ( )
private

Reads a SOC marker (Start of Codestream).

References grk::grk_read(), grk::MARKER_BYTES, markerCache_, grk::SOC, and grk::CodeStream::stream_.

Referenced by readHeaderProcedure().

◆ readSOT()

bool grk::CodeStreamDecompress::readSOT ( uint8_t * headerData,
uint16_t headerSize )
private

Read SOT (Start of tile part) marker.

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_, currTileIndex_, currTilePartInfo_, currTileProcessor_, getTileProcessor(), grk::grk_read(), grk::grklog, grk::MARKER_BYTES_PLUS_MARKER_LENGTH_BYTES, grk::sotMarkerSegmentLen, grk::CodeStream::stream_, tileCache_, and tilesToDecompress_.

Referenced by CodeStreamDecompress().

◆ readTLM()

bool grk::CodeStreamDecompress::readTLM ( uint8_t * headerData,
uint16_t headerSize )
private

Reads a TLM marker (Tile Length Marker).

Parameters
headerDataheader data
headerSizesize of header data
Returns
true if successful

References grk::CodeStream::cp_, and GRK_RANDOM_ACCESS_TLM.

Referenced by CodeStreamDecompress().

◆ readUNK()

bool grk::CodeStreamDecompress::readUNK ( void )
private

Reads unknown marker.

Returns
true
false

References grk::grklog, grk::MARKER_BYTES, markerCache_, markerParser_, and grk::CodeStream::stream_.

Referenced by readHeaderProcedure().

◆ schedule()

◆ scheduleSwathCopy()

void grk::CodeStreamDecompress::scheduleSwathCopy ( const grk_wait_swath * swath,
grk_swath_buffer * buf )
overridevirtual

Schedule SIMD-accelerated tile-to-swath copies for decoded tiles.

For each tile in the swath range, retrieves the decoded tile image and submits a Taskflow task that converts int32 component data to the caller's output buffer (int8/int16/int32, signed or unsigned).

Tile image lookup

  • Multi-tile (has_multiple_tiles=true): post_decompressT2T1 calls extractFrom() which sets image_ on the tile processor. getImage() returns this per-tile image directly — no composite needed.
  • Single-tile (has_multiple_tiles=false): post_decompressT2T1 calls transferDataFrom() into scratchImage_ but does NOT set image_. getImage() returns null, so the fallback to scratchImage_ is used. IMPORTANT: scratchImage_ only contains valid data if the caller used the swath-based wait path (wait(swath) with tileCompletion_). If wait(nullptr) was called instead, postMulti_() will have already transferred data from scratchImage_ to multiTileComposite_, leaving scratchImage_ empty. In that case, callers should use getImage() (which returns multiTileComposite_) rather than this function.
Parameters
swathTile range and grid info from grk_decompress_wait
bufOutput buffer descriptor (data pointer, layout, precision)

Reimplemented from grk::IDecompressor.

References grk_swath_buffer::data, TFSingleton::get(), grk::hwy_copy_tile_to_swath(), multiTileComposite_, grk_wait_swath::num_tile_cols, grk_swath_buffer::prec, scheduleSwathCopy(), scratchImage_, swathCopyFutureManager_, grk_wait_swath::tile_x0, grk_wait_swath::tile_y0, and tileCache_.

Referenced by scheduleSwathCopy().

◆ scheduleTileBatch()

◆ sequentialParseAndSchedule()

◆ setBandCallback()

void grk::CodeStreamDecompress::setBandCallback ( grk_io_band_callback callback,
void * user_data )
overridevirtual

Sets a band-completion callback for incremental writing.

Must be called after readHeader() but before decompress().

Reimplemented from grk::IDecompressor.

References ioBandCallback_, and ioBandUserData_.

◆ setDecompressRegion()

bool grk::CodeStreamDecompress::setDecompressRegion ( RectD region)
protected

Sets the decompress region.

Parameters
regionregion in canvas coordinates, relative to image origin
Returns
true if region is not set by user, or if it is set successfully

References grk::ceildiv(), grk::CodeStream::cp_, grk::grklog, grk::CodeStream::headerImage_, multiTileComposite_, region_, setDecompressRegion(), tileCache_, tileCompletion_, tilesToDecompress_, grk::Rect< T >::x0, grk::Rect< T >::x1, grk::Rect< T >::y0, and grk::Rect< T >::y1.

Referenced by postReadHeader(), and setDecompressRegion().

◆ setNumComponents()

void grk::CodeStreamDecompress::setNumComponents ( uint16_t numComps)

◆ setPostPostProcess()

void grk::CodeStreamDecompress::setPostPostProcess ( std::function< bool(GrkImage *)> func)

Sets the Post Post Process object.

Parameters
func

References postPostProcess_, and setPostPostProcess().

Referenced by setPostPostProcess().

◆ setProgressionState()

bool grk::CodeStreamDecompress::setProgressionState ( grk_progression_state state)
overridevirtual

Sets the grk_progression_state for a tile.

Parameters
stategrk_progression_state
Returns
true if successful

Implements grk::IDecompressor.

References setProgressionState(), and tileCache_.

Referenced by setProgressionState().

◆ startDecompressConsumer()

void grk::CodeStreamDecompress::startDecompressConsumer ( uint16_t maxInFlight)
private

◆ startSequentialDecompress()

◆ startTLMDecompress()

bool grk::CodeStreamDecompress::startTLMDecompress ( std::set< uint16_t > & pendingTiles)
private

◆ wait() [1/2]

void grk::CodeStreamDecompress::wait ( grk_wait_swath * swath)
overridevirtual

Wait for tile decompression to complete.

Two calling modes:

Swath-based (swath != nullptr, tileCompletion_ active): Returns as soon as the requested swath tiles are decompressed. Tile data is available via entry->processor->getImage() for multi-tile images (has_multiple_tiles=true), or in scratchImage_ for single-tile images. NOTE: postMulti_() does NOT run in this path, so scratchImage_ data is raw (no postProcess). Callers needing post-processed data for single-tile images must subsequently call wait(nullptr) or use getImage() which triggers a full wait.

Full wait (swath == nullptr, or no tileCompletion_): Joins all worker threads, waits for all tile futures, and runs postMulti_() which transfers scratchImage_ data to multiTileComposite_ with post-processing applied.

Implements grk::IDecompressor.

References batchTileScheduledRows_, decompressConsumer_, decompressQueue_, decompressTileFutureManager_, decompressWorker_, doTileBatching(), fetchByTileFutures_, grk::grklog, postMulti_, scheduleTileBatch(), success_, tileCompletion_, and wait().

Referenced by decompressTile(), getImage(), getImage(), wait(), and wait().

◆ wait() [2/2]

void grk::CodeStreamDecompress::wait ( uint16_t tile_index)
private

◆ waitSwathCopy()

void grk::CodeStreamDecompress::waitSwathCopy ( )
overridevirtual

Wait for all in-flight swath copy tasks to complete.

Reimplemented from grk::IDecompressor.

References swathCopyFutureManager_, and waitSwathCopy().

Referenced by waitSwathCopy().

Member Data Documentation

◆ activeImage_

std::unique_ptr<GrkImage, std::function<void(GrkImage*)> > grk::CodeStreamDecompress::activeImage_
private

◆ bandDrainCV_

std::condition_variable grk::CodeStreamDecompress::bandDrainCV_
private

◆ bandOrderMutex_

std::mutex grk::CodeStreamDecompress::bandOrderMutex_
private

◆ batchTileInitialRows_

uint16_t grk::CodeStreamDecompress::batchTileInitialRows_ = 2
private

◆ batchTileNextRows_

uint16_t grk::CodeStreamDecompress::batchTileNextRows_ = 2
private

Referenced by scheduleTileBatch().

◆ batchTileQueueCondition_

std::condition_variable grk::CodeStreamDecompress::batchTileQueueCondition_
private

◆ batchTileQueueMutex_

std::mutex grk::CodeStreamDecompress::batchTileQueueMutex_
private

◆ batchTileQueueSequential_

std::queue<ITileProcessor*> grk::CodeStreamDecompress::batchTileQueueSequential_
private

◆ batchTileQueueTLM_

std::queue<uint16_t> grk::CodeStreamDecompress::batchTileQueueTLM_
private

Referenced by decompressTLM(), and scheduleTileBatch().

◆ batchTileScheduledRows_

int32_t grk::CodeStreamDecompress::batchTileScheduledRows_ = 0
private

◆ batchTileScheduleHeadroomSequential_

uint16_t grk::CodeStreamDecompress::batchTileScheduleHeadroomSequential_ = 0
private

◆ batchTileUnscheduledSequential_

uint16_t grk::CodeStreamDecompress::batchTileUnscheduledSequential_ = 0
private

◆ chunkBuffer_

std::shared_ptr<ChunkBuffer<> > grk::CodeStreamDecompress::chunkBuffer_
private

◆ coderPool_

CoderPool grk::CodeStreamDecompress::coderPool_
private

◆ compressedChunkCache_

std::unique_ptr<CompressedChunkCache> grk::CodeStreamDecompress::compressedChunkCache_
private

Referenced by decompressImpl(), and init().

◆ currTileIndex_

int32_t grk::CodeStreamDecompress::currTileIndex_ = -1
private

◆ currTilePartInfo_

TilePartInfo grk::CodeStreamDecompress::currTilePartInfo_
private

◆ currTileProcessor_

ITileProcessor* grk::CodeStreamDecompress::currTileProcessor_ = nullptr
private

Tile processor currently being parsed.

Referenced by decompress(), readSOT(), and sequentialParseAndSchedule().

◆ decompressConsumer_

std::thread grk::CodeStreamDecompress::decompressConsumer_
private

◆ decompressInFlight_

uint16_t grk::CodeStreamDecompress::decompressInFlight_ = 0
private

◆ decompressQueue_

std::unique_ptr<ConcurrentQueue<std::function<void()> > > grk::CodeStreamDecompress::decompressQueue_
private

◆ decompressStart_

std::function<bool(std::set<uint16_t>&)> grk::CodeStreamDecompress::decompressStart_
private

Referenced by decompressImpl().

◆ decompressThrottleCV_

std::condition_variable grk::CodeStreamDecompress::decompressThrottleCV_
private

◆ decompressThrottleMutex_

std::mutex grk::CodeStreamDecompress::decompressThrottleMutex_
private

◆ decompressTileFutureManager_

TileFutureManager grk::CodeStreamDecompress::decompressTileFutureManager_
private

futures for scheduled tiles

Referenced by decompress(), decompressTileImpl(), genDecompressTileTLMTask(), schedule(), wait(), and wait().

◆ decompressWorker_

std::thread grk::CodeStreamDecompress::decompressWorker_
private

◆ defaultTcp_

std::unique_ptr<TileCodingParams> grk::CodeStreamDecompress::defaultTcp_
private

Default TileCodingParams.

Store decoding parameters common to all tiles (information like COD, COC and RGN in main header)

Referenced by activateScratch(), CodeStreamDecompress(), dumpMainHeader(), getTileProcessor(), initDefaultTCP(), readHeader(), and setNumComponents().

◆ fetchByTileFutures_

std::vector<std::future<bool> > grk::CodeStreamDecompress::fetchByTileFutures_
private

Referenced by fetchByTile(), wait(), and wait().

◆ grkRegisterReclaimCallback_

grk_io_register_reclaim_callback grk::CodeStreamDecompress::grkRegisterReclaimCallback_ = nullptr
private

callback to reclaim io buffers

Referenced by init().

◆ headerError_

bool grk::CodeStreamDecompress::headerError_ = false
private

true if there was an error reading the main header

Referenced by needsHeaderRead(), and readHeader().

◆ headerRead_

bool grk::CodeStreamDecompress::headerRead_ = false
private

true if main header was successfully read

Referenced by needsHeaderRead(), postReadHeader(), and readHeader().

◆ ioBandCallback_

grk_io_band_callback grk::CodeStreamDecompress::ioBandCallback_ = nullptr
private

callback invoked when a tile-row band is ready for incremental writing

Referenced by activateScratch(), decompress(), decompressTLM(), getBandCallback(), init(), postMultiTile(), postMultiTile(), schedule(), sequentialParseAndSchedule(), and setBandCallback().

◆ ioBandUserData_

void* grk::CodeStreamDecompress::ioBandUserData_ = nullptr
private

◆ ioBufferCallback_

grk_io_pixels_callback grk::CodeStreamDecompress::ioBufferCallback_ = nullptr
private

callback for io pixels

Referenced by init().

◆ ioUserData_

void* grk::CodeStreamDecompress::ioUserData_ = nullptr
private

io user data

Referenced by init().

◆ isHT_

bool grk::CodeStreamDecompress::isHT_ = false
private

global HT flag

Referenced by readCAP(), and readHeader().

◆ markerCache_

std::unique_ptr<MarkerCache> grk::CodeStreamDecompress::markerCache_
private

◆ markerParser_

◆ maxDecompressInFlight_

uint16_t grk::CodeStreamDecompress::maxDecompressInFlight_ = 0
private

◆ maxFetchedTileRow_

std::atomic<int32_t> grk::CodeStreamDecompress::maxFetchedTileRow_ {-1}
private

Referenced by fetchByTile().

◆ maxRowsAhead_

int32_t grk::CodeStreamDecompress::maxRowsAhead_ = 2
staticconstexprprivate

◆ multiTileComposite_

std::unique_ptr<GrkImage, RefCountedDeleter<GrkImage> > grk::CodeStreamDecompress::multiTileComposite_
private

multi tile composite GrkImage Used to composite multiple tiles - subsampled and reduced for region decompression

Referenced by activateScratch(), CodeStreamDecompress(), decompress(), decompressTile(), getCompositeNoWait(), getImage(), postMultiTile(), postReadHeader(), readHeader(), scheduleSwathCopy(), and setDecompressRegion().

◆ nextBandTileY_

uint16_t grk::CodeStreamDecompress::nextBandTileY_ = 0
private

◆ numTilesDecompressed_

std::atomic<uint32_t> grk::CodeStreamDecompress::numTilesDecompressed_ {0}
private

number of decompressed tiles

Referenced by decompressImpl(), postMultiTile(), and postMultiTile().

◆ pendingBands_

std::map<uint16_t, PendingBand_> grk::CodeStreamDecompress::pendingBands_
private

Referenced by decompress().

◆ postMulti_

std::function<void()> grk::CodeStreamDecompress::postMulti_
private

Referenced by wait().

◆ postPostProcess_

std::function<bool(GrkImage*)> grk::CodeStreamDecompress::postPostProcess_
private

post post-decompress method

Referenced by postProcess(), and setPostPostProcess().

◆ region_

Rect32 grk::CodeStreamDecompress::region_
private

Holds unreduced unsubsampled decompress region , if set.

Referenced by activateScratch(), getTileProcessor(), and setDecompressRegion().

◆ scratchImage_

std::unique_ptr<GrkImage, RefCountedDeleter<GrkImage> > grk::CodeStreamDecompress::scratchImage_
private

Scratch GrkImage for decompressor This image may composite multiple tiles, if needed.

Referenced by decompressImpl(), decompressTileImpl(), postMultiTile(), postMultiTile(), postSingleTile(), schedule(), scheduleSwathCopy(), and startTLMDecompress().

◆ success_

std::atomic<bool> grk::CodeStreamDecompress::success_ {true}
private

◆ swathCopyFutureManager_

TileFutureManager grk::CodeStreamDecompress::swathCopyFutureManager_
private

futures for swath copy tasks scheduled via scheduleSwathCopy()

Referenced by scheduleSwathCopy(), and waitSwathCopy().

◆ tileCache_

◆ tileCompletion_

◆ tileMarkerParsers_

std::vector<std::unique_ptr<MarkerParser> > grk::CodeStreamDecompress::tileMarkerParsers_
private

◆ tilePartFetchByTile_

std::shared_ptr<std::unordered_map<uint16_t, std::shared_ptr<TPFetchSeq> > > grk::CodeStreamDecompress::tilePartFetchByTile_
private

Referenced by schedule(), and startTLMDecompress().

◆ tilePartFetchFlat_

std::shared_ptr<TPFetchSeq> grk::CodeStreamDecompress::tilePartFetchFlat_
private

◆ tilesToDecompress_


The documentation for this class was generated from the following files: