Grok 10.0.5
CodeStreamDecompress.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2023 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 *
17 * This source code incorporates work covered by the BSD 2-clause license.
18 * Please see the LICENSE file in the root directory for details.
19 *
20 */
21
22#pragma once
23
24namespace grk
25{
26typedef std::function<bool(uint8_t* headerData, uint16_t header_size)> MARKER_FUNC;
27struct marker_handler
28{
29 marker_handler(uint16_t ID, uint32_t flags, MARKER_FUNC f) : id(ID), states(flags), func(f) {}
31 uint16_t id;
33 uint32_t states;
34 MARKER_FUNC func;
35};
36
37class CodeStreamDecompress : public CodeStream, public ICodeStreamDecompress
38{
39 public:
40 CodeStreamDecompress(BufferedStream* stream);
41 virtual ~CodeStreamDecompress();
42 TileProcessor* allocateProcessor(uint16_t tileIndex);
43 DecompressorState* getDecompressorState(void);
44 TileCodingParams* get_current_decode_tcp(void);
45 bool isDecodingTilePartHeader();
46 bool readHeader(grk_header_info* header_info);
47 GrkImage* getImage(uint16_t tileIndex);
48 GrkImage* getImage(void);
49 std::vector<GrkImage*> getAllImages(void);
50 void init(grk_decompress_core_params* p_param);
51 bool setDecompressRegion(grk_rect_single region);
52 bool decompress(grk_plugin_tile* tile);
53 bool decompressTile(uint16_t tileIndex);
54 bool preProcess(void);
55 bool postProcess(void);
56 CodeStreamInfo* getCodeStreamInfo(void);
57 GrkImage* getCompositeImage();
58 bool readMarker(void);
59 bool readMarker(bool suppressWarning);
60 GrkImage* getHeaderImage(void);
61 uint16_t getCurrentMarker(void);
62 void dump(uint32_t flag, FILE* outputFileStream);
63 bool needsHeaderRead(void);
64 void setExpectSOD();
65
66 protected:
67 void dump_MH_info(FILE* outputFileStream);
76 void dump_image_header(GrkImage* image, bool dev_dump_flag, FILE* outputFileStream);
77 void dump_tile_info(TileCodingParams* default_tile, uint32_t numcomps, FILE* outputFileStream);
86 void dump_image_comp_header(grk_image_comp* comp, bool dev_dump_flag, FILE* outputFileStream);
87
88 private:
89 bool readCurrentMarkerBody(uint16_t* markerSize);
90 bool endOfCodeStream(void);
91 bool read_short(uint16_t* val);
92 bool process_marker(const marker_handler* marker_handler, uint16_t marker_size);
93 bool readSOTorEOC(void);
94 bool parseTileParts(bool* can_decode_tile_data);
95 bool readHeaderProcedureImpl(void);
96 bool decompressExec();
97 bool decompressTile();
98 bool findNextSOT(TileProcessor* tileProcessor);
99 bool skipNonScheduledTLM(CodingParams* cp);
100 bool hasTLM(void);
101 void nextTLM(void);
102 bool decompressTiles(void);
103 bool decompressValidation(void);
104 bool copy_default_tcp(void);
105 bool read_unk(void);
112 void addMarker(uint16_t id, uint64_t pos, uint32_t len);
120 bool read_mct(uint8_t* headerData, uint16_t header_size);
128 bool read_mcc(uint8_t* headerData, uint16_t header_size);
136 bool read_mco(uint8_t* headerData, uint16_t header_size);
137 bool add_mct(TileCodingParams* p_tcp, GrkImage* p_image, uint32_t index);
145 bool read_cbd(uint8_t* headerData, uint16_t header_size);
152 bool read_rgn(uint8_t* headerData, uint16_t header_size);
153
154 bool readHeaderProcedure(void);
158 bool read_soc();
165 bool read_siz(uint8_t* headerData, uint16_t header_size);
172 bool read_cap(uint8_t* headerData, uint16_t header_size);
180 bool read_com(uint8_t* headerData, uint16_t header_size);
188 bool read_cod(uint8_t* headerData, uint16_t header_size);
195 bool read_poc(uint8_t* headerData, uint16_t header_size);
203 bool read_crg(uint8_t* headerData, uint16_t header_size);
210 bool read_tlm(uint8_t* headerData, uint16_t header_size);
218 bool read_plm(uint8_t* headerData, uint16_t header_size);
226 bool read_plt(uint8_t* headerData, uint16_t header_size);
234 bool read_ppm(uint8_t* headerData, uint16_t header_size);
242 bool read_ppt(uint8_t* headerData, uint16_t header_size);
250 bool read_sot(uint8_t* headerData, uint16_t header_size);
258 bool read_SPCod_SPCoc(uint16_t compno, uint8_t* headerData, uint16_t* header_size);
270 bool read_SQcd_SQcc(bool fromQCC, uint16_t compno, uint8_t* headerData, uint16_t* header_size);
277 bool merge_ppm(CodingParams* p_cp);
284 bool merge_ppt(TileCodingParams* p_tcp);
292 bool read_coc(uint8_t* headerData, uint16_t header_size);
299 bool read_qcd(uint8_t* headerData, uint16_t header_size);
307 bool read_qcc(uint8_t* headerData, uint16_t header_size);
315 const marker_handler* get_marker_handler(uint16_t id);
316
317 bool createOutputImage(void);
318 bool checkForIllegalTilePart(void);
319
320 std::map<uint16_t, marker_handler*> marker_map;
321 DecompressorState decompressorState_;
323 uint16_t curr_marker_;
328 GrkImage* outputImage_;
329 TileCache* tileCache_;
330 StripCache stripCache_;
334};
335
336} // namespace grk
BufferedStream * stream
Definition BitIO.h:88
GrkImage * outputImage_
Definition CodeStreamDecompress.h:328
MARKER_FUNC func
Definition CodeStreamDecompress.h:34
uint16_t curr_marker_
Definition CodeStreamDecompress.h:323
bool expectSOD_
Definition CodeStreamDecompress.h:322
uint16_t id
marker value
Definition CodeStreamDecompress.h:31
StripCache stripCache_
Definition CodeStreamDecompress.h:330
TileCache * tileCache_
Definition CodeStreamDecompress.h:329
bool headerRead_
Definition CodeStreamDecompress.h:325
DecompressorState decompressorState_
Definition CodeStreamDecompress.h:321
std::map< uint16_t, marker_handler * > marker_map
Definition CodeStreamDecompress.h:320
uint8_t * marker_scratch_
Definition CodeStreamDecompress.h:326
bool headerError_
Definition CodeStreamDecompress.h:324
uint32_t states
value of the state when the marker can appear
Definition CodeStreamDecompress.h:33
void * ioUserData
Definition CodeStreamDecompress.h:332
uint16_t marker_scratch_size_
Definition CodeStreamDecompress.h:327
grk_io_register_reclaim_callback grkRegisterReclaimCallback_
Definition CodeStreamDecompress.h:333
grk_io_pixels_callback ioBufferCallback
Definition CodeStreamDecompress.h:331
uint32_t len
Definition Codeblock.h:38
bool fromQCC
Definition CodingParams.h:71
uint16_t numcomps
Definition FileFormat.h:149
TileProcessor * tileProcessor
Definition PacketManager.h:100
CodingParams * cp
Definition PacketManager.h:95
grk_flag * flags
Flags used by decompressor and compressor.
Definition T1.h:72
T val[N]
Definition WaveletCommon.h:65
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
bool(* grk_io_pixels_callback)(uint32_t threadId, grk_io_buf buffer, void *user_data)
Definition grok.h:455
grk_rect< float > grk_rect_single
Definition TileCache.h:63
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
std::function< bool(uint8_t *headerData, uint16_t header_size)> MARKER_FUNC
Definition CodeStreamDecompress.h:26
grk_plugin_tile * tile
Definition plugin_interface.h:64
grk_image * image
Definition plugin_interface.h:63
uint16_t compno
Definition plugin_interface.h:43
grk_header_info header_info
Definition plugin_interface.h:111
Core decompression parameters.
Definition grok.h:480
Header info.
Definition grok.h:361
Image component.
Definition grok.h:572
Plugin tile.
Definition grok.h:739