Enable accepting file names with `-´ symbol .Modification getopt.c

Rsiz profile name generation to be STD_RSIZ for profiles which are not DCI compliant.Modification in image_to_j2k.c
Renamed convert_progression_order to j2k_convert_progression_order. Modification j2k.c
Calculation of number of tile part in each tile in j2k_calculate_tp. Modification j2k.c
j2k_setup_encoder to set bit rate limitation for digital cinema compliance with quality option. Modification in j2k.c
Equation to check multiple tile precincts. Modification pi.c
array size generation of pi->include in pi_initialise_encode().Modification in pi.c
Modification in pi_create_encode for tile part generation.Modification in pi.c
In tcd_rateallocate a variable stable_threshold which holds the valid threshold value. This is used to avoid error in case of a wrong threshold value in the last iteration. Modification in tcd.c.
This commit is contained in:
Parvatha Elangovan 2007-03-29 14:15:14 +00:00
parent a1fe5809a4
commit 9ba672366e
13 changed files with 182 additions and 124 deletions

View File

@ -5,6 +5,17 @@ What's New for OpenJPEG
! : changed ! : changed
+ : added + : added
March 29, 2007
* [Parvatha] Enable accepting file names with `-´ symbol .Modification getopt.c
* [Parvatha] Rsiz profile name generation to be STD_RSIZ for profiles which are not DCI compliant.Modification in image_to_j2k.c
! [Parvatha] renamed convert_progression_order to j2k_convert_progression_order. Modification j2k.c
* [Parvatha] Calculation of number of tile part in each tile in j2k_calculate_tp. Modification j2k.c
! [Parvatha] j2k_setup_encoder to set bit rate limitation for digital cinema compliance with quality option. Modification in j2k.c
* [Parvatha] Equation to check multiple tile precincts. Modification pi.c
! [Parvatha] array size generation of pi->include in pi_initialise_encode().Modification in pi.c
* [Parvatha] modification in pi_create_encode for tile part generation.Modification in pi.c
+ [Parvatha] In tcd_rateallocate a variable stable_threshold which holds the valid threshold value. This is used to avoid error in case of a wrong threshold value in the last iteration. Modification in tcd.c.
March 28, 2007 March 28, 2007
* [FOD] Fixed an historical bug in t1.c that leaded to the inclusion of useless 0xFF in the codestream. Thanks to Sylvain, Pascal and Parvatha ! * [FOD] Fixed an historical bug in t1.c that leaded to the inclusion of useless 0xFF in the codestream. Thanks to Sylvain, Pascal and Parvatha !

View File

