Reformatage : indent -kr -i2 -ci2 $(find . -name '*.c') $(find . -name '*.h')
This commit is contained in:
parent
ec9bd9f6a4
commit
64c34e0d52
|
@ -61,57 +61,56 @@ char *const *nargv;
|
|||
const char *ostr;
|
||||
{
|
||||
# define __progname nargv[0]
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int) *place++) == (int) ':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (optopt == (int) '-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':')
|
||||
(void) fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __progname,
|
||||
optopt);
|
||||
return (BADCH);
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
} else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (opterr)
|
||||
(void) fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__progname, optopt);
|
||||
return (BADCH);
|
||||
} else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
return (optopt); /* dump back option letter */
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int) *place++) == (int) ':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (optopt == (int) '-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':')
|
||||
(void) fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __progname, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
} else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (opterr)
|
||||
(void) fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__progname, optopt);
|
||||
return (BADCH);
|
||||
} else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return (optopt); /* dump back option letter */
|
||||
}
|
||||
|
|
1583
codec/convert.c
1583
codec/convert.c
File diff suppressed because it is too large
Load Diff
1330
codec/image_to_j2k.c
1330
codec/image_to_j2k.c
File diff suppressed because it is too large
Load Diff
|
@ -35,488 +35,476 @@
|
|||
|
||||
int ceildiv(int a, int b)
|
||||
{
|
||||
return (a + b - 1) / b;
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
char *src, *src_name;
|
||||
char *dest, S1, S2, S3;
|
||||
int len;
|
||||
j2k_image_t *img;
|
||||
j2k_cp_t *cp;
|
||||
j2k_option_t option;
|
||||
int w, wr, wrr, h, hr, hrr, max;
|
||||
int i, image_type = -1, compno, pad;
|
||||
int adjust;
|
||||
FILE *f;
|
||||
char *src, *src_name;
|
||||
char *dest, S1, S2, S3;
|
||||
int len;
|
||||
j2k_image_t *img;
|
||||
j2k_cp_t *cp;
|
||||
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 image-file -reduce n (<- optional)\n",
|
||||
argv[0]);
|
||||
if (argc < 3) {
|
||||
fprintf(stderr,
|
||||
"usage: %s j2k-file image-file -reduce n (<- optional)\n",
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
f = fopen(argv[1], "rb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
dest--;
|
||||
S3 = *dest;
|
||||
dest--;
|
||||
S2 = *dest;
|
||||
dest--;
|
||||
S1 = *dest;
|
||||
|
||||
if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
|
||||
|| (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
|
||||
image_type = 0;
|
||||
}
|
||||
|
||||
if ((S1 == 'p' && S2 == 'n' && S3 == 'm')
|
||||
|| (S1 == 'P' && S2 == 'N' && S3 == 'M') || (S1 == 'p' && S2 == 'g'
|
||||
&& S3 == 'm')
|
||||
|| (S1 == 'P' && S2 == 'G' && S3 == 'M') || (S1 == 'P' && S2 == 'P'
|
||||
&& S3 == 'M')
|
||||
|| (S1 == 'p' && S2 == 'p' && S3 == 'm')) {
|
||||
image_type = 1;
|
||||
}
|
||||
|
||||
if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
|
||||
|| (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
|
||||
image_type = 2;
|
||||
}
|
||||
|
||||
if (image_type == -1) {
|
||||
fprintf(stderr,
|
||||
"!! Unrecognized format for infile : %c%c%c [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
|
||||
S1, S2, S3);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
src = (char *) malloc(len);
|
||||
fread(src, 1, len, f);
|
||||
fclose(f);
|
||||
|
||||
src_name = argv[1];
|
||||
while (*src_name) {
|
||||
src_name++;
|
||||
}
|
||||
src_name--;
|
||||
S3 = *src_name;
|
||||
src_name--;
|
||||
S2 = *src_name;
|
||||
src_name--;
|
||||
S1 = *src_name;
|
||||
|
||||
if (S1 == 'j' && S2 == '2' && S3 == 'k') {
|
||||
if (!j2k_decode(src, len, &img, &cp, option)) {
|
||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (S1 == 'j' && S2 == 'p' && S3 == 't') {
|
||||
if (!j2k_decode_jpt_stream(src, len, &img, &cp)) {
|
||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
f = fopen(argv[1], "rb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
dest--;
|
||||
S3 = *dest;
|
||||
dest--;
|
||||
S2 = *dest;
|
||||
dest--;
|
||||
S1 = *dest;
|
||||
|
||||
if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
|
||||
|| (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
|
||||
image_type = 0;
|
||||
}
|
||||
|
||||
if ((S1 == 'p' && S2 == 'n' && S3 == 'm')
|
||||
|| (S1 == 'P' && S2 == 'N' && S3 == 'M') || (S1 == 'p' && S2 == 'g'
|
||||
&& S3 == 'm')
|
||||
|| (S1 == 'P' && S2 == 'G' && S3 == 'M') || (S1 == 'P' && S2 == 'P'
|
||||
&& S3 == 'M')
|
||||
|| (S1 == 'p' && S2 == 'p' && S3 == 'm')) {
|
||||
image_type = 1;
|
||||
}
|
||||
|
||||
if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
|
||||
|| (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
|
||||
image_type = 2;
|
||||
}
|
||||
|
||||
if (image_type == -1) {
|
||||
fprintf(stderr,
|
||||
"!! Unrecognized format for infile : %c%c%c [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
|
||||
S1, S2, S3);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
src = (char *) malloc(len);
|
||||
fread(src, 1, len, f);
|
||||
fclose(f);
|
||||
|
||||
src_name = argv[1];
|
||||
while (*src_name) {
|
||||
src_name++;
|
||||
}
|
||||
src_name--;
|
||||
S3 = *src_name;
|
||||
src_name--;
|
||||
S2 = *src_name;
|
||||
src_name--;
|
||||
S1 = *src_name;
|
||||
|
||||
if (S1 == 'j' && S2 == '2' && S3 == 'k') {
|
||||
if (!j2k_decode(src, len, &img, &cp, option)) {
|
||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (S1 == 'j' && S2 == 'p' && S3 == 't') {
|
||||
if (!j2k_decode_jpt_stream(src, len, &img, &cp)) {
|
||||
fprintf(stderr, "j2k_to_image: failed to decode image!\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr,
|
||||
"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k or *.jpt]!! \n",
|
||||
S1, S2, S3);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
free(src);
|
||||
/* ------------------ CREATE OUT IMAGE WITH THE RIGHT FORMAT ----------------------- */
|
||||
|
||||
/* ---------------------------- / */
|
||||
/* / / */
|
||||
/* / FORMAT : PNM, PGM or PPM / */
|
||||
/* / / */
|
||||
/* ---------------------------- / */
|
||||
|
||||
switch (image_type) {
|
||||
case 1: /* PNM PGM PPM */
|
||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
||||
&& img->comps[1].dx == img->comps[2].dx
|
||||
&& img->comps[0].dy == img->comps[1].dy
|
||||
&& img->comps[1].dy == img->comps[2].dy
|
||||
&& img->comps[0].prec == img->comps[1].prec
|
||||
&& img->comps[1].prec == img->comps[2].prec) {
|
||||
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);
|
||||
// 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;
|
||||
|
||||
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 < wrr * hrr; i++) {
|
||||
char r, g, b;
|
||||
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 / 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 / wrr * wr + i % wrr];
|
||||
b += (img->comps[2].sgnd ? 1 << (img->comps[2].prec - 1) : 0);
|
||||
b = b >> adjust;
|
||||
|
||||
fprintf(f, "%c%c%c", r, g, b);
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
for (compno = 0; compno < img->numcomps; compno++) {
|
||||
char name[256];
|
||||
if (img->numcomps > 1) {
|
||||
sprintf(name, "%d.%s", compno, argv[2]);
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k or *.jpt]!! \n",
|
||||
S1, S2, S3);
|
||||
return 1;
|
||||
sprintf(name, "%s", argv[2]);
|
||||
}
|
||||
f = fopen(name, "wb");
|
||||
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 = 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);
|
||||
// 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;
|
||||
|
||||
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 < wrr * hrr; i++) {
|
||||
char l;
|
||||
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);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------ / */
|
||||
/* / / */
|
||||
/* / FORMAT : PGX / */
|
||||
/* / / */
|
||||
/* /----------------------- / */
|
||||
case 0: /* PGX */
|
||||
for (compno = 0; compno < img->numcomps; compno++) {
|
||||
j2k_comp_t *comp = &img->comps[compno];
|
||||
char name[256];
|
||||
if (img->numcomps > 1)
|
||||
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);
|
||||
// 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 / wr * w + i % wr];
|
||||
if (comp->prec <= 8) {
|
||||
char c = (char) v;
|
||||
fwrite(&c, 1, 1, f);
|
||||
} else if (comp->prec <= 16) {
|
||||
short s = (short) v;
|
||||
fwrite(&s, 2, 1, f);
|
||||
} else {
|
||||
fwrite(&v, 4, 1, f);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------ / */
|
||||
/* / / */
|
||||
/* / FORMAT : BMP / */
|
||||
/* / / */
|
||||
/* /----------------------- / */
|
||||
|
||||
case 2: /* BMP */
|
||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
||||
&& img->comps[1].dx == img->comps[2].dx
|
||||
&& img->comps[0].dy == img->comps[1].dy
|
||||
&& img->comps[1].dy == img->comps[2].dy
|
||||
&& img->comps[0].prec == img->comps[1].prec
|
||||
&& img->comps[1].prec == img->comps[2].prec) {
|
||||
/* -->> -->> -->> -->>
|
||||
|
||||
24 bits color
|
||||
|
||||
<<-- <<-- <<-- <<-- */
|
||||
|
||||
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);
|
||||
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) (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) ((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 * 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 < wr * hr; i++) {
|
||||
unsigned char R, G, B;
|
||||
/* 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) % wr == 0) {
|
||||
for (pad = (3 * wr) % 4 ? 4 - (3 * wr) % 4 : 0; pad > 0; pad--) /* ADD */
|
||||
fprintf(f, "%c", 0);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
} else { /* Gray-scale */
|
||||
|
||||
/* -->> -->> -->> -->>
|
||||
|
||||
8 bits non code (Gray scale)
|
||||
|
||||
<<-- <<-- <<-- <<-- */
|
||||
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);
|
||||
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) (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);
|
||||
|
||||
/* 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) ((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) (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);
|
||||
fprintf(f, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff,
|
||||
((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
|
||||
}
|
||||
|
||||
free(src);
|
||||
/* ------------------ CREATE OUT IMAGE WITH THE RIGHT FORMAT ----------------------- */
|
||||
|
||||
/* ---------------------------- / */
|
||||
/* / / */
|
||||
/* / FORMAT : PNM, PGM or PPM / */
|
||||
/* / / */
|
||||
/* ---------------------------- / */
|
||||
|
||||
switch (image_type) {
|
||||
case 1: /* PNM PGM PPM */
|
||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
||||
&& img->comps[1].dx == img->comps[2].dx
|
||||
&& img->comps[0].dy == img->comps[1].dy
|
||||
&& img->comps[1].dy == img->comps[2].dy
|
||||
&& img->comps[0].prec == img->comps[1].prec
|
||||
&& img->comps[1].prec == img->comps[2].prec) {
|
||||
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);
|
||||
// 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;
|
||||
|
||||
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 < wrr * hrr; i++) {
|
||||
char r, g, b;
|
||||
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 / 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 / wrr * wr + i % wrr];
|
||||
b += (img->comps[2].
|
||||
sgnd ? 1 << (img->comps[2].prec - 1) : 0);
|
||||
b = b >> adjust;
|
||||
|
||||
fprintf(f, "%c%c%c", r, g, b);
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
for (compno = 0; compno < img->numcomps; compno++) {
|
||||
char name[256];
|
||||
if (img->numcomps > 1) {
|
||||
sprintf(name, "%d.%s", compno, argv[2]);
|
||||
} else {
|
||||
sprintf(name, "%s", argv[2]);
|
||||
}
|
||||
f = fopen(name, "wb");
|
||||
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 = 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);
|
||||
// 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;
|
||||
|
||||
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 < wrr * hrr; i++) {
|
||||
char l;
|
||||
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);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------ / */
|
||||
/* / / */
|
||||
/* / FORMAT : PGX / */
|
||||
/* / / */
|
||||
/* /----------------------- / */
|
||||
case 0: /* PGX */
|
||||
for (compno = 0; compno < img->numcomps; compno++) {
|
||||
j2k_comp_t *comp = &img->comps[compno];
|
||||
char name[256];
|
||||
if (img->numcomps > 1)
|
||||
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);
|
||||
// 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 / wr * w + i % wr];
|
||||
if (comp->prec <= 8) {
|
||||
char c = (char) v;
|
||||
fwrite(&c, 1, 1, f);
|
||||
} else if (comp->prec <= 16) {
|
||||
short s = (short) v;
|
||||
fwrite(&s, 2, 1, f);
|
||||
} else {
|
||||
fwrite(&v, 4, 1, f);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
break;
|
||||
|
||||
/* ------------------------ / */
|
||||
/* / / */
|
||||
/* / FORMAT : BMP / */
|
||||
/* / / */
|
||||
/* /----------------------- / */
|
||||
|
||||
case 2: /* BMP */
|
||||
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
||||
&& img->comps[1].dx == img->comps[2].dx
|
||||
&& img->comps[0].dy == img->comps[1].dy
|
||||
&& img->comps[1].dy == img->comps[2].dy
|
||||
&& img->comps[0].prec == img->comps[1].prec
|
||||
&& img->comps[1].prec == img->comps[2].prec) {
|
||||
/* -->> -->> -->> -->>
|
||||
|
||||
24 bits color
|
||||
|
||||
<<-- <<-- <<-- <<-- */
|
||||
|
||||
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);
|
||||
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) (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) ((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 * 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 < wr * hr; i++) {
|
||||
unsigned char R, G, B;
|
||||
/* 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) % wr == 0) {
|
||||
for (pad = (3 * wr) % 4 ? 4 - (3 * wr) % 4 : 0; pad > 0; pad--) /* ADD */
|
||||
fprintf(f, "%c", 0);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
} else { /* Gray-scale */
|
||||
|
||||
/* -->> -->> -->> -->>
|
||||
|
||||
8 bits non code (Gray scale)
|
||||
|
||||
<<-- <<-- <<-- <<-- */
|
||||
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);
|
||||
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) (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);
|
||||
|
||||
/* 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) ((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) (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);
|
||||
fprintf(f, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff,
|
||||
((256) >> 16) & 0xff, ((256) >> 24) & 0xff);
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
fprintf(f, "%c%c%c%c", i, i, i, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < wr * hr; i++) {
|
||||
/* 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;
|
||||
for (i = 0; i < 256; i++) {
|
||||
fprintf(f, "%c%c%c%c", i, i, i, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
for (i = 0; i < wr * hr; i++) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ extern jmp_buf j2k_error;
|
|||
*/
|
||||
int bio_numbytes()
|
||||
{
|
||||
return bio_bp - bio_start;
|
||||
return bio_bp - bio_start;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -55,11 +55,11 @@ int bio_numbytes()
|
|||
*/
|
||||
void bio_init_enc(unsigned char *bp, int len)
|
||||
{
|
||||
bio_start = bp;
|
||||
bio_end = bp + len;
|
||||
bio_bp = bp;
|
||||
bio_buf = 0;
|
||||
bio_ct = 8;
|
||||
bio_start = bp;
|
||||
bio_end = bp + len;
|
||||
bio_bp = bp;
|
||||
bio_buf = 0;
|
||||
bio_ct = 8;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -70,11 +70,11 @@ void bio_init_enc(unsigned char *bp, int len)
|
|||
*/
|
||||
void bio_init_dec(unsigned char *bp, int len)
|
||||
{
|
||||
bio_start = bp;
|
||||
bio_end = bp + len;
|
||||
bio_bp = bp;
|
||||
bio_buf = 0;
|
||||
bio_ct = 0;
|
||||
bio_start = bp;
|
||||
bio_end = bp + len;
|
||||
bio_bp = bp;
|
||||
bio_buf = 0;
|
||||
bio_ct = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -83,12 +83,12 @@ void bio_init_dec(unsigned char *bp, int len)
|
|||
*/
|
||||
int bio_byteout()
|
||||
{
|
||||
bio_buf = (bio_buf << 8) & 0xffff;
|
||||
bio_ct = bio_buf == 0xff00 ? 7 : 8;
|
||||
if (bio_bp >= bio_end)
|
||||
return 1;
|
||||
*bio_bp++ = bio_buf >> 8;
|
||||
return 0;
|
||||
bio_buf = (bio_buf << 8) & 0xffff;
|
||||
bio_ct = bio_buf == 0xff00 ? 7 : 8;
|
||||
if (bio_bp >= bio_end)
|
||||
return 1;
|
||||
*bio_bp++ = bio_buf >> 8;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -97,12 +97,12 @@ int bio_byteout()
|
|||
*/
|
||||
int bio_bytein()
|
||||
{
|
||||
bio_buf = (bio_buf << 8) & 0xffff;
|
||||
bio_ct = bio_buf == 0xff00 ? 7 : 8;
|
||||
if (bio_bp >= bio_end)
|
||||
return 1;
|
||||
bio_buf |= *bio_bp++;
|
||||
return 0;
|
||||
bio_buf = (bio_buf << 8) & 0xffff;
|
||||
bio_ct = bio_buf == 0xff00 ? 7 : 8;
|
||||
if (bio_bp >= bio_end)
|
||||
return 1;
|
||||
bio_buf |= *bio_bp++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -112,11 +112,11 @@ int bio_bytein()
|
|||
*/
|
||||
void bio_putbit(int b)
|
||||
{
|
||||
if (bio_ct == 0) {
|
||||
bio_byteout();
|
||||
}
|
||||
bio_ct--;
|
||||
bio_buf |= b << bio_ct;
|
||||
if (bio_ct == 0) {
|
||||
bio_byteout();
|
||||
}
|
||||
bio_ct--;
|
||||
bio_buf |= b << bio_ct;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -125,11 +125,11 @@ void bio_putbit(int b)
|
|||
*/
|
||||
int bio_getbit()
|
||||
{
|
||||
if (bio_ct == 0) {
|
||||
bio_bytein();
|
||||
}
|
||||
bio_ct--;
|
||||
return (bio_buf >> bio_ct) & 1;
|
||||
if (bio_ct == 0) {
|
||||
bio_bytein();
|
||||
}
|
||||
bio_ct--;
|
||||
return (bio_buf >> bio_ct) & 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -140,10 +140,10 @@ int bio_getbit()
|
|||
*/
|
||||
void bio_write(int v, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
bio_putbit((v >> i) & 1);
|
||||
}
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
bio_putbit((v >> i) & 1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -153,12 +153,12 @@ void bio_write(int v, int n)
|
|||
*/
|
||||
int bio_read(int n)
|
||||
{
|
||||
int i, v;
|
||||
v = 0;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
v += bio_getbit() << i;
|
||||
}
|
||||
return v;
|
||||
int i, v;
|
||||
v = 0;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
v += bio_getbit() << i;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -167,16 +167,16 @@ int bio_read(int n)
|
|||
*/
|
||||
int bio_flush()
|
||||
{
|
||||
bio_ct = 0;
|
||||
if (bio_byteout())
|
||||
return 1;
|
||||
if (bio_ct == 7) {
|
||||
bio_ct = 0;
|
||||
if (bio_byteout())
|
||||
return 1;
|
||||
if (bio_ct == 7) {
|
||||
bio_ct = 0;
|
||||
|
||||
if (bio_byteout())
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
if (bio_byteout())
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -184,11 +184,11 @@ int bio_flush()
|
|||
*/
|
||||
int bio_inalign()
|
||||
{
|
||||
bio_ct = 0;
|
||||
if ((bio_buf & 0xff) == 0xff) {
|
||||
if (bio_bytein())
|
||||
return 1;
|
||||
bio_ct = 0;
|
||||
if ((bio_buf & 0xff) == 0xff) {
|
||||
if (bio_bytein())
|
||||
return 1;
|
||||
bio_ct = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ extern jmp_buf j2k_error;
|
|||
*/
|
||||
int cio_numbytes()
|
||||
{
|
||||
return cio_bp - cio_start;
|
||||
return cio_bp - cio_start;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -46,7 +46,7 @@ int cio_numbytes()
|
|||
*/
|
||||
int cio_tell()
|
||||
{
|
||||
return cio_bp - cio_start;
|
||||
return cio_bp - cio_start;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -56,7 +56,7 @@ int cio_tell()
|
|||
*/
|
||||
void cio_seek(int pos)
|
||||
{
|
||||
cio_bp = cio_start + pos;
|
||||
cio_bp = cio_start + pos;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,7 +64,7 @@ void cio_seek(int pos)
|
|||
*/
|
||||
int cio_numbytesleft()
|
||||
{
|
||||
return cio_end - cio_bp;
|
||||
return cio_end - cio_bp;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -72,7 +72,7 @@ int cio_numbytesleft()
|
|||
*/
|
||||
unsigned char *cio_getbp()
|
||||
{
|
||||
return cio_bp;
|
||||
return cio_bp;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -83,9 +83,9 @@ unsigned char *cio_getbp()
|
|||
*/
|
||||
void cio_init(unsigned char *bp, int len)
|
||||
{
|
||||
cio_start = bp;
|
||||
cio_end = bp + len;
|
||||
cio_bp = bp;
|
||||
cio_start = bp;
|
||||
cio_end = bp + len;
|
||||
cio_bp = bp;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -93,9 +93,9 @@ void cio_init(unsigned char *bp, int len)
|
|||
*/
|
||||
void cio_byteout(unsigned char v)
|
||||
{
|
||||
if (cio_bp >= cio_end)
|
||||
longjmp(j2k_error, 1);
|
||||
*cio_bp++ = v;
|
||||
if (cio_bp >= cio_end)
|
||||
longjmp(j2k_error, 1);
|
||||
*cio_bp++ = v;
|
||||
|
||||
}
|
||||
|
||||
|
@ -104,9 +104,9 @@ void cio_byteout(unsigned char v)
|
|||
*/
|
||||
unsigned char cio_bytein()
|
||||
{
|
||||
if (cio_bp >= cio_end)
|
||||
longjmp(j2k_error, 1);
|
||||
return *cio_bp++;
|
||||
if (cio_bp >= cio_end)
|
||||
longjmp(j2k_error, 1);
|
||||
return *cio_bp++;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -117,10 +117,10 @@ unsigned char cio_bytein()
|
|||
*/
|
||||
void cio_write(unsigned int v, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
cio_byteout((unsigned char) ((v >> (i << 3)) & 0xff));
|
||||
}
|
||||
int i;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
cio_byteout((unsigned char) ((v >> (i << 3)) & 0xff));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -132,13 +132,13 @@ void cio_write(unsigned int v, int n)
|
|||
*/
|
||||
unsigned int cio_read(int n)
|
||||
{
|
||||
int i;
|
||||
unsigned int v;
|
||||
v = 0;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
v += cio_bytein() << (i << 3);
|
||||
}
|
||||
return v;
|
||||
int i;
|
||||
unsigned int v;
|
||||
v = 0;
|
||||
for (i = n - 1; i >= 0; i--) {
|
||||
v += cio_bytein() << (i << 3);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -148,5 +148,5 @@ unsigned int cio_read(int n)
|
|||
*/
|
||||
void cio_skip(int n)
|
||||
{
|
||||
cio_bp += n;
|
||||
cio_bp += n;
|
||||
}
|
||||
|
|
|
@ -46,20 +46,20 @@
|
|||
/* This table contains the norms of the 5-3 wavelets for different bands. */
|
||||
/* </summary> */
|
||||
double dwt_norms[4][10] = {
|
||||
{1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
{.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}
|
||||
{1.000, 1.500, 2.750, 5.375, 10.68, 21.34, 42.67, 85.33, 170.7, 341.3},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
{1.038, 1.592, 2.919, 5.703, 11.33, 22.64, 45.25, 90.48, 180.9},
|
||||
{.7186, .9218, 1.586, 3.043, 6.019, 12.01, 24.00, 47.97, 95.93}
|
||||
};
|
||||
|
||||
/* <summary> */
|
||||
/* This table contains the norms of the 9-7 wavelets for different bands. */
|
||||
/* </summary> */
|
||||
double dwt_norms_real[4][10] = {
|
||||
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
||||
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
||||
};
|
||||
|
||||
/* Add Patrick */
|
||||
|
@ -72,11 +72,11 @@ static int lastSizeOfB = 0;
|
|||
|
||||
void dwt_clean()
|
||||
{
|
||||
if (b != NULL) {
|
||||
free(b);
|
||||
}
|
||||
b = NULL;
|
||||
lastSizeOfB = 0;
|
||||
if (b != NULL) {
|
||||
free(b);
|
||||
}
|
||||
b = NULL;
|
||||
lastSizeOfB = 0;
|
||||
}
|
||||
|
||||
/* \ Add Patrick */
|
||||
|
@ -86,29 +86,29 @@ void dwt_clean()
|
|||
/* </summary> */
|
||||
void dwt_deinterleave(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
if (lastSizeOfB != n) {
|
||||
if (b != NULL)
|
||||
free(b);
|
||||
b = (int *) malloc(n * sizeof(int));
|
||||
lastSizeOfB = n;
|
||||
}
|
||||
int dn, sn, i;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
if (lastSizeOfB != n) {
|
||||
if (b != NULL)
|
||||
free(b);
|
||||
b = (int *) malloc(n * sizeof(int));
|
||||
lastSizeOfB = n;
|
||||
}
|
||||
|
||||
if (cas) {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[i] = a[(2 * i + 1) * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[sn + i] = a[2 * i * x];
|
||||
} else {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[i] = a[2 * i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[sn + i] = a[(2 * i + 1) * x];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
a[i * x] = b[i];
|
||||
if (cas) {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[i] = a[(2 * i + 1) * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[sn + i] = a[2 * i * x];
|
||||
} else {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[i] = a[2 * i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[sn + i] = a[(2 * i + 1) * x];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
a[i * x] = b[i];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -116,30 +116,30 @@ void dwt_deinterleave(int *a, int n, int x, int res, int cas)
|
|||
/* </summary> */
|
||||
void dwt_interleave(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
int dn, sn, i;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
|
||||
if (lastSizeOfB != n) {
|
||||
if (b != NULL)
|
||||
free(b);
|
||||
b = (int *) malloc(n * sizeof(int));
|
||||
lastSizeOfB = n;
|
||||
}
|
||||
if (lastSizeOfB != n) {
|
||||
if (b != NULL)
|
||||
free(b);
|
||||
b = (int *) malloc(n * sizeof(int));
|
||||
lastSizeOfB = n;
|
||||
}
|
||||
|
||||
if (cas) {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[2 * i + 1] = a[i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[2 * i] = a[(sn + i) * x];
|
||||
} else {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[2 * i] = a[i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[2 * i + 1] = a[(sn + i) * x];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
a[i * x] = b[i];
|
||||
if (cas) {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[2 * i + 1] = a[i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[2 * i] = a[(sn + i) * x];
|
||||
} else {
|
||||
for (i = 0; i < sn; i++)
|
||||
b[2 * i] = a[i * x];
|
||||
for (i = 0; i < dn; i++)
|
||||
b[2 * i + 1] = a[(sn + i) * x];
|
||||
}
|
||||
for (i = 0; i < n; i++)
|
||||
a[i * x] = b[i];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -147,28 +147,28 @@ void dwt_interleave(int *a, int n, int x, int res, int cas)
|
|||
/* </summary> */
|
||||
void dwt_encode_1(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i = 0;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
int dn, sn, i = 0;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
|
||||
if (cas) {
|
||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||
S(i) *= 2;
|
||||
else {
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= (S_(i) + S_(i + 1)) >> 1;
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
|
||||
}
|
||||
if (cas) {
|
||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||
S(i) *= 2;
|
||||
else {
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||
}
|
||||
dwt_deinterleave(a, n, x, res, cas);
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= (S_(i) + S_(i + 1)) >> 1;
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
|
||||
}
|
||||
}
|
||||
dwt_deinterleave(a, n, x, res, cas);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -176,28 +176,28 @@ void dwt_encode_1(int *a, int n, int x, int res, int cas)
|
|||
/* </summary> */
|
||||
void dwt_decode_1(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i = 0;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
int dn, sn, i = 0;
|
||||
sn = res;
|
||||
dn = n - res;
|
||||
|
||||
dwt_interleave(a, n, x, res, cas);
|
||||
if (cas) {
|
||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||
S(i) /= 2;
|
||||
else {
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += (DD_(i) + DD_(i - 1)) >> 1;
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += (S_(i) + S_(i + 1)) >> 1;
|
||||
}
|
||||
dwt_interleave(a, n, x, res, cas);
|
||||
if (cas) {
|
||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||
S(i) /= 2;
|
||||
else {
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += (DD_(i) + DD_(i - 1)) >> 1;
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += (S_(i) + S_(i + 1)) >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -205,34 +205,32 @@ void dwt_decode_1(int *a, int n, int x, int res, int cas)
|
|||
/* </summary> */
|
||||
void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
||||
{
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
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 = 0; i < l; 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 */
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i -
|
||||
1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i -
|
||||
1].y0;
|
||||
for (i = 0; i < l; 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 */
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_encode_1(a + j, rh, w, rh1, cas_col);
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_encode_1(a + j * w, rw, 1, rw1, cas_row);
|
||||
}
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_encode_1(a + j, rh, w, rh1, cas_col);
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_encode_1(a + j * w, rw, 1, rw1, cas_row);
|
||||
}
|
||||
|
||||
dwt_clean();
|
||||
dwt_clean();
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -241,34 +239,32 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
|||
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 */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
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 >= 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 */
|
||||
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 */
|
||||
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i -
|
||||
1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i -
|
||||
1].y0;
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_decode_1(a + j * w, rw, 1, rw1, cas_row);
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_decode_1(a + j, rh, w, rh1, cas_col);
|
||||
}
|
||||
dwt_clean();
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_decode_1(a + j * w, rw, 1, rw1, cas_row);
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_decode_1(a + j, rh, w, rh1, cas_col);
|
||||
}
|
||||
dwt_clean();
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -276,11 +272,11 @@ void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
|||
/* </summary> */
|
||||
int dwt_getgain(int orient)
|
||||
{
|
||||
if (orient == 0)
|
||||
return 0;
|
||||
if (orient == 1 || orient == 2)
|
||||
return 1;
|
||||
return 2;
|
||||
if (orient == 0)
|
||||
return 0;
|
||||
if (orient == 1 || orient == 2)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -288,7 +284,7 @@ int dwt_getgain(int orient)
|
|||
/* </summary> */
|
||||
double dwt_getnorm(int level, int orient)
|
||||
{
|
||||
return dwt_norms[orient][level];
|
||||
return dwt_norms[orient][level];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -296,42 +292,42 @@ double dwt_getnorm(int level, int orient)
|
|||
/* </summary> */
|
||||
void dwt_encode_1_real(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i = 0;
|
||||
dn = n - res;
|
||||
sn = res;
|
||||
int dn, sn, i = 0;
|
||||
dn = n - res;
|
||||
sn = res;
|
||||
|
||||
if (cas) {
|
||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) = fix_mul(S(i), 5038); /*5038 */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) = fix_mul(D(i), 6659); /*6660 */
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) = fix_mul(D(i), 5038); /*5038 */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) = fix_mul(S(i), 6659); /*6660 */
|
||||
}
|
||||
if (cas) {
|
||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) = fix_mul(S(i), 5038); /*5038 */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) = fix_mul(D(i), 6659); /*6660 */
|
||||
}
|
||||
dwt_deinterleave(a, n, x, res, cas);
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) = fix_mul(D(i), 5038); /*5038 */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) = fix_mul(S(i), 6659); /*6660 */
|
||||
}
|
||||
}
|
||||
dwt_deinterleave(a, n, x, res, cas);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -339,41 +335,41 @@ void dwt_encode_1_real(int *a, int n, int x, int res, int cas)
|
|||
/* </summary> */
|
||||
void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
|
||||
{
|
||||
int dn, sn, i = 0;
|
||||
dn = n - res;
|
||||
sn = res;
|
||||
dwt_interleave(a, n, x, res, cas);
|
||||
if (cas) {
|
||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) = fix_mul(D(i), 10078); /* 10076 */
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) = fix_mul(S(i), 13318); /* 13320 */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12993);
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) = fix_mul(S(i), 10078); /* 10076 */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) = fix_mul(D(i), 13318); /* 13320 */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += fix_mul(S_(i) + S_(i + 1), 12993);
|
||||
}
|
||||
int dn, sn, i = 0;
|
||||
dn = n - res;
|
||||
sn = res;
|
||||
dwt_interleave(a, n, x, res, cas);
|
||||
if (cas) {
|
||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) = fix_mul(D(i), 10078); /* 10076 */
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) = fix_mul(S(i), 13318); /* 13320 */
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12993);
|
||||
}
|
||||
} else {
|
||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) = fix_mul(S(i), 10078); /* 10076 */
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) = fix_mul(D(i), 13318); /* 13320 */
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
|
||||
for (i = 0; i < sn; i++)
|
||||
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
|
||||
for (i = 0; i < dn; i++)
|
||||
D(i) += fix_mul(S_(i) + S_(i + 1), 12993);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -382,32 +378,30 @@ void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
|
|||
|
||||
void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
||||
{
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
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 = 0; i < l; 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 */
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i -
|
||||
1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i -
|
||||
1].y0;
|
||||
for (i = 0; i < l; 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 */
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_encode_1_real(a + j, rh, w, rh1, cas_col);
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_encode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
||||
}
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_encode_1_real(a + j, rh, w, rh1, cas_col);
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_encode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -416,33 +410,31 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
|||
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 */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
int rw1; /* width of the resolution level once lower than computed one */
|
||||
int rh1; /* height of the resolution level once lower than computed one */
|
||||
int i, j;
|
||||
int rw; /* width of the resolution level computed */
|
||||
int rh; /* heigth of the resolution level computed */
|
||||
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 >= 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 */
|
||||
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 */
|
||||
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i -
|
||||
1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i -
|
||||
1].y0;
|
||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||
rw1 =
|
||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||
rh1 =
|
||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_decode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_decode_1_real(a + j, rh, w, rh1, cas_col);
|
||||
}
|
||||
for (j = 0; j < rh; j++)
|
||||
dwt_decode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
||||
for (j = 0; j < rw; j++)
|
||||
dwt_decode_1_real(a + j, rh, w, rh1, cas_col);
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -450,7 +442,7 @@ void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
|||
/* </summary> */
|
||||
int dwt_getgain_real(int orient)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -458,5 +450,5 @@ int dwt_getgain_real(int orient)
|
|||
/* </summary> */
|
||||
double dwt_getnorm_real(int level, int orient)
|
||||
{
|
||||
return dwt_norms_real[orient][level];
|
||||
return dwt_norms_real[orient][level];
|
||||
}
|
||||
|
|
|
@ -37,5 +37,5 @@
|
|||
*/
|
||||
int fix_mul(int a, int b)
|
||||
{
|
||||
return (int) ((int64) a * (int64) b >> 13);
|
||||
return (int) ((int64) a * (int64) b >> 13);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
*/
|
||||
int int_min(int a, int b)
|
||||
{
|
||||
return a < b ? a : b;
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -41,7 +41,7 @@ int int_min(int a, int b)
|
|||
*/
|
||||
int int_max(int a, int b)
|
||||
{
|
||||
return a > b ? a : b;
|
||||
return a > b ? a : b;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -53,11 +53,11 @@ int int_max(int a, int b)
|
|||
*/
|
||||
int int_clamp(int a, int min, int max)
|
||||
{
|
||||
if (a < min)
|
||||
return min;
|
||||
if (a > max)
|
||||
return max;
|
||||
return a;
|
||||
if (a < min)
|
||||
return min;
|
||||
if (a > max)
|
||||
return max;
|
||||
return a;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -65,7 +65,7 @@ int int_clamp(int a, int min, int max)
|
|||
*/
|
||||
int int_abs(int a)
|
||||
{
|
||||
return a < 0 ? -a : a;
|
||||
return a < 0 ? -a : a;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -75,7 +75,7 @@ int int_abs(int a)
|
|||
*/
|
||||
int int_ceildiv(int a, int b)
|
||||
{
|
||||
return (a + b - 1) / b;
|
||||
return (a + b - 1) / b;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -85,7 +85,7 @@ int int_ceildiv(int a, int b)
|
|||
*/
|
||||
int int_ceildivpow2(int a, int b)
|
||||
{
|
||||
return (a + (1 << b) - 1) >> b;
|
||||
return (a + (1 << b) - 1) >> b;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -95,7 +95,7 @@ int int_ceildivpow2(int a, int b)
|
|||
*/
|
||||
int int_floordivpow2(int a, int b)
|
||||
{
|
||||
return a >> b;
|
||||
return a >> b;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -105,9 +105,9 @@ int int_floordivpow2(int a, int b)
|
|||
*/
|
||||
int int_floorlog2(int a)
|
||||
{
|
||||
int l;
|
||||
for (l = 0; a > 1; l++) {
|
||||
a >>= 1;
|
||||
}
|
||||
return l;
|
||||
int l;
|
||||
for (l = 0; a > 1; l++) {
|
||||
a >>= 1;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
|
2002
libopenjpeg/j2k.c
2002
libopenjpeg/j2k.c
File diff suppressed because it is too large
Load Diff
|
@ -59,126 +59,126 @@
|
|||
#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 */
|
||||
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 */
|
||||
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;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0; /* XOsiz, YOsiz */
|
||||
int x1, y1; /* Xsiz, Ysiz */
|
||||
int numcomps; /* number of components */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
j2k_comp_t *comps; /* image-components */
|
||||
int x0, y0; /* XOsiz, YOsiz */
|
||||
int x1, y1; /* Xsiz, Ysiz */
|
||||
int numcomps; /* number of components */
|
||||
int index_on; /* 0 = no index || 1 = index */
|
||||
j2k_comp_t *comps; /* image-components */
|
||||
} j2k_image_t;
|
||||
|
||||
typedef struct {
|
||||
int expn; /* exponent */
|
||||
int mant; /* mantissa */
|
||||
int expn; /* exponent */
|
||||
int mant; /* mantissa */
|
||||
} j2k_stepsize_t;
|
||||
|
||||
typedef struct {
|
||||
int csty; /* coding style */
|
||||
int numresolutions; /* number of resolutions */
|
||||
int cblkw; /* width of code-blocks */
|
||||
int cblkh; /* height of code-blocks */
|
||||
int cblksty; /* code-block coding style */
|
||||
int qmfbid; /* discrete wavelet transform identifier */
|
||||
int qntsty; /* quantisation style */
|
||||
j2k_stepsize_t stepsizes[J2K_MAXBANDS]; /* stepsizes used for quantisation */
|
||||
int numgbits; /* number of guard bits */
|
||||
int roishift; /* Region Of Interest shift */
|
||||
int prcw[J2K_MAXRLVLS]; /* Precinct width */
|
||||
int prch[J2K_MAXRLVLS]; /* Precinct height */
|
||||
int csty; /* coding style */
|
||||
int numresolutions; /* number of resolutions */
|
||||
int cblkw; /* width of code-blocks */
|
||||
int cblkh; /* height of code-blocks */
|
||||
int cblksty; /* code-block coding style */
|
||||
int qmfbid; /* discrete wavelet transform identifier */
|
||||
int qntsty; /* quantisation style */
|
||||
j2k_stepsize_t stepsizes[J2K_MAXBANDS]; /* stepsizes used for quantisation */
|
||||
int numgbits; /* number of guard bits */
|
||||
int roishift; /* Region Of Interest shift */
|
||||
int prcw[J2K_MAXRLVLS]; /* Precinct width */
|
||||
int prch[J2K_MAXRLVLS]; /* Precinct height */
|
||||
} j2k_tccp_t;
|
||||
|
||||
typedef struct {
|
||||
int resno0, compno0;
|
||||
int layno1, resno1, compno1;
|
||||
int prg;
|
||||
int tile;
|
||||
char progorder[4];
|
||||
int resno0, compno0;
|
||||
int layno1, resno1, compno1;
|
||||
int prg;
|
||||
int tile;
|
||||
char progorder[4];
|
||||
} j2k_poc_t;
|
||||
|
||||
typedef struct {
|
||||
int first; /* 1 : first part-tile of a tile */
|
||||
int csty; /* coding style */
|
||||
int prg; /* progression order */
|
||||
int numlayers; /* number of layers */
|
||||
int mct; /* multi-component transform identifier */
|
||||
int rates[100]; /* rates of layers */
|
||||
int numpocs; /* number of progression order changes */
|
||||
int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
|
||||
j2k_poc_t pocs[32]; /* progression order changes */
|
||||
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
||||
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
||||
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
||||
j2k_tccp_t *tccps; /* tile-component coding parameters */
|
||||
int first; /* 1 : first part-tile of a tile */
|
||||
int csty; /* coding style */
|
||||
int prg; /* progression order */
|
||||
int numlayers; /* number of layers */
|
||||
int mct; /* multi-component transform identifier */
|
||||
int rates[100]; /* rates of layers */
|
||||
int numpocs; /* number of progression order changes */
|
||||
int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
|
||||
j2k_poc_t pocs[32]; /* progression order changes */
|
||||
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
||||
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
||||
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
||||
j2k_tccp_t *tccps; /* tile-component coding parameters */
|
||||
} j2k_tcp_t;
|
||||
|
||||
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; /* 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) */
|
||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
||||
j2k_tcp_t *tcps; /* tile coding parameters */
|
||||
int *matrice; /* Fixed layer */
|
||||
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; /* 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) */
|
||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
||||
j2k_tcp_t *tcps; /* tile coding parameters */
|
||||
int *matrice; /* Fixed layer */
|
||||
} j2k_cp_t;
|
||||
|
||||
typedef struct {
|
||||
int start_pos, end_pos; /* start and end position */
|
||||
double disto; /* ADD for Marcela */
|
||||
int start_pos, end_pos; /* start and end position */
|
||||
double disto; /* ADD for Marcela */
|
||||
} info_packet; /* Index struct */
|
||||
|
||||
typedef struct {
|
||||
double *thresh; /* value of thresh for each layer by tile cfr. Marcela */
|
||||
int num_tile; /* Number of Tile */
|
||||
int start_pos; /* Start position */
|
||||
int end_header; /* End position of the header */
|
||||
int end_pos; /* End position */
|
||||
int pw, ph; /* number of precinct by tile */
|
||||
info_packet *packet; /* information concerning packets inside tile */
|
||||
double *thresh; /* value of thresh for each layer by tile cfr. Marcela */
|
||||
int num_tile; /* Number of Tile */
|
||||
int start_pos; /* Start position */
|
||||
int end_header; /* End position of the header */
|
||||
int end_pos; /* End position */
|
||||
int pw, ph; /* number of precinct by tile */
|
||||
info_packet *packet; /* information concerning packets inside tile */
|
||||
} info_tile; /* index struct */
|
||||
|
||||
typedef struct {
|
||||
int index_on;
|
||||
double D_max; /* ADD for Marcela */
|
||||
int num; /* numero of packet */
|
||||
int index_write; /* writing the packet inthe index with t2_encode_packets */
|
||||
int Im_w, Im_h; /* Image width and Height */
|
||||
int Prog; /* progression order */
|
||||
int Tile_x, Tile_y; /* Number of Tile in X and Y */
|
||||
int tw, th;
|
||||
int Comp; /* Component numbers */
|
||||
int Layer; /* number of layer */
|
||||
int Decomposition; /* number of decomposition */
|
||||
int pw, ph; /* nombre precinct in X and Y */
|
||||
int pdx, pdy; /* size of precinct in X and Y */
|
||||
int Main_head_end; /* Main header position */
|
||||
int codestream_size; /* codestream's size */
|
||||
info_tile *tile; /* information concerning tiles inside image */
|
||||
int index_on;
|
||||
double D_max; /* ADD for Marcela */
|
||||
int num; /* numero of packet */
|
||||
int index_write; /* writing the packet inthe index with t2_encode_packets */
|
||||
int Im_w, Im_h; /* Image width and Height */
|
||||
int Prog; /* progression order */
|
||||
int Tile_x, Tile_y; /* Number of Tile in X and Y */
|
||||
int tw, th;
|
||||
int Comp; /* Component numbers */
|
||||
int Layer; /* number of layer */
|
||||
int Decomposition; /* number of decomposition */
|
||||
int pw, ph; /* nombre precinct in X and Y */
|
||||
int pdx, pdy; /* size of precinct in X and Y */
|
||||
int Main_head_end; /* Main header position */
|
||||
int codestream_size; /* codestream's size */
|
||||
info_tile *tile; /* information concerning tiles inside image */
|
||||
} info_image; /* index struct */
|
||||
|
||||
/*
|
||||
|
|
|
@ -40,18 +40,18 @@
|
|||
*/
|
||||
unsigned int jpt_read_VBAS_info(unsigned int value)
|
||||
{
|
||||
unsigned char elmt;
|
||||
unsigned char elmt;
|
||||
|
||||
elmt = cio_read(1);
|
||||
while ((elmt >> 7) == 1) {
|
||||
value = (value << 7);
|
||||
value |= (elmt & 0x7f);
|
||||
elmt = cio_read(1);
|
||||
}
|
||||
elmt = cio_read(1);
|
||||
while ((elmt >> 7) == 1) {
|
||||
value = (value << 7);
|
||||
value |= (elmt & 0x7f);
|
||||
elmt = cio_read(1);
|
||||
}
|
||||
value = (value << 7);
|
||||
value |= (elmt & 0x7f);
|
||||
|
||||
return value;
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -60,13 +60,13 @@ unsigned int jpt_read_VBAS_info(unsigned int value)
|
|||
*/
|
||||
void jpt_init_Msg_Header(jpt_msg_header_struct_t * header)
|
||||
{
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Class_Id = 0; /* Class Identifier */
|
||||
header->CSn_Id = 0; /* CSn : index identifier */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
header->Layer_nb = 0; /* Auxiliary for JPP case */
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Class_Id = 0; /* Class Identifier */
|
||||
header->CSn_Id = 0; /* CSn : index identifier */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
header->Layer_nb = 0; /* Auxiliary for JPP case */
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -77,10 +77,10 @@ void jpt_init_Msg_Header(jpt_msg_header_struct_t * header)
|
|||
*/
|
||||
void jpt_reinit_Msg_Header(jpt_msg_header_struct_t * header)
|
||||
{
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
header->Id = 0; /* In-class Identifier */
|
||||
header->last_byte = 0; /* Last byte information */
|
||||
header->Msg_offset = 0; /* Message offset */
|
||||
header->Msg_length = 0; /* Message length */
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -89,76 +89,75 @@ void jpt_reinit_Msg_Header(jpt_msg_header_struct_t * header)
|
|||
*/
|
||||
void jpt_read_Msg_Header(jpt_msg_header_struct_t * header)
|
||||
{
|
||||
unsigned char elmt, Class = 0, CSn = 0;
|
||||
jpt_reinit_Msg_Header(header);
|
||||
unsigned char elmt, Class = 0, CSn = 0;
|
||||
jpt_reinit_Msg_Header(header);
|
||||
|
||||
/* ------------- */
|
||||
/* VBAS : Bin-ID */
|
||||
/* ------------- */
|
||||
elmt = cio_read(1);
|
||||
/* ------------- */
|
||||
/* VBAS : Bin-ID */
|
||||
/* ------------- */
|
||||
elmt = cio_read(1);
|
||||
|
||||
/* See for Class and CSn */
|
||||
switch ((elmt >> 5) & 0x03) {
|
||||
case 0:
|
||||
fprintf(stderr,
|
||||
"Forbidden value encounter in message header !!\n");
|
||||
break;
|
||||
case 1:
|
||||
Class = 0;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 2:
|
||||
Class = 1;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 3:
|
||||
Class = 1;
|
||||
CSn = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* See for Class and CSn */
|
||||
switch ((elmt >> 5) & 0x03) {
|
||||
case 0:
|
||||
fprintf(stderr, "Forbidden value encounter in message header !!\n");
|
||||
break;
|
||||
case 1:
|
||||
Class = 0;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 2:
|
||||
Class = 1;
|
||||
CSn = 0;
|
||||
break;
|
||||
case 3:
|
||||
Class = 1;
|
||||
CSn = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
|
||||
if (((elmt >> 3) & 0x01) == 1)
|
||||
header->last_byte = 1;
|
||||
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
|
||||
if (((elmt >> 3) & 0x01) == 1)
|
||||
header->last_byte = 1;
|
||||
|
||||
/* In-class identifier */
|
||||
header->Id |= (elmt & 0x0f);
|
||||
if ((elmt >> 7) == 1)
|
||||
header->Id = jpt_read_VBAS_info(header->Id);
|
||||
/* In-class identifier */
|
||||
header->Id |= (elmt & 0x0f);
|
||||
if ((elmt >> 7) == 1)
|
||||
header->Id = jpt_read_VBAS_info(header->Id);
|
||||
|
||||
/* ------------ */
|
||||
/* VBAS : Class */
|
||||
/* ------------ */
|
||||
if (Class == 1) {
|
||||
header->Class_Id = 0;
|
||||
header->Class_Id = jpt_read_VBAS_info(header->Class_Id);
|
||||
}
|
||||
/* ------------ */
|
||||
/* VBAS : Class */
|
||||
/* ------------ */
|
||||
if (Class == 1) {
|
||||
header->Class_Id = 0;
|
||||
header->Class_Id = jpt_read_VBAS_info(header->Class_Id);
|
||||
}
|
||||
|
||||
/* ---------- */
|
||||
/* VBAS : CSn */
|
||||
/* ---------- */
|
||||
if (CSn == 1) {
|
||||
header->CSn_Id = 0;
|
||||
header->CSn_Id = jpt_read_VBAS_info(header->CSn_Id);
|
||||
}
|
||||
/* ---------- */
|
||||
/* VBAS : CSn */
|
||||
/* ---------- */
|
||||
if (CSn == 1) {
|
||||
header->CSn_Id = 0;
|
||||
header->CSn_Id = jpt_read_VBAS_info(header->CSn_Id);
|
||||
}
|
||||
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_offset */
|
||||
/* ----------------- */
|
||||
header->Msg_offset = jpt_read_VBAS_info(header->Msg_offset);
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_offset */
|
||||
/* ----------------- */
|
||||
header->Msg_offset = jpt_read_VBAS_info(header->Msg_offset);
|
||||
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_length */
|
||||
/* ----------------- */
|
||||
header->Msg_length = jpt_read_VBAS_info(header->Msg_length);
|
||||
/* ----------------- */
|
||||
/* VBAS : Msg_length */
|
||||
/* ----------------- */
|
||||
header->Msg_length = jpt_read_VBAS_info(header->Msg_length);
|
||||
|
||||
/* ---------- */
|
||||
/* VBAS : Aux */
|
||||
/* ---------- */
|
||||
if (header->CSn_Id == 1) {
|
||||
header->Layer_nb = 0;
|
||||
header->Layer_nb = jpt_read_VBAS_info(header->Layer_nb);
|
||||
}
|
||||
/* ---------- */
|
||||
/* VBAS : Aux */
|
||||
/* ---------- */
|
||||
if (header->CSn_Id == 1) {
|
||||
header->Layer_nb = 0;
|
||||
header->Layer_nb = jpt_read_VBAS_info(header->Layer_nb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,13 +30,13 @@
|
|||
*
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned int Id; /* In-class Identifier */
|
||||
unsigned int last_byte; /* Last byte information */
|
||||
unsigned int Class_Id; /* Class Identifier */
|
||||
unsigned int CSn_Id; /* CSn : index identifier */
|
||||
unsigned int Msg_offset; /* Message offset */
|
||||
unsigned int Msg_length; /* Message length */
|
||||
unsigned int Layer_nb; /* Auxiliary for JPP case */
|
||||
unsigned int Id; /* In-class Identifier */
|
||||
unsigned int last_byte; /* Last byte information */
|
||||
unsigned int Class_Id; /* Class Identifier */
|
||||
unsigned int CSn_Id; /* CSn : index identifier */
|
||||
unsigned int Msg_offset; /* Message offset */
|
||||
unsigned int Msg_length; /* Message length */
|
||||
unsigned int Layer_nb; /* Auxiliary for JPP case */
|
||||
} jpt_msg_header_struct_t;
|
||||
|
||||
/*
|
||||
|
|
|
@ -42,19 +42,19 @@ double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
|
|||
/* </summary> */
|
||||
void mct_encode(int *c0, int *c1, int *c2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int r, g, b, y, u, v;
|
||||
r = c0[i];
|
||||
g = c1[i];
|
||||
b = c2[i];
|
||||
y = (r + (g << 1) + b) >> 2;
|
||||
u = b - g;
|
||||
v = r - g;
|
||||
c0[i] = y;
|
||||
c1[i] = u;
|
||||
c2[i] = v;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int r, g, b, y, u, v;
|
||||
r = c0[i];
|
||||
g = c1[i];
|
||||
b = c2[i];
|
||||
y = (r + (g << 1) + b) >> 2;
|
||||
u = b - g;
|
||||
v = r - g;
|
||||
c0[i] = y;
|
||||
c1[i] = u;
|
||||
c2[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -62,19 +62,19 @@ void mct_encode(int *c0, int *c1, int *c2, int n)
|
|||
/* </summary> */
|
||||
void mct_decode(int *c0, int *c1, int *c2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int y, u, v, r, g, b;
|
||||
y = c0[i];
|
||||
u = c1[i];
|
||||
v = c2[i];
|
||||
g = y - ((u + v) >> 2);
|
||||
r = v + g;
|
||||
b = u + g;
|
||||
c0[i] = r;
|
||||
c1[i] = g;
|
||||
c2[i] = b;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int y, u, v, r, g, b;
|
||||
y = c0[i];
|
||||
u = c1[i];
|
||||
v = c2[i];
|
||||
g = y - ((u + v) >> 2);
|
||||
r = v + g;
|
||||
b = u + g;
|
||||
c0[i] = r;
|
||||
c1[i] = g;
|
||||
c2[i] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -82,7 +82,7 @@ void mct_decode(int *c0, int *c1, int *c2, int n)
|
|||
/* </summary> */
|
||||
double mct_getnorm(int compno)
|
||||
{
|
||||
return mct_norms[compno];
|
||||
return mct_norms[compno];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -90,19 +90,19 @@ double mct_getnorm(int compno)
|
|||
/* </summary> */
|
||||
void mct_encode_real(int *c0, int *c1, int *c2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int r, g, b, y, u, v;
|
||||
r = c0[i];
|
||||
g = c1[i];
|
||||
b = c2[i];
|
||||
y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
|
||||
u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
|
||||
v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
|
||||
c0[i] = y;
|
||||
c1[i] = u;
|
||||
c2[i] = v;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int r, g, b, y, u, v;
|
||||
r = c0[i];
|
||||
g = c1[i];
|
||||
b = c2[i];
|
||||
y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
|
||||
u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
|
||||
v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
|
||||
c0[i] = y;
|
||||
c1[i] = u;
|
||||
c2[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -110,19 +110,19 @@ void mct_encode_real(int *c0, int *c1, int *c2, int n)
|
|||
/* </summary> */
|
||||
void mct_decode_real(int *c0, int *c1, int *c2, int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int y, u, v, r, g, b;
|
||||
y = c0[i];
|
||||
u = c1[i];
|
||||
v = c2[i];
|
||||
r = y + fix_mul(v, 11485);
|
||||
g = y - fix_mul(u, 2819) - fix_mul(v, 5850);
|
||||
b = y + fix_mul(u, 14516);
|
||||
c0[i] = r;
|
||||
c1[i] = g;
|
||||
c2[i] = b;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
int y, u, v, r, g, b;
|
||||
y = c0[i];
|
||||
u = c1[i];
|
||||
v = c2[i];
|
||||
r = y + fix_mul(v, 11485);
|
||||
g = y - fix_mul(u, 2819) - fix_mul(v, 5850);
|
||||
b = y + fix_mul(u, 14516);
|
||||
c0[i] = r;
|
||||
c1[i] = g;
|
||||
c2[i] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -130,5 +130,5 @@ void mct_decode_real(int *c0, int *c1, int *c2, int n)
|
|||
/* </summary> */
|
||||
double mct_getnorm_real(int compno)
|
||||
{
|
||||
return mct_norms_real[compno];
|
||||
return mct_norms_real[compno];
|
||||
}
|
||||
|
|
|
@ -33,110 +33,110 @@
|
|||
/* This struct defines the state of a context. */
|
||||
/* </summary> */
|
||||
typedef struct mqc_state_s {
|
||||
unsigned int qeval; /* the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
|
||||
int mps; /* the Most Probable Symbol (0 or 1) */
|
||||
struct mqc_state_s *nmps; /* next state if the next encoded symbol is the MPS */
|
||||
struct mqc_state_s *nlps; /* next state if the next encoded symbol is the LPS */
|
||||
unsigned int qeval; /* the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
|
||||
int mps; /* the Most Probable Symbol (0 or 1) */
|
||||
struct mqc_state_s *nmps; /* next state if the next encoded symbol is the MPS */
|
||||
struct mqc_state_s *nlps; /* next state if the next encoded symbol is the LPS */
|
||||
} mqc_state_t;
|
||||
|
||||
/* <summary> */
|
||||
/* This array defines all the possible states for a context. */
|
||||
/* </summary> */
|
||||
mqc_state_t mqc_states[47 * 2] = {
|
||||
{0x5601, 0, &mqc_states[2], &mqc_states[3]},
|
||||
{0x5601, 1, &mqc_states[3], &mqc_states[2]},
|
||||
{0x3401, 0, &mqc_states[4], &mqc_states[12]},
|
||||
{0x3401, 1, &mqc_states[5], &mqc_states[13]},
|
||||
{0x1801, 0, &mqc_states[6], &mqc_states[18]},
|
||||
{0x1801, 1, &mqc_states[7], &mqc_states[19]},
|
||||
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
|
||||
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
|
||||
{0x0521, 0, &mqc_states[10], &mqc_states[58]},
|
||||
{0x0521, 1, &mqc_states[11], &mqc_states[59]},
|
||||
{0x0221, 0, &mqc_states[76], &mqc_states[66]},
|
||||
{0x0221, 1, &mqc_states[77], &mqc_states[67]},
|
||||
{0x5601, 0, &mqc_states[14], &mqc_states[13]},
|
||||
{0x5601, 1, &mqc_states[15], &mqc_states[12]},
|
||||
{0x5401, 0, &mqc_states[16], &mqc_states[28]},
|
||||
{0x5401, 1, &mqc_states[17], &mqc_states[29]},
|
||||
{0x4801, 0, &mqc_states[18], &mqc_states[28]},
|
||||
{0x4801, 1, &mqc_states[19], &mqc_states[29]},
|
||||
{0x3801, 0, &mqc_states[20], &mqc_states[28]},
|
||||
{0x3801, 1, &mqc_states[21], &mqc_states[29]},
|
||||
{0x3001, 0, &mqc_states[22], &mqc_states[34]},
|
||||
{0x3001, 1, &mqc_states[23], &mqc_states[35]},
|
||||
{0x2401, 0, &mqc_states[24], &mqc_states[36]},
|
||||
{0x2401, 1, &mqc_states[25], &mqc_states[37]},
|
||||
{0x1c01, 0, &mqc_states[26], &mqc_states[40]},
|
||||
{0x1c01, 1, &mqc_states[27], &mqc_states[41]},
|
||||
{0x1601, 0, &mqc_states[58], &mqc_states[42]},
|
||||
{0x1601, 1, &mqc_states[59], &mqc_states[43]},
|
||||
{0x5601, 0, &mqc_states[30], &mqc_states[29]},
|
||||
{0x5601, 1, &mqc_states[31], &mqc_states[28]},
|
||||
{0x5401, 0, &mqc_states[32], &mqc_states[28]},
|
||||
{0x5401, 1, &mqc_states[33], &mqc_states[29]},
|
||||
{0x5101, 0, &mqc_states[34], &mqc_states[30]},
|
||||
{0x5101, 1, &mqc_states[35], &mqc_states[31]},
|
||||
{0x4801, 0, &mqc_states[36], &mqc_states[32]},
|
||||
{0x4801, 1, &mqc_states[37], &mqc_states[33]},
|
||||
{0x3801, 0, &mqc_states[38], &mqc_states[34]},
|
||||
{0x3801, 1, &mqc_states[39], &mqc_states[35]},
|
||||
{0x3401, 0, &mqc_states[40], &mqc_states[36]},
|
||||
{0x3401, 1, &mqc_states[41], &mqc_states[37]},
|
||||
{0x3001, 0, &mqc_states[42], &mqc_states[38]},
|
||||
{0x3001, 1, &mqc_states[43], &mqc_states[39]},
|
||||
{0x2801, 0, &mqc_states[44], &mqc_states[38]},
|
||||
{0x2801, 1, &mqc_states[45], &mqc_states[39]},
|
||||
{0x2401, 0, &mqc_states[46], &mqc_states[40]},
|
||||
{0x2401, 1, &mqc_states[47], &mqc_states[41]},
|
||||
{0x2201, 0, &mqc_states[48], &mqc_states[42]},
|
||||
{0x2201, 1, &mqc_states[49], &mqc_states[43]},
|
||||
{0x1c01, 0, &mqc_states[50], &mqc_states[44]},
|
||||
{0x1c01, 1, &mqc_states[51], &mqc_states[45]},
|
||||
{0x1801, 0, &mqc_states[52], &mqc_states[46]},
|
||||
{0x1801, 1, &mqc_states[53], &mqc_states[47]},
|
||||
{0x1601, 0, &mqc_states[54], &mqc_states[48]},
|
||||
{0x1601, 1, &mqc_states[55], &mqc_states[49]},
|
||||
{0x1401, 0, &mqc_states[56], &mqc_states[50]},
|
||||
{0x1401, 1, &mqc_states[57], &mqc_states[51]},
|
||||
{0x1201, 0, &mqc_states[58], &mqc_states[52]},
|
||||
{0x1201, 1, &mqc_states[59], &mqc_states[53]},
|
||||
{0x1101, 0, &mqc_states[60], &mqc_states[54]},
|
||||
{0x1101, 1, &mqc_states[61], &mqc_states[55]},
|
||||
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
|
||||
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
|
||||
{0x09c1, 0, &mqc_states[64], &mqc_states[58]},
|
||||
{0x09c1, 1, &mqc_states[65], &mqc_states[59]},
|
||||
{0x08a1, 0, &mqc_states[66], &mqc_states[60]},
|
||||
{0x08a1, 1, &mqc_states[67], &mqc_states[61]},
|
||||
{0x0521, 0, &mqc_states[68], &mqc_states[62]},
|
||||
{0x0521, 1, &mqc_states[69], &mqc_states[63]},
|
||||
{0x0441, 0, &mqc_states[70], &mqc_states[64]},
|
||||
{0x0441, 1, &mqc_states[71], &mqc_states[65]},
|
||||
{0x02a1, 0, &mqc_states[72], &mqc_states[66]},
|
||||
{0x02a1, 1, &mqc_states[73], &mqc_states[67]},
|
||||
{0x0221, 0, &mqc_states[74], &mqc_states[68]},
|
||||
{0x0221, 1, &mqc_states[75], &mqc_states[69]},
|
||||
{0x0141, 0, &mqc_states[76], &mqc_states[70]},
|
||||
{0x0141, 1, &mqc_states[77], &mqc_states[71]},
|
||||
{0x0111, 0, &mqc_states[78], &mqc_states[72]},
|
||||
{0x0111, 1, &mqc_states[79], &mqc_states[73]},
|
||||
{0x0085, 0, &mqc_states[80], &mqc_states[74]},
|
||||
{0x0085, 1, &mqc_states[81], &mqc_states[75]},
|
||||
{0x0049, 0, &mqc_states[82], &mqc_states[76]},
|
||||
{0x0049, 1, &mqc_states[83], &mqc_states[77]},
|
||||
{0x0025, 0, &mqc_states[84], &mqc_states[78]},
|
||||
{0x0025, 1, &mqc_states[85], &mqc_states[79]},
|
||||
{0x0015, 0, &mqc_states[86], &mqc_states[80]},
|
||||
{0x0015, 1, &mqc_states[87], &mqc_states[81]},
|
||||
{0x0009, 0, &mqc_states[88], &mqc_states[82]},
|
||||
{0x0009, 1, &mqc_states[89], &mqc_states[83]},
|
||||
{0x0005, 0, &mqc_states[90], &mqc_states[84]},
|
||||
{0x0005, 1, &mqc_states[91], &mqc_states[85]},
|
||||
{0x0001, 0, &mqc_states[90], &mqc_states[86]},
|
||||
{0x0001, 1, &mqc_states[91], &mqc_states[87]},
|
||||
{0x5601, 0, &mqc_states[92], &mqc_states[92]},
|
||||
{0x5601, 1, &mqc_states[93], &mqc_states[93]},
|
||||
{0x5601, 0, &mqc_states[2], &mqc_states[3]},
|
||||
{0x5601, 1, &mqc_states[3], &mqc_states[2]},
|
||||
{0x3401, 0, &mqc_states[4], &mqc_states[12]},
|
||||
{0x3401, 1, &mqc_states[5], &mqc_states[13]},
|
||||
{0x1801, 0, &mqc_states[6], &mqc_states[18]},
|
||||
{0x1801, 1, &mqc_states[7], &mqc_states[19]},
|
||||
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
|
||||
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
|
||||
{0x0521, 0, &mqc_states[10], &mqc_states[58]},
|
||||
{0x0521, 1, &mqc_states[11], &mqc_states[59]},
|
||||
{0x0221, 0, &mqc_states[76], &mqc_states[66]},
|
||||
{0x0221, 1, &mqc_states[77], &mqc_states[67]},
|
||||
{0x5601, 0, &mqc_states[14], &mqc_states[13]},
|
||||
{0x5601, 1, &mqc_states[15], &mqc_states[12]},
|
||||
{0x5401, 0, &mqc_states[16], &mqc_states[28]},
|
||||
{0x5401, 1, &mqc_states[17], &mqc_states[29]},
|
||||
{0x4801, 0, &mqc_states[18], &mqc_states[28]},
|
||||
{0x4801, 1, &mqc_states[19], &mqc_states[29]},
|
||||
{0x3801, 0, &mqc_states[20], &mqc_states[28]},
|
||||
{0x3801, 1, &mqc_states[21], &mqc_states[29]},
|
||||
{0x3001, 0, &mqc_states[22], &mqc_states[34]},
|
||||
{0x3001, 1, &mqc_states[23], &mqc_states[35]},
|
||||
{0x2401, 0, &mqc_states[24], &mqc_states[36]},
|
||||
{0x2401, 1, &mqc_states[25], &mqc_states[37]},
|
||||
{0x1c01, 0, &mqc_states[26], &mqc_states[40]},
|
||||
{0x1c01, 1, &mqc_states[27], &mqc_states[41]},
|
||||
{0x1601, 0, &mqc_states[58], &mqc_states[42]},
|
||||
{0x1601, 1, &mqc_states[59], &mqc_states[43]},
|
||||
{0x5601, 0, &mqc_states[30], &mqc_states[29]},
|
||||
{0x5601, 1, &mqc_states[31], &mqc_states[28]},
|
||||
{0x5401, 0, &mqc_states[32], &mqc_states[28]},
|
||||
{0x5401, 1, &mqc_states[33], &mqc_states[29]},
|
||||
{0x5101, 0, &mqc_states[34], &mqc_states[30]},
|
||||
{0x5101, 1, &mqc_states[35], &mqc_states[31]},
|
||||
{0x4801, 0, &mqc_states[36], &mqc_states[32]},
|
||||
{0x4801, 1, &mqc_states[37], &mqc_states[33]},
|
||||
{0x3801, 0, &mqc_states[38], &mqc_states[34]},
|
||||
{0x3801, 1, &mqc_states[39], &mqc_states[35]},
|
||||
{0x3401, 0, &mqc_states[40], &mqc_states[36]},
|
||||
{0x3401, 1, &mqc_states[41], &mqc_states[37]},
|
||||
{0x3001, 0, &mqc_states[42], &mqc_states[38]},
|
||||
{0x3001, 1, &mqc_states[43], &mqc_states[39]},
|
||||
{0x2801, 0, &mqc_states[44], &mqc_states[38]},
|
||||
{0x2801, 1, &mqc_states[45], &mqc_states[39]},
|
||||
{0x2401, 0, &mqc_states[46], &mqc_states[40]},
|
||||
{0x2401, 1, &mqc_states[47], &mqc_states[41]},
|
||||
{0x2201, 0, &mqc_states[48], &mqc_states[42]},
|
||||
{0x2201, 1, &mqc_states[49], &mqc_states[43]},
|
||||
{0x1c01, 0, &mqc_states[50], &mqc_states[44]},
|
||||
{0x1c01, 1, &mqc_states[51], &mqc_states[45]},
|
||||
{0x1801, 0, &mqc_states[52], &mqc_states[46]},
|
||||
{0x1801, 1, &mqc_states[53], &mqc_states[47]},
|
||||
{0x1601, 0, &mqc_states[54], &mqc_states[48]},
|
||||
{0x1601, 1, &mqc_states[55], &mqc_states[49]},
|
||||
{0x1401, 0, &mqc_states[56], &mqc_states[50]},
|
||||
{0x1401, 1, &mqc_states[57], &mqc_states[51]},
|
||||
{0x1201, 0, &mqc_states[58], &mqc_states[52]},
|
||||
{0x1201, 1, &mqc_states[59], &mqc_states[53]},
|
||||
{0x1101, 0, &mqc_states[60], &mqc_states[54]},
|
||||
{0x1101, 1, &mqc_states[61], &mqc_states[55]},
|
||||
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
|
||||
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
|
||||
{0x09c1, 0, &mqc_states[64], &mqc_states[58]},
|
||||
{0x09c1, 1, &mqc_states[65], &mqc_states[59]},
|
||||
{0x08a1, 0, &mqc_states[66], &mqc_states[60]},
|
||||
{0x08a1, 1, &mqc_states[67], &mqc_states[61]},
|
||||
{0x0521, 0, &mqc_states[68], &mqc_states[62]},
|
||||
{0x0521, 1, &mqc_states[69], &mqc_states[63]},
|
||||
{0x0441, 0, &mqc_states[70], &mqc_states[64]},
|
||||
{0x0441, 1, &mqc_states[71], &mqc_states[65]},
|
||||
{0x02a1, 0, &mqc_states[72], &mqc_states[66]},
|
||||
{0x02a1, 1, &mqc_states[73], &mqc_states[67]},
|
||||
{0x0221, 0, &mqc_states[74], &mqc_states[68]},
|
||||
{0x0221, 1, &mqc_states[75], &mqc_states[69]},
|
||||
{0x0141, 0, &mqc_states[76], &mqc_states[70]},
|
||||
{0x0141, 1, &mqc_states[77], &mqc_states[71]},
|
||||
{0x0111, 0, &mqc_states[78], &mqc_states[72]},
|
||||
{0x0111, 1, &mqc_states[79], &mqc_states[73]},
|
||||
{0x0085, 0, &mqc_states[80], &mqc_states[74]},
|
||||
{0x0085, 1, &mqc_states[81], &mqc_states[75]},
|
||||
{0x0049, 0, &mqc_states[82], &mqc_states[76]},
|
||||
{0x0049, 1, &mqc_states[83], &mqc_states[77]},
|
||||
{0x0025, 0, &mqc_states[84], &mqc_states[78]},
|
||||
{0x0025, 1, &mqc_states[85], &mqc_states[79]},
|
||||
{0x0015, 0, &mqc_states[86], &mqc_states[80]},
|
||||
{0x0015, 1, &mqc_states[87], &mqc_states[81]},
|
||||
{0x0009, 0, &mqc_states[88], &mqc_states[82]},
|
||||
{0x0009, 1, &mqc_states[89], &mqc_states[83]},
|
||||
{0x0005, 0, &mqc_states[90], &mqc_states[84]},
|
||||
{0x0005, 1, &mqc_states[91], &mqc_states[85]},
|
||||
{0x0001, 0, &mqc_states[90], &mqc_states[86]},
|
||||
{0x0001, 1, &mqc_states[91], &mqc_states[87]},
|
||||
{0x5601, 0, &mqc_states[92], &mqc_states[92]},
|
||||
{0x5601, 1, &mqc_states[93], &mqc_states[93]},
|
||||
};
|
||||
|
||||
#define MQC_NUMCTXS 32
|
||||
|
@ -155,7 +155,7 @@ mqc_state_t **mqc_curctx;
|
|||
/* </summary> */
|
||||
int mqc_numbytes()
|
||||
{
|
||||
return mqc_bp - mqc_start;
|
||||
return mqc_bp - mqc_start;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -164,33 +164,33 @@ int mqc_numbytes()
|
|||
/* </summary> */
|
||||
void mqc_byteout()
|
||||
{
|
||||
if (*mqc_bp == 0xff) {
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 20;
|
||||
mqc_c &= 0xfffff;
|
||||
mqc_ct = 7;
|
||||
} else {
|
||||
if ((mqc_c & 0x8000000) == 0) { /* ((mqc_c&0x8000000)==0) CHANGE */
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 19;
|
||||
mqc_c &= 0x7ffff;
|
||||
mqc_ct = 8;
|
||||
} else {
|
||||
(*mqc_bp)++;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_c &= 0x7ffffff;
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 20;
|
||||
mqc_c &= 0xfffff;
|
||||
mqc_ct = 7;
|
||||
} else {
|
||||
if ((mqc_c & 0x8000000) == 0) { /* ((mqc_c&0x8000000)==0) CHANGE */
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 19;
|
||||
mqc_c &= 0x7ffff;
|
||||
mqc_ct = 8;
|
||||
} else {
|
||||
(*mqc_bp)++;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_c &= 0x7ffffff;
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 20;
|
||||
mqc_c &= 0xfffff;
|
||||
mqc_ct = 7;
|
||||
} else {
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 19;
|
||||
mqc_c &= 0x7ffff;
|
||||
mqc_ct = 8;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c >> 19;
|
||||
mqc_c &= 0x7ffff;
|
||||
mqc_ct = 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -198,14 +198,14 @@ void mqc_byteout()
|
|||
/* </summary> */
|
||||
void mqc_renorme()
|
||||
{
|
||||
do {
|
||||
mqc_a <<= 1;
|
||||
mqc_c <<= 1;
|
||||
mqc_ct--;
|
||||
if (mqc_ct == 0) {
|
||||
mqc_byteout();
|
||||
}
|
||||
} while ((mqc_a & 0x8000) == 0);
|
||||
do {
|
||||
mqc_a <<= 1;
|
||||
mqc_c <<= 1;
|
||||
mqc_ct--;
|
||||
if (mqc_ct == 0) {
|
||||
mqc_byteout();
|
||||
}
|
||||
} while ((mqc_a & 0x8000) == 0);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -213,18 +213,18 @@ void mqc_renorme()
|
|||
/* </summary> */
|
||||
void mqc_codemps()
|
||||
{
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if ((mqc_a & 0x8000) == 0) {
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
} else {
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
}
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
mqc_renorme();
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if ((mqc_a & 0x8000) == 0) {
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
} else {
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
}
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
mqc_renorme();
|
||||
} else {
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -232,14 +232,14 @@ void mqc_codemps()
|
|||
/* </summary> */
|
||||
void mqc_codelps()
|
||||
{
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
} else {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
}
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
mqc_renorme();
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_c += (*mqc_curctx)->qeval;
|
||||
} else {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
}
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
mqc_renorme();
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -248,15 +248,15 @@ void mqc_codelps()
|
|||
/* <param name="bp">Output buffer.</param> */
|
||||
void mqc_init_enc(unsigned char *bp)
|
||||
{
|
||||
mqc_setcurctx(0);
|
||||
mqc_a = 0x8000;
|
||||
mqc_c = 0;
|
||||
mqc_bp = bp - 1;
|
||||
mqc_ct = 12;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 13;
|
||||
}
|
||||
mqc_start = bp;
|
||||
mqc_setcurctx(0);
|
||||
mqc_a = 0x8000;
|
||||
mqc_c = 0;
|
||||
mqc_bp = bp - 1;
|
||||
mqc_ct = 12;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 13;
|
||||
}
|
||||
mqc_start = bp;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -265,7 +265,7 @@ void mqc_init_enc(unsigned char *bp)
|
|||
/* <param name="ctxno">Context number.</param> */
|
||||
void mqc_setcurctx(int ctxno)
|
||||
{
|
||||
mqc_curctx = &mqc_ctxs[ctxno];
|
||||
mqc_curctx = &mqc_ctxs[ctxno];
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -274,11 +274,11 @@ void mqc_setcurctx(int ctxno)
|
|||
/* <param name="d"> The symbol to be encoded (0 or 1).</param> */
|
||||
void mqc_encode(int d)
|
||||
{
|
||||
if ((*mqc_curctx)->mps == d) {
|
||||
mqc_codemps();
|
||||
} else {
|
||||
mqc_codelps();
|
||||
}
|
||||
if ((*mqc_curctx)->mps == d) {
|
||||
mqc_codemps();
|
||||
} else {
|
||||
mqc_codelps();
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -286,11 +286,11 @@ void mqc_encode(int d)
|
|||
/* </summary> */
|
||||
void mqc_setbits()
|
||||
{
|
||||
unsigned int tempc = mqc_c + mqc_a;
|
||||
mqc_c |= 0xffff;
|
||||
if (mqc_c >= tempc) {
|
||||
mqc_c -= 0x8000;
|
||||
}
|
||||
unsigned int tempc = mqc_c + mqc_a;
|
||||
mqc_c |= 0xffff;
|
||||
if (mqc_c >= tempc) {
|
||||
mqc_c -= 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -298,15 +298,15 @@ void mqc_setbits()
|
|||
/* </summary> */
|
||||
void mqc_flush()
|
||||
{
|
||||
mqc_setbits();
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_byteout();
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_byteout();
|
||||
mqc_setbits();
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_byteout();
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_byteout();
|
||||
|
||||
if (*mqc_bp != 0xff) {
|
||||
mqc_bp++;
|
||||
}
|
||||
if (*mqc_bp != 0xff) {
|
||||
mqc_bp++;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -316,11 +316,11 @@ void mqc_flush()
|
|||
/* </summary> */
|
||||
void mqc_bypass_init_enc()
|
||||
{
|
||||
mqc_c = 0;
|
||||
mqc_ct = 8;
|
||||
/*if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 7;
|
||||
} */
|
||||
mqc_c = 0;
|
||||
mqc_ct = 8;
|
||||
/*if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 7;
|
||||
} */
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -330,17 +330,17 @@ void mqc_bypass_init_enc()
|
|||
/* </summary> */
|
||||
void mqc_bypass_enc(int d)
|
||||
{
|
||||
mqc_ct--;
|
||||
mqc_c = mqc_c + (d << mqc_ct);
|
||||
if (mqc_ct == 0) {
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c;
|
||||
mqc_ct = 8;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 7;
|
||||
}
|
||||
mqc_c = 0;
|
||||
mqc_ct--;
|
||||
mqc_c = mqc_c + (d << mqc_ct);
|
||||
if (mqc_ct == 0) {
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c;
|
||||
mqc_ct = 8;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 7;
|
||||
}
|
||||
mqc_c = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -349,23 +349,23 @@ void mqc_bypass_enc(int d)
|
|||
/* </summary> */
|
||||
int mqc_bypass_flush_enc()
|
||||
{
|
||||
unsigned char bit_padding;
|
||||
unsigned char bit_padding;
|
||||
|
||||
bit_padding = 0;
|
||||
bit_padding = 0;
|
||||
|
||||
if (mqc_ct != 0) {
|
||||
while (mqc_ct > 0) {
|
||||
mqc_ct--;
|
||||
mqc_c += bit_padding << mqc_ct;
|
||||
bit_padding = (bit_padding + 1) & 0x01;
|
||||
}
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c;
|
||||
mqc_ct = 8;
|
||||
mqc_c = 0;
|
||||
if (mqc_ct != 0) {
|
||||
while (mqc_ct > 0) {
|
||||
mqc_ct--;
|
||||
mqc_c += bit_padding << mqc_ct;
|
||||
bit_padding = (bit_padding + 1) & 0x01;
|
||||
}
|
||||
mqc_bp++;
|
||||
*mqc_bp = mqc_c;
|
||||
mqc_ct = 8;
|
||||
mqc_c = 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -373,10 +373,10 @@ int mqc_bypass_flush_enc()
|
|||
/* </summary> */
|
||||
void mqc_reset_enc()
|
||||
{
|
||||
mqc_resetstates();
|
||||
mqc_setstate(18, 0, 46);
|
||||
mqc_setstate(0, 0, 3);
|
||||
mqc_setstate(1, 0, 4);
|
||||
mqc_resetstates();
|
||||
mqc_setstate(18, 0, 46);
|
||||
mqc_setstate(0, 0, 3);
|
||||
mqc_setstate(1, 0, 4);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -384,19 +384,19 @@ void mqc_reset_enc()
|
|||
/* </summary> */
|
||||
int mqc_restart_enc()
|
||||
{
|
||||
int correction = 1;
|
||||
int correction = 1;
|
||||
|
||||
/* <flush part> */
|
||||
int n = 27 - 15 - mqc_ct;
|
||||
mqc_c <<= mqc_ct;
|
||||
while (n > 0) {
|
||||
mqc_byteout();
|
||||
n -= mqc_ct;
|
||||
mqc_c <<= mqc_ct;
|
||||
}
|
||||
/* <flush part> */
|
||||
int n = 27 - 15 - mqc_ct;
|
||||
mqc_c <<= mqc_ct;
|
||||
while (n > 0) {
|
||||
mqc_byteout();
|
||||
n -= mqc_ct;
|
||||
mqc_c <<= mqc_ct;
|
||||
}
|
||||
mqc_byteout();
|
||||
|
||||
return correction;
|
||||
return correction;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -404,15 +404,15 @@ int mqc_restart_enc()
|
|||
/* </summary> */
|
||||
void mqc_restart_init_enc()
|
||||
{
|
||||
/* <Re-init part> */
|
||||
mqc_setcurctx(0);
|
||||
mqc_a = 0x8000;
|
||||
mqc_c = 0;
|
||||
mqc_ct = 12;
|
||||
mqc_bp--;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 13;
|
||||
}
|
||||
/* <Re-init part> */
|
||||
mqc_setcurctx(0);
|
||||
mqc_a = 0x8000;
|
||||
mqc_c = 0;
|
||||
mqc_ct = 12;
|
||||
mqc_bp--;
|
||||
if (*mqc_bp == 0xff) {
|
||||
mqc_ct = 13;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -421,18 +421,18 @@ void mqc_restart_init_enc()
|
|||
/* </summary> */
|
||||
void mqc_erterm_enc()
|
||||
{
|
||||
int k = 11 - mqc_ct + 1;
|
||||
int k = 11 - mqc_ct + 1;
|
||||
|
||||
while (k > 0) {
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_ct = 0;
|
||||
mqc_byteout();
|
||||
k -= mqc_ct;
|
||||
}
|
||||
while (k > 0) {
|
||||
mqc_c <<= mqc_ct;
|
||||
mqc_ct = 0;
|
||||
mqc_byteout();
|
||||
k -= mqc_ct;
|
||||
}
|
||||
|
||||
if (*mqc_bp != 0xff) {
|
||||
mqc_byteout();
|
||||
}
|
||||
if (*mqc_bp != 0xff) {
|
||||
mqc_byteout();
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -440,44 +440,44 @@ void mqc_erterm_enc()
|
|||
/* </summary> */
|
||||
void mqc_segmark_enc()
|
||||
{
|
||||
int i;
|
||||
mqc_setcurctx(18);
|
||||
int i;
|
||||
mqc_setcurctx(18);
|
||||
|
||||
for (i = 1; i < 5; i++) {
|
||||
mqc_encode(i % 2);
|
||||
}
|
||||
for (i = 1; i < 5; i++) {
|
||||
mqc_encode(i % 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* </summary> */
|
||||
int mqc_mpsexchange()
|
||||
{
|
||||
int d;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
d = 1 - (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
} else {
|
||||
d = (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
}
|
||||
return d;
|
||||
int d;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
d = 1 - (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
} else {
|
||||
d = (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
/* </summary> */
|
||||
int mqc_lpsexchange()
|
||||
{
|
||||
int d;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
d = (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
} else {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
d = 1 - (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
}
|
||||
return d;
|
||||
int d;
|
||||
if (mqc_a < (*mqc_curctx)->qeval) {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
d = (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nmps;
|
||||
} else {
|
||||
mqc_a = (*mqc_curctx)->qeval;
|
||||
d = 1 - (*mqc_curctx)->mps;
|
||||
*mqc_curctx = (*mqc_curctx)->nlps;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -485,31 +485,31 @@ int mqc_lpsexchange()
|
|||
/* </summary> */
|
||||
void mqc_bytein()
|
||||
{
|
||||
if (mqc_bp != mqc_end) {
|
||||
unsigned int c;
|
||||
if (mqc_bp + 1 != mqc_end) {
|
||||
c = *(mqc_bp + 1);
|
||||
} else {
|
||||
c = 0xff;
|
||||
}
|
||||
if (*mqc_bp == 0xff) {
|
||||
if (c > 0x8f) {
|
||||
mqc_c += 0xff00;
|
||||
mqc_ct = 8;
|
||||
} else {
|
||||
mqc_bp++;
|
||||
mqc_c += c << 9;
|
||||
mqc_ct = 7;
|
||||
}
|
||||
} else {
|
||||
mqc_bp++;
|
||||
mqc_c += c << 8;
|
||||
mqc_ct = 8;
|
||||
}
|
||||
if (mqc_bp != mqc_end) {
|
||||
unsigned int c;
|
||||
if (mqc_bp + 1 != mqc_end) {
|
||||
c = *(mqc_bp + 1);
|
||||
} else {
|
||||
c = 0xff;
|
||||
}
|
||||
if (*mqc_bp == 0xff) {
|
||||
if (c > 0x8f) {
|
||||
mqc_c += 0xff00;
|
||||
mqc_ct = 8;
|
||||
} else {
|
||||
mqc_bp++;
|
||||
mqc_c += c << 9;
|
||||
mqc_ct = 7;
|
||||
}
|
||||
} else {
|
||||
mqc_bp++;
|
||||
mqc_c += c << 8;
|
||||
mqc_ct = 8;
|
||||
}
|
||||
} else {
|
||||
mqc_c += 0xff00;
|
||||
mqc_ct = 8;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -517,14 +517,14 @@ void mqc_bytein()
|
|||
/* </summary> */
|
||||
void mqc_renormd()
|
||||
{
|
||||
do {
|
||||
if (mqc_ct == 0) {
|
||||
mqc_bytein();
|
||||
}
|
||||
mqc_a <<= 1;
|
||||
mqc_c <<= 1;
|
||||
mqc_ct--;
|
||||
} while (mqc_a < 0x8000);
|
||||
do {
|
||||
if (mqc_ct == 0) {
|
||||
mqc_bytein();
|
||||
}
|
||||
mqc_a <<= 1;
|
||||
mqc_c <<= 1;
|
||||
mqc_ct--;
|
||||
} while (mqc_a < 0x8000);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -532,15 +532,15 @@ void mqc_renormd()
|
|||
/* </summary> */
|
||||
void mqc_init_dec(unsigned char *bp, int len)
|
||||
{
|
||||
mqc_setcurctx(0);
|
||||
mqc_start = bp;
|
||||
mqc_end = bp + len;
|
||||
mqc_bp = bp;
|
||||
mqc_c = *mqc_bp << 16;
|
||||
mqc_bytein();
|
||||
mqc_c <<= 7;
|
||||
mqc_ct -= 7;
|
||||
mqc_a = 0x8000;
|
||||
mqc_setcurctx(0);
|
||||
mqc_start = bp;
|
||||
mqc_end = bp + len;
|
||||
mqc_bp = bp;
|
||||
mqc_c = *mqc_bp << 16;
|
||||
mqc_bytein();
|
||||
mqc_c <<= 7;
|
||||
mqc_ct -= 7;
|
||||
mqc_a = 0x8000;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -548,21 +548,21 @@ void mqc_init_dec(unsigned char *bp, int len)
|
|||
/* </summary> */
|
||||
int mqc_decode()
|
||||
{
|
||||
int d;
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if ((mqc_c >> 16) < (*mqc_curctx)->qeval) {
|
||||
d = mqc_lpsexchange();
|
||||
mqc_renormd();
|
||||
int d;
|
||||
mqc_a -= (*mqc_curctx)->qeval;
|
||||
if ((mqc_c >> 16) < (*mqc_curctx)->qeval) {
|
||||
d = mqc_lpsexchange();
|
||||
mqc_renormd();
|
||||
} else {
|
||||
mqc_c -= (*mqc_curctx)->qeval << 16;
|
||||
if ((mqc_a & 0x8000) == 0) {
|
||||
d = mqc_mpsexchange();
|
||||
mqc_renormd();
|
||||
} else {
|
||||
mqc_c -= (*mqc_curctx)->qeval << 16;
|
||||
if ((mqc_a & 0x8000) == 0) {
|
||||
d = mqc_mpsexchange();
|
||||
mqc_renormd();
|
||||
} else {
|
||||
d = (*mqc_curctx)->mps;
|
||||
}
|
||||
d = (*mqc_curctx)->mps;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -570,10 +570,10 @@ int mqc_decode()
|
|||
/* </summary> */
|
||||
void mqc_resetstates()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MQC_NUMCTXS; i++) {
|
||||
mqc_ctxs[i] = mqc_states;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < MQC_NUMCTXS; i++) {
|
||||
mqc_ctxs[i] = mqc_states;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -584,5 +584,5 @@ void mqc_resetstates()
|
|||
/* <param name="prob">Index to the probability of symbols</param> */
|
||||
void mqc_setstate(int ctxno, int msb, int prob)
|
||||
{
|
||||
mqc_ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
|
||||
mqc_ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
|
||||
}
|
||||
|
|
837
libopenjpeg/pi.c
837
libopenjpeg/pi.c
|
@ -36,110 +36,108 @@
|
|||
* </summary> */
|
||||
pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
|
||||
{
|
||||
int p, q, i;
|
||||
int compno, resno, pino;
|
||||
int maxres = 0;
|
||||
pi_iterator_t *pi;
|
||||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tccp;
|
||||
int p, q, i;
|
||||
int compno, resno, pino;
|
||||
int maxres = 0;
|
||||
pi_iterator_t *pi;
|
||||
j2k_tcp_t *tcp;
|
||||
j2k_tccp_t *tccp;
|
||||
|
||||
tcp = &cp->tcps[tileno];
|
||||
pi = (pi_iterator_t *) malloc((tcp->numpocs + 1) *
|
||||
sizeof(pi_iterator_t));
|
||||
tcp = &cp->tcps[tileno];
|
||||
pi = (pi_iterator_t *) malloc((tcp->numpocs + 1) *
|
||||
sizeof(pi_iterator_t));
|
||||
|
||||
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
|
||||
p = tileno % cp->tw;
|
||||
q = tileno / cp->tw;
|
||||
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
|
||||
p = tileno % cp->tw;
|
||||
q = tileno / cp->tw;
|
||||
|
||||
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, img->x0);
|
||||
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, img->y0);
|
||||
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, img->x1);
|
||||
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, img->y1);
|
||||
pi[pino].numcomps = img->numcomps;
|
||||
pi[pino].comps =
|
||||
(pi_comp_t *) malloc(img->numcomps * sizeof(pi_comp_t));
|
||||
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, img->x0);
|
||||
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, img->y0);
|
||||
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, img->x1);
|
||||
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, img->y1);
|
||||
pi[pino].numcomps = img->numcomps;
|
||||
pi[pino].comps =
|
||||
(pi_comp_t *) malloc(img->numcomps * sizeof(pi_comp_t));
|
||||
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
int tcx0, tcy0, tcx1, tcy1;
|
||||
pi_comp_t *comp = &pi[pino].comps[compno];
|
||||
tccp = &tcp->tccps[compno];
|
||||
comp->dx = img->comps[compno].dx;
|
||||
comp->dy = img->comps[compno].dy;
|
||||
comp->numresolutions = tccp->numresolutions;
|
||||
comp->resolutions =
|
||||
(pi_resolution_t *) malloc(comp->numresolutions *
|
||||
sizeof(pi_resolution_t));
|
||||
tcx0 = int_ceildiv(pi->tx0, comp->dx);
|
||||
tcy0 = int_ceildiv(pi->ty0, comp->dy);
|
||||
tcx1 = int_ceildiv(pi->tx1, comp->dx);
|
||||
tcy1 = int_ceildiv(pi->ty1, comp->dy);
|
||||
if (comp->numresolutions > maxres) {
|
||||
maxres = comp->numresolutions;
|
||||
}
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int levelno;
|
||||
int rx0, ry0, rx1, ry1;
|
||||
int px0, py0, px1, py1;
|
||||
pi_resolution_t *res = &comp->resolutions[resno];
|
||||
if (tccp->csty & J2K_CCP_CSTY_PRT) {
|
||||
res->pdx = tccp->prcw[resno];
|
||||
res->pdy = tccp->prch[resno];
|
||||
} else {
|
||||
res->pdx = 15;
|
||||
res->pdy = 15;
|
||||
}
|
||||
levelno = comp->numresolutions - 1 - resno;
|
||||
rx0 = int_ceildivpow2(tcx0, levelno);
|
||||
ry0 = int_ceildivpow2(tcy0, levelno);
|
||||
rx1 = int_ceildivpow2(tcx1, levelno);
|
||||
ry1 = int_ceildivpow2(tcy1, levelno);
|
||||
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
|
||||
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
||||
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
||||
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
||||
res->pw = (px1 - px0) >> res->pdx;
|
||||
res->ph = (py1 - py0) >> res->pdy;
|
||||
}
|
||||
}
|
||||
|
||||
tccp = &tcp->tccps[0];
|
||||
pi[pino].step_p = 1;
|
||||
pi[pino].step_c = 100 * pi[pino].step_p;
|
||||
pi[pino].step_r = img->numcomps * pi[pino].step_c;
|
||||
pi[pino].step_l = maxres * pi[pino].step_r;
|
||||
|
||||
if (pino == 0) {
|
||||
pi[pino].include =
|
||||
(short int *) malloc(img->numcomps * maxres *
|
||||
tcp->numlayers * 100 *
|
||||
sizeof(short int));
|
||||
for (i = 0; i < img->numcomps * maxres * tcp->numlayers * 100;
|
||||
i++)
|
||||
pi[pino].include[i] = 0;
|
||||
}
|
||||
/* pi[pino].include=(short int*)calloc(img->numcomps*maxres*tcp->numlayers*1000,sizeof(short int)); */
|
||||
else
|
||||
pi[pino].include = pi[pino - 1].include;
|
||||
|
||||
if (tcp->POC == 0) {
|
||||
pi[pino].first = 1;
|
||||
pi[pino].poc.resno0 = 0;
|
||||
pi[pino].poc.compno0 = 0;
|
||||
pi[pino].poc.layno1 = tcp->numlayers;
|
||||
pi[pino].poc.resno1 = maxres;
|
||||
pi[pino].poc.compno1 = img->numcomps;
|
||||
pi[pino].poc.prg = tcp->prg;
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
int tcx0, tcy0, tcx1, tcy1;
|
||||
pi_comp_t *comp = &pi[pino].comps[compno];
|
||||
tccp = &tcp->tccps[compno];
|
||||
comp->dx = img->comps[compno].dx;
|
||||
comp->dy = img->comps[compno].dy;
|
||||
comp->numresolutions = tccp->numresolutions;
|
||||
comp->resolutions =
|
||||
(pi_resolution_t *) malloc(comp->numresolutions *
|
||||
sizeof(pi_resolution_t));
|
||||
tcx0 = int_ceildiv(pi->tx0, comp->dx);
|
||||
tcy0 = int_ceildiv(pi->ty0, comp->dy);
|
||||
tcx1 = int_ceildiv(pi->tx1, comp->dx);
|
||||
tcy1 = int_ceildiv(pi->ty1, comp->dy);
|
||||
if (comp->numresolutions > maxres) {
|
||||
maxres = comp->numresolutions;
|
||||
}
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int levelno;
|
||||
int rx0, ry0, rx1, ry1;
|
||||
int px0, py0, px1, py1;
|
||||
pi_resolution_t *res = &comp->resolutions[resno];
|
||||
if (tccp->csty & J2K_CCP_CSTY_PRT) {
|
||||
res->pdx = tccp->prcw[resno];
|
||||
res->pdy = tccp->prch[resno];
|
||||
} else {
|
||||
pi[pino].first = 1;
|
||||
pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
|
||||
pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
|
||||
pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
|
||||
pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
|
||||
pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
|
||||
pi[pino].poc.prg = tcp->pocs[pino].prg;
|
||||
res->pdx = 15;
|
||||
res->pdy = 15;
|
||||
}
|
||||
levelno = comp->numresolutions - 1 - resno;
|
||||
rx0 = int_ceildivpow2(tcx0, levelno);
|
||||
ry0 = int_ceildivpow2(tcy0, levelno);
|
||||
rx1 = int_ceildivpow2(tcx1, levelno);
|
||||
ry1 = int_ceildivpow2(tcy1, levelno);
|
||||
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
|
||||
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
||||
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
||||
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
||||
res->pw = (px1 - px0) >> res->pdx;
|
||||
res->ph = (py1 - py0) >> res->pdy;
|
||||
}
|
||||
}
|
||||
return pi;
|
||||
|
||||
tccp = &tcp->tccps[0];
|
||||
pi[pino].step_p = 1;
|
||||
pi[pino].step_c = 100 * pi[pino].step_p;
|
||||
pi[pino].step_r = img->numcomps * pi[pino].step_c;
|
||||
pi[pino].step_l = maxres * pi[pino].step_r;
|
||||
|
||||
if (pino == 0) {
|
||||
pi[pino].include =
|
||||
(short int *) malloc(img->numcomps * maxres *
|
||||
tcp->numlayers * 100 * sizeof(short int));
|
||||
for (i = 0; i < img->numcomps * maxres * tcp->numlayers * 100; i++)
|
||||
pi[pino].include[i] = 0;
|
||||
}
|
||||
/* pi[pino].include=(short int*)calloc(img->numcomps*maxres*tcp->numlayers*1000,sizeof(short int)); */
|
||||
else
|
||||
pi[pino].include = pi[pino - 1].include;
|
||||
|
||||
if (tcp->POC == 0) {
|
||||
pi[pino].first = 1;
|
||||
pi[pino].poc.resno0 = 0;
|
||||
pi[pino].poc.compno0 = 0;
|
||||
pi[pino].poc.layno1 = tcp->numlayers;
|
||||
pi[pino].poc.resno1 = maxres;
|
||||
pi[pino].poc.compno1 = img->numcomps;
|
||||
pi[pino].poc.prg = tcp->prg;
|
||||
} else {
|
||||
pi[pino].first = 1;
|
||||
pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
|
||||
pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
|
||||
pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
|
||||
pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
|
||||
pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
|
||||
pi[pino].poc.prg = tcp->pocs[pino].prg;
|
||||
}
|
||||
}
|
||||
return pi;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -149,45 +147,43 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
|
|||
* </summary> */
|
||||
int pi_next_lrcp(pi_iterator_t * pi)
|
||||
{
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
|
||||
if (!pi->first) {
|
||||
if (!pi->first) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
res = &comp->resolutions[pi->resno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
}
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
|
||||
pi->resno++) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
res = &comp->resolutions[pi->resno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
}
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
|
||||
pi->resno++) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
for (pi->precno = 0; pi->precno < res->pw * res->ph;
|
||||
pi->precno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c + pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -197,44 +193,41 @@ int pi_next_lrcp(pi_iterator_t * pi)
|
|||
* </summary> */
|
||||
int pi_next_rlcp(pi_iterator_t * pi)
|
||||
{
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
res = &comp->resolutions[pi->resno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
}
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
res = &comp->resolutions[pi->resno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
}
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
|
||||
pi->resno++) {
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
for (pi->precno = 0; pi->precno < res->pw * res->ph;
|
||||
pi->precno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c + pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -244,96 +237,88 @@ int pi_next_rlcp(pi_iterator_t * pi)
|
|||
* </summary> */
|
||||
int pi_next_rpcl(pi_iterator_t * pi)
|
||||
{
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
goto skip;
|
||||
} else {
|
||||
int compno, resno;
|
||||
pi->first = 0;
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
comp = &pi->comps[compno];
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx *
|
||||
(1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy *
|
||||
(1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
}
|
||||
}
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
goto skip;
|
||||
} else {
|
||||
int compno, resno;
|
||||
pi->first = 0;
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
comp = &pi->comps[compno];
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx *
|
||||
(1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy *
|
||||
(1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
}
|
||||
}
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
|
||||
pi->resno++) {
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
comp = &pi->comps[pi->compno];
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0
|
||||
&& (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0
|
||||
&& (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0,
|
||||
res->
|
||||
pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0,
|
||||
res->
|
||||
pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1;
|
||||
pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
comp = &pi->comps[pi->compno];
|
||||
if (pi->resno >= comp->numresolutions) {
|
||||
continue;
|
||||
}
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -343,96 +328,88 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||
* </summary> */
|
||||
int pi_next_pcrl(pi_iterator_t * pi)
|
||||
{
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
goto skip;
|
||||
} else {
|
||||
int compno, resno;
|
||||
pi->first = 0;
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
comp = &pi->comps[compno];
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx *
|
||||
(1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy *
|
||||
(1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
goto skip;
|
||||
} else {
|
||||
int compno, resno;
|
||||
pi->first = 0;
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
||||
comp = &pi->comps[compno];
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx *
|
||||
(1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy *
|
||||
(1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
for (pi->resno = pi->poc.resno0;
|
||||
pi->resno < int_min(pi->poc.resno1,
|
||||
comp->numresolutions); pi->resno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->compno = pi->poc.compno0;
|
||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
for (pi->resno = pi->poc.resno0;
|
||||
pi->resno < int_min(pi->poc.resno1,
|
||||
comp->numresolutions);
|
||||
pi->resno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0
|
||||
&& (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0
|
||||
&& (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0,
|
||||
res->
|
||||
pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0,
|
||||
res->
|
||||
pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1;
|
||||
pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -442,93 +419,83 @@ int pi_next_pcrl(pi_iterator_t * pi)
|
|||
* </summary> */
|
||||
int pi_next_cprl(pi_iterator_t * pi)
|
||||
{
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
pi_comp_t *comp;
|
||||
pi_resolution_t *res;
|
||||
if (!pi->first) {
|
||||
comp = &pi->comps[pi->compno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->first = 0;
|
||||
}
|
||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
||||
pi->compno++) {
|
||||
int resno;
|
||||
comp = &pi->comps[pi->compno];
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
}
|
||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
||||
pi->compno++) {
|
||||
int resno;
|
||||
comp = &pi->comps[pi->compno];
|
||||
pi->dx = 0;
|
||||
pi->dy = 0;
|
||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
||||
int dx, dy;
|
||||
res = &comp->resolutions[resno];
|
||||
dx = comp->dx *
|
||||
(1 << (res->pdx + comp->numresolutions - 1 - resno));
|
||||
dy = comp->dy *
|
||||
(1 << (res->pdy + comp->numresolutions - 1 - resno));
|
||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
||||
}
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->resno = pi->poc.resno0;
|
||||
pi->resno < int_min(pi->poc.resno1,
|
||||
comp->numresolutions);
|
||||
pi->resno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0
|
||||
&& (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0
|
||||
&& (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0,
|
||||
res->
|
||||
pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0,
|
||||
res->
|
||||
pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1;
|
||||
pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||
for (pi->resno = pi->poc.resno0;
|
||||
pi->resno < int_min(pi->poc.resno1,
|
||||
comp->numresolutions); pi->resno++) {
|
||||
int levelno;
|
||||
int trx0, try0;
|
||||
int rpx, rpy;
|
||||
int prci, prcj;
|
||||
res = &comp->resolutions[pi->resno];
|
||||
levelno = comp->numresolutions - 1 - pi->resno;
|
||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||
rpx = res->pdx + levelno;
|
||||
rpy = res->pdy + levelno;
|
||||
if (!
|
||||
(pi->x % (comp->dx << rpx) == 0
|
||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
if (!
|
||||
(pi->y % (comp->dy << rpy) == 0
|
||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||
continue;
|
||||
}
|
||||
prci =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->x, comp->dx << levelno),
|
||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
||||
prcj =
|
||||
int_floordivpow2(int_ceildiv
|
||||
(pi->y, comp->dy << levelno),
|
||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
||||
pi->precno = prci + prcj * res->pw;
|
||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||
if (!pi->
|
||||
include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p]) {
|
||||
pi->include[pi->layno * pi->step_l +
|
||||
pi->resno * pi->step_r +
|
||||
pi->compno * pi->step_c +
|
||||
pi->precno * pi->step_p] = 1;
|
||||
return 1;
|
||||
}
|
||||
skip:;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* <summary>
|
||||
|
@ -538,17 +505,17 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||
* </summary> */
|
||||
int pi_next(pi_iterator_t * pi)
|
||||
{
|
||||
switch (pi->poc.prg) {
|
||||
case 0:
|
||||
return pi_next_lrcp(pi);
|
||||
case 1:
|
||||
return pi_next_rlcp(pi);
|
||||
case 2:
|
||||
return pi_next_rpcl(pi);
|
||||
case 3:
|
||||
return pi_next_pcrl(pi);
|
||||
case 4:
|
||||
return pi_next_cprl(pi);
|
||||
}
|
||||
return 0;
|
||||
switch (pi->poc.prg) {
|
||||
case 0:
|
||||
return pi_next_lrcp(pi);
|
||||
case 1:
|
||||
return pi_next_rlcp(pi);
|
||||
case 2:
|
||||
return pi_next_rpcl(pi);
|
||||
case 3:
|
||||
return pi_next_pcrl(pi);
|
||||
case 4:
|
||||
return pi_next_cprl(pi);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,26 +31,26 @@
|
|||
#include "tcd.h"
|
||||
|
||||
typedef struct {
|
||||
int pdx, pdy;
|
||||
int pw, ph;
|
||||
int pdx, pdy;
|
||||
int pw, ph;
|
||||
} pi_resolution_t;
|
||||
|
||||
typedef struct {
|
||||
int dx, dy;
|
||||
int numresolutions;
|
||||
pi_resolution_t *resolutions;
|
||||
int dx, dy;
|
||||
int numresolutions;
|
||||
pi_resolution_t *resolutions;
|
||||
} pi_comp_t;
|
||||
|
||||
typedef struct {
|
||||
short int *include; /* precise if the packet has been already used (usefull for progression order change) */
|
||||
int step_l, step_r, step_c, step_p; /* different steps (layer, resolution, component, precinct) to localize the packet in the include vector */
|
||||
int compno, resno, precno, layno; /* component, resolution, precinct and layer that indentify the packet */
|
||||
int first; /* 0 if the first packet */
|
||||
j2k_poc_t poc;
|
||||
int numcomps;
|
||||
pi_comp_t *comps;
|
||||
int tx0, ty0, tx1, ty1;
|
||||
int x, y, dx, dy;
|
||||
short int *include; /* precise if the packet has been already used (usefull for progression order change) */
|
||||
int step_l, step_r, step_c, step_p; /* different steps (layer, resolution, component, precinct) to localize the packet in the include vector */
|
||||
int compno, resno, precno, layno; /* component, resolution, precinct and layer that indentify the packet */
|
||||
int first; /* 0 if the first packet */
|
||||
j2k_poc_t poc;
|
||||
int numcomps;
|
||||
pi_comp_t *comps;
|
||||
int tx0, ty0, tx1, ty1;
|
||||
int x, y, dx, dy;
|
||||
} pi_iterator_t; /* packet iterator */
|
||||
|
||||
/*
|
||||
|
|
|
@ -40,7 +40,7 @@ unsigned char *raw_end; /* pointer to the end of the buffer */
|
|||
*/
|
||||
int raw_numbytes()
|
||||
{
|
||||
return raw_bp - raw_start;
|
||||
return raw_bp - raw_start;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -51,11 +51,11 @@ int raw_numbytes()
|
|||
*/
|
||||
void raw_init_dec(unsigned char *bp, int len)
|
||||
{
|
||||
raw_start = bp;
|
||||
raw_lenmax = len;
|
||||
raw_len = 0;
|
||||
raw_c = 0;
|
||||
raw_ct = 0;
|
||||
raw_start = bp;
|
||||
raw_lenmax = len;
|
||||
raw_len = 0;
|
||||
raw_c = 0;
|
||||
raw_ct = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -63,19 +63,19 @@ void raw_init_dec(unsigned char *bp, int len)
|
|||
*/
|
||||
int raw_decode()
|
||||
{
|
||||
int d;
|
||||
if (raw_ct == 0) {
|
||||
raw_ct = 8;
|
||||
if (raw_len == raw_lenmax)
|
||||
raw_c = 0xff;
|
||||
else {
|
||||
if (raw_c == 0xff)
|
||||
raw_ct = 7;
|
||||
raw_c = *(raw_start + raw_len);
|
||||
raw_len++;
|
||||
}
|
||||
int d;
|
||||
if (raw_ct == 0) {
|
||||
raw_ct = 8;
|
||||
if (raw_len == raw_lenmax)
|
||||
raw_c = 0xff;
|
||||
else {
|
||||
if (raw_c == 0xff)
|
||||
raw_ct = 7;
|
||||
raw_c = *(raw_start + raw_len);
|
||||
raw_len++;
|
||||
}
|
||||
raw_ct--;
|
||||
d = (raw_c >> raw_ct) & 0x01;
|
||||
return d;
|
||||
}
|
||||
raw_ct--;
|
||||
d = (raw_c >> raw_ct) & 0x01;
|
||||
return d;
|
||||
}
|
||||
|
|
1666
libopenjpeg/t1.c
1666
libopenjpeg/t1.c
File diff suppressed because it is too large
Load Diff
922
libopenjpeg/t2.c
922
libopenjpeg/t2.c
File diff suppressed because it is too large
Load Diff
2610
libopenjpeg/tcd.c
2610
libopenjpeg/tcd.c
File diff suppressed because it is too large
Load Diff
|
@ -33,82 +33,82 @@
|
|||
#include "tgt.h"
|
||||
|
||||
typedef struct {
|
||||
int numpasses;
|
||||
int len;
|
||||
unsigned char *data;
|
||||
int maxpasses;
|
||||
int numnewpasses;
|
||||
int newlen;
|
||||
int numpasses;
|
||||
int len;
|
||||
unsigned char *data;
|
||||
int maxpasses;
|
||||
int numnewpasses;
|
||||
int newlen;
|
||||
} tcd_seg_t;
|
||||
|
||||
typedef struct {
|
||||
int rate;
|
||||
double distortiondec;
|
||||
int term, len;
|
||||
int rate;
|
||||
double distortiondec;
|
||||
int term, len;
|
||||
} tcd_pass_t;
|
||||
|
||||
typedef struct {
|
||||
int numpasses; /* Number of passes in the layer */
|
||||
int len; /* len of information */
|
||||
double disto; /* add for index (Cfr. Marcela) */
|
||||
unsigned char *data; /* data */
|
||||
int numpasses; /* Number of passes in the layer */
|
||||
int len; /* len of information */
|
||||
double disto; /* add for index (Cfr. Marcela) */
|
||||
unsigned char *data; /* data */
|
||||
} tcd_layer_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numbps;
|
||||
int numlenbits;
|
||||
int len; /* length */
|
||||
int numpasses; /* number of pass already done for the code-blocks */
|
||||
int numnewpasses; /* number of pass added to the code-blocks */
|
||||
int numsegs; /* number of segments */
|
||||
tcd_seg_t segs[100]; /* segments informations */
|
||||
unsigned char data[8192]; /* Data */
|
||||
int numpassesinlayers; /* number of passes in the layer */
|
||||
tcd_layer_t layers[100]; /* layer information */
|
||||
int totalpasses; /* total number of passes */
|
||||
tcd_pass_t passes[100]; /* information about the passes */
|
||||
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numbps;
|
||||
int numlenbits;
|
||||
int len; /* length */
|
||||
int numpasses; /* number of pass already done for the code-blocks */
|
||||
int numnewpasses; /* number of pass added to the code-blocks */
|
||||
int numsegs; /* number of segments */
|
||||
tcd_seg_t segs[100]; /* segments informations */
|
||||
unsigned char data[8192]; /* Data */
|
||||
int numpassesinlayers; /* number of passes in the layer */
|
||||
tcd_layer_t layers[100]; /* layer information */
|
||||
int totalpasses; /* total number of passes */
|
||||
tcd_pass_t passes[100]; /* information about the passes */
|
||||
} tcd_cblk_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int cw, ch; /* number of precinct in width and heigth */
|
||||
tcd_cblk_t *cblks; /* code-blocks informations */
|
||||
tgt_tree_t *incltree; /* inclusion tree */
|
||||
tgt_tree_t *imsbtree; /* IMSB tree */
|
||||
int x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int cw, ch; /* number of precinct in width and heigth */
|
||||
tcd_cblk_t *cblks; /* code-blocks informations */
|
||||
tgt_tree_t *incltree; /* inclusion tree */
|
||||
tgt_tree_t *imsbtree; /* IMSB tree */
|
||||
} tcd_precinct_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int bandno;
|
||||
tcd_precinct_t *precincts; /* precinct information */
|
||||
int numbps;
|
||||
int stepsize;
|
||||
int x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int bandno;
|
||||
tcd_precinct_t *precincts; /* precinct information */
|
||||
int numbps;
|
||||
int stepsize;
|
||||
} tcd_band_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int pw, ph;
|
||||
int numbands; /* number sub-band for the resolution level */
|
||||
tcd_band_t bands[3]; /* subband information */
|
||||
int x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int pw, ph;
|
||||
int numbands; /* number sub-band for the resolution level */
|
||||
tcd_band_t bands[3]; /* subband information */
|
||||
} tcd_resolution_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numresolutions; /* number of resolutions level */
|
||||
tcd_resolution_t *resolutions; /* resolutions information */
|
||||
int *data; /* data of the component */
|
||||
int x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numresolutions; /* number of resolutions level */
|
||||
tcd_resolution_t *resolutions; /* resolutions information */
|
||||
int *data; /* data of the component */
|
||||
} tcd_tilecomp_t;
|
||||
|
||||
typedef struct {
|
||||
int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numcomps; /* number of components in tile */
|
||||
tcd_tilecomp_t *comps; /* Components information */
|
||||
int x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||
int numcomps; /* number of components in tile */
|
||||
tcd_tilecomp_t *comps; /* Components information */
|
||||
} tcd_tile_t;
|
||||
|
||||
typedef struct {
|
||||
int tw, th; /* number of tiles in width and heigth */
|
||||
tcd_tile_t *tiles; /* Tiles information */
|
||||
int tw, th; /* number of tiles in width and heigth */
|
||||
tcd_tile_t *tiles; /* Tiles information */
|
||||
} tcd_image_t;
|
||||
|
||||
/*
|
||||
|
|
|
@ -34,16 +34,16 @@
|
|||
/* </summary> */
|
||||
void tgt_reset(tgt_tree_t * tree)
|
||||
{
|
||||
int i;
|
||||
/* new */
|
||||
if (!tree || tree == NULL)
|
||||
return;
|
||||
int i;
|
||||
/* new */
|
||||
if (!tree || tree == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; i < tree->numnodes; i++) {
|
||||
tree->nodes[i].value = 999;
|
||||
tree->nodes[i].low = 0;
|
||||
tree->nodes[i].known = 0;
|
||||
}
|
||||
for (i = 0; i < tree->numnodes; i++) {
|
||||
tree->nodes[i].value = 999;
|
||||
tree->nodes[i].low = 0;
|
||||
tree->nodes[i].known = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -51,70 +51,69 @@ void tgt_reset(tgt_tree_t * tree)
|
|||
/* </summary> */
|
||||
tgt_tree_t *tgt_create(int numleafsh, int numleafsv)
|
||||
{
|
||||
int nplh[32];
|
||||
int nplv[32];
|
||||
tgt_node_t *node;
|
||||
tgt_node_t *parentnode;
|
||||
tgt_node_t *parentnode0;
|
||||
tgt_tree_t *tree;
|
||||
int i, j, k;
|
||||
int numlvls;
|
||||
int n;
|
||||
int nplh[32];
|
||||
int nplv[32];
|
||||
tgt_node_t *node;
|
||||
tgt_node_t *parentnode;
|
||||
tgt_node_t *parentnode0;
|
||||
tgt_tree_t *tree;
|
||||
int i, j, k;
|
||||
int numlvls;
|
||||
int n;
|
||||
|
||||
tree = (tgt_tree_t *) malloc(sizeof(tgt_tree_t));
|
||||
tree->numleafsh = numleafsh;
|
||||
tree->numleafsv = numleafsv;
|
||||
tree = (tgt_tree_t *) malloc(sizeof(tgt_tree_t));
|
||||
tree->numleafsh = numleafsh;
|
||||
tree->numleafsv = numleafsv;
|
||||
|
||||
numlvls = 0;
|
||||
nplh[0] = numleafsh;
|
||||
nplv[0] = numleafsv;
|
||||
tree->numnodes = 0;
|
||||
do {
|
||||
n = nplh[numlvls] * nplv[numlvls];
|
||||
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
|
||||
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
|
||||
tree->numnodes += n;
|
||||
++numlvls;
|
||||
} while (n > 1);
|
||||
numlvls = 0;
|
||||
nplh[0] = numleafsh;
|
||||
nplv[0] = numleafsv;
|
||||
tree->numnodes = 0;
|
||||
do {
|
||||
n = nplh[numlvls] * nplv[numlvls];
|
||||
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
|
||||
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
|
||||
tree->numnodes += n;
|
||||
++numlvls;
|
||||
} while (n > 1);
|
||||
|
||||
/* ADD */
|
||||
if (tree->numnodes == 0) {
|
||||
free(tree);
|
||||
return NULL;
|
||||
}
|
||||
/* ADD */
|
||||
if (tree->numnodes == 0) {
|
||||
free(tree);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tree->nodes =
|
||||
(tgt_node_t *) malloc(tree->numnodes * sizeof(tgt_node_t));
|
||||
tree->nodes = (tgt_node_t *) malloc(tree->numnodes * sizeof(tgt_node_t));
|
||||
|
||||
node = tree->nodes;
|
||||
parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv];
|
||||
parentnode0 = parentnode;
|
||||
node = tree->nodes;
|
||||
parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv];
|
||||
parentnode0 = parentnode;
|
||||
|
||||
for (i = 0; i < numlvls - 1; ++i) {
|
||||
for (j = 0; j < nplv[i]; ++j) {
|
||||
k = nplh[i];
|
||||
while (--k >= 0) {
|
||||
node->parent = parentnode;
|
||||
++node;
|
||||
if (--k >= 0) {
|
||||
node->parent = parentnode;
|
||||
++node;
|
||||
}
|
||||
++parentnode;
|
||||
}
|
||||
if ((j & 1) || j == nplv[i] - 1) {
|
||||
parentnode0 = parentnode;
|
||||
} else {
|
||||
parentnode = parentnode0;
|
||||
parentnode0 += nplh[i];
|
||||
}
|
||||
for (i = 0; i < numlvls - 1; ++i) {
|
||||
for (j = 0; j < nplv[i]; ++j) {
|
||||
k = nplh[i];
|
||||
while (--k >= 0) {
|
||||
node->parent = parentnode;
|
||||
++node;
|
||||
if (--k >= 0) {
|
||||
node->parent = parentnode;
|
||||
++node;
|
||||
}
|
||||
++parentnode;
|
||||
}
|
||||
if ((j & 1) || j == nplv[i] - 1) {
|
||||
parentnode0 = parentnode;
|
||||
} else {
|
||||
parentnode = parentnode0;
|
||||
parentnode0 += nplh[i];
|
||||
}
|
||||
}
|
||||
node->parent = 0;
|
||||
}
|
||||
node->parent = 0;
|
||||
|
||||
tgt_reset(tree);
|
||||
tgt_reset(tree);
|
||||
|
||||
return tree;
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -122,8 +121,8 @@ tgt_tree_t *tgt_create(int numleafsh, int numleafsv)
|
|||
/* </summary> */
|
||||
void tgt_destroy(tgt_tree_t * t)
|
||||
{
|
||||
free(t->nodes);
|
||||
free(t);
|
||||
free(t->nodes);
|
||||
free(t);
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -131,12 +130,12 @@ void tgt_destroy(tgt_tree_t * t)
|
|||
/* </summary> */
|
||||
void tgt_setvalue(tgt_tree_t * tree, int leafno, int value)
|
||||
{
|
||||
tgt_node_t *node;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node && node->value > value) {
|
||||
node->value = value;
|
||||
node = node->parent;
|
||||
}
|
||||
tgt_node_t *node;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node && node->value > value) {
|
||||
node->value = value;
|
||||
node = node->parent;
|
||||
}
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -144,44 +143,44 @@ void tgt_setvalue(tgt_tree_t * tree, int leafno, int value)
|
|||
/* </summary> */
|
||||
void tgt_encode(tgt_tree_t * tree, int leafno, int threshold)
|
||||
{
|
||||
tgt_node_t *stk[31];
|
||||
tgt_node_t **stkptr;
|
||||
tgt_node_t *node;
|
||||
int low;
|
||||
tgt_node_t *stk[31];
|
||||
tgt_node_t **stkptr;
|
||||
tgt_node_t *node;
|
||||
int low;
|
||||
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
while (low < threshold) {
|
||||
if (low >= node->value) {
|
||||
if (!node->known) {
|
||||
bio_write(1, 1);
|
||||
node->known = 1;
|
||||
}
|
||||
|
||||
while (low < threshold) {
|
||||
if (low >= node->value) {
|
||||
if (!node->known) {
|
||||
bio_write(1, 1);
|
||||
node->known = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
bio_write(0, 1);
|
||||
++low;
|
||||
}
|
||||
|
||||
node->low = low;
|
||||
if (stkptr == stk)
|
||||
break;
|
||||
node = *--stkptr;
|
||||
break;
|
||||
}
|
||||
bio_write(0, 1);
|
||||
++low;
|
||||
}
|
||||
|
||||
node->low = low;
|
||||
if (stkptr == stk)
|
||||
break;
|
||||
node = *--stkptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* <summary> */
|
||||
|
@ -189,38 +188,38 @@ void tgt_encode(tgt_tree_t * tree, int leafno, int threshold)
|
|||
/* </summary> */
|
||||
int tgt_decode(tgt_tree_t * tree, int leafno, int threshold)
|
||||
{
|
||||
tgt_node_t *stk[31];
|
||||
tgt_node_t **stkptr;
|
||||
tgt_node_t *node;
|
||||
int low;
|
||||
tgt_node_t *stk[31];
|
||||
tgt_node_t **stkptr;
|
||||
tgt_node_t *node;
|
||||
int low;
|
||||
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
stkptr = stk;
|
||||
node = &tree->nodes[leafno];
|
||||
while (node->parent) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low) {
|
||||
node->low = low;
|
||||
} else {
|
||||
low = node->low;
|
||||
}
|
||||
while (low < threshold && low < node->value) {
|
||||
if (bio_read(1)) {
|
||||
node->value = low;
|
||||
} else {
|
||||
++low;
|
||||
}
|
||||
}
|
||||
node->low = low;
|
||||
if (stkptr == stk) {
|
||||
break;
|
||||
}
|
||||
node = *--stkptr;
|
||||
while (low < threshold && low < node->value) {
|
||||
if (bio_read(1)) {
|
||||
node->value = low;
|
||||
} else {
|
||||
++low;
|
||||
}
|
||||
}
|
||||
node->low = low;
|
||||
if (stkptr == stk) {
|
||||
break;
|
||||
}
|
||||
node = *--stkptr;
|
||||
}
|
||||
|
||||
return (node->value < threshold) ? 1 : 0;
|
||||
return (node->value < threshold) ? 1 : 0;
|
||||
}
|
||||
|
|
|
@ -28,17 +28,17 @@
|
|||
#define __TGT_H
|
||||
|
||||
typedef struct tgt_node {
|
||||
struct tgt_node *parent;
|
||||
int value;
|
||||
int low;
|
||||
int known;
|
||||
struct tgt_node *parent;
|
||||
int value;
|
||||
int low;
|
||||
int known;
|
||||
} tgt_node_t;
|
||||
|
||||
typedef struct {
|
||||
int numleafsh;
|
||||
int numleafsv;
|
||||
int numnodes;
|
||||
tgt_node_t *nodes;
|
||||
int numleafsh;
|
||||
int numleafsv;
|
||||
int numnodes;
|
||||
tgt_node_t *nodes;
|
||||
} tgt_tree_t;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue