- /* 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;
- }
- }
- }
-
- dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec);
- }
- }
-}
-
-void opj_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 = 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_v2_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_v2_t));
- if (parameters->numpocs) {
- /* initialisation of POC */
- l_res = opj_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];
- }
-
- opj_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) {
- 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[it_res] = 1;
- } else {
- tccp->prcw[it_res] = int_floorlog2(parameters->prcw_init[p]);
- }
-
- if (parameters->prch_init[p] < 1) {
- tccp->prch[it_res] = 1;
- }else {
- 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[it_res] = 1;
- } else {
- tccp->prcw[it_res] = int_floorlog2(size_prcw);
- }
-
- if (size_prch < 1) {
- tccp->prch[it_res] = 1;
- } else {
- tccp->prch[it_res] = int_floorlog2(size_prch);
- }
- }
- p++;
- /*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;
- 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;
- }
-}