- /* Initialization for PPM marker */
- cp.ppm = 0;
- cp.ppm_data = NULL;
- cp.ppm_data_first = NULL;
- cp.ppm_previous = 0;
- cp.ppm_store = 0;
-
- /* Init the mutiple tiles */
- /* ---------------------- */
- cp.tcps = (j2k_tcp_t *) malloc(cp.tw * cp.th * sizeof(j2k_tcp_t));
-
- for (tileno = 0; tileno < cp.tw * cp.th; tileno++) {
- tcp = &cp.tcps[tileno];
- tcp->numlayers = tcp_init->numlayers;
- for (j = 0; j < tcp->numlayers; j++) {
- if (cp.fixed_quality) /* add fixed_quality*/
- tcp->distoratio[j] = tcp_init->distoratio[j];
- else
- tcp->rates[j] = tcp_init->rates[j];
- }
- tcp->csty = CSty;
- tcp->prg = Prog_order;
- tcp->mct = img.numcomps == 3 ? 1 : 0;
- tcp->ppt = 0;
- tcp->ppt_data = NULL;
- tcp->ppt_data_first = NULL;
- tcp->ppt_store = 0;
-
- numpocs_tile = 0;
- tcp->POC = 0;
- if (numpocs) {
- /* intialisation of POC */
- tcp->POC = 1;
- for (i = 0; i < numpocs; i++) {
- if (tileno == POC[i].tile - 1 || POC[i].tile == -1) {
- tcp_poc = &tcp->pocs[numpocs_tile];
- tcp_poc->resno0 = POC[numpocs_tile].resno0;
- tcp_poc->compno0 = POC[numpocs_tile].compno0;
- tcp_poc->layno1 = POC[numpocs_tile].layno1;
- tcp_poc->resno1 = POC[numpocs_tile].resno1;
- tcp_poc->compno1 = POC[numpocs_tile].compno1;
- tcp_poc->prg = POC[numpocs_tile].prg;
- tcp_poc->tile = POC[numpocs_tile].tile;
- numpocs_tile++;
- }
- }
- }
- tcp->numpocs = numpocs_tile;
- tcp->tccps = (j2k_tccp_t *) malloc(img.numcomps * sizeof(j2k_tccp_t));
-
- for (i = 0; i < img.numcomps; i++) {
- tccp = &tcp->tccps[i];
- tccp->csty = CSty & 0x01; /* 0 => one precinct || 1 => custom precinct */
- tccp->numresolutions = NumResolution;
- tccp->cblkw = int_floorlog2(cblockw_init);
- tccp->cblkh = int_floorlog2(cblockh_init);
- tccp->cblksty = mode;
- tccp->qmfbid = ir ? 0 : 1;
- tccp->qntsty = ir ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
- tccp->numgbits = 2;
- if (i == ROI_compno)
- tccp->roishift = ROI_shift;
- else
- tccp->roishift = 0;
- if (CSty & J2K_CCP_CSTY_PRT) {
- int p = 0;
- for (j = tccp->numresolutions - 1; j >= 0; j--) {
- if (p < res_spec) {
- if (prcw_init[p] < 1)
- tccp->prcw[j] = 1;
- else
- tccp->prcw[j] = int_floorlog2(prcw_init[p]);
-
- if (prch_init[p] < 1)
- tccp->prch[j] = 1;
- else
- tccp->prch[j] = int_floorlog2(prch_init[p]);
- } else {
- int size_prcw, size_prch;
- size_prcw = prcw_init[res_spec - 1] >> (p - (res_spec - 1));
- size_prch = 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 pour 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;
- }
- }
- calc_explicit_stepsizes(tccp, img.comps[i].prec);
- }
+/* -------------------------------------------------------------------------- */
+
+int main(int argc, char **argv) {
+ bool bSuccess;
+ bool delete_comment = true;
+ opj_cparameters_t parameters; /* compression parameters */
+ opj_event_mgr_t event_mgr; /* event manager */
+ opj_image_t *image = NULL;
+
+ /*
+ configure the event callbacks (not required)
+ setting of each callback is optionnal
+ */
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = error_callback;
+ event_mgr.warning_handler = warning_callback;
+ event_mgr.info_handler = info_callback;
+
+ /* set encoding parameters to default values */
+ opj_set_default_encoder_parameters(¶meters);
+
+ /* parse input and get user encoding parameters */
+ if(parse_cmdline_encoder(argc, argv, ¶meters) == 1) {
+ return 0;