2014-03-07 10:44:32 +01:00
|
|
|
/*
|
2017-05-15 12:21:30 +02:00
|
|
|
* The copyright in this software is being made available under the 2-clauses
|
|
|
|
* BSD License, included below. This software may be subject to other third
|
2014-04-03 17:30:57 +02:00
|
|
|
* party and contributor rights, including patent rights, and no such rights
|
|
|
|
* are granted under this license.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
|
|
|
|
* Copyright (c) 2002-2014, Professor Benoit Macq
|
2014-03-07 10:44:32 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2017-07-30 19:46:52 +02:00
|
|
|
#ifndef OPJ_CODEC_H
|
|
|
|
#define OPJ_CODEC_H
|
2014-03-07 10:44:32 +01:00
|
|
|
/**
|
|
|
|
@file opj_codec.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main codec handler used for compression or decompression.
|
|
|
|
*/
|
2017-05-15 12:21:30 +02:00
|
|
|
typedef struct opj_codec_private {
|
2014-03-07 10:44:32 +01:00
|
|
|
/** FIXME DOC */
|
2017-05-15 12:21:30 +02:00
|
|
|
union {
|
2014-03-07 10:44:32 +01:00
|
|
|
/**
|
|
|
|
* Decompression handler.
|
|
|
|
*/
|
2017-05-15 12:21:30 +02:00
|
|
|
struct opj_decompression {
|
2014-03-07 10:44:32 +01:00
|
|
|
/** Main header reading function handler */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_read_header)(struct opj_stream_private * cio,
|
|
|
|
void * p_codec,
|
|
|
|
opj_image_t **p_image,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Decoding function */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_decode)(void * p_codec,
|
|
|
|
struct opj_stream_private * p_cio,
|
|
|
|
opj_image_t * p_image,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** FIXME DOC */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_read_tile_header)(void * p_codec,
|
|
|
|
OPJ_UINT32 * p_tile_index,
|
|
|
|
OPJ_UINT32 * p_data_size,
|
|
|
|
OPJ_INT32 * p_tile_x0,
|
|
|
|
OPJ_INT32 * p_tile_y0,
|
|
|
|
OPJ_INT32 * p_tile_x1,
|
|
|
|
OPJ_INT32 * p_tile_y1,
|
|
|
|
OPJ_UINT32 * p_nb_comps,
|
|
|
|
OPJ_BOOL * p_should_go_on,
|
|
|
|
struct opj_stream_private * p_cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** FIXME DOC */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_decode_tile_data)(void * p_codec,
|
|
|
|
OPJ_UINT32 p_tile_index,
|
|
|
|
OPJ_BYTE * p_data,
|
|
|
|
OPJ_UINT32 p_data_size,
|
|
|
|
struct opj_stream_private * p_cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Reading function used after codestream if necessary */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(* opj_end_decompress)(void *p_codec,
|
|
|
|
struct opj_stream_private * cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Codec destroy function handler */
|
2017-05-15 12:21:30 +02:00
|
|
|
void (*opj_destroy)(void * p_codec);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Setup decoder function handler */
|
2017-05-15 12:21:30 +02:00
|
|
|
void (*opj_setup_decoder)(void * p_codec, opj_dparameters_t * p_param);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Set decode area function handler */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_set_decode_area)(void * p_codec,
|
|
|
|
opj_image_t * p_image,
|
|
|
|
OPJ_INT32 p_start_x,
|
|
|
|
OPJ_INT32 p_end_x,
|
|
|
|
OPJ_INT32 p_start_y,
|
|
|
|
OPJ_INT32 p_end_y,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Get tile function */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_get_decoded_tile)(void *p_codec,
|
|
|
|
opj_stream_private_t * p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager,
|
|
|
|
OPJ_UINT32 tile_index);
|
2014-03-07 10:44:32 +01:00
|
|
|
|
|
|
|
/** Set the decoded resolution factor */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_set_decoded_resolution_factor)(void * p_codec,
|
|
|
|
OPJ_UINT32 res_factor,
|
|
|
|
opj_event_mgr_t * p_manager);
|
2016-05-25 16:36:47 +02:00
|
|
|
|
2017-09-19 16:52:07 +02:00
|
|
|
/** Set the decoded components */
|
|
|
|
OPJ_BOOL(*opj_set_decoded_components)(void * p_codec,
|
|
|
|
OPJ_UINT32 num_comps,
|
|
|
|
const OPJ_UINT32* comps_indices,
|
|
|
|
opj_event_mgr_t * p_manager);
|
2014-03-07 10:44:32 +01:00
|
|
|
} m_decompression;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compression handler. FIXME DOC
|
|
|
|
*/
|
2017-05-15 12:21:30 +02:00
|
|
|
struct opj_compression {
|
|
|
|
OPJ_BOOL(* opj_start_compress)(void *p_codec,
|
|
|
|
struct opj_stream_private * cio,
|
|
|
|
struct opj_image * p_image,
|
|
|
|
struct opj_event_mgr * p_manager);
|
|
|
|
|
|
|
|
OPJ_BOOL(* opj_encode)(void * p_codec,
|
|
|
|
struct opj_stream_private *p_cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
|
|
|
|
|
|
|
OPJ_BOOL(* opj_write_tile)(void * p_codec,
|
|
|
|
OPJ_UINT32 p_tile_index,
|
|
|
|
OPJ_BYTE * p_data,
|
|
|
|
OPJ_UINT32 p_data_size,
|
|
|
|
struct opj_stream_private * p_cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
|
|
|
|
|
|
|
OPJ_BOOL(* opj_end_compress)(void * p_codec,
|
|
|
|
struct opj_stream_private * p_cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
|
|
|
|
|
|
|
void (* opj_destroy)(void * p_codec);
|
|
|
|
|
|
|
|
OPJ_BOOL(* opj_setup_encoder)(void * p_codec,
|
|
|
|
opj_cparameters_t * p_param,
|
|
|
|
struct opj_image * p_image,
|
2014-03-07 10:44:32 +01:00
|
|
|
struct opj_event_mgr * p_manager);
|
Add support for generation of PLT markers in encoder
* -PLT switch added to opj_compress
* Add a opj_encoder_set_extra_options() function that
accepts a PLT=YES option, and could be expanded later
for other uses.
-------
Testing with a Sentinel2 10m band, T36JTT_20160914T074612_B02.jp2,
coming from S2A_MSIL1C_20160914T074612_N0204_R135_T36JTT_20160914T081456.SAFE
Decompress it to TIFF:
```
opj_uncompress -i T36JTT_20160914T074612_B02.jp2 -o T36JTT_20160914T074612_B02.tif
```
Recompress it with similar parameters as original:
```
opj_compress -n 5 -c [256,256],[256,256],[256,256],[256,256],[256,256] -t 1024,1024 -PLT -i T36JTT_20160914T074612_B02.tif -o T36JTT_20160914T074612_B02_PLT.jp2
```
Dump codestream detail with GDAL dump_jp2.py utility (https://github.com/OSGeo/gdal/blob/master/gdal/swig/python/samples/dump_jp2.py)
```
python dump_jp2.py T36JTT_20160914T074612_B02.jp2 > /tmp/dump_sentinel2_ori.txt
python dump_jp2.py T36JTT_20160914T074612_B02_PLT.jp2 > /tmp/dump_sentinel2_openjpeg_plt.txt
```
The diff between both show very similar structure, and identical number of packets in PLT markers
Now testing with Kakadu (KDU803_Demo_Apps_for_Linux-x86-64_200210)
Full file decompression:
```
kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp.tif
Consumed 121 tile-part(s) from a total of 121 tile(s).
Consumed 80,318,806 codestream bytes (excluding any file format) = 5.329697
bits/pel.
Processed using the multi-threaded environment, with
8 parallel threads of execution
```
Partial decompresson (presumably using PLT markers):
```
kdu_expand -i T36JTT_20160914T074612_B02.jp2 -o tmp.pgm -region "{0.5,0.5},{0.01,0.01}"
kdu_expand -i T36JTT_20160914T074612_B02_PLT.jp2 -o tmp2.pgm -region "{0.5,0.5},{0.01,0.01}"
diff tmp.pgm tmp2.pgm && echo "same !"
```
-------
Funded by ESA for S2-MPC project
2020-04-21 15:55:44 +02:00
|
|
|
|
|
|
|
OPJ_BOOL(* opj_encoder_set_extra_options)(void * p_codec,
|
|
|
|
const char* const* p_options,
|
|
|
|
struct opj_event_mgr * p_manager);
|
|
|
|
|
2014-03-07 10:44:32 +01:00
|
|
|
} m_compression;
|
|
|
|
} m_codec_data;
|
|
|
|
/** FIXME DOC*/
|
|
|
|
void * m_codec;
|
|
|
|
/** Event handler */
|
|
|
|
opj_event_mgr_t m_event_mgr;
|
|
|
|
/** Flag to indicate if the codec is used to decode or encode*/
|
|
|
|
OPJ_BOOL is_decompressor;
|
2017-05-15 12:21:30 +02:00
|
|
|
void (*opj_dump_codec)(void * p_codec, OPJ_INT32 info_flag,
|
|
|
|
FILE* output_stream);
|
2014-03-07 10:44:32 +01:00
|
|
|
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
|
|
|
|
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
|
2016-05-25 16:36:47 +02:00
|
|
|
|
|
|
|
/** Set number of threads */
|
2017-05-15 12:21:30 +02:00
|
|
|
OPJ_BOOL(*opj_set_threads)(void * p_codec, OPJ_UINT32 num_threads);
|
2014-03-07 10:44:32 +01:00
|
|
|
}
|
|
|
|
opj_codec_private_t;
|
|
|
|
|
|
|
|
|
2017-07-30 19:46:52 +02:00
|
|
|
#endif /* OPJ_CODEC_H */
|
2014-03-07 10:44:32 +01:00
|
|
|
|