CodeStreamDecompress.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
namespace grk
{
typedef std::function<bool(uint8_t* headerData, uint16_t header_size)> MARKER_FUNC;
struct marker_handler
{
marker_handler(uint16_t ID, uint32_t flags, MARKER_FUNC f) : id(ID), states(flags), func(f) {}
uint16_t id;
uint32_t states;
MARKER_FUNC func;
};
class CodeStreamDecompress : public CodeStream, public ICodeStreamDecompress
{
public:
CodeStreamDecompress(BufferedStream* stream);
virtual ~CodeStreamDecompress();
TileProcessor* allocateProcessor(uint16_t tileIndex);
DecompressorState* getDecompressorState(void);
TileCodingParams* get_current_decode_tcp(void);
bool isDecodingTilePartHeader();
bool readHeader(grk_header_info* header_info);
GrkImage* getImage(uint16_t tileIndex);
GrkImage* getImage(void);
std::vector<GrkImage*> getAllImages(void);
void init(grk_decompress_core_params* p_param);
bool setDecompressRegion(grk_rect_single region);
bool decompress(grk_plugin_tile* tile);
bool decompressTile(uint16_t tileIndex);
bool preProcess(void);
bool postProcess(void);
CodeStreamInfo* getCodeStreamInfo(void);
GrkImage* getCompositeImage();
bool readMarker(void);
bool readMarker(bool suppressWarning);
GrkImage* getHeaderImage(void);
uint16_t getCurrentMarker(void);
void dump(uint32_t flag, FILE* outputFileStream);
bool needsHeaderRead(void);
void setExpectSOD();
protected:
void dump_MH_info(FILE* outputFileStream);
void dump_image_header(GrkImage* image, bool dev_dump_flag, FILE* outputFileStream);
void dump_tile_info(TileCodingParams* default_tile, uint32_t numcomps, FILE* outputFileStream);
void dump_image_comp_header(grk_image_comp* comp, bool dev_dump_flag, FILE* outputFileStream);
private:
bool readCurrentMarkerBody(uint16_t* markerSize);
bool endOfCodeStream(void);
bool read_short(uint16_t* val);
bool process_marker(const marker_handler* marker_handler, uint16_t marker_size);
bool readSOTorEOC(void);
bool parseTileParts(bool* can_decode_tile_data);
bool readHeaderProcedureImpl(void);
bool decompressExec();
bool decompressTile();
bool findNextSOT(TileProcessor* tileProcessor);
bool skipNonScheduledTLM(CodingParams* cp);
bool hasTLM(void);
void nextTLM(void);
bool decompressTiles(void);
bool decompressValidation(void);
bool copy_default_tcp(void);
bool read_unk(void);
void addMarker(uint16_t id, uint64_t pos, uint32_t len);
bool read_mct(uint8_t* headerData, uint16_t header_size);
bool read_mcc(uint8_t* headerData, uint16_t header_size);
bool read_mco(uint8_t* headerData, uint16_t header_size);
bool add_mct(TileCodingParams* p_tcp, GrkImage* p_image, uint32_t index);
bool read_cbd(uint8_t* headerData, uint16_t header_size);
bool read_rgn(uint8_t* headerData, uint16_t header_size);
bool readHeaderProcedure(void);
bool read_soc();
bool read_siz(uint8_t* headerData, uint16_t header_size);
bool read_cap(uint8_t* headerData, uint16_t header_size);
bool read_com(uint8_t* headerData, uint16_t header_size);
bool read_cod(uint8_t* headerData, uint16_t header_size);
bool read_poc(uint8_t* headerData, uint16_t header_size);
bool read_crg(uint8_t* headerData, uint16_t header_size);
bool read_tlm(uint8_t* headerData, uint16_t header_size);
bool read_plm(uint8_t* headerData, uint16_t header_size);
bool read_plt(uint8_t* headerData, uint16_t header_size);
bool read_ppm(uint8_t* headerData, uint16_t header_size);
bool read_ppt(uint8_t* headerData, uint16_t header_size);
bool read_sot(uint8_t* headerData, uint16_t header_size);
bool read_SPCod_SPCoc(uint16_t compno, uint8_t* headerData, uint16_t* header_size);
bool read_SQcd_SQcc(bool fromQCC, uint16_t compno, uint8_t* headerData, uint16_t* header_size);
bool merge_ppm(CodingParams* p_cp);
bool merge_ppt(TileCodingParams* p_tcp);
bool read_coc(uint8_t* headerData, uint16_t header_size);
bool read_qcd(uint8_t* headerData, uint16_t header_size);
bool read_qcc(uint8_t* headerData, uint16_t header_size);
const marker_handler* get_marker_handler(uint16_t id);
bool createOutputImage(void);
bool checkForIllegalTilePart(void);
std::map<uint16_t, marker_handler*> marker_map;
DecompressorState decompressorState_;
bool expectSOD_;
uint16_t curr_marker_;
bool headerError_;
bool headerRead_;
uint8_t* marker_scratch_;
uint16_t marker_scratch_size_;
GrkImage* outputImage_;
TileCache* tileCache_;
StripCache stripCache_;
grk_io_pixels_callback ioBufferCallback;
void* ioUserData;
grk_io_register_reclaim_callback grkRegisterReclaimCallback_;
};
} // namespace grk
grk::CodeStreamDecompress
Definition CodeStreamDecompress.h:38
grk::CodeStreamDecompress::getCodeStreamInfo
CodeStreamInfo * getCodeStreamInfo(void)
Definition CodeStreamDecompress.cpp:141
grk::CodeStreamDecompress::addMarker
void addMarker(uint16_t id, uint64_t pos, uint32_t len)
Add main header marker information.
Definition CodeStreamDecompress.cpp:651
grk::CodeStreamDecompress::marker_map
std::map< uint16_t, marker_handler * > marker_map
Definition CodeStreamDecompress.h:320
grk::CodeStreamDecompress::dump_image_header
void dump_image_header(GrkImage *image, bool dev_dump_flag, FILE *outputFileStream)
Dump an image header structure.
Definition CodeStreamDecompress.cpp:1163
grk::CodeStreamDecompress::decompressTiles
bool decompressTiles(void)
Definition CodeStreamDecompress.cpp:454
grk::CodeStreamDecompress::isDecodingTilePartHeader
bool isDecodingTilePartHeader()
Definition CodeStreamDecompress.cpp:145
grk::CodeStreamDecompress::findNextSOT
bool findNextSOT(TileProcessor *tileProcessor)
Definition CodeStreamDecompress.cpp:929
grk::CodeStreamDecompress::outputImage_
GrkImage * outputImage_
Definition CodeStreamDecompress.h:328
grk::CodeStreamDecompress::headerRead_
bool headerRead_
Definition CodeStreamDecompress.h:325
grk::CodeStreamDecompress::dump_MH_info
void dump_MH_info(FILE *outputFileStream)
Definition CodeStreamDecompress.cpp:1153
grk::CodeStreamDecompress::read_plm
bool read_plm(uint8_t *headerData, uint16_t header_size)
Reads a PLM marker (Packet length, main header marker)
Definition CodeStreamDecompress_Markers.cpp:538
grk::CodeStreamDecompress::needsHeaderRead
bool needsHeaderRead(void)
Definition CodeStreamDecompress.cpp:111
grk::CodeStreamDecompress::merge_ppm
bool merge_ppm(CodingParams *p_cp)
Merges all PPM markers read (Packed headers, main header)
Definition CodeStreamDecompress_Markers.cpp:587
grk::CodeStreamDecompress::init
void init(grk_decompress_core_params *p_param)
Definition CodeStreamDecompress.cpp:353
grk::CodeStreamDecompress::createOutputImage
bool createOutputImage(void)
Definition CodeStreamDecompress.cpp:797
grk::CodeStreamDecompress::getImage
GrkImage * getImage(void)
Definition CodeStreamDecompress.cpp:162
grk::CodeStreamDecompress::read_soc
bool read_soc()
Reads a SOC marker (Start of Codestream)
Definition CodeStreamDecompress_Markers.cpp:1932
grk::CodeStreamDecompress::process_marker
bool process_marker(const marker_handler *marker_handler, uint16_t marker_size)
Definition CodeStreamDecompress.cpp:958
grk::CodeStreamDecompress::dump
void dump(uint32_t flag, FILE *outputFileStream)
Definition CodeStreamDecompress.cpp:1112
grk::CodeStreamDecompress::decompress
bool decompress(grk_plugin_tile *tile)
Definition CodeStreamDecompress.cpp:366
grk::CodeStreamDecompress::read_rgn
bool read_rgn(uint8_t *headerData, uint16_t header_size)
Reads a RGN marker (Region Of Interest)
Definition CodeStreamDecompress_Markers.cpp:750
grk::CodeStreamDecompress::read_mco
bool read_mco(uint8_t *headerData, uint16_t header_size)
Reads a MCO marker (Multiple Component Transform Ordering)
Definition CodeStreamDecompress_Markers.cpp:800
grk::CodeStreamDecompress::stripCache_
StripCache stripCache_
Definition CodeStreamDecompress.h:330
grk::CodeStreamDecompress::ioUserData
void * ioUserData
Definition CodeStreamDecompress.h:332
grk::CodeStreamDecompress::read_ppm
bool read_ppm(uint8_t *headerData, uint16_t header_size)
Reads a PPM marker (Packed headers, main header)
Definition CodeStreamDecompress_Markers.cpp:573
grk::CodeStreamDecompress::expectSOD_
bool expectSOD_
Definition CodeStreamDecompress.h:322
grk::CodeStreamDecompress::read_cap
bool read_cap(uint8_t *headerData, uint16_t header_size)
Reads a CAP marker.
Definition CodeStreamDecompress_Markers.cpp:1961
grk::CodeStreamDecompress::readHeaderProcedure
bool readHeaderProcedure(void)
Definition CodeStreamDecompress.cpp:664
grk::CodeStreamDecompress::read_mcc
bool read_mcc(uint8_t *headerData, uint16_t header_size)
Reads a MCC marker (Multiple Component Collection)
Definition CodeStreamDecompress_Markers.cpp:1267
grk::CodeStreamDecompress::skipNonScheduledTLM
bool skipNonScheduledTLM(CodingParams *cp)
Definition CodeStreamDecompress.cpp:820
grk::CodeStreamDecompress::dump_image_comp_header
void dump_image_comp_header(grk_image_comp *comp, bool dev_dump_flag, FILE *outputFileStream)
Dump a component image header structure.
Definition CodeStreamDecompress.cpp:1194
grk::CodeStreamDecompress::read_crg
bool read_crg(uint8_t *headerData, uint16_t header_size)
Reads a CRG marker (Component registration)
Definition CodeStreamDecompress_Markers.cpp:510
grk::CodeStreamDecompress::read_cod
bool read_cod(uint8_t *headerData, uint16_t header_size)
Reads a COD marker (Coding Style defaults)
Definition CodeStreamDecompress_Markers.cpp:1683
grk::CodeStreamDecompress::read_com
bool read_com(uint8_t *headerData, uint16_t header_size)
Reads a COM marker (comments)
Definition CodeStreamDecompress_Markers.cpp:2024
grk::CodeStreamDecompress::read_SPCod_SPCoc
bool read_SPCod_SPCoc(uint16_t compno, uint8_t *headerData, uint16_t *header_size)
Reads a SPCod or SPCoc element, i.e.
Definition CodeStreamDecompress_Markers.cpp:1127
grk::CodeStreamDecompress::setDecompressRegion
bool setDecompressRegion(grk_rect_single region)
Definition CodeStreamDecompress.cpp:244
grk::CodeStreamDecompress::read_qcd
bool read_qcd(uint8_t *headerData, uint16_t header_size)
Reads a QCD marker (Quantization defaults)
Definition CodeStreamDecompress_Markers.cpp:1839
grk::CodeStreamDecompress::dump_tile_info
void dump_tile_info(TileCodingParams *default_tile, uint32_t numcomps, FILE *outputFileStream)
Definition CodeStreamDecompress.cpp:1053
grk::CodeStreamDecompress::getAllImages
std::vector< GrkImage * > getAllImages(void)
Definition CodeStreamDecompress.cpp:158
grk::CodeStreamDecompress::read_cbd
bool read_cbd(uint8_t *headerData, uint16_t header_size)
Reads a CBD marker (Component bit depth definition)
Definition CodeStreamDecompress_Markers.cpp:926
grk::CodeStreamDecompress::setExpectSOD
void setExpectSOD()
Definition CodeStreamDecompress.cpp:115
grk::CodeStreamDecompress::decompressorState_
DecompressorState decompressorState_
Definition CodeStreamDecompress.h:321
grk::CodeStreamDecompress::curr_marker_
uint16_t curr_marker_
Definition CodeStreamDecompress.h:323
grk::CodeStreamDecompress::read_plt
bool read_plt(uint8_t *headerData, uint16_t header_size)
Reads a PLT marker (Packet length, tile-part header)
Definition CodeStreamDecompress_Markers.cpp:553
grk::CodeStreamDecompress::marker_scratch_
uint8_t * marker_scratch_
Definition CodeStreamDecompress.h:326
grk::CodeStreamDecompress::decompressTile
bool decompressTile()
Definition CodeStreamDecompress.cpp:833
grk::CodeStreamDecompress::getDecompressorState
DecompressorState * getDecompressorState(void)
Definition CodeStreamDecompress.cpp:149
grk::CodeStreamDecompress::read_short
bool read_short(uint16_t *val)
Definition CodeStreamDecompress.cpp:985
grk::CodeStreamDecompress::getCurrentMarker
uint16_t getCurrentMarker(void)
Definition CodeStreamDecompress.cpp:656
grk::CodeStreamDecompress::allocateProcessor
TileProcessor * allocateProcessor(uint16_t tileIndex)
Definition CodeStreamDecompress.cpp:123
grk::CodeStreamDecompress::copy_default_tcp
bool copy_default_tcp(void)
Definition CodeStreamDecompress.cpp:640
grk::CodeStreamDecompress::readHeaderProcedureImpl
bool readHeaderProcedureImpl(void)
Definition CodeStreamDecompress.cpp:678
grk::CodeStreamDecompress::read_qcc
bool read_qcc(uint8_t *headerData, uint16_t header_size)
Reads a QCC marker (Quantization component)
Definition CodeStreamDecompress_Markers.cpp:1881
grk::CodeStreamDecompress::postProcess
bool postProcess(void)
Definition CodeStreamDecompress.cpp:1034
grk::CodeStreamDecompress::readMarker
bool readMarker(void)
Definition CodeStreamDecompress.cpp:1006
grk::CodeStreamDecompress::read_ppt
bool read_ppt(uint8_t *headerData, uint16_t header_size)
Reads a PPT marker (Packed packet headers, tile-part header)
Definition CodeStreamDecompress_Markers.cpp:598
grk::CodeStreamDecompress::hasTLM
bool hasTLM(void)
Definition CodeStreamDecompress.cpp:813
grk::CodeStreamDecompress::add_mct
bool add_mct(TileCodingParams *p_tcp, GrkImage *p_image, uint32_t index)
Definition CodeStreamDecompress_Markers.cpp:847
grk::CodeStreamDecompress::grkRegisterReclaimCallback_
grk_io_register_reclaim_callback grkRegisterReclaimCallback_
Definition CodeStreamDecompress.h:333
grk::CodeStreamDecompress::get_current_decode_tcp
TileCodingParams * get_current_decode_tcp(void)
Definition CodeStreamDecompress.cpp:136
grk::CodeStreamDecompress::parseTileParts
bool parseTileParts(bool *can_decode_tile_data)
Definition CodeStreamDecompress_Markers.cpp:124
grk::CodeStreamDecompress::merge_ppt
bool merge_ppt(TileCodingParams *p_tcp)
Merges all PPT markers read (Packed headers, tile-part header)
Definition CodeStreamDecompress_Markers.cpp:681
grk::CodeStreamDecompress::read_siz
bool read_siz(uint8_t *headerData, uint16_t header_size)
Reads a SIZ marker (image and tile size)
Definition CodeStreamDecompress_Markers.cpp:2004
grk::CodeStreamDecompress::tileCache_
TileCache * tileCache_
Definition CodeStreamDecompress.h:329
grk::CodeStreamDecompress::getCompositeImage
GrkImage * getCompositeImage()
Definition CodeStreamDecompress.cpp:119
grk::CodeStreamDecompress::preProcess
bool preProcess(void)
Definition CodeStreamDecompress.cpp:1030
grk::CodeStreamDecompress::get_marker_handler
const marker_handler * get_marker_handler(uint16_t id)
Reads the lookup table containing all the marker, status and action, and returns the handler associat...
Definition CodeStreamDecompress.cpp:995
grk::CodeStreamDecompress::read_SQcd_SQcc
bool read_SQcd_SQcc(bool fromQCC, uint16_t compno, uint8_t *headerData, uint16_t *header_size)
Reads a SQcd or SQcc element, i.e.
Definition CodeStreamDecompress_Markers.cpp:977
grk::CodeStreamDecompress::decompressExec
bool decompressExec()
Definition CodeStreamDecompress.cpp:786
grk::CodeStreamDecompress::read_coc
bool read_coc(uint8_t *headerData, uint16_t header_size)
Reads a COC marker (Coding Style Component)
Definition CodeStreamDecompress_Markers.cpp:1793
grk::CodeStreamDecompress::~CodeStreamDecompress
virtual ~CodeStreamDecompress()
Definition CodeStreamDecompress.cpp:101
grk::CodeStreamDecompress::read_tlm
bool read_tlm(uint8_t *headerData, uint16_t header_size)
Reads a TLM marker (Tile Length Marker)
Definition CodeStreamDecompress_Markers.cpp:965
grk::CodeStreamDecompress::decompressValidation
bool decompressValidation(void)
Definition CodeStreamDecompress.cpp:951
grk::CodeStreamDecompress::endOfCodeStream
bool endOfCodeStream(void)
Definition CodeStreamDecompress.cpp:449
grk::CodeStreamDecompress::readCurrentMarkerBody
bool readCurrentMarkerBody(uint16_t *markerSize)
Definition CodeStreamDecompress_Markers.cpp:80
grk::CodeStreamDecompress::nextTLM
void nextTLM(void)
Definition CodeStreamDecompress_Markers.cpp:375
grk::CodeStreamDecompress::read_sot
bool read_sot(uint8_t *headerData, uint16_t header_size)
Read SOT (Start of tile part) marker.
Definition CodeStreamDecompress_Markers.cpp:737
grk::CodeStreamDecompress::read_poc
bool read_poc(uint8_t *headerData, uint16_t header_size)
Reads a POC marker (Progression Order Change)
Definition CodeStreamDecompress_Markers.cpp:415
grk::CodeStreamDecompress::headerError_
bool headerError_
Definition CodeStreamDecompress.h:324
grk::CodeStreamDecompress::marker_scratch_size_
uint16_t marker_scratch_size_
Definition CodeStreamDecompress.h:327
grk::CodeStreamDecompress::readHeader
bool readHeader(grk_header_info *header_info)
Definition CodeStreamDecompress.cpp:166
grk::CodeStreamDecompress::ioBufferCallback
grk_io_pixels_callback ioBufferCallback
Definition CodeStreamDecompress.h:331
grk::CodeStreamDecompress::getHeaderImage
GrkImage * getHeaderImage(void)
Definition CodeStreamDecompress.cpp:660
grk::CodeStreamDecompress::readSOTorEOC
bool readSOTorEOC(void)
Definition CodeStreamDecompress_Markers.cpp:66
grk::CodeStreamDecompress::read_mct
bool read_mct(uint8_t *headerData, uint16_t header_size)
Reads a MCT marker (Multiple Component Transform)
Definition CodeStreamDecompress_Markers.cpp:1513
grk::CodeStreamDecompress::read_unk
bool read_unk(void)
Definition CodeStreamDecompress_Markers.cpp:1639
grk::CodeStreamDecompress::checkForIllegalTilePart
bool checkForIllegalTilePart(void)
Definition CodeStreamDecompress.cpp:915
grk::CodeStream
Definition CodeStream.h:133
grk::GrkImage
Definition GrkImage.h:25
grk::StripCache
Definition StripCache.h:110
grk::TileCache
Definition TileCache.h:38
grk_io_register_reclaim_callback
void(* grk_io_register_reclaim_callback)(grk_io_init io_init, grk_io_callback reclaim_callback, void *io_user_data, void *reclaim_user_data)
Definition grok.h:452
grk_io_pixels_callback
bool(* grk_io_pixels_callback)(uint32_t threadId, grk_io_buf buffer, void *user_data)
Definition grok.h:455
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::MARKER_FUNC
std::function< bool(uint8_t *headerData, uint16_t header_size)> MARKER_FUNC
Definition CodeStreamDecompress.h:26
_grk_decompress_core_params
Core decompression parameters.
Definition grok.h:480
_grk_header_info
Header info.
Definition grok.h:361
_grk_image_comp
Image component.
Definition grok.h:572
_grk_plugin_tile
Plugin tile.
Definition grok.h:739
grk::BufferedStream
Definition BufferedStream.h:35
grk::CodeStreamInfo
Definition LengthCache.h:70
grk::CodingParams
Coding parameters.
Definition CodingParams.h:245
grk::DecompressorState
Definition CodingParams.h:310
grk::ICodeStreamDecompress
Definition CodeStream.h:115
grk::TileCodingParams
Tile coding parameters : this structure is used to store coding/decoding parameters common to all til...
Definition CodingParams.h:122
grk::TileProcessor
Definition TileProcessor.h:78
grk::grk_rect
Definition geometry.h:102
grk::marker_handler
Definition CodeStreamDecompress.h:28
grk::marker_handler::states
uint32_t states
value of the state when the marker can appear
Definition CodeStreamDecompress.h:33
grk::marker_handler::id
uint16_t id
marker value
Definition CodeStreamDecompress.h:31
grk::marker_handler::marker_handler
marker_handler(uint16_t ID, uint32_t flags, MARKER_FUNC f)
Definition CodeStreamDecompress.h:29
grk::marker_handler::func
MARKER_FUNC func
Definition CodeStreamDecompress.h:34