CodeStream.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 "CodingParams.h"
namespace grk
{
const uint32_t default_numbers_segments = 10;
const uint32_t default_header_size = 4096;
const uint32_t default_number_mcc_records = 10;
const uint32_t default_number_mct_records = 10;
// includes marker and marker length (4 bytes)
const uint32_t sot_marker_segment_len_minus_tile_data_len = 12U;
const uint32_t sot_marker_segment_min_len = 14U;
const uint32_t SPCod_SPCoc_len = 5U;
const uint32_t cod_coc_len = 5U;
const uint32_t tlmMarkerBytesPerTilePart = 6;
const uint32_t GRK_COMP_PARAM_DEFAULT_CBLOCKW = 64;
const uint32_t GRK_COMP_PARAM_DEFAULT_CBLOCKH = 64;
const GRK_PROG_ORDER GRK_COMP_PARAM_DEFAULT_PROG_ORDER = GRK_LRCP;
const uint32_t GRK_COMP_PARAM_DEFAULT_NUMRESOLUTION = 6;
#define J2K_CP_CSTY_PRT 0x01
#define J2K_CP_CSTY_SOP 0x02
#define J2K_CP_CSTY_EPH 0x04
#define J2K_CCP_CSTY_PRT 0x01
#define J2K_CCP_QNTSTY_NOQNT 0 // no quantization
#define J2K_CCP_QNTSTY_SIQNT 1 // derived quantization
#define J2K_CCP_QNTSTY_SEQNT 2 // expounded quantization
const uint16_t J2K_MS_SOC = 0xff4f;
const uint16_t J2K_MS_SOT = 0xff90;
const uint16_t J2K_MS_SOD = 0xff93;
const uint16_t J2K_MS_EOC = 0xffd9;
const uint16_t J2K_MS_CAP = 0xff50;
const uint16_t J2K_MS_SIZ = 0xff51;
const uint16_t J2K_MS_COD = 0xff52;
const uint16_t J2K_MS_COC = 0xff53;
const uint16_t J2K_MS_RGN = 0xff5e;
const uint16_t J2K_MS_QCD = 0xff5c;
const uint16_t J2K_MS_QCC = 0xff5d;
const uint16_t J2K_MS_POC = 0xff5f;
const uint16_t J2K_MS_TLM = 0xff55;
const uint16_t J2K_MS_PLM = 0xff57;
const uint16_t J2K_MS_PLT = 0xff58;
const uint16_t J2K_MS_PPM = 0xff60;
const uint16_t J2K_MS_PPT = 0xff61;
const uint16_t J2K_MS_SOP = 0xff91;
const uint16_t J2K_MS_EPH = 0xff92;
const uint16_t J2K_MS_CRG = 0xff63;
const uint16_t J2K_MS_COM = 0xff64;
const uint16_t J2K_MS_CBD = 0xff78;
const uint16_t J2K_MS_MCC = 0xff75;
const uint16_t J2K_MS_MCT = 0xff74;
const uint16_t J2K_MS_MCO = 0xff77;
const uint16_t J2K_MS_UNK = 0;
// number of bytes needed to store marker
const uint8_t MARKER_BYTES = 2;
// number of bytes neede to store length of marker (excluding marker itself)
const uint8_t MARKER_LENGTH_BYTES = 2;
const uint8_t MARKER_PLUS_MARKER_LENGTH_BYTES = MARKER_BYTES + MARKER_LENGTH_BYTES;
class GrkImage;
template<typename S, typename D>
void j2k_write(const void* p_src_data, void* p_dest_data, uint64_t nb_elem)
{
uint8_t* dest_data = (uint8_t*)p_dest_data;
S* src_data = (S*)p_src_data;
for(uint32_t i = 0; i < nb_elem; ++i)
{
D temp = (D) * (src_data++);
grk_write<D>(dest_data, temp, sizeof(D));
dest_data += sizeof(D);
}
}
const uint32_t MCT_ELEMENT_SIZE[] = {2, 4, 4, 8};
typedef void (*j2k_mct_function)(const void* p_src_data, void* p_dest_data, uint64_t nb_elem);
typedef std::function<bool(void)> PROCEDURE_FUNC;
struct ICodeStreamCompress
{
virtual ~ICodeStreamCompress() = default;
virtual bool init(grk_cparameters* p_param, GrkImage* p_image) = 0;
virtual bool start(void) = 0;
virtual bool compress(grk_plugin_tile* tile) = 0;
};
struct ICodeStreamDecompress
{
public:
virtual ~ICodeStreamDecompress() = default;
virtual bool readHeader(grk_header_info* header_info) = 0;
virtual GrkImage* getImage(uint16_t tileIndex) = 0;
virtual GrkImage* getImage(void) = 0;
virtual void init(grk_decompress_core_params* p_param) = 0;
virtual bool setDecompressRegion(grk_rect_single region) = 0;
virtual bool decompress(grk_plugin_tile* tile) = 0;
virtual bool decompressTile(uint16_t tileIndex) = 0;
virtual bool preProcess(void) = 0;
virtual bool postProcess(void) = 0;
virtual void dump(uint32_t flag, FILE* outputFileStream) = 0;
};
class TileCache;
class CodeStream
{
public:
CodeStream(BufferedStream* stream);
virtual ~CodeStream();
TileProcessor* currentProcessor(void);
BufferedStream* getStream();
GrkImage* getHeaderImage(void);
grk_plugin_tile* getCurrentPluginTile();
CodingParams* getCodingParams(void);
static std::string markerString(uint16_t marker);
protected:
bool exec(std::vector<PROCEDURE_FUNC>& p_procedure_list);
CodingParams cp_;
CodeStreamInfo* codeStreamInfo;
std::vector<PROCEDURE_FUNC> procedure_list_;
std::vector<PROCEDURE_FUNC> validation_list_;
// stores header image information (decompress/compress)
// decompress: components are subsampled and resolution-reduced
GrkImage* headerImage_;
TileProcessor* currentTileProcessor_;
BufferedStream* stream_;
std::map<uint32_t, TileProcessor*> processors_;
grk_plugin_tile* current_plugin_tile;
};
/* ----------------------------------------------------------------------- */
/* ----------------------------------------------------------------------- */
} // namespace grk
CodingParams.h
grk::CodeStream
Definition CodeStream.h:133
grk::CodeStream::getCodingParams
CodingParams * getCodingParams(void)
Definition CodeStream.cpp:35
grk::CodeStream::codeStreamInfo
CodeStreamInfo * codeStreamInfo
Definition CodeStream.h:148
grk::CodeStream::current_plugin_tile
grk_plugin_tile * current_plugin_tile
Definition CodeStream.h:157
grk::CodeStream::getStream
BufferedStream * getStream()
Definition CodeStream.cpp:59
grk::CodeStream::headerImage_
GrkImage * headerImage_
Definition CodeStream.h:153
grk::CodeStream::validation_list_
std::vector< PROCEDURE_FUNC > validation_list_
Definition CodeStream.h:150
grk::CodeStream::cp_
CodingParams cp_
Definition CodeStream.h:147
grk::CodeStream::exec
bool exec(std::vector< PROCEDURE_FUNC > &p_procedure_list)
Definition CodeStream.cpp:47
grk::CodeStream::currentTileProcessor_
TileProcessor * currentTileProcessor_
Definition CodeStream.h:154
grk::CodeStream::~CodeStream
virtual ~CodeStream()
Definition CodeStream.cpp:29
grk::CodeStream::getCurrentPluginTile
grk_plugin_tile * getCurrentPluginTile()
Definition CodeStream.cpp:55
grk::CodeStream::markerString
static std::string markerString(uint16_t marker)
Definition CodeStream.cpp:64
grk::CodeStream::currentProcessor
TileProcessor * currentProcessor(void)
Definition CodeStream.cpp:43
grk::CodeStream::procedure_list_
std::vector< PROCEDURE_FUNC > procedure_list_
Definition CodeStream.h:149
grk::CodeStream::processors_
std::map< uint32_t, TileProcessor * > processors_
Definition CodeStream.h:156
grk::CodeStream::getHeaderImage
GrkImage * getHeaderImage(void)
Definition CodeStream.cpp:39
grk::CodeStream::stream_
BufferedStream * stream_
Definition CodeStream.h:155
grk::GrkImage
Definition GrkImage.h:25
grk::TileCache
Definition TileCache.h:38
GRK_PROG_ORDER
enum _GRK_PROG_ORDER GRK_PROG_ORDER
Progression order.
GRK_LRCP
@ GRK_LRCP
layer-resolution-component-precinct order
Definition grok.h:59
grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
grk::j2k_mct_function
void(* j2k_mct_function)(const void *p_src_data, void *p_dest_data, uint64_t nb_elem)
Definition CodeStream.h:103
grk::J2K_MS_MCC
const uint16_t J2K_MS_MCC
MCC marker value.
Definition CodeStream.h:76
grk::J2K_MS_PPM
const uint16_t J2K_MS_PPM
PPM marker value.
Definition CodeStream.h:69
grk::MCT_ELEMENT_SIZE
const uint32_t MCT_ELEMENT_SIZE[]
Definition CodeStream.h:102
grk::J2K_MS_MCO
const uint16_t J2K_MS_MCO
MCO marker value.
Definition CodeStream.h:78
grk::MARKER_LENGTH_BYTES
const uint8_t MARKER_LENGTH_BYTES
Definition CodeStream.h:84
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk::PROCEDURE_FUNC
std::function< bool(void)> PROCEDURE_FUNC
Definition CodeStream.h:104
grk::J2K_MS_SIZ
const uint16_t J2K_MS_SIZ
SIZ marker value.
Definition CodeStream.h:59
grk::J2K_MS_SOC
const uint16_t J2K_MS_SOC
SOC marker value.
Definition CodeStream.h:54
grk::default_number_mcc_records
const uint32_t default_number_mcc_records
Definition CodeStream.h:30
grk::MARKER_PLUS_MARKER_LENGTH_BYTES
const uint8_t MARKER_PLUS_MARKER_LENGTH_BYTES
Definition CodeStream.h:85
grk::default_header_size
const uint32_t default_header_size
Definition CodeStream.h:29
grk::J2K_MS_MCT
const uint16_t J2K_MS_MCT
MCT marker value.
Definition CodeStream.h:77
grk::SPCod_SPCoc_len
const uint32_t SPCod_SPCoc_len
Definition CodeStream.h:37
grk::J2K_MS_QCC
const uint16_t J2K_MS_QCC
QCC marker value.
Definition CodeStream.h:64
grk::J2K_MS_POC
const uint16_t J2K_MS_POC
POC marker value.
Definition CodeStream.h:65
grk::J2K_MS_COM
const uint16_t J2K_MS_COM
COM marker value.
Definition CodeStream.h:74
grk::J2K_MS_EOC
const uint16_t J2K_MS_EOC
EOC marker value.
Definition CodeStream.h:57
grk::GRK_COMP_PARAM_DEFAULT_PROG_ORDER
const GRK_PROG_ORDER GRK_COMP_PARAM_DEFAULT_PROG_ORDER
Definition CodeStream.h:43
grk::J2K_MS_COC
const uint16_t J2K_MS_COC
COC marker value.
Definition CodeStream.h:61
grk::default_number_mct_records
const uint32_t default_number_mct_records
Definition CodeStream.h:31
grk::J2K_MS_CRG
const uint16_t J2K_MS_CRG
CRG marker value.
Definition CodeStream.h:73
grk::j2k_write
void j2k_write(const void *p_src_data, void *p_dest_data, uint64_t nb_elem)
Definition CodeStream.h:90
grk::GRK_COMP_PARAM_DEFAULT_CBLOCKW
const uint32_t GRK_COMP_PARAM_DEFAULT_CBLOCKW
Definition CodeStream.h:41
grk::J2K_MS_PLT
const uint16_t J2K_MS_PLT
PLT marker value.
Definition CodeStream.h:68
grk::J2K_MS_CBD
const uint16_t J2K_MS_CBD
CBD marker value.
Definition CodeStream.h:75
grk::J2K_MS_QCD
const uint16_t J2K_MS_QCD
QCD marker value.
Definition CodeStream.h:63
grk::J2K_MS_RGN
const uint16_t J2K_MS_RGN
RGN marker value.
Definition CodeStream.h:62
grk::sot_marker_segment_len_minus_tile_data_len
const uint32_t sot_marker_segment_len_minus_tile_data_len
Definition CodeStream.h:34
grk::default_numbers_segments
const uint32_t default_numbers_segments
Definition CodeStream.h:28
grk::J2K_MS_UNK
const uint16_t J2K_MS_UNK
UNKNOWN marker value.
Definition CodeStream.h:79
grk::GRK_COMP_PARAM_DEFAULT_NUMRESOLUTION
const uint32_t GRK_COMP_PARAM_DEFAULT_NUMRESOLUTION
Definition CodeStream.h:44
grk::cod_coc_len
const uint32_t cod_coc_len
Definition CodeStream.h:38
grk::J2K_MS_CAP
const uint16_t J2K_MS_CAP
CAP marker value.
Definition CodeStream.h:58
grk::J2K_MS_COD
const uint16_t J2K_MS_COD
COD marker value.
Definition CodeStream.h:60
grk::J2K_MS_SOP
const uint16_t J2K_MS_SOP
SOP marker value.
Definition CodeStream.h:71
grk::GRK_COMP_PARAM_DEFAULT_CBLOCKH
const uint32_t GRK_COMP_PARAM_DEFAULT_CBLOCKH
Definition CodeStream.h:42
grk::MARKER_BYTES
const uint8_t MARKER_BYTES
Definition CodeStream.h:82
grk::J2K_MS_EPH
const uint16_t J2K_MS_EPH
EPH marker value.
Definition CodeStream.h:72
grk::J2K_MS_TLM
const uint16_t J2K_MS_TLM
TLM marker value.
Definition CodeStream.h:66
grk::tlmMarkerBytesPerTilePart
const uint32_t tlmMarkerBytesPerTilePart
Definition CodeStream.h:39
grk::sot_marker_segment_min_len
const uint32_t sot_marker_segment_min_len
Definition CodeStream.h:35
grk::J2K_MS_SOD
const uint16_t J2K_MS_SOD
SOD marker value.
Definition CodeStream.h:56
grk::J2K_MS_PLM
const uint16_t J2K_MS_PLM
PLM marker value.
Definition CodeStream.h:67
grk::J2K_MS_SOT
const uint16_t J2K_MS_SOT
SOT marker value.
Definition CodeStream.h:55
grk::J2K_MS_PPT
const uint16_t J2K_MS_PPT
PPT marker value.
Definition CodeStream.h:70
_grk_cparameters
Compress parameters.
Definition grok.h:912
_grk_decompress_core_params
Core decompression parameters.
Definition grok.h:480
_grk_header_info
Header info.
Definition grok.h:361
_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::ICodeStreamCompress
Definition CodeStream.h:107
grk::ICodeStreamCompress::start
virtual bool start(void)=0
grk::ICodeStreamCompress::init
virtual bool init(grk_cparameters *p_param, GrkImage *p_image)=0
grk::ICodeStreamCompress::compress
virtual bool compress(grk_plugin_tile *tile)=0
grk::ICodeStreamCompress::~ICodeStreamCompress
virtual ~ICodeStreamCompress()=default
grk::ICodeStreamDecompress
Definition CodeStream.h:115
grk::ICodeStreamDecompress::postProcess
virtual bool postProcess(void)=0
grk::ICodeStreamDecompress::getImage
virtual GrkImage * getImage(uint16_t tileIndex)=0
grk::ICodeStreamDecompress::preProcess
virtual bool preProcess(void)=0
grk::ICodeStreamDecompress::readHeader
virtual bool readHeader(grk_header_info *header_info)=0
grk::ICodeStreamDecompress::decompressTile
virtual bool decompressTile(uint16_t tileIndex)=0
grk::ICodeStreamDecompress::~ICodeStreamDecompress
virtual ~ICodeStreamDecompress()=default
grk::ICodeStreamDecompress::decompress
virtual bool decompress(grk_plugin_tile *tile)=0
grk::ICodeStreamDecompress::getImage
virtual GrkImage * getImage(void)=0
grk::ICodeStreamDecompress::setDecompressRegion
virtual bool setDecompressRegion(grk_rect_single region)=0
grk::ICodeStreamDecompress::init
virtual void init(grk_decompress_core_params *p_param)=0
grk::ICodeStreamDecompress::dump
virtual void dump(uint32_t flag, FILE *outputFileStream)=0
grk::TileProcessor
Definition TileProcessor.h:78
grk::grk_rect
Definition geometry.h:102