* Bug fixed in jpt decoding
* Bug fixed in pcrl progression order (profile-1 compliance) * Change in tcd_dump
This commit is contained in:
parent
aa6c1d28ad
commit
d38080aa00
@ -48,14 +48,13 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
j2k_cp_t cp;
|
j2k_cp_t cp;
|
||||||
int w, wr, wrr, h, hr, hrr, max;
|
int w, wr, wrr, h, hr, hrr, max;
|
||||||
int i, image_type = -1, compno, pad,j;
|
int i, image_type = -1, compno, pad, j;
|
||||||
int adjust;
|
int adjust;
|
||||||
jp2_struct_t * jp2_struct;
|
jp2_struct_t *jp2_struct;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s j2k-file image-file [-reduce n]\n",
|
"usage: %s j2k-file image-file [-reduce n]\n", argv[0]);
|
||||||
argv[0]);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,40 +140,48 @@ int main(int argc, char **argv)
|
|||||||
S1 = *src_name;
|
S1 = *src_name;
|
||||||
|
|
||||||
/* J2K format */
|
/* J2K format */
|
||||||
if ((S1 == 'j' && S2 == '2' && S3 == 'k') || (S1 == 'J' && S2 == '2' && S3 == 'K')) {
|
if ((S1 == 'j' && S2 == '2' && S3 == 'k')
|
||||||
|
|| (S1 == 'J' && S2 == '2' && S3 == 'K') || (S1 == 'j' && S2 == '2'
|
||||||
|
&& S3 == 'c')
|
||||||
|
|| (S1 == 'J' && S2 == '2' && S3 == 'C')) {
|
||||||
if (!j2k_decode(src, len, &img, &cp)) {
|
if (!j2k_decode(src, len, &img, &cp)) {
|
||||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* JP2 format */
|
/* JP2 format */
|
||||||
else if ((S1 == 'j' && S2 == 'p' && S3 == '2') || (S1 == 'J' && S2 == 'P' && S3 == '2')) {
|
else if ((S1 == 'j' && S2 == 'p' && S3 == '2')
|
||||||
|
|| (S1 == 'J' && S2 == 'P' && S3 == '2')) {
|
||||||
jp2_struct = (jp2_struct_t *) malloc(sizeof(jp2_struct_t));
|
jp2_struct = (jp2_struct_t *) malloc(sizeof(jp2_struct_t));
|
||||||
|
|
||||||
jp2_struct->image=&img;
|
jp2_struct->image = &img;
|
||||||
|
|
||||||
if (jp2_decode(src,len,jp2_struct,&cp)) {
|
if (jp2_decode(src, len, jp2_struct, &cp)) {
|
||||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* Insert code here if you want to create actions on jp2_struct before deleting it */
|
/* Insert code here if you want to create actions on jp2_struct before deleting it */
|
||||||
free(jp2_struct);
|
free(jp2_struct);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* JPT format */
|
/* JPT format */
|
||||||
else if ((S1 == 'j' && S2 == 'p' && S3 == 't') || (S1 == 'J' && S2 == 'P' && S3 == 'T')){
|
else if ((S1 == 'j' && S2 == 'p' && S3 == 't')
|
||||||
if (!j2k_decode_jpt_stream(src, len, &img, &cp)) {
|
|| (S1 == 'J' && S2 == 'P' && S3 == 'T')) {
|
||||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
if (!j2k_decode_jpt_stream(src, len, &img, &cp)) {
|
||||||
return 1;
|
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr,
|
|
||||||
"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k, *.jp2 or *.jpt]!! \n",
|
|
||||||
S1, S2, S3);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* otherwise : error */
|
||||||
|
else {
|
||||||
|
fprintf(stderr,
|
||||||
|
"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k, *.jp2, *.jpc or *.jpt]!! \n",
|
||||||
|
S1, S2, S3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
free(src);
|
free(src);
|
||||||
/* ------------------ CREATE OUT IMAGE WITH THE RIGHT FORMAT ----------------------- */
|
/* ------------------ CREATE OUT IMAGE WITH THE RIGHT FORMAT ----------------------- */
|
||||||
|
|
||||||
@ -305,43 +312,44 @@ int main(int argc, char **argv)
|
|||||||
j2k_comp_t *comp = &img.comps[compno];
|
j2k_comp_t *comp = &img.comps[compno];
|
||||||
char name[256];
|
char name[256];
|
||||||
|
|
||||||
int nbytes=0;
|
int nbytes = 0;
|
||||||
//if (img.numcomps > 1)
|
//if (img.numcomps > 1)
|
||||||
sprintf(name, "%s-%d.pgx", argv[2], compno);
|
sprintf(name, "%s-%d.pgx", argv[2], compno);
|
||||||
|
|
||||||
//else
|
//else
|
||||||
|
|
||||||
//sprintf(name, "%s.pgx", argv[2]);
|
//sprintf(name, "%s.pgx", argv[2]);
|
||||||
|
|
||||||
f = fopen(name, "wb");
|
f = fopen(name, "wb");
|
||||||
// w = ceildiv(img.x1 - img.x0, comp->dx);
|
// w = ceildiv(img.x1 - img.x0, comp->dx);
|
||||||
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), comp->dx);
|
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), comp->dx);
|
||||||
w = img.comps[compno].w;
|
w = img.comps[compno].w;
|
||||||
wr = int_ceildivpow2(img.comps[compno].w,
|
wr = int_ceildivpow2(img.comps[compno].w, img.comps[compno].factor);
|
||||||
img.comps[compno].factor);
|
|
||||||
|
|
||||||
// h = ceildiv(img.y1 - img.y0, comp->dy);
|
// h = ceildiv(img.y1 - img.y0, comp->dy);
|
||||||
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), comp->dy);
|
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), comp->dy);
|
||||||
h = img.comps[compno].h;
|
h = img.comps[compno].h;
|
||||||
hr = int_ceildivpow2(img.comps[compno].h,
|
hr = int_ceildivpow2(img.comps[compno].h, img.comps[compno].factor);
|
||||||
img.comps[compno].factor);
|
|
||||||
|
|
||||||
fprintf(f, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+',
|
fprintf(f, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+',
|
||||||
comp->prec, wr, hr);
|
comp->prec, wr, hr);
|
||||||
|
|
||||||
if (comp->prec <= 8) nbytes=1;
|
if (comp->prec <= 8)
|
||||||
|
nbytes = 1;
|
||||||
|
|
||||||
else if (comp->prec <= 16) nbytes=2;
|
else if (comp->prec <= 16)
|
||||||
|
nbytes = 2;
|
||||||
|
|
||||||
else nbytes=4;
|
else
|
||||||
|
nbytes = 4;
|
||||||
for (i = 0; i < wr * hr; i++) {
|
for (i = 0; i < wr * hr; i++) {
|
||||||
int v = img.comps[compno].data[i / wr * w + i % wr];
|
int v = img.comps[compno].data[i / wr * w + i % wr];
|
||||||
|
|
||||||
for (j=nbytes-1 ; j>=0 ; j--) {
|
for (j = nbytes - 1; j >= 0; j--) {
|
||||||
|
|
||||||
char byte=(char)(v>>(j*8));
|
char byte = (char) (v >> (j * 8));
|
||||||
|
|
||||||
fwrite(&byte, 1, 1, f);
|
fwrite(&byte, 1, 1, f);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,7 +538,7 @@ int main(int argc, char **argv)
|
|||||||
// fprintf(f, "%c", img.comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]);
|
// fprintf(f, "%c", img.comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]);
|
||||||
fprintf(f, "%c",
|
fprintf(f, "%c",
|
||||||
img.comps[0].data[w * hr - ((i) / (wr) + 1) * w +
|
img.comps[0].data[w * hr - ((i) / (wr) + 1) * w +
|
||||||
(i) % (wr)]);
|
(i) % (wr)]);
|
||||||
/*if (((i + 1) % w == 0 && w % 2))
|
/*if (((i + 1) % w == 0 && w % 2))
|
||||||
fprintf(f, "%c", 0); */
|
fprintf(f, "%c", 0); */
|
||||||
if ((i + 1) % wr == 0) {
|
if ((i + 1) % wr == 0) {
|
||||||
|
@ -269,6 +269,7 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;// Add antonin pcrl
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
comp = &pi->comps[pi->compno];
|
comp = &pi->comps[pi->compno];
|
||||||
@ -279,6 +280,8 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);// Add antonin pcrl
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);// Add antonin pcrl
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
@ -296,6 +299,10 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
//ddA
|
||||||
|
|
||||||
|
//Add Antonin : pcrl
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
//ddA
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->x, comp->dx << levelno),
|
(pi->x, comp->dx << levelno),
|
||||||
@ -358,62 +365,69 @@ int pi_next_pcrl(pi_iterator_t * pi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||||
for (pi->compno = pi->poc.compno0;
|
for (pi->compno = pi->poc.compno0;
|
||||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||||
comp = &pi->comps[pi->compno];
|
comp = &pi->comps[pi->compno];
|
||||||
for (pi->resno = pi->poc.resno0;
|
for (pi->resno = pi->poc.resno0;
|
||||||
pi->resno < int_min(pi->poc.resno1,
|
pi->resno < int_min(pi->poc.resno1,
|
||||||
comp->numresolutions); pi->resno++) {
|
comp->numresolutions); pi->resno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;// Add antonin pcrl
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
res = &comp->resolutions[pi->resno];
|
res = &comp->resolutions[pi->resno];
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);// Add antonin pcrl
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);// Add antonin pcrl
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
(pi->x % (comp->dx << rpx) == 0
|
(pi->x % (comp->dx << rpx) == 0
|
||||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!
|
if (!
|
||||||
(pi->y % (comp->dy << rpy) == 0
|
(pi->y % (comp->dy << rpy) == 0
|
||||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
//Add Antonin : sizebug1
|
||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
//ddA
|
||||||
|
|
||||||
|
//Add Antonin : pcrl
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
//ddA
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->x, comp->dx << levelno),
|
(pi->x, comp->dx << levelno),
|
||||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
||||||
prcj =
|
prcj =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->y, comp->dy << levelno),
|
(pi->y, comp->dy << levelno),
|
||||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
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 = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||||
if (!pi->
|
if (!pi->
|
||||||
include[pi->layno * pi->step_l +
|
include[pi->layno * pi->step_l +
|
||||||
pi->resno * pi->step_r +
|
pi->resno * pi->step_r +
|
||||||
pi->compno * pi->step_c +
|
pi->compno * pi->step_c +
|
||||||
pi->precno * pi->step_p]) {
|
pi->precno * pi->step_p]) {
|
||||||
pi->include[pi->layno * pi->step_l +
|
pi->include[pi->layno * pi->step_l +
|
||||||
pi->resno * pi->step_r +
|
pi->resno * pi->step_r +
|
||||||
pi->compno * pi->step_c +
|
pi->compno * pi->step_c +
|
||||||
pi->precno * pi->step_p] = 1;
|
pi->precno * pi->step_p] = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
skip:;
|
skip:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -460,12 +474,15 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||||||
comp->numresolutions); pi->resno++) {
|
comp->numresolutions); pi->resno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;// Add antonin pcrl
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
res = &comp->resolutions[pi->resno];
|
res = &comp->resolutions[pi->resno];
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);// Add antonin pcrl
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);// Add antonin pcrl
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
@ -483,6 +500,10 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
//ddA
|
||||||
|
|
||||||
|
//Add Antonin : pcrl
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
//ddA
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->x, comp->dx << levelno),
|
(pi->x, comp->dx << levelno),
|
||||||
|
@ -64,8 +64,8 @@ void tcd_dump(tcd_image_t * img, int curtileno)
|
|||||||
fprintf(stderr, "image {\n");
|
fprintf(stderr, "image {\n");
|
||||||
fprintf(stderr, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw, img->th,
|
fprintf(stderr, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw, img->th,
|
||||||
tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
|
tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
|
||||||
for (tileno = 0; tileno < 1; tileno++) {
|
for (tileno = 0; tileno < img->th*img->tw; tileno++) {
|
||||||
tcd_tile_t *tile = &tcd_image.tiles[curtileno];
|
tcd_tile_t *tile = &tcd_image.tiles[tileno];
|
||||||
fprintf(stderr, " tile {\n");
|
fprintf(stderr, " tile {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n", tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
|
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n", tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user