Digital cinema compliance for 4K chosen by "-cinema4K" option. Modification in image_to_j2k.c.

Bit rate limitation for each color component. Modification in image_to_j2k.c, t2.c.
Modified and tested Progression order change "-POC" option. Modification in image_to_j2k.c, j2k.c, pi.c.
Function j2k_check_poc_val() to check for possible loss of packets in case of wrong POC declaration. Modification in j2k.c.
Structure T2_MODE. This tells if the t2_encode_packets() is called during Threshold calculation or in Final pass. Modification in j2k.h, tcd.c
This commit is contained in:
Parvatha Elangovan 2007-04-04 13:40:32 +00:00
parent 24146a96cf
commit dd18811600
12 changed files with 206 additions and 71 deletions

View File

@ -5,6 +5,13 @@ What's New for OpenJPEG
! : changed
+ : added
April 4,2007
+ [Parvatha] Digital cinema compliance for 4K chosen by "-cinema4K" option. Modification in image_to_j2k.c.
+ [Parvatha] Bit rate limitation for each color component. Modification in image_to_j2k.c, t2.c.
* [Parvatha] Modified and tested Progression order change "-POC" option. Modification in image_to_j2k.c, j2k.c, pi.c.
+ [Parvatha] Function j2k_check_poc_val() to check for possible loss of packets in case of wrong POC declaration. Modification in j2k.c.
+ [Parvatha] Structure T2_MODE. This tells if the t2_encode_packets() is called during Threshold calculation or in Final pass. Modification in j2k.h, tcd.c
March 30, 2007
* [GB] OPJViewer should now work under Linux, at least with not big j2k files. Tested under Suse 10.1 64 bit.

View File

