[trunk] add test_tile_encoder test and function related

This commit is contained in:
Mickael Savinaud 2012-03-23 17:47:53 +00:00
parent b9d271c1a8
commit 855b5b513d
9 changed files with 721 additions and 1 deletions

View File

@ -195,3 +195,40 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
return;
}
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
OPJ_UINT32 compno;
opj_image_t *image = 00;
image = (opj_image_t*) opj_malloc(sizeof(opj_image_t));
if
(image)
{
memset(image,0,sizeof(opj_image_t));
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
if
(!image->comps)
{
opj_image_destroy(image);
return 00;
}
memset(image->comps,0,image->numcomps * sizeof(opj_image_comp_t));
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0;
}
}
return image;
}

View File

@ -1288,6 +1288,25 @@ static opj_bool j2k_write_epc( opj_j2k_v2_t *p_j2k,
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.
*
@ -1671,6 +1690,120 @@ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
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;
@ -7833,6 +7966,322 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
}
}
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(!p_j2k || !parameters || ! image) {
return;
}
/* keep a link to cp so that we can destroy it later in j2k_destroy_compress */
cp = &(p_j2k->m_cp);
/* set default values for cp */
cp->tw = 1;
cp->th = 1;
/*
copy user encoding parameters
*/
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->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(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->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->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_INT32 i;
/* set JPWL on */
cp->epc_on = true;
cp->info_on = false; /* no informative technique */
/* set EPB on */
if ((parameters->jpwl_hprot_MH > 0) || (parameters->jpwl_hprot_TPH[0] > 0)) {
cp->epb_on = 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 = 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 = false;
} else {
cp->epc_on = false;
}
#endif /* USE_JPWL */
/* initialize the mutiple tiles */
/* ---------------------------- */
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_v2_t *tcp = &cp->tcps[tileno];
tcp->numlayers = parameters->tcp_numlayers;
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->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;
numpocs_tile = 0;
tcp->POC = 0;
if (parameters->numpocs) {
/* initialisation of POC */
tcp->POC = 1;
// 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->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));
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->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;
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
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;
for (j = tccp->numresolutions - 1; 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;
}
}
}
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;
@ -8291,6 +8740,140 @@ opj_bool j2k_mct_validation ( opj_j2k_v2_t * p_j2k,
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.
*/

View File

@ -842,6 +842,12 @@ Coding parameters are returned in j2k->cp.
@param image input filled image
*/
void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_t *image);
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);
/**
Converts an enum type progression order to string type
*/
@ -1067,5 +1073,7 @@ opj_bool j2k_end_compress( opj_j2k_v2_t *p_j2k,
opj_stream_private_t *cio,
struct opj_event_mgr * p_manager);
opj_bool j2k_setup_mct_encoding (opj_tcp_v2_t * p_tcp, opj_image_t * p_image);
#endif /* __J2K_H */

View File

@ -309,3 +309,25 @@ opj_bool mct_decode_custom(
opj_free(lCurrentData);
return OPJ_TRUE;
}
void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 pNbComps,
OPJ_FLOAT32 * pMatrix)
{
OPJ_UINT32 i,j,lIndex;
OPJ_FLOAT32 lCurrentValue;
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
for (i=0;i<pNbComps;++i) {
lNorms[i] = 0;
lIndex = i;
for (j=0;j<pNbComps;++j) {
lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue;
}
lNorms[i] = sqrt(lNorms[i]);
}
}

View File

@ -116,6 +116,8 @@ opj_bool mct_decode_custom(
/* tells if the data is signed */
OPJ_UINT32 isSigned);
void opj_calculate_norms(OPJ_FLOAT64 * pNorms,OPJ_UINT32 p_nb_comps,OPJ_FLOAT32 * pMatrix);
const OPJ_FLOAT64 * get_mct_norms ();
const OPJ_FLOAT64 * get_mct_norms_real ();
/* ----------------------------------------------------------------------- */

View File

@ -589,7 +589,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress_v2(OPJ_CODEC_FORMAT p_format)
l_info->m_codec_data.m_compression.opj_setup_encoder = (void (*) ( void *,
opj_cparameters_t *,
struct opj_image *,
struct opj_event_mgr * )) j2k_setup_encoder;
struct opj_event_mgr * )) j2k_setup_encoder_v2;
l_info->m_codec = j2k_create_compress_v2();
if (! l_info->m_codec) {
@ -1239,5 +1239,34 @@ opj_bool OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,OPJ_FLOAT32 * pE
return OPJ_TRUE;
}
/**
* Writes a tile with the given data.
*
* @param p_compressor the jpeg2000 codec.
* @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
* @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes,
* depending on the precision of the given component.
* @param p_stream the stream to write data to.
*/
opj_bool OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_t *p_stream )
{
if (p_codec && p_stream && p_data) {
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
if (l_info->is_decompressor) {
return OPJ_FALSE;
}
return l_info->m_codec_data.m_compression.opj_write_tile(l_info->m_codec,p_tile_index,p_data,p_data_size,l_cio,l_info->m_event_mgr);
}
return OPJ_FALSE;
}

View File

@ -1042,6 +1042,18 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptp
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
/**
* Creates an image without allocating memory for the image (used in the new version of the library).
*
* @param p_num_cmpts the number of components
* @param p_cmpt_parms the components parameters
* @param p_clr_spc the image color space
*
* @return a new image structure if successful, NULL otherwise.
*/
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
/*
==========================================================
stream functions definitions
@ -1315,6 +1327,25 @@ OPJ_API opj_bool OPJ_CALLCONV opj_get_decoded_tile( opj_codec_t *p_codec,
OPJ_API opj_bool OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
/**
* Writes a tile with the given data.
*
* @param p_compressor the jpeg2000 codec.
* @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
* @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes,
* depending on the precision of the given component.
* @param p_stream the stream to write data to.
*
* @return true if the data could be written.
*/
OPJ_API opj_bool OPJ_CALLCONV opj_write_tile ( opj_codec_t *p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_t *p_stream );
/**
* Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.

View File

@ -39,6 +39,9 @@ TARGET_LINK_LIBRARIES(j2k_random_tile_access ${OPENJPEG_LIBRARY_NAME})
ADD_EXECUTABLE(compareRAWimages ${compareRAWimages_SRCS})
ADD_EXECUTABLE(test_tile_encoder test_tile_encoder.c)
TARGET_LINK_LIBRARIES(test_tile_encoder ${OPENJPEG_LIBRARY_NAME})
# No image send to the dashboard if lib PNG is not available.
IF(NOT HAVE_LIBPNG)
MESSAGE(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)")

View File

@ -317,3 +317,8 @@ FOREACH(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST})
ENDFOREACH(OPJ_TEST_CMD_LINE)
# Encode an image into the jpeg2000 format
ADD_TEST(test_tile_encoder
${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder
)