FileFormat.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 <string>
namespace grk
{
#define JP2_JP 0x6a502020
#define JP2_FTYP 0x66747970
#define JP2_JP2H 0x6a703268
#define JP2_IHDR 0x69686472
#define JP2_COLR 0x636f6c72
#define JP2_JP2C 0x6a703263
#define JP2_PCLR 0x70636c72
#define JP2_CMAP 0x636d6170
#define JP2_CDEF 0x63646566
#define JP2_DTBL 0x6474626c
#define JP2_BPCC 0x62706363
#define JP2_JP2 0x6a703220
#define JP2_RES 0x72657320
#define JP2_CAPTURE_RES 0x72657363
#define JP2_DISPLAY_RES 0x72657364
#define JP2_JP2I 0x6a703269
#define JP2_XML 0x786d6c20
#define JP2_UUID 0x75756964
#define JP2_UINF 0x75696e66
#define JP2_ULST 0x756c7374
#define JP2_URL 0x75726c20
#define JP2_ASOC 0x61736f63
#define JP2_LBL 0x6c626c20
#define JP2_MAX_NUM_UUIDS 128
const uint8_t IPTC_UUID[16] = {0x33, 0xC7, 0xA4, 0xD2, 0xB8, 0x1D, 0x47, 0x23,
0xA0, 0xBA, 0xF1, 0xA3, 0xE0, 0x97, 0xAD, 0x38};
const uint8_t XMP_UUID[16] = {0xBE, 0x7A, 0xCF, 0xCB, 0x97, 0xA9, 0x42, 0xE8,
0x9C, 0x71, 0x99, 0x94, 0x91, 0xE3, 0xAF, 0xAC};
#define GRK_BOX_SIZE 1024
#define GRK_RESOLUTION_BOX_SIZE (4 + 4 + 10)
enum JP2_STATE
{
JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2,
JP2_STATE_HEADER = 0x4,
JP2_STATE_CODESTREAM = 0x8,
JP2_STATE_END_CODESTREAM = 0x10,
JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
};
struct FileFormatBox
{
FileFormatBox() : length(0), type(0) {}
uint64_t length;
uint32_t type;
};
struct ComponentInfo
{
ComponentInfo() : bpc(0) {}
uint8_t bpc;
};
struct AsocBox : FileFormatBox, grk_buf8
{
~AsocBox() override
{
dealloc();
}
void dealloc() override
{
grk_buf8::dealloc();
for(auto& as : children)
{
delete as;
}
children.clear();
}
std::string label;
std::vector<AsocBox*> children;
};
struct UUIDBox : public FileFormatBox, grk_buf8
{
UUIDBox()
{
memset(uuid, 0, sizeof(uuid));
}
UUIDBox(const uint8_t myuuid[16], uint8_t* buf, size_t size)
: FileFormatBox(), grk_buf8(buf, size, false)
{
memcpy(uuid, myuuid, 16);
}
uint8_t uuid[16];
};
class FileFormat
{
public:
FileFormat(void);
virtual ~FileFormat();
protected:
bool exec(std::vector<PROCEDURE_FUNC>* procs);
std::vector<PROCEDURE_FUNC>* validation_list_;
std::vector<PROCEDURE_FUNC>* procedure_list_;
/* width of image */
uint32_t w;
/* height of image */
uint32_t h;
/* number of components in the image */
uint16_t numcomps;
uint8_t bpc;
uint8_t C;
uint8_t UnkC;
uint8_t IPR;
uint8_t meth;
uint8_t approx;
GRK_ENUM_COLOUR_SPACE enumcs;
uint8_t precedence;
uint32_t brand;
uint32_t minversion;
uint32_t numcl;
uint32_t* cl;
ComponentInfo* comps;
bool has_capture_resolution;
double capture_resolution[2];
bool has_display_resolution;
double display_resolution[2];
grk_buf8 xml;
UUIDBox uuids[JP2_MAX_NUM_UUIDS];
uint32_t numUuids;
};
/* ----------------------------------------------------------------------- */
} // namespace grk
JP2_MAX_NUM_UUIDS
#define JP2_MAX_NUM_UUIDS
Definition FileFormat.h:59
grk::FileFormat
JPEG 2000 file format reader/writer.
Definition FileFormat.h:132
grk::FileFormat::C
uint8_t C
Definition FileFormat.h:151
grk::FileFormat::h
uint32_t h
Definition FileFormat.h:147
grk::FileFormat::w
uint32_t w
Definition FileFormat.h:145
grk::FileFormat::precedence
uint8_t precedence
Definition FileFormat.h:157
grk::FileFormat::minversion
uint32_t minversion
Definition FileFormat.h:159
grk::FileFormat::capture_resolution
double capture_resolution[2]
Definition FileFormat.h:165
grk::FileFormat::validation_list_
std::vector< PROCEDURE_FUNC > * validation_list_
list of validation procedures
Definition FileFormat.h:140
grk::FileFormat::brand
uint32_t brand
Definition FileFormat.h:158
grk::FileFormat::~FileFormat
virtual ~FileFormat()
Definition FileFormat.cpp:39
grk::FileFormat::numcomps
uint16_t numcomps
Definition FileFormat.h:149
grk::FileFormat::FileFormat
FileFormat(void)
Definition FileFormat.cpp:26
grk::FileFormat::IPR
uint8_t IPR
Definition FileFormat.h:153
grk::FileFormat::numUuids
uint32_t numUuids
Definition FileFormat.h:172
grk::FileFormat::exec
bool exec(std::vector< PROCEDURE_FUNC > *procs)
Definition FileFormat.cpp:50
grk::FileFormat::comps
ComponentInfo * comps
Definition FileFormat.h:162
grk::FileFormat::has_display_resolution
bool has_display_resolution
Definition FileFormat.h:166
grk::FileFormat::numcl
uint32_t numcl
Definition FileFormat.h:160
grk::FileFormat::display_resolution
double display_resolution[2]
Definition FileFormat.h:167
grk::FileFormat::cl
uint32_t * cl
Definition FileFormat.h:161
grk::FileFormat::bpc
uint8_t bpc
Definition FileFormat.h:150
grk::FileFormat::meth
uint8_t meth
Definition FileFormat.h:154
grk::FileFormat::has_capture_resolution
bool has_capture_resolution
Definition FileFormat.h:164
grk::FileFormat::UnkC
uint8_t UnkC
Definition FileFormat.h:152
grk::FileFormat::procedure_list_
std::vector< PROCEDURE_FUNC > * procedure_list_
list of execution procedures
Definition FileFormat.h:142
grk::FileFormat::approx
uint8_t approx
Definition FileFormat.h:155
grk::FileFormat::uuids
UUIDBox uuids[JP2_MAX_NUM_UUIDS]
Definition FileFormat.h:171
grk::FileFormat::enumcs
GRK_ENUM_COLOUR_SPACE enumcs
Definition FileFormat.h:156
grk::FileFormat::xml
grk_buf8 xml
Definition FileFormat.h:169
GRK_ENUM_COLOUR_SPACE
enum _GRK_ENUM_COLOUR_SPACE GRK_ENUM_COLOUR_SPACE
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::IPTC_UUID
const uint8_t IPTC_UUID[16]
Definition FileFormat.h:60
grk::JP2_STATE
JP2_STATE
Definition FileFormat.h:69
grk::JP2_STATE_UNKNOWN
@ JP2_STATE_UNKNOWN
Definition FileFormat.h:76
grk::JP2_STATE_FILE_TYPE
@ JP2_STATE_FILE_TYPE
Definition FileFormat.h:72
grk::JP2_STATE_SIGNATURE
@ JP2_STATE_SIGNATURE
Definition FileFormat.h:71
grk::JP2_STATE_CODESTREAM
@ JP2_STATE_CODESTREAM
Definition FileFormat.h:74
grk::JP2_STATE_NONE
@ JP2_STATE_NONE
Definition FileFormat.h:70
grk::JP2_STATE_HEADER
@ JP2_STATE_HEADER
Definition FileFormat.h:73
grk::JP2_STATE_END_CODESTREAM
@ JP2_STATE_END_CODESTREAM
Definition FileFormat.h:75
grk::XMP_UUID
const uint8_t XMP_UUID[16]
Definition FileFormat.h:62
grk::AsocBox
Association box (defined in ITU 15444-2 Annex M 11.1 )
Definition FileFormat.h:96
grk::AsocBox::label
std::string label
Definition FileFormat.h:110
grk::AsocBox::dealloc
void dealloc() override
Definition FileFormat.h:101
grk::AsocBox::~AsocBox
~AsocBox() override
Definition FileFormat.h:97
grk::AsocBox::children
std::vector< AsocBox * > children
Definition FileFormat.h:111
grk::ComponentInfo
Definition FileFormat.h:87
grk::ComponentInfo::bpc
uint8_t bpc
Definition FileFormat.h:89
grk::ComponentInfo::ComponentInfo
ComponentInfo()
Definition FileFormat.h:88
grk::FileFormatBox
Definition FileFormat.h:80
grk::FileFormatBox::length
uint64_t length
Definition FileFormat.h:82
grk::FileFormatBox::FileFormatBox
FileFormatBox()
Definition FileFormat.h:81
grk::FileFormatBox::type
uint32_t type
Definition FileFormat.h:83
grk::UUIDBox
Definition FileFormat.h:115
grk::UUIDBox::UUIDBox
UUIDBox()
Definition FileFormat.h:116
grk::UUIDBox::UUIDBox
UUIDBox(const uint8_t myuuid[16], uint8_t *buf, size_t size)
Definition FileFormat.h:120
grk::UUIDBox::uuid
uint8_t uuid[16]
Definition FileFormat.h:125
grk::grk_buf< uint8_t, AllocatorVanilla >
grk::grk_buf< uint8_t, AllocatorVanilla >::dealloc
virtual void dealloc()
Definition buffer.h:117
grk::grk_buf< uint8_t, AllocatorVanilla >::buf
uint8_t * buf
Definition buffer.h:195