2005-12-02 14:34:15 +01:00
|
|
|
/*
|
2014-04-03 17:30:57 +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
|
|
|
|
* party and contributor rights, including patent rights, and no such rights
|
|
|
|
* are granted under this license.
|
|
|
|
*
|
2011-01-29 15:15:26 +01:00
|
|
|
* Copyright (c) 2005, Herve Drolon, FreeImage Team
|
2014-04-03 17:30:57 +02:00
|
|
|
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
|
2012-11-15 16:22:29 +01:00
|
|
|
* Copyright (c) 2012, CS Systemes d'Information, France
|
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
|
|
|
|
2005-12-02 14:34:15 +01:00
|
|
|
#include "opj_includes.h"
|
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
2012-10-24 13:17:48 +02:00
|
|
|
/* Functions to set the message handlers */
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_info_handler( opj_codec_t * p_codec,
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_msg_callback p_callback,
|
|
|
|
void * p_user_data)
|
|
|
|
{
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
if(! l_codec){
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_codec->m_event_mgr.info_handler = p_callback;
|
|
|
|
l_codec->m_event_mgr.m_info_data = p_user_data;
|
|
|
|
|
|
|
|
return OPJ_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler( opj_codec_t * p_codec,
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_msg_callback p_callback,
|
|
|
|
void * p_user_data)
|
|
|
|
{
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
if (! l_codec) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_codec->m_event_mgr.warning_handler = p_callback;
|
|
|
|
l_codec->m_event_mgr.m_warning_data = p_user_data;
|
|
|
|
|
|
|
|
return OPJ_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_msg_callback p_callback,
|
|
|
|
void * p_user_data)
|
|
|
|
{
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
if (! l_codec) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_codec->m_event_mgr.error_handler = p_callback;
|
|
|
|
l_codec->m_event_mgr.m_error_data = p_user_data;
|
|
|
|
|
|
|
|
return OPJ_TRUE;
|
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
|
2012-10-15 17:47:56 +02:00
|
|
|
static 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);
|
2012-10-29 14:53:02 +01:00
|
|
|
return l_nb_read ? l_nb_read : (OPJ_SIZE_T)-1;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 17:47:56 +02:00
|
|
|
static 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);
|
2014-03-07 12:28:34 +01:00
|
|
|
file_length = (OPJ_OFF_T)OPJ_FTELL(p_file);
|
2011-11-30 17:55:25 +01:00
|
|
|
OPJ_FSEEK(p_file, 0, SEEK_SET);
|
2011-10-11 10:01:31 +02:00
|
|
|
|
2014-03-07 12:28:34 +01:00
|
|
|
return (OPJ_UINT64)file_length;
|
2011-10-11 10:01:31 +02:00
|
|
|
}
|
|
|
|
|
2012-10-15 17:47:56 +02:00
|
|
|
static 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);
|
|
|
|
}
|
|
|
|
|
2012-10-15 17:47:56 +02:00
|
|
|
static 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;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
static 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)) {
|
2012-05-14 19:17:53 +02:00
|
|
|
return OPJ_FALSE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-14 19:17:53 +02:00
|
|
|
return OPJ_TRUE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
|
|
|
|
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
|
2014-09-16 17:38:11 +02:00
|
|
|
DllMain(HINSTANCE 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) {
|
2012-10-01 12:39:39 +02:00
|
|
|
return OPJ_PACKAGE_VERSION;
|
2005-12-08 10:38:47 +01:00
|
|
|
}
|
|
|
|
|
2012-08-09 14:26:04 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
/* DECOMPRESSION FUNCTIONS*/
|
|
|
|
|
2012-08-09 13:51:07 +02:00
|
|
|
opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_codec_private_t *l_codec = 00;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
|
|
|
|
if (!l_codec){
|
2011-09-19 15:04:04 +02:00
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->is_decompressor = 1;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2011-09-19 15:36:07 +02:00
|
|
|
switch (p_format) {
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_J2K:
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) j2k_dump;
|
2011-09-27 14:14:11 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) j2k_get_cstr_info;
|
2011-09-27 14:14:11 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;
|
2011-09-27 14:14:11 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_decode =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2011-10-05 18:27:16 +02:00
|
|
|
struct opj_stream_private *,
|
2012-08-09 17:16:33 +02:00
|
|
|
opj_image_t*, struct opj_event_mgr * )) opj_j2k_decode;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_end_decompress =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2011-10-05 18:27:16 +02:00
|
|
|
struct opj_stream_private *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr *)) opj_j2k_end_decompress;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_read_header =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( struct opj_stream_private *,
|
2011-09-19 18:01:49 +02:00
|
|
|
void *,
|
2011-10-12 16:42:21 +02:00
|
|
|
opj_image_t **,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr * )) opj_j2k_read_header;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_destroy =
|
2012-08-16 13:51:34 +02:00
|
|
|
(void (*) (void *))opj_j2k_destroy;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_setup_decoder =
|
2012-08-09 17:08:33 +02:00
|
|
|
(void (*) (void * , opj_dparameters_t * )) opj_j2k_setup_decoder;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_read_tile_header =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2011-09-19 18:01:49 +02:00
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_INT32*, OPJ_INT32*,
|
|
|
|
OPJ_INT32*, OPJ_INT32*,
|
|
|
|
OPJ_UINT32*,
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL*,
|
2011-09-19 18:01:49 +02:00
|
|
|
struct opj_stream_private *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr * )) opj_j2k_read_tile_header;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_UINT32,
|
|
|
|
OPJ_BYTE*,
|
|
|
|
OPJ_UINT32,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr *)) opj_j2k_decode_tile;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_set_decode_area =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
opj_image_t*,
|
|
|
|
OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32,
|
|
|
|
struct opj_event_mgr *)) opj_j2k_set_decode_area;
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_get_decoded_tile =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *p_codec,
|
2012-08-16 13:51:34 +02:00
|
|
|
opj_stream_private_t *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager,
|
|
|
|
OPJ_UINT32 tile_index)) opj_j2k_get_tile;
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void * p_codec,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_UINT32 res_factor,
|
|
|
|
struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor;
|
2011-11-17 15:21:11 +01:00
|
|
|
|
2012-08-09 17:00:50 +02:00
|
|
|
l_codec->m_codec = opj_j2k_create_decompress();
|
2011-09-19 15:36:07 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
if (! l_codec->m_codec) {
|
|
|
|
opj_free(l_codec);
|
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;
|
|
|
|
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_JP2:
|
2011-09-19 15:04:04 +02:00
|
|
|
/* get a JP2 decoder handle */
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) jp2_dump;
|
2011-10-07 19:31:35 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) jp2_get_cstr_info;
|
2011-10-07 19:31:35 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) jp2_get_cstr_index;
|
2011-10-07 19:31:35 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_decode =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2011-10-05 18:27:16 +02:00
|
|
|
struct opj_stream_private *,
|
|
|
|
opj_image_t*,
|
2012-08-09 16:46:11 +02:00
|
|
|
struct opj_event_mgr * )) opj_jp2_decode;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-08-16 13:51:34 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_end_decompress =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr *)) opj_jp2_end_decompress;
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_read_header =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( struct opj_stream_private *,
|
2012-08-16 13:51:34 +02:00
|
|
|
void *,
|
|
|
|
opj_image_t **,
|
|
|
|
struct opj_event_mgr * )) opj_jp2_read_header;
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_read_tile_header =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_UINT32*,
|
|
|
|
OPJ_INT32*,
|
|
|
|
OPJ_INT32*,
|
|
|
|
OPJ_INT32 * ,
|
|
|
|
OPJ_INT32 * ,
|
|
|
|
OPJ_UINT32 * ,
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr * )) opj_jp2_read_tile_header;
|
|
|
|
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,
|
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_event_mgr * )) opj_jp2_decode_tile;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-08-13 11:24:15 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))opj_jp2_destroy;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-08-16 13:51:34 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_setup_decoder =
|
|
|
|
(void (*) (void * ,opj_dparameters_t * )) opj_jp2_setup_decoder;
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-08-16 13:51:34 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_set_decode_area =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *,
|
2012-08-16 13:51:34 +02:00
|
|
|
opj_image_t*,
|
|
|
|
OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32,
|
|
|
|
struct opj_event_mgr * )) opj_jp2_set_decode_area;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-08-16 13:51:34 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_get_decoded_tile =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void *p_codec,
|
2012-08-16 13:51:34 +02:00
|
|
|
opj_stream_private_t *p_cio,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
struct opj_event_mgr * p_manager,
|
|
|
|
OPJ_UINT32 tile_index)) opj_jp2_get_tile;
|
2011-11-08 14:21:17 +01:00
|
|
|
|
2012-08-16 13:51:34 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor =
|
2012-11-15 14:13:36 +01:00
|
|
|
(OPJ_BOOL (*) ( void * p_codec,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_UINT32 res_factor,
|
|
|
|
opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor;
|
2011-11-17 15:21:11 +01:00
|
|
|
|
2012-08-13 11:24:15 +02:00
|
|
|
l_codec->m_codec = opj_jp2_create(OPJ_TRUE);
|
2011-09-19 15:36:07 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
if (! l_codec->m_codec) {
|
|
|
|
opj_free(l_codec);
|
2011-09-19 15:04:04 +02:00
|
|
|
return 00;
|
|
|
|
}
|
2011-09-19 15:36:07 +02:00
|
|
|
|
2011-09-19 15:04:04 +02:00
|
|
|
break;
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_UNKNOWN:
|
|
|
|
case OPJ_CODEC_JPT:
|
2011-09-19 15:04:04 +02:00
|
|
|
default:
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_free(l_codec);
|
2011-09-19 15:04:04 +02:00
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
2012-08-09 16:00:31 +02:00
|
|
|
opj_set_default_event_handler(&(l_codec->m_event_mgr));
|
2012-05-02 09:01:13 +02:00
|
|
|
return (opj_codec_t*) l_codec;
|
2011-09-19 15:04:04 +02: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;
|
|
|
|
|
|
|
|
parameters->decod_format = -1;
|
|
|
|
parameters->cod_format = -1;
|
2012-03-02 15:19:44 +01:00
|
|
|
parameters->flags = 0;
|
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
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
|
2012-08-09 14:11:24 +02:00
|
|
|
opj_dparameters_t *parameters
|
|
|
|
)
|
2011-09-19 15:04:04 +02:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
if (p_codec && parameters) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
if (! l_codec->is_decompressor) {
|
2012-10-25 15:49:20 +02:00
|
|
|
opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR,
|
2012-08-16 13:51:34 +02:00
|
|
|
"Codec provided to the opj_setup_decoder function is not a decompressor handler.\n");
|
2012-05-02 09:01:13 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 15:18:19 +02:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_decompression.opj_setup_decoder(l_codec->m_codec,
|
|
|
|
parameters);
|
|
|
|
return OPJ_TRUE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2012-05-02 09:01:13 +02:00
|
|
|
return OPJ_FALSE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_codec_t *p_codec,
|
|
|
|
opj_image_t **p_image )
|
|
|
|
{
|
|
|
|
if (p_codec && p_stream) {
|
|
|
|
opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
|
|
|
|
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
|
|
|
|
|
|
|
|
if(! l_codec->is_decompressor) {
|
2012-10-25 15:49:20 +02:00
|
|
|
opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR,
|
2012-08-16 13:51:34 +02:00
|
|
|
"Codec provided to the opj_read_header function is not a decompressor handler.\n");
|
2012-08-09 14:51:16 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_read_header( l_stream,
|
|
|
|
l_codec->m_codec,
|
|
|
|
p_image,
|
|
|
|
&(l_codec->m_event_mgr) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_decode( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_stream_t *p_stream,
|
|
|
|
opj_image_t* p_image)
|
|
|
|
{
|
|
|
|
if (p_codec && p_stream) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_decode(l_codec->m_codec,
|
|
|
|
l_stream,
|
|
|
|
p_image,
|
|
|
|
&(l_codec->m_event_mgr) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_decode_area( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_image_t* p_image,
|
|
|
|
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_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_set_decode_area( l_codec->m_codec,
|
|
|
|
p_image,
|
|
|
|
p_start_x, p_start_y,
|
|
|
|
p_end_x, p_end_y,
|
|
|
|
&(l_codec->m_event_mgr) );
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_read_tile_header( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
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,
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL * p_should_go_on)
|
2012-08-09 14:51:16 +02:00
|
|
|
{
|
|
|
|
if (p_codec && p_stream && p_data_size && p_tile_index) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_read_tile_header( l_codec->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_stream,
|
|
|
|
&(l_codec->m_event_mgr));
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
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_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_decode_tile_data( l_codec->m_codec,
|
|
|
|
p_tile_index,
|
|
|
|
p_data,
|
|
|
|
p_data_size,
|
|
|
|
l_stream,
|
|
|
|
&(l_codec->m_event_mgr) );
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_stream_t *p_stream,
|
|
|
|
opj_image_t *p_image,
|
|
|
|
OPJ_UINT32 tile_index)
|
|
|
|
{
|
|
|
|
if (p_codec && p_stream) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:26:04 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
|
|
|
/* COMPRESSION FUNCTIONS*/
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-08-09 14:28:51 +02:00
|
|
|
opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
|
2012-03-15 11:23:20 +01:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_codec_private_t *l_codec = 00;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
|
|
|
|
if (!l_codec) {
|
2012-03-15 11:23:20 +01:00
|
|
|
return 00;
|
|
|
|
}
|
2012-05-02 09:01:13 +02:00
|
|
|
|
|
|
|
l_codec->is_decompressor = 0;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
|
|
|
switch(p_format) {
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_J2K:
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
2012-11-16 09:29:43 +01:00
|
|
|
struct opj_event_mgr * )) opj_j2k_encode;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL (*) ( void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr *)) opj_j2k_end_compress;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_image * ,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr *)) opj_j2k_start_compress;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
OPJ_UINT32,
|
|
|
|
OPJ_BYTE*,
|
|
|
|
OPJ_UINT32,
|
|
|
|
struct opj_stream_private *,
|
2012-08-16 13:51:34 +02:00
|
|
|
struct opj_event_mgr *) ) opj_j2k_write_tile;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-10-25 12:41:55 +02:00
|
|
|
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_j2k_destroy;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-10-25 12:41:55 +02:00
|
|
|
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_cparameters_t *,
|
|
|
|
struct opj_image *,
|
2012-08-16 15:37:34 +02:00
|
|
|
struct opj_event_mgr * )) opj_j2k_setup_encoder;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-08-16 15:46:43 +02:00
|
|
|
l_codec->m_codec = opj_j2k_create_compress();
|
2012-05-02 09:01:13 +02:00
|
|
|
if (! l_codec->m_codec) {
|
|
|
|
opj_free(l_codec);
|
2012-03-15 11:23:20 +01:00
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_JP2:
|
2012-03-15 11:23:20 +01:00
|
|
|
/* get a JP2 decoder handle */
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
2012-08-13 11:24:15 +02:00
|
|
|
struct opj_event_mgr * )) opj_jp2_encode;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL (*) ( void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
2012-08-13 11:24:15 +02:00
|
|
|
struct opj_event_mgr *)) opj_jp2_end_compress;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
struct opj_stream_private *,
|
|
|
|
struct opj_image * ,
|
2012-08-13 11:24:15 +02:00
|
|
|
struct opj_event_mgr *)) opj_jp2_start_compress;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL (*) (void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
OPJ_UINT32,
|
|
|
|
OPJ_BYTE*,
|
|
|
|
OPJ_UINT32,
|
|
|
|
struct opj_stream_private *,
|
2012-08-13 11:24:15 +02:00
|
|
|
struct opj_event_mgr *)) opj_jp2_write_tile;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-10-25 12:41:55 +02:00
|
|
|
l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-10-25 12:41:55 +02:00
|
|
|
l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_cparameters_t *,
|
|
|
|
struct opj_image *,
|
2012-08-13 11:24:15 +02:00
|
|
|
struct opj_event_mgr * )) opj_jp2_setup_encoder;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
2012-08-13 11:24:15 +02:00
|
|
|
l_codec->m_codec = opj_jp2_create(OPJ_FALSE);
|
2012-05-02 09:01:13 +02:00
|
|
|
if (! l_codec->m_codec) {
|
|
|
|
opj_free(l_codec);
|
2012-03-15 11:23:20 +01:00
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2012-11-15 13:58:32 +01:00
|
|
|
case OPJ_CODEC_UNKNOWN:
|
|
|
|
case OPJ_CODEC_JPT:
|
2012-03-15 11:23:20 +01:00
|
|
|
default:
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_free(l_codec);
|
2012-03-15 11:23:20 +01:00
|
|
|
return 00;
|
|
|
|
}
|
|
|
|
|
2012-08-09 16:00:31 +02:00
|
|
|
opj_set_default_event_handler(&(l_codec->m_event_mgr));
|
2012-05-02 09:01:13 +02:00
|
|
|
return (opj_codec_t*) l_codec;
|
2012-03-15 11:23:20 +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 */
|
2014-04-17 11:31:37 +02:00
|
|
|
parameters->cp_cinema = OPJ_OFF; /* DEPRECATED */
|
|
|
|
parameters->rsiz = OPJ_PROFILE_NONE;
|
2007-04-04 15:40:32 +02:00
|
|
|
parameters->max_comp_size = 0;
|
2005-12-08 10:38:47 +01:00
|
|
|
parameters->numresolution = 6;
|
2014-04-17 11:31:37 +02:00
|
|
|
parameters->cp_rsiz = OPJ_STD_RSIZ; /* DEPRECATED */
|
2005-12-08 10:38:47 +01:00
|
|
|
parameters->cblockw_init = 64;
|
|
|
|
parameters->cblockh_init = 64;
|
2012-11-15 13:58:32 +01:00
|
|
|
parameters->prog_order = OPJ_LRCP;
|
2005-12-08 10:38:47 +01:00
|
|
|
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;
|
2012-10-29 11:12:03 +01: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
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
|
2012-08-09 14:35:13 +02:00
|
|
|
opj_cparameters_t *parameters,
|
|
|
|
opj_image_t *p_image)
|
2012-03-15 11:23:20 +01:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
if (p_codec && parameters && p_image) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
2012-05-02 09:01:13 +02:00
|
|
|
l_codec->m_codec_data.m_compression.opj_setup_encoder( l_codec->m_codec,
|
|
|
|
parameters,
|
|
|
|
p_image,
|
|
|
|
&(l_codec->m_event_mgr) );
|
2012-03-15 11:23:20 +01:00
|
|
|
return OPJ_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_start_compress ( opj_codec_t *p_codec,
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_image_t * p_image,
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_stream_t *p_stream)
|
2012-03-15 11:23:20 +01:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
if (p_codec && p_stream) {
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
2012-05-02 09:01:13 +02:00
|
|
|
return l_codec->m_codec_data.m_compression.opj_start_compress( l_codec->m_codec,
|
|
|
|
l_stream,
|
|
|
|
p_image,
|
|
|
|
&(l_codec->m_event_mgr));
|
2012-03-15 11:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream)
|
2012-03-15 11:23:20 +01:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
if (p_info && p_stream) {
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_info;
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
2013-09-26 11:28:47 +02:00
|
|
|
return l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec,
|
2012-05-02 09:01:13 +02:00
|
|
|
l_stream,
|
|
|
|
&(l_codec->m_event_mgr));
|
2012-03-15 11:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPJ_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_stream_t *p_stream)
|
2012-03-15 11:23:20 +01:00
|
|
|
{
|
2012-05-02 09:01:13 +02:00
|
|
|
if (p_codec && p_stream) {
|
2012-03-15 11:23:20 +01:00
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
2012-03-15 11:23:20 +01:00
|
|
|
|
|
|
|
if (! l_codec->is_decompressor) {
|
2012-05-02 09:01:13 +02:00
|
|
|
return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec,
|
|
|
|
l_stream,
|
|
|
|
&(l_codec->m_event_mgr));
|
2012-03-15 11:23:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return OPJ_FALSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_stream_t *p_stream)
|
|
|
|
{
|
|
|
|
if (p_codec && p_stream) {
|
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
2007-09-17 17:11:20 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
if (! l_codec->is_decompressor) {
|
|
|
|
return OPJ_FALSE;
|
2007-09-07 17:01:55 +02:00
|
|
|
}
|
2012-08-09 14:51:16 +02:00
|
|
|
|
|
|
|
return l_codec->m_codec_data.m_decompression.opj_end_decompress(l_codec->m_codec,
|
|
|
|
l_stream,
|
|
|
|
&(l_codec->m_event_mgr) );
|
2007-09-07 17:01:55 +02:00
|
|
|
}
|
2012-08-09 14:51:16 +02:00
|
|
|
|
|
|
|
return OPJ_FALSE;
|
2007-09-07 17:01:55 +02:00
|
|
|
}
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
|
2012-08-16 13:51:34 +02:00
|
|
|
OPJ_FLOAT32 * pEncodingMatrix,
|
|
|
|
OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp)
|
2011-09-19 15:30:21 +02:00
|
|
|
{
|
2014-03-03 17:11:41 +01:00
|
|
|
OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
|
|
|
|
OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32);
|
2012-08-09 14:51:16 +02:00
|
|
|
OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
|
2011-09-19 15:04:04 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
/* add MCT capability */
|
2014-04-17 11:31:37 +02:00
|
|
|
if (OPJ_IS_PART2(parameters->rsiz)) {
|
|
|
|
parameters->rsiz |= OPJ_EXTENSION_MCT;
|
|
|
|
} else {
|
|
|
|
parameters->rsiz = ((OPJ_PROFILE_PART2) | (OPJ_EXTENSION_MCT));
|
|
|
|
}
|
2012-08-09 14:51:16 +02:00
|
|
|
parameters->irreversible = 1;
|
2011-09-19 15:30:21 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
/* use array based MCT */
|
|
|
|
parameters->tcp_mct = 2;
|
|
|
|
parameters->mct_data = opj_malloc(l_mct_total_size);
|
|
|
|
if (! parameters->mct_data) {
|
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-21 18:37:45 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
memcpy(parameters->mct_data,pEncodingMatrix,l_matrix_size);
|
|
|
|
memcpy(((OPJ_BYTE *) parameters->mct_data) + l_matrix_size,p_dc_shift,l_dc_shift_size);
|
2011-09-21 18:37:45 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
return OPJ_TRUE;
|
2011-09-19 15:04:04 +02:00
|
|
|
}
|
2011-09-19 18:01:49 +02:00
|
|
|
|
2012-11-15 14:13:36 +01:00
|
|
|
OPJ_BOOL OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
|
2012-08-09 14:51:16 +02:00
|
|
|
OPJ_UINT32 p_tile_index,
|
|
|
|
OPJ_BYTE * p_data,
|
|
|
|
OPJ_UINT32 p_data_size,
|
|
|
|
opj_stream_t *p_stream )
|
2011-09-19 18:01:49 +02:00
|
|
|
{
|
2012-08-09 14:51:16 +02:00
|
|
|
if (p_codec && p_stream && p_data) {
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2012-08-09 14:51:16 +02:00
|
|
|
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
|
|
|
|
|
|
|
|
if (l_codec->is_decompressor) {
|
2011-09-19 18:01:49 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
return l_codec->m_codec_data.m_compression.opj_write_tile( l_codec->m_codec,
|
|
|
|
p_tile_index,
|
|
|
|
p_data,
|
|
|
|
p_data_size,
|
|
|
|
l_stream,
|
|
|
|
&(l_codec->m_event_mgr) );
|
2011-09-19 18:01:49 +02:00
|
|
|
}
|
2012-08-09 14:51:16 +02:00
|
|
|
|
2011-09-19 18:01:49 +02:00
|
|
|
return OPJ_FALSE;
|
|
|
|
}
|
2011-09-19 18:05:43 +02:00
|
|
|
|
2012-08-09 15:22:25 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
2011-09-19 18:05:43 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
|
2011-09-19 18:34:44 +02:00
|
|
|
{
|
2012-08-09 14:51:16 +02:00
|
|
|
if (p_codec) {
|
2012-05-02 09:01:13 +02:00
|
|
|
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
|
2011-09-19 18:34:44 +02:00
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
if (l_codec->is_decompressor) {
|
|
|
|
l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec);
|
2011-09-19 18:34:44 +02:00
|
|
|
}
|
|
|
|
|
2012-08-09 14:51:16 +02:00
|
|
|
l_codec->m_codec = 00;
|
|
|
|
opj_free(l_codec);
|
2011-09-19 18:34:44 +02:00
|
|
|
}
|
|
|
|
}
|
2011-09-27 14:14:11 +02:00
|
|
|
|
2012-08-09 15:22:25 +02:00
|
|
|
/* ---------------------------------------------------------------------- */
|
2012-08-09 14:51:16 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-09 14:56:43 +02:00
|
|
|
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) {
|
2011-10-12 16:42:21 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 09:46:11 +02:00
|
|
|
opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream)
|
2014-02-25 17:49:26 +01:00
|
|
|
{
|
2014-04-23 09:46:11 +02:00
|
|
|
return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream);
|
2014-02-25 17:49:26 +01:00
|
|
|
}
|
|
|
|
|
2014-04-23 09:46:11 +02:00
|
|
|
opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
|
2013-02-16 18:20:55 +01:00
|
|
|
const char *fname,
|
|
|
|
OPJ_SIZE_T p_size,
|
|
|
|
OPJ_BOOL p_is_read_stream)
|
|
|
|
{
|
|
|
|
opj_stream_t* l_stream = 00;
|
|
|
|
FILE *p_file;
|
|
|
|
const char *mode;
|
|
|
|
|
|
|
|
if (! fname) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(p_is_read_stream) mode = "rb"; else mode = "wb";
|
|
|
|
|
|
|
|
p_file = fopen(fname, mode);
|
|
|
|
|
|
|
|
if (! p_file) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_stream = opj_stream_create(p_size,p_is_read_stream);
|
|
|
|
if (! l_stream) {
|
|
|
|
fclose(p_file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-23 09:46:11 +02:00
|
|
|
opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose);
|
2013-02-16 18:20:55 +01:00
|
|
|
opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file));
|
|
|
|
opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file);
|
|
|
|
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);
|
2012-08-09 14:40:22 +02:00
|
|
|
|
2013-02-16 18:20:55 +01:00
|
|
|
return l_stream;
|
2012-08-30 18:56:31 +02:00
|
|
|
}
|