@ -125,7 +125,7 @@ int getopt(int nargc, char *const *nargv, const char *ostr) {
int getopt_long(int argc, char * const argv[], const char *optstring, int getopt_long(int argc, char * const argv[], const char *optstring,
struct option *longopts, int *longindex, int totlen) { struct option *longopts, int totlen) {
static int lastidx,lastofs; static int lastidx,lastofs;
char *tmp; char *tmp;
int i,len; int i,len;
@ -147,11 +147,15 @@ again:
if(strlen(arg)>1){ if(strlen(arg)>1){
for (i=0;i<totlen;i=i+len,o++) { for (i=0;i<totlen;i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */ if (!strcmp(o->name,arg)) { /* match */
if (longindex) *longindex=o-longopts; if (o->has_arg == 0) {
if (o->has_arg>0) { if (!(argv[optind+1][0]=='-')){
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[optind+1]);
++optind;
}
}else{
optarg=argv[optind+1]; optarg=argv[optind+1];
if(optarg){ if(optarg){
if (strchr(optarg,'-')){ /* Has read next input parameter: No arg for current parameter */ if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opterr) { if (opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg); fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH); return (BADCH);
@ -160,7 +164,7 @@ again:
} }
if (!optarg && o->has_arg==1) { /* no argument there */ if (!optarg && o->has_arg==1) { /* no argument there */
if (opterr) { if (opterr) {
fprintf(stderr,"%s: option requires an argument %c\n",arg, optopt); fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH); return (BADCH);
} }
} }
@ -195,7 +199,7 @@ again:
} }
optarg=argv[optind+1]; optarg=argv[optind+1];
if(optarg){ if(optarg){
if (strchr(optarg,'-')){ /* Has read next input parameter: No arg for current parameter */ if (optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opterr) { if (opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg); fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH); return (BADCH);

View File

@ -23,7 +23,7 @@ extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr); extern int getopt(int nargc, char *const *nargv, const char *ostr);
extern int getopt_long(int argc, char * const argv[], const char *optstring, extern int getopt_long(int argc, char * const argv[], const char *optstring,
const struct option *longopts, int *longindex,int totlen); const struct option *longopts, int totlen);
#endif /* _GETOPT_H_ */ #endif /* _GETOPT_H_ */

View File

@ -450,24 +450,24 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
switch (parameters->cp_cinema){ switch (parameters->cp_cinema){
case CINEMA2K_24: case CINEMA2K_24:
case CINEMA2K_48: case CINEMA2K_48:
parameters->cp_rsiz = CINEMA2K;
if(parameters->numresolution > 6){ if(parameters->numresolution > 6){
parameters->numresolution = 6; parameters->numresolution = 6;
} }
if (!((image->comps[0].w == 2048) & (image->comps[0].h == 1080))){ if (!((image->comps[0].w == 2048) & (image->comps[0].h == 1080))){
fprintf(stdout,"Image coordinates is not 2K, %d x %d\n",image->comps[0].w,image->comps[0].h); 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);
parameters->cp_rsiz = STD_RSIZ;
} }
break; break;
case CINEMA4K_24: case CINEMA4K_24:
parameters->cp_rsiz = CINEMA4K;
if(parameters->numresolution < 1){ if(parameters->numresolution < 1){
parameters->numresolution = 1; parameters->numresolution = 1;
}else if(parameters->numresolution > 7){ }else if((parameters->numresolution < 7) || (parameters->numresolution > 7)){
parameters->numresolution = 7; parameters->numresolution = 7;
} }
if (!((image->comps[0].w == 4096) & (image->comps[0].h == 2160))){ if (!((image->comps[0].w == 4096) & (image->comps[0].h == 2160))){
fprintf(stdout,"Image coordinates is not 4K, %d x %d\n",image->comps[0].w,image->comps[0].h); 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);
parameters->cp_rsiz = STD_RSIZ;
} }
break; break;
} }
@ -493,22 +493,21 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
case CINEMA2K_48: case CINEMA2K_48:
for(i=0;i<parameters->tcp_numlayers;i++){ for(i=0;i<parameters->tcp_numlayers;i++){
temp_rate = 0 ;
if (parameters->tcp_rates[i]== 0){ if (parameters->tcp_rates[i]== 0){
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{ }else{
parameters->tcp_rates[i]=((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(parameters->tcp_rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); (parameters->tcp_rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (parameters->tcp_rates[i] > CINEMA_48_CS ){ if (temp_rate > CINEMA_48_CS ){
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
} }
} }
} }
break; break;
} }
parameters->cp_disto_alloc = 1; parameters->cp_disto_alloc = 1;
} }
@ -517,8 +516,8 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,img_fol_t *img_fol) { int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,img_fol_t *img_fol) {
int i, j,totlen; int i, j,totlen;
option_t long_option[]={ option_t long_option[]={
{"cinema2k",REQ_ARG, NULL ,'w'}, {"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4k",NO_ARG, NULL ,'y'}, {"cinema4K",NO_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'z'}, {"ImgDir",REQ_ARG, NULL ,'z'},
{"TP",REQ_ARG, NULL ,'v'}, {"TP",REQ_ARG, NULL ,'v'},
{"SOP",NO_ARG, NULL ,'S'}, {"SOP",NO_ARG, NULL ,'S'},
@ -538,7 +537,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
img_fol->set_out_format=0; img_fol->set_out_format=0;
while (1) { while (1) {
int c = getopt_long(argc, argv, optlist,long_option,NULL,totlen); int c = getopt_long(argc, argv, optlist,long_option,totlen);
/* <<UniPG */ /* <<UniPG */
if (c == -1) if (c == -1)
break; break;
@ -943,6 +942,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
return 1; return 1;
} }
fprintf(stdout,"CINEMA 2K compliant codestream\n"); fprintf(stdout,"CINEMA 2K compliant codestream\n");
parameters->cp_rsiz = CINEMA2K;
} }
break; break;
@ -953,6 +953,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
{ {
parameters->cp_cinema = CINEMA4K_24; parameters->cp_cinema = CINEMA4K_24;
fprintf(stdout,"CINEMA 4K compliant codestream\n"); fprintf(stdout,"CINEMA 4K compliant codestream\n");
parameters->cp_rsiz = CINEMA4K;
} }
break; break;
@ -1292,7 +1293,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
/* check for possible errors */ /* check for possible errors */
if (parameters->cp_cinema){ if (parameters->cp_cinema){
if(parameters->tcp_numlayers > 0){ if(parameters->tcp_numlayers > 1){
parameters->cp_rsiz = STD_RSIZ;
fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n"); fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n");
} }
} }
@ -1604,7 +1606,7 @@ int main(int argc, char **argv) {
} }
fwrite(cio->buffer, 1, codestream_length, f); fwrite(cio->buffer, 1, codestream_length, f);
fclose(f); fclose(f);
fprintf(stderr,"Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */ /* close and free the byte stream */
opj_cio_close(cio); opj_cio_close(cio);

View File

@ -240,7 +240,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
while (1) { while (1) {
int c = getopt_long(argc, argv,optlist,long_option,NULL,totlen); int c = getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
@ -678,7 +678,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} }
else { else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -687,7 +687,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} }
else { else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -696,7 +696,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} }
else { else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -705,7 +705,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} }
else { else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
} }

View File

@ -245,10 +245,10 @@ j2k_prog_order_t j2k_prog_order_list[] = {
{PCRL, "PCRL"}, {PCRL, "PCRL"},
{RLCP, "RLCP"}, {RLCP, "RLCP"},
{RPCL, "RPCL"}, {RPCL, "RPCL"},
{-1, NULL} {-1, ""}
}; };
char *convert_progression_order(OPJ_PROG_ORDER prg_order){ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
j2k_prog_order_t *po; j2k_prog_order_t *po;
for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){ for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){
if(po->enum_prog == prg_order){ if(po->enum_prog == prg_order){
@ -332,12 +332,12 @@ void j2k_dump_cp(FILE *fd, opj_image_t * img, opj_cp_t * cp) {
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){ static int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
char *prog; char *prog;
int i; int i;
int tpnum=1,tpend=0; int tpnum=1,tpend=0;
opj_tcp_t *tcp = &cp->tcps[tileno]; opj_tcp_t *tcp = &cp->tcps[tileno];
prog = convert_progression_order(tcp->prg); prog = j2k_convert_progression_order(tcp->prg);
if(cp->tp_on == 1){ if(cp->tp_on == 1){
for(i=0;i<4;i++){ for(i=0;i<4;i++){
@ -368,19 +368,22 @@ int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno){
} }
/** mem allocation for TLM marker*/ /** mem allocation for TLM marker*/
int j2k_generate_tlm(opj_cp_t *cp,int img_numcomp,opj_image_t *image ){ int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *j2k ){
int pino,tileno,maxres=0,totnum_tp=0; int pino,tileno,maxres=0,totnum_tp=0;
j2k->cur_totnum_tp = (int *) opj_malloc(cp->tw * cp->th * sizeof(int));
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
int cur_totnum_tp = 0;
opj_tcp_t *tcp = &cp->tcps[tileno]; opj_tcp_t *tcp = &cp->tcps[tileno];
for(pino = 0; pino <= tcp->numpocs; pino++) { for(pino = 0; pino <= tcp->numpocs; pino++) {
int tp_num=0; int tp_num=0;
opj_pi_iterator_t *pi = (opj_pi_iterator_t *) opj_malloc(sizeof(opj_pi_iterator_t)); opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,pino);
pi = pi_initialise_encode(image, cp, tileno,pino);
if(!pi) { return -1;} if(!pi) { return -1;}
tp_num = j2k_get_num_tp(cp,pino,tileno); tp_num = j2k_get_num_tp(cp,pino,tileno);
totnum_tp = totnum_tp + tp_num; totnum_tp = totnum_tp + tp_num;
cur_totnum_tp = cur_totnum_tp + tp_num;
pi_destroy(pi, cp, tileno); pi_destroy(pi, cp, tileno);
} }
j2k->cur_totnum_tp[tileno] = cur_totnum_tp;
} }
return totnum_tp; return totnum_tp;
} }
@ -1184,7 +1187,7 @@ static void j2k_write_sot(opj_j2k_t *j2k) {
cio_write(cio, j2k->curtileno, 2); /* Isot */ cio_write(cio, j2k->curtileno, 2); /* Isot */
cio_skip(cio, 4); /* Psot (further in j2k_write_sod) */ cio_skip(cio, 4); /* Psot (further in j2k_write_sod) */
cio_write(cio, j2k->cur_tp_num , 1); /* TPsot */ cio_write(cio, j2k->cur_tp_num , 1); /* TPsot */
cio_write(cio, j2k->cur_totnum_tp, 1); /* TNsot */ cio_write(cio, j2k->cur_totnum_tp[j2k->curtileno], 1); /* TNsot */
len = cio_tell(cio) - lenp; len = cio_tell(cio) - lenp;
cio_seek(cio, lenp); cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lsot */ cio_write(cio, len, 2); /* Lsot */
@ -1306,8 +1309,9 @@ static void j2k_write_sod(opj_j2k_t *j2k, void *tile_coder) {
opj_cp_t *cp = j2k->cp; opj_cp_t *cp = j2k->cp;
opj_cio_t *cio = j2k->cio; opj_cio_t *cio = j2k->cio;
tcd->tp_num = j2k->tp_num ;
tcd->cur_tp_num = j2k->cur_tp_num; tcd->cur_tp_num = j2k->cur_tp_num;
tcd->cur_totnum_tp = j2k->cur_totnum_tp; tcd->cur_totnum_tp = j2k->cur_totnum_tp[j2k->curtileno];
cio_write(cio, J2K_MS_SOD, 2); cio_write(cio, J2K_MS_SOD, 2);
if (j2k->curtileno == 0) { if (j2k->curtileno == 0) {
@ -2026,12 +2030,19 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
opj_tcp_t *tcp = &cp->tcps[tileno]; opj_tcp_t *tcp = &cp->tcps[tileno];
tcp->numlayers = parameters->tcp_numlayers; tcp->numlayers = parameters->tcp_numlayers;
for (j = 0; j < tcp->numlayers; j++) { for (j = 0; j < 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 */ if (cp->fixed_quality) { /* add fixed_quality */
tcp->distoratio[j] = parameters->tcp_distoratio[j]; tcp->distoratio[j] = parameters->tcp_distoratio[j];
} else { } else {
tcp->rates[j] = parameters->tcp_rates[j]; tcp->rates[j] = parameters->tcp_rates[j];
} }
} }
}
tcp->csty = parameters->csty; tcp->csty = parameters->csty;
tcp->prg = parameters->prog_order; tcp->prg = parameters->prog_order;
tcp->mct = image->numcomps == 3 ? 1 : 0; tcp->mct = image->numcomps == 3 ? 1 : 0;
@ -2432,9 +2443,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
} }
/* << INDEX */ /* << INDEX */
j2k->totnum_tp = j2k_calculate_tp(cp,image->numcomps,image,j2k);
/* TLM Marker*/ /* TLM Marker*/
if(cp->cinema){ if(cp->cinema){
j2k->totnum_tp = j2k_generate_tlm(cp,image->numcomps,image);
j2k_write_tlm(j2k); j2k_write_tlm(j2k);
} }
/**** Main Header ENDS here ***/ /**** Main Header ENDS here ***/
@ -2452,6 +2463,7 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th); opj_event_msg(j2k->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th);
j2k->curtileno = tileno; j2k->curtileno = tileno;
j2k->cur_tp_num = 0;
/* initialisation before tile encoding */ /* initialisation before tile encoding */
if (tileno == 0) { if (tileno == 0) {
@ -2469,18 +2481,14 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
for(pino = 0; pino <= tcp->numpocs; pino++) { for(pino = 0; pino <= tcp->numpocs; pino++) {
int tot_num_tp; int tot_num_tp;
opj_pi_iterator_t *pi = NULL;
tcd->cur_pino=pino; tcd->cur_pino=pino;
tcd->pi = pi_initialise_encode(image, cp, tileno,pino);
pi=tcd->pi;
/*Get number of tile parts*/ /*Get number of tile parts*/
tot_num_tp = j2k_get_num_tp(cp,pino,tileno); tot_num_tp = j2k_get_num_tp(cp,pino,tileno);
tcd->tp_pos = cp->tp_pos; tcd->tp_pos = cp->tp_pos;
for(tilepartno = 0; tilepartno < tot_num_tp ; tilepartno++){ for(tilepartno = 0; tilepartno < tot_num_tp ; tilepartno++){
j2k->cur_tp_num = tilepartno; j2k->tp_num = tilepartno;
j2k->cur_totnum_tp = tot_num_tp;
j2k_write_sot(j2k); j2k_write_sot(j2k);
if(j2k->cur_tp_num == 0 && cp->cinema == 0){ if(j2k->cur_tp_num == 0 && cp->cinema == 0){
@ -2494,8 +2502,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
} }
j2k_write_sod(j2k, tcd); j2k_write_sod(j2k, tcd);
j2k->cur_tp_num ++;
} }
pi_destroy(pi, cp, tileno);
} }
/* INDEX >> */ /* INDEX >> */
if(image_info && image_info->index_on) { if(image_info && image_info->index_on) {

View File

@ -391,10 +391,12 @@ typedef struct opj_j2k {
int state; int state;
/** number of the tile curently concern by coding/decoding */ /** number of the tile curently concern by coding/decoding */
int curtileno; int curtileno;
/** Tile part number*/
int tp_num;
/** Tilepart number currently coding*/ /** Tilepart number currently coding*/
int cur_tp_num; int cur_tp_num;
/** Total number of tileparts of the current tile*/ /** Total number of tileparts of the current tile*/
int cur_totnum_tp; int *cur_totnum_tp;
/** /**
locate the start position of the TLM marker locate the start position of the TLM marker
after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length. after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
@ -495,11 +497,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
/** /**
Converts an enum type progression order to string type Converts an enum type progression order to string type
*/ */
char *convert_progression_order(OPJ_PROG_ORDER prg_order); char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
/**
Generates the number of tile parts for the current tile
*/
int j2k_get_num_tp(opj_cp_t *cp,int pino,int tileno);
/** /**
Encode an image into a JPEG-2000 codestream Encode an image into a JPEG-2000 codestream
@param j2k J2K compressor handle @param j2k J2K compressor handle

View File

@ -113,21 +113,28 @@ braindamage below.
enum definitions enum definitions
========================================================== ==========================================================
*/ */
/**
Rsiz Capabilities
*/
typedef enum RSIZ_CAPABILITIES { typedef enum RSIZ_CAPABILITIES {
STD_RSIZ = 0, STD_RSIZ = 0, /** Standard JPEG2000 profile*/
CINEMA2K = 3, /** Profile name for a 2K image*/ CINEMA2K = 3, /** Profile name for a 2K image*/
CINEMA4K = 4 /** Profile name for a 4K image*/ CINEMA4K = 4 /** Profile name for a 4K image*/
} OPJ_RSIZ_CAPABILITIES; } OPJ_RSIZ_CAPABILITIES;
/**
Digital cinema operation mode
*/
typedef enum CINEMA_MODE { typedef enum CINEMA_MODE {
OFF = 0, OFF = 0, /** Not Digital Cinema*/
CINEMA2K_24 = 1, CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
CINEMA2K_48 = 2, CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
CINEMA4K_24 = 3 CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
}OPJ_CINEMA_MODE; }OPJ_CINEMA_MODE;
/** Progression order */ /**
Progression order
*/
typedef enum PROG_ORDER { typedef enum PROG_ORDER {
PROG_UNKNOWN = -1, /**< place-holder */ PROG_UNKNOWN = -1, /**< place-holder */
LRCP = 0, /**< layer-resolution-component-precinct order */ LRCP = 0, /**< layer-resolution-component-precinct order */

View File

@ -92,7 +92,7 @@ static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
pi->first = 0; pi->first = 0;
} }
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
pi->resno++) { pi->resno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
@ -133,7 +133,7 @@ static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
} }
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno]; comp = &pi->comps[pi->compno];
if (pi->resno >= comp->numresolutions) { if (pi->resno >= comp->numresolutions) {
@ -209,10 +209,10 @@ if (!pi->tp_on){
try1 = int_ceildiv(pi->ty1, comp->dy << levelno); try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) { if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpx))))){
continue; continue;
} }
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) { if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue; continue;
} }
@ -225,7 +225,7 @@ if (!pi->tp_on){
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy); - int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw; pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) { if (!pi->include[index]) {
pi->include[index] = 1; pi->include[index] = 1;
@ -290,10 +290,10 @@ static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
try1 = int_ceildiv(pi->ty1, comp->dy << levelno); try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) { if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpx))))){
continue; continue;
} }
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) { if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue; continue;
} }
@ -306,7 +306,7 @@ static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy); - int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw; pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) { if (!pi->include[index]) {
pi->include[index] = 1; pi->include[index] = 1;
@ -369,10 +369,10 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
try1 = int_ceildiv(pi->ty1, comp->dy << levelno); try1 = int_ceildiv(pi->ty1, comp->dy << levelno);
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) { if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpx))))){
continue; continue;
} }
if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) { if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue; continue;
} }
@ -385,7 +385,7 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy) prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- int_floordivpow2(try0, res->pdy); - int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw; pi->precno = prci + prcj * res->pw;
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) { if (!pi->include[index]) {
pi->include[index] = 1; pi->include[index] = 1;
@ -562,7 +562,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
pi = (opj_pi_iterator_t *) opj_malloc(array_size); pi = (opj_pi_iterator_t *) opj_malloc(array_size);
pi->tp_on = cp->tp_on; pi->tp_on = cp->tp_on;
if(!pi) { return NULL;} if(!pi) { return NULL;}
for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
p = tileno % cp->tw; p = tileno % cp->tw;
q = tileno / cp->tw; q = tileno / cp->tw;
@ -652,7 +652,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
} }
if (pino == 0) { if (pino == 0) {
array_size = image->numcomps * maxres * tcp->numlayers * 100 * sizeof(short int); array_size = (tcp->numpocs+1) * tcp->numlayers * pi[pino].step_l * sizeof(short int);
pi[pino].include = (short int *) opj_malloc(array_size); pi[pino].include = (short int *) opj_malloc(array_size);
if(!pi[pino].include) { if(!pi[pino].include) {
pi_destroy(pi, cp, tileno); pi_destroy(pi, cp, tileno);
@ -688,6 +688,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
tcp->pocs[pino].tyE = pi[pino].ty1; tcp->pocs[pino].tyE = pi[pino].ty1;
tcp->pocs[pino].dx = pi[pino].dx; tcp->pocs[pino].dx = pi[pino].dx;
tcp->pocs[pino].dy = pi[pino].dy; tcp->pocs[pino].dy = pi[pino].dy;
}
return pi; return pi;
} }
@ -822,7 +823,7 @@ void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,
int incr_top=1,resetX=0; int incr_top=1,resetX=0;
opj_tcp_t *tcps =&cp->tcps[tileno]; opj_tcp_t *tcps =&cp->tcps[tileno];
opj_poc_t *tcp= &tcps->pocs[pino]; opj_poc_t *tcp= &tcps->pocs[pino];
prog = convert_progression_order(tcp->prg); prog = j2k_convert_progression_order(tcp->prg);
pi[pino].first = 1; pi[pino].first = 1;
pi[pino].poc.prg = tcp->prg; pi[pino].poc.prg = tcp->prg;
@ -920,6 +921,35 @@ void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,
incr_top=1; incr_top=1;
}else{ }else{
for(i=tppos;i>=0;i--){ for(i=tppos;i>=0;i--){
switch(prog[i]){
case 'C':
pi[pino].poc.compno0 = tcp->comp_t-1;
pi[pino].poc.compno1 = tcp->comp_t;
break;
case 'R':
pi[pino].poc.resno0 = tcp->res_t-1;
pi[pino].poc.resno1 = tcp->res_t;
break;
case 'L':
pi[pino].poc.layno0 = tcp->lay_t-1;
pi[pino].poc.layno1 = tcp->lay_t;
break;
case 'P':
switch(tcp->prg){
case LRCP:
case RLCP:
pi[pino].poc.precno0 = tcp->prc_t-1;
pi[pino].poc.precno1 = tcp->prc_t;
break;
default:
pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
pi[pino].poc.tx1 = tcp->tx0_t ;
pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
pi[pino].poc.ty1 = tcp->ty0_t ;
break;
}
break;
}
if(incr_top==1){ if(incr_top==1){
switch(prog[i]){ switch(prog[i]){
case 'R': case 'R':

View File

@ -563,7 +563,7 @@ static int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_t
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,opj_pi_iterator_t *tcd_pi,int tpnum, int tppos,int pino, char final_encoding){ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino, char final_encoding){
unsigned char *c = dest; unsigned char *c = dest;
int e = 0; int e = 0;
opj_pi_iterator_t *pi = NULL; opj_pi_iterator_t *pi = NULL;
@ -571,11 +571,7 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
opj_image_t *image = t2->image; opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp; opj_cp_t *cp = t2->cp;
if(final_encoding == 0){
pi = pi_initialise_encode(image, cp, tileno,pino); pi = pi_initialise_encode(image, cp, tileno,pino);
}else{
pi = tcd_pi;
}
if(!pi) { if(!pi) {
/* TODO: throw an error */ /* TODO: throw an error */
return -999; return -999;
@ -613,9 +609,9 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
/* << INDEX */ /* << INDEX */
} }
} }
if(final_encoding == 0){
pi_destroy(pi, cp, tileno); pi_destroy(pi, cp, tileno);
}
if (e == -999) { if (e == -999) {
return e; return e;
} }

View File

@ -66,7 +66,7 @@ Encode the packets of a tile to a destination buffer
@param len the length of the destination buffer @param len the length of the destination buffer
@param image_info structure to create an index file @param image_info structure to create an index file
*/ */
int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,opj_pi_iterator_t *tcd_pi,int tpnum, int tppos,int pino,char final_encoding); int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_image_info_t *image_info,int tpnum, int tppos,int pino,char final_encoding);
/** /**
Decode the packets of a tile from a source buffer Decode the packets of a tile from a source buffer
@param t2 T2 handle @param t2 T2 handle

View File

@ -1024,6 +1024,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
/* TODO: remove maxlen */ /* TODO: remove maxlen */
int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len; int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len;
double goodthresh = 0; double goodthresh = 0;
double stable_thresh = 0;
int i; int i;
double distotarget; /* fixed_quality */ double distotarget; /* fixed_quality */
@ -1042,7 +1043,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
if (cp->fixed_quality) { /* fixed_quality */ if (cp->fixed_quality) { /* fixed_quality */
if(cp->cinema){ if(cp->cinema){
l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->pi,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,0); l = t2_encode_packets(t2,tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,0);
if (l == -999) { if (l == -999) {
lo = thresh; lo = thresh;
continue; continue;
@ -1050,7 +1051,9 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
distoachieved = layno == 0 ? distoachieved = layno == 0 ?
tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
if (distoachieved < distotarget) { if (distoachieved < distotarget) {
hi=thresh; continue; hi=thresh;
stable_thresh = thresh;
continue;
}else{ }else{
lo=thresh; lo=thresh;
} }
@ -1060,12 +1063,13 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]); tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
if (distoachieved < distotarget) { if (distoachieved < distotarget) {
hi = thresh; hi = thresh;
stable_thresh = thresh;
continue; continue;
} }
lo = thresh; lo = thresh;
} }
} else { } else {
l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->pi,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,0); l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,0);
/* TODO: what to do with l ??? seek / tell ??? */ /* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) { if (l == -999) {
@ -1073,11 +1077,11 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
continue; continue;
} }
hi = thresh; hi = thresh;
stable_thresh = thresh;
}
} }
success = 1; success = 1;
goodthresh = thresh; goodthresh = stable_thresh;
}
t2_destroy(t2); t2_destroy(t2);
} else { } else {
success = 1; success = 1;
@ -1229,19 +1233,16 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
} }
t2 = t2_create(tcd->cinfo, image, cp); t2 = t2_create(tcd->cinfo, image, cp);
l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, image_info,tcd->pi,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,1); l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, image_info,tcd->tp_num,tcd->tp_pos,tcd->cur_pino,1);
t2_destroy(t2); t2_destroy(t2);
/*---------------CLEAN-------------------*/ /*---------------CLEAN-------------------*/
encoding_time = opj_clock() - encoding_time;
if(tcd->cur_totnum_tp > 1){
opj_event_msg(tcd->cinfo, EVT_INFO, "- Tile part num %d encoded in %f s\n", tcd->cur_tp_num,encoding_time);
}else{
opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", encoding_time);
}
if(tcd->cur_tp_num == tcd->cur_totnum_tp - 1){ 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);
/* cleaning memory */ /* cleaning memory */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; opj_tcd_tilecomp_t *tilec = &tile->comps[compno];

View File

@ -160,6 +160,8 @@ Tile coder/decoder
typedef struct opj_tcd { typedef struct opj_tcd {
/** Position of the tilepart flag in Progression order*/ /** Position of the tilepart flag in Progression order*/
int tp_pos; int tp_pos;
/** Tile part number*/
int tp_num;
/** Current tile part number*/ /** Current tile part number*/
int cur_tp_num; int cur_tp_num;
/** Total number of tileparts of the current tile*/ /** Total number of tileparts of the current tile*/
@ -181,8 +183,6 @@ typedef struct opj_tcd {
opj_tcp_t *tcp; opj_tcp_t *tcp;
/** current encoded/decoded tile */ /** current encoded/decoded tile */
int tcd_tileno; int tcd_tileno;
/** Packet iterator*/
opj_pi_iterator_t *pi;
} opj_tcd_t; } opj_tcd_t;
/** @name Exported functions */ /** @name Exported functions */