Update to version 0.9 : option -reduce added on decoder
This commit is contained in:
parent
8ed5edaefa
commit
1f7520c88b
|
@ -30,6 +30,7 @@
|
|||
#include <openjpeg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <unistd.h>
|
||||
|
||||
int ceildiv(int a, int b)
|
||||
|
@ -45,12 +46,13 @@ int main(int argc, char **argv)
|
|||
int len;
|
||||
j2k_image_t *img;
|
||||
j2k_cp_t *cp;
|
||||
int w, h, max;
|
||||
j2k_option_t option;
|
||||
int w, wr, wrr, h, hr, hrr, max;
|
||||
int i, image_type = -1, compno, pad;
|
||||
int adjust;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "usage: %s j2k-file pnm-file\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s j2k-file image-file -reduce n (<- optional)\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -62,6 +64,21 @@ int main(int argc, char **argv)
|
|||
|
||||
dest = argv[2];
|
||||
|
||||
option.reduce_on = 0;
|
||||
option.reduce_value = 0;
|
||||
|
||||
/* OPTION REDUCE IS ACTIVE */
|
||||
if (argc == 5)
|
||||
{
|
||||
if (strcmp(argv[3],"-reduce"))
|
||||
{
|
||||
fprintf(stderr, "usage: options ""-reduce n"" where n is the factor of reduction [%s]\n",argv[3]);
|
||||
return 1;
|
||||
}
|
||||
option.reduce_on = 1;
|
||||
sscanf(argv[4],"%d",&option.reduce_value);
|
||||
}
|
||||
|
||||
while (*dest) {
|
||||
dest++;
|
||||
}
|
||||
|
@ -111,7 +128,7 @@ int main(int argc, char **argv)
|
|||
|
||||
if (S1 == 'j' && S2 == '2' && S3 == 'k')
|
||||
{
|
||||
if (!j2k_decode(src, len, &img, &cp)) {
|
||||
if (!j2k_decode(src, len, &img, &cp, option)) {
|
||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -153,23 +170,35 @@ int main(int argc, char **argv)
|
|||
{
|
||||
f = fopen(argv[2], "wb");
|
||||
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 = img->comps[0].w;
|
||||
wrr = int_ceildivpow2(img->comps[0].w ,img->comps[0].factor);
|
||||
|
||||
h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||
//max = (1 << img->comps[0].prec) - 1;
|
||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
||||
hr = img->comps[0].h;
|
||||
hrr = int_ceildivpow2(img->comps[0].h ,img->comps[0].factor);
|
||||
|
||||
max = img->comps[0].prec > 8 ? 255 : (1 << img->comps[0].prec) - 1;
|
||||
fprintf(f, "P6\n%d %d\n%d\n", w, h, max);
|
||||
|
||||
img->comps[0].x0 = int_ceildivpow2(img->comps[0].x0 - int_ceildiv(img->x0, img->comps[0].dx),img->comps[0].factor);
|
||||
img->comps[0].y0 = int_ceildivpow2(img->comps[0].y0 - int_ceildiv(img->y0, img->comps[0].dy),img->comps[0].factor);
|
||||
|
||||
|
||||
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,img->comps[0].x0, img->comps[0].y0, wrr, hrr, max);
|
||||
adjust = img->comps[0].prec > 8 ? img->comps[0].prec - 8 : 0;
|
||||
for (i = 0; i < w * h; i++)
|
||||
for (i = 0; i < wrr * hrr; i++)
|
||||
{
|
||||
char r, g, b;
|
||||
r = img->comps[0].data[i];
|
||||
r = img->comps[0].data[i / wrr * wr + i % wrr];
|
||||
r += (img->comps[0].sgnd ? 1 << (img->comps[0].prec-1):0);
|
||||
r = r >> adjust;
|
||||
|
||||
g = img->comps[1].data[i];
|
||||
g = img->comps[1].data[i / wrr * wr + i % wrr];
|
||||
g += (img->comps[1].sgnd ? 1 << (img->comps[1].prec-1):0);
|
||||
g = g >> adjust;
|
||||
|
||||
b = img->comps[2].data[i];
|
||||
b = img->comps[2].data[i / wrr * wr + i % wrr];
|
||||
b += (img->comps[2].sgnd ? 1 << (img->comps[2].prec-1):0);
|
||||
b = b >> adjust;
|
||||
|
||||
|
@ -189,16 +218,29 @@ int main(int argc, char **argv)
|
|||
}
|
||||
f = fopen(name, "wb");
|
||||
w = ceildiv(img->x1 - img->x0, img->comps[compno].dx);
|
||||
// w = 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;
|
||||
wrr = int_ceildivpow2(img->comps[compno].w ,img->comps[compno].factor);
|
||||
|
||||
h = ceildiv(img->y1 - img->y0, img->comps[compno].dy);
|
||||
// h = 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;
|
||||
hrr = int_ceildivpow2(img->comps[compno].h ,img->comps[compno].factor);
|
||||
|
||||
max = img->comps[compno].prec > 8 ? 255 : (1 << img->comps[compno].prec) - 1;
|
||||
fprintf(f, "P5\n%d %d\n%d\n", w, h, max);
|
||||
|
||||
img->comps[compno].x0 = int_ceildivpow2(img->comps[compno].x0 - int_ceildiv(img->x0, img->comps[compno].dx),
|
||||
img->comps[compno].factor);
|
||||
img->comps[compno].y0 = int_ceildivpow2(img->comps[compno].y0 - int_ceildiv(img->y0, img->comps[compno].dy),
|
||||
img->comps[compno].factor);
|
||||
|
||||
fprintf(f, "P5\n# %d %d %d %d %d\n%d %d\n%d\n", cp->tcps[cp->tileno[0]].tccps[compno].numresolutions, w,
|
||||
h, img->comps[compno].x0, img->comps[compno].y0,wrr, hrr, max);
|
||||
adjust = img->comps[compno].prec > 8 ? img->comps[compno].prec - 8 : 0;
|
||||
for (i = 0; i < w * h; i++)
|
||||
for (i = 0; i < wrr * hrr; i++)
|
||||
{
|
||||
char l;
|
||||
l = img->comps[compno].data[i];
|
||||
l = img->comps[compno].data[i / wrr * wr + i % wrr];
|
||||
l += (img->comps[compno].sgnd ? 1 << (img->comps[compno].prec - 1) : 0);
|
||||
l = l >> adjust;
|
||||
fprintf(f, "%c", l);
|
||||
|
@ -222,13 +264,22 @@ int main(int argc, char **argv)
|
|||
sprintf(name, "%d_%s", compno, argv[2]);
|
||||
else
|
||||
sprintf(name, "%s", argv[2]);
|
||||
|
||||
f = fopen(name, "wb");
|
||||
w = ceildiv(img->x1 - img->x0, comp->dx);
|
||||
h = ceildiv(img->y1 - img->y0, comp->dy);
|
||||
fprintf(f, "PG LM %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, w, h);
|
||||
for (i = 0; i < w * h; i++)
|
||||
// w = ceildiv(img->x1 - img->x0, comp->dx);
|
||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor), comp->dx);
|
||||
w = img->comps[compno].w;
|
||||
wr = int_ceildivpow2(img->comps[compno].w ,img->comps[compno].factor);
|
||||
|
||||
// h = ceildiv(img->y1 - img->y0, comp->dy);
|
||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), comp->dy);
|
||||
h = img->comps[compno].h;
|
||||
hr = int_ceildivpow2(img->comps[compno].h ,img->comps[compno].factor);
|
||||
|
||||
fprintf(f, "PG LM %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, wr, hr);
|
||||
for (i = 0; i < wr * hr; i++)
|
||||
{
|
||||
int v = img->comps[compno].data[i];
|
||||
int v = img->comps[compno].data[i / wr * w + i % wr];
|
||||
if (comp->prec <= 8)
|
||||
{
|
||||
char c = (char) v;
|
||||
|
@ -267,52 +318,62 @@ int main(int argc, char **argv)
|
|||
<<-- <<-- <<-- <<-- */
|
||||
|
||||
f = fopen(argv[2], "wb");
|
||||
w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||
h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||
// w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor), img->comps[0].dx);
|
||||
w = img->comps[0].w;
|
||||
wr = int_ceildivpow2(img->comps[0].w ,img->comps[0].factor);
|
||||
|
||||
// h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
||||
h = img->comps[0].h;
|
||||
hr = int_ceildivpow2(img->comps[0].h ,img->comps[0].factor);
|
||||
|
||||
fprintf(f, "BM");
|
||||
|
||||
/* FILE HEADER */
|
||||
/* ------------- */
|
||||
fprintf(f, "%c%c%c%c",
|
||||
(unsigned char) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff);
|
||||
(unsigned char) (hr * wr * 3 + 3 * hr * (wr % 2) + 54) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54) >> 8) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54) >> 16) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff, ((54) >> 16) & 0xff, ((54) >> 24) & 0xff);
|
||||
|
||||
/* INFO HEADER */
|
||||
/* ------------- */
|
||||
fprintf(f, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((w) & 0xff),(unsigned char) ((w) >> 8) & 0xff,
|
||||
(unsigned char) ((w) >> 16) & 0xff, (unsigned char) ((w) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((h) & 0xff), (unsigned char) ((h) >> 8) & 0xff,
|
||||
(unsigned char) ((h) >> 16) & 0xff, (unsigned char) ((h) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((wr) & 0xff),(unsigned char) ((wr) >> 8) & 0xff,
|
||||
(unsigned char) ((wr) >> 16) & 0xff, (unsigned char) ((wr) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((hr) & 0xff), (unsigned char) ((hr) >> 8) & 0xff,
|
||||
(unsigned char) ((hr) >> 16) & 0xff, (unsigned char) ((hr) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
|
||||
fprintf(f, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) (3 * h * w + 3 * h * (w % 2)) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) (3 * hr * wr + 3 * hr * (wr % 2)) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
|
||||
for (i = 0; i < w * h; i++)
|
||||
for (i = 0; i < wr * hr; i++)
|
||||
{
|
||||
unsigned char R, G, B;
|
||||
|
||||
R = img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||
G = img->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||
B = img->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||
/* a modifier */
|
||||
// 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)];
|
||||
// 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)];
|
||||
// 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)];
|
||||
fprintf(f, "%c%c%c", B, G, R);
|
||||
|
||||
if ((i + 1) % w == 0)
|
||||
if ((i + 1) % wr == 0)
|
||||
{
|
||||
for (pad = (3*w)%4?4-(3*w)%4:0 ; pad > 0 ; pad--) /* ADD */
|
||||
for (pad = (3 * wr) % 4 ? 4 - (3 * wr) % 4 : 0 ; pad > 0 ; pad--) /* ADD */
|
||||
fprintf(f, "%c", 0);
|
||||
}
|
||||
}
|
||||
|
@ -326,18 +387,25 @@ int main(int argc, char **argv)
|
|||
|
||||
<<-- <<-- <<-- <<-- */
|
||||
f = fopen(argv[2], "wb");
|
||||
w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||
h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||
// w = ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||
// wr = ceildiv(int_ceildivpow2(img->x1 - img->x0,img->factor), img->comps[0].dx);
|
||||
w = img->comps[0].w;
|
||||
wr = int_ceildivpow2(img->comps[0].w ,img->comps[0].factor);
|
||||
|
||||
// h = ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||
// hr = ceildiv(int_ceildivpow2(img->y1 - img->y0,img->factor), img->comps[0].dy);
|
||||
h = img->comps[0].h;
|
||||
hr = int_ceildivpow2(img->comps[0].h ,img->comps[0].factor);
|
||||
|
||||
fprintf(f, "BM");
|
||||
|
||||
/* FILE HEADER */
|
||||
/* ------------- */
|
||||
fprintf(f, "%c%c%c%c",
|
||||
(unsigned char) (h * w + 54 + 1024 + h * (w % 2)) & 0xff,
|
||||
(unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff);
|
||||
(unsigned char) (hr * wr + 54 + 1024 + hr * (wr % 2)) & 0xff,
|
||||
(unsigned char) ((hr * wr + 54 + 1024 + hr * (wr % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((hr * wr + 54 + 1024 + hr * (wr % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((hr * wr + 54 + 1024 + wr * (wr % 2)) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff,
|
||||
((54 + 1024) >> 16) & 0xff, ((54 + 1024) >> 24) & 0xff);
|
||||
|
@ -345,17 +413,17 @@ int main(int argc, char **argv)
|
|||
/* INFO HEADER */
|
||||
/* ------------- */
|
||||
fprintf(f, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((w) & 0xff), (unsigned char) ((w) >> 8) & 0xff,
|
||||
(unsigned char) ((w) >> 16) & 0xff, (unsigned char) ((w) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((h) & 0xff), (unsigned char) ((h) >> 8) & 0xff,
|
||||
(unsigned char) ((h) >> 16) & 0xff, (unsigned char) ((h) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((wr) & 0xff), (unsigned char) ((wr) >> 8) & 0xff,
|
||||
(unsigned char) ((wr) >> 16) & 0xff, (unsigned char) ((wr) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) ((hr) & 0xff), (unsigned char) ((hr) >> 8) & 0xff,
|
||||
(unsigned char) ((hr) >> 16) & 0xff, (unsigned char) ((hr) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
|
||||
fprintf(f, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) (h * w + h * (w % 2)) & 0xff,
|
||||
(unsigned char) ((h * w + h * (w % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((h * w + h * (w % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((h * w + h * (w % 2)) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (unsigned char) (hr * wr + hr * (wr % 2)) & 0xff,
|
||||
(unsigned char) ((hr * wr + hr * (wr % 2)) >> 8) & 0xff,
|
||||
(unsigned char) ((hr * wr + hr * (wr % 2)) >> 16) & 0xff,
|
||||
(unsigned char) ((hr * wr + hr * (wr % 2)) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||
fprintf(f, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
|
||||
|
@ -367,12 +435,19 @@ int main(int argc, char **argv)
|
|||
fprintf(f, "%c%c%c%c", i, i, i, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < w * h; i++)
|
||||
for (i = 0; i < wr * hr; i++)
|
||||
{
|
||||
fprintf(f, "%c", img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]);
|
||||
if (((i + 1) % w == 0 && w % 2))
|
||||
/* 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 * hr - ((i) / (wr) + 1) * w + (i) % (wr)]);
|
||||
/*if (((i + 1) % w == 0 && w % 2))
|
||||
fprintf(f, "%c", 0);*/
|
||||
if ((i + 1) % wr == 0)
|
||||
{
|
||||
for (pad = wr % 4 ? 4 - wr % 4 : 0 ; pad > 0 ; pad--) /* ADD */
|
||||
fprintf(f, "%c", 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
|
|
|
@ -234,7 +234,7 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
|||
/* <summary> */
|
||||
/* Inverse 5-3 wavelet tranform in 2-D. */
|
||||
/* </summary> */
|
||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)//, tcd_tilecomp_t * row_tilec, tcd_tilecomp_t * col_tilec)
|
||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop)
|
||||
{
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
|
@ -242,7 +242,7 @@ void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)//, tcd_tile
|
|||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
|
||||
for (i = l - 1; i >= 0; i--) {
|
||||
for (i = l - 1; i >= stop; i--) {
|
||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
|
||||
|
@ -400,7 +400,7 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
|||
/* <summary> */
|
||||
/* Inverse 9-7 wavelet transform in 2-D. */
|
||||
/* </summary> */
|
||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)//, tcd_tilecomp_t * row_tilec, tcd_tilecomp_t * col_tilec)
|
||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop)
|
||||
{
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
|
@ -408,7 +408,7 @@ void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)//, tcd
|
|||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
|
||||
for (i = l - 1; i >= 0; i--) {
|
||||
for (i = l - 1; i >= stop; i--) {
|
||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
|
|||
* row_tilec : tile component information (previous tile on the same row)
|
||||
* col_tilec : tile component information (previous tile on the same column)
|
||||
*/
|
||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);//, tcd_tilecomp_t * row_tilec, tcd_tilecomp_t * col_tilec);
|
||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop);
|
||||
|
||||
/*
|
||||
* Get the gain of a subband for the reversible DWT
|
||||
|
@ -82,7 +82,7 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
|
|||
* h: height of the component
|
||||
* l: number of decomposition levels in the DWT
|
||||
*/
|
||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);//, tcd_tilecomp_t * row_tilec, tcd_tilecomp_t * col_tilec);
|
||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop);
|
||||
/*
|
||||
* Get the gain of a subband for the irreversible DWT
|
||||
* orient: number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
|
||||
|
|
|
@ -182,13 +182,11 @@ void j2k_dump_cp(j2k_image_t * img, j2k_cp_t * cp)
|
|||
|
||||
void j2k_write_soc()
|
||||
{
|
||||
/* fprintf(stderr, "%.8x: SOC\n", cio_tell()); */
|
||||
cio_write(J2K_MS_SOC, 2);
|
||||
}
|
||||
|
||||
void j2k_read_soc()
|
||||
{
|
||||
fprintf(stderr, "%.8x: SOC\n", cio_tell()-2);
|
||||
j2k_state = J2K_STATE_MHSIZ;
|
||||
}
|
||||
|
||||
|
@ -196,7 +194,7 @@ void j2k_write_siz()
|
|||
{
|
||||
int i;
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: SIZ\n", cio_tell()); */
|
||||
|
||||
cio_write(J2K_MS_SIZ, 2); /* SIZ */
|
||||
lenp = cio_tell();
|
||||
cio_skip(2);
|
||||
|
@ -225,7 +223,7 @@ void j2k_write_siz()
|
|||
void j2k_read_siz()
|
||||
{
|
||||
int len, i;
|
||||
fprintf(stderr, "%.8x: SIZ\n", cio_tell());
|
||||
|
||||
len = cio_read(2); /* Lsiz */
|
||||
cio_read(2); /* Rsiz (capabilities) */
|
||||
j2k_img->x1 = cio_read(4); /* Xsiz */
|
||||
|
@ -248,12 +246,16 @@ void j2k_read_siz()
|
|||
j2k_img->comps[i].dy = cio_read(1); /* YRsiz_i */
|
||||
w = int_ceildiv(j2k_img->x1 - j2k_img->x0, j2k_img->comps[i].dx);
|
||||
h = int_ceildiv(j2k_img->y1 - j2k_img->y0, j2k_img->comps[i].dy);
|
||||
j2k_img->comps[i].data = (int *) malloc(sizeof(int) * w * h);
|
||||
j2k_img->comps[i].resno_decoded = 0; /* number of resolution decoded */
|
||||
j2k_img->comps[i].factor = 0; /* reducing factor by component */
|
||||
}
|
||||
|
||||
j2k_cp->tw = int_ceildiv(j2k_img->x1 - j2k_cp->tx0, j2k_cp->tdx);
|
||||
j2k_cp->th = int_ceildiv(j2k_img->y1 - j2k_cp->ty0, j2k_cp->tdy);
|
||||
j2k_cp->tcps = (j2k_tcp_t *) calloc(j2k_cp->tw * j2k_cp->th, sizeof(j2k_tcp_t));
|
||||
j2k_cp->tileno = (int*)calloc(j2k_cp->tw * j2k_cp->th, sizeof(int));
|
||||
j2k_cp->tileno_size = 0;
|
||||
|
||||
for (i=0; i<j2k_cp->tw * j2k_cp->th; i++)
|
||||
{
|
||||
j2k_cp->tcps[i].POC=0;
|
||||
|
@ -284,7 +286,7 @@ void j2k_write_com()
|
|||
int lenp, len;
|
||||
char str[256];
|
||||
sprintf(str, "%s", j2k_cp->comment);
|
||||
/* fprintf(stderr, "%.8x: COM\n", cio_tell()); */
|
||||
|
||||
cio_write(J2K_MS_COM, 2);
|
||||
lenp = cio_tell();
|
||||
cio_skip(2);
|
||||
|
@ -302,7 +304,7 @@ void j2k_write_com()
|
|||
void j2k_read_com()
|
||||
{
|
||||
int len;
|
||||
fprintf(stderr, "%.8x: COM\n", cio_tell()-2);
|
||||
|
||||
len = cio_read(2);
|
||||
cio_skip(len - 2);
|
||||
|
||||
|
@ -354,7 +356,7 @@ void j2k_write_cod()
|
|||
{
|
||||
j2k_tcp_t *tcp;
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: COD\n", cio_tell()+pos_correction); */
|
||||
|
||||
cio_write(J2K_MS_COD, 2); /* COD */
|
||||
|
||||
lenp = cio_tell();
|
||||
|
@ -377,15 +379,14 @@ void j2k_read_cod()
|
|||
{
|
||||
int len, i, pos;
|
||||
j2k_tcp_t *tcp;
|
||||
fprintf(stderr, "%.8x: COD\n", cio_tell()-2);
|
||||
|
||||
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
|
||||
len = cio_read(2); /* Lcod */
|
||||
tcp->csty = cio_read(1); /* Scod */
|
||||
tcp->prg = cio_read(1); /* SGcod (A) */
|
||||
tcp->numlayers = cio_read(2); /* SGcod (B) */
|
||||
tcp->mct = cio_read(1); /* SGcod (C) */
|
||||
/*tcp->numpocs=0;
|
||||
tcp->POC=0;*/
|
||||
|
||||
pos = cio_tell();
|
||||
for (i = 0; i < j2k_img->numcomps; i++) {
|
||||
tcp->tccps[i].csty = tcp->csty & J2K_CP_CSTY_PRT;
|
||||
|
@ -398,7 +399,7 @@ void j2k_write_coc(int compno)
|
|||
{
|
||||
j2k_tcp_t *tcp;
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: COC\n", cio_tell()+pos_correction); */
|
||||
|
||||
cio_write(J2K_MS_COC, 2); /* COC */
|
||||
lenp = cio_tell();
|
||||
cio_skip(2);
|
||||
|
@ -416,7 +417,7 @@ void j2k_read_coc()
|
|||
{
|
||||
int len, compno;
|
||||
j2k_tcp_t *tcp;
|
||||
fprintf(stderr, "%.8x: COC\n", cio_tell());
|
||||
|
||||
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
|
||||
len = cio_read(2); /* Lcoc */
|
||||
compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2); /* Ccoc */
|
||||
|
@ -430,6 +431,7 @@ void j2k_write_qcx(int compno)
|
|||
j2k_tccp_t *tccp;
|
||||
int bandno, numbands;
|
||||
int expn, mant;
|
||||
|
||||
tcp = &j2k_cp->tcps[j2k_curtileno];
|
||||
tccp = &tcp->tccps[compno];
|
||||
|
||||
|
@ -455,6 +457,7 @@ void j2k_read_qcx(int compno, int len)
|
|||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tccp;
|
||||
int bandno, numbands;
|
||||
|
||||
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
|
||||
tccp = &tcp->tccps[compno];
|
||||
tmp = cio_read(1); /* Sqcx */
|
||||
|
@ -479,7 +482,7 @@ void j2k_read_qcx(int compno, int len)
|
|||
void j2k_write_qcd()
|
||||
{
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: QCD\n", cio_tell()+pos_correction); */
|
||||
|
||||
cio_write(J2K_MS_QCD, 2); /* QCD */
|
||||
lenp = cio_tell();
|
||||
cio_skip(2);
|
||||
|
@ -493,7 +496,7 @@ void j2k_write_qcd()
|
|||
void j2k_read_qcd()
|
||||
{
|
||||
int len, i, pos;
|
||||
fprintf(stderr, "%.8x: QCD\n", cio_tell()-2);
|
||||
|
||||
len = cio_read(2); /* Lqcd */
|
||||
pos = cio_tell();
|
||||
for (i = 0; i < j2k_img->numcomps; i++) {
|
||||
|
@ -505,7 +508,7 @@ void j2k_read_qcd()
|
|||
void j2k_write_qcc(int compno)
|
||||
{
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: QCC\n", cio_tell()+pos_correction); */
|
||||
|
||||
cio_write(J2K_MS_QCC, 2); /* QCC */
|
||||
lenp = cio_tell();
|
||||
cio_skip(2);
|
||||
|
@ -520,7 +523,7 @@ void j2k_write_qcc(int compno)
|
|||
void j2k_read_qcc()
|
||||
{
|
||||
int len, compno;
|
||||
fprintf(stderr, "%.8x: QCC\n", cio_tell()-2);
|
||||
|
||||
len = cio_read(2); /* Lqcc */
|
||||
compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2); /* Cqcc */
|
||||
j2k_read_qcx(compno, len - 2 - (j2k_img->numcomps <= 256 ? 1 : 2));
|
||||
|
@ -530,7 +533,7 @@ void j2k_write_poc() {
|
|||
int len, numpchgs, i;
|
||||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tccp;
|
||||
fprintf(stderr, "%.8x: POC\n", cio_tell() + pos_correction);
|
||||
|
||||
tcp = &j2k_cp->tcps[j2k_curtileno];
|
||||
tccp = &tcp->tccps[0];
|
||||
numpchgs = tcp->numpocs;
|
||||
|
@ -558,11 +561,10 @@ void j2k_read_poc() {
|
|||
int len, numpchgs, i, old_poc;
|
||||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tccp;
|
||||
fprintf(stderr, "%.8x: POC\n", cio_tell()-2);
|
||||
|
||||
tcp = j2k_state==J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
|
||||
|
||||
old_poc = tcp->POC ? tcp->numpocs+1 : 0;
|
||||
printf("old_poc %d\n",old_poc);
|
||||
tcp->POC = 1;
|
||||
tccp = &tcp->tccps[0];
|
||||
len = cio_read(2); /* Lpoc */
|
||||
|
@ -578,7 +580,6 @@ void j2k_read_poc() {
|
|||
poc->resno1 = int_min(cio_read(1), tccp->numresolutions); /* REpoc_i */
|
||||
poc->compno1 = int_min(cio_read(j2k_img->numcomps <= 256 ? 1 : 2), j2k_img->numcomps); /* CEpoc_i */
|
||||
poc->prg = cio_read(1); /* Ppoc_i */
|
||||
printf("res0 %d comp0 %d lay1 %d res1 %d comp1 %d prg %d\n",poc->resno0,poc->compno0,poc->layno1,poc->resno1,poc->compno1,poc->prg);
|
||||
}
|
||||
|
||||
tcp->numpocs = numpchgs+old_poc-1;
|
||||
|
@ -587,7 +588,7 @@ void j2k_read_poc() {
|
|||
void j2k_read_crg()
|
||||
{
|
||||
int len, i, Xcrg_i, Ycrg_i;
|
||||
fprintf(stderr, "%.8x: CRG\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2); /* Lcrg */
|
||||
for (i=0;i<j2k_img->numcomps;i++)
|
||||
{
|
||||
|
@ -600,7 +601,7 @@ void j2k_read_tlm()
|
|||
{
|
||||
int len, Ztlm, Stlm, ST, SP, tile_tlm, i;
|
||||
long int Ttlm_i, Ptlm_i;
|
||||
fprintf(stderr, "%.8x: TLM\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2); /* Ltlm */
|
||||
Ztlm = cio_read(1); /* Ztlm */
|
||||
Stlm = cio_read(1); /* Stlm */
|
||||
|
@ -617,7 +618,7 @@ void j2k_read_tlm()
|
|||
void j2k_read_plm()
|
||||
{
|
||||
int len, i, Zplm, Nplm, add, packet_len = 0;
|
||||
fprintf(stderr, "%.8x: PLM\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2); /* Lplm */
|
||||
Zplm = cio_read(1); /* Zplm */
|
||||
len-=3;
|
||||
|
@ -643,7 +644,7 @@ void j2k_read_plm()
|
|||
void j2k_read_plt()
|
||||
{
|
||||
int len, i, Zplt, packet_len=0, add;
|
||||
fprintf(stderr, "%.8x: PLT\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2); /* Lplt */
|
||||
Zplt=cio_read(1); /* Zplt */
|
||||
for (i=len-3;i>0;i--)
|
||||
|
@ -662,7 +663,7 @@ void j2k_read_ppm()
|
|||
{
|
||||
int len, Z_ppm, i, j;
|
||||
int N_ppm;
|
||||
fprintf(stderr, "%.8x: PPM\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2);
|
||||
j2k_cp->ppm=1;
|
||||
|
||||
|
@ -702,7 +703,7 @@ void j2k_read_ppt()
|
|||
{
|
||||
int len, Z_ppt, i, j=0;
|
||||
j2k_tcp_t *tcp;
|
||||
fprintf(stderr, "%.8x: PPT\n", cio_tell() - 2);
|
||||
|
||||
len = cio_read(2);
|
||||
Z_ppt = cio_read(1);
|
||||
tcp=&j2k_cp->tcps[j2k_curtileno];
|
||||
|
@ -727,7 +728,7 @@ void j2k_read_ppt()
|
|||
void j2k_write_sot()
|
||||
{
|
||||
int lenp, len;
|
||||
/* fprintf(stderr, "%.8x: SOT\n", cio_tell()+pos_correction); */
|
||||
|
||||
j2k_sot_start = cio_tell();
|
||||
cio_write(J2K_MS_SOT, 2); /* SOT */
|
||||
lenp = cio_tell();
|
||||
|
@ -747,10 +748,31 @@ void j2k_read_sot()
|
|||
int len, tileno, totlen, partno, numparts, i;
|
||||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tmp;
|
||||
char status = 0;
|
||||
|
||||
fprintf(stderr, "%.8x: SOT\n", cio_tell()-2);
|
||||
len = cio_read(2);
|
||||
tileno = cio_read(2);
|
||||
|
||||
if (j2k_cp->tileno_size == 0)
|
||||
{
|
||||
j2k_cp->tileno[j2k_cp->tileno_size] = tileno;
|
||||
j2k_cp->tileno_size++;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
while (i < j2k_cp->tileno_size && status == 0)
|
||||
{
|
||||
status = j2k_cp->tileno[i] == tileno ? 1 : 0;
|
||||
i++;
|
||||
}
|
||||
if (status == 0)
|
||||
{
|
||||
j2k_cp->tileno[j2k_cp->tileno_size] = tileno;
|
||||
j2k_cp->tileno_size++;
|
||||
}
|
||||
}
|
||||
|
||||
totlen = cio_read(4);
|
||||
if (!totlen)
|
||||
totlen = cio_numbytesleft() + 8;
|
||||
|
@ -787,7 +809,6 @@ void j2k_write_sod()
|
|||
j2k_tcp_t *tcp;
|
||||
static int j2k_sod_start;
|
||||
|
||||
/* fprintf(stderr, "%.8x: SOD\n", cio_tell()+pos_correction); */
|
||||
cio_write(J2K_MS_SOD, 2);
|
||||
if (j2k_curtileno == 0) {
|
||||
j2k_sod_start = cio_tell() + pos_correction;
|
||||
|
@ -796,15 +817,14 @@ void j2k_write_sod()
|
|||
/* INDEX >> */
|
||||
if (info_IM.index_on) {
|
||||
info_IM.tile[j2k_curtileno].end_header = cio_tell() + pos_correction - 1;
|
||||
info_IM.tile[j2k_curtileno].packet = (info_packet *) calloc(info_IM.Comp * info_IM.Layer * (info_IM.Decomposition + 1) *
|
||||
10,sizeof(info_packet));
|
||||
info_IM.tile[j2k_curtileno].packet = (info_packet *) calloc(info_IM.Comp * info_IM.Layer *
|
||||
(info_IM.Decomposition + 1) * 100,sizeof(info_packet));
|
||||
}
|
||||
/* << INDEX */
|
||||
|
||||
tcp = &j2k_cp->tcps[j2k_curtileno];
|
||||
for (layno = 0; layno < tcp->numlayers; layno++) {
|
||||
tcp->rates[layno] -= (j2k_sod_start / (j2k_cp->th * j2k_cp->tw));
|
||||
/* fprintf(stderr, "tcp->rates[%d]=%d\n", layno, tcp->rates[layno]); */
|
||||
}
|
||||
|
||||
info_IM.num = 0;
|
||||
|
@ -822,20 +842,23 @@ void j2k_write_sod()
|
|||
|
||||
void j2k_read_sod()
|
||||
{
|
||||
int len, truncate = 0;
|
||||
int len, truncate = 0, i;
|
||||
unsigned char *data;
|
||||
|
||||
fprintf(stderr, "%.8x: SOD\n", cio_tell()-2);
|
||||
len = int_min(j2k_eot - cio_getbp(), cio_numbytesleft() + 1);
|
||||
if (len == cio_numbytesleft() + 1)
|
||||
truncate = 1; /* Case of a truncate codestream */
|
||||
|
||||
j2k_tile_len[j2k_curtileno] += len;
|
||||
data = (unsigned char *) realloc(j2k_tile_data[j2k_curtileno], j2k_tile_len[j2k_curtileno]);
|
||||
memcpy(data, cio_getbp(), len);
|
||||
j2k_tile_data[j2k_curtileno] = data;
|
||||
data = (unsigned char*)malloc((j2k_tile_len[j2k_curtileno] + len) * sizeof(unsigned char));
|
||||
for (i=0; i<j2k_tile_len[j2k_curtileno]; i++)
|
||||
data[i] = j2k_tile_data[j2k_curtileno][i];
|
||||
for (i=0 ; i<len ; i++)
|
||||
data[i+j2k_tile_len[j2k_curtileno]] = cio_read(1);
|
||||
|
||||
cio_skip(len);
|
||||
j2k_tile_len[j2k_curtileno] += len;
|
||||
free(j2k_tile_data[j2k_curtileno]);
|
||||
j2k_tile_data[j2k_curtileno] = data;
|
||||
data=NULL;
|
||||
|
||||
if (!truncate)
|
||||
j2k_state = J2K_STATE_TPHSOT;
|
||||
|
@ -846,7 +869,7 @@ void j2k_read_sod()
|
|||
void j2k_write_rgn(int compno, int tileno)
|
||||
{
|
||||
j2k_tcp_t *tcp = &j2k_cp->tcps[tileno];
|
||||
/* fprintf(stderr, "%.8x: RGN\n",cio_tell()+pos_correction); */
|
||||
|
||||
cio_write(J2K_MS_RGN, 2); /* RGN */
|
||||
cio_write(j2k_img->numcomps <= 256 ? 5 : 6, 2); /* Lrgn */
|
||||
cio_write(compno, j2k_img->numcomps <= 256 ? 1 : 2); /* Crgn */
|
||||
|
@ -858,7 +881,7 @@ void j2k_read_rgn()
|
|||
{
|
||||
int len, compno, roisty;
|
||||
j2k_tcp_t *tcp;
|
||||
fprintf(stderr, "%.8x: RGN\n", cio_tell() - 2);
|
||||
|
||||
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
|
||||
len = cio_read(2); /* Lrgn */
|
||||
compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2); /* Crgn */
|
||||
|
@ -874,13 +897,12 @@ void j2k_write_eoc()
|
|||
|
||||
void j2k_read_eoc()
|
||||
{
|
||||
int tileno;
|
||||
fprintf(stderr, "%.8x: EOC\n", cio_tell()-2);
|
||||
/* j2k_dump_image(j2k_img); */
|
||||
/* j2k_dump_cp(j2k_img, j2k_cp); */
|
||||
int i, tileno;
|
||||
|
||||
tcd_init(j2k_img, j2k_cp);
|
||||
for (tileno = 0; tileno < j2k_cp->tw * j2k_cp->th; tileno++) {
|
||||
|
||||
for (i = 0; i < j2k_cp->tileno_size; i++) {
|
||||
tileno = j2k_cp->tileno[i];
|
||||
tcd_decode_tile(j2k_tile_data[tileno], j2k_tile_len[tileno], tileno);
|
||||
}
|
||||
|
||||
|
@ -1053,7 +1075,7 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
|
|||
fprintf(INDEX, "%d %d\n", info_IM.pdx, info_IM.pdy);
|
||||
fprintf(INDEX, "%d\n", info_IM.Main_head_end);
|
||||
fprintf(INDEX, "%d\n", info_IM.codestream_size);
|
||||
|
||||
fprintf(INDEX, "%f\n",info_IM.D_max);
|
||||
for (tileno = 0; tileno < j2k_cp->tw * j2k_cp->th; tileno++) {
|
||||
fprintf(INDEX, "%d %d %d %d", info_IM.tile[tileno].num_tile,
|
||||
info_IM.tile[tileno].start_pos,
|
||||
|
@ -1073,7 +1095,7 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
|
|||
precno <
|
||||
info_IM.tile[tileno].pw * info_IM.tile[tileno].ph;
|
||||
precno++) {
|
||||
fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto);
|
||||
fprintf(INDEX,"%d %d %d %d %d %d %d %d %.08f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max);
|
||||
/*fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb, tileno, layno, resno, compno, precno, info_IM.tile[tileno].packet[pack_nb].start_pos, info_IM.tile[tileno].packet[pack_nb].end_pos);*/
|
||||
pack_nb++;
|
||||
}
|
||||
|
@ -1188,7 +1210,7 @@ j2k_dec_mstabent_t *j2k_dec_mstab_lookup(int id)
|
|||
return e;
|
||||
}
|
||||
|
||||
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp)
|
||||
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp, j2k_option_t option)
|
||||
{
|
||||
|
||||
if (setjmp(j2k_error)) {
|
||||
|
@ -1203,6 +1225,10 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_c
|
|||
j2k_cp = (j2k_cp_t *) malloc(sizeof(j2k_cp_t));
|
||||
*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;
|
||||
cio_init(src, len);
|
||||
|
||||
|
@ -1251,6 +1277,7 @@ int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_c
|
|||
j2k_cp = (j2k_cp_t *) malloc(sizeof(j2k_cp_t));
|
||||
*img = j2k_img;
|
||||
*cp = j2k_cp;
|
||||
|
||||
j2k_state = J2K_STATE_MHSOC;
|
||||
cio_init(src, len);
|
||||
|
||||
|
|
|
@ -58,11 +58,20 @@
|
|||
#define J2K_CCP_QNTSTY_SIQNT 1
|
||||
#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 {
|
||||
int dx, dy; /* XRsiz, YRsiz */
|
||||
int w, h; /* width and height of data */
|
||||
int x0, y0; /* offset of the component compare to the whole image */
|
||||
int prec; /* precision */
|
||||
int bpp; /* deapth of image in bits */
|
||||
int sgnd; /* signed */
|
||||
int resno_decoded; /* number of decoded resolution */
|
||||
int factor; /* number of division by 2 of the out image compare to the original size of image */
|
||||
int *data; /* image-component data */
|
||||
} j2k_comp_t;
|
||||
|
||||
|
@ -122,10 +131,14 @@ typedef struct {
|
|||
int image_type; /* 0: PNM, PGM, PPM 1: PGX */
|
||||
int disto_alloc; /* Allocation by rate/distortion */
|
||||
int fixed_alloc; /* Allocation by fixed layer */
|
||||
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 tx0, ty0; /* XTOsiz, YTOsiz */
|
||||
int tdx, tdy; /* XTsiz, YTsiz */
|
||||
char *comment; /* comment for coding */
|
||||
int tw, th;
|
||||
int tw, th; /* number of tiles in width and heigth */
|
||||
int *tileno; /* ID number of the tiles present in the codestream */
|
||||
int tileno_size; /* size of the vector tileno */
|
||||
unsigned char *ppm_data; /* packet header store there for futur use in t2_decode_packet */
|
||||
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) */
|
||||
|
@ -186,7 +199,7 @@ LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *outfile, int len
|
|||
* i: decode 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);
|
||||
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp, j2k_option_t option);
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -241,7 +241,7 @@ int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno,
|
|||
if (info_IM->index_write && info_IM->index_on) {
|
||||
info_tile *info_TL = &info_IM->tile[tileno];
|
||||
info_packet *info_PK = &info_TL->packet[info_IM->num];
|
||||
info_PK->disto = layer->disto;
|
||||
info_PK->disto += layer->disto;
|
||||
if (info_IM->D_max < info_PK->disto)
|
||||
info_IM->D_max = info_PK->disto;
|
||||
} /* </ADD> */
|
||||
|
@ -258,7 +258,7 @@ int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno,
|
|||
if (info_IM->index_write && info_IM->index_on) {
|
||||
info_tile *info_TL = &info_IM->tile[tileno];
|
||||
info_packet *info_PK = &info_TL->packet[info_IM->num];
|
||||
info_PK->disto = layer->disto;
|
||||
info_PK->disto += layer->disto;
|
||||
if (info_IM->D_max < info_PK->disto)
|
||||
info_IM->D_max = info_PK->disto;
|
||||
} /* </ADD> */
|
||||
|
@ -303,13 +303,16 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
|
|||
unsigned char *c = src;
|
||||
int present;
|
||||
|
||||
if (layno == 0) {
|
||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||
if (layno == 0)
|
||||
{
|
||||
for (bandno = 0; bandno < res->numbands; bandno++)
|
||||
{
|
||||
tcd_band_t *band = &res->bands[bandno];
|
||||
tcd_precinct_t *prc = &band->precincts[precno];
|
||||
tgt_reset(prc->incltree);
|
||||
tgt_reset(prc->imsbtree);
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++)
|
||||
{
|
||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
||||
cblk->numsegs = 0;
|
||||
}
|
||||
|
@ -335,7 +338,6 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
|
|||
if (tcp->csty & J2K_CP_CSTY_SOP)
|
||||
{
|
||||
if ((*c)!=255 || (*(c+1)!=145)) {printf("Error : expected SOP marker [1]!!!\n");}
|
||||
/*printf(" %d %d %d %d %d %d %d\n",*c,*(c+1),*(c+6),*(c+7),*(c+8),*(c+9),*(c+10));*/
|
||||
c += 6;
|
||||
}
|
||||
bio_init_dec(c, src + len - c);
|
||||
|
@ -368,27 +370,32 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
|
|||
}
|
||||
return c - src;
|
||||
}
|
||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||
for (bandno = 0; bandno < res->numbands; bandno++)
|
||||
{
|
||||
tcd_band_t *band = &res->bands[bandno];
|
||||
tcd_precinct_t *prc = &band->precincts[precno];
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++)
|
||||
{
|
||||
int included, increment, n;
|
||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
||||
tcd_seg_t *seg;
|
||||
/* if cblk not yet included before --> inclusion tagtree */
|
||||
if (!cblk->numsegs) {
|
||||
if (!cblk->numsegs)
|
||||
{
|
||||
included = tgt_decode(prc->incltree, cblkno, layno + 1);
|
||||
/* else one bit */
|
||||
} else {
|
||||
included = bio_read(1);
|
||||
}
|
||||
/* if cblk not included */
|
||||
if (!included) {
|
||||
if (!included)
|
||||
{
|
||||
cblk->numnewpasses = 0;
|
||||
continue;
|
||||
}
|
||||
/* if cblk not yet included --> zero-bitplane tagtree */
|
||||
if (!cblk->numsegs) {
|
||||
if (!cblk->numsegs)
|
||||
{
|
||||
int i, numimsbs;
|
||||
for (i = 0; !tgt_decode(prc->imsbtree, cblkno, i); i++) {
|
||||
}
|
||||
|
@ -428,8 +435,8 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
|
|||
c += bio_numbytes();
|
||||
|
||||
if (tcp->csty & J2K_CP_CSTY_EPH) { /* EPH marker */
|
||||
if ((*c)!=255 || (*(c+1)!=146)) { printf("Error : expected EPH marker [2]!!!\n");
|
||||
printf(" %d %d %d %d %d %d %d\n",*c,*(c+1),*(c+2),*(c+3),*(c+4),*(c+5),*(c+6));}
|
||||
if ((*c)!=255 || (*(c+1)!=146)) {
|
||||
printf("Error : expected EPH marker [2]!!!\n"); }
|
||||
c += 2;
|
||||
}
|
||||
|
||||
|
@ -597,16 +604,17 @@ int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t *
|
|||
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
|
||||
while (pi_next(&pi[pino]))
|
||||
{
|
||||
// fprintf(stderr,"codeblock %d [%d %d %d %d] pino %d/%d\n",n,pi[pino].layno,pi[pino].resno,pi[pino].compno,pi[pino].precno,pino,cp->tcps[tileno].numpocs);
|
||||
e = t2_decode_packet(c, src + len - c, tile, cp, &cp->tcps[tileno], pi[pino].compno,
|
||||
pi[pino].resno, pi[pino].precno, pi[pino].layno);
|
||||
|
||||
/* progression in resolution */
|
||||
img->comps[pi[pino].compno].resno_decoded = e > 0 ? int_max(pi[pino].resno, img->comps[pi[pino].compno].resno_decoded) : img->comps[pi[pino].compno].resno_decoded;
|
||||
n++;
|
||||
|
||||
if (e == -999) { /* ADD */
|
||||
break;
|
||||
} else
|
||||
c += e;
|
||||
/* printf("next\n"); */
|
||||
}
|
||||
|
||||
/* FREE space memory taken by pi */
|
||||
|
|
|
@ -151,7 +151,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||
tilec->x1 = int_ceildiv(tile->x1, img->comps[compno].dx);
|
||||
tilec->y1 = int_ceildiv(tile->y1, img->comps[compno].dy);
|
||||
|
||||
tilec->data = (int *) malloc(sizeof(int) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
|
||||
tilec->data = (int *) malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
|
||||
tilec->numresolutions = tccp->numresolutions;
|
||||
|
||||
tilec->resolutions = (tcd_resolution_t *) malloc(tilec->numresolutions * sizeof(tcd_resolution_t));
|
||||
|
@ -375,7 +375,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||
tilec->x1 = int_ceildiv(tile->x1, img->comps[compno].dx);
|
||||
tilec->y1 = int_ceildiv(tile->y1, img->comps[compno].dy);
|
||||
|
||||
tilec->data = (int *) malloc(sizeof(int) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
|
||||
tilec->data = (int *) malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
|
||||
tilec->numresolutions = tccp->numresolutions;
|
||||
/* tilec->resolutions=(tcd_resolution_t*)realloc(tilec->resolutions,tilec->numresolutions*sizeof(tcd_resolution_t)); */
|
||||
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
||||
|
@ -516,15 +516,24 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||
|
||||
void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||
{
|
||||
int tileno, compno, resno, bandno, precno, cblkno;
|
||||
int tileno, compno, resno, bandno, precno, cblkno, i;
|
||||
unsigned int x0=0 , y0=0, x1 = 0, y1 = 0, w, h, j;
|
||||
tcd_img = img;
|
||||
tcd_cp = cp;
|
||||
tcd_image.tw = cp->tw;
|
||||
tcd_image.th = cp->th;
|
||||
tcd_image.tiles = (tcd_tile_t *) malloc(cp->tw * cp->th * sizeof(tcd_tile_t));
|
||||
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||
|
||||
/*for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
|
||||
j2k_tcp_t *tcp = &cp->tcps[tileno];
|
||||
tcd_tile_t *tile = &tcd_image.tiles[tileno];
|
||||
tcd_tile_t *tile = &tcd_image.tiles[tileno];*/
|
||||
|
||||
for (i = 0 ; i < cp->tileno_size ; i++){
|
||||
j2k_tcp_t *tcp = &cp->tcps[cp->tileno[i]];
|
||||
tcd_tile_t *tile = &tcd_image.tiles[cp->tileno[i]];
|
||||
tileno = cp->tileno[i];
|
||||
|
||||
|
||||
// int previous_x0, previous_x1, previous_y0, previous_y1;
|
||||
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
||||
int p = tileno % cp->tw; /* si numerotation matricielle .. */
|
||||
|
@ -547,7 +556,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||
tilec->x1 = int_ceildiv(tile->x1, img->comps[compno].dx);
|
||||
tilec->y1 = int_ceildiv(tile->y1, img->comps[compno].dy);
|
||||
|
||||
tilec->data = (int *) malloc(sizeof(int) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
|
||||
tilec->data = (int *) malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * sizeof(int));
|
||||
tilec->numresolutions = tccp->numresolutions;
|
||||
tilec->resolutions = (tcd_resolution_t *) malloc(tilec->numresolutions * sizeof(tcd_resolution_t));
|
||||
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
||||
|
@ -675,6 +684,27 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||
}
|
||||
}
|
||||
/* tcd_dump(&tcd_image,0); */
|
||||
|
||||
|
||||
/* Allocate place to store the date decoded = fianl image */
|
||||
/* Place limited by the tile really present in the codestream */
|
||||
for (i = 0; i < img->numcomps; i++) {
|
||||
for (j = 0; j < cp->tileno_size; j++) {
|
||||
tileno = cp->tileno[j];
|
||||
x0 = j == 0 ? tcd_image.tiles[tileno].x0 : int_min(x0 , tcd_image.tiles[tileno].x0);
|
||||
y0 = j == 0 ? tcd_image.tiles[tileno].y0 : int_min(y0 , tcd_image.tiles[tileno].y0);
|
||||
x1 = j == 0 ? tcd_image.tiles[tileno].x1 : int_max(x1 , tcd_image.tiles[tileno].x1);
|
||||
y1 = j == 0 ? tcd_image.tiles[tileno].y1 : int_max(y1 , tcd_image.tiles[tileno].y1);
|
||||
}
|
||||
w = int_ceildiv(x1 - x0, img->comps[i].dx);
|
||||
h = int_ceildiv(y1 - y0, img->comps[i].dy);
|
||||
img->comps[i].data = (int *) calloc(w * h,sizeof(int));
|
||||
img->comps[i].w = w;
|
||||
img->comps[i].h = h;
|
||||
img->comps[i].x0 = x0;
|
||||
img->comps[i].y0 = y0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void tcd_makelayer_fixed(int layno, int final) {
|
||||
|
@ -1053,7 +1083,7 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len, info_image * i
|
|||
{
|
||||
int compno;
|
||||
int l;
|
||||
clock_t time7;
|
||||
clock_t time;
|
||||
tcd_tile_t *tile;
|
||||
j2k_tcp_t *tcp = &tcd_cp->tcps[0];
|
||||
j2k_tccp_t *tccp = &tcp->tccps[0];
|
||||
|
@ -1075,7 +1105,7 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len, info_image * i
|
|||
}
|
||||
/* << INDEX */
|
||||
/*---------------TILE-------------------*/
|
||||
time7 = clock();
|
||||
time = clock();
|
||||
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
FILE *src;
|
||||
|
@ -1171,8 +1201,8 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len, info_image * i
|
|||
l = t2_encode_packets(tcd_img, tcd_cp, tileno, tile, tcd_tcp->numlayers, dest, len, info_IM);
|
||||
|
||||
/*---------------CLEAN-------------------*/
|
||||
time7 = clock() - time7;
|
||||
printf("total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC, (time7 % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
time = clock() - time;
|
||||
printf("total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC, (time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
tilec = &tile->comps[compno];
|
||||
|
@ -1188,7 +1218,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||
int l;
|
||||
int compno;
|
||||
int eof = 0;
|
||||
clock_t time1, time2, time3, time4, time5, time6;
|
||||
clock_t time;
|
||||
tcd_tile_t *tile;
|
||||
|
||||
tcd_tileno = tileno;
|
||||
|
@ -1196,10 +1226,11 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||
tcd_tcp = &tcd_cp->tcps[tileno];
|
||||
tile = tcd_tile;
|
||||
|
||||
time6 = clock();
|
||||
time = clock();
|
||||
|
||||
time1 = clock();
|
||||
printf("tile decoding time %d/%d:\n", tileno + 1, tcd_cp->tw * tcd_cp->th);
|
||||
fprintf(stderr,"tile decoding time %d/%d: ", tileno + 1, tcd_cp->tw * tcd_cp->th);
|
||||
|
||||
/*--------------TIER2------------------*/
|
||||
|
||||
l = t2_decode_packets(src, len, tcd_img, tcd_cp, tileno, tile);
|
||||
|
||||
|
@ -1207,77 +1238,81 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||
eof = 1;
|
||||
fprintf(stderr, "tcd_decode: incomplete bistream\n");
|
||||
}
|
||||
time1 = clock() - time1;
|
||||
|
||||
/* printf("tier 2: %ld.%.3ld s\n", time1/CLOCKS_PER_SEC, (time1%CLOCKS_PER_SEC)*1000/CLOCKS_PER_SEC); */
|
||||
|
||||
time2 = clock();
|
||||
/*------------------TIER1-----------------*/
|
||||
t1_init_luts();
|
||||
t1_decode_cblks(tile, tcd_tcp);
|
||||
time2 = clock() - time2;
|
||||
/* printf("tier 1: %ld.%.3ld s\n", time2/CLOCKS_PER_SEC, (time2%CLOCKS_PER_SEC)*1000/CLOCKS_PER_SEC); */
|
||||
|
||||
time3 = clock();
|
||||
/*----------------DWT---------------------*/
|
||||
|
||||
for (compno = 0; compno < tile->numcomps; compno++)
|
||||
{
|
||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||
if (tcd_cp->reduce_on == 1)
|
||||
{
|
||||
tcd_img->comps[compno].resno_decoded = tile->comps[compno].numresolutions - tcd_cp->reduce_value - 1;
|
||||
}
|
||||
|
||||
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1)
|
||||
{
|
||||
dwt_decode(tilec->data, tilec->x1 - tilec->x0,tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1);
|
||||
} else
|
||||
{ /*if (tcd_tcp->tccps[compno].qmfbid == 0) {*/
|
||||
dwt_decode_real(tilec->data, tilec->x1 - tilec->x0, tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1);
|
||||
}
|
||||
}
|
||||
|
||||
time3 = clock() - time3;
|
||||
/* printf("dwt: %ld.%.3ld s\n", time3/CLOCKS_PER_SEC, (time3%CLOCKS_PER_SEC)*1000/CLOCKS_PER_SEC); */
|
||||
|
||||
time4 = clock();
|
||||
if (tcd_tcp->mct) {
|
||||
if (tcd_tcp->tccps[0].qmfbid == 0) {
|
||||
mct_decode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data,
|
||||
(tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
|
||||
dwt_decode(tilec->data, tilec->x1 - tilec->x0, tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1,
|
||||
tilec->numresolutions - 1 - tcd_img->comps[compno].resno_decoded);
|
||||
} else {
|
||||
dwt_decode_real(tilec->data, tilec->x1 - tilec->x0, tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1,
|
||||
tilec->numresolutions - 1 - tcd_img->comps[compno].resno_decoded);
|
||||
}
|
||||
|
||||
if (tile->comps[compno].numresolutions > 0)
|
||||
tcd_img->comps[compno].factor = tile->comps[compno].numresolutions - (tcd_img->comps[compno].resno_decoded + 1);
|
||||
}
|
||||
|
||||
/*----------------MCT-------------------*/
|
||||
|
||||
if (tcd_tcp->mct) {
|
||||
if (tcd_tcp->tccps[0].qmfbid == 1) {
|
||||
mct_decode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data,
|
||||
(tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
|
||||
} else {
|
||||
mct_decode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data,
|
||||
(tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0));
|
||||
}
|
||||
}
|
||||
time4 = clock() - time4;
|
||||
/* printf("mct: %ld.%.3ld s\n", time4/CLOCKS_PER_SEC, (time4%CLOCKS_PER_SEC)*1000/CLOCKS_PER_SEC); */
|
||||
|
||||
time5 = clock();
|
||||
/*---------------TILE-------------------*/
|
||||
|
||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||
tcd_resolution_t *res = &tilec->resolutions[tcd_img->comps[compno].resno_decoded];
|
||||
int adjust = tcd_img->comps[compno].sgnd ? 0 : 1 << (tcd_img->comps[compno].prec - 1);
|
||||
int min = tcd_img->comps[compno].sgnd ? - (1 << (tcd_img->comps[compno].prec - 1)) : 0;
|
||||
int max = tcd_img->comps[compno].sgnd ? (1 << (tcd_img->comps[compno].prec - 1)) - 1 : (1 << tcd_img->comps[compno].prec) - 1;
|
||||
int tw = tilec->x1 - tilec->x0;
|
||||
int w = int_ceildiv(tcd_img->x1 - tcd_img->x0, tcd_img->comps[compno].dx);
|
||||
int i, j;
|
||||
int offset_x = int_ceildiv(tcd_img->x0, tcd_img->comps[compno].dx);
|
||||
int offset_y = int_ceildiv(tcd_img->y0, tcd_img->comps[compno].dy);
|
||||
|
||||
for (j = tilec->y0; j < tilec->y1; j++) {
|
||||
for (i = tilec->x0; i < tilec->x1; i++) {
|
||||
int tw = tilec->x1 - tilec->x0;
|
||||
int w = tcd_img->comps[compno].w;
|
||||
|
||||
int i, j;
|
||||
int offset_x = int_ceildivpow2(tcd_img->comps[compno].x0, tcd_img->comps[compno].factor);
|
||||
int offset_y = int_ceildivpow2(tcd_img->comps[compno].y0, tcd_img->comps[compno].factor);
|
||||
|
||||
for (j = res->y0; j < res->y1; j++) {
|
||||
for (i = res->x0; i < res->x1; i++) {
|
||||
|
||||
int v;
|
||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||
v = tilec->data[i - tilec->x0 + (j - tilec->y0) * tw];
|
||||
} else { /* if (tcd_tcp->tccps[compno].qmfbid == 0) */
|
||||
v = tilec->data[i - tilec->x0 + (j - tilec->y0) * tw] >> 13;
|
||||
v = tilec->data[i - res->x0 + (j - res->y0) * tw];
|
||||
} else {
|
||||
v = tilec->data[i - res->x0 + (j - res->y0) * tw] >> 13;
|
||||
}
|
||||
v += adjust;
|
||||
|
||||
/* tcd_img->comps[compno].data[i+j*w]=int_clamp(v, min, max); */
|
||||
tcd_img->comps[compno].data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max); /* change ! */
|
||||
tcd_img->comps[compno].data[(i - offset_x) + (j - offset_y) * w] = int_clamp(v, min, max);
|
||||
}
|
||||
}
|
||||
}
|
||||
time5 = clock() - time5;
|
||||
/* printf("tile->img: %ld.%.3ld s\n", time5/CLOCKS_PER_SEC, (time5%CLOCKS_PER_SEC)*1000/CLOCKS_PER_SEC); */
|
||||
|
||||
time6 = clock() - time6;
|
||||
printf("total: %ld.%.3ld s\n\n", time6 / CLOCKS_PER_SEC, (time6 % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
time = clock() - time;
|
||||
fprintf(stderr,"total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC, (time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||
|
||||
if (eof) {
|
||||
longjmp(j2k_error, 1);
|
||||
|
|
Loading…
Reference in New Issue