2005-12-02 14:34:15 +01:00
|
|
|
/*
|
2011-01-29 15:15:26 +01:00
|
|
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
2005-12-02 14:34:15 +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.
|
|
|
|
*/
|
|
|
|
|
2010-11-25 12:58:26 +01:00
|
|
|
#ifdef _WIN32
|
2006-01-31 22:26:11 +01:00
|
|
|
#include <windows.h>
|
2010-11-25 12:58:26 +01:00
|
|
|
#endif /* _WIN32 */
|
2006-01-31 22:26:11 +01:00
|
|
|
|
2010-11-22 12:48:19 +01:00
|
|
|
#include "opj_config.h"
|
2005-12-02 14:34:15 +01:00
|
|
|
#include "opj_includes.h"
|
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decompression handler.
|
|
|
|
*/
|
2011-09-19 15:04:04 +02:00
|
|
|
typedef struct opj_decompression
|
|
|
|
{
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Main header reading function handler*/
|
2011-11-08 14:13:05 +01:00
|
|
|
opj_bool (*opj_read_header) ( struct opj_stream_private * cio,
|
2011-09-19 18:01:49 +02:00
|
|
|
void * p_codec,
|
2011-10-12 16:42:21 +02:00
|
|
|
opj_image_t **p_image,
|
2011-09-19 18:01:49 +02:00
|
|
|
struct opj_event_mgr * p_manager);
|
2011-11-08 14:13:05 +01:00
|
|
|
/** Decoding function */
|
|
|
|
opj_bool (*opj_decode) ( void * p_codec,
|
2011-10-05 18:27:16 +02:00
|
|
|
struct opj_stream_private *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2011-09-21 18:37:45 +02:00
|
|
|
/** FIXME DOC */
|
2011-09-19 18:01:49 +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);
|
2011-09-21 18:37:45 +02:00
|
|
|
/** FIXME DOC */
|
2011-09-19 18:01:49 +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);
|
2011-11-08 14:13:05 +01:00
|
|
|
/** Reading function used after codestream if necessary */
|
2011-09-19 18:01:49 +02:00
|
|
|
opj_bool (* opj_end_decompress) ( void *p_codec,
|
|
|
|
struct opj_stream_private *cio,
|
|
|
|
struct opj_event_mgr * p_manager);
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Codec destroy function handler*/
|
2011-11-08 14:13:05 +01:00
|
|
|
void (*opj_destroy) (void * p_codec);
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Setup decoder function handler */
|
2011-09-19 18:01:49 +02:00
|
|
|
void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Set decode area function handler */
|
2011-09-19 18:01:49 +02:00
|
|
|
opj_bool (*opj_set_decode_area) ( void * p_codec,
|
2011-10-21 18:38:08 +02:00
|
|
|
opj_image_t* p_image,
|
2011-09-19 18:01:49 +02:00
|
|
|
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);
|
2011-11-08 14:21:17 +01:00
|
|
|
|
|
|
|
/** Get tile function */
|
|
|
|
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);
|
2011-11-17 15:21:11 +01:00
|
|
|
|
|
|
|
/** Set the decoded resolution factor */
|
|
|
|
opj_bool (*opj_set_decoded_resolution_factor) (void * p_codec, OPJ_UINT32 res_factor, struct opj_event_mgr * p_manager);
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
}opj_decompression_t;
|
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
/**
|
|
|
|
* Compression handler. FIXME DOC
|
|
|
|
*/
|
2011-09-19 15:04:04 +02:00
|
|
|
typedef 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);
|
|
|
|
void (*opj_setup_encoder) (void * p_codec,opj_cparameters_t * p_param,struct opj_image * p_image, struct opj_event_mgr * p_manager);
|
|
|
|
|
|
|
|
}opj_compression_t;
|
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
/**
|
|
|
|
* Main codec handler used for compression or decompression.
|
|
|
|
*/
|
2011-09-19 15:04:04 +02:00
|
|
|
typedef struct opj_codec_private
|
|
|
|
{
|
2011-09-21 18:37:45 +02:00
|
|
|
/** FIXME DOC */
|
2011-09-19 18:01:49 +02:00
|
|
|
union {
|
|
|
|
opj_decompression_t m_decompression;
|
|
|
|
opj_compression_t m_compression;
|
2011-09-19 15:04:04 +02:00
|
|
|
} m_codec_data;
|
2011-09-21 18:37:45 +02:00
|
|
|
/** FIXME DOC*/
|
2011-09-19 15:04:04 +02:00
|
|
|
void * m_codec;
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Event handler */
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_event_mgr_t* m_event_mgr;
|
2011-09-21 18:37:45 +02:00
|
|
|
/** Flag to indicate if the codec is used to decode or encode*/
|
|
|
|
opj_bool is_decompressor;
|
2011-10-07 19:31:35 +02:00
|
|
|
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
|
2011-09-27 14:14:11 +02:00
|
|
|
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
|
|
|
|
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
|
|
|
opj_codec_private_t;
|
|
|
|
|
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_SIZE_T opj_read_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_SIZE_T l_nb_read = fread(p_buffer,1,p_nb_bytes,p_file);
|
2011-09-19 15:04:04 +02:00
|
|
|
return l_nb_read ? l_nb_read : -1;
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_UINT64 opj_get_data_length_from_file (FILE * p_file)
|
2011-10-11 10:01:31 +02:00
|
|
|
{
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_OFF_T file_length = 0;
|
2011-10-11 10:01:31 +02:00
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_FSEEK(p_file, 0, SEEK_END);
|
|
|
|
file_length = (OPJ_UINT64)OPJ_FTELL(p_file);
|
|
|
|
OPJ_FSEEK(p_file, 0, SEEK_SET);
|
2011-10-11 10:01:31 +02:00
|
|
|
|
|
|
|
return file_length;
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_SIZE_T opj_write_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
|
|
|
return fwrite(p_buffer,1,p_nb_bytes,p_file);
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_OFF_T opj_skip_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
2011-11-30 17:55:25 +01:00
|
|
|
if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_CUR)) {
|
2011-09-19 15:04:04 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
return p_nb_bytes;
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
opj_bool opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
2011-11-30 17:55:25 +01:00
|
|
|
if (OPJ_FSEEK(p_user_data,p_nb_bytes,SEEK_SET)) {
|
2011-09-19 15:04:04 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
/* ---------------------------------------------------------------------- */
|
2010-11-25 12:58:26 +01:00
|
|
|
#ifdef _WIN32
|
2006-01-31 22:26:11 +01:00
|
|
|
#ifndef OPJ_STATIC
|
|
|
|
BOOL APIENTRY
|
|
|
|
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
|
2011-08-10 10:12:10 +02:00
|
|
|
|
|
|
|
OPJ_ARG_NOT_USED(lpReserved);
|
|
|
|
OPJ_ARG_NOT_USED(hModule);
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
switch (ul_reason_for_call) {
|
|
|
|
case DLL_PROCESS_ATTACH :
|
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH :
|
|
|
|
break;
|
|
|
|
case DLL_THREAD_ATTACH :
|
|
|
|
case DLL_THREAD_DETACH :
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
#endif /* OPJ_STATIC */
|
2010-11-25 12:58:26 +01:00
|
|
|
#endif /* _WIN32 */
|
2006-01-31 22:26:11 +01:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2007-08-21 14:02:23 +02:00
|
|
|
const char* OPJ_CALLCONV opj_version(void) {
|
2010-10-05 12:33:15 +02:00
|
|
|
return PACKAGE_VERSION;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
|
2011-11-08 14:13:05 +01:00
|
|
|
/* DEPRECATED */
|
2006-01-31 22:26:11 +01:00
|
|
|
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
|
2008-02-29 10:36:12 +01:00
|
|
|
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
|
2005-12-08 10:38:47 +01:00
|
|
|
if(!dinfo) return NULL;
|
2011-05-18 13:02:27 +02:00
|
|
|
dinfo->is_decompressor = OPJ_TRUE;
|
2005-12-08 10:38:47 +01:00
|
|
|
switch(format) {
|
|
|
|
case CODEC_J2K:
|
|
|
|
case CODEC_JPT:
|
|
|
|
/* get a J2K decoder handle */
|
|
|
|
dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
|
|
|
|
if(!dinfo->j2k_handle) {
|
|
|
|
opj_free(dinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
|
|
|
/* get a JP2 decoder handle */
|
|
|
|
dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
|
|
|
|
if(!dinfo->jp2_handle) {
|
|
|
|
opj_free(dinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_UNKNOWN:
|
2005-12-08 10:38:47 +01:00
|
|
|
default:
|
|
|
|
opj_free(dinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dinfo->codec_format = format;
|
|
|
|
|
|
|
|
return dinfo;
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
|
|
|
|
{
|
|
|
|
opj_codec_private_t *l_info = 00;
|
|
|
|
|
|
|
|
l_info = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
|
|
|
|
if (!l_info){
|
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
memset(l_info, 0, sizeof(opj_codec_private_t));
|
|
|
|
|
|
|
|
l_info->is_decompressor = 1;
|
|
|
|
|
2011-09-19 15:36:07 +02:00
|
|
|
switch (p_format) {
|
2011-09-19 15:04:04 +02:00
|
|
|
case CODEC_J2K:
|
2011-10-07 19:31:35 +02:00
|
|
|
l_info->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) j2k_dump;
|
2011-09-27 14:14:11 +02:00
|
|
|
|
|
|
|
l_info->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) j2k_get_cstr_info;
|
|
|
|
|
|
|
|
l_info->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;
|
|
|
|
|
2011-09-19 18:01:49 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_decode =
|
2011-10-05 18:27:16 +02:00
|
|
|
(opj_bool (*) ( void *,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
opj_image_t*, struct opj_event_mgr * )) j2k_decode_v2;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_end_decompress =
|
2011-10-05 18:27:16 +02:00
|
|
|
(opj_bool (*) ( void *,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr *)) j2k_end_decompress;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_read_header =
|
|
|
|
(opj_bool (*) ( struct opj_stream_private *,
|
|
|
|
void *,
|
2011-10-12 16:42:21 +02:00
|
|
|
opj_image_t **,
|
2011-09-19 18:01:49 +02:00
|
|
|
struct opj_event_mgr * )) j2k_read_header;
|
|
|
|
|
2011-10-05 18:27:16 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_destroy =
|
|
|
|
(void (*) (void *))j2k_destroy;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-10-05 18:27:16 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_setup_decoder =
|
|
|
|
(void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_read_tile_header =
|
|
|
|
(opj_bool (*) ( void *,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_INT32*, OPJ_INT32*,
|
|
|
|
OPJ_INT32*, OPJ_INT32*,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
opj_bool*,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr * )) j2k_read_tile_header;
|
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_decode_tile_data =
|
|
|
|
(opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile;
|
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_set_decode_area =
|
2011-10-21 18:38:08 +02:00
|
|
|
(opj_bool (*) (void *, opj_image_t*, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-11-08 14:21:17 +01:00
|
|
|
l_info->m_codec_data.m_decompression.opj_get_decoded_tile = (opj_bool (*) ( void *p_codec,
|
|
|
|
opj_stream_private_t *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager,
|
|
|
|
OPJ_UINT32 tile_index)) j2k_get_tile;
|
|
|
|
|
2011-11-17 15:21:11 +01:00
|
|
|
l_info->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = (opj_bool (*) (void * p_codec,
|
|
|
|
OPJ_UINT32 res_factor,
|
|
|
|
struct opj_event_mgr * p_manager)) j2k_set_decoded_resolution_factor;
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec = j2k_create_decompress_v2();
|
2011-09-19 15:36:07 +02:00
|
|
|
|
|
|
|
if (! l_info->m_codec) {
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_free(l_info);
|
2011-09-19 15:36:07 +02:00
|
|
|
return NULL;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-19 15:36:07 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CODEC_JP2:
|
|
|
|
/* get a JP2 decoder handle */
|
2011-10-07 19:31:35 +02:00
|
|
|
l_info->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) jp2_dump;
|
|
|
|
|
|
|
|
l_info->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) jp2_get_cstr_info;
|
|
|
|
|
|
|
|
l_info->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) jp2_get_cstr_index;
|
|
|
|
|
2011-10-05 18:27:16 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_decode =
|
|
|
|
(opj_bool (*) ( void *,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
opj_image_t*,
|
2011-10-12 16:42:21 +02:00
|
|
|
struct opj_event_mgr * )) jp2_decode_v2;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
|
2011-09-19 15:36:07 +02:00
|
|
|
struct opj_stream_private *,
|
|
|
|
void *,
|
2011-10-12 16:42:21 +02:00
|
|
|
opj_image_t **,
|
2011-09-19 15:36:07 +02:00
|
|
|
struct opj_event_mgr * )) jp2_read_header;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-09-19 18:01:49 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
|
2011-09-19 15:04:04 +02:00
|
|
|
void *,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_INT32*,
|
|
|
|
OPJ_INT32*,
|
|
|
|
OPJ_INT32 * ,
|
|
|
|
OPJ_INT32 * ,
|
|
|
|
OPJ_UINT32 * ,
|
|
|
|
opj_bool *,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr * )) jp2_read_tile_header;
|
|
|
|
|
2011-10-12 16:42:21 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *, struct opj_event_mgr * )) jp2_decode_tile;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:36:07 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-10-21 18:38:08 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,opj_image_t*, OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-11-08 14:21:17 +01:00
|
|
|
l_info->m_codec_data.m_decompression.opj_get_decoded_tile = (opj_bool (*) ( void *p_codec,
|
|
|
|
opj_stream_private_t *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager,
|
|
|
|
OPJ_UINT32 tile_index)) jp2_get_tile;
|
|
|
|
|
2011-11-17 15:21:11 +01:00
|
|
|
l_info->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = (opj_bool (*) (void * p_codec,
|
|
|
|
OPJ_UINT32 res_factor,
|
|
|
|
opj_event_mgr_t * p_manager)) jp2_set_decoded_resolution_factor;
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec = jp2_create(OPJ_TRUE);
|
2011-09-19 15:36:07 +02:00
|
|
|
|
|
|
|
if (! l_info->m_codec) {
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_free(l_info);
|
|
|
|
return 00;
|
|
|
|
}
|
2011-09-19 15:36:07 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
break;
|
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
case CODEC_JPT:
|
|
|
|
default:
|
|
|
|
opj_free(l_info);
|
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (opj_codec_t*) l_info;
|
|
|
|
}
|
|
|
|
|
2011-11-08 14:13:05 +01:00
|
|
|
/* DEPRECATED */
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(dinfo) {
|
|
|
|
/* destroy the codec */
|
|
|
|
switch(dinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
|
|
|
case CODEC_JPT:
|
|
|
|
j2k_destroy_decompress((opj_j2k_t*)dinfo->j2k_handle);
|
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
|
|
|
jp2_destroy_decompress((opj_jp2_t*)dinfo->jp2_handle);
|
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
/* destroy the decompressor */
|
|
|
|
opj_free(dinfo);
|
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(parameters) {
|
|
|
|
memset(parameters, 0, sizeof(opj_dparameters_t));
|
|
|
|
/* default decoding parameters */
|
|
|
|
parameters->cp_layer = 0;
|
|
|
|
parameters->cp_reduce = 0;
|
2007-02-19 10:59:29 +01:00
|
|
|
parameters->cp_limit_decoding = NO_LIMITATION;
|
2005-12-08 10:38:47 +01:00
|
|
|
|
|
|
|
parameters->decod_format = -1;
|
|
|
|
parameters->cod_format = -1;
|
2006-12-04 15:59:33 +01:00
|
|
|
/* UniPG>> */
|
|
|
|
#ifdef USE_JPWL
|
2011-05-18 13:02:27 +02:00
|
|
|
parameters->jpwl_correct = OPJ_FALSE;
|
2006-12-04 15:59:33 +01:00
|
|
|
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
|
|
|
|
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
|
|
|
|
#endif /* USE_JPWL */
|
|
|
|
/* <<UniPG */
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2011-11-08 14:13:05 +01:00
|
|
|
/* DEPRECATED */
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(dinfo && parameters) {
|
|
|
|
switch(dinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
|
|
|
case CODEC_JPT:
|
|
|
|
j2k_setup_decoder((opj_j2k_t*)dinfo->j2k_handle, parameters);
|
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
|
|
|
jp2_setup_decoder((opj_jp2_t*)dinfo->jp2_handle, parameters);
|
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr)
|
|
|
|
{
|
2011-09-21 18:37:45 +02:00
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
if ( !p_info || !parameters || !event_mgr ){
|
|
|
|
fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
if ( !event_mgr->error_handler || !event_mgr->warning_handler || !event_mgr->error_handler){
|
|
|
|
fprintf(stderr, "[ERROR] Event handler provided to the setup_decoder function is not valid.\n");
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 15:18:19 +02:00
|
|
|
|
2011-09-21 18:37:45 +02:00
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
opj_event_msg_v2(event_mgr, EVT_ERROR, "Codec provided to the setup_decoder function is not a decompressor handler.\n");
|
|
|
|
return OPJ_FALSE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec, parameters);
|
|
|
|
|
|
|
|
l_info->m_event_mgr = event_mgr;
|
|
|
|
|
|
|
|
return OPJ_TRUE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
|
|
|
|
2011-11-08 14:13:05 +01:00
|
|
|
/* DEPRECATED */
|
2007-09-17 17:11:20 +02:00
|
|
|
opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
|
|
|
|
return opj_decode_with_info(dinfo, cio, NULL);
|
|
|
|
}
|
|
|
|
|
2011-11-08 14:13:05 +01:00
|
|
|
/* DEPRECATED */
|
2007-09-17 17:11:20 +02:00
|
|
|
opj_image_t* OPJ_CALLCONV opj_decode_with_info(opj_dinfo_t *dinfo, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(dinfo && cio) {
|
|
|
|
switch(dinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
2007-09-07 17:01:55 +02:00
|
|
|
return j2k_decode((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
|
2005-12-08 10:38:47 +01:00
|
|
|
case CODEC_JPT:
|
2007-09-07 17:01:55 +02:00
|
|
|
return j2k_decode_jpt_stream((opj_j2k_t*)dinfo->j2k_handle, cio, cstr_info);
|
2005-12-08 10:38:47 +01:00
|
|
|
case CODEC_JP2:
|
2011-04-12 19:24:30 +02:00
|
|
|
return opj_jp2_decode((opj_jp2_t*)dinfo->jp2_handle, cio, cstr_info);
|
2006-01-31 22:26:11 +01:00
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
|
2008-02-29 10:36:12 +01:00
|
|
|
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
|
2005-12-08 10:38:47 +01:00
|
|
|
if(!cinfo) return NULL;
|
2011-05-18 13:02:27 +02:00
|
|
|
cinfo->is_decompressor = OPJ_FALSE;
|
2005-12-08 10:38:47 +01:00
|
|
|
switch(format) {
|
|
|
|
case CODEC_J2K:
|
|
|
|
/* get a J2K coder handle */
|
|
|
|
cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
|
|
|
|
if(!cinfo->j2k_handle) {
|
|
|
|
opj_free(cinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
|
|
|
/* get a JP2 coder handle */
|
|
|
|
cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
|
|
|
|
if(!cinfo->jp2_handle) {
|
|
|
|
opj_free(cinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_JPT:
|
|
|
|
case CODEC_UNKNOWN:
|
2005-12-08 10:38:47 +01:00
|
|
|
default:
|
|
|
|
opj_free(cinfo);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cinfo->codec_format = format;
|
|
|
|
|
|
|
|
return cinfo;
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(cinfo) {
|
|
|
|
/* destroy the codec */
|
|
|
|
switch(cinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
2007-08-28 12:13:58 +02:00
|
|
|
j2k_destroy_compress((opj_j2k_t*)cinfo->j2k_handle);
|
2005-12-08 10:38:47 +01:00
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
2007-08-28 12:13:58 +02:00
|
|
|
jp2_destroy_compress((opj_jp2_t*)cinfo->jp2_handle);
|
2005-12-08 10:38:47 +01:00
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_JPT:
|
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
/* destroy the decompressor */
|
|
|
|
opj_free(cinfo);
|
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(parameters) {
|
|
|
|
memset(parameters, 0, sizeof(opj_cparameters_t));
|
|
|
|
/* default coding parameters */
|
2007-03-07 17:04:33 +01:00
|
|
|
parameters->cp_cinema = OFF;
|
2007-04-04 15:40:32 +02:00
|
|
|
parameters->max_comp_size = 0;
|
2005-12-08 10:38:47 +01:00
|
|
|
parameters->numresolution = 6;
|
2007-03-07 17:04:33 +01:00
|
|
|
parameters->cp_rsiz = STD_RSIZ;
|
2005-12-08 10:38:47 +01:00
|
|
|
parameters->cblockw_init = 64;
|
|
|
|
parameters->cblockh_init = 64;
|
|
|
|
parameters->prog_order = LRCP;
|
|
|
|
parameters->roi_compno = -1; /* no ROI */
|
|
|
|
parameters->subsampling_dx = 1;
|
|
|
|
parameters->subsampling_dy = 1;
|
2007-03-20 18:15:18 +01:00
|
|
|
parameters->tp_on = 0;
|
2005-12-08 10:38:47 +01:00
|
|
|
parameters->decod_format = -1;
|
|
|
|
parameters->cod_format = -1;
|
2008-07-09 13:43:02 +02:00
|
|
|
parameters->tcp_rates[0] = 0;
|
2009-09-08 20:25:51 +02:00
|
|
|
parameters->tcp_numlayers = 0;
|
2011-09-19 18:01:49 +02:00
|
|
|
parameters->cp_disto_alloc = 0;
|
2009-09-08 20:25:51 +02:00
|
|
|
parameters->cp_fixed_alloc = 0;
|
|
|
|
parameters->cp_fixed_quality = 0;
|
2011-09-09 16:49:08 +02:00
|
|
|
parameters->jpip_on = OPJ_FALSE;
|
2006-12-04 15:59:33 +01:00
|
|
|
/* UniPG>> */
|
|
|
|
#ifdef USE_JPWL
|
2011-05-18 13:02:27 +02:00
|
|
|
parameters->jpwl_epc_on = OPJ_FALSE;
|
2006-12-04 15:59:33 +01:00
|
|
|
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
|
|
|
parameters->jpwl_hprot_TPH_tileno[i] = -1; /* unassigned */
|
|
|
|
parameters->jpwl_hprot_TPH[i] = 0; /* absent */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
|
|
|
|
parameters->jpwl_pprot_tileno[i] = -1; /* unassigned */
|
|
|
|
parameters->jpwl_pprot_packno[i] = -1; /* unassigned */
|
|
|
|
parameters->jpwl_pprot[i] = 0; /* absent */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
parameters->jpwl_sens_size = 0; /* 0 means no ESD */
|
|
|
|
parameters->jpwl_sens_addr = 0; /* 0 means auto */
|
|
|
|
parameters->jpwl_sens_range = 0; /* 0 means packet */
|
|
|
|
parameters->jpwl_sens_MH = -1; /* -1 means unassigned */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
|
|
|
|
parameters->jpwl_sens_TPH_tileno[i] = -1; /* unassigned */
|
|
|
|
parameters->jpwl_sens_TPH[i] = -1; /* absent */
|
|
|
|
}
|
|
|
|
};
|
2007-01-31 16:19:54 +01:00
|
|
|
#endif /* USE_JPWL */
|
2006-12-04 15:59:33 +01:00
|
|
|
/* <<UniPG */
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
/**
|
|
|
|
* Helper function.
|
|
|
|
* Sets the stream to be a file stream. The FILE must have been open previously.
|
|
|
|
* @param p_stream the stream to modify
|
|
|
|
* @param p_file handler to an already open file.
|
|
|
|
*/
|
|
|
|
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, opj_bool p_is_read_stream)
|
|
|
|
{
|
|
|
|
return opj_stream_create_file_stream(p_file,J2K_STREAM_CHUNK_SIZE,p_is_read_stream);
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:55:25 +01:00
|
|
|
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_SIZE_T p_size, opj_bool p_is_read_stream)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
|
|
|
opj_stream_t* l_stream = 00;
|
2011-09-19 15:30:21 +02:00
|
|
|
|
|
|
|
if (! p_file) {
|
|
|
|
return NULL;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-19 15:30:21 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_stream = opj_stream_create(p_size,p_is_read_stream);
|
2011-09-19 15:30:21 +02:00
|
|
|
if (! l_stream) {
|
|
|
|
return NULL;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-19 15:30:21 +02:00
|
|
|
|
|
|
|
opj_stream_set_user_data(l_stream, p_file);
|
2011-10-11 10:01:31 +02:00
|
|
|
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
|
2011-09-19 15:30:21 +02:00
|
|
|
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file);
|
|
|
|
opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file);
|
|
|
|
opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file);
|
2011-09-19 15:30:21 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
return l_stream;
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:26:11 +01:00
|
|
|
void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_image_t *image) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(cinfo && parameters && image) {
|
|
|
|
switch(cinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
|
|
|
j2k_setup_encoder((opj_j2k_t*)cinfo->j2k_handle, parameters, image);
|
|
|
|
break;
|
|
|
|
case CODEC_JP2:
|
|
|
|
jp2_setup_encoder((opj_jp2_t*)cinfo->jp2_handle, parameters, image);
|
|
|
|
break;
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_JPT:
|
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 13:02:27 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, char *index) {
|
2007-09-17 17:11:20 +02:00
|
|
|
if (index != NULL)
|
|
|
|
opj_event_msg((opj_common_ptr)cinfo, EVT_WARNING, "Set index to NULL when calling the opj_encode function.\n"
|
|
|
|
"To extract the index, use the opj_encode_with_info() function.\n"
|
|
|
|
"No index will be generated during this encoding\n");
|
|
|
|
return opj_encode_with_info(cinfo, cio, image, NULL);
|
|
|
|
}
|
|
|
|
|
2011-05-18 13:02:27 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_encode_with_info(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
|
2005-12-08 10:38:47 +01:00
|
|
|
if(cinfo && cio && image) {
|
|
|
|
switch(cinfo->codec_format) {
|
|
|
|
case CODEC_J2K:
|
2007-08-30 11:51:20 +02:00
|
|
|
return j2k_encode((opj_j2k_t*)cinfo->j2k_handle, cio, image, cstr_info);
|
2005-12-08 10:38:47 +01:00
|
|
|
case CODEC_JP2:
|
2011-09-09 16:49:08 +02:00
|
|
|
return opj_jp2_encode((opj_jp2_t*)cinfo->jp2_handle, cio, image, cstr_info);
|
2006-01-26 21:02:04 +01:00
|
|
|
case CODEC_JPT:
|
|
|
|
case CODEC_UNKNOWN:
|
|
|
|
default:
|
|
|
|
break;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
}
|
2011-05-18 13:02:27 +02:00
|
|
|
return OPJ_FALSE;
|
2005-12-02 14:34:15 +01:00
|
|
|
}
|
2007-09-07 17:01:55 +02:00
|
|
|
|
|
|
|
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
|
|
|
|
if (cstr_info) {
|
|
|
|
int tileno;
|
|
|
|
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
|
|
|
|
opj_tile_info_t *tile_info = &cstr_info->tile[tileno];
|
|
|
|
opj_free(tile_info->thresh);
|
|
|
|
opj_free(tile_info->packet);
|
|
|
|
opj_free(tile_info->tp);
|
2011-09-09 16:49:08 +02:00
|
|
|
opj_free(tile_info->marker);
|
2007-09-07 17:01:55 +02:00
|
|
|
}
|
|
|
|
opj_free(cstr_info->tile);
|
2007-11-05 14:05:07 +01:00
|
|
|
opj_free(cstr_info->marker);
|
2008-05-22 11:54:44 +02:00
|
|
|
opj_free(cstr_info->numdecompos);
|
2007-09-07 17:01:55 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2011-09-19 15:30:21 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
|
|
|
|
opj_codec_t *p_codec,
|
2011-10-12 16:42:21 +02:00
|
|
|
opj_image_t **p_image )
|
2011-09-19 15:30:21 +02:00
|
|
|
{
|
|
|
|
if (p_codec && p_cio) {
|
|
|
|
opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
|
|
|
|
opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio;
|
|
|
|
|
|
|
|
if(! l_info->is_decompressor) {
|
2011-09-21 18:37:45 +02:00
|
|
|
opj_event_msg_v2(l_info->m_event_mgr, EVT_ERROR, "Codec provided to the read_header function is not a decompressor handler.\n");
|
2011-09-19 15:30:21 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_info->m_codec_data.m_decompression.opj_read_header(
|
|
|
|
l_cio,
|
|
|
|
l_info->m_codec,
|
2011-10-05 18:27:16 +02:00
|
|
|
p_image,
|
2011-09-19 15:30:21 +02:00
|
|
|
l_info->m_event_mgr);
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
fprintf(stderr, "[ERROR] Input parameters of the read_header function are incorrect.\n");
|
2011-09-19 15:04:04 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-09-19 15:30:21 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
|
|
|
|
{
|
2011-09-21 18:37:45 +02:00
|
|
|
if (p_info) {
|
2011-09-19 15:04:04 +02:00
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
if (l_info->is_decompressor) {
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
|
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
else {
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
|
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
l_info->m_codec = 00;
|
|
|
|
opj_free(l_info);
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 18:01:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
|
|
|
|
*
|
|
|
|
* @param p_codec the jpeg2000 codec.
|
|
|
|
* @param p_start_x the left position of the rectangle to decode (in image coordinates).
|
|
|
|
* @param p_end_x the right position of the rectangle to decode (in image coordinates).
|
|
|
|
* @param p_start_y the up position of the rectangle to decode (in image coordinates).
|
|
|
|
* @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
|
|
|
|
*
|
|
|
|
* @return true if the area could be set.
|
|
|
|
*/
|
|
|
|
opj_bool OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
|
2011-10-21 18:38:08 +02:00
|
|
|
opj_image_t* p_image,
|
2011-09-19 18:01:49 +02:00
|
|
|
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
|
|
|
|
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (p_codec) {
|
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-10-21 18:38:08 +02:00
|
|
|
return l_info->m_codec_data.m_decompression.opj_set_decode_area( l_info->m_codec,
|
|
|
|
p_image,
|
|
|
|
p_start_x, p_start_y,
|
|
|
|
p_end_x, p_end_y,
|
|
|
|
l_info->m_event_mgr);
|
2011-09-19 18:01:49 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 18:05:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
|
|
|
|
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
|
|
|
*
|
|
|
|
* @param p_codec the jpeg2000 codec.
|
|
|
|
* @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
|
|
|
|
* @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
|
|
|
|
* of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
|
|
|
|
* as depicted in opj_write_tile.
|
|
|
|
* @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
|
|
|
|
* @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
|
|
|
|
* @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
|
|
|
|
* @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
|
|
|
|
* @param p_nb_comps pointer to a value that will hold the number of components in the tile.
|
|
|
|
* @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
|
|
|
|
* codestream is over at the time of the call, the value will be set to false. The user should then stop
|
|
|
|
* the decoding.
|
|
|
|
* @param p_stream the stream to decode.
|
|
|
|
* @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
|
|
|
|
* returning false may be the result of a shortage of memory or an internal error.
|
|
|
|
*/
|
|
|
|
opj_bool OPJ_CALLCONV opj_read_tile_header(
|
|
|
|
opj_codec_t *p_codec,
|
|
|
|
opj_stream_t * p_stream,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (p_codec && p_stream && p_data_size && p_tile_index) {
|
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_info->m_codec_data.m_decompression.opj_read_tile_header(
|
|
|
|
l_info->m_codec,
|
|
|
|
p_tile_index,
|
|
|
|
p_data_size,
|
|
|
|
p_tile_x0, p_tile_y0,
|
|
|
|
p_tile_x1, p_tile_y1,
|
|
|
|
p_nb_comps,
|
|
|
|
p_should_go_on,
|
|
|
|
l_cio,
|
|
|
|
l_info->m_event_mgr);
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 18:34:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
|
|
|
|
* The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
|
|
|
|
*
|
|
|
|
* @param p_codec the jpeg2000 codec.
|
|
|
|
* @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
|
|
|
|
* @param p_data pointer to a memory block that will hold the decoded data.
|
|
|
|
* @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
|
|
|
|
* @param p_stream the stream to decode.
|
|
|
|
*
|
|
|
|
* @return true if the data could be decoded.
|
|
|
|
*/
|
|
|
|
opj_bool OPJ_CALLCONV opj_decode_tile_data(
|
|
|
|
opj_codec_t *p_codec,
|
|
|
|
OPJ_UINT32 p_tile_index,
|
|
|
|
OPJ_BYTE * p_data,
|
|
|
|
OPJ_UINT32 p_data_size,
|
|
|
|
opj_stream_t *p_stream
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (p_codec && p_data && p_stream) {
|
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_info->m_codec_data.m_decompression.opj_decode_tile_data( l_info->m_codec,
|
|
|
|
p_tile_index,
|
|
|
|
p_data,
|
|
|
|
p_data_size,
|
|
|
|
l_cio,
|
|
|
|
l_info->m_event_mgr);
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-27 14:14:11 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void OPJ_CALLCONV opj_dump_codec( opj_codec_t *p_codec,
|
|
|
|
OPJ_INT32 info_flag,
|
|
|
|
FILE* output_stream)
|
|
|
|
{
|
|
|
|
if (p_codec) {
|
|
|
|
opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
|
|
|
|
|
|
|
|
l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream);
|
2011-10-07 19:11:12 +02:00
|
|
|
return;
|
2011-09-27 14:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
|
2011-10-07 19:11:12 +02:00
|
|
|
return;
|
2011-09-27 14:14:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
|
|
|
|
{
|
|
|
|
if (p_codec) {
|
|
|
|
opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
|
|
|
|
|
|
|
|
return l_codec->opj_get_codec_info(l_codec->m_codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-12 16:42:21 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t **cstr_info) {
|
|
|
|
if (cstr_info) {
|
|
|
|
|
|
|
|
if ((*cstr_info)->m_default_tile_info.tccp_info){
|
|
|
|
opj_free((*cstr_info)->m_default_tile_info.tccp_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*cstr_info)->tile_info){
|
|
|
|
/* FIXME not used for the moment*/
|
|
|
|
}
|
|
|
|
|
|
|
|
opj_free((*cstr_info));
|
|
|
|
(*cstr_info) = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-27 14:14:11 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
|
|
|
|
{
|
|
|
|
if (p_codec) {
|
|
|
|
opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
|
|
|
|
|
|
|
|
return l_codec->opj_get_codec_index(l_codec->m_codec);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-10-05 18:27:16 +02:00
|
|
|
|
2011-10-12 16:42:21 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
|
|
|
|
{
|
|
|
|
if (*p_cstr_index){
|
|
|
|
|
2011-10-21 18:36:04 +02:00
|
|
|
j2k_destroy_cstr_index(*p_cstr_index);
|
2011-10-12 16:42:21 +02:00
|
|
|
(*p_cstr_index) = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-05 18:27:16 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_info,
|
|
|
|
opj_stream_t *cio,
|
|
|
|
opj_image_t* p_image)
|
|
|
|
{
|
|
|
|
if (p_info && cio) {
|
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
|
|
|
|
opj_stream_private_t * l_cio = (opj_stream_private_t *) cio;
|
|
|
|
|
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_info->m_codec_data.m_decompression.opj_decode( l_info->m_codec,
|
|
|
|
l_cio,
|
|
|
|
p_image,
|
|
|
|
l_info->m_event_mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-11-08 14:21:17 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2011-10-05 18:27:16 +02:00
|
|
|
opj_bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio)
|
|
|
|
{
|
|
|
|
if (p_codec && p_cio) {
|
|
|
|
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
|
|
|
|
|
|
|
|
if (! l_info->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
return l_info->m_codec_data.m_decompression.opj_end_decompress( l_info->m_codec,
|
|
|
|
l_cio,
|
|
|
|
l_info->m_event_mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-11-08 14:21:17 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
opj_bool OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
|
|
|
|
opj_stream_t *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
OPJ_UINT32 tile_index)
|
|
|
|
{
|
|
|
|
if (p_codec && p_cio) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_cio;
|
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_get_decoded_tile( l_codec->m_codec,
|
|
|
|
l_stream,
|
|
|
|
p_image,
|
|
|
|
l_codec->m_event_mgr,
|
|
|
|
tile_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-11-17 15:21:11 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
opj_bool OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor)
|
|
|
|
{
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
|
|
|
|
if ( !l_codec ){
|
|
|
|
fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor(l_codec->m_codec, res_factor, l_codec->m_event_mgr);
|
|
|
|
|
|
|
|
return OPJ_TRUE;
|
|
|
|
}
|