Grok 20.3.2
FileFormatMJ2Decompress.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 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
18#pragma once
19
20#include <set>
21#include <vector>
22
23namespace grk
24{
25
27
29{
30public:
31 explicit FileFormatMJ2Decompress(IStream* stream);
32 ~FileFormatMJ2Decompress() override;
33 bool readHeader(grk_header_info* header_info) override;
34 GrkImage* getImage(uint16_t tile_index, bool wait) override;
35 GrkImage* getImage(void) override;
36 void init(grk_decompress_parameters* param) override;
37 grk_progression_state getProgressionState(uint16_t tile_index) override;
38 bool setProgressionState(grk_progression_state state) override;
39 bool decompress(grk_plugin_tile* tile) override;
40 bool decompressTile(uint16_t tile_index) override;
41 void dump(uint32_t flag, FILE* outputFileStream) override;
42 void wait(grk_wait_swath* swath) override;
43
44 void setBandCallback(grk_io_band_callback callback, void* user_data) override;
45
46 uint32_t getNumSamples(void) override;
47 bool decompressSample(uint32_t sampleIndex) override;
48 GrkImage* getSampleImage(uint32_t sampleIndex) override;
49 GrkImage* getSampleTileImage(uint32_t sampleIndex, uint16_t tileIndex) override;
50
51private:
52 bool decompressSampleInternal(uint32_t sampleIndex);
53 GrkImage* getHeaderImage(void) override;
54 void read_version_and_flag(uint8_t** headerData, uint8_t& version, uint32_t& flag);
55 bool read_version_and_flag_check(uint8_t** headerData, uint32_t* headerSize, uint8_t maxVersion,
56 std::set<uint32_t> allowedFlags);
57 bool read_mvhd(uint8_t* headerData, uint32_t headerSize);
58 bool read_tkhd(uint8_t* headerData, uint32_t headerSize);
59 bool read_mdhd(uint8_t* headerData, uint32_t headerSize);
60 bool read_mdat(uint8_t* headerData, uint32_t headerSize);
61 bool read_hdlr(uint8_t* headerData, uint32_t headerSize);
62 bool read_vmhd(uint8_t* headerData, uint32_t headerSize);
63 bool read_dref(uint8_t* headerData, uint32_t headerSize);
64 bool read_stsd(uint8_t* headerData, uint32_t headerSize);
65 bool read_stts(uint8_t* headerData, uint32_t headerSize);
66 bool read_stsc(uint8_t* headerData, uint32_t headerSize);
67 bool read_stsz(uint8_t* headerData, uint32_t headerSize);
68 bool read_stco(uint8_t* headerData, uint32_t headerSize);
69 bool read_smj2(uint8_t* headerData, uint32_t headerSize);
70
71 bool read_fiel(uint8_t* headerData, uint32_t headerSize);
72 bool read_jp2p(uint8_t* headerData, uint32_t headerSize);
73 bool read_jp2x(uint8_t* headerData, uint32_t headerSize);
74 bool read_jsub(uint8_t* headerData, uint32_t headerSize);
75 bool read_orfo(uint8_t* headerData, uint32_t headerSize);
76
77 bool read_url(uint8_t* headerData, uint32_t headerSize);
78 bool read_urn(uint8_t* headerData, uint32_t headerSize);
79
80 void tts_decompact(mj2_tk* tk);
81 void stsc_decompact(mj2_tk* tk);
82 void stco_decompact(mj2_tk* tk);
83
86 std::vector<GrkImage*> decompressedImages_;
87
89 {
91 IStream* stream = nullptr;
92 };
93 std::vector<SampleCodeStream> sampleCodeStreams_;
94};
95} // namespace grk
Manages decompression.
Definition CodeStreamDecompress.h:36
bool read_fiel(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:154
bool decompressSampleInternal(uint32_t sampleIndex)
Definition FileFormatMJ2Decompress.cpp:742
void init(grk_decompress_parameters *param) override
Initializes decompressor.
Definition FileFormatMJ2Decompress.cpp:671
void read_version_and_flag(uint8_t **headerData, uint8_t &version, uint32_t &flag)
Definition FileFormatMJ2Decompress.cpp:117
void wait(grk_wait_swath *swath) override
Waits for asynchronous decompression to complete.
Definition FileFormatMJ2Decompress.cpp:694
bool decompressTile(uint16_t tile_index) override
Decompresses a single tile.
Definition FileFormatMJ2Decompress.cpp:680
void stsc_decompact(mj2_tk *tk)
Definition FileFormatMJ2Decompress.cpp:547
GrkImage * getSampleImage(uint32_t sampleIndex) override
Definition FileFormatMJ2Decompress.cpp:888
bool read_vmhd(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:320
bool read_hdlr(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:299
void tts_decompact(mj2_tk *tk)
Definition FileFormatMJ2Decompress.cpp:508
bool read_stts(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:522
void dump(uint32_t flag, FILE *outputFileStream) override
Dumps image tags to file.
Definition FileFormatMJ2Decompress.cpp:692
bool read_tkhd(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:239
void stco_decompact(mj2_tk *tk)
Definition FileFormatMJ2Decompress.cpp:622
bool read_stsd(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:470
bool read_jsub(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:191
bool read_mvhd(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:210
bool decompress(grk_plugin_tile *tile) override
Decompresses image / image region.
Definition FileFormatMJ2Decompress.cpp:849
bool read_stsz(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:588
GrkImage * getSampleTileImage(uint32_t sampleIndex, uint16_t tileIndex) override
Definition FileFormatMJ2Decompress.cpp:897
bool read_jp2p(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:162
std::vector< SampleCodeStream > sampleCodeStreams_
Definition FileFormatMJ2Decompress.h:93
bool readHeader(grk_header_info *header_info) override
Reads header.
Definition FileFormatMJ2Decompress.cpp:703
~FileFormatMJ2Decompress() override
Definition FileFormatMJ2Decompress.cpp:101
void setBandCallback(grk_io_band_callback callback, void *user_data) override
Sets a band-completion callback for incremental writing.
Definition FileFormatMJ2Decompress.cpp:695
uint32_t getNumSamples(void) override
Definition FileFormatMJ2Decompress.cpp:880
bool read_stco(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:636
bool decompressParamsSet_
Definition FileFormatMJ2Decompress.h:85
bool read_stsc(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:562
bool read_url(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:335
bool read_dref(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:382
GrkImage * getImage(void) override
Gets composite GrkImage for all tiles in decompress region.
Definition FileFormatMJ2Decompress.cpp:665
FileFormatMJ2Decompress(IStream *stream)
Definition FileFormatMJ2Decompress.cpp:64
bool read_orfo(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:201
std::vector< GrkImage * > decompressedImages_
Definition FileFormatMJ2Decompress.h:86
bool read_mdat(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:293
bool read_mdhd(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:280
grk_progression_state getProgressionState(uint16_t tile_index) override
Gets the grk_progression_state for a tile.
Definition FileFormatMJ2Decompress.cpp:737
bool read_urn(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:357
bool read_smj2(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:427
bool read_version_and_flag_check(uint8_t **headerData, uint32_t *headerSize, uint8_t maxVersion, std::set< uint32_t > allowedFlags)
Definition FileFormatMJ2Decompress.cpp:127
GrkImage * getHeaderImage(void) override
Definition FileFormatMJ2Decompress.cpp:112
bool setProgressionState(grk_progression_state state) override
Sets the grk_progression_state for a tile.
Definition FileFormatMJ2Decompress.cpp:731
bool decompressSample(uint32_t sampleIndex) override
Definition FileFormatMJ2Decompress.cpp:884
grk_decompress_parameters decompressParams_
Definition FileFormatMJ2Decompress.h:84
bool read_jp2x(uint8_t *headerData, uint32_t headerSize)
Definition FileFormatMJ2Decompress.cpp:178
FileFormatMJ2(IStream *stream)
Definition FileFormatMJ2.cpp:65
Stores header and data for an image.
Definition GrkImage.h:54
bool(* grk_io_band_callback)(uint32_t yBegin, uint32_t yEnd, grk_image *image, void *user_data)
Callback invoked when a horizontal band of the decompressed image is ready for writing.
Definition grok.h:647
ResWindow.
Definition CompressedChunkCache.h:36
Definition FileFormatMJ2Decompress.h:89
IStream * stream
Definition FileFormatMJ2Decompress.h:91
CodeStreamDecompress * codeStream
Definition FileFormatMJ2Decompress.h:90
Decompress interface.
Definition IDecompressor.h:29
Definition IStream.h:60
Video Track Parameters.
Definition FileFormatMJ2.h:148
Decompression parameters.
JPEG 2000 header info.
Plugin tile.
Stores progression state information Note: limited to 256 components.
Specify swath region to wait on during asynchronous decompression.
Definition grok.h:1004