diff --git a/ChangeLog b/ChangeLog index 3c691460..09530617 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ What's New for OpenJPEG ! : changed + : added +May 4, 2007 +* [FOD] Bugs corrected in decoding of command line (getopt.c), in the handling of 16 bit files (t1.c and tcd.c) and the calculation of elapsed time for multiple tiles parts (tcd.c and tdc.h). + June 2, 2007 + [GB] OPJViewer opens now BMP, PNG, GIF, PNM, TIFF (with wxWidgets internals); added an encoder settings tab, for future integration with "save file as..." in JPEG 2000 format diff --git a/codec/compat/getopt.c b/codec/compat/getopt.c index 3ecbde15..1491bf03 100644 --- a/codec/compat/getopt.c +++ b/codec/compat/getopt.c @@ -129,11 +129,27 @@ struct option *longopts, int totlen) { static int lastidx,lastofs; char *tmp; int i,len; + char param = 1; + again: - if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0) + if (optind>argc || !argv[optind] || *argv[optind]!='-') return -1; if (argv[optind][0]=='-' && argv[optind][1]==0) { + if(optind >= (argc - 1)){ /* no more input parameters */ + param = 0; + } + else{ /* more input parameters */ + if(argv[optind + 1][0] == '-'){ + param = 0; /* Missing parameter after '-' */ + } + else{ + param = 2; + } + } + } + + if (param == 0) { ++optind; return (BADCH); } @@ -144,11 +160,18 @@ again: o=longopts; len=sizeof(longopts[0]); + if (param > 1){ + arg = argv[optind+1]; + optind++; + } + else + arg = argv[optind]+1; + if(strlen(arg)>1){ for (i=0;iname,arg)) { /* match */ if (o->has_arg == 0) { - if (!(argv[optind+1][0]=='-')){ + if ((argv[optind+1])&&(!(argv[optind+1][0]=='-'))){ fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[optind+1]); ++optind; } diff --git a/codec/convert.c b/codec/convert.c index 936d5a48..4aafaae8 100644 --- a/codec/convert.c +++ b/codec/convert.c @@ -1278,7 +1278,7 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters) /* initialize image components*/ memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); for(j = 0; j < numcomps; j++) { - if ((parameters->cp_cinema) & (Info.tiBps== 16)){ + if (parameters->cp_cinema) { cmptparm[j].prec = 12; cmptparm[j].bpp = 12; }else{ @@ -1335,7 +1335,7 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters) image->comps[0].data[index] = (image->comps[0].data[index] + 0x08) >> 4 ; image->comps[1].data[index] = (image->comps[1].data[index] + 0x08) >> 4 ; image->comps[2].data[index] = (image->comps[2].data[index] + 0x08) >> 4 ; - } + } index++; } } @@ -1344,6 +1344,11 @@ opj_image_t* tiftoimage(char *filename, opj_cparameters_t *parameters) image->comps[0].data[index] = dat8[i+0]; // R image->comps[1].data[index] = dat8[i+1]; // G image->comps[2].data[index] = dat8[i+2]; // B + if(parameters->cp_cinema){/* Rounding to 12 bits*/ + image->comps[0].data[index] = image->comps[0].data[index] << 4 ; + image->comps[1].data[index] = image->comps[1].data[index] << 4 ; + image->comps[2].data[index] = image->comps[2].data[index] << 4 ; + } index++; } } diff --git a/codec/image_to_j2k.c b/codec/image_to_j2k.c index d54fe383..24276028 100644 --- a/codec/image_to_j2k.c +++ b/codec/image_to_j2k.c @@ -483,7 +483,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){ parameters->numresolution = 6; } if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){ - fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nDCI 2K compliance requires that atleast one of coordinates match 2048 x 1080\n",image->comps[0].w,image->comps[0].h); + fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 (2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",image->comps[0].w,image->comps[0].h); parameters->cp_rsiz = STD_RSIZ; } break; @@ -495,7 +495,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){ parameters->numresolution = 7; } if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){ - fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nDCI 4K compliance requires that atleast one of coordinates match 4096 x 2160\n",image->comps[0].w,image->comps[0].h); + fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\JPEG Digital Cinema Profile-4 (4K profile) compliance requires that atleast one of coordinates match 4096 x 2160\n",image->comps[0].w,image->comps[0].h); parameters->cp_rsiz = STD_RSIZ; } parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); diff --git a/libopenjpeg/t1.c b/libopenjpeg/t1.c index 8f8a7eeb..b5d95994 100644 --- a/libopenjpeg/t1.c +++ b/libopenjpeg/t1.c @@ -1086,7 +1086,7 @@ void t1_encode_cblks( t1->data[(j * t1->w) + i] = fix_mul( tilec->data[x + i + (y + j) * w], - 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); + 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (11 - T1_NMSEDEC_FRACBITS); } } } diff --git a/libopenjpeg/tcd.c b/libopenjpeg/tcd.c index 06f021b3..525ec91d 100644 --- a/libopenjpeg/tcd.c +++ b/libopenjpeg/tcd.c @@ -1107,7 +1107,6 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_image_info_t * image_info) { int compno; int l, i, npck = 0; - double encoding_time; opj_tcd_tile_t *tile = NULL; opj_tcp_t *tcd_tcp = NULL; opj_cp_t *cp = NULL; @@ -1127,104 +1126,105 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op tcd_tcp = tcd->tcp; cp = tcd->cp; - encoding_time = opj_clock(); /* time needed to encode a tile */ if(tcd->cur_tp_num == 0){ - /* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */ - if(image_info && image_info->index_on) { - opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ - for (i = 0; i < tilec_idx->numresolutions; i++) { - opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; - - image_info->tile[tileno].pw[i] = res_idx->pw; - image_info->tile[tileno].ph[i] = res_idx->ph; - - npck += res_idx->pw * res_idx->ph; - - image_info->tile[tileno].pdx[i] = tccp->prcw[i]; - image_info->tile[tileno].pdy[i] = tccp->prch[i]; + tcd->encoding_time = opj_clock(); /* time needed to encode a tile */ + /* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */ + if(image_info && image_info->index_on) { + opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ + for (i = 0; i < tilec_idx->numresolutions; i++) { + opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; + + image_info->tile[tileno].pw[i] = res_idx->pw; + image_info->tile[tileno].ph[i] = res_idx->ph; + + npck += res_idx->pw * res_idx->ph; + + image_info->tile[tileno].pdx[i] = tccp->prcw[i]; + image_info->tile[tileno].pdy[i] = tccp->prch[i]; + } + image_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(image_info->comp * image_info->layer * npck * sizeof(opj_packet_info_t)); } - image_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(image_info->comp * image_info->layer * npck * sizeof(opj_packet_info_t)); - } - /* << INDEX */ - - /*---------------TILE-------------------*/ - - for (compno = 0; compno < tile->numcomps; compno++) { - int x, y; - - int adjust = image->comps[compno].sgnd ? 0 : 1 << (image->comps[compno].prec - 1); - int offset_x = int_ceildiv(image->x0, image->comps[compno].dx); - int offset_y = int_ceildiv(image->y0, image->comps[compno].dy); + /* << INDEX */ - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - int tw = tilec->x1 - tilec->x0; - int w = int_ceildiv(image->x1 - image->x0, image->comps[compno].dx); - - /* extract tile data */ - - if (tcd_tcp->tccps[compno].qmfbid == 1) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = *data++ - adjust; + /*---------------TILE-------------------*/ + + for (compno = 0; compno < tile->numcomps; compno++) { + int x, y; + + int adjust = image->comps[compno].sgnd ? 0 : 1 << (image->comps[compno].prec - 1); + int offset_x = int_ceildiv(image->x0, image->comps[compno].dx); + int offset_y = int_ceildiv(image->y0, image->comps[compno].dy); + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + int tw = tilec->x1 - tilec->x0; + int w = int_ceildiv(image->x1 - image->x0, image->comps[compno].dx); + + /* extract tile data */ + + if (tcd_tcp->tccps[compno].qmfbid == 1) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = *data++ - adjust; + } } - } - } else if (tcd_tcp->tccps[compno].qmfbid == 0) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = (*data++ - adjust) << 13; + } else if (tcd_tcp->tccps[compno].qmfbid == 0) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &image->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = (*data++ - adjust) << 11; + } + } } } - } - - /*----------------MCT-------------------*/ - if (tcd_tcp->mct) { - int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); - if (tcd_tcp->tccps[0].qmfbid == 0) { - mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + + /*----------------MCT-------------------*/ + if (tcd_tcp->mct) { + int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0); + if (tcd_tcp->tccps[0].qmfbid == 0) { + mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } else { + mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } + } + + /*----------------DWT---------------------*/ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + if (tcd_tcp->tccps[compno].qmfbid == 1) { + dwt_encode(tilec); + } else if (tcd_tcp->tccps[compno].qmfbid == 0) { + dwt_encode_real(tilec); + } + } + + /*------------------TIER1-----------------*/ + t1 = t1_create(tcd->cinfo); + t1_encode_cblks(t1, tile, tcd_tcp); + t1_destroy(t1); + + /*-----------RATE-ALLOCATE------------------*/ + + /* INDEX */ + if(image_info) { + image_info->index_write = 0; + } + if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */ + /* Normal Rate/distortion allocation */ + tcd_rateallocate(tcd, dest, len, image_info); } else { - mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + /* Fixed layer allocation */ + tcd_rateallocate_fixed(tcd); } } - - /*----------------DWT---------------------*/ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - if (tcd_tcp->tccps[compno].qmfbid == 1) { - dwt_encode(tilec); - } else if (tcd_tcp->tccps[compno].qmfbid == 0) { - dwt_encode_real(tilec); - } - } - - /*------------------TIER1-----------------*/ - t1 = t1_create(tcd->cinfo); - t1_encode_cblks(t1, tile, tcd_tcp); - t1_destroy(t1); - - /*-----------RATE-ALLOCATE------------------*/ - - /* INDEX */ - if(image_info) { - image_info->index_write = 0; - } - if (cp->disto_alloc || cp->fixed_quality) { /* fixed_quality */ - /* Normal Rate/distortion allocation */ - tcd_rateallocate(tcd, dest, len, image_info); - } else { - /* Fixed layer allocation */ - tcd_rateallocate_fixed(tcd); - } - } /*--------------TIER2------------------*/ /* INDEX */ @@ -1240,8 +1240,8 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){ - encoding_time = opj_clock() - encoding_time; - opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", encoding_time); + tcd->encoding_time = opj_clock() - tcd->encoding_time; + opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", tcd->encoding_time); /* cleaning memory */ for (compno = 0; compno < tile->numcomps; compno++) { diff --git a/libopenjpeg/tcd.h b/libopenjpeg/tcd.h index b81a94a6..ae667098 100644 --- a/libopenjpeg/tcd.h +++ b/libopenjpeg/tcd.h @@ -183,6 +183,8 @@ typedef struct opj_tcd { opj_tcp_t *tcp; /** current encoded/decoded tile */ int tcd_tileno; + /** Time taken to encode a tile*/ + double encoding_time; } opj_tcd_t; /** @name Exported functions */