* PPM markers handling modified (comment keyword : ppmbug1)
* empty resolution level or subband handling (comment keyword : sizebug1) * index_on field forwarded to j2k_cp_t structure
This commit is contained in:
parent
de5a22aea0
commit
55e5910d6b
|
@ -288,7 +288,7 @@ int main(int argc, char **argv)
|
|||
cblockh_init = 64;
|
||||
cp.tw = 1;
|
||||
cp.th = 1;
|
||||
img.index_on = 0;
|
||||
cp.index_on = 0;
|
||||
Prog_order = 0;
|
||||
numpocs = 0;
|
||||
mode = 0;
|
||||
|
@ -491,7 +491,7 @@ int main(int argc, char **argv)
|
|||
/* ----------------------------------------------------- */
|
||||
case 'x': /* creation of index file */
|
||||
index = optarg;
|
||||
img.index_on = 1;
|
||||
cp.index_on = 1;
|
||||
break;
|
||||
/* ----------------------------------------------------- */
|
||||
case 'p': /* progression order */
|
||||
|
|
|
@ -72,7 +72,6 @@ typedef struct {
|
|||
int x0, y0; /* XOsiz, YOsiz */
|
||||
int x1, y1; /* Xsiz, Ysiz */
|
||||
int numcomps; /* number of components */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
j2k_comp_t *comps; /* image-components */
|
||||
} j2k_image_t;
|
||||
|
||||
|
@ -128,6 +127,7 @@ typedef struct {
|
|||
int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
|
||||
int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
|
||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
j2k_tcp_t *tcps; /* tile coding parameters */
|
||||
} j2k_cp_t;
|
||||
|
||||
|
|
|
@ -702,15 +702,18 @@ void j2k_read_ppm()
|
|||
}
|
||||
|
||||
j = j2k_cp->ppm_store;
|
||||
if (Z_ppm == 0) /* First PPM marker */
|
||||
if (Z_ppm == 0) { /* First PPM marker */
|
||||
j2k_cp->ppm_data =
|
||||
(unsigned char *) calloc(N_ppm, sizeof(unsigned char));
|
||||
else /* NON-first PPM marker */
|
||||
j2k_cp->ppm_len = N_ppm; //Add antonin : ppmbug1
|
||||
} else { /* NON-first PPM marker */
|
||||
j2k_cp->ppm_data =
|
||||
(unsigned char *) realloc(j2k_cp->ppm_data,
|
||||
(N_ppm +
|
||||
j2k_cp->ppm_store) *
|
||||
sizeof(unsigned char));
|
||||
j2k_cp->ppm_len = N_ppm + j2k_cp->ppm_store; //Add antonin : ppmbug1
|
||||
}
|
||||
|
||||
for (i = N_ppm; i > 0; i--) { /* Read packet header */
|
||||
j2k_cp->ppm_data[j] = cio_read(1);
|
||||
|
@ -738,11 +741,14 @@ void j2k_read_ppt()
|
|||
tcp->ppt_data =
|
||||
(unsigned char *) calloc(len - 3, sizeof(unsigned char));
|
||||
tcp->ppt_store = 0;
|
||||
} else /* NON-first PPT marker */
|
||||
tcp->ppt_len = len-3; //Add antonin : ppmbug1
|
||||
} else { /* NON-first PPT marker */
|
||||
tcp->ppt_data =
|
||||
(unsigned char *) realloc(tcp->ppt_data,
|
||||
(len - 3 +
|
||||
tcp->ppt_store) * sizeof(unsigned char));
|
||||
tcp->ppt_len=len - 3 + tcp->ppt_store; //Add antonin : ppmbug1
|
||||
}
|
||||
|
||||
j = tcp->ppt_store;
|
||||
for (i = len - 3; i > 0; i--) {
|
||||
|
@ -972,7 +978,7 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
|
|||
/* j2k_dump_cp(j2k_img, j2k_cp); */
|
||||
|
||||
/* INDEX >> */
|
||||
info_IM.index_on = j2k_img->index_on;
|
||||
info_IM.index_on = j2k_cp->index_on;
|
||||
if (info_IM.index_on) {
|
||||
info_IM.tile =
|
||||
(info_tile *) malloc(j2k_cp->tw * j2k_cp->th * sizeof(info_tile));
|
||||
|
|
|
@ -74,7 +74,6 @@ typedef struct {
|
|||
int x0, y0; /* XOsiz, YOsiz */
|
||||
int x1, y1; /* Xsiz, Ysiz */
|
||||
int numcomps; /* number of components */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
int color_space; /* sRGB, Greyscale or YUV */
|
||||
j2k_comp_t *comps; /* image-components */
|
||||
} j2k_image_t;
|
||||
|
@ -120,6 +119,7 @@ typedef struct {
|
|||
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
||||
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
||||
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
||||
int ppt_len; /* ppmbug1 */
|
||||
float distoratio[100]; /* add fixed_quality */
|
||||
j2k_tccp_t *tccps; /* tile-component coding parameters */
|
||||
} j2k_tcp_t;
|
||||
|
@ -133,6 +133,7 @@ typedef struct {
|
|||
int fixed_quality; /* add fixed_quality */
|
||||
int reduce_on; /* option reduce is used if reduce = 1 */
|
||||
int reduce_value; /* if option reduce is used -> original dimension divided by 2^value */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
int tx0, ty0; /* XTOsiz, YTOsiz */
|
||||
int tdx, tdy; /* XTsiz, YTsiz */
|
||||
char *comment; /* comment for coding */
|
||||
|
@ -143,6 +144,7 @@ typedef struct {
|
|||
int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
|
||||
int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
|
||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
||||
int ppm_len; /* ppmbug1 */
|
||||
j2k_tcp_t *tcps; /* tile coding parameters */
|
||||
int *matrice; /* Fixed layer */
|
||||
} j2k_cp_t;
|
||||
|
|
|
@ -97,8 +97,8 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
|
|||
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
||||
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
||||
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
||||
res->pw = (px1 - px0) >> res->pdx;
|
||||
res->ph = (py1 - py0) >> res->pdy;
|
||||
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); //Mod Antonin : sizebug1
|
||||
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); //Mod Antonin : sizebug1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,6 +291,11 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((res->pw==0)||(res->pw==0)) continue;
|
||||
//ddA
|
||||
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
|
@ -382,6 +387,11 @@ int pi_next_pcrl(pi_iterator_t * pi)
|
|||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((res->pw==0)||(res->pw==0)) continue;
|
||||
//ddA
|
||||
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
|
@ -468,6 +478,11 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((res->pw==0)||(res->pw==0)) continue;
|
||||
//ddA
|
||||
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
|
|
135
libopenjpeg/t2.c
135
libopenjpeg/t2.c
|
@ -303,12 +303,18 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||
tcd_resolution_t *res = &tilec->resolutions[resno];
|
||||
unsigned char *c = src;
|
||||
unsigned char *hd = NULL;
|
||||
int present;
|
||||
|
||||
if (layno == 0) {
|
||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||
tcd_band_t *band = &res->bands[bandno];
|
||||
tcd_precinct_t *prc = &band->precincts[precno];
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||
//ddA
|
||||
|
||||
tgt_reset(prc->incltree);
|
||||
tgt_reset(prc->imsbtree);
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||
|
@ -318,56 +324,69 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||
}
|
||||
}
|
||||
|
||||
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
|
||||
This part deal with this caracteristic
|
||||
step 1: Read packet header in the saved structure
|
||||
step 2: (futher) return to codestream for decoding */
|
||||
if (cp->ppm == 1) { /* PPM */
|
||||
c = cp->ppm_data;
|
||||
bio_init_dec(c, 1000);
|
||||
} else {
|
||||
if (tcp->ppt == 1) { /* PPT */
|
||||
c = tcp->ppt_data;
|
||||
bio_init_dec(c, 1000);
|
||||
} else { /* Normal Case */
|
||||
|
||||
if (tcp->csty & J2K_CP_CSTY_SOP) {
|
||||
if ((*c) != 255 || (*(c + 1) != 145)) {
|
||||
printf("Error : expected SOP marker [1]!!!\n");
|
||||
}
|
||||
c += 6;
|
||||
}
|
||||
bio_init_dec(c, src + len - c);
|
||||
// SOP markers
|
||||
if (tcp->csty & J2K_CP_CSTY_SOP) {
|
||||
if ((*c) != 0xff || (*(c + 1) != 0x91)) {
|
||||
printf("Warning : expected SOP marker\n");
|
||||
} else {
|
||||
c += 6;
|
||||
}
|
||||
//TODO : check the Nsop value
|
||||
}
|
||||
|
||||
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
|
||||
This part deal with this caracteristic
|
||||
step 1: Read packet header in the saved structure
|
||||
step 2: Return to codestream for decoding */
|
||||
|
||||
if (cp->ppm == 1) { /* PPM */
|
||||
hd = cp->ppm_data;
|
||||
bio_init_dec(hd, cp->ppm_len); //Mod Antonin : ppmbug1
|
||||
} else if (tcp->ppt == 1) { /* PPT */
|
||||
hd = tcp->ppt_data;
|
||||
bio_init_dec(hd, tcp->ppt_len); //Mod Antonin : ppmbug1
|
||||
} else { /* Normal Case */
|
||||
hd = c;
|
||||
bio_init_dec(hd, src+len-hd);
|
||||
}
|
||||
|
||||
present = bio_read(1);
|
||||
|
||||
if (!present) {
|
||||
bio_inalign();
|
||||
/* Normal case */
|
||||
c += bio_numbytes();
|
||||
hd += bio_numbytes();
|
||||
|
||||
// EPH markers
|
||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||
if ((*c) != 255 || (*(c + 1) != 146)) {
|
||||
printf("Error : expected EPH marker [1]!!!\n");
|
||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||
printf("Error : expected EPH marker\n");
|
||||
} else {
|
||||
hd += 2;
|
||||
}
|
||||
c += 2;
|
||||
}
|
||||
|
||||
/* PPT and PPM dealing */
|
||||
if (cp->ppm == 1) { /* PPM */
|
||||
cp->ppm_data = c;
|
||||
return 0;
|
||||
if (cp->ppm == 1) { /* PPM case */
|
||||
cp->ppm_len+=cp->ppm_data-hd;
|
||||
cp->ppm_data = hd;
|
||||
return c - src;
|
||||
}
|
||||
if (tcp->ppt == 1) { /* PPT */
|
||||
tcp->ppt_data = c;
|
||||
return 0;
|
||||
if (tcp->ppt == 1) { /* PPT case */
|
||||
tcp->ppt_len+=tcp->ppt_data-hd;
|
||||
tcp->ppt_data = hd;
|
||||
return c - src;
|
||||
}
|
||||
return c - src;
|
||||
|
||||
return hd - src;
|
||||
}
|
||||
|
||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||
tcd_band_t *band = &res->bands[bandno];
|
||||
tcd_precinct_t *prc = &band->precincts[precno];
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||
//ddA
|
||||
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||
int included, increment, n;
|
||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
||||
|
@ -423,45 +442,37 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||
if (bio_inalign())
|
||||
return -999;
|
||||
|
||||
c += bio_numbytes();
|
||||
hd += bio_numbytes();
|
||||
|
||||
if (tcp->csty & J2K_CP_CSTY_EPH) { /* EPH marker */
|
||||
if ((*c) != 255 || (*(c + 1) != 146)) {
|
||||
printf("Error : expected EPH marker [2]!!!\n");
|
||||
// EPH markers
|
||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||
printf("Error : expected EPH marker\n");
|
||||
} else {
|
||||
hd += 2;
|
||||
}
|
||||
c += 2;
|
||||
}
|
||||
|
||||
/* PPT Step 2 : see above for details */
|
||||
if (cp->ppm == 1) {
|
||||
cp->ppm_data = c; /* Update pointer */
|
||||
|
||||
c = src;
|
||||
if (tcp->csty & J2K_CP_CSTY_SOP) {
|
||||
if ((*c) != 255 || (*(c + 1) != 145)) {
|
||||
printf("Error : expected SOP marker [2] !!!\n");
|
||||
}
|
||||
c += 6;
|
||||
}
|
||||
bio_init_dec(c, src + len - c);
|
||||
if (cp->ppm==1) {
|
||||
cp->ppm_len+=cp->ppm_data-hd;
|
||||
cp->ppm_data = hd;
|
||||
} else if (tcp->ppt == 1) {
|
||||
tcp->ppt_len+=tcp->ppt_data-hd;
|
||||
tcp->ppt_data = hd;
|
||||
} else {
|
||||
if (tcp->ppt == 1) {
|
||||
tcp->ppt_data = c; /* Update pointer */
|
||||
c = src;
|
||||
if (tcp->csty & J2K_CP_CSTY_SOP) { /* SOP marker */
|
||||
if ((*c) != 255 || (*(c + 1) != 145)) {
|
||||
printf("Error : expected SOP marker [2] !!!\n");
|
||||
}
|
||||
c += 6;
|
||||
}
|
||||
bio_init_dec(c, src + len - c);
|
||||
|
||||
}
|
||||
c=hd;
|
||||
}
|
||||
|
||||
//bio_init_dec(c, src + len - c);
|
||||
|
||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||
tcd_band_t *band = &res->bands[bandno];
|
||||
tcd_precinct_t *prc = &band->precincts[precno];
|
||||
|
||||
//Add Antonin : sizebug1
|
||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||
//ddA
|
||||
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
||||
tcd_seg_t *seg;
|
||||
|
|
|
@ -658,8 +658,8 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
|
||||
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
|
||||
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
|
||||
res->pw = (brprcxend - tlprcxstart) >> pdx;
|
||||
res->ph = (brprcyend - tlprcystart) >> pdy;
|
||||
res->pw = (res->x0==res->x1)?0:((brprcxend - tlprcxstart) >> pdx); // Mod Antonin : sizebug1
|
||||
res->ph = (res->y0==res->y1)?0:((brprcyend - tlprcystart) >> pdy); // Mod Antonin : sizebug1
|
||||
|
||||
if (resno == 0) {
|
||||
tlcbgxstart = tlprcxstart;
|
||||
|
|
Loading…
Reference in New Issue