FileFormatDecompress.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, uint32_t header_size)> BOX_FUNC;
class FileFormatDecompress : public FileFormat, public ICodeStreamDecompress
{
public:
FileFormatDecompress(BufferedStream* stream);
virtual ~FileFormatDecompress();
bool readHeader(grk_header_info* header_info);
GrkImage* getImage(uint16_t tileIndex);
GrkImage* getImage(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 end(void);
bool postProcess(void);
bool preProcess(void);
void dump(uint32_t flag, FILE* outputFileStream);
private:
grk_color* getColour(void);
uint32_t read_asoc(AsocBox* parent, uint8_t** header_data, uint32_t* header_data_size,
uint32_t asocSize);
bool readHeaderProcedureImpl(void);
bool read_box_hdr(FileFormatBox* box, uint32_t* p_number_bytes_read, BufferedStream* stream);
bool read_ihdr(uint8_t* p_image_header_data, uint32_t image_header_size);
bool read_xml(uint8_t* p_xml_data, uint32_t xml_size);
bool read_uuid(uint8_t* headerData, uint32_t header_size);
bool read_res_box(uint32_t* id, uint32_t* num, uint32_t* den, uint32_t* exponent,
uint8_t** p_resolution_data);
bool read_res(uint8_t* p_resolution_data, uint32_t resolution_size);
double calc_res(uint16_t num, uint16_t den, uint8_t exponent);
bool read_bpc(uint8_t* p_bpc_header_data, uint32_t bpc_header_size);
bool read_channel_definition(uint8_t* p_cdef_header_data, uint32_t cdef_header_size);
bool read_colr(uint8_t* p_colr_header_data, uint32_t colr_header_size);
bool read_component_mapping(uint8_t* component_mapping_header_data,
uint32_t component_mapping_header_size);
bool read_palette_clr(uint8_t* p_pclr_header_data, uint32_t pclr_header_size);
const BOX_FUNC find_handler(uint32_t id);
const BOX_FUNC img_find_handler(uint32_t id);
bool read_jp(uint8_t* headerData, uint32_t header_size);
bool read_ftyp(uint8_t* headerData, uint32_t header_size);
bool read_jp2h(uint8_t* headerData, uint32_t header_size);
bool read_box(FileFormatBox* box, uint8_t* p_data, uint32_t* p_number_bytes_read,
uint64_t p_box_max_size);
bool read_asoc(uint8_t* header_data, uint32_t header_data_size);
void serializeAsoc(AsocBox* asoc, grk_asoc* serial_asocs, uint32_t* num_asocs, uint32_t level);
std::map<uint32_t, BOX_FUNC> header;
std::map<uint32_t, BOX_FUNC> img_header;
bool headerError_;
AsocBox root_asoc;
CodeStreamDecompress* codeStream;
uint32_t jp2_state;
};
} // namespace grk
grk::CodeStreamDecompress
Definition CodeStreamDecompress.h:38
grk::FileFormatDecompress
Definition FileFormatDecompress.h:29
grk::FileFormatDecompress::read_ihdr
bool read_ihdr(uint8_t *p_image_header_data, uint32_t image_header_size)
Definition FileFormatDecompress.cpp:589
grk::FileFormatDecompress::read_jp2h
bool read_jp2h(uint8_t *headerData, uint32_t header_size)
Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
Definition FileFormatDecompress.cpp:1249
grk::FileFormatDecompress::jp2_state
uint32_t jp2_state
Definition FileFormatDecompress.h:79
grk::FileFormatDecompress::preProcess
bool preProcess(void)
Definition FileFormatDecompress.cpp:286
grk::FileFormatDecompress::read_bpc
bool read_bpc(uint8_t *p_bpc_header_data, uint32_t bpc_header_size)
Definition FileFormatDecompress.cpp:770
grk::FileFormatDecompress::read_box_hdr
bool read_box_hdr(FileFormatBox *box, uint32_t *p_number_bytes_read, BufferedStream *stream)
Definition FileFormatDecompress.cpp:548
grk::FileFormatDecompress::read_channel_definition
bool read_channel_definition(uint8_t *p_cdef_header_data, uint32_t cdef_header_size)
Definition FileFormatDecompress.cpp:795
grk::FileFormatDecompress::read_res_box
bool read_res_box(uint32_t *id, uint32_t *num, uint32_t *den, uint32_t *exponent, uint8_t **p_resolution_data)
Definition FileFormatDecompress.cpp:707
grk::FileFormatDecompress::read_palette_clr
bool read_palette_clr(uint8_t *p_pclr_header_data, uint32_t pclr_header_size)
Definition FileFormatDecompress.cpp:1067
grk::FileFormatDecompress::root_asoc
AsocBox root_asoc
Definition FileFormatDecompress.h:77
grk::FileFormatDecompress::readHeader
bool readHeader(grk_header_info *header_info)
Main header reading function handler.
Definition FileFormatDecompress.cpp:113
grk::FileFormatDecompress::header
std::map< uint32_t, BOX_FUNC > header
Definition FileFormatDecompress.h:73
grk::FileFormatDecompress::serializeAsoc
void serializeAsoc(AsocBox *asoc, grk_asoc *serial_asocs, uint32_t *num_asocs, uint32_t level)
Definition FileFormatDecompress.cpp:71
grk::FileFormatDecompress::init
void init(grk_decompress_core_params *p_param)
Set up decompressor function handler.
Definition FileFormatDecompress.cpp:269
grk::FileFormatDecompress::calc_res
double calc_res(uint16_t num, uint16_t den, uint8_t exponent)
Definition FileFormatDecompress.cpp:700
grk::FileFormatDecompress::find_handler
const BOX_FUNC find_handler(uint32_t id)
Definition FileFormatDecompress.cpp:1134
grk::FileFormatDecompress::decompressTile
bool decompressTile(uint16_t tileIndex)
Definition FileFormatDecompress.cpp:312
grk::FileFormatDecompress::img_header
std::map< uint32_t, BOX_FUNC > img_header
Definition FileFormatDecompress.h:74
grk::FileFormatDecompress::~FileFormatDecompress
virtual ~FileFormatDecompress()
Definition FileFormatDecompress.cpp:46
grk::FileFormatDecompress::read_uuid
bool read_uuid(uint8_t *headerData, uint32_t header_size)
Definition FileFormatDecompress.cpp:675
grk::FileFormatDecompress::decompress
bool decompress(grk_plugin_tile *tile)
Definition FileFormatDecompress.cpp:274
grk::FileFormatDecompress::read_ftyp
bool read_ftyp(uint8_t *headerData, uint32_t header_size)
Reads a a FTYP box - File type box.
Definition FileFormatDecompress.cpp:1194
grk::FileFormatDecompress::img_find_handler
const BOX_FUNC img_find_handler(uint32_t id)
Finds the image execution function related to the given box id.
Definition FileFormatDecompress.cpp:1146
grk::FileFormatDecompress::postProcess
bool postProcess(void)
Definition FileFormatDecompress.cpp:308
grk::FileFormatDecompress::read_colr
bool read_colr(uint8_t *p_colr_header_data, uint32_t colr_header_size)
Definition FileFormatDecompress.cpp:898
grk::FileFormatDecompress::read_res
bool read_res(uint8_t *p_resolution_data, uint32_t resolution_size)
Definition FileFormatDecompress.cpp:731
grk::FileFormatDecompress::readHeaderProcedureImpl
bool readHeaderProcedureImpl(void)
Definition FileFormatDecompress.cpp:401
grk::FileFormatDecompress::read_asoc
uint32_t read_asoc(AsocBox *parent, uint8_t **header_data, uint32_t *header_data_size, uint32_t asocSize)
Definition FileFormatDecompress.cpp:322
grk::FileFormatDecompress::read_component_mapping
bool read_component_mapping(uint8_t *component_mapping_header_data, uint32_t component_mapping_header_size)
Definition FileFormatDecompress.cpp:1021
grk::FileFormatDecompress::getColour
grk_color * getColour(void)
Definition FileFormatDecompress.cpp:105
grk::FileFormatDecompress::read_xml
bool read_xml(uint8_t *p_xml_data, uint32_t xml_size)
Definition FileFormatDecompress.cpp:660
grk::FileFormatDecompress::codeStream
CodeStreamDecompress * codeStream
Definition FileFormatDecompress.h:78
grk::FileFormatDecompress::setDecompressRegion
bool setDecompressRegion(grk_rect_single region)
Definition FileFormatDecompress.cpp:264
grk::FileFormatDecompress::dump
void dump(uint32_t flag, FILE *outputFileStream)
Definition FileFormatDecompress.cpp:397
grk::FileFormatDecompress::read_jp
bool read_jp(uint8_t *headerData, uint32_t header_size)
Reads a JPEG 2000 file signature box.
Definition FileFormatDecompress.cpp:1159
grk::FileFormatDecompress::end
bool end(void)
grk::FileFormatDecompress::read_box
bool read_box(FileFormatBox *box, uint8_t *p_data, uint32_t *p_number_bytes_read, uint64_t p_box_max_size)
Definition FileFormatDecompress.cpp:1291
grk::FileFormatDecompress::getImage
GrkImage * getImage(void)
Definition FileFormatDecompress.cpp:101
grk::FileFormatDecompress::headerError_
bool headerError_
Definition FileFormatDecompress.h:76
grk::FileFormat
JPEG 2000 file format reader/writer.
Definition FileFormat.h:132
grk::GrkImage
Definition GrkImage.h:25
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::BOX_FUNC
std::function< bool(uint8_t *headerData, uint32_t header_size)> BOX_FUNC
Definition FileFormatDecompress.h:26
_grk_asoc
Association box info.
Definition grok.h:332
_grk_color
ICC profile, palette, channel definition.
Definition grok.h:319
_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::AsocBox
Association box (defined in ITU 15444-2 Annex M 11.1 )
Definition FileFormat.h:96
grk::BufferedStream
Definition BufferedStream.h:35
grk::FileFormatBox
Definition FileFormat.h:80
grk::ICodeStreamDecompress
Definition CodeStream.h:115
grk::grk_rect
Definition geometry.h:102