@ -58,6 +58,8 @@
/* ----------------------------------------------------------------------- */
#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/
#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/
#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@ -180,6 +182,10 @@ void encode_help_display() {
fprintf(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n");
fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n");
fprintf(stdout,"\n");
fprintf(stdout,"-POC : Progression order change (-POC T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL) \n");
fprintf(stdout," Example: T1=0,0,1,5,3,CPRL \n");
fprintf(stdout," : Ttilenumber=Resolution num start,Component num start,Layer num end,Resolution num end,Component num end,Progression order\n");
fprintf(stdout,"\n");
fprintf(stdout,"-SOP : write SOP marker before each packet \n");
fprintf(stdout,"\n");
fprintf(stdout,"-EPH : write EPH marker after each header packet \n");
@ -414,6 +420,23 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparamet
return 0;
}
static int initialise_4K_poc(opj_poc_t *POC, int numres){
POC[0].tile = 1;
POC[0].resno0 = 0;
POC[0].compno0 = 0;
POC[0].layno1 = 1;
POC[0].resno1 = numres-1;
POC[0].compno1 = 3;
POC[0].prg1 = CPRL;
POC[1].tile = 1;
POC[1].resno0 = numres-1;
POC[1].compno0 = 0;
POC[1].layno1 = 1;
POC[1].resno1 = numres;
POC[1].compno1 = 3;
POC[1].prg1 = CPRL;
return 2;
}
void cinema_parameters(opj_cparameters_t *parameters){
parameters->tile_size_on = false;
@ -447,6 +470,8 @@ void cinema_parameters(opj_cparameters_t *parameters){
void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
int i;
float temp_rate;
opj_poc_t *POC = NULL;
switch (parameters->cp_cinema){
case CINEMA2K_24:
case CINEMA2K_48:
@ -462,13 +487,14 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
case CINEMA4K_24:
if(parameters->numresolution < 1){
parameters->numresolution = 1;
}else if((parameters->numresolution < 7) || (parameters->numresolution > 7)){
}else if(parameters->numresolution > 7){
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);
parameters->cp_rsiz = STD_RSIZ;
}
parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution);
break;
}
@ -489,6 +515,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
}
}
}
parameters->max_comp_size = COMP_24_CS;
break;
case CINEMA2K_48:
@ -506,6 +533,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image){
}
}
}
parameters->max_comp_size = COMP_48_CS;
break;
}
parameters->cp_disto_alloc = 1;
@ -523,6 +551,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
{"SOP",NO_ARG, NULL ,'S'},
{"EPH",NO_ARG, NULL ,'E'},
{"OutFor",REQ_ARG, NULL ,'O'},
{"POC",REQ_ARG, NULL ,'P'},
};
/* parse the command line */
@ -582,7 +611,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
break;
/* ----------------------------------------------------- */
case 'O': /* output file */
case 'O': /* output format */
{
char outformat[50];
char *of = optarg;
@ -811,16 +840,11 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,i
char *s = optarg;
POC = parameters->POC;
fprintf(stderr, "/----------------------------------\\\n");
fprintf(stderr, "| POC option not fully tested !! |\n");
fprintf(stderr, "\\----------------------------------/\n");
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile,
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
POC[numpocs].prg = give_progression(POC[numpocs].progorder);
/* POC[numpocs].tile; */
&POC[numpocs].compno1, &POC[numpocs].progorder) == 7) {
POC[numpocs].prg1 = give_progression(POC[numpocs].progorder);
numpocs++;
while (*s && *s != '/') {
s++;

View File

@ -258,6 +258,43 @@ char *j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
return po->str_prog;
}
static void j2k_check_poc_val(opj_cparameters_t *parameters, int numcomps, int numlayers){
int index, resno, compno, layno, i;
char loss = 0;
int step_c = 1;
int step_r = numcomps * step_c;
int step_l = parameters->numresolution * step_r;
int array_size = step_l * numlayers * sizeof(int);
int *packet_array = (int *) opj_malloc(array_size);
for (i = 0; i < parameters->numpocs ; i++) {
int layno0 = 0;
if(i > 0)
layno0 = (parameters->POC[i].layno1 > parameters->POC[i-1].layno1 )? parameters->POC[i-1].layno1 : 0;
for (resno = parameters->POC[i].resno0 ; resno < parameters->POC[i].resno1 ; resno++) {
for (compno = parameters->POC[i].compno0 ; compno < parameters->POC[i].compno1 ; compno++) {
for (layno = layno0; layno < parameters->POC[i].layno1 ; layno++) {
index = step_r * resno + step_c * compno + step_l * layno;
packet_array[index]= 1;
}
}
}
}
for (resno = 0; resno < parameters->numresolution; resno++) {
for (compno = 0; compno < numcomps; compno++) {
for (layno = 0; layno < numlayers ; layno++) {
index = step_r * resno + step_c * compno + step_l * layno;
if(!( packet_array[index]== 1)){
loss = 1;
}
}
}
}
if(loss == 1)
fprintf(stdout,"Missing packets possible loss of data\n");
opj_free(packet_array);
}
void j2k_dump_image(FILE *fd, opj_image_t * img) {
int compno;
fprintf(fd, "image {\n");
@ -376,7 +413,7 @@ int j2k_calculate_tp(opj_cp_t *cp,int img_numcomp,opj_image_t *image,opj_j2k_t *
opj_tcp_t *tcp = &cp->tcps[tileno];
for(pino = 0; pino <= tcp->numpocs; pino++) {
int tp_num=0;
opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,pino);
opj_pi_iterator_t *pi = pi_initialise_encode(image, cp, tileno,FINAL_PASS);
if(!pi) { return -1;}
tp_num = j2k_get_num_tp(cp,pino,tileno);
totnum_tp = totnum_tp + tp_num;
@ -956,7 +993,7 @@ static void j2k_write_poc(opj_j2k_t *j2k) {
opj_tccp_t *tccp = &tcp->tccps[0];
opj_cio_t *cio = j2k->cio;
numpchgs = tcp->numpocs;
numpchgs = 1 + tcp->numpocs;
cio_write(cio, J2K_MS_POC, 2); /* POC */
len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs;
cio_write(cio, len, 2); /* Lpoc */
@ -1908,6 +1945,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
copy user encoding parameters
*/
cp->cinema = parameters->cp_cinema;
cp->max_comp_size = parameters->max_comp_size;
cp->rsiz = parameters->cp_rsiz;
cp->disto_alloc = parameters->cp_disto_alloc;
cp->fixed_alloc = parameters->cp_fixed_alloc;
@ -2052,6 +2090,7 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
if (parameters->numpocs) {
/* initialisation of POC */
tcp->POC = 1;
j2k_check_poc_val(parameters, image->numcomps, tcp->numlayers);
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];
@ -2060,13 +2099,15 @@ void j2k_setup_encoder(opj_j2k_t *j2k, opj_cparameters_t *parameters, opj_image_
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->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->numpocs = numpocs_tile;
tcp->tccps = (opj_tccp_t *) opj_malloc(image->numcomps * sizeof(opj_tccp_t));
@ -2447,6 +2488,9 @@ bool j2k_encode(opj_j2k_t *j2k, opj_cio_t *cio, opj_image_t *image, char *index)
/* TLM Marker*/
if(cp->cinema){
j2k_write_tlm(j2k);
if (cp->cinema == CINEMA4K_24) {
j2k_write_poc(j2k);
}
}
/**** Main Header ENDS here ***/

View File

@ -104,6 +104,14 @@ typedef enum J2K_STATUS {
/* ----------------------------------------------------------------------- */
/**
T2 encoding mode
*/
typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE;
/**
Quantization stepsize
*/
@ -190,6 +198,8 @@ Coding parameters
typedef struct opj_cp {
/** Digital cinema profile*/
OPJ_CINEMA_MODE cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Size of the image in bits*/
int img_size;
/** Rsiz*/

View File

@ -223,6 +223,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
parameters->cp_cinema = OFF;
parameters->max_comp_size = 0;
parameters->numresolution = 6;
parameters->cp_rsiz = STD_RSIZ;
parameters->cblockw_init = 64;

View File

@ -214,17 +214,28 @@ typedef struct opj_event_mgr {
Progression order changes
*/
typedef struct opj_poc {
int resno0, compno0;
int layno1, resno1, compno1;
OPJ_PROG_ORDER prg;
int tile;
char progorder[4];
int txS,txE,tyS,tyE,dx,dy;
int tx0,tx1,ty0,ty1;
int layno0, precno0, precno1;
int layS, resS, compS, prcS;
int layE, resE, compE, prcE;
int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
/** Resolution num start, Component num start, given by POC */
int resno0, compno0;
/** Layer num end,Resolution num end, Component num end, given by POC */
int layno1, resno1, compno1;
/** Layer num start,Precinct num start, Precinct num end */
int layno0, precno0, precno1;
/** Progression order enum*/
OPJ_PROG_ORDER prg1,prg;
/** Progression order string*/
char progorder[5];
/** Tile number */
int tile;
/** Start and end values for Tile width and height*/
int tx0,tx1,ty0,ty1;
/** Start value, initialised in pi_initialise_encode*/
int layS, resS, compS, prcS;
/** End value, initialised in pi_initialise_encode */
int layE, resE, compE, prcE;
/** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
int txS,txE,tyS,tyE,dx,dy;
/** Temporary values for Tile parts, initialised in pi_create_encode */
int lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
} opj_poc_t;
/**
@ -233,6 +244,8 @@ Compression parameters
typedef struct opj_cparameters {
/** Digital Cinema compliance 0-not compliant, 1-compliant*/
OPJ_CINEMA_MODE cp_cinema;
/** Maximum rate for each component. If == 0, component size limitation is not considered */
int max_comp_size;
/** Profile name*/
OPJ_RSIZ_CAPABILITIES cp_rsiz;
/** Tile part generation*/

View File

@ -546,8 +546,8 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
}
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, int pino){
int p, q;
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){
int p, q, pino;
int compno, resno;
int maxres = 0;
int maxprec = 0;
@ -560,8 +560,9 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t);
pi = (opj_pi_iterator_t *) opj_malloc(array_size);
pi->tp_on = cp->tp_on;
if(!pi) { return NULL;}
pi->tp_on = cp->tp_on;
for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
p = tileno % cp->tw;
q = tileno / cp->tw;
@ -580,7 +581,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
}
memset(pi[pino].comps, 0, array_size);
for (compno = 0; compno < pi->numcomps; compno++) {
for (compno = 0; compno < pi[pino].numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
opj_pi_comp_t *comp = &pi[pino].comps[compno];
tccp = &tcp->tccps[compno];
@ -595,10 +596,10 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
return NULL;
}
tcx0 = int_ceildiv(pi->tx0, comp->dx);
tcy0 = int_ceildiv(pi->ty0, comp->dy);
tcx1 = int_ceildiv(pi->tx1, comp->dx);
tcy1 = int_ceildiv(pi->ty1, comp->dy);
tcx0 = int_ceildiv(pi[pino].tx0, comp->dx);
tcy0 = int_ceildiv(pi[pino].ty0, comp->dy);
tcx1 = int_ceildiv(pi[pino].tx1, comp->dx);
tcy1 = int_ceildiv(pi[pino].ty1, comp->dy);
if (comp->numresolutions > maxres) {
maxres = comp->numresolutions;
}
@ -652,7 +653,7 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
}
if (pino == 0) {
array_size = (tcp->numpocs+1) * tcp->numlayers * pi[pino].step_l * sizeof(short int);
array_size = tcp->numlayers * pi[pino].step_l * sizeof(short int);
pi[pino].include = (short int *) opj_malloc(array_size);
if(!pi[pino].include) {
pi_destroy(pi, cp, tileno);
@ -664,22 +665,24 @@ opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int ti
}
/* Generation of boundaries for each prog flag*/
if (tcp->POC == 1){
if(tcp->POC & (t2_mode == FINAL_PASS)){
tcp->pocs[pino].compS= tcp->pocs[pino].compno0;
tcp->pocs[pino].compE= tcp->pocs[pino].compno1;
tcp->pocs[pino].resS = tcp->pocs[pino].resno0;
tcp->pocs[pino].resE = tcp->pocs[pino].resno1;
tcp->pocs[pino].layE = tcp->pocs[pino].layno1;
tcp->pocs[pino].prg = tcp->pocs[pino].prg;
tcp->pocs[pino].layE = tcp->pocs[pino].layno1;
tcp->pocs[pino].prg = tcp->pocs[pino].prg1;
if (pino > 0)
tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0;
}else {
tcp->pocs[pino].compS= 0;
tcp->pocs[pino].compE= image->numcomps;
tcp->pocs[pino].resS = 0;
tcp->pocs[pino].resE = maxres;
tcp->pocs[pino].layS = 0;
tcp->pocs[pino].layE = tcp->numlayers;
tcp->pocs[pino].prg = tcp->prg;
}
tcp->pocs[pino].layS = 0;
tcp->pocs[pino].prcS = 0;
tcp->pocs[pino].prcE = maxprec;;
tcp->pocs[pino].txS = pi[pino].tx0;
@ -817,7 +820,7 @@ int pi_check_next_level(int pos,opj_cp_t *cp,int tileno, int pino, char *prog){
}
void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos,char final_encoding) {
void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos){
char *prog;
int i,l;
int incr_top=1,resetX=0;
@ -828,7 +831,7 @@ void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,
pi[pino].first = 1;
pi[pino].poc.prg = tcp->prg;
if(!(cp->tp_on & final_encoding)){
if(!(cp->tp_on)){
pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE;
pi[pino].poc.compno0 = tcp->compS;

View File

@ -89,9 +89,9 @@ typedef struct opj_pi_iterator {
int first;
/** progression order change information */
opj_poc_t poc;
/** */
/** number of components in the image */
int numcomps;
/** */
/** Components*/
opj_pi_comp_t *comps;
int tx0, ty0, tx1, ty1;
int x, y, dx, dy;
@ -105,10 +105,11 @@ Create a packet iterator for Encoder
@param image Raw image for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, int pino);
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno,J2K_T2_MODE t2_mode);
/**
Modify the packet iterator for enabling tile part generation
@param pi Handle to the packet iterator generated in pi_initialise_encode
@ -116,9 +117,8 @@ Modify the packet iterator for enabling tile part generation
@param tileno Number that identifies the tile for which to list the packets
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param final_encoding If 0 Create a new packet iterator which is destroyed at end of call,If 1 use the packet iterator previously generated.
*/
void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos,char final_encoding);
void pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int pino,int tpnum, int tppos);
/**
Create a packet iterator for Decoder
@param image Raw image for which the packets will be listed

View File

@ -110,7 +110,7 @@ typedef struct opj_t1 {
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
int data[T1_MAXCBLKH][T1_MAXCBLKW];
int flags[T1_MAXCBLKH + 2][T1_MAXCBLKH + 2];
int flags[T1_MAXCBLKH + 2][T1_MAXCBLKW + 2];
} opj_t1_t;

View File

@ -563,36 +563,69 @@ 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,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, J2K_T2_MODE t2_mode){
unsigned char *c = dest;
int e = 0;
int compno;
int comp_len = 0;
opj_pi_iterator_t *pi = NULL;
int poc;
opj_image_t *image = t2->image;
opj_cp_t *cp = t2->cp;
int pocno = cp->cinema == CINEMA4K_24? 2: 1;
int maxcomp = cp->max_comp_size > 0 ? image->numcomps : 1;
pi = pi_initialise_encode(image, cp, tileno,pino);
pi = pi_initialise_encode(image, cp, tileno, t2_mode);
if(!pi) {
/* TODO: throw an error */
return -999;
}
pi_create_encode(pi, cp,tileno,pino,tpnum,tppos,final_encoding);
if(image_info) {
image_info->num = 0;
}
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno);
if (e == -999) {
break;
} else {
c += e;
if(t2_mode == THRESH_CALC ){
for(compno = 0; compno < maxcomp; compno++ ){
for(poc = 0; poc < pocno ; poc++){
int comp_len = 0;
int tpnum = compno;
pi_create_encode(pi, cp,tileno,poc,tpnum,tppos);
while (pi_next(&pi[poc])) {
if (pi[poc].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[poc], c, dest + len - c, image_info, tileno);
comp_len = comp_len + e;
if (e == -999) {
break;
} else {
c += e;
}
}
}
if (e == -999) break;
if (comp_len > cp->max_comp_size){
e = -999;
break;
}
}
/* INDEX >> */
if(image_info && image_info->index_on) {
if (e == -999) break;
}
}else{
pi_create_encode(pi, cp,tileno,pino,tpnum,tppos);
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, image_info, tileno);
if (e == -999) {
break;
} else {
c += e;
}
}
}
}
/* INDEX >> */
if(image_info && image_info->index_on) {
if(image_info->index_write) {
opj_tile_info_t *info_TL = &image_info->tile[tileno];
opj_packet_info_t *info_PK = &info_TL->packet[image_info->num];
@ -606,11 +639,8 @@ int t2_encode_packets(opj_t2_t* t2,int tileno, opj_tcd_tile_t *tile, int maxlaye
image_info->num++;
}
/* << INDEX */
}
}
pi_destroy(pi, cp, tileno);
/* << INDEX */
pi_destroy(pi, cp, tileno);
if (e == -999) {
return e;

View File

@ -65,8 +65,11 @@ Encode the packets of a tile to a destination buffer
@param dest the destination buffer
@param len the length of the destination buffer
@param image_info structure to create an index file
@param tpnum Tile part number of the current tile
@param tppos The position of the tile part flag in the progression order
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
*/
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);
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,J2K_T2_MODE t2_mode);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle

View File

@ -1043,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->cinema){
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);
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,THRESH_CALC);
if (l == -999) {
lo = thresh;
continue;
@ -1069,7 +1069,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
lo = thresh;
}
} else {
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);
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,THRESH_CALC);
/* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
if (l == -999) {
@ -1233,7 +1233,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
}
t2 = t2_create(tcd->cinfo, image, cp);
l = t2_encode_packets(t2,tileno, tile, tcd_tcp->numlayers, dest, len, image_info,tcd->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,FINAL_PASS);
t2_destroy(t2);
/*---------------CLEAN-------------------*/