Structure j2k_option_t deleted and option "-reduce" integrated to j2k_cp_t.
Parameters changed for j2k_decode, jp2_decode, j2k_decode_jpt_stream
This commit is contained in:
parent
bc563fc5ba
commit
de5a22aea0
|
@ -43,9 +43,8 @@ int main(int argc, char **argv)
|
||||||
char *src, *src_name;
|
char *src, *src_name;
|
||||||
char *dest, S1, S2, S3;
|
char *dest, S1, S2, S3;
|
||||||
int len;
|
int len;
|
||||||
j2k_image_t *img;
|
j2k_image_t img;
|
||||||
j2k_cp_t *cp;
|
j2k_cp_t cp;
|
||||||
j2k_option_t option;
|
|
||||||
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;
|
||||||
|
@ -66,8 +65,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
dest = argv[2];
|
dest = argv[2];
|
||||||
|
|
||||||
option.reduce_on = 0;
|
cp.reduce_on = 0;
|
||||||
option.reduce_value = 0;
|
cp.reduce_value = 0;
|
||||||
|
|
||||||
/* OPTION REDUCE IS ACTIVE */
|
/* OPTION REDUCE IS ACTIVE */
|
||||||
if (argc == 5) {
|
if (argc == 5) {
|
||||||
|
@ -77,8 +76,8 @@ int main(int argc, char **argv)
|
||||||
" where n is the factor of reduction [%s]\n", argv[3]);
|
" where n is the factor of reduction [%s]\n", argv[3]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
option.reduce_on = 1;
|
cp.reduce_on = 1;
|
||||||
sscanf(argv[4], "%d", &option.reduce_value);
|
sscanf(argv[4], "%d", &cp.reduce_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*dest) {
|
while (*dest) {
|
||||||
|
@ -139,7 +138,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* 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')) {
|
||||||
if (!j2k_decode(src, len, &img, &cp, option)) {
|
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;
|
||||||
}
|
}
|
||||||
|
@ -147,11 +146,11 @@ int main(int argc, char **argv)
|
||||||
/* 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));
|
||||||
if (jp2_decode(src,len,jp2_struct,&cp, option)) {
|
jp2_struct->image=&img;
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
img = jp2_struct->image;
|
|
||||||
}
|
}
|
||||||
/* 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') || (S1 == 'J' && S2 == 'P' && S3 == 'T')){
|
||||||
|
@ -178,103 +177,103 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
switch (image_type) {
|
switch (image_type) {
|
||||||
case 1: /* PNM PGM PPM */
|
case 1: /* PNM PGM PPM */
|
||||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
if (img.numcomps == 3 && img.comps[0].dx == img.comps[1].dx
|
||||||
&& img->comps[1].dx == img->comps[2].dx
|
&& img.comps[1].dx == img.comps[2].dx
|
||||||
&& img->comps[0].dy == img->comps[1].dy
|
&& img.comps[0].dy == img.comps[1].dy
|
||||||
&& img->comps[1].dy == img->comps[2].dy
|
&& img.comps[1].dy == img.comps[2].dy
|
||||||
&& img->comps[0].prec == img->comps[1].prec
|
&& img.comps[0].prec == img.comps[1].prec
|
||||||
&& img->comps[1].prec == img->comps[2].prec) {
|
&& img.comps[1].prec == img.comps[2].prec) {
|
||||||
f = fopen(argv[2], "wb");
|
f = fopen(argv[2], "wb");
|
||||||
w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
w = ceildiv(img.x1 - img.x0, img.comps[0].dx);
|
||||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor),img->comps[0].dx);
|
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor),img.comps[0].dx);
|
||||||
wr = img->comps[0].w;
|
wr = img.comps[0].w;
|
||||||
wrr = int_ceildivpow2(img->comps[0].w, img->comps[0].factor);
|
wrr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
|
||||||
|
|
||||||
h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
h = ceildiv(img.y1 - img.y0, img.comps[0].dy);
|
||||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy);
|
||||||
hr = img->comps[0].h;
|
hr = img.comps[0].h;
|
||||||
hrr = int_ceildivpow2(img->comps[0].h, img->comps[0].factor);
|
hrr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
|
||||||
|
|
||||||
max = img->comps[0].prec > 8 ? 255 : (1 << img->comps[0].prec) - 1;
|
max = img.comps[0].prec > 8 ? 255 : (1 << img.comps[0].prec) - 1;
|
||||||
|
|
||||||
img->comps[0].x0 =
|
img.comps[0].x0 =
|
||||||
int_ceildivpow2(img->comps[0].x0 -
|
int_ceildivpow2(img.comps[0].x0 -
|
||||||
int_ceildiv(img->x0, img->comps[0].dx),
|
int_ceildiv(img.x0, img.comps[0].dx),
|
||||||
img->comps[0].factor);
|
img.comps[0].factor);
|
||||||
img->comps[0].y0 =
|
img.comps[0].y0 =
|
||||||
int_ceildivpow2(img->comps[0].y0 -
|
int_ceildivpow2(img.comps[0].y0 -
|
||||||
int_ceildiv(img->y0, img->comps[0].dy),
|
int_ceildiv(img.y0, img.comps[0].dy),
|
||||||
img->comps[0].factor);
|
img.comps[0].factor);
|
||||||
|
|
||||||
|
|
||||||
fprintf(f, "P6\n# %d %d %d %d %d\n%d %d\n%d\n",
|
fprintf(f, "P6\n# %d %d %d %d %d\n%d %d\n%d\n",
|
||||||
cp->tcps[cp->tileno[0]].tccps[0].numresolutions, w, h,
|
cp.tcps[cp.tileno[0]].tccps[0].numresolutions, w, h,
|
||||||
img->comps[0].x0, img->comps[0].y0, wrr, hrr, max);
|
img.comps[0].x0, img.comps[0].y0, wrr, hrr, max);
|
||||||
adjust = img->comps[0].prec > 8 ? img->comps[0].prec - 8 : 0;
|
adjust = img.comps[0].prec > 8 ? img.comps[0].prec - 8 : 0;
|
||||||
for (i = 0; i < wrr * hrr; i++) {
|
for (i = 0; i < wrr * hrr; i++) {
|
||||||
char r, g, b;
|
char r, g, b;
|
||||||
r = img->comps[0].data[i / wrr * wr + i % wrr];
|
r = img.comps[0].data[i / wrr * wr + i % wrr];
|
||||||
r += (img->comps[0].sgnd ? 1 << (img->comps[0].prec - 1) : 0);
|
r += (img.comps[0].sgnd ? 1 << (img.comps[0].prec - 1) : 0);
|
||||||
r = r >> adjust;
|
r = r >> adjust;
|
||||||
|
|
||||||
g = img->comps[1].data[i / wrr * wr + i % wrr];
|
g = img.comps[1].data[i / wrr * wr + i % wrr];
|
||||||
g += (img->comps[1].sgnd ? 1 << (img->comps[1].prec - 1) : 0);
|
g += (img.comps[1].sgnd ? 1 << (img.comps[1].prec - 1) : 0);
|
||||||
g = g >> adjust;
|
g = g >> adjust;
|
||||||
|
|
||||||
b = img->comps[2].data[i / wrr * wr + i % wrr];
|
b = img.comps[2].data[i / wrr * wr + i % wrr];
|
||||||
b += (img->comps[2].sgnd ? 1 << (img->comps[2].prec - 1) : 0);
|
b += (img.comps[2].sgnd ? 1 << (img.comps[2].prec - 1) : 0);
|
||||||
b = b >> adjust;
|
b = b >> adjust;
|
||||||
|
|
||||||
fprintf(f, "%c%c%c", r, g, b);
|
fprintf(f, "%c%c%c", r, g, b);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else {
|
} else {
|
||||||
for (compno = 0; compno < img->numcomps; compno++) {
|
for (compno = 0; compno < img.numcomps; compno++) {
|
||||||
char name[256];
|
char name[256];
|
||||||
if (img->numcomps > 1) {
|
if (img.numcomps > 1) {
|
||||||
sprintf(name, "%d.%s", compno, argv[2]);
|
sprintf(name, "%d.%s", compno, argv[2]);
|
||||||
} else {
|
} else {
|
||||||
sprintf(name, "%s", argv[2]);
|
sprintf(name, "%s", argv[2]);
|
||||||
}
|
}
|
||||||
f = fopen(name, "wb");
|
f = fopen(name, "wb");
|
||||||
w = ceildiv(img->x1 - img->x0, img->comps[compno].dx);
|
w = ceildiv(img.x1 - img.x0, img.comps[compno].dx);
|
||||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor),img->comps[compno].dx);
|
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor),img.comps[compno].dx);
|
||||||
wr = img->comps[compno].w;
|
wr = img.comps[compno].w;
|
||||||
wrr =
|
wrr =
|
||||||
int_ceildivpow2(img->comps[compno].w, img->comps[compno].factor);
|
int_ceildivpow2(img.comps[compno].w, img.comps[compno].factor);
|
||||||
|
|
||||||
h = ceildiv(img->y1 - img->y0, img->comps[compno].dy);
|
h = ceildiv(img.y1 - img.y0, img.comps[compno].dy);
|
||||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[compno].dy);
|
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[compno].dy);
|
||||||
hr = img->comps[compno].h;
|
hr = img.comps[compno].h;
|
||||||
hrr =
|
hrr =
|
||||||
int_ceildivpow2(img->comps[compno].h, img->comps[compno].factor);
|
int_ceildivpow2(img.comps[compno].h, img.comps[compno].factor);
|
||||||
|
|
||||||
max =
|
max =
|
||||||
img->comps[compno].prec >
|
img.comps[compno].prec >
|
||||||
8 ? 255 : (1 << img->comps[compno].prec) - 1;
|
8 ? 255 : (1 << img.comps[compno].prec) - 1;
|
||||||
|
|
||||||
img->comps[compno].x0 =
|
img.comps[compno].x0 =
|
||||||
int_ceildivpow2(img->comps[compno].x0 -
|
int_ceildivpow2(img.comps[compno].x0 -
|
||||||
int_ceildiv(img->x0,
|
int_ceildiv(img.x0,
|
||||||
img->comps[compno].dx),
|
img.comps[compno].dx),
|
||||||
img->comps[compno].factor);
|
img.comps[compno].factor);
|
||||||
img->comps[compno].y0 =
|
img.comps[compno].y0 =
|
||||||
int_ceildivpow2(img->comps[compno].y0 -
|
int_ceildivpow2(img.comps[compno].y0 -
|
||||||
int_ceildiv(img->y0,
|
int_ceildiv(img.y0,
|
||||||
img->comps[compno].dy),
|
img.comps[compno].dy),
|
||||||
img->comps[compno].factor);
|
img.comps[compno].factor);
|
||||||
|
|
||||||
fprintf(f, "P5\n# %d %d %d %d %d\n%d %d\n%d\n",
|
fprintf(f, "P5\n# %d %d %d %d %d\n%d %d\n%d\n",
|
||||||
cp->tcps[cp->tileno[0]].tccps[compno].
|
cp.tcps[cp.tileno[0]].tccps[compno].
|
||||||
numresolutions, w, h, img->comps[compno].x0,
|
numresolutions, w, h, img.comps[compno].x0,
|
||||||
img->comps[compno].y0, wrr, hrr, max);
|
img.comps[compno].y0, wrr, hrr, max);
|
||||||
adjust =
|
adjust =
|
||||||
img->comps[compno].prec > 8 ? img->comps[compno].prec - 8 : 0;
|
img.comps[compno].prec > 8 ? img.comps[compno].prec - 8 : 0;
|
||||||
for (i = 0; i < wrr * hrr; i++) {
|
for (i = 0; i < wrr * hrr; i++) {
|
||||||
char l;
|
char l;
|
||||||
l = img->comps[compno].data[i / wrr * wr + i % wrr];
|
l = img.comps[compno].data[i / wrr * wr + i % wrr];
|
||||||
l += (img->comps[compno].
|
l += (img.comps[compno].
|
||||||
sgnd ? 1 << (img->comps[compno].prec - 1) : 0);
|
sgnd ? 1 << (img.comps[compno].prec - 1) : 0);
|
||||||
l = l >> adjust;
|
l = l >> adjust;
|
||||||
fprintf(f, "%c", l);
|
fprintf(f, "%c", l);
|
||||||
}
|
}
|
||||||
|
@ -289,27 +288,27 @@ int main(int argc, char **argv)
|
||||||
/* / / */
|
/* / / */
|
||||||
/* /----------------------- / */
|
/* /----------------------- / */
|
||||||
case 0: /* PGX */
|
case 0: /* PGX */
|
||||||
for (compno = 0; compno < img->numcomps; compno++) {
|
for (compno = 0; compno < img.numcomps; compno++) {
|
||||||
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);
|
||||||
|
@ -317,7 +316,7 @@ int main(int argc, char **argv)
|
||||||
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);
|
||||||
|
@ -334,12 +333,12 @@ int main(int argc, char **argv)
|
||||||
/* /----------------------- / */
|
/* /----------------------- / */
|
||||||
|
|
||||||
case 2: /* BMP */
|
case 2: /* BMP */
|
||||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
if (img.numcomps == 3 && img.comps[0].dx == img.comps[1].dx
|
||||||
&& img->comps[1].dx == img->comps[2].dx
|
&& img.comps[1].dx == img.comps[2].dx
|
||||||
&& img->comps[0].dy == img->comps[1].dy
|
&& img.comps[0].dy == img.comps[1].dy
|
||||||
&& img->comps[1].dy == img->comps[2].dy
|
&& img.comps[1].dy == img.comps[2].dy
|
||||||
&& img->comps[0].prec == img->comps[1].prec
|
&& img.comps[0].prec == img.comps[1].prec
|
||||||
&& img->comps[1].prec == img->comps[2].prec) {
|
&& img.comps[1].prec == img.comps[2].prec) {
|
||||||
/* -->> -->> -->> -->>
|
/* -->> -->> -->> -->>
|
||||||
|
|
||||||
24 bits color
|
24 bits color
|
||||||
|
@ -347,15 +346,15 @@ int main(int argc, char **argv)
|
||||||
<<-- <<-- <<-- <<-- */
|
<<-- <<-- <<-- <<-- */
|
||||||
|
|
||||||
f = fopen(argv[2], "wb");
|
f = fopen(argv[2], "wb");
|
||||||
// w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
// w = ceildiv(img.x1 - img.x0, img.comps[0].dx);
|
||||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor), img->comps[0].dx);
|
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), img.comps[0].dx);
|
||||||
w = img->comps[0].w;
|
w = img.comps[0].w;
|
||||||
wr = int_ceildivpow2(img->comps[0].w, img->comps[0].factor);
|
wr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
|
||||||
|
|
||||||
// h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
// h = ceildiv(img.y1 - img.y0, img.comps[0].dy);
|
||||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy);
|
||||||
h = img->comps[0].h;
|
h = img.comps[0].h;
|
||||||
hr = int_ceildivpow2(img->comps[0].h, img->comps[0].factor);
|
hr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
|
||||||
|
|
||||||
fprintf(f, "BM");
|
fprintf(f, "BM");
|
||||||
|
|
||||||
|
@ -412,12 +411,12 @@ int main(int argc, char **argv)
|
||||||
for (i = 0; i < wr * hr; i++) {
|
for (i = 0; i < wr * hr; i++) {
|
||||||
unsigned char R, G, B;
|
unsigned char R, G, B;
|
||||||
/* a modifier */
|
/* a modifier */
|
||||||
// R = img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
// R = img.comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
R = img->comps[0].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
R = img.comps[0].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
// G = img->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
// G = img.comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
G = img->comps[1].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
G = img.comps[1].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
// B = img->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
// B = img.comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
B = img->comps[2].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
B = img.comps[2].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
fprintf(f, "%c%c%c", B, G, R);
|
fprintf(f, "%c%c%c", B, G, R);
|
||||||
|
|
||||||
if ((i + 1) % wr == 0) {
|
if ((i + 1) % wr == 0) {
|
||||||
|
@ -434,15 +433,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
<<-- <<-- <<-- <<-- */
|
<<-- <<-- <<-- <<-- */
|
||||||
f = fopen(argv[2], "wb");
|
f = fopen(argv[2], "wb");
|
||||||
// w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
// w = ceildiv(img.x1 - img.x0, img.comps[0].dx);
|
||||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor), img->comps[0].dx);
|
// wr = ceildiv(int_ceildivpow2(img.x1 - img.x0,img.factor), img.comps[0].dx);
|
||||||
w = img->comps[0].w;
|
w = img.comps[0].w;
|
||||||
wr = int_ceildivpow2(img->comps[0].w, img->comps[0].factor);
|
wr = int_ceildivpow2(img.comps[0].w, img.comps[0].factor);
|
||||||
|
|
||||||
// h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
// h = ceildiv(img.y1 - img.y0, img.comps[0].dy);
|
||||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
// hr = ceildiv(int_ceildivpow2(img.y1 - img.y0,img.factor), img.comps[0].dy);
|
||||||
h = img->comps[0].h;
|
h = img.comps[0].h;
|
||||||
hr = int_ceildivpow2(img->comps[0].h, img->comps[0].factor);
|
hr = int_ceildivpow2(img.comps[0].h, img.comps[0].factor);
|
||||||
|
|
||||||
fprintf(f, "BM");
|
fprintf(f, "BM");
|
||||||
|
|
||||||
|
@ -502,9 +501,9 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
for (i = 0; i < wr * hr; i++) {
|
for (i = 0; i < wr * hr; i++) {
|
||||||
/* a modifier !! */
|
/* a modifier !! */
|
||||||
// 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); */
|
||||||
|
|
|
@ -1096,7 +1096,7 @@ j2k_dec_mstabent_t *j2k_dec_mstab_lookup(int id) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
int j2k_decode(unsigned char *src, int len, j2k_image_t **image, j2k_cp_t **cp) {
|
int j2k_decode(unsigned char *src, int len, j2k_image_t *image, j2k_cp_t *cp) {
|
||||||
if (setjmp(j2k_error)) {
|
if (setjmp(j2k_error)) {
|
||||||
if (j2k_state != J2K_STATE_MT) {
|
if (j2k_state != J2K_STATE_MT) {
|
||||||
fprintf(stderr, "WARNING: incomplete bitstream\n");
|
fprintf(stderr, "WARNING: incomplete bitstream\n");
|
||||||
|
@ -1104,10 +1104,8 @@ int j2k_decode(unsigned char *src, int len, j2k_image_t **image, j2k_cp_t **cp)
|
||||||
}
|
}
|
||||||
return cio_numbytes();
|
return cio_numbytes();
|
||||||
}
|
}
|
||||||
j2k_img = (j2k_image_t*)calloc(1, sizeof(j2k_image_t));
|
j2k_img = img;
|
||||||
j2k_cp = (j2k_cp_t*)calloc(1, sizeof(j2k_cp_t));
|
j2k_cp = cp;
|
||||||
*image = j2k_img;
|
|
||||||
*cp = j2k_cp;
|
|
||||||
j2k_state = J2K_STATE_MHSOC;
|
j2k_state = J2K_STATE_MHSOC;
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -1195,7 +1193,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* decode */
|
/* decode */
|
||||||
|
|
||||||
if (!j2k_decode(j2kfile, totlen, &imgg, &cp)) {
|
if (!j2k_decode(j2kfile, totlen, imgg, cp)) {
|
||||||
fprintf(stderr, "Index_creator: failed to decode image!\n");
|
fprintf(stderr, "Index_creator: failed to decode image!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1408,8 +1408,9 @@ j2k_dec_mstabent_t *j2k_dec_mstab_lookup(int id)
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
|
|
||||||
j2k_cp_t ** cp, j2k_option_t option)
|
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t * img,
|
||||||
|
j2k_cp_t * cp)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (setjmp(j2k_error)) {
|
if (setjmp(j2k_error)) {
|
||||||
|
@ -1420,13 +1421,8 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
|
||||||
return cio_numbytes();
|
return cio_numbytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
j2k_img = (j2k_image_t *) malloc(sizeof(j2k_image_t));
|
j2k_img = img;
|
||||||
j2k_cp = (j2k_cp_t *) malloc(sizeof(j2k_cp_t));
|
j2k_cp = cp;
|
||||||
*img = j2k_img;
|
|
||||||
*cp = j2k_cp;
|
|
||||||
/* Option */
|
|
||||||
j2k_cp->reduce_on = option.reduce_on;
|
|
||||||
j2k_cp->reduce_value = option.reduce_value;
|
|
||||||
|
|
||||||
j2k_state = J2K_STATE_MHSOC;
|
j2k_state = J2K_STATE_MHSOC;
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
|
@ -1460,8 +1456,8 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
|
||||||
* Read a JPT-stream and decode file
|
* Read a JPT-stream and decode file
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img,
|
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
||||||
j2k_cp_t ** cp)
|
j2k_cp_t * cp)
|
||||||
{
|
{
|
||||||
jpt_msg_header_struct_t header;
|
jpt_msg_header_struct_t header;
|
||||||
int position;
|
int position;
|
||||||
|
@ -1474,10 +1470,8 @@ int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img,
|
||||||
return cio_numbytes();
|
return cio_numbytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
j2k_img = (j2k_image_t *) malloc(sizeof(j2k_image_t));
|
j2k_img = img;
|
||||||
j2k_cp = (j2k_cp_t *) malloc(sizeof(j2k_cp_t));
|
j2k_cp = cp;
|
||||||
*img = j2k_img;
|
|
||||||
*cp = j2k_cp;
|
|
||||||
|
|
||||||
j2k_state = J2K_STATE_MHSOC;
|
j2k_state = J2K_STATE_MHSOC;
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
|
|
|
@ -58,11 +58,6 @@
|
||||||
#define J2K_CCP_QNTSTY_SIQNT 1
|
#define J2K_CCP_QNTSTY_SIQNT 1
|
||||||
#define J2K_CCP_QNTSTY_SEQNT 2
|
#define J2K_CCP_QNTSTY_SEQNT 2
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int reduce_on; /* option reduce is used if reduce = 1 */
|
|
||||||
int reduce_value; /* if option reduce is used -> original dimension divided by 2^value */
|
|
||||||
} j2k_option_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int dx, dy; /* XRsiz, YRsiz */
|
int dx, dy; /* XRsiz, YRsiz */
|
||||||
int w, h; /* width and height of data */
|
int w, h; /* width and height of data */
|
||||||
|
@ -207,8 +202,9 @@ LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *output,
|
||||||
* i: decode image
|
* i: decode image
|
||||||
* cp: coding parameters that were used to encode the image
|
* cp: coding parameters that were used to encode the image
|
||||||
*/
|
*/
|
||||||
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
|
|
||||||
j2k_cp_t ** cp, j2k_option_t option);
|
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t * img,
|
||||||
|
j2k_cp_t * cp);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -219,7 +215,7 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
|
||||||
* cp: coding parameters that were used to encode the image
|
* cp: coding parameters that were used to encode the image
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img,
|
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
||||||
j2k_cp_t ** cp);
|
j2k_cp_t * cp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -445,7 +445,7 @@ int jp2_write_jp2c(j2k_image_t * img, j2k_cp_t * cp, char *jp2_buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
int jp2_read_jp2c(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
int jp2_read_jp2c(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
||||||
j2k_cp_t ** cp, j2k_option_t option)
|
j2k_cp_t * cp)
|
||||||
{
|
{
|
||||||
jp2_box_t box;
|
jp2_box_t box;
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ int jp2_read_jp2c(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
||||||
|
|
||||||
src += cio_tell();
|
src += cio_tell();
|
||||||
|
|
||||||
if (j2k_decode(src, len, &jp2_struct->image, cp, option) == 0) {
|
if (j2k_decode(src, len, jp2_struct->image, cp) == 0) {
|
||||||
fprintf(stderr, "JP2F box: failed to decode J2K bitstream image!\n");
|
fprintf(stderr, "JP2F box: failed to decode J2K bitstream image!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -509,7 +509,7 @@ int jp2_read_jp()
|
||||||
}
|
}
|
||||||
|
|
||||||
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
||||||
j2k_cp_t ** cp, j2k_option_t option)
|
j2k_cp_t * cp)
|
||||||
{
|
{
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
||||||
return 1;
|
return 1;
|
||||||
if (jp2_read_jp2h(jp2_struct))
|
if (jp2_read_jp2h(jp2_struct))
|
||||||
return 1;
|
return 1;
|
||||||
if (jp2_read_jp2c(src, len, jp2_struct, cp, option))
|
if (jp2_read_jp2c(src, len, jp2_struct, cp))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,6 @@ int jp2_encode(jp2_struct_t * jp2_struct, j2k_cp_t * cp, char *output,
|
||||||
char *index);
|
char *index);
|
||||||
|
|
||||||
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
||||||
j2k_cp_t ** cp, j2k_option_t option);
|
j2k_cp_t * cp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue