Logo Search packages:      
Sourcecode: gdcm version File versions

void j2k_setup_encoder ( opj_j2k_t j2k,
opj_cparameters_t parameters,
opj_image_t image 
)

Setup the encoder parameters using the current image and using user parameters. Coding parameters are returned in j2k->cp.

Parameters:
j2k J2K compressor handle
parameters compression parameters
image input filled image

Definition at line 1409 of file j2k.c.

References opj_tccp::cblkh, opj_tccp::cblksty, opj_tccp::cblkw, opj_cparameters::cblockh_init, opj_cparameters::cblockw_init, opj_cp::comment, opj_poc::compno0, opj_poc::compno1, opj_image::comps, opj_j2k::cp, opj_cparameters::cp_comment, opj_cparameters::cp_disto_alloc, opj_cparameters::cp_fixed_alloc, opj_cparameters::cp_fixed_quality, opj_cparameters::cp_matrice, opj_cparameters::cp_tdx, opj_cparameters::cp_tdy, opj_cparameters::cp_tx0, opj_cparameters::cp_ty0, opj_tccp::csty, opj_cparameters::csty, opj_tcp::csty, opj_cp::disto_alloc, opj_tcp::distoratio, dwt_calc_explicit_stepsizes(), opj_cp::fixed_alloc, opj_cp::fixed_quality, opj_j2k::image_info, opj_cparameters::index_on, opj_cp::index_on, int_ceildiv(), int_floorlog2(), opj_cparameters::irreversible, opj_poc::layno1, opj_cp::matrice, opj_tcp::mct, opj_cparameters::mode, opj_image::numcomps, opj_tccp::numgbits, opj_tcp::numlayers, opj_tcp::numpocs, opj_cparameters::numpocs, opj_cparameters::numresolution, opj_tccp::numresolutions, opj_malloc(), opj_cparameters::POC, opj_tcp::POC, opj_tcp::pocs, opj_tccp::prch, opj_cparameters::prch_init, opj_tccp::prcw, opj_cparameters::prcw_init, opj_image_comp::prec, opj_poc::prg, opj_tcp::prg, opj_cparameters::prog_order, opj_tccp::qmfbid, opj_tccp::qntsty, opj_tcp::rates, opj_cparameters::res_spec, opj_poc::resno0, opj_poc::resno1, opj_cparameters::roi_compno, opj_cparameters::roi_shift, opj_tccp::roishift, opj_tcp::tccps, opj_cparameters::tcp_distoratio, opj_cparameters::tcp_numlayers, opj_cparameters::tcp_rates, opj_cp::tcps, opj_cp::tdx, opj_cp::tdy, opj_cp::th, opj_poc::tile, opj_cparameters::tile_size_on, opj_cp::tw, opj_cp::tx0, opj_cp::ty0, opj_image::x1, and opj_image::y1.

Referenced by jp2_setup_encoder().

                                                                                          {
      int i, j, 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_malloc(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->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);
      }

      /* creation of an index file ? */
      cp->index_on = parameters->index_on;
      if(cp->index_on) {
            j2k->image_info = (opj_image_info_t*)opj_malloc(sizeof(opj_image_info_t));
      }

      /* 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;
      }

      /* initialize the mutiple tiles */
      /* ---------------------------- */
      cp->tcps = (opj_tcp_t *) opj_malloc(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;
            for (j = 0; j < tcp->numlayers; j++) {
                  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 = image->numcomps == 3 ? 1 : 0;

            numpocs_tile = 0;
            tcp->POC = 0;
            if (parameters->numpocs) {
                  /* initialisation of POC */
                  tcp->POC = 1;
                  for (i = 0; i < 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->prg            = parameters->POC[numpocs_tile].prg;
                              tcp_poc->tile           = parameters->POC[numpocs_tile].tile;
                              numpocs_tile++;
                        }
                  }
            }
            tcp->numpocs = numpocs_tile;

            tcp->tccps = (opj_tccp_t *) opj_malloc(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;
                  if (i == parameters->roi_compno) {
                        tccp->roishift = parameters->roi_shift;
                  } else {
                        tccp->roishift = 0;
                  }
                  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]); */
                        }
                  } 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);
            }
      }
}


Generated by  Doxygen 1.6.0   Back to index