* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2010-2011, Kaori Hagihara
- * Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
+ * Copyright (c) 2011-2012, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
*/
#include "opj_includes.h"
-#ifdef HAVE_INTTYPES_H
-#include <inttypes.h> /* PRIi64 */
-#endif
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
/*@{*/
/**
* The read header procedure.
*/
-opj_bool j2k_read_header_procedure(
- opj_j2k_v2_t *p_j2k,
- struct opj_stream_private *p_stream,
- struct opj_event_mgr * p_manager);
+static opj_bool j2k_read_header_procedure( opj_j2k_v2_t *p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager);
/**
* The default encoding validation procedure without any extension.
*
* @param p_j2k the jpeg2000 codec to validate.
- * @param p_stream the input stream to validate.
+ * @param p_stream the input stream to validate.
* @param p_manager the user event manager.
*
* @return true if the parameters are correct.
*/
-opj_bool j2k_encoding_validation ( opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_encoding_validation ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* The default decoding validation procedure without any extension.
*
* @return true if the parameters are correct.
*/
-opj_bool j2k_decoding_validation (
- opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager
- );
+static opj_bool j2k_decoding_validation ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters
*
* @return true if the parameters are correct.
*/
-opj_bool j2k_mct_validation ( opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_mct_validation (opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Builds the tcd decoder to use to decode tile.
*/
-opj_bool j2k_build_decoder (opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_build_decoder ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Builds the tcd encoder to use to encode tile.
*/
-opj_bool j2k_build_encoder (opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_build_encoder ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Creates a tile-coder decoder.
*
- * @param p_stream the stream to write data to.
+ * @param p_stream the stream to write data to.
* @param p_j2k J2K codec.
- * @param p_manager the user event manager.
+ * @param p_manager the user event manager.
*/
static opj_bool j2k_create_tcd( opj_j2k_v2_t *p_j2k,
struct opj_stream_private *p_stream,
* Excutes the given procedures on the given codec.
*
* @param p_procedure_list the list of procedures to execute
- * @param p_j2k the jpeg2000 codec to execute the procedures on.
- * @param p_stream the stream to execute the procedures on.
+ * @param p_j2k the jpeg2000 codec to execute the procedures on.
+ * @param p_stream the stream to execute the procedures on.
* @param p_manager the user manager.
*
* @return true if all the procedures were successfully executed.
*/
-static opj_bool j2k_exec (
- opj_j2k_v2_t * p_j2k,
- opj_procedure_list_t * p_procedure_list,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager
- );
+static opj_bool j2k_exec ( opj_j2k_v2_t * p_j2k,
+ opj_procedure_list_t * p_procedure_list,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager);
/**
* Updates the rates of the tcp.
* @param p_manager the user event manager.
*/
static opj_bool j2k_update_rates( opj_j2k_v2_t *p_j2k,
- struct opj_stream_private *p_stream,
- struct opj_event_mgr * p_manager );
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Copies the decoding tile parameters onto all the tile parameters.
* Creates also the tile decoder.
*/
-opj_bool j2k_copy_default_tcp_and_create_tcd ( opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_copy_default_tcp_and_create_tcd ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Destroys the memory associated with the decoding of headers.
*/
-opj_bool j2k_destroy_header_memory (opj_j2k_v2_t * p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager );
+static opj_bool j2k_destroy_header_memory ( opj_j2k_v2_t * p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Reads the lookup table containing all the marker, status and action, and returns the handler associated
* @param p_header_size the size of the data contained in the COM marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_SPCod_SPCoc(
- opj_j2k_v2_t *p_j2k,
- OPJ_UINT32 compno,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 * p_header_size,
- struct opj_event_mgr * p_manager
- );
+static opj_bool j2k_read_SPCod_SPCoc( opj_j2k_v2_t *p_j2k,
+ OPJ_UINT32 compno,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 * p_header_size,
+ opj_event_mgr_t * p_manager );
/**
* Gets the size taken by writing SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC.
OPJ_UINT32 p_comp_no,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_header_size,
- struct opj_event_mgr * p_manager
- );
+ opj_event_mgr_t * p_manager);
/**
* Updates the Tile Length Marker.
* @param p_manager the user event manager.
*
*/
-static opj_bool j2k_read_SQcd_SQcc(
- opj_j2k_v2_t *p_j2k,
- OPJ_UINT32 compno,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 * p_header_size,
- struct opj_event_mgr * p_manager
- );
+static opj_bool j2k_read_SQcd_SQcc( opj_j2k_v2_t *p_j2k,
+ OPJ_UINT32 compno,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 * p_header_size,
+ opj_event_mgr_t * p_manager );
/**
* Copies the tile component parameters of all the component from the first tile component.
*
* @param p_j2k the J2k codec.
*/
-static void j2k_copy_tile_component_parameters(
- opj_j2k_v2_t *p_j2k
- );
+static void j2k_copy_tile_component_parameters( opj_j2k_v2_t *p_j2k );
/**
* Copies the tile quantization parameters of all the component from the first tile component.
*
* @param p_j2k the J2k codec.
*/
-static void j2k_copy_tile_quantization_parameters(
- opj_j2k_v2_t *p_j2k
- );
+static void j2k_copy_tile_quantization_parameters( opj_j2k_v2_t *p_j2k );
/**
* Reads the tiles.
*/
-opj_bool j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
- opj_stream_private_t *p_stream,
- opj_event_mgr_t * p_manager);
+static opj_bool j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager);
static opj_bool j2k_pre_write_tile ( opj_j2k_v2_t * p_j2k,
* Sets up the procedures to do on writing header.
* Developers wanting to extend the library can add their own writing procedures.
*/
-void j2k_setup_header_writting (opj_j2k_v2_t *p_j2k);
+static void j2k_setup_header_writting (opj_j2k_v2_t *p_j2k);
static opj_bool j2k_write_first_tile_part( opj_j2k_v2_t *p_j2k,
OPJ_BYTE * p_data,
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager );
-/**
-Read the SOC marker (Start of Codestream)
-@param j2k J2K handle
-*/
-static void j2k_read_soc(opj_j2k_t *j2k);
-
/**
* Reads a SOC marker (Start of Codestream)
* @param p_header_data the data contained in the SOC box.
* @param p_header_size the size of the data contained in the SOC marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_soc_v2(
+static opj_bool opj_j2k_read_soc(
opj_j2k_v2_t *p_j2k,
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager );
-/**
-Read the SIZ marker (image and tile size)
-@param j2k J2K handle
-*/
-static void j2k_read_siz(opj_j2k_t *j2k);
-
/**
* Reads a SIZ marker (image and tile size)
* @param p_header_data the data contained in the SIZ box.
* @param p_header_size the size of the data contained in the SIZ marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_siz_v2 (
- opj_j2k_v2_t *p_j2k,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 p_header_size,
- struct opj_event_mgr * p_manager
- );
+static opj_bool opj_j2k_read_siz(opj_j2k_v2_t *p_j2k,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 p_header_size,
+ opj_event_mgr_t * p_manager);
/**
Write the COM marker (comment)
@param j2k J2K handle
*/
static void j2k_write_com(opj_j2k_t *j2k);
+
+/**
+ * Writes the COM marker (comment)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+static opj_bool j2k_write_com_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager );
+
/**
Read the COM marker (comment)
@param j2k J2K handle
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager );
-/**
-Read the COD marker (coding style default)
-@param j2k J2K handle
-*/
-static void j2k_read_cod(opj_j2k_t *j2k);
-
/**
* Reads a COD marker (Coding Styke defaults)
* @param p_header_data the data contained in the COD box.
* @param p_header_size the size of the data contained in the COD marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_cod_v2 (
+static opj_bool opj_j2k_read_cod (
opj_j2k_v2_t *p_j2k,
OPJ_BYTE * p_header_data,
OPJ_UINT32 p_header_size,
*/
static void j2k_write_poc(opj_j2k_t *j2k);
+/**
+ * Writes the POC marker (Progression Order Change)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+static opj_bool j2k_write_poc_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager );
+
/**
* Writes the POC marker (Progression Order Change)
*
@param j2k J2K handle
*/
static void j2k_write_tlm(opj_j2k_t *j2k);
+
/**
-Write the SOT marker (start of tile-part)
-@param j2k J2K handle
+ * Writes the TLM marker (Tile Length Marker)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
*/
-static void j2k_write_sot(opj_j2k_t *j2k);
+static opj_bool j2k_write_tlm_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager );
+
/**
-Read the SOT marker (start of tile-part)
+Write the SOT marker (start of tile-part)
@param j2k J2K handle
*/
-static void j2k_read_sot(opj_j2k_t *j2k);
+static void j2k_write_sot(opj_j2k_t *j2k);
/**
* Writes the SOT marker (Start of tile-part)
* @param p_header_size the size of the data contained in the PPT marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_sot_v2 (
- opj_j2k_v2_t *p_j2k,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 p_header_size,
- struct opj_event_mgr * p_manager
- );
+static opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 p_header_size,
+ opj_event_mgr_t * p_manager );
+
/**
Write the SOD marker (start of data)
@param j2k J2K handle
const struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager );
-/**
-Read the SOD marker (start of data)
-@param j2k J2K handle
-*/
-static void j2k_read_sod(opj_j2k_t *j2k);
-
/**
* Reads a SOD marker (Start Of Data)
*
* @param p_header_size the size of the data contained in the SOD marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_sod_v2 (
- opj_j2k_v2_t *p_j2k,
- struct opj_stream_private *p_stream,
- struct opj_event_mgr * p_manager
- );
+static opj_bool opj_j2k_read_sod( opj_j2k_v2_t *p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager );
/**
* Updates the Tile Length Marker.
struct opj_event_mgr * p_manager
) ;
+/**
+ * Writes the EOC marker (End of Codestream)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+static opj_bool j2k_write_eoc_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager );
+
/**
Write the EOC marker (end of codestream)
@param j2k J2K handle
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager );
+/**
+ * Checks the progression order changes values. Tells of the poc given as input are valid.
+ * A nice message is outputted at errors.
+ *
+ * @param p_pocs the progression order changes.
+ * @param p_nb_pocs the number of progression order changes.
+ * @param p_nb_resolutions the number of resolutions.
+ * @param numcomps the number of components
+ * @param numlayers the number of layers.
+ *
+ * @return true if the pocs are valid.
+ */
+static opj_bool j2k_check_poc_val( const opj_poc_t *p_pocs,
+ OPJ_UINT32 p_nb_pocs,
+ OPJ_UINT32 p_nb_resolutions,
+ OPJ_UINT32 numcomps,
+ OPJ_UINT32 numlayers,
+ opj_event_mgr_t * p_manager);
+
/**
* Gets the number of tile parts used for the given change of progression (if any) and the given tile.
*
{J2K_MS_MCC, J2K_DEC_STATE_MH | J2K_DEC_STATE_TPH, j2k_read_mcc},
{J2K_MS_MCO, J2K_DEC_STATE_MH | J2K_DEC_STATE_TPH, j2k_read_mco},
#endif
- {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot_v2},
+ {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot},
{J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod_v2},
{J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc_v2},
{J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn_v2},
{J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd_v2},
{J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcc_v2},
{J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_poc_v2},
- {J2K_MS_SIZ, J2K_STATE_MHSIZ , j2k_read_siz_v2},
+ {J2K_MS_SIZ, J2K_STATE_MHSIZ , opj_j2k_read_siz},
{J2K_MS_TLM, J2K_STATE_MH, j2k_read_tlm_v2},
{J2K_MS_PLM, J2K_STATE_MH, j2k_read_plm_v2},
{J2K_MS_PLT, J2K_STATE_TPH, j2k_read_plt_v2},
return po->str_prog;
}
+/**
+ * Checks the progression order changes values. Tells if the poc given as input are valid.
+ *
+ * @param p_pocs the progression order changes.
+ * @param p_nb_pocs the number of progression order changes.
+ * @param p_nb_resolutions the number of resolutions.
+ * @param numcomps the number of components
+ * @param numlayers the number of layers.
+ * @param p_manager the user event manager.
+ *
+ * @return true if the pocs are valid.
+ */
+opj_bool j2k_check_poc_val( const opj_poc_t *p_pocs,
+ OPJ_UINT32 p_nb_pocs,
+ OPJ_UINT32 p_nb_resolutions,
+ OPJ_UINT32 p_num_comps,
+ OPJ_UINT32 p_num_layers,
+ opj_event_mgr_t * p_manager)
+{
+ OPJ_UINT32* packet_array;
+ OPJ_UINT32 index , resno, compno, layno;
+ OPJ_UINT32 i;
+ OPJ_UINT32 step_c = 1;
+ OPJ_UINT32 step_r = p_num_comps * step_c;
+ OPJ_UINT32 step_l = p_nb_resolutions * step_r;
+ opj_bool loss = OPJ_FALSE;
+ OPJ_UINT32 layno0 = 0;
+
+ packet_array = (OPJ_UINT32*) opj_calloc(step_l * p_num_layers, sizeof(OPJ_UINT32));
+ if (packet_array == 00) {
+ opj_event_msg_v2(p_manager , EVT_ERROR, "Not enough memory for checking the poc values.\n");
+ return OPJ_FALSE;
+ }
+ memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32));
+
+ if (p_nb_pocs == 0) {
+ return OPJ_TRUE;
+ }
+
+ index = step_r * p_pocs->resno0;
+ // take each resolution for each poc
+ for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno)
+ {
+ OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c;
+
+ // take each comp of each resolution for each poc
+ for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) {
+ OPJ_UINT32 comp_index = res_index + layno0 * step_l;
+
+ // and finally take each layer of each res of ...
+ for (layno = layno0; layno < p_pocs->layno1 ; ++layno) {
+ //index = step_r * resno + step_c * compno + step_l * layno;
+ packet_array[comp_index] = 1;
+ comp_index += step_l;
+ }
+
+ res_index += step_c;
+ }
+
+ index += step_r;
+ }
+ ++p_pocs;
+
+ // iterate through all the pocs
+ for (i = 1; i < p_nb_pocs ; ++i) {
+ OPJ_UINT32 l_last_layno1 = (p_pocs-1)->layno1 ;
+
+ layno0 = (p_pocs->layno1 > l_last_layno1)? l_last_layno1 : 0;
+ index = step_r * p_pocs->resno0;
+
+ // take each resolution for each poc
+ for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) {
+ OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c;
+
+ // take each comp of each resolution for each poc
+ for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) {
+ OPJ_UINT32 comp_index = res_index + layno0 * step_l;
+
+ // and finally take each layer of each res of ...
+ for (layno = layno0; layno < p_pocs->layno1 ; ++layno) {
+ //index = step_r * resno + step_c * compno + step_l * layno;
+ packet_array[comp_index] = 1;
+ comp_index += step_l;
+ }
+
+ res_index += step_c;
+ }
+
+ index += step_r;
+ }
+
+ ++p_pocs;
+ }
+
+ index = 0;
+ for (layno = 0; layno < p_num_layers ; ++layno) {
+ for (resno = 0; resno < p_nb_resolutions; ++resno) {
+ for (compno = 0; compno < p_num_comps; ++compno) {
+ loss |= (packet_array[index]!=1);
+ //index = step_r * resno + step_c * compno + step_l * layno;
+ index += step_c;
+ }
+ }
+ }
+
+ if (loss) {
+ opj_event_msg_v2(p_manager , EVT_ERROR, "Missing packets possible loss of data\n");
+ }
+
+ opj_free(packet_array);
+
+ return !loss;
+}
+
/* ----------------------------------------------------------------------- */
static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
char *prog;
return OPJ_TRUE;
}
-static void j2k_read_soc(opj_j2k_t *j2k) {
- j2k->state = J2K_STATE_MHSIZ;
- /* Index */
- if (j2k->cstr_info) {
- j2k->cstr_info->main_head_start = cio_tell(j2k->cio) - 2;
- j2k->cstr_info->codestream_size = cio_numbytesleft(j2k->cio) + 2 - j2k->cstr_info->main_head_start;
- }
-}
+
/**
* Reads a SOC marker (Start of Codestream)
* @param p_header_size the size of the data contained in the SOC marker.
* @param p_manager the user event manager.
*/
-static opj_bool j2k_read_soc_v2( opj_j2k_v2_t *p_j2k,
+static opj_bool opj_j2k_read_soc( opj_j2k_v2_t *p_j2k,
struct opj_stream_private *p_stream,
struct opj_event_mgr * p_manager )
{
return OPJ_TRUE;
}
-static void j2k_read_siz(opj_j2k_t *j2k) {
- int len;
- OPJ_UINT32 i;
-
- opj_cio_t *cio = j2k->cio;
- opj_image_t *image = j2k->image;
- opj_cp_t *cp = j2k->cp;
-
- len = cio_read(cio, 2); /* Lsiz */
- cio_read(cio, 2); /* Rsiz (capabilities) */
- image->x1 = cio_read(cio, 4); /* Xsiz */
- image->y1 = cio_read(cio, 4); /* Ysiz */
- image->x0 = cio_read(cio, 4); /* X0siz */
- image->y0 = cio_read(cio, 4); /* Y0siz */
- cp->tdx = cio_read(cio, 4); /* XTsiz */
- cp->tdy = cio_read(cio, 4); /* YTsiz */
- cp->tx0 = cio_read(cio, 4); /* XT0siz */
- cp->ty0 = cio_read(cio, 4); /* YT0siz */
-
- /* the following code triggers: */
- /* warning: comparison of unsigned expression < 0 is always false */
-#if 0
- if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR,
- "%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
- image->x0,image->x1,image->y0,image->y1);
- return;
- }
-#endif
-
- image->numcomps = cio_read(cio, 2); /* Csiz */
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
- /* if JPWL is on, we check whether TX errors have damaged
- too much the SIZ parameters */
- if (!(image->x1 * image->y1)) {
- opj_event_msg(j2k->cinfo, EVT_ERROR,
- "JPWL: bad image size (%d x %d)\n",
- image->x1, image->y1);
- if (!JPWL_ASSUME || JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- }
- assert( len >= 38 );
- if (image->numcomps != (OPJ_UINT32)((len - 38) / 3)) {
- opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
- "JPWL: Csiz is %d => space in SIZ only for %d comps.!!!\n",
- image->numcomps, ((len - 38) / 3));
- if (!JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- /* we try to correct */
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n");
- if (image->numcomps < (OPJ_UINT32)((len - 38) / 3)) {
- len = 38 + 3 * image->numcomps;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Lsiz to %d => HYPOTHESIS!!!\n",
- len);
- } else {
- image->numcomps = ((len - 38) / 3);
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting Csiz to %d => HYPOTHESIS!!!\n",
- image->numcomps);
- }
- }
- /* update components number in the jpwl_exp_comps filed */
- cp->exp_comps = image->numcomps;
- }
-#endif /* USE_JPWL */
+/**
+ * Reads a SIZ marker (image and tile size)
+ * @param p_header_data the data contained in the SIZ box.
+ * @param jp2 the jpeg2000 file codec.
+ * @param p_header_size the size of the data contained in the SIZ marker.
+ * @param p_manager the user event manager.
+*/
+static opj_bool opj_j2k_read_siz(opj_j2k_v2_t *p_j2k,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 p_header_size,
+ opj_event_mgr_t * p_manager
+ )
+{
+ OPJ_UINT32 l_size, i;
+ OPJ_UINT32 l_nb_comp;
+ OPJ_UINT32 l_nb_comp_remain;
+ OPJ_UINT32 l_remaining_size;
+ OPJ_UINT32 l_nb_tiles;
+ OPJ_UINT32 l_tmp;
+ opj_image_t *l_image = 00;
+ opj_cp_v2_t *l_cp = 00;
+ opj_image_comp_t * l_img_comp = 00;
+ opj_tcp_v2_t * l_current_tile_param = 00;
- image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
- for (i = 0; i < image->numcomps; i++) {
- int tmp, w, h;
- tmp = cio_read(cio, 1); /* Ssiz_i */
- image->comps[i].prec = (tmp & 0x7f) + 1;
- image->comps[i].sgnd = tmp >> 7;
- image->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */
- image->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */
-
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
- /* if JPWL is on, we check whether TX errors have damaged
- too much the SIZ parameters, again */
- if (!(image->comps[i].dx * image->comps[i].dy)) {
- opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
- "JPWL: bad XRsiz_%d/YRsiz_%d (%d x %d)\n",
- i, i, image->comps[i].dx, image->comps[i].dy);
- if (!JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- /* we try to correct */
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
- if (!image->comps[i].dx) {
- image->comps[i].dx = 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting XRsiz_%d to %d => HYPOTHESIS!!!\n",
- i, image->comps[i].dx);
- }
- if (!image->comps[i].dy) {
- image->comps[i].dy = 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting YRsiz_%d to %d => HYPOTHESIS!!!\n",
- i, image->comps[i].dy);
- }
- }
-
- }
-#endif /* USE_JPWL */
+ /* preconditions */
+ assert(p_j2k != 00);
+ assert(p_manager != 00);
+ assert(p_header_data != 00);
- /* TODO: unused ? */
- w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
- h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
+ l_image = p_j2k->m_private_image;
+ l_cp = &(p_j2k->m_cp);
- image->comps[i].resno_decoded = 0; /* number of resolution decoded */
- image->comps[i].factor = cp->reduce; /* reducing factor per component */
- }
-
- cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
- cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
-
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
- /* if JPWL is on, we check whether TX errors have damaged
- too much the SIZ parameters */
- if ((cp->tw < 1) || (cp->th < 1) || (cp->tw > cp->max_tiles) || (cp->th > cp->max_tiles)) {
- opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
- "JPWL: bad number of tiles (%d x %d)\n",
- cp->tw, cp->th);
- if (!JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- /* we try to correct */
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust them\n");
- if (cp->tw < 1) {
- cp->tw= 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in x => HYPOTHESIS!!!\n",
- cp->tw);
- }
- if (cp->tw > cp->max_tiles) {
- cp->tw= 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large x, increase expectance of %d\n"
- "- setting %d tiles in x => HYPOTHESIS!!!\n",
- cp->max_tiles, cp->tw);
- }
- if (cp->th < 1) {
- cp->th= 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- setting %d tiles in y => HYPOTHESIS!!!\n",
- cp->th);
- }
- if (cp->th > cp->max_tiles) {
- cp->th= 1;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- too large y, increase expectance of %d to continue\n",
- "- setting %d tiles in y => HYPOTHESIS!!!\n",
- cp->max_tiles, cp->th);
- }
- }
- }
-#endif /* USE_JPWL */
-
- cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
- cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
- cp->tileno_size = 0;
-
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
- if (!cp->tcps) {
- opj_event_msg(j2k->cinfo, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR,
- "JPWL: could not alloc tcps field of cp\n");
- if (!JPWL_ASSUME || JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- }
- }
-#endif /* USE_JPWL */
-
- for (i = 0; i < (OPJ_UINT32)cp->tw * cp->th; i++) {
- cp->tcps[i].POC = 0;
- cp->tcps[i].numpocs = 0;
- cp->tcps[i].first = 1;
- }
-
- /* Initialization for PPM marker */
- cp->ppm = 0;
- cp->ppm_data = NULL;
- cp->ppm_data_first = NULL;
- cp->ppm_previous = 0;
- cp->ppm_store = 0;
-
- j2k->default_tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
- for (i = 0; i < (OPJ_UINT32)cp->tw * cp->th; i++) {
- cp->tcps[i].tccps = (opj_tccp_t*) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
- }
- j2k->tile_data = (unsigned char**) opj_calloc(cp->tw * cp->th, sizeof(unsigned char*));
- j2k->tile_len = (int*) opj_calloc(cp->tw * cp->th, sizeof(int));
- j2k->state = J2K_STATE_MH;
-
- /* Index */
- if (j2k->cstr_info) {
- opj_codestream_info_t *cstr_info = j2k->cstr_info;
- cstr_info->image_w = image->x1 - image->x0;
- cstr_info->image_h = image->y1 - image->y0;
- cstr_info->numcomps = image->numcomps;
- cstr_info->tw = cp->tw;
- cstr_info->th = cp->th;
- cstr_info->tile_x = cp->tdx;
- cstr_info->tile_y = cp->tdy;
- cstr_info->tile_Ox = cp->tx0;
- cstr_info->tile_Oy = cp->ty0;
- cstr_info->tile = (opj_tile_info_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tile_info_t));
- }
-}
-
-
-/**
- * Reads a SIZ marker (image and tile size)
- * @param p_header_data the data contained in the SIZ box.
- * @param jp2 the jpeg2000 file codec.
- * @param p_header_size the size of the data contained in the SIZ marker.
- * @param p_manager the user event manager.
-*/
-opj_bool j2k_read_siz_v2 (
- opj_j2k_v2_t *p_j2k,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 p_header_size,
- struct opj_event_mgr * p_manager
- )
-{
- OPJ_UINT32 l_size, i;
- OPJ_UINT32 l_nb_comp;
- OPJ_UINT32 l_nb_comp_remain;
- OPJ_UINT32 l_remaining_size;
- OPJ_UINT32 l_nb_tiles;
- OPJ_UINT32 l_tmp;
- opj_image_t *l_image = 00;
- opj_cp_v2_t *l_cp = 00;
- opj_image_comp_t * l_img_comp = 00;
- opj_tcp_v2_t * l_current_tile_param = 00;
-
- /* preconditions */
- assert(p_j2k != 00);
- assert(p_manager != 00);
- assert(p_header_data != 00);
-
- l_image = p_j2k->m_private_image;
- l_cp = &(p_j2k->m_cp);
-
- /* minimum size == 39 - 3 (= minimum component parameter) */
- if (p_header_size < 36) {
- opj_event_msg_v2(p_manager, EVT_ERROR, "Error with SIZ marker size\n");
- return OPJ_FALSE;
+ /* minimum size == 39 - 3 (= minimum component parameter) */
+ if (p_header_size < 36) {
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error with SIZ marker size\n");
+ return OPJ_FALSE;
}
l_remaining_size = p_header_size - 36;
}
}
+/**
+ * Writes the COM marker (comment)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+opj_bool j2k_write_com_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager )
+{
+ OPJ_UINT32 l_comment_size;
+ OPJ_UINT32 l_total_com_size;
+ const OPJ_CHAR *l_comment;
+ OPJ_BYTE * l_current_ptr = 00;
+
+ // preconditions
+ assert(p_j2k != 00);
+ assert(p_stream != 00);
+ assert(p_manager != 00);
+
+ l_comment = p_j2k->m_cp.comment;
+ l_comment_size = strlen(l_comment);
+ l_total_com_size = l_comment_size + 6;
+
+ if (l_total_com_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data
+ = (OPJ_BYTE*)opj_realloc( p_j2k->m_specific_param.m_encoder.m_header_tile_data,
+ l_total_com_size);
+
+ if(! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
+ return OPJ_FALSE;
+ }
+
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_total_com_size;
+ }
+
+ l_current_ptr = p_j2k->m_specific_param.m_encoder.m_header_tile_data;
+
+ opj_write_bytes(l_current_ptr,J2K_MS_COM , 2); /* COM */
+ l_current_ptr+=2;
+
+ opj_write_bytes(l_current_ptr,l_total_com_size - 2 , 2); /* L_COM */
+ l_current_ptr+=2;
+
+ opj_write_bytes(l_current_ptr,1 , 2); /* General use (IS 8859-15:1999 (Latin) values) */
+ l_current_ptr+=2;
+
+ memcpy( l_current_ptr,l_comment,l_comment_size);
+
+ if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,l_total_com_size,p_manager) != l_total_com_size) {
+ return OPJ_FALSE;
+ }
+
+ return OPJ_TRUE;
+}
+
static void j2k_read_com(opj_j2k_t *j2k) {
int len;
return OPJ_TRUE;
}
-static void j2k_read_cod(opj_j2k_t *j2k) {
- int len, pos;
- OPJ_UINT32 i;
-
- opj_cio_t *cio = j2k->cio;
- opj_cp_t *cp = j2k->cp;
- opj_tcp_t *tcp = j2k->state == J2K_STATE_TPH ? &cp->tcps[j2k->curtileno] : j2k->default_tcp;
- opj_image_t *image = j2k->image;
-
- len = cio_read(cio, 2); /* Lcod */
- tcp->csty = cio_read(cio, 1); /* Scod */
- tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* SGcod (A) */
- tcp->numlayers = cio_read(cio, 2); /* SGcod (B) */
- tcp->mct = cio_read(cio, 1); /* SGcod (C) */
-
- pos = cio_tell(cio);
- for (i = 0; i < image->numcomps; i++) {
- tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT;
- cio_seek(cio, pos);
- j2k_read_cox(j2k, i);
- }
-
- /* Index */
- if (j2k->cstr_info) {
- opj_codestream_info_t *cstr_info = j2k->cstr_info;
- cstr_info->prog = tcp->prg;
- cstr_info->numlayers = tcp->numlayers;
- cstr_info->numdecompos = (int*) opj_malloc(image->numcomps * sizeof(int));
- for (i = 0; i < image->numcomps; i++) {
- cstr_info->numdecompos[i] = tcp->tccps[i].numresolutions - 1;
- }
- }
-}
/**
* Reads a COD marker (Coding Styke defaults)
}
}
+/**
+ * Writes the POC marker (Progression Order Change)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+opj_bool j2k_write_poc_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager )
+{
+ OPJ_UINT32 l_nb_comp;
+ OPJ_UINT32 l_nb_poc;
+ OPJ_UINT32 l_poc_size;
+ OPJ_UINT32 l_written_size = 0;
+ opj_tcp_v2_t *l_tcp = 00;
+ opj_tccp_t *l_tccp = 00;
+ OPJ_UINT32 l_poc_room;
+
+ // preconditions
+ assert(p_j2k != 00);
+ assert(p_manager != 00);
+ assert(p_stream != 00);
+
+ l_tcp = &p_j2k->m_cp.tcps[p_j2k->m_current_tile_number];
+ l_tccp = &l_tcp->tccps[0];
+ l_nb_comp = p_j2k->m_private_image->numcomps;
+ l_nb_poc = 1 + l_tcp->numpocs;
+
+ if (l_nb_comp <= 256) {
+ l_poc_room = 1;
+ }
+ else {
+ l_poc_room = 2;
+ }
+ l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc;
+
+ if (l_poc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data
+ = (OPJ_BYTE*)opj_realloc(
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data,
+ l_poc_size);
+
+ if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
+ return OPJ_FALSE;
+ }
+
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_poc_size;
+ }
+
+ j2k_write_poc_in_memory(p_j2k,p_j2k->m_specific_param.m_encoder.m_header_tile_data,&l_written_size,p_manager);
+
+ if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,l_poc_size,p_manager) != l_poc_size) {
+ return OPJ_FALSE;
+ }
+
+ return OPJ_TRUE;
+}
+
+
/**
* Writes the POC marker (Progression Order Change)
*
assert(p_manager != 00);
if (p_header_size < 1) {
- opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PLM marker\n");
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PLT marker\n");
return OPJ_FALSE;
}
}
if (l_packet_len != 0) {
- opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PLM marker\n");
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading PLT marker\n");
return OPJ_FALSE;
}
return OPJ_TRUE;
}
+/**
+ * Writes the TLM marker (Tile Length Marker)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+opj_bool j2k_write_tlm_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager )
+{
+ OPJ_BYTE * l_current_data = 00;
+ OPJ_UINT32 l_tlm_size;
+
+ // preconditions
+ assert(p_j2k != 00);
+ assert(p_manager != 00);
+ assert(p_stream != 00);
+
+ l_tlm_size = 6 + (5*p_j2k->m_specific_param.m_encoder.m_total_tile_parts);
+
+ if (l_tlm_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data
+ = (OPJ_BYTE*)opj_realloc(
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data,
+ l_tlm_size);
+
+ if (! p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
+ return OPJ_FALSE;
+ }
+
+ p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_tlm_size;
+ }
+
+ l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data;
+
+ /* change the way data is written to avoid seeking if possible */
+ // TODO
+ p_j2k->m_specific_param.m_encoder.m_tlm_start = opj_stream_tell(p_stream);
+
+ opj_write_bytes(l_current_data,J2K_MS_TLM,2); /* TLM */
+ l_current_data += 2;
+
+ opj_write_bytes(l_current_data,l_tlm_size-2,2); /* Lpoc */
+ l_current_data += 2;
+
+ opj_write_bytes(l_current_data,0,1); /* Ztlm=0*/
+ ++l_current_data;
+
+ opj_write_bytes(l_current_data,0x50,1); /* Stlm ST=1(8bits-255 tiles max),SP=1(Ptlm=32bits) */
+ ++l_current_data;
+
+ /* do nothing on the 5 * l_j2k->m_specific_param.m_encoder.m_total_tile_parts remaining data */
+ if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,l_tlm_size,p_manager) != l_tlm_size) {
+ return OPJ_FALSE;
+ }
+
+ return OPJ_TRUE;
+}
+
static void j2k_write_tlm(opj_j2k_t *j2k){
int lenp;
opj_cio_t *cio = j2k->cio;
}
-static void j2k_read_sot(opj_j2k_t *j2k) {
- int len, tileno, totlen, partno, numparts;
- OPJ_UINT32 i;
- opj_tcp_t *tcp = NULL;
- char status = 0;
- opj_cp_t *cp = j2k->cp;
- opj_cio_t *cio = j2k->cio;
- len = cio_read(cio, 2);
- tileno = cio_read(cio, 2);
+/**
+ * Reads a PPT marker (Packed packet headers, tile-part header)
+ *
+ * @param p_header_data the data contained in the PPT box.
+ * @param p_j2k the jpeg2000 codec.
+ * @param p_header_size the size of the data contained in the PPT marker.
+ * @param p_manager the user event manager.
+*/
+opj_bool opj_j2k_read_sot ( opj_j2k_v2_t *p_j2k,
+ OPJ_BYTE * p_header_data,
+ OPJ_UINT32 p_header_size,
+ opj_event_mgr_t * p_manager )
+{
+ opj_cp_v2_t *l_cp = 00;
+ opj_tcp_v2_t *l_tcp = 00;
+ OPJ_UINT32 l_tot_len, l_num_parts = 0;
+ OPJ_UINT32 l_current_part;
+ OPJ_UINT32 l_tile_x,l_tile_y;
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
+ /* preconditions */
+ assert(p_header_data != 00);
+ assert(p_j2k != 00);
+ assert(p_manager != 00);
- static int backup_tileno = 0;
-
- /* tileno is negative or larger than the number of tiles!!! */
- if ((tileno < 0) || (tileno > (cp->tw * cp->th))) {
- opj_event_msg(j2k->cinfo, EVT_ERROR,
- "JPWL: bad tile number (%d out of a maximum of %d)\n",
- tileno, (cp->tw * cp->th));
- if (!JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- /* we try to correct */
- tileno = backup_tileno;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
- "- setting tile number to %d\n",
- tileno);
- }
-
- /* keep your private count of tiles */
- backup_tileno++;
- };
-#endif /* USE_JPWL */
-
- if (cp->tileno_size == 0) {
- cp->tileno[cp->tileno_size] = tileno;
- cp->tileno_size++;
- } else {
- i = 0;
- assert(cp->tileno_size >= 0);
- while (i < (OPJ_UINT32)cp->tileno_size && status == 0) {
- status = cp->tileno[i] == tileno ? 1 : 0;
- i++;
- }
- if (status == 0) {
- cp->tileno[cp->tileno_size] = tileno;
- cp->tileno_size++;
- }
- }
-
- totlen = cio_read(cio, 4);
-
-#ifdef USE_JPWL
- if (j2k->cp->correct) {
-
- /* totlen is negative or larger than the bytes left!!! */
- if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) {
- opj_event_msg(j2k->cinfo, EVT_ERROR,
- "JPWL: bad tile byte size (%d bytes against %d bytes left)\n",
- totlen, cio_numbytesleft(cio) + 8);
- if (!JPWL_ASSUME) {
- opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: giving up\n");
- return;
- }
- /* we try to correct */
- totlen = 0;
- opj_event_msg(j2k->cinfo, EVT_WARNING, "- trying to adjust this\n"
- "- setting Psot to %d => assuming it is the last tile\n",
- totlen);
- }
-
- };
-#endif /* USE_JPWL */
-
- if (!totlen)
- totlen = cio_numbytesleft(cio) + 8;
-
- partno = cio_read(cio, 1);
- numparts = cio_read(cio, 1);
-
- if (partno >= numparts) {
- opj_event_msg(j2k->cinfo, EVT_WARNING, "SOT marker inconsistency in tile %d: tile-part index greater (%d) than number of tile-parts (%d)\n", tileno, partno, numparts);
- numparts = partno+1;
- }
-
- j2k->curtileno = tileno;
- j2k->cur_tp_num = partno;
- j2k->eot = cio_getbp(cio) - 12 + totlen;
- j2k->state = J2K_STATE_TPH;
- tcp = &cp->tcps[j2k->curtileno];
-
- /* Index */
- if (j2k->cstr_info) {
- if (tcp->first) {
- if (tileno == 0)
- j2k->cstr_info->main_head_end = cio_tell(cio) - 13;
- j2k->cstr_info->tile[tileno].tileno = tileno;
- j2k->cstr_info->tile[tileno].start_pos = cio_tell(cio) - 12;
- j2k->cstr_info->tile[tileno].end_pos = j2k->cstr_info->tile[tileno].start_pos + totlen - 1;
- } else {
- j2k->cstr_info->tile[tileno].end_pos += totlen;
- }
- j2k->cstr_info->tile[tileno].num_tps = numparts;
- if (numparts)
- j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, numparts * sizeof(opj_tp_info_t));
- else
- j2k->cstr_info->tile[tileno].tp = (opj_tp_info_t *) opj_realloc(j2k->cstr_info->tile[tileno].tp, 10 * sizeof(opj_tp_info_t)); /* Fixme (10)*/
- j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = cio_tell(cio) - 12;
- j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos =
- j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totlen - 1;
- }
-
- if (tcp->first == 1) {
- /* Initialization PPT */
- opj_tccp_t *tmp = tcp->tccps;
- memcpy(tcp, j2k->default_tcp, sizeof(opj_tcp_t));
- tcp->ppt = 0;
- tcp->ppt_data = NULL;
- tcp->ppt_data_first = NULL;
- tcp->tccps = tmp;
-
- for (i = 0; i < j2k->image->numcomps; i++) {
- tcp->tccps[i] = j2k->default_tcp->tccps[i];
- }
- cp->tcps[j2k->curtileno].first = 0;
- }
-}
-
-/**
- * Reads a PPT marker (Packed packet headers, tile-part header)
- *
- * @param p_header_data the data contained in the PPT box.
- * @param p_j2k the jpeg2000 codec.
- * @param p_header_size the size of the data contained in the PPT marker.
- * @param p_manager the user event manager.
-*/
-opj_bool j2k_read_sot_v2 (
- opj_j2k_v2_t *p_j2k,
- OPJ_BYTE * p_header_data,
- OPJ_UINT32 p_header_size,
- struct opj_event_mgr * p_manager
- )
-{
-
- opj_cp_v2_t *l_cp = 00;
- opj_tcp_v2_t *l_tcp = 00;
- OPJ_UINT32 l_tot_len, l_num_parts = 0;
- OPJ_UINT32 l_current_part;
- OPJ_UINT32 l_tile_x,l_tile_y;
-
- /* preconditions */
- assert(p_header_data != 00);
- assert(p_j2k != 00);
- assert(p_manager != 00);
-
- /* Size of this marker is fixed = 12 (we have already read marker and its size)*/
- if (p_header_size != 8) {
- opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SOT marker\n");
- return OPJ_FALSE;
- }
+ /* Size of this marker is fixed = 12 (we have already read marker and its size)*/
+ if (p_header_size != 8) {
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading SOT marker\n");
+ return OPJ_FALSE;
+ }
l_cp = &(p_j2k->m_cp);
opj_read_bytes(p_header_data,&(p_j2k->m_current_tile_number),2); /* Isot */
/* Index */
if (p_j2k->cstr_index)
{
+ assert(p_j2k->cstr_index->tile_index != 00);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tileno = p_j2k->m_current_tile_number;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_tpsno = l_current_part;
}
-static void j2k_read_sod(opj_j2k_t *j2k) {
- int len, truncate = 0, i;
- unsigned char *data = NULL, *data_ptr = NULL;
-
- opj_cio_t *cio = j2k->cio;
- int curtileno = j2k->curtileno;
-
- /* Index */
- if (j2k->cstr_info) {
- j2k->cstr_info->tile[j2k->curtileno].tp[j2k->cur_tp_num].tp_end_header =
- cio_tell(cio) + j2k->pos_correction - 1;
- if (j2k->cur_tp_num == 0)
- j2k->cstr_info->tile[j2k->curtileno].end_header = cio_tell(cio) + j2k->pos_correction - 1;
- j2k->cstr_info->packno = 0;
- }
-
- len = int_min(j2k->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1);
-
- if (len == cio_numbytesleft(cio) + 1) {
- truncate = 1; /* Case of a truncate codestream */
- }
-
- data = j2k->tile_data[curtileno];
- data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
- data_ptr = data + j2k->tile_len[curtileno];
- for (i = 0; i < len; i++) {
- data_ptr[i] = cio_read(cio, 1);
- }
-
- j2k->tile_len[curtileno] += len;
- j2k->tile_data[curtileno] = data;
-
- if (!truncate) {
- j2k->state = J2K_STATE_TPHSOT;
- } else {
- j2k->state = J2K_STATE_NEOC; /* RAJOUTE !! */
- }
- j2k->cur_tp_num++;
-}
/**
* Reads a SOD marker (Start Of Data)
* @param p_header_size the size of the data contained in the SOD marker.
* @param p_manager the user event manager.
*/
-opj_bool j2k_read_sod_v2 (
- opj_j2k_v2_t *p_j2k,
- struct opj_stream_private *p_stream,
- struct opj_event_mgr * p_manager
- )
+opj_bool opj_j2k_read_sod (opj_j2k_v2_t *p_j2k,
+ opj_stream_private_t *p_stream,
+ opj_event_mgr_t * p_manager
+ )
{
OPJ_UINT32 l_current_read_size;
opj_codestream_index_t * l_cstr_index = 00;
/* <<UniPG */
}
+/**
+ * Writes the EOC marker (End of Codestream)
+ *
+ * @param p_stream the stream to write data to.
+ * @param p_j2k J2K codec.
+ * @param p_manager the user event manager.
+*/
+opj_bool j2k_write_eoc_v2( opj_j2k_v2_t *p_j2k,
+ struct opj_stream_private *p_stream,
+ struct opj_event_mgr * p_manager )
+{
+ /* preconditions */
+ assert(p_j2k != 00);
+ assert(p_manager != 00);
+ assert(p_stream != 00);
+
+ opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_header_tile_data,J2K_MS_EOC,2); /* EOC */
+
+
+/* UniPG>> */
+#ifdef USE_JPWL
+ /* update markers struct */
+ /*
+ j2k_add_marker(p_j2k->cstr_info, J2K_MS_EOC, p_stream_tell(p_stream) - 2, 2);
+*/
+#endif /* USE_JPWL */
+
+ if ( opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,2,p_manager) != 2) {
+ return OPJ_FALSE;
+ }
+
+ if ( ! opj_stream_flush(p_stream,p_manager) ) {
+ return OPJ_FALSE;
+ }
+
+ return OPJ_TRUE;
+}
+
+
/**
* Reads a RGN marker (Region Of Interest)
*
static void j2k_read_eoc(opj_j2k_t *j2k) {
int i, tileno;
- opj_bool success;
+ opj_bool success = OPJ_FALSE;
/* if packets should be decoded */
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
for (i = 0; i < j2k->cp->tileno_size; i++) {
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
- tileno = j2k->cp->tileno[i];
- success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
- opj_free(j2k->tile_data[tileno]);
- j2k->tile_data[tileno] = NULL;
- tcd_free_decode_tile(tcd, i);
+ if (j2k->cp->tileno[i] != -1)
+ {
+ tileno = j2k->cp->tileno[i];
+ success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
+ opj_free(j2k->tile_data[tileno]);
+ j2k->tile_data[tileno] = NULL;
+ tcd_free_decode_tile(tcd, i);
+ }
+ else
+ success = OPJ_FALSE;
if (success == OPJ_FALSE) {
j2k->state |= J2K_STATE_ERR;
break;
} opj_dec_mstabent_t;
opj_dec_mstabent_t j2k_dec_mstab[] = {
- {J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},
- {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot},
- {J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},
+ /*{J2K_MS_SOC, J2K_STATE_MHSOC, j2k_read_soc},*/
+ /*{J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, j2k_read_sot},*/
+ /*{J2K_MS_SOD, J2K_STATE_TPH, j2k_read_sod},*/
{J2K_MS_EOC, J2K_STATE_TPHSOT, j2k_read_eoc},
- {J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},
- {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod},
+ /*{J2K_MS_SIZ, J2K_STATE_MHSIZ, j2k_read_siz},*/
+ /*{J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_cod},*/
{J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_coc},
{J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_rgn},
{J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_qcd},
/* J2K / JPT decoder interface */
/* ----------------------------------------------------------------------- */
-opj_j2k_t* j2k_create_decompress(opj_common_ptr cinfo) {
- opj_j2k_t *j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t));
- if(!j2k)
- return NULL;
-
- j2k->default_tcp = (opj_tcp_t*) opj_calloc(1, sizeof(opj_tcp_t));
- if(!j2k->default_tcp) {
- opj_free(j2k);
- return NULL;
- }
-
- j2k->cinfo = cinfo;
- j2k->tile_data = NULL;
- return j2k;
-}
void j2k_destroy_decompress(opj_j2k_t *j2k) {
int i = 0;
opj_free(j2k);
}
-void j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) {
- if(j2k && parameters) {
- /* create and initialize the coding parameters structure */
- opj_cp_t *cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
- cp->reduce = parameters->cp_reduce;
- cp->layer = parameters->cp_layer;
- cp->limit_decoding = parameters->cp_limit_decoding;
-
-#ifdef USE_JPWL
- cp->correct = parameters->jpwl_correct;
- cp->exp_comps = parameters->jpwl_exp_comps;
- cp->max_tiles = parameters->jpwl_max_tiles;
-#endif /* USE_JPWL */
-
-
- /* keep a link to cp so that we can destroy it later in j2k_destroy_decompress */
- j2k->cp = cp;
- }
-}
-void j2k_setup_decoder_v2(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters)
+void opj_j2k_setup_decoder(opj_j2k_v2_t *j2k, opj_dparameters_t *parameters)
{
if(j2k && parameters) {
j2k->m_cp.m_specific_param.m_dec.m_layer = parameters->cp_layer;
}
}
-opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *cstr_info) {
- opj_image_t *image = NULL;
-
- opj_common_ptr cinfo = j2k->cinfo;
-
- j2k->cio = cio;
- j2k->cstr_info = cstr_info;
- if (cstr_info)
- memset(cstr_info, 0, sizeof(opj_codestream_info_t));
- /* create an empty image */
- image = opj_image_create0();
- j2k->image = image;
-
- j2k->state = J2K_STATE_MHSOC;
-
- for (;;) {
- opj_dec_mstabent_t *e;
- int id = cio_read(cio, 2);
-
-#ifdef USE_JPWL
- /* we try to honor JPWL correction power */
- if (j2k->cp->correct) {
-
- int orig_pos = cio_tell(cio);
- opj_bool status;
-
- /* call the corrector */
- status = jpwl_correct(j2k);
-
- /* go back to where you were */
- cio_seek(cio, orig_pos - 2);
-
- /* re-read the marker */
- id = cio_read(cio, 2);
-
- /* check whether it begins with ff */
- if (id >> 8 != 0xff) {
- opj_event_msg(cinfo, EVT_ERROR,
- "JPWL: possible bad marker %x at %d\n",
- id, cio_tell(cio) - 2);
- if (!JPWL_ASSUME) {
- opj_image_destroy(image);
- opj_event_msg(cinfo, EVT_ERROR, "JPWL: giving up\n");
- return 0;
- }
- /* we try to correct */
- id = id | 0xff00;
- cio_seek(cio, cio_tell(cio) - 2);
- cio_write(cio, id, 2);
- opj_event_msg(cinfo, EVT_WARNING, "- trying to adjust this\n"
- "- setting marker to %x\n",
- id);
- }
-
- }
-#endif /* USE_JPWL */
-
- if (id >> 8 != 0xff) {
- opj_image_destroy(image);
- opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
- return 0;
- }
- e = j2k_dec_mstab_lookup(id);
- /* Check if the marker is known*/
- if (!(j2k->state & e->states)) {
- opj_image_destroy(image);
- opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id);
- return 0;
- }
- /* Check if the decoding is limited to the main header*/
- if (e->id == J2K_MS_SOT && j2k->cp->limit_decoding == LIMIT_TO_MAIN_HEADER) {
- opj_event_msg(cinfo, EVT_INFO, "Main Header decoded.\n");
- return image;
- }
-
- if (e->handler) {
- (*e->handler)(j2k);
- }
- if (j2k->state & J2K_STATE_ERR)
- return NULL;
-
- if (j2k->state == J2K_STATE_MT) {
- break;
- }
- if (j2k->state == J2K_STATE_NEOC) {
- break;
- }
- }
- if (j2k->state == J2K_STATE_NEOC) {
- j2k_read_eoc(j2k);
- }
-
- if (j2k->state != J2K_STATE_MT) {
- opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n");
- }
- return image;
-}
/*
* Read a JPT-stream and decode file
void j2k_destroy_compress(opj_j2k_t *j2k) {
int tileno;
- if(!j2k) return;
- if(j2k->cp != NULL) {
- opj_cp_t *cp = j2k->cp;
+ if(!j2k) return;
+ if(j2k->cp != NULL) {
+ opj_cp_t *cp = j2k->cp;
+
+ if(cp->comment) {
+ opj_free(cp->comment);
+ }
+ if(cp->matrice) {
+ opj_free(cp->matrice);
+ }
+ for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
+ opj_free(cp->tcps[tileno].tccps);
+ }
+ opj_free(cp->tcps);
+ opj_free(cp);
+ }
+
+ opj_free(j2k);
+}
+
+void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image) {
+ OPJ_UINT32 i,j;
+ int tileno, numpocs_tile;
+ opj_cp_t *cp = NULL;
+
+ if(!j2k || !parameters || ! image) {
+ return;
+ }
+
+ /* create and initialize the coding parameters structure */
+ cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
+
+ /* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
+ j2k->cp = cp;
+
+ /* set default values for cp */
+ cp->tw = 1;
+ cp->th = 1;
+
+ /*
+ copy user encoding parameters
+ */
+ cp->cinema = parameters->cp_cinema;
+ cp->max_comp_size = parameters->max_comp_size;
+ cp->rsiz = parameters->cp_rsiz;
+ cp->disto_alloc = parameters->cp_disto_alloc;
+ cp->fixed_alloc = parameters->cp_fixed_alloc;
+ cp->fixed_quality = parameters->cp_fixed_quality;
+
+ /* mod fixed_quality */
+ if(parameters->cp_matrice) {
+ size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(int);
+ cp->matrice = (int *) opj_malloc(array_size);
+ memcpy(cp->matrice, parameters->cp_matrice, array_size);
+ }
+
+ /* tiles */
+ cp->tdx = parameters->cp_tdx;
+ cp->tdy = parameters->cp_tdy;
+
+ /* tile offset */
+ cp->tx0 = parameters->cp_tx0;
+ cp->ty0 = parameters->cp_ty0;
+
+ /* comment string */
+ if(parameters->cp_comment) {
+ cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1);
+ if(cp->comment) {
+ strcpy(cp->comment, parameters->cp_comment);
+ }
+ }
+
+ /*
+ calculate other encoding parameters
+ */
+
+ if (parameters->tile_size_on) {
+ cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
+ cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
+ } else {
+ cp->tdx = image->x1 - cp->tx0;
+ cp->tdy = image->y1 - cp->ty0;
+ }
+
+ if(parameters->tp_on){
+ cp->tp_flag = parameters->tp_flag;
+ cp->tp_on = 1;
+ }
+
+ cp->img_size = 0;
+ for(i=0;i<image->numcomps ;i++){
+ cp->img_size += (image->comps[i].w *image->comps[i].h * image->comps[i].prec);
+ }
+
+
+#ifdef USE_JPWL
+ /*
+ calculate JPWL encoding parameters
+ */
+
+ if (parameters->jpwl_epc_on) {
+ OPJ_UINT32 i;
+
+ /* set JPWL on */
+ cp->epc_on = OPJ_TRUE;
+ cp->info_on = OPJ_FALSE; /* no informative technique */
+
+ /* set EPB on */
+ if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
+ cp->epb_on = OPJ_TRUE;
+
+ cp->hprot_MH = parameters->jpwl_hprot_MH;
+ for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
+ cp->hprot_TPH_tileno[i] = parameters->jpwl_hprot_TPH_tileno[i];
+ cp->hprot_TPH[i] = parameters->jpwl_hprot_TPH[i];
+ }
+ /* if tile specs are not specified, copy MH specs */
+ if (cp->hprot_TPH[0] == -1) {
+ cp->hprot_TPH_tileno[0] = 0;
+ cp->hprot_TPH[0] = parameters->jpwl_hprot_MH;
+ }
+ for (i = 0; i < JPWL_MAX_NO_PACKSPECS; i++) {
+ cp->pprot_tileno[i] = parameters->jpwl_pprot_tileno[i];
+ cp->pprot_packno[i] = parameters->jpwl_pprot_packno[i];
+ cp->pprot[i] = parameters->jpwl_pprot[i];
+ }
+ }
+
+ /* set ESD writing */
+ if ((parameters->jpwl_sens_size == 1) || (parameters->jpwl_sens_size == 2)) {
+ cp->esd_on = OPJ_TRUE;
+
+ cp->sens_size = parameters->jpwl_sens_size;
+ cp->sens_addr = parameters->jpwl_sens_addr;
+ cp->sens_range = parameters->jpwl_sens_range;
+
+ cp->sens_MH = parameters->jpwl_sens_MH;
+ for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
+ cp->sens_TPH_tileno[i] = parameters->jpwl_sens_TPH_tileno[i];
+ cp->sens_TPH[i] = parameters->jpwl_sens_TPH[i];
+ }
+ }
+
+ /* always set RED writing to false: we are at the encoder */
+ cp->red_on = OPJ_FALSE;
+
+ } else {
+ cp->epc_on = OPJ_FALSE;
+ }
+#endif /* USE_JPWL */
+
+
+ /* initialize the mutiple tiles */
+ /* ---------------------------- */
+ cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
+
+ for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
+ opj_tcp_t *tcp = &cp->tcps[tileno];
+ tcp->numlayers = parameters->tcp_numlayers;
+ assert ( tcp->numlayers >= 0 );
+ for (j = 0; j < (OPJ_UINT32)tcp->numlayers; j++) {
+ if(cp->cinema){
+ if (cp->fixed_quality) {
+ tcp->distoratio[j] = parameters->tcp_distoratio[j];
+ }
+ tcp->rates[j] = parameters->tcp_rates[j];
+ }else{
+ if (cp->fixed_quality) { /* add fixed_quality */
+ tcp->distoratio[j] = parameters->tcp_distoratio[j];
+ } else {
+ tcp->rates[j] = parameters->tcp_rates[j];
+ }
+ }
+ }
+ tcp->csty = parameters->csty;
+ tcp->prg = parameters->prog_order;
+ tcp->mct = parameters->tcp_mct;
+
+ numpocs_tile = 0;
+ tcp->POC = 0;
+ if (parameters->numpocs) {
+ /* initialisation of POC */
+ tcp->POC = 1;
+ assert( parameters->numpocs >= 0 );
+ for (i = 0; i < (OPJ_UINT32)parameters->numpocs; i++) {
+ if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) {
+ opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile];
+ tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0;
+ tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0;
+ tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1;
+ tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1;
+ tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1;
+ tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1;
+ tcp_poc->tile = parameters->POC[numpocs_tile].tile;
+ numpocs_tile++;
+ }
+ }
+ tcp->numpocs = numpocs_tile -1 ;
+ }else{
+ tcp->numpocs = 0;
+ }
+
+ tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
+
+ for (i = 0; i < image->numcomps; i++) {
+ opj_tccp_t *tccp = &tcp->tccps[i];
+ tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */
+ tccp->numresolutions = parameters->numresolution;
+ tccp->cblkw = int_floorlog2(parameters->cblockw_init);
+ tccp->cblkh = int_floorlog2(parameters->cblockh_init);
+ tccp->cblksty = parameters->mode;
+ tccp->qmfbid = parameters->irreversible ? 0 : 1;
+ tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
+ tccp->numgbits = 2;
+ assert(parameters->roi_compno >= 0);
+ if (i == (OPJ_UINT32)parameters->roi_compno) {
+ tccp->roishift = parameters->roi_shift;
+ } else {
+ tccp->roishift = 0;
+ }
+
+ if(parameters->cp_cinema)
+ {
+ /*Precinct size for lowest frequency subband=128*/
+ tccp->prcw[0] = 7;
+ tccp->prch[0] = 7;
+ /*Precinct size at all other resolutions = 256*/
+ for (j = 1; j < tccp->numresolutions; j++) {
+ tccp->prcw[j] = 8;
+ tccp->prch[j] = 8;
+ }
+ }else{
+ if (parameters->csty & J2K_CCP_CSTY_PRT) {
+ int p = 0;
+ assert(tccp->numresolutions > 0);
+ for (j = (OPJ_UINT32)(tccp->numresolutions - 1); (int)j >= 0; j--) {
+ if (p < parameters->res_spec) {
+
+ if (parameters->prcw_init[p] < 1) {
+ tccp->prcw[j] = 1;
+ } else {
+ tccp->prcw[j] = int_floorlog2(parameters->prcw_init[p]);
+ }
+
+ if (parameters->prch_init[p] < 1) {
+ tccp->prch[j] = 1;
+ }else {
+ tccp->prch[j] = int_floorlog2(parameters->prch_init[p]);
+ }
+
+ } else {
+ int res_spec = parameters->res_spec;
+ int size_prcw = parameters->prcw_init[res_spec - 1] >> (p - (res_spec - 1));
+ int size_prch = parameters->prch_init[res_spec - 1] >> (p - (res_spec - 1));
+
+ if (size_prcw < 1) {
+ tccp->prcw[j] = 1;
+ } else {
+ tccp->prcw[j] = int_floorlog2(size_prcw);
+ }
+
+ if (size_prch < 1) {
+ tccp->prch[j] = 1;
+ } else {
+ tccp->prch[j] = int_floorlog2(size_prch);
+ }
+ }
+ p++;
+ /*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */
+ } /*end for*/
+ } else {
+ for (j = 0; j < tccp->numresolutions; j++) {
+ tccp->prcw[j] = 15;
+ tccp->prch[j] = 15;
+ }
+ }
+ }
- if(cp->comment) {
- opj_free(cp->comment);
- }
- if(cp->matrice) {
- opj_free(cp->matrice);
- }
- for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
- opj_free(cp->tcps[tileno].tccps);
+ dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec);
}
- opj_free(cp->tcps);
- opj_free(cp);
}
-
- opj_free(j2k);
}
-void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image) {
- OPJ_UINT32 i,j;
- int tileno, numpocs_tile;
- opj_cp_t *cp = NULL;
+void j2k_setup_encoder_v2( opj_j2k_v2_t *p_j2k,
+ opj_cparameters_t *parameters,
+ opj_image_t *image,
+ struct opj_event_mgr * p_manager)
+{
+ OPJ_UINT32 i, j, tileno, numpocs_tile;
+ opj_cp_v2_t *cp = 00;
+ opj_bool l_res;
- if(!j2k || !parameters || ! image) {
+ if(!p_j2k || !parameters || ! image) {
return;
}
- /* create and initialize the coding parameters structure */
- cp = (opj_cp_t*) opj_calloc(1, sizeof(opj_cp_t));
-
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
- j2k->cp = cp;
+ cp = &(p_j2k->m_cp);
/* set default values for cp */
cp->tw = 1;
cp->th = 1;
- /*
- copy user encoding parameters
+ /*
+ copy user encoding parameters
*/
- cp->cinema = parameters->cp_cinema;
- cp->max_comp_size = parameters->max_comp_size;
+ cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema;
+ cp->m_specific_param.m_enc.m_max_comp_size = parameters->max_comp_size;
cp->rsiz = parameters->cp_rsiz;
- cp->disto_alloc = parameters->cp_disto_alloc;
- cp->fixed_alloc = parameters->cp_fixed_alloc;
- cp->fixed_quality = parameters->cp_fixed_quality;
+ cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc;
+ cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc;
+ cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality;
/* mod fixed_quality */
- if(parameters->cp_matrice) {
- size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(int);
- cp->matrice = (int *) opj_malloc(array_size);
- memcpy(cp->matrice, parameters->cp_matrice, array_size);
+ if (parameters->cp_matrice) {
+ size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(OPJ_INT32);
+ cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size);
+ memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size);
}
/* tiles */
cp->tdy = image->y1 - cp->ty0;
}
- if(parameters->tp_on){
- cp->tp_flag = parameters->tp_flag;
- cp->tp_on = 1;
- }
-
- cp->img_size = 0;
- for(i=0;i<image->numcomps ;i++){
- cp->img_size += (image->comps[i].w *image->comps[i].h * image->comps[i].prec);
+ if (parameters->tp_on) {
+ cp->m_specific_param.m_enc.m_tp_flag = parameters->tp_flag;
+ cp->m_specific_param.m_enc.m_tp_on = 1;
}
-
#ifdef USE_JPWL
/*
calculate JPWL encoding parameters
*/
if (parameters->jpwl_epc_on) {
- OPJ_UINT32 i;
+ OPJ_INT32 i;
/* set JPWL on */
cp->epc_on = OPJ_TRUE;
/* set EPB on */
if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
cp->epb_on = OPJ_TRUE;
-
+
cp->hprot_MH = parameters->jpwl_hprot_MH;
for (i = 0; i < JPWL_MAX_NO_TILESPECS; i++) {
cp->hprot_TPH_tileno[i] = parameters->jpwl_hprot_TPH_tileno[i];
/* initialize the mutiple tiles */
/* ---------------------------- */
- cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
+ cp->tcps = (opj_tcp_v2_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_v2_t));
+ if (parameters->numpocs) {
+ /* initialisation of POC */
+ l_res = j2k_check_poc_val(parameters->POC,parameters->numpocs, parameters->numresolution, image->numcomps, parameters->tcp_numlayers, p_manager);
+ // TODO
+ }
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
- opj_tcp_t *tcp = &cp->tcps[tileno];
+ opj_tcp_v2_t *tcp = &cp->tcps[tileno];
tcp->numlayers = parameters->tcp_numlayers;
- assert ( tcp->numlayers >= 0 );
- for (j = 0; j < (OPJ_UINT32)tcp->numlayers; j++) {
- if(cp->cinema){
- if (cp->fixed_quality) {
+
+ for (j = 0; j < tcp->numlayers; j++) {
+ if(cp->m_specific_param.m_enc.m_cinema){
+ if (cp->m_specific_param.m_enc.m_fixed_quality) {
tcp->distoratio[j] = parameters->tcp_distoratio[j];
}
tcp->rates[j] = parameters->tcp_rates[j];
}else{
- if (cp->fixed_quality) { /* add fixed_quality */
+ if (cp->m_specific_param.m_enc.m_fixed_quality) { /* add fixed_quality */
tcp->distoratio[j] = parameters->tcp_distoratio[j];
} else {
tcp->rates[j] = parameters->tcp_rates[j];
}
}
}
+
tcp->csty = parameters->csty;
tcp->prg = parameters->prog_order;
- tcp->mct = parameters->tcp_mct;
+ tcp->mct = parameters->tcp_mct;
numpocs_tile = 0;
tcp->POC = 0;
+
if (parameters->numpocs) {
/* initialisation of POC */
tcp->POC = 1;
- assert( parameters->numpocs >= 0 );
- for (i = 0; i < (OPJ_UINT32)parameters->numpocs; i++) {
+ // TODO
+ for (i = 0; i < (unsigned int) parameters->numpocs; i++) {
if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) {
opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile];
+
tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0;
tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0;
tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1;
tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1;
tcp_poc->prg1 = parameters->POC[numpocs_tile].prg1;
tcp_poc->tile = parameters->POC[numpocs_tile].tile;
+
numpocs_tile++;
}
}
+
tcp->numpocs = numpocs_tile -1 ;
- }else{
+ }else{
tcp->numpocs = 0;
}
tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t));
+ if (parameters->mct_data) {
+
+ opj_event_msg_v2(p_manager, EVT_ERROR, "MCT not supported for now\n");
+ return;
+
+ /* TODO MSD : merge v2 add invert.c or used a external lib ?
+ OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * sizeof(OPJ_FLOAT32);
+ OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize);
+ OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + lMctSize);
+
+ tcp->mct = 2;
+ tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
+ memcpy(tcp->m_mct_coding_matrix,parameters->mct_data,lMctSize);
+ memcpy(lTmpBuf,parameters->mct_data,lMctSize);
+
+ tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize);
+ assert(opj_matrix_inversion_f(lTmpBuf,(tcp->m_mct_decoding_matrix),image->numcomps));
+
+ tcp->mct_norms = (OPJ_FLOAT64*)
+ opj_malloc(image->numcomps * sizeof(OPJ_FLOAT64));
+
+ opj_calculate_norms(tcp->mct_norms,image->numcomps,tcp->m_mct_decoding_matrix);
+ opj_free(lTmpBuf);
+
+ for (i = 0; i < image->numcomps; i++) {
+ opj_tccp_t *tccp = &tcp->tccps[i];
+ tccp->m_dc_level_shift = l_dc_shift[i];
+ }
+
+ j2k_setup_mct_encoding(tcp,image);
+ */
+ }
+ else {
+ for (i = 0; i < image->numcomps; i++) {
+ opj_tccp_t *tccp = &tcp->tccps[i];
+ opj_image_comp_t * l_comp = &(image->comps[i]);
+
+ if (! l_comp->sgnd) {
+ tccp->m_dc_level_shift = 1 << (l_comp->prec - 1);
+ }
+ }
+ }
+
for (i = 0; i < image->numcomps; i++) {
opj_tccp_t *tccp = &tcp->tccps[i];
+
tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */
tccp->numresolutions = parameters->numresolution;
tccp->cblkw = int_floorlog2(parameters->cblockw_init);
tccp->qmfbid = parameters->irreversible ? 0 : 1;
tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
tccp->numgbits = 2;
- assert(parameters->roi_compno >= 0);
- if (i == (OPJ_UINT32)parameters->roi_compno) {
+
+ if (i == parameters->roi_compno) {
tccp->roishift = parameters->roi_shift;
} else {
tccp->roishift = 0;
}
- if(parameters->cp_cinema)
- {
- /*Precinct size for lowest frequency subband=128*/
+ if(parameters->cp_cinema) {
+ //Precinct size for lowest frequency subband=128
tccp->prcw[0] = 7;
tccp->prch[0] = 7;
- /*Precinct size at all other resolutions = 256*/
+ //Precinct size at all other resolutions = 256
for (j = 1; j < tccp->numresolutions; j++) {
tccp->prcw[j] = 8;
tccp->prch[j] = 8;
}
}else{
if (parameters->csty & J2K_CCP_CSTY_PRT) {
- int p = 0;
- assert(tccp->numresolutions > 0);
- for (j = (OPJ_UINT32)(tccp->numresolutions - 1); (int)j >= 0; j--) {
+ OPJ_INT32 p = 0, it_res;
+ for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) {
if (p < parameters->res_spec) {
-
+
if (parameters->prcw_init[p] < 1) {
- tccp->prcw[j] = 1;
+ tccp->prcw[it_res] = 1;
} else {
- tccp->prcw[j] = int_floorlog2(parameters->prcw_init[p]);
+ tccp->prcw[it_res] = int_floorlog2(parameters->prcw_init[p]);
}
-
+
if (parameters->prch_init[p] < 1) {
- tccp->prch[j] = 1;
+ tccp->prch[it_res] = 1;
}else {
- tccp->prch[j] = int_floorlog2(parameters->prch_init[p]);
+ tccp->prch[it_res] = int_floorlog2(parameters->prch_init[p]);
}
} else {
int res_spec = parameters->res_spec;
int size_prcw = parameters->prcw_init[res_spec - 1] >> (p - (res_spec - 1));
int size_prch = parameters->prch_init[res_spec - 1] >> (p - (res_spec - 1));
-
+
if (size_prcw < 1) {
- tccp->prcw[j] = 1;
+ tccp->prcw[it_res] = 1;
} else {
- tccp->prcw[j] = int_floorlog2(size_prcw);
+ tccp->prcw[it_res] = int_floorlog2(size_prcw);
}
-
+
if (size_prch < 1) {
- tccp->prch[j] = 1;
+ tccp->prch[it_res] = 1;
} else {
- tccp->prch[j] = int_floorlog2(size_prch);
+ tccp->prch[it_res] = int_floorlog2(size_prch);
}
}
p++;
- /*printf("\nsize precinct for level %d : %d,%d\n", j,tccp->prcw[j], tccp->prch[j]); */
- } /*end for*/
+ /*printf("\nsize precinct for level %d : %d,%d\n", it_res,tccp->prcw[it_res], tccp->prch[it_res]); */
+ } //end for
} else {
for (j = 0; j < tccp->numresolutions; j++) {
tccp->prcw[j] = 15;
dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec);
}
}
+
+ if (parameters->mct_data) {
+ opj_free(parameters->mct_data);
+ parameters->mct_data = 00;
+ }
}
+
opj_bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
int tileno;
OPJ_UINT32 compno;
/* Copy codestream image information to the output image */
opj_copy_image_header(p_j2k->m_private_image, *p_image);
+ /*Allocate and initialize some elements of codestrem index*/
+ if (!j2k_allocate_tile_element_cstr_index(p_j2k)){
+ return OPJ_FALSE;
+ }
return OPJ_TRUE;
}
return l_is_valid;
}
+opj_bool j2k_setup_mct_encoding(opj_tcp_v2_t * p_tcp, opj_image_t * p_image)
+{
+ OPJ_UINT32 i;
+ OPJ_UINT32 l_indix = 1;
+ opj_mct_data_t * l_mct_deco_data = 00,* l_mct_offset_data = 00;
+ opj_simple_mcc_decorrelation_data_t * l_mcc_data;
+ OPJ_UINT32 l_mct_size,l_nb_elem;
+ OPJ_FLOAT32 * l_data, * l_current_data;
+ opj_tccp_t * l_tccp;
+
+ // preconditions
+ assert(p_tcp != 00);
+
+ if (p_tcp->mct != 2) {
+ return OPJ_TRUE;
+ }
+
+ if (p_tcp->m_mct_decoding_matrix) {
+ if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
+ p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
+
+ p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
+ if (! p_tcp->m_mct_records) {
+ return OPJ_FALSE;
+ }
+ l_mct_deco_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
+
+ memset(l_mct_deco_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
+ }
+ l_mct_deco_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
+
+ if (l_mct_deco_data->m_data) {
+ opj_free(l_mct_deco_data->m_data);
+ l_mct_deco_data->m_data = 00;
+ }
+
+ l_mct_deco_data->m_index = l_indix++;
+ l_mct_deco_data->m_array_type = MCT_TYPE_DECORRELATION;
+ l_mct_deco_data->m_element_type = MCT_TYPE_FLOAT;
+ l_nb_elem = p_image->numcomps * p_image->numcomps;
+ l_mct_size = l_nb_elem * MCT_ELEMENT_SIZE[l_mct_deco_data->m_element_type];
+ l_mct_deco_data->m_data = (OPJ_BYTE*)opj_malloc(l_mct_size );
+
+ if (! l_mct_deco_data->m_data) {
+ return OPJ_FALSE;
+ }
+
+ j2k_mct_write_functions_from_float[l_mct_deco_data->m_element_type](p_tcp->m_mct_decoding_matrix,l_mct_deco_data->m_data,l_nb_elem);
+
+ l_mct_deco_data->m_data_size = l_mct_size;
+ ++p_tcp->m_nb_mct_records;
+ }
+
+ if (p_tcp->m_nb_mct_records == p_tcp->m_nb_max_mct_records) {
+ p_tcp->m_nb_max_mct_records += J2K_MCT_DEFAULT_NB_RECORDS;
+ p_tcp->m_mct_records = (opj_mct_data_t*)opj_realloc(p_tcp->m_mct_records,p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t));
+
+ if (! p_tcp->m_mct_records) {
+ return OPJ_FALSE;
+ }
+
+ l_mct_offset_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
+ memset(l_mct_offset_data ,0,(p_tcp->m_nb_max_mct_records - p_tcp->m_nb_mct_records) * sizeof(opj_mct_data_t));
+
+ if (l_mct_deco_data) {
+ l_mct_deco_data = l_mct_offset_data - 1;
+ }
+ }
+
+ l_mct_offset_data = p_tcp->m_mct_records + p_tcp->m_nb_mct_records;
+
+ if (l_mct_offset_data->m_data) {
+ opj_free(l_mct_offset_data->m_data);
+ l_mct_offset_data->m_data = 00;
+ }
+
+ l_mct_offset_data->m_index = l_indix++;
+ l_mct_offset_data->m_array_type = MCT_TYPE_OFFSET;
+ l_mct_offset_data->m_element_type = MCT_TYPE_FLOAT;
+ l_nb_elem = p_image->numcomps;
+ l_mct_size = l_nb_elem * MCT_ELEMENT_SIZE[l_mct_offset_data->m_element_type];
+ l_mct_offset_data->m_data = (OPJ_BYTE*)opj_malloc(l_mct_size );
+
+ if (! l_mct_offset_data->m_data) {
+ return OPJ_FALSE;
+ }
+
+ l_data = (OPJ_FLOAT32*)opj_malloc(l_nb_elem * sizeof(OPJ_FLOAT32));
+ if (! l_data) {
+ opj_free(l_mct_offset_data->m_data);
+ l_mct_offset_data->m_data = 00;
+ return OPJ_FALSE;
+ }
+
+ l_tccp = p_tcp->tccps;
+ l_current_data = l_data;
+
+ for (i=0;i<l_nb_elem;++i) {
+ *(l_current_data++) = (OPJ_FLOAT32) (l_tccp->m_dc_level_shift);
+ ++l_tccp;
+ }
+
+ j2k_mct_write_functions_from_float[l_mct_offset_data->m_element_type](l_data,l_mct_offset_data->m_data,l_nb_elem);
+
+ opj_free(l_data);
+
+ l_mct_offset_data->m_data_size = l_mct_size;
+
+ ++p_tcp->m_nb_mct_records;
+
+ if (p_tcp->m_nb_mcc_records == p_tcp->m_nb_max_mcc_records) {
+ p_tcp->m_nb_max_mcc_records += J2K_MCT_DEFAULT_NB_RECORDS;
+ p_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*)
+ opj_realloc(p_tcp->m_mcc_records,p_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t));
+
+ if (! p_tcp->m_mcc_records) {
+ return OPJ_FALSE;
+ }
+ l_mcc_data = p_tcp->m_mcc_records + p_tcp->m_nb_mcc_records;
+ memset(l_mcc_data ,0,(p_tcp->m_nb_max_mcc_records - p_tcp->m_nb_mcc_records) * sizeof(opj_simple_mcc_decorrelation_data_t));
+
+ }
+
+ l_mcc_data = p_tcp->m_mcc_records + p_tcp->m_nb_mcc_records;
+ l_mcc_data->m_decorrelation_array = l_mct_deco_data;
+ l_mcc_data->m_is_irreversible = 1;
+ l_mcc_data->m_nb_comps = p_image->numcomps;
+ l_mcc_data->m_index = l_indix++;
+ l_mcc_data->m_offset_array = l_mct_offset_data;
+ ++p_tcp->m_nb_mcc_records;
+
+ return OPJ_TRUE;
+}
+
/**
* Builds the cp decoder parameters to use to decode tile.
*/
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_MHSOC;
/* Try to read the SOC marker, the codestream must begin with SOC marker */
- if (! j2k_read_soc_v2(p_j2k,p_stream,p_manager)) {
+ if (! opj_j2k_read_soc(p_j2k,p_stream,p_manager)) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Expected a SOC marker \n");
return OPJ_FALSE;
}
/* If we didn't skip data before, we need to read the SOD marker*/
if (! p_j2k->m_specific_param.m_decoder.m_skip_data) {
/* Try to read the SOD marker and skip data ? FIXME */
- if (! j2k_read_sod_v2(p_j2k, p_stream, p_manager)) {
+ if (! opj_j2k_read_sod(p_j2k, p_stream, p_manager)) {
return OPJ_FALSE;
}
/* Check if the positions provided by the user are correct */
/* Left */
- assert(p_start_x > 0 );
- assert(p_start_y > 0 );
+ assert(p_start_x >= 0 );
+ assert(p_start_y >= 0 );
if ((OPJ_UINT32)p_start_x > l_image->x1 ) {
opj_event_msg_v2(p_manager, EVT_ERROR,
*
* @return a handle to a J2K decompressor if successful, NULL otherwise.
*/
-opj_j2k_v2_t* j2k_create_decompress_v2(void)
+opj_j2k_v2_t* opj_j2k_create_decompress(void)
{
opj_j2k_v2_t *l_j2k = (opj_j2k_v2_t*) opj_malloc(sizeof(opj_j2k_v2_t));
if (!l_j2k) {
if (cstr_index->tile_index){
- fprintf(out_stream, "\t Tile index: {\n");
-
- for (it_tile=0; it_tile < cstr_index->nb_of_tiles ; it_tile++){
- OPJ_UINT32 nb_of_tile_part = cstr_index->tile_index[it_tile].nb_tps;
-
- fprintf(out_stream, "\t\t nb of tile-part in tile [%d]=%d\n", it_tile, nb_of_tile_part);
-
- if (cstr_index->tile_index[it_tile].tp_index){
- for (it_tile_part =0; it_tile_part < nb_of_tile_part; it_tile_part++){
- fprintf(out_stream, "\t\t\t tile-part[%d]: star_pos=%" PRIi64 ", end_header=%" PRIi64 ", end_pos=%" PRIi64 ".\n",
- it_tile_part,
- cstr_index->tile_index[it_tile].tp_index[it_tile_part].start_pos,
- cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_header,
- cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_pos);
- }
- }
- if (cstr_index->tile_index[it_tile].marker){
- for (it_marker=0; it_marker < cstr_index->tile_index[it_tile].marknum ; it_marker++){
- fprintf(out_stream, "\t\t type=%#x, pos=%" PRIi64 ", len=%d\n",
- cstr_index->tile_index[it_tile].marker[it_marker].type,
- cstr_index->tile_index[it_tile].marker[it_marker].pos,
- cstr_index->tile_index[it_tile].marker[it_marker].len );
- }
- }
- }
- fprintf(out_stream,"\t }\n");
+ /* Simple test to avoid to write empty information*/
+ OPJ_UINT32 l_acc_nb_of_tile_part = 0;
+ for (it_tile=0; it_tile < cstr_index->nb_of_tiles ; it_tile++){
+ l_acc_nb_of_tile_part += cstr_index->tile_index[it_tile].nb_tps;
+ }
+
+ if (l_acc_nb_of_tile_part)
+ {
+ fprintf(out_stream, "\t Tile index: {\n");
+
+ for (it_tile=0; it_tile < cstr_index->nb_of_tiles ; it_tile++){
+ OPJ_UINT32 nb_of_tile_part = cstr_index->tile_index[it_tile].nb_tps;
+
+ fprintf(out_stream, "\t\t nb of tile-part in tile [%d]=%d\n", it_tile, nb_of_tile_part);
+
+ if (cstr_index->tile_index[it_tile].tp_index){
+ for (it_tile_part =0; it_tile_part < nb_of_tile_part; it_tile_part++){
+ fprintf(out_stream, "\t\t\t tile-part[%d]: star_pos=%" PRIi64 ", end_header=%" PRIi64 ", end_pos=%" PRIi64 ".\n",
+ it_tile_part,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].start_pos,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_header,
+ cstr_index->tile_index[it_tile].tp_index[it_tile_part].end_pos);
+ }
+ }
+
+ if (cstr_index->tile_index[it_tile].marker){
+ for (it_marker=0; it_marker < cstr_index->tile_index[it_tile].marknum ; it_marker++){
+ fprintf(out_stream, "\t\t type=%#x, pos=%" PRIi64 ", len=%d\n",
+ cstr_index->tile_index[it_tile].marker[it_marker].type,
+ cstr_index->tile_index[it_tile].marker[it_marker].pos,
+ cstr_index->tile_index[it_tile].marker[it_marker].len );
+ }
+ }
+ }
+ fprintf(out_stream,"\t }\n");
+ }
}
fprintf(out_stream,"}\n");
}
l_max_data_size = 1000;
- /*Allocate and initialize some elements of codestrem index*/
- if (!j2k_allocate_tile_element_cstr_index(p_j2k)){
- opj_free(l_current_data);
- return OPJ_FALSE;
- }
+
while (OPJ_TRUE) {
if (! j2k_read_tile_header( p_j2k,
if(l_current_tile_no == l_tile_no_to_dec)
{
/* move into the codestream to the the first SOT (FIXME or not move?)*/
- if (opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) {
+ if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) ) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Problem with seek function\n");
return OPJ_FALSE;
}
/**
* Decodes the tiles of the stream.
*/
-opj_bool j2k_decode_v2( opj_j2k_v2_t * p_j2k,
+opj_bool opj_j2k_decode(opj_j2k_v2_t * p_j2k,
opj_stream_private_t * p_stream,
opj_image_t * p_image,
opj_event_mgr_t * p_manager)
assert(p_stream != 00);
assert(p_manager != 00);
- p_j2k->m_private_image = p_image;
+ p_j2k->m_private_image = opj_image_create0();
+ opj_copy_image_header(p_image, p_j2k->m_private_image);
+
+ // TODO_MSD: Find a better way
+ if (p_image->comps) {
+ OPJ_UINT32 it_comp;
+ for (it_comp = 0 ; it_comp < p_image->numcomps; it_comp++) {
+ if (p_image->comps[it_comp].data) {
+ p_j2k->m_private_image->comps[it_comp].data =p_image->comps[it_comp].data;
+ p_image->comps[it_comp].data = NULL;
+
+ }
+ }
+ }
/* customization of the validation */
j2k_setup_encoding_validation (p_j2k);
l_current_data = p_j2k->m_specific_param.m_encoder.m_encoded_tile_data;
if (! tcd_copy_tile_data(l_tcd,p_data,p_data_size)) {
- opj_event_msg_v2(p_manager, EVT_ERROR, "Size mismtach between tile data and sent data." );
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Size mismatch between tile data and sent data." );
return OPJ_FALSE;
}
l_available_data -= l_nb_bytes_written;
l_nb_bytes_written = l_tile_size - l_available_data;
- if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_encoded_tile_data,l_nb_bytes_written,p_manager) != l_nb_bytes_written) {
+ if ( opj_stream_write_data( p_stream,
+ p_j2k->m_specific_param.m_encoder.m_encoded_tile_data,
+ l_nb_bytes_written,p_manager) != l_nb_bytes_written) {
return OPJ_FALSE;
}
assert(p_j2k != 00);
/* DEVELOPER CORNER, insert your custom procedures */
- opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_eoc );
+ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_eoc_v2 );
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) {
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_updated_tlm);
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) {
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_image_components );
- opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_tlm );
+ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_tlm_v2 );
if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == CINEMA4K_24) {
- opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_poc );
+ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_poc_v2 );
}
}
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_regions);
if (p_j2k->m_cp.comment != 00) {
- opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_com);
+ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)j2k_write_com_v2);
}
/* DEVELOPER CORNER, insert your custom procedures */
opj_event_mgr_t * p_manager )
{
if (! j2k_pre_write_tile(p_j2k,p_tile_index,p_stream,p_manager)) {
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error while j2k_pre_write_tile with tile index = %d\n", p_tile_index);
return OPJ_FALSE;
}
+ else {
+ if (! j2k_post_write_tile(p_j2k,p_data,p_data_size,p_stream,p_manager)) {
+ opj_event_msg_v2(p_manager, EVT_ERROR, "Error while j2k_post_write_tile with tile index = %d\n", p_tile_index);
+ return OPJ_FALSE;
+ }
+ }
- return j2k_post_write_tile(p_j2k,p_data,p_data_size,p_stream,p_manager);
+ return OPJ_TRUE;
}