Reformatage : indent -kr $(find . -name '*.c') $(find . -name '*.h')

This commit is contained in:
Sebastien Lugan 2004-04-29 13:10:05 +00:00
parent 4f83e82a74
commit ec9bd9f6a4
29 changed files with 7411 additions and 6598 deletions

View File

@ -88,7 +88,8 @@ const char *ostr;
++optind;
if (opterr && *ostr != ':')
(void) fprintf(stderr,
"%s: illegal option -- %c\n", __progname, optopt);
"%s: illegal option -- %c\n", __progname,
optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */

View File

@ -66,7 +66,8 @@ typedef struct {
UINT4 biClrImportant; /* Number of important color (0: ALL) */
} BITMAPINFOHEADER_t;
int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsampling_dy, int Dim[2])
int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx,
int subsampling_dy, int Dim[2])
{
FILE *IN;
FILE *Compo0 = NULL, *Compo1 = NULL, *Compo2 = NULL;
@ -81,7 +82,9 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
IN = fopen(filename, "rb");
if (!IN) {
fprintf(stderr, "\033[0;33mFailed to open %s for reading !!\033[0;39m\n", filename);
fprintf(stderr,
"\033[0;33mFailed to open %s for reading !!\033[0;39m\n",
filename);
return 0;
}
@ -171,10 +174,17 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
if (Info_h.biBitCount == 24) {
img->x0 = Dim[0];
img->y0 = Dim[1];
img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
img->x1 =
!Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
1) *
subsampling_dx + 1;
img->y1 =
!Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
1) *
subsampling_dy + 1;
img->numcomps = 3;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
img->comps[i].bpp = 8;
@ -184,15 +194,18 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
}
Compo0 = fopen("Compo0", "wb");
if (!Compo0) {
fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
Compo1 = fopen("Compo1", "wb");
if (!Compo1) {
fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
}
Compo2 = fopen("Compo2", "wb");
if (!Compo2) {
fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
}
/* Place the cursor at the beginning of the image information */
@ -207,20 +220,19 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
PAD = (3 * W) % 4 ? 4 - (3 * W) % 4 : 0;
RGB = (unsigned char *) malloc((3 * W + PAD) * H * sizeof(unsigned char));
RGB =
(unsigned char *) malloc((3 * W + PAD) * H *
sizeof(unsigned char));
fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN);
for (i = 0; i < (3 * W + PAD) * H; i++)
{
for (i = 0; i < (3 * W + PAD) * H; i++) {
unsigned char elmt;
int Wp = 3 * W + PAD;
elmt = RGB[(H - (i/Wp + 1)) * Wp + i % Wp];
if ((i % Wp) < (3 * W))
{
switch (type)
{
elmt = RGB[(H - (i / Wp + 1)) * Wp + i % Wp];
if ((i % Wp) < (3 * W)) {
switch (type) {
case 0:
fprintf(Compo2, "%c", elmt);
type = 1;
@ -244,19 +256,29 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) {
img->x0 = Dim[0];
img->y0 = Dim[1];
img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
img->x1 =
!Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
1) *
subsampling_dx + 1;
img->y1 =
!Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
1) *
subsampling_dy + 1;
table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_R =
(unsigned char *) malloc(256 * sizeof(unsigned char));
table_G =
(unsigned char *) malloc(256 * sizeof(unsigned char));
table_B =
(unsigned char *) malloc(256 * sizeof(unsigned char));
for (i = 0; i < Info_h.biClrUsed; i++) {
table_B[i] = getc(IN);
table_G[i] = getc(IN);
table_R[i] = getc(IN);
getc(IN);
if (table_R[i] != table_G[i] && table_R[i] != table_B[i] && table_G[i] != table_B[i])
if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
&& table_G[i] != table_B[i])
gray_scale = 0;
}
@ -274,7 +296,9 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
fread(RGB, sizeof(unsigned char), W * H, IN);
if (gray_scale) {
img->numcomps = 1;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps *
sizeof(j2k_comp_t));
img->comps[0].prec = 8;
img->comps[0].bpp = 8;
img->comps[0].sgnd = 0;
@ -282,16 +306,23 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
img->comps[0].dy = subsampling_dy;
Compo0 = fopen("Compo0", "wb");
if (!Compo0) {
fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
for (i = 0; i < W * H; i++) {
if ((i % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2))
fprintf(Compo0, "%c", table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
if ((i % W < W - 1 && Info_h.biWidth % 2)
|| !(Info_h.biWidth % 2))
fprintf(Compo0, "%c",
table_R[RGB
[W * H - ((i) / (W) + 1) * W +
(i) % (W)]]);
}
fclose(Compo0);
} else {
img->numcomps = 3;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps *
sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
img->comps[i].bpp = 8;
@ -302,22 +333,35 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
Compo0 = fopen("Compo0", "wb");
if (!Compo0) {
fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
Compo1 = fopen("Compo1", "wb");
if (!Compo1) {
fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
}
Compo2 = fopen("Compo2", "wb");
if (!Compo2) {
fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
}
for (i = 0; i < W * H; i++) {
if ((i % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2)) {
fprintf(Compo0, "%c", table_R[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
fprintf(Compo1, "%c", table_G[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
fprintf(Compo2, "%c", table_B[RGB[W * H - ((i) / (W) + 1) * W + (i) % (W)]]);
if ((i % W < W - 1 && Info_h.biWidth % 2)
|| !(Info_h.biWidth % 2)) {
fprintf(Compo0, "%c",
table_R[RGB
[W * H - ((i) / (W) + 1) * W +
(i) % (W)]]);
fprintf(Compo1, "%c",
table_G[RGB
[W * H - ((i) / (W) + 1) * W +
(i) % (W)]]);
fprintf(Compo2, "%c",
table_B[RGB
[W * H - ((i) / (W) + 1) * W +
(i) % (W)]]);
}
}
@ -330,19 +374,29 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
} else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) {
img->x0 = Dim[0];
img->y0 = Dim[1];
img->x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w - 1) * subsampling_dx + 1;
img->y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h - 1) * subsampling_dy + 1;
img->x1 =
!Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
1) *
subsampling_dx + 1;
img->y1 =
!Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
1) *
subsampling_dy + 1;
table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_R =
(unsigned char *) malloc(256 * sizeof(unsigned char));
table_G =
(unsigned char *) malloc(256 * sizeof(unsigned char));
table_B =
(unsigned char *) malloc(256 * sizeof(unsigned char));
for (i = 0; i < Info_h.biClrUsed; i++) {
table_B[i] = getc(IN);
table_G[i] = getc(IN);
table_R[i] = getc(IN);
getc(IN);
if (table_R[i] != table_G[i] && table_R[i] != table_B[i] && table_G[i] != table_B[i])
if (table_R[i] != table_G[i] && table_R[i] != table_B[i]
&& table_G[i] != table_B[i])
gray_scale = 0;
}
@ -360,11 +414,14 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
img->comps[0].dy = subsampling_dy;
Compo0 = fopen("Compo0", "wb");
if (!Compo0) {
fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
} else {
img->numcomps = 3;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps *
sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
img->comps[i].bpp = 8;
@ -374,19 +431,24 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
}
Compo0 = fopen("Compo0", "wb");
if (!Compo0) {
fprintf(stderr, "\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo0 for writing !\033[0;39m\n");
}
Compo1 = fopen("Compo1", "wb");
if (!Compo1) {
fprintf(stderr, "\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo1 for writing !\033[0;39m\n");
}
Compo2 = fopen("Compo2", "wb");
if (!Compo2) {
fprintf(stderr, "\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
fprintf(stderr,
"\033[0;33mFailed to open Compo2 for writing !\033[0;39m\n");
}
}
RGB = (unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight * sizeof(unsigned char));
RGB =
(unsigned char *) malloc(Info_h.biWidth * Info_h.biHeight *
sizeof(unsigned char));
while (not_end_file) {
v = getc(IN);
@ -425,14 +487,26 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
if (gray_scale) {
for (line = 0; line < Info_h.biHeight; line++)
for (col = 0; col < Info_h.biWidth; col++)
fprintf(Compo0, "%c", table_R[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
fprintf(Compo0, "%c",
table_R[(int)
RGB[(Info_h.biHeight - line -
1) * Info_h.biWidth + col]]);
fclose(Compo0);
} else {
for (line = 0; line < Info_h.biHeight; line++)
for (col = 0; col < Info_h.biWidth; col++) {
fprintf(Compo0, "%c", table_R[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
fprintf(Compo1, "%c", table_G[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
fprintf(Compo2, "%c", table_B[(int)RGB[(Info_h.biHeight - line - 1) * Info_h.biWidth + col]]);
fprintf(Compo0, "%c",
table_R[(int)
RGB[(Info_h.biHeight - line -
1) * Info_h.biWidth + col]]);
fprintf(Compo1, "%c",
table_G[(int)
RGB[(Info_h.biHeight - line -
1) * Info_h.biWidth + col]]);
fprintf(Compo2, "%c",
table_B[(int)
RGB[(Info_h.biHeight - line -
1) * Info_h.biWidth + col]]);
}
fclose(Compo0);
fclose(Compo1);
@ -440,7 +514,8 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx, int subsam
}
free(RGB);
} else
fprintf(stderr,"Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
fprintf(stderr,
"Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n",
Info_h.biBitCount);
fclose(IN);
@ -512,8 +587,8 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
fprintf(stderr, "Failed to open %s for reading !\n", str);
return 0;
}
if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5)
{
if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) ==
5) {
fgetc(f);
if (!strcmp(endian, "ML"))
bigendian = 1;
@ -545,8 +620,7 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
comp->dy = subsampling_dy;
bandno = 1;
Y1 =
cp.ty0 + bandno * cp.tdy <
Y1 = cp.ty0 + bandno * cp.tdy <
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
Y1 -= img->y0;
@ -563,10 +637,10 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
sprintf(tmp, "bandtile%d", bandno);
src = fopen(tmp, "wb");
if (!src) {
fprintf(stderr, "failed to open %s for writing !\n", tmp);
fprintf(stderr,
"failed to open %s for writing !\n", tmp);
}
Y1 =
cp.ty0 + bandno * cp.tdy <
Y1 = cp.ty0 + bandno * cp.tdy <
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
Y1 -= img->y0;
}
@ -740,7 +814,8 @@ int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
1) *
subsampling_dy + 1;
img->numcomps = 3;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
img->comps[i].bpp = 8;
@ -802,7 +877,8 @@ int pnmtoimage(char *filename, j2k_image_t * img, int subsampling_dx,
1) *
subsampling_dy + 1;
img->numcomps = 3;
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
img->comps =
(j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < img->numcomps; i++) {
img->comps[i].prec = 8;
img->comps[i].bpp = 8;

View File

@ -88,26 +88,19 @@ void help_display()
printf
("-i : source file (-i source.pnm also *.pgm, *.ppm) required\n");
printf("\n");
printf
("-o : destination file (-o dest.j2k) required\n");
printf("-o : destination file (-o dest.j2k) required\n");
printf("\n");
printf
("-help : Display the help information optional\n ");
printf("-help : Display the help information optional\n ");
printf("\n");
printf
("-r : different rates (-r 20,10,5) optional\n ");
printf("-r : different rates (-r 20,10,5) optional\n ");
printf("\n");
printf
("-n : Number of resolution (-n 3) optional\n");
printf("-n : Number of resolution (-n 3) optional\n");
printf("\n");
printf
("-b : size of code block (-b 32,32) optional\n");
printf("-b : size of code block (-b 32,32) optional\n");
printf("\n");
printf
("-c : size of precinct (-c 128,128) optional\n");
printf("-c : size of precinct (-c 128,128) optional\n");
printf("\n");
printf
("-t : size of tile (-t 512,512) optional\n");
printf("-t : size of tile (-t 512,512) optional\n");
printf("\n");
printf
("-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] optional\n");
@ -150,10 +143,8 @@ void help_display()
printf("\n");
printf("* subsampling bigger than 2 can produce error\n");
printf("\n");
printf
("The index file respect the structure below :\n");
printf
("---------------------------------------------\n");
printf("The index file respect the structure below :\n");
printf("---------------------------------------------\n");
printf("\n");
printf("Image_height Image_width\n");
printf("progression order\n");
@ -175,31 +166,27 @@ void help_display()
int give_progression(char progression[4])
{
if (progression[0] == 'L' && progression[1] == 'R' && progression[2] == 'C' && progression[3] == 'P')
{
if (progression[0] == 'L' && progression[1] == 'R'
&& progression[2] == 'C' && progression[3] == 'P') {
return 0;
} else
{
if (progression[0] == 'R' && progression[1] == 'L' && progression[2] == 'C' && progression[3] == 'P')
{
} else {
if (progression[0] == 'R' && progression[1] == 'L'
&& progression[2] == 'C' && progression[3] == 'P') {
return 1;
} else
{
if (progression[0] == 'R' && progression[1] == 'P' && progression[2] == 'C' && progression[3] == 'L')
{
} else {
if (progression[0] == 'R' && progression[1] == 'P'
&& progression[2] == 'C' && progression[3] == 'L') {
return 2;
} else
{
if (progression[0] == 'P' && progression[1] == 'C' && progression[2] == 'R' && progression[3] == 'L')
{
} else {
if (progression[0] == 'P' && progression[1] == 'C'
&& progression[2] == 'R' && progression[3] == 'L') {
return 3;
} else
{
if (progression[0] == 'C' && progression[1] == 'P' && progression[2] == 'R' && progression[3] == 'L')
{
} else {
if (progression[0] == 'C' && progression[1] == 'P'
&& progression[2] == 'R'
&& progression[3] == 'L') {
return 4;
} else
{
} else {
return -1;
}
}
@ -244,14 +231,18 @@ void calc_explicit_stepsizes(j2k_tccp_t * tccp, int prec)
resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
orient = bandno == 0 ? 0 : (bandno - 1) % 3 + 1;
level = tccp->numresolutions - 1 - resno;
gain = tccp->qmfbid == 0 ? 0 : (orient == 0 ? 0 : (orient == 1 || orient == 2 ? 1 : 2));
gain =
tccp->qmfbid == 0 ? 0 : (orient ==
0 ? 0 : (orient == 1
|| orient == 2 ? 1 : 2));
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
stepsize = 1.0;
} else {
double norm = dwt_norms_97[orient][level];
stepsize = (1 << (gain + 1)) / norm;
}
encode_stepsize((int) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno].expn,
encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
&tccp->stepsizes[bandno].expn,
&tccp->stepsizes[bandno].mant);
}
}
@ -317,7 +308,8 @@ int main(int argc, char **argv)
while (1) {
int c =
getopt(argc, argv, "i:o:r:q:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I");
getopt(argc, argv,
"i:o:r:q:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I");
if (c == -1)
break;
switch (c) {
@ -334,23 +326,33 @@ int main(int argc, char **argv)
s--;
S1 = *s;
if ((S1 == 'p' && S2 == 'g' && S3 == 'x') || (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
|| (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
cp.image_type = 0;
break;
}
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')) {
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')) {
cp.image_type = 1;
break;
}
if ((S1 == 'b' && S2 == 'm' && S3 == 'p') || (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
|| (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
cp.image_type = 2;
break;
}
fprintf(stderr, "!! Unrecognized format for infile : %c%c%c [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",S1,S2,S3);
fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
S1, S2, S3);
return 1;
break;
/* ----------------------------------------------------- */
@ -358,9 +360,10 @@ int main(int argc, char **argv)
outfile = optarg;
break;
/* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion*/
case 'r': /* rates rates/distorsion */
s = optarg;
while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers]) == 1) {
while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers])
== 1) {
tcp_init->numlayers++;
while (*s && *s != ',') {
s++;
@ -374,31 +377,40 @@ int main(int argc, char **argv)
break;
/* ----------------------------------------------------- */
case 'q': /* rates fixed */
s=optarg;
sscanf(s, "%d",&tcp_init->numlayers);
s = optarg;
sscanf(s, "%d", &tcp_init->numlayers);
s++;
if (tcp_init->numlayers > 9)
s++;
cp.matrice =
(int *) malloc(tcp_init->numlayers * NumResolution * 3 *
sizeof(int));
s = s + 2;
for (i = 0; i < tcp_init->numlayers; i++) {
tcp_init->rates[i] = 1;
sscanf(s, "%d,", &cp.matrice[i * NumResolution * 3]);
s += 2;
if (cp.matrice[i * NumResolution * 3] > 9)
s++;
cp.matrice[i * NumResolution * 3 + 1] = 0;
cp.matrice[i * NumResolution * 3 + 2] = 0;
for (j = 1; j < NumResolution; j++) {
sscanf(s, "%d,%d,%d",
&cp.matrice[i * NumResolution * 3 + j * 3 + 0],
&cp.matrice[i * NumResolution * 3 + j * 3 + 1],
&cp.matrice[i * NumResolution * 3 + j * 3 + 2]);
s += 6;
if (cp.matrice[i * NumResolution * 3 + j * 3] > 9)
s++;
if (cp.matrice[i * NumResolution * 3 + j * 3 + 1] > 9)
s++;
if (cp.matrice[i * NumResolution * 3 + j * 3 + 2] > 9)
s++;
if (tcp_init->numlayers>9) s++;
cp.matrice=(int*)malloc(tcp_init->numlayers*NumResolution*3*sizeof(int));
s=s+2;
for(i=0;i<tcp_init->numlayers;i++)
{
tcp_init->rates[i]=1;
sscanf(s, "%d,", &cp.matrice[i*NumResolution*3]);
s+=2;
if (cp.matrice[i*NumResolution*3]>9) s++;
cp.matrice[i*NumResolution*3+1]=0;
cp.matrice[i*NumResolution*3+2]=0;
for (j=1;j<NumResolution;j++)
{
sscanf(s, "%d,%d,%d", &cp.matrice[i*NumResolution*3+j*3+0],&cp.matrice[i*NumResolution*3+j*3+1],&cp.matrice[i*NumResolution*3+j*3+2]);
s+=6;
if (cp.matrice[i*NumResolution*3+j*3]>9) s++;
if (cp.matrice[i*NumResolution*3+j*3+1]>9) s++;
if (cp.matrice[i*NumResolution*3+j*3+2]>9) s++;
}
if (i<tcp_init->numlayers-1) s++;
if (i < tcp_init->numlayers - 1)
s++;
}
cp.fixed_alloc=1;
cp.fixed_alloc = 1;
break;
/* ----------------------------------------------------- */
case 't': /* tiles */
@ -418,8 +430,10 @@ int main(int argc, char **argv)
case 'b': /* code-block dimension */
sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
fprintf(stderr,"!! Size of code_block error (option -b) !!\n\nRestriction :\n * width*height<=4096\n * 4<=width,height<= 1024\n\n");
|| cblockw_init < 4 || cblockh_init > 1024
|| cblockh_init < 4) {
fprintf(stderr,
"!! Size of code_block error (option -b) !!\n\nRestriction :\n * width*height<=4096\n * 4<=width,height<= 1024\n\n");
return 1;
}
break;
@ -431,29 +445,32 @@ int main(int argc, char **argv)
/* ----------------------------------------------------- */
case 'p': /* progression order */
s = optarg;
for (i=0; i<4; i++)
{
for (i = 0; i < 4; i++) {
progression[i] = *s;
s++;
}
Prog_order = give_progression(progression);
if (Prog_order == -1) {
fprintf(stderr,"Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
fprintf(stderr,
"Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
return 1;
}
break;
/* ----------------------------------------------------- */
case 's': /* subsampling factor */
if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy) != 2) {
fprintf(stderr,"'-s' sub-sampling argument error ! [-s dx,dy]\n");
if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy)
!= 2) {
fprintf(stderr,
"'-s' sub-sampling argument error ! [-s dx,dy]\n");
return 1;
}
break;
/* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */
if (sscanf(optarg, "%d,%d", &Dim[0], &Dim[1]) != 2) {
fprintf(stderr,"-d 'coordonnate of the reference grid' argument error !! [-d x0,y0]\n");
fprintf(stderr,
"-d 'coordonnate of the reference grid' argument error !! [-d x0,y0]\n");
return 1;
}
break;
@ -472,8 +489,10 @@ int main(int argc, char **argv)
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
POC[numpocs].prg = give_progression(POC[numpocs].progorder);
&POC[numpocs].compno1,
POC[numpocs].progorder) == 7) {
POC[numpocs].prg =
give_progression(POC[numpocs].progorder);
/* POC[numpocs].tile; */
numpocs++;
while (*s && *s != '/') {
@ -504,15 +523,18 @@ int main(int argc, char **argv)
break;
/* ------------------------------------------------------ */
case 'R': /* ROI */
if (sscanf(optarg, "OI:c=%d,U=%d", &ROI_compno, &ROI_shift) != 2) {
fprintf(stderr,"ROI error !! [-ROI:c='compno',U='shift']\n");
if (sscanf(optarg, "OI:c=%d,U=%d", &ROI_compno, &ROI_shift) !=
2) {
fprintf(stderr,
"ROI error !! [-ROI:c='compno',U='shift']\n");
return 1;
}
break;
/* ------------------------------------------------------ */
case 'T': /* Tile offset */
if (sscanf(optarg, "%d,%d", &TX0, &TY0) != 2) {
fprintf(stderr,"-T 'tile offset' argument error !! [-T X0,Y0]");
fprintf(stderr,
"-T 'tile offset' argument error !! [-T X0,Y0]");
return 1;
}
break;
@ -536,12 +558,14 @@ int main(int argc, char **argv)
/* Error messages */
/* -------------- */
if (!infile || !outfile) {
fprintf(stderr, "usage: image_to_j2k -i image-file -o j2k-file (+ options)\n");
fprintf(stderr,
"usage: image_to_j2k -i image-file -o j2k-file (+ options)\n");
return 1;
}
if (cp.disto_alloc & cp.fixed_alloc) {
fprintf(stderr, "Error: option -r and -q can not be used together !!\n");
fprintf(stderr,
"Error: option -r and -q can not be used together !!\n");
return 1;
}
@ -553,14 +577,16 @@ int main(int argc, char **argv)
}
if (TX0 > Dim[0] || TY0 > Dim[1]) {
fprintf(stderr, "Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
fprintf(stderr,
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
TX0, Dim[0], TY0, Dim[1]);
return 1;
}
for (i = 0; i < numpocs; i++) {
if (POC[i].prg == -1) {
fprintf(stderr, "Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",
fprintf(stderr,
"Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",
i + 1);
}
}
@ -568,12 +594,16 @@ int main(int argc, char **argv)
switch (cp.image_type) {
case 0:
if (Tile_arg) {
if (!pgxtoimage(infile, &img, cp.tdy, subsampling_dx, subsampling_dy, Dim, cp)) {
if (!pgxtoimage
(infile, &img, cp.tdy, subsampling_dx, subsampling_dy, Dim,
cp)) {
fprintf(stderr, "not a pgx file\n");
return 1;
}
} else {
if (!pgxtoimage(infile, &img, -1, subsampling_dx, subsampling_dy, Dim, cp)) {
if (!pgxtoimage
(infile, &img, -1, subsampling_dx, subsampling_dy, Dim,
cp)) {
fprintf(stderr, " not a pgx file\n");
return 1;
}
@ -615,10 +645,10 @@ int main(int argc, char **argv)
}
/* Initialization for PPM marker */
cp.ppm=0;
cp.ppm_data=NULL;
cp.ppm_previous=0;
cp.ppm_store=0;
cp.ppm = 0;
cp.ppm_data = NULL;
cp.ppm_previous = 0;
cp.ppm_store = 0;
/* Init the mutiple tiles */
/* ---------------------- */
@ -634,14 +664,14 @@ int main(int argc, char **argv)
tcp->prg = Prog_order;
tcp->mct = img.numcomps == 3 ? 1 : 0;
tcp->ppt = 0;
tcp->ppt_data=NULL;
tcp->ppt_store=0;
tcp->ppt_data = NULL;
tcp->ppt_store = 0;
numpocs_tile = 0;
tcp->POC=0;
tcp->POC = 0;
if (numpocs) {
/* intialisation of POC */
tcp->POC=1;
tcp->POC = 1;
for (i = 0; i < numpocs; i++) {
if (tileno == POC[i].tile - 1 || POC[i].tile == -1) {
tcp_poc = &tcp->pocs[numpocs_tile];
@ -657,7 +687,8 @@ int main(int argc, char **argv)
}
}
tcp->numpocs = numpocs_tile;
tcp->tccps = (j2k_tccp_t *) malloc(img.numcomps * sizeof(j2k_tccp_t));
tcp->tccps =
(j2k_tccp_t *) malloc(img.numcomps * sizeof(j2k_tccp_t));
for (i = 0; i < img.numcomps; i++) {
tccp = &tcp->tccps[i];
@ -667,7 +698,8 @@ int main(int argc, char **argv)
tccp->cblkh = int_floorlog2(cblockh_init);
tccp->cblksty = mode;
tccp->qmfbid = ir ? 0 : 1;
tccp->qntsty = ir ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
tccp->qntsty =
ir ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
tccp->numgbits = 2;
if (i == ROI_compno)
tccp->roishift = ROI_shift;
@ -677,19 +709,23 @@ int main(int argc, char **argv)
for (j = 0; j < tccp->numresolutions; j++) {
int size_prcw, size_prch;
size_prcw = prcw_init >> (tccp->numresolutions - j - 1);
size_prch = prch_init >> (tccp->numresolutions - j - 1);
size_prcw =
prcw_init >> (tccp->numresolutions - j - 1);
size_prch =
prch_init >> (tccp->numresolutions - j - 1);
if (size_prcw < 1) {
tccp->prcw[j] = 1;
} else {
tccp->prcw[j] =
int_floorlog2(prcw_init >> (tccp->numresolutions - j - 1));
int_floorlog2(prcw_init >>
(tccp->numresolutions - j - 1));
}
if (size_prch < 1) {
tccp->prch[j] = 1;
} else {
tccp->prch[j] =
int_floorlog2(prch_init >> (tccp->numresolutions - j - 1));
int_floorlog2(prch_init >>
(tccp->numresolutions - j - 1));
}
}
} else {

View File

@ -52,7 +52,9 @@ int main(int argc, char **argv)
int adjust;
if (argc < 3) {
fprintf(stderr, "usage: %s j2k-file image-file -reduce n (<- optional)\n", argv[0]);
fprintf(stderr,
"usage: %s j2k-file image-file -reduce n (<- optional)\n",
argv[0]);
return 1;
}
@ -68,15 +70,15 @@ int main(int argc, char **argv)
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]);
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);
sscanf(argv[4], "%d", &option.reduce_value);
}
while (*dest) {
@ -89,22 +91,29 @@ int main(int argc, char **argv)
dest--;
S1 = *dest;
if ((S1 == 'p' && S2 == 'g' && S3 == 'x') || (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
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')) {
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')) {
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);
fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.pnm, *.pgm, *.ppm, *.pgx or *.bmp] !!\n\n",
S1, S2, S3);
return 1;
}
@ -115,7 +124,7 @@ int main(int argc, char **argv)
fread(src, 1, len, f);
fclose(f);
src_name=argv[1];
src_name = argv[1];
while (*src_name) {
src_name++;
}
@ -126,25 +135,21 @@ int main(int argc, char **argv)
src_name--;
S1 = *src_name;
if (S1 == 'j' && S2 == '2' && S3 == 'k')
{
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')
{
} 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;
}
}
else
{
fprintf(stderr,"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k or *.jpt]!! \n",S1,S2,S3);
} else {
fprintf(stderr,
"j2k_to_image : Unknown format image *.%c%c%c [only *.j2k or *.jpt]!! \n",
S1, S2, S3);
return 1;
}
}
@ -158,97 +163,120 @@ int main(int argc, char **argv)
/* / / */
/* ---------------------------- / */
switch (image_type)
{
case 1: /* PNM PGM 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)
{
&& 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);
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);
hrr = int_ceildivpow2(img->comps[0].h, img->comps[0].factor);
max = img->comps[0].prec > 8 ? 255 : (1 << img->comps[0].prec) - 1;
max =
img->comps[0].prec >
8 ? 255 : (1 << img->comps[0].prec) - 1;
img->comps[0].x0 = 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);
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);
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++)
{
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 += (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 += (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 += (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++)
{
} else {
for (compno = 0; compno < img->numcomps; compno++) {
char name[256];
if (img->numcomps > 1) {
sprintf(name, "%d.%s", compno, argv[2]);
} else
{
} 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);
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),
hrr =
int_ceildivpow2(img->comps[compno].h,
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++)
{
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 += (img->comps[compno].
sgnd ? 1 << (img->comps[compno].prec - 1) : 0);
l = l >> adjust;
fprintf(f, "%c", l);
}
fclose(f);
}
}
break ;
break;
/* ------------------------ / */
/* / / */
@ -256,11 +284,10 @@ int main(int argc, char **argv)
/* / / */
/* /----------------------- / */
case 0: /* PGX */
for (compno = 0; compno < img->numcomps; compno++)
{
for (compno = 0; compno < img->numcomps; compno++) {
j2k_comp_t *comp = &img->comps[compno];
char name[256];
if (img->numcomps>1)
if (img->numcomps > 1)
sprintf(name, "%d_%s", compno, argv[2]);
else
sprintf(name, "%s", argv[2]);
@ -269,33 +296,32 @@ int main(int argc, char **argv)
// 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);
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);
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++)
{
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)
{
if (comp->prec <= 8) {
char c = (char) v;
fwrite(&c, 1, 1, f);
} else if (comp->prec <= 16)
{
} else if (comp->prec <= 16) {
short s = (short) v;
fwrite(&s, 2, 1, f);
} else
{
} else {
fwrite(&v, 4, 1, f);
}
}
fclose(f);
}
break ;
break;
/* ------------------------ / */
/* / / */
@ -309,8 +335,7 @@ int main(int argc, char **argv)
&& 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)
{
&& img->comps[1].prec == img->comps[2].prec) {
/* -->> -->> -->> -->>
24 bits color
@ -321,65 +346,86 @@ int main(int argc, char **argv)
// 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);
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);
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);
(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%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);
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++)
{
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)];
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)];
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)];
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 */
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 */
} else { /* Gray-scale */
/* -->> -->> -->> -->>
@ -390,66 +436,85 @@ int main(int argc, char **argv)
// 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);
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);
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);
(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%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);
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++)
{
for (i = 0; i < 256; i++) {
fprintf(f, "%c%c%c%c", i, i, i, 0);
}
for (i = 0; i < wr * hr; i++)
{
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)]);
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); */
if ((i + 1) % wr == 0) {
for (pad = wr % 4 ? 4 - wr % 4 : 0; pad > 0; pad--) /* ADD */
fprintf(f, "%c", 0);
}
}
break;
default :
default:
break;
}

View File

@ -216,8 +216,12 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
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;
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;
@ -234,7 +238,8 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
/* <summary> */
/* Inverse 5-3 wavelet tranform in 2-D. */
/* </summary> */
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop)
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 */
@ -248,8 +253,12 @@ void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop)
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;
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;
@ -302,9 +311,9 @@ void dwt_encode_1_real(int *a, int n, int x, int res, int cas)
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*/
S(i) = fix_mul(S(i), 5038); /*5038 */
for (i = 0; i < sn; i++)
D(i) = fix_mul(D(i), 6659); /*6660*/
D(i) = fix_mul(D(i), 6659); /*6660 */
}
} else {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
@ -317,9 +326,9 @@ void dwt_encode_1_real(int *a, int n, int x, int res, int cas)
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*/
D(i) = fix_mul(D(i), 5038); /*5038 */
for (i = 0; i < sn; i++)
S(i) = fix_mul(S(i), 6659); /*6660*/
S(i) = fix_mul(S(i), 6659); /*6660 */
}
}
dwt_deinterleave(a, n, x, res, cas);
@ -339,7 +348,7 @@ void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
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*/
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++)
@ -354,7 +363,7 @@ void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
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*/
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++)
@ -384,8 +393,12 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
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;
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;
@ -400,7 +413,8 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
/* <summary> */
/* Inverse 9-7 wavelet transform in 2-D. */
/* </summary> */
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop)
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 */
@ -414,8 +428,12 @@ void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int st
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;
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;

View File

@ -51,7 +51,8 @@ void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
* row_tilec : tile component information (previous tile on the same row)
* col_tilec : tile component information (previous tile on the same column)
*/
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop);
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
int stop);
/*
* Get the gain of a subband for the reversible DWT
@ -82,7 +83,8 @@ void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
* h: height of the component
* l: number of decomposition levels in the DWT
*/
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l, int stop);
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
int stop);
/*
* Get the gain of a subband for the irreversible DWT
* orient: number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)

View File

@ -143,7 +143,8 @@ void j2k_dump_cp(j2k_image_t * img, j2k_cp_t * cp)
j2k_tccp_t *tccp = &tcp->tccps[compno];
fprintf(stderr, " comp %d {\n", compno);
fprintf(stderr, " csty=%x\n", tccp->csty);
fprintf(stderr, " numresolutions=%d\n", tccp->numresolutions);
fprintf(stderr, " numresolutions=%d\n",
tccp->numresolutions);
fprintf(stderr, " cblkw=%d\n", tccp->cblkw);
fprintf(stderr, " cblkh=%d\n", tccp->cblkh);
fprintf(stderr, " cblksty=%x\n", tccp->cblksty);
@ -236,7 +237,8 @@ void j2k_read_siz()
j2k_cp->ty0 = cio_read(4); /* YT0siz */
j2k_img->numcomps = cio_read(2); /* Csiz */
j2k_img->comps = (j2k_comp_t *) malloc(j2k_img->numcomps * sizeof(j2k_comp_t));
j2k_img->comps =
(j2k_comp_t *) malloc(j2k_img->numcomps * sizeof(j2k_comp_t));
for (i = 0; i < j2k_img->numcomps; i++) {
int tmp, w, h;
tmp = cio_read(1); /* Ssiz_i */
@ -252,15 +254,15 @@ void j2k_read_siz()
j2k_cp->tw = int_ceildiv(j2k_img->x1 - j2k_cp->tx0, j2k_cp->tdx);
j2k_cp->th = int_ceildiv(j2k_img->y1 - j2k_cp->ty0, j2k_cp->tdy);
j2k_cp->tcps = (j2k_tcp_t *) calloc(j2k_cp->tw * j2k_cp->th, sizeof(j2k_tcp_t));
j2k_cp->tileno = (int*)calloc(j2k_cp->tw * j2k_cp->th, sizeof(int));
j2k_cp->tcps =
(j2k_tcp_t *) calloc(j2k_cp->tw * j2k_cp->th, sizeof(j2k_tcp_t));
j2k_cp->tileno = (int *) calloc(j2k_cp->tw * j2k_cp->th, sizeof(int));
j2k_cp->tileno_size = 0;
for (i=0; i<j2k_cp->tw * j2k_cp->th; i++)
{
j2k_cp->tcps[i].POC=0;
j2k_cp->tcps[i].numpocs=0;
j2k_cp->tcps[i].first=1;
for (i = 0; i < j2k_cp->tw * j2k_cp->th; i++) {
j2k_cp->tcps[i].POC = 0;
j2k_cp->tcps[i].numpocs = 0;
j2k_cp->tcps[i].first = 1;
}
/* Initialization for PPM marker */
@ -269,11 +271,14 @@ void j2k_read_siz()
j2k_cp->ppm_previous = 0;
j2k_cp->ppm_store = 0;
j2k_default_tcp.tccps = (j2k_tccp_t *) calloc(sizeof(j2k_tccp_t), j2k_img->numcomps);
j2k_default_tcp.tccps =
(j2k_tccp_t *) calloc(sizeof(j2k_tccp_t), j2k_img->numcomps);
for (i = 0; i < j2k_cp->tw * j2k_cp->th; i++) {
j2k_cp->tcps[i].tccps = (j2k_tccp_t *) calloc(sizeof(j2k_tccp_t), j2k_img->numcomps);
j2k_cp->tcps[i].tccps =
(j2k_tccp_t *) calloc(sizeof(j2k_tccp_t), j2k_img->numcomps);
}
j2k_tile_data = (unsigned char **) calloc(j2k_cp->tw * j2k_cp->th, sizeof(char *));
j2k_tile_data =
(unsigned char **) calloc(j2k_cp->tw * j2k_cp->th, sizeof(char *));
j2k_tile_len = (int *) calloc(j2k_cp->tw * j2k_cp->th, sizeof(int));
j2k_state = J2K_STATE_MH;
@ -336,7 +341,9 @@ void j2k_read_cox(int compno)
int i;
j2k_tcp_t *tcp;
j2k_tccp_t *tccp;
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tccp = &tcp->tccps[compno];
tccp->numresolutions = cio_read(1) + 1; /* SPcox (D) */
tccp->cblkw = cio_read(1) + 2; /* SPcox (E) */
@ -380,7 +387,9 @@ void j2k_read_cod()
int len, i, pos;
j2k_tcp_t *tcp;
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
len = cio_read(2); /* Lcod */
tcp->csty = cio_read(1); /* Scod */
tcp->prg = cio_read(1); /* SGcod (A) */
@ -418,7 +427,9 @@ void j2k_read_coc()
int len, compno;
j2k_tcp_t *tcp;
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
len = cio_read(2); /* Lcoc */
compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2); /* Ccoc */
tcp->tccps[compno].csty = cio_read(1); /* Scoc */
@ -436,7 +447,9 @@ void j2k_write_qcx(int compno)
tccp = &tcp->tccps[compno];
cio_write(tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx */
numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
numbands =
tccp->qntsty ==
J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
for (bandno = 0; bandno < numbands; bandno++) {
expn = tccp->stepsizes[bandno].expn;
@ -458,12 +471,18 @@ void j2k_read_qcx(int compno, int len)
j2k_tccp_t *tccp;
int bandno, numbands;
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tccp = &tcp->tccps[compno];
tmp = cio_read(1); /* Sqcx */
tccp->qntsty = tmp & 0x1f;
tccp->numgbits = tmp >> 5;
numbands = tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT ? len - 1 : (len - 1) / 2);
numbands =
tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : (tccp->qntsty ==
J2K_CCP_QNTSTY_NOQNT ?
len - 1 : (len -
1) / 2);
for (bandno = 0; bandno < numbands; bandno++) {
int expn, mant;
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { /* WHY STEPSIZES WHEN NOQNT ? */
@ -529,7 +548,8 @@ void j2k_read_qcc()
j2k_read_qcx(compno, len - 2 - (j2k_img->numcomps <= 256 ? 1 : 2));
}
void j2k_write_poc() {
void j2k_write_poc()
{
int len, numpchgs, i;
j2k_tcp_t *tcp;
j2k_tccp_t *tccp;
@ -538,10 +558,9 @@ void j2k_write_poc() {
tccp = &tcp->tccps[0];
numpchgs = tcp->numpocs;
cio_write(J2K_MS_POC, 2); /* POC */
len = 2 + (5 + 2*(j2k_img->numcomps <= 256 ? 1 : 2))*numpchgs;
len = 2 + (5 + 2 * (j2k_img->numcomps <= 256 ? 1 : 2)) * numpchgs;
cio_write(len, 2); /* Lpoc */
for (i = 0; i < numpchgs; i++)
{
for (i = 0; i < numpchgs; i++) {
// MODIF
j2k_poc_t *poc;
poc = &tcp->pocs[i];
@ -557,21 +576,23 @@ void j2k_write_poc() {
}
}
void j2k_read_poc() {
void j2k_read_poc()
{
int len, numpchgs, i, old_poc;
j2k_tcp_t *tcp;
j2k_tccp_t *tccp;
tcp = j2k_state==J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
old_poc = tcp->POC ? tcp->numpocs+1 : 0;
old_poc = tcp->POC ? tcp->numpocs + 1 : 0;
tcp->POC = 1;
tccp = &tcp->tccps[0];
len = cio_read(2); /* Lpoc */
numpchgs = (len-2)/(5+2*(j2k_img->numcomps <= 256 ? 1 : 2));
numpchgs = (len - 2) / (5 + 2 * (j2k_img->numcomps <= 256 ? 1 : 2));
for (i = old_poc; i < numpchgs+old_poc; i++)
{
for (i = old_poc; i < numpchgs + old_poc; i++) {
j2k_poc_t *poc;
poc = &tcp->pocs[i];
poc->resno0 = cio_read(1); /* RSpoc_i */
@ -582,7 +603,7 @@ void j2k_read_poc() {
poc->prg = cio_read(1); /* Ppoc_i */
}
tcp->numpocs = numpchgs+old_poc-1;
tcp->numpocs = numpchgs + old_poc - 1;
}
void j2k_read_crg()
@ -590,8 +611,7 @@ void j2k_read_crg()
int len, i, Xcrg_i, Ycrg_i;
len = cio_read(2); /* Lcrg */
for (i=0;i<j2k_img->numcomps;i++)
{
for (i = 0; i < j2k_img->numcomps; i++) {
Xcrg_i = cio_read(2); /* Xcrg_i */
Ycrg_i = cio_read(2); /* Ycrg_i */
}
@ -607,11 +627,10 @@ void j2k_read_tlm()
Stlm = cio_read(1); /* Stlm */
ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02);
SP = (Stlm >> 6) & 0x01;
tile_tlm = (len-4)/((SP+1)*2+ST);
for (i=0;i<tile_tlm;i++)
{
tile_tlm = (len - 4) / ((SP + 1) * 2 + ST);
for (i = 0; i < tile_tlm; i++) {
Ttlm_i = cio_read(ST); /* Ttlm_i */
Ptlm_i = cio_read(SP?4:2); /* Ptlm_i */
Ptlm_i = cio_read(SP ? 4 : 2); /* Ptlm_i */
}
}
@ -621,40 +640,36 @@ void j2k_read_plm()
len = cio_read(2); /* Lplm */
Zplm = cio_read(1); /* Zplm */
len-=3;
while (len>0)
{
len -= 3;
while (len > 0) {
Nplm = cio_read(4); /* Nplm */
len-=4;
for (i=Nplm ; i>0 ; i--)
{
add=cio_read(1);
len -= 4;
for (i = Nplm; i > 0; i--) {
add = cio_read(1);
len--;
packet_len=(packet_len<<7) + add; /* Iplm_ij */
if ((add & 0x80)==0)
{
packet_len = (packet_len << 7) + add; /* Iplm_ij */
if ((add & 0x80) == 0) {
/* New packet */
packet_len=0;
packet_len = 0;
}
if (len<=0) break;
if (len <= 0)
break;
}
}
}
void j2k_read_plt()
{
int len, i, Zplt, packet_len=0, add;
int len, i, Zplt, packet_len = 0, add;
len = cio_read(2); /* Lplt */
Zplt=cio_read(1); /* Zplt */
for (i=len-3;i>0;i--)
{
add=cio_read(1);
packet_len=(packet_len<<7) + add; /* Iplt_i */
if ((add & 0x80)==0)
{
Zplt = cio_read(1); /* Zplt */
for (i = len - 3; i > 0; i--) {
add = cio_read(1);
packet_len = (packet_len << 7) + add; /* Iplt_i */
if ((add & 0x80) == 0) {
/* New packet */
packet_len=0;
packet_len = 0;
}
}
}
@ -665,64 +680,68 @@ void j2k_read_ppm()
int N_ppm;
len = cio_read(2);
j2k_cp->ppm=1;
j2k_cp->ppm = 1;
Z_ppm = cio_read(1); /* Z_ppm */
len-=3;
while (len > 0)
{
if (j2k_cp->ppm_previous==0)
{
len -= 3;
while (len > 0) {
if (j2k_cp->ppm_previous == 0) {
N_ppm = cio_read(4); /* N_ppm */
len-=4;
} else
{
len -= 4;
} else {
N_ppm = j2k_cp->ppm_previous;
}
j=j2k_cp->ppm_store;
if (Z_ppm==0) /* First PPM marker */
j2k_cp->ppm_data=(unsigned char*)calloc(N_ppm,sizeof(unsigned char));
j = j2k_cp->ppm_store;
if (Z_ppm == 0) /* First PPM marker */
j2k_cp->ppm_data =
(unsigned char *) calloc(N_ppm, sizeof(unsigned char));
else /* NON-first PPM marker */
j2k_cp->ppm_data=(unsigned char*)realloc(j2k_cp->ppm_data, (N_ppm+j2k_cp->ppm_store)*sizeof(unsigned char));
j2k_cp->ppm_data =
(unsigned char *) realloc(j2k_cp->ppm_data,
(N_ppm +
j2k_cp->ppm_store) *
sizeof(unsigned char));
for (i=N_ppm ; i>0 ; i--) /* Read packet header */
{
j2k_cp->ppm_data[j]=cio_read(1);
for (i = N_ppm; i > 0; i--) { /* Read packet header */
j2k_cp->ppm_data[j] = cio_read(1);
j++;
len--;
if (len==0) break; /* Case of non-finished packet header in present marker but finished in next one */
if (len == 0)
break; /* Case of non-finished packet header in present marker but finished in next one */
}
j2k_cp->ppm_previous=i-1;
j2k_cp->ppm_store=j;
j2k_cp->ppm_previous = i - 1;
j2k_cp->ppm_store = j;
}
}
void j2k_read_ppt()
{
int len, Z_ppt, i, j=0;
int len, Z_ppt, i, j = 0;
j2k_tcp_t *tcp;
len = cio_read(2);
Z_ppt = cio_read(1);
tcp=&j2k_cp->tcps[j2k_curtileno];
tcp->ppt=1;
if (Z_ppt==0) /* First PPT marker */
{
tcp->ppt_data=(unsigned char*)calloc(len-3,sizeof(unsigned char));
tcp->ppt_store=0;
}
else /* NON-first PPT marker */
tcp->ppt_data=(unsigned char*)realloc(tcp->ppt_data, (len-3+tcp->ppt_store)*sizeof(unsigned char));
tcp = &j2k_cp->tcps[j2k_curtileno];
tcp->ppt = 1;
if (Z_ppt == 0) { /* First PPT marker */
tcp->ppt_data =
(unsigned char *) calloc(len - 3, sizeof(unsigned char));
tcp->ppt_store = 0;
} else /* NON-first PPT marker */
tcp->ppt_data =
(unsigned char *) realloc(tcp->ppt_data,
(len - 3 +
tcp->ppt_store) *
sizeof(unsigned char));
j=tcp->ppt_store;
for (i=len-3 ; i>0 ; i--)
{
tcp->ppt_data[j]=cio_read(1);
j = tcp->ppt_store;
for (i = len - 3; i > 0; i--) {
tcp->ppt_data[j] = cio_read(1);
j++;
}
tcp->ppt_store=j;
tcp->ppt_store = j;
}
void j2k_write_sot()
@ -753,21 +772,16 @@ void j2k_read_sot()
len = cio_read(2);
tileno = cio_read(2);
if (j2k_cp->tileno_size == 0)
{
if (j2k_cp->tileno_size == 0) {
j2k_cp->tileno[j2k_cp->tileno_size] = tileno;
j2k_cp->tileno_size++;
}
else
{
} else {
i = 0;
while (i < j2k_cp->tileno_size && status == 0)
{
while (i < j2k_cp->tileno_size && status == 0) {
status = j2k_cp->tileno[i] == tileno ? 1 : 0;
i++;
}
if (status == 0)
{
if (status == 0) {
j2k_cp->tileno[j2k_cp->tileno_size] = tileno;
j2k_cp->tileno_size++;
}
@ -785,20 +799,19 @@ void j2k_read_sot()
j2k_state = J2K_STATE_TPH;
tcp = &j2k_cp->tcps[j2k_curtileno];
if (tcp->first == 1)
{
if (tcp->first == 1) {
tmp = tcp->tccps;
*tcp = j2k_default_tcp;
/* Initialization PPT */
tcp->ppt=0;
tcp->ppt_data=NULL;
tcp->ppt = 0;
tcp->ppt_data = NULL;
tcp->tccps = tmp;
for (i = 0; i < j2k_img->numcomps; i++) {
tcp->tccps[i] = j2k_default_tcp.tccps[i];
}
j2k_cp->tcps[j2k_curtileno].first=0;
j2k_cp->tcps[j2k_curtileno].first = 0;
}
}
@ -816,9 +829,12 @@ void j2k_write_sod()
/* INDEX >> */
if (info_IM.index_on) {
info_IM.tile[j2k_curtileno].end_header = cio_tell() + pos_correction - 1;
info_IM.tile[j2k_curtileno].packet = (info_packet *) calloc(info_IM.Comp * info_IM.Layer *
(info_IM.Decomposition + 1) * 100,sizeof(info_packet));
info_IM.tile[j2k_curtileno].end_header =
cio_tell() + pos_correction - 1;
info_IM.tile[j2k_curtileno].packet =
(info_packet *) calloc(info_IM.Comp * info_IM.Layer *
(info_IM.Decomposition + 1) * 100,
sizeof(info_packet));
}
/* << INDEX */
@ -829,9 +845,11 @@ void j2k_write_sod()
info_IM.num = 0;
if (j2k_cp->image_type)
l = tcd_encode_tile_pxm(j2k_curtileno, cio_getbp(), cio_numbytesleft() - 2, &info_IM);
l = tcd_encode_tile_pxm(j2k_curtileno, cio_getbp(),
cio_numbytesleft() - 2, &info_IM);
else
l = tcd_encode_tile_pgx(j2k_curtileno, cio_getbp(), cio_numbytesleft() - 2, &info_IM);
l = tcd_encode_tile_pgx(j2k_curtileno, cio_getbp(),
cio_numbytesleft() - 2, &info_IM);
/* Writing Psot in SOT marker */
totlen = cio_tell() + l - j2k_sot_start;
@ -849,16 +867,18 @@ void j2k_read_sod()
if (len == cio_numbytesleft() + 1)
truncate = 1; /* Case of a truncate codestream */
data = (unsigned char*)malloc((j2k_tile_len[j2k_curtileno] + len) * sizeof(unsigned char));
for (i=0; i<j2k_tile_len[j2k_curtileno]; i++)
data =
(unsigned char *) malloc((j2k_tile_len[j2k_curtileno] + len) *
sizeof(unsigned char));
for (i = 0; i < j2k_tile_len[j2k_curtileno]; i++)
data[i] = j2k_tile_data[j2k_curtileno][i];
for (i=0 ; i<len ; i++)
data[i+j2k_tile_len[j2k_curtileno]] = cio_read(1);
for (i = 0; i < len; i++)
data[i + j2k_tile_len[j2k_curtileno]] = cio_read(1);
j2k_tile_len[j2k_curtileno] += len;
free(j2k_tile_data[j2k_curtileno]);
j2k_tile_data[j2k_curtileno] = data;
data=NULL;
data = NULL;
if (!truncate)
j2k_state = J2K_STATE_TPHSOT;
@ -882,7 +902,9 @@ void j2k_read_rgn()
int len, compno, roisty;
j2k_tcp_t *tcp;
tcp = j2k_state == J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
tcp =
j2k_state ==
J2K_STATE_TPH ? &j2k_cp->tcps[j2k_curtileno] : &j2k_default_tcp;
len = cio_read(2); /* Lrgn */
compno = cio_read(j2k_img->numcomps <= 256 ? 1 : 2); /* Crgn */
roisty = cio_read(1); /* Srgn */
@ -903,7 +925,8 @@ void j2k_read_eoc()
for (i = 0; i < j2k_cp->tileno_size; i++) {
tileno = j2k_cp->tileno[i];
tcd_decode_tile(j2k_tile_data[tileno], j2k_tile_len[tileno], tileno);
tcd_decode_tile(j2k_tile_data[tileno], j2k_tile_len[tileno],
tileno);
}
j2k_state = J2K_STATE_MT;
@ -915,7 +938,8 @@ void j2k_read_unk()
fprintf(stderr, "warning: unknown marker\n");
}
LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int len, char *index)
LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile,
int len, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb;
char *dest;
@ -943,7 +967,9 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
/* INDEX >> */
info_IM.index_on = j2k_img->index_on;
if (info_IM.index_on) {
info_IM.tile = (info_tile *) malloc(j2k_cp->tw * j2k_cp->th * sizeof(info_tile));
info_IM.tile =
(info_tile *) malloc(j2k_cp->tw * j2k_cp->th *
sizeof(info_tile));
info_IM.Im_w = j2k_img->x1 - j2k_img->x0;
info_IM.Im_h = j2k_img->y1 - j2k_img->y0;
info_IM.Prog = (&j2k_cp->tcps[0])->prg;
@ -953,7 +979,8 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
info_IM.Tile_y = j2k_cp->tdy; /* new version parser */
info_IM.Comp = j2k_img->numcomps;
info_IM.Layer = (&j2k_cp->tcps[0])->numlayers;
info_IM.Decomposition = (&j2k_cp->tcps[0])->tccps->numresolutions - 1;
info_IM.Decomposition =
(&j2k_cp->tcps[0])->tccps->numresolutions - 1;
info_IM.D_max = 0; /* ADD Marcela */
}
/* << INDEX */
@ -1001,7 +1028,8 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
/* INDEX >> */
if (info_IM.index_on) {
info_IM.tile[j2k_curtileno].num_tile = j2k_curtileno;
info_IM.tile[j2k_curtileno].start_pos = cio_tell() + pos_correction;
info_IM.tile[j2k_curtileno].start_pos =
cio_tell() + pos_correction;
}
/* << INDEX */
j2k_write_sot();
@ -1075,7 +1103,7 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
fprintf(INDEX, "%d %d\n", info_IM.pdx, info_IM.pdy);
fprintf(INDEX, "%d\n", info_IM.Main_head_end);
fprintf(INDEX, "%d\n", info_IM.codestream_size);
fprintf(INDEX, "%f\n",info_IM.D_max);
fprintf(INDEX, "%f\n", info_IM.D_max);
for (tileno = 0; tileno < j2k_cp->tw * j2k_cp->th; tileno++) {
fprintf(INDEX, "%d %d %d %d", info_IM.tile[tileno].num_tile,
info_IM.tile[tileno].start_pos,
@ -1083,20 +1111,31 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
info_IM.tile[tileno].end_pos);
/*for (layno=0;layno<info_IM.Layer;layno++)
fprintf(INDEX, " %f",info_IM.tile[tileno].thresh[layno]);
*/ fprintf(INDEX,"\n");
*/ fprintf(INDEX, "\n");
}
for (tileno = 0; tileno < j2k_cp->tw * j2k_cp->th; tileno++) {
pack_nb = 0;
if (info_IM.Prog == 0) { /* LRCP */
for (layno = 0; layno < info_IM.Layer; layno++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (resno = 0; resno < info_IM.Decomposition + 1;
resno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (precno = 0;
precno <
info_IM.tile[tileno].pw * info_IM.tile[tileno].ph;
precno++) {
fprintf(INDEX,"%d %d %d %d %d %d %d %d %.08f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max);
/*fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb, tileno, layno, resno, compno, precno, info_IM.tile[tileno].packet[pack_nb].start_pos, info_IM.tile[tileno].packet[pack_nb].end_pos);*/
info_IM.tile[tileno].pw *
info_IM.tile[tileno].ph; precno++) {
fprintf(INDEX,
"%d %d %d %d %d %d %d %d %.08f\n",
pack_nb, tileno, layno, resno,
compno, precno,
info_IM.tile[tileno].
packet[pack_nb].start_pos,
info_IM.tile[tileno].
packet[pack_nb].end_pos,
info_IM.tile[tileno].
packet[pack_nb].disto /
info_IM.D_max);
/*fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb, tileno, layno, resno, compno, precno, info_IM.tile[tileno].packet[pack_nb].start_pos, info_IM.tile[tileno].packet[pack_nb].end_pos); */
pack_nb++;
}
}
@ -1106,12 +1145,17 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph; precno++) {
for (precno = 0;
precno < info_IM.pw * info_IM.ph;
precno++) {
/* fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max); */
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb,
tileno, layno, resno, compno, precno,
info_IM.tile[tileno].packet[pack_nb].start_pos,
info_IM.tile[tileno].packet[pack_nb].end_pos);
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n",
pack_nb, tileno, layno, resno,
compno, precno,
info_IM.tile[tileno].
packet[pack_nb].start_pos,
info_IM.tile[tileno].
packet[pack_nb].end_pos);
pack_nb++;
}
}
@ -1119,29 +1163,38 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
}
} else if (info_IM.Prog == 2) { /* RPCL */
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph; precno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph;
precno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
/* fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max); */
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb,
tileno, layno, resno, compno, precno,
info_IM.tile[tileno].packet[pack_nb].start_pos,
info_IM.tile[tileno].packet[pack_nb].end_pos);
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n",
pack_nb, tileno, layno, resno,
compno, precno,
info_IM.tile[tileno].
packet[pack_nb].start_pos,
info_IM.tile[tileno].
packet[pack_nb].end_pos);
pack_nb++;
}
}
}
}
} else if (info_IM.Prog == 3) { /* PCRL */
for (precno = 0; precno < info_IM.pw * info_IM.ph; precno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph;
precno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (resno = 0; resno < info_IM.Decomposition + 1;
resno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
/* fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max); */
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb,
tileno, layno, resno, compno, precno,
info_IM.tile[tileno].packet[pack_nb].start_pos,
info_IM.tile[tileno].packet[pack_nb].end_pos);
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n",
pack_nb, tileno, layno, resno,
compno, precno,
info_IM.tile[tileno].
packet[pack_nb].start_pos,
info_IM.tile[tileno].
packet[pack_nb].end_pos);
pack_nb++;
}
}
@ -1150,11 +1203,19 @@ LIBJ2K_API int j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *outfile, int l
} else { /* CPRL */
for (compno = 0; compno < info_IM.Comp; compno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph; precno++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (precno = 0; precno < info_IM.pw * info_IM.ph;
precno++) {
for (resno = 0; resno < info_IM.Decomposition + 1;
resno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
/*fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max);*/
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n", pack_nb, tileno, layno, resno, compno, precno, info_IM.tile[tileno].packet[pack_nb].start_pos, info_IM.tile[tileno].packet[pack_nb].end_pos);
/*fprintf(INDEX,"%d %d %d %d %d %d %d %d %.04f\n",pack_nb,tileno,layno,resno,compno,precno,info_IM.tile[tileno].packet[pack_nb].start_pos,info_IM.tile[tileno].packet[pack_nb].end_pos,info_IM.tile[tileno].packet[pack_nb].disto/info_IM.D_max); */
fprintf(INDEX, "%d %d %d %d %d %d %d %d\n",
pack_nb, tileno, layno, resno,
compno, precno,
info_IM.tile[tileno].
packet[pack_nb].start_pos,
info_IM.tile[tileno].
packet[pack_nb].end_pos);
pack_nb++;
}
}
@ -1210,7 +1271,8 @@ j2k_dec_mstabent_t *j2k_dec_mstab_lookup(int id)
return e;
}
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp, j2k_option_t option)
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
j2k_cp_t ** cp, j2k_option_t option)
{
if (setjmp(j2k_error)) {
@ -1236,12 +1298,14 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_c
j2k_dec_mstabent_t *e;
int id = cio_read(2);
if (id >> 8 != 0xff) {
fprintf(stderr, "%.8x: expected a marker instead of %x\n", cio_tell() - 2, id);
fprintf(stderr, "%.8x: expected a marker instead of %x\n",
cio_tell() - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);
if (!(j2k_state & e->states)) {
fprintf(stderr, "%.8x: unexpected marker %x\n", cio_tell() - 2, id);
fprintf(stderr, "%.8x: unexpected marker %x\n", cio_tell() - 2,
id);
return 0;
}
if (e->handler) {
@ -1260,7 +1324,8 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_c
* Read a JPT-stream and decode file
*
*/
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp)
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img,
j2k_cp_t ** cp)
{
jpt_msg_header_struct_t header;
int position;
@ -1287,9 +1352,10 @@ int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_c
jpt_read_Msg_Header(&header);
position = cio_tell();
if (header.Class_Id != 6) /* 6 : Main header data-bin message */
{
fprintf(stderr,"[JPT-stream] : Expecting Main header first [class_Id %d] !\n",header.Class_Id);
if (header.Class_Id != 6) { /* 6 : Main header data-bin message */
fprintf(stderr,
"[JPT-stream] : Expecting Main header first [class_Id %d] !\n",
header.Class_Id);
return 0;
}
@ -1297,31 +1363,30 @@ int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_c
j2k_dec_mstabent_t *e;
int id;
if(!cio_numbytesleft())
{
if (!cio_numbytesleft()) {
j2k_read_eoc();
return 0;
}
/* data-bin read -> need to read a new header */
if ((cio_tell() - position) == header.Msg_length)
{
if ((cio_tell() - position) == header.Msg_length) {
jpt_read_Msg_Header(&header);
position = cio_tell();
if (header.Class_Id != 4) /* 4 : Tile data-bin message */
{
fprintf(stderr,"[JPT-stream] : Expecting Tile info !\n");
if (header.Class_Id != 4) { /* 4 : Tile data-bin message */
fprintf(stderr, "[JPT-stream] : Expecting Tile info !\n");
return 0;
}
}
id = cio_read(2);
if (id >> 8 != 0xff) {
fprintf(stderr, "%.8x: expected a marker instead of %x\n", cio_tell() - 2, id);
fprintf(stderr, "%.8x: expected a marker instead of %x\n",
cio_tell() - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);
if (!(j2k_state & e->states)) {
fprintf(stderr, "%.8x: unexpected marker %x\n", cio_tell() - 2, id);
fprintf(stderr, "%.8x: unexpected marker %x\n", cio_tell() - 2,
id);
return 0;
}
if (e->handler) {
@ -1339,7 +1404,8 @@ int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_c
#ifdef WIN32
#include <windows.h>
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved)
{
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:

View File

@ -189,7 +189,8 @@ typedef struct {
* len: length of destination buffer
* index : index file name
*/
LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *outfile, int len, char *index);
LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *outfile,
int len, char *index);
/* LIBJ2K_API int j2k_encode(j2k_image_t *i, j2k_cp_t *cp,unsigned char *dest, int len); */
/*
@ -199,7 +200,8 @@ LIBJ2K_API int j2k_encode(j2k_image_t * i, j2k_cp_t * cp, char *outfile, int len
* i: decode image
* cp: coding parameters that were used to encode the image
*/
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp, j2k_option_t option);
LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img,
j2k_cp_t ** cp, j2k_option_t option);
/*
@ -210,6 +212,7 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t ** img, j2k_c
* cp: coding parameters that were used to encode the image
*
*/
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img, j2k_cp_t ** cp);
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t ** img,
j2k_cp_t ** cp);
#endif

View File

@ -43,8 +43,7 @@ unsigned int jpt_read_VBAS_info(unsigned int value)
unsigned char elmt;
elmt = cio_read(1);
while ((elmt >> 7) == 1)
{
while ((elmt >> 7) == 1) {
value = (value << 7);
value |= (elmt & 0x7f);
elmt = cio_read(1);
@ -59,7 +58,7 @@ unsigned int jpt_read_VBAS_info(unsigned int value)
* Initialize the value of the message header structure
*
*/
void jpt_init_Msg_Header(jpt_msg_header_struct_t *header)
void jpt_init_Msg_Header(jpt_msg_header_struct_t * header)
{
header->Id = 0; /* In-class Identifier */
header->last_byte = 0; /* Last byte information */
@ -76,7 +75,7 @@ void jpt_init_Msg_Header(jpt_msg_header_struct_t *header)
* Only parameters always present in message header
*
*/
void jpt_reinit_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 */
@ -88,7 +87,7 @@ void jpt_reinit_Msg_Header(jpt_msg_header_struct_t *header)
* Read the message header for a JPP/JPT - stream
*
*/
void jpt_read_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);
@ -99,10 +98,10 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t *header)
elmt = cio_read(1);
/* See for Class and CSn */
switch((elmt>>5) & 0x03)
{
switch ((elmt >> 5) & 0x03) {
case 0:
fprintf(stderr,"Forbidden value encounter in message header !!\n");
fprintf(stderr,
"Forbidden value encounter in message header !!\n");
break;
case 1:
Class = 0;
@ -116,24 +115,23 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t *header)
Class = 1;
CSn = 1;
break;
default :
default:
break;
}
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
if (((elmt>>3) & 0x01) == 1)
if (((elmt >> 3) & 0x01) == 1)
header->last_byte = 1;
/* In-class identifier */
header->Id |= (elmt & 0x0f);
if ((elmt>>7)==1)
if ((elmt >> 7) == 1)
header->Id = jpt_read_VBAS_info(header->Id);
/* ------------ */
/* VBAS : Class */
/* ------------ */
if (Class==1)
{
if (Class == 1) {
header->Class_Id = 0;
header->Class_Id = jpt_read_VBAS_info(header->Class_Id);
}
@ -141,8 +139,7 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t *header)
/* ---------- */
/* VBAS : CSn */
/* ---------- */
if (CSn==1)
{
if (CSn == 1) {
header->CSn_Id = 0;
header->CSn_Id = jpt_read_VBAS_info(header->CSn_Id);
}
@ -160,8 +157,7 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t *header)
/* ---------- */
/* VBAS : Aux */
/* ---------- */
if (header->CSn_Id == 1)
{
if (header->CSn_Id == 1) {
header->Layer_nb = 0;
header->Layer_nb = jpt_read_VBAS_info(header->Layer_nb);
}

View File

@ -45,7 +45,7 @@ typedef struct {
* header : Message header structure
*
*/
void jpt_init_Msg_Header(jpt_msg_header_struct_t *header);
void jpt_init_Msg_Header(jpt_msg_header_struct_t * header);
/*
* Read the message header for a JPP/JPT - stream
@ -53,4 +53,4 @@ void jpt_init_Msg_Header(jpt_msg_header_struct_t *header);
* header : Message header structure
*
*/
void jpt_read_Msg_Header(jpt_msg_header_struct_t *header);
void jpt_read_Msg_Header(jpt_msg_header_struct_t * header);

View File

@ -320,7 +320,7 @@ void mqc_bypass_init_enc()
mqc_ct = 8;
/*if (*mqc_bp == 0xff) {
mqc_ct = 7;
}*/
} */
}
/* <summary> */
@ -332,8 +332,7 @@ void mqc_bypass_enc(int d)
{
mqc_ct--;
mqc_c = mqc_c + (d << mqc_ct);
if (mqc_ct == 0)
{
if (mqc_ct == 0) {
mqc_bp++;
*mqc_bp = mqc_c;
mqc_ct = 8;

View File

@ -44,7 +44,8 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
j2k_tccp_t *tccp;
tcp = &cp->tcps[tileno];
pi = (pi_iterator_t *) malloc((tcp->numpocs + 1) * sizeof(pi_iterator_t));
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;
@ -55,7 +56,8 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
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].comps =
(pi_comp_t *) malloc(img->numcomps * sizeof(pi_comp_t));
for (compno = 0; compno < pi->numcomps; compno++) {
int tcx0, tcy0, tcx1, tcy1;
@ -64,7 +66,9 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
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));
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);
@ -99,20 +103,23 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
}
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;
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;
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));*/
/* pi[pino].include=(short int*)calloc(img->numcomps*maxres*tcp->numlayers*1000,sizeof(short int)); */
else
pi[pino].include=pi[pino-1].include;
pi[pino].include = pi[pino - 1].include;
if (tcp->POC == 0) {
pi[pino].first = 1;
@ -153,17 +160,26 @@ int pi_next_lrcp(pi_iterator_t * pi)
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++) {
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;
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:;
@ -190,18 +206,27 @@ int pi_next_rlcp(pi_iterator_t * pi)
} else {
pi->first = 0;
}
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
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++) {
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;
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:;
@ -233,17 +258,23 @@ int pi_next_rpcl(pi_iterator_t * pi)
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));
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++) {
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;
@ -258,20 +289,42 @@ int pi_next_rpcl(pi_iterator_t * pi)
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)))) {
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)))) {
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);
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;
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:;
@ -305,18 +358,26 @@ int pi_next_pcrl(pi_iterator_t * pi)
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));
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++) {
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++) {
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;
@ -327,18 +388,42 @@ int pi_next_pcrl(pi_iterator_t * pi)
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)))) {
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)))) {
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);
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;
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:;
@ -374,8 +459,10 @@ int pi_next_cprl(pi_iterator_t * pi)
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));
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);
}
@ -384,7 +471,8 @@ int pi_next_cprl(pi_iterator_t * pi)
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_min(pi->poc.resno1,
comp->numresolutions);
pi->resno++) {
int levelno;
int trx0, try0;
@ -396,18 +484,42 @@ int pi_next_cprl(pi_iterator_t * pi)
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)))) {
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)))) {
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);
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;
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:;

View File

@ -107,7 +107,8 @@ int t1_getctxno_sc(int f)
int t1_getctxno_mag(int f)
{
return t1_lut_ctxno_mag[(f & T1_SIG_OTH) | (((f & T1_REFINE) != 0) << 11)];
return t1_lut_ctxno_mag[(f & T1_SIG_OTH) |
(((f & T1_REFINE) != 0) << 11)];
}
int t1_getspb(int f)
@ -118,7 +119,8 @@ int t1_getspb(int f)
int t1_getnmsedec_sig(int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS)
return t1_lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
return t1_lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) &
((1 << T1_NMSEDEC_BITS) - 1)];
else
return t1_lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
@ -126,7 +128,8 @@ int t1_getnmsedec_sig(int x, int bitpos)
int t1_getnmsedec_ref(int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS)
return t1_lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
return t1_lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) &
((1 << T1_NMSEDEC_BITS) - 1)];
else
return t1_lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
}
@ -151,10 +154,13 @@ void t1_updateflags(int *fp, int s)
}
}
void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc)
void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one,
int *nmsedec, char type, int vsc)
{
int v, flag;
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp);
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
v = int_abs(*dp) & one ? 1 : 0;
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
@ -166,7 +172,9 @@ void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one, int *n
}
if (v) {
v = *dp < 0 ? 1 : 0;
*nmsedec += t1_getnmsedec_sig(int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec +=
t1_getnmsedec_sig(int_abs(*dp),
bpno + T1_NMSEDEC_FRACBITS);
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
mqc_setcurctx(t1_getctxno_sc(flag)); /* ESSAI */
mqc_bypass_enc(v);
@ -181,11 +189,11 @@ void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one, int *n
}
}
void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf, char type, int vsc)
void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf,
char type, int vsc)
{
int v, flag;
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
if (type == T1_TYPE_RAW) {
@ -209,7 +217,8 @@ void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf, char typ
}
} /* VSC and BYPASS by Antonin */
void t1_enc_sigpass(int w, int h, int bpno, int orient, int *nmsedec, char type, int cblksty)
void t1_enc_sigpass(int w, int h, int bpno, int orient, int *nmsedec,
char type, int cblksty)
{
int i, j, k, one, vsc;
*nmsedec = 0;
@ -217,14 +226,18 @@ void t1_enc_sigpass(int w, int h, int bpno, int orient, int *nmsedec, char type,
for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_sigpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], orient, bpno, one, nmsedec, type, vsc);
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_sigpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, bpno, one,
nmsedec, type, vsc);
}
}
}
}
void t1_dec_sigpass(int w, int h, int bpno, int orient, char type, int cblksty)
void t1_dec_sigpass(int w, int h, int bpno, int orient, char type,
int cblksty)
{
int i, j, k, one, half, oneplushalf, vsc;
one = 1 << bpno;
@ -235,18 +248,24 @@ void t1_dec_sigpass(int w, int h, int bpno, int orient, char type, int cblksty)
for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], orient, oneplushalf, type, vsc);
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, oneplushalf,
type, vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc)
void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec,
char type, int vsc)
{
int v, flag;
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp);
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
*nmsedec += t1_getnmsedec_ref(int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec +=
t1_getnmsedec_ref(int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS);
v = int_abs(*dp) & one ? 1 : 0;
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
mqc_setcurctx(t1_getctxno_mag(flag)); /* ESSAI */
@ -259,10 +278,13 @@ void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec, char
}
}
void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf, char type, int vsc)
void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf,
char type, int vsc)
{
int v, t, flag;
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp);
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
if (type == T1_TYPE_RAW) {
mqc_setcurctx(t1_getctxno_mag(flag)); /* ESSAI */
@ -277,7 +299,8 @@ void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf, char type,
}
} /* VSC and BYPASS by Antonin */
void t1_enc_refpass(int w, int h, int bpno, int *nmsedec, char type, int cblksty)
void t1_enc_refpass(int w, int h, int bpno, int *nmsedec, char type,
int cblksty)
{
int i, j, k, one, vsc;
*nmsedec = 0;
@ -285,8 +308,11 @@ void t1_enc_refpass(int w, int h, int bpno, int *nmsedec, char type, int cblksty
for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_refpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], bpno, one, nmsedec, type, vsc);
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_refpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], bpno, one, nmsedec,
type, vsc);
}
}
}
@ -302,17 +328,23 @@ void t1_dec_refpass(int w, int h, int bpno, char type, int cblksty)
for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_refpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], poshalf, neghalf, type, vsc);
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_refpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], poshalf, neghalf, type,
vsc);
}
}
}
} /* VSC and BYPASS by Antonin */
void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc)
void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one,
int *nmsedec, int partial, int vsc)
{
int v, flag;
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp);
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if (partial)
goto label_partial;
if (!(*fp & (T1_SIG | T1_VISIT))) {
@ -321,7 +353,9 @@ void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one, int *n
mqc_encode(v);
if (v) {
label_partial:
*nmsedec += t1_getnmsedec_sig(int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec +=
t1_getnmsedec_sig(int_abs(*dp),
bpno + T1_NMSEDEC_FRACBITS);
mqc_setcurctx(t1_getctxno_sc(flag));
v = *dp < 0 ? 1 : 0;
mqc_encode(v ^ t1_getspb(flag));
@ -332,10 +366,13 @@ void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one, int *n
*fp &= ~T1_VISIT;
}
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc)
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf,
int partial, int vsc)
{
int v, flag;
flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp);
flag =
vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S)))
: (*fp);
if (partial)
goto label_partial;
if (!(flag & (T1_SIG | T1_VISIT))) {
@ -352,7 +389,8 @@ void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf, int part
*fp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */
void t1_enc_clnpass(int w, int h, int bpno, int orient, int *nmsedec, int cblksty)
void t1_enc_clnpass(int w, int h, int bpno, int orient, int *nmsedec,
int cblksty)
{
int i, j, k, one, agg, runlen, vsc;
*nmsedec = 0;
@ -361,16 +399,33 @@ void t1_enc_clnpass(int w, int h, int bpno, int orient, int *nmsedec, int cblkst
for (i = 0; i < w; i++) {
if (k + 3 < h) {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
agg = !(t1_flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || t1_flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || (t1_flags[1 + k + 3][1 + i] & (~(T1_SIG_S | T1_SIG_SE
| T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
agg =
!(t1_flags[1 + k][1 + i] &
(T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 2][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| (t1_flags[1 + k + 3][1 + i] &
(~
(T1_SIG_S | T1_SIG_SE | T1_SIG_SW |
T1_SGN_S))) & (T1_SIG | T1_VISIT |
T1_SIG_OTH));
} else {
agg = !(t1_flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH));
agg =
!(t1_flags[1 + k][1 + i] &
(T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 2][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 3][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH));
}
} else {
agg = 0;
@ -392,8 +447,11 @@ void t1_enc_clnpass(int w, int h, int bpno, int orient, int *nmsedec, int cblkst
runlen = 0;
}
for (j = k + runlen; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_clnpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], orient, bpno, one, nmsedec, agg
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_enc_clnpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, bpno, one,
nmsedec, agg
&& (j == k + runlen), vsc);
}
}
@ -411,16 +469,32 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
for (i = 0; i < w; i++) {
if (k + 3 < h) {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
agg = !(t1_flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || t1_flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || (t1_flags[1 + k + 3][1 + i] & (~(T1_SIG_S | T1_SIG_SE |
T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH));
agg =
!(t1_flags[1 + k][1 + i] &
(T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 2][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| (t1_flags[1 + k + 3][1 + i] &
(~
(T1_SIG_S | T1_SIG_SE | T1_SIG_SW |
T1_SGN_S))) & (T1_SIG | T1_VISIT |
T1_SIG_OTH));
} else {
agg = !(t1_flags[1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || t1_flags[1 + k + 2][1 + i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH) || t1_flags[1 + k + 3][1 + i] & (T1_SIG | T1_VISIT |
agg =
!(t1_flags[1 + k][1 + i] &
(T1_SIG | T1_VISIT | T1_SIG_OTH)
|| t1_flags[1 + k + 1][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 2][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH)
|| t1_flags[1 + k + 3][1 +
i] & (T1_SIG | T1_VISIT |
T1_SIG_OTH));
}
} else {
@ -438,8 +512,10 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
runlen = 0;
}
for (j = k + runlen; j < k + 4 && j < h; j++) {
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i], &t1_data[j][i], orient, oneplushalf,
vsc = ((cblksty & J2K_CCP_CBLKSTY_VSC)
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i],
&t1_data[j][i], orient, oneplushalf,
agg && (j == k + runlen), vsc);
}
}
@ -458,7 +534,8 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
}
} /* VSC and BYPASS by Antonin */
double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize)
double t1_getwmsedec(int nmsedec, int compno, int level, int orient,
int bpno, int qmfbid, double stepsize)
{
double w1, w2, wmsedec;
if (qmfbid == 1) {
@ -473,7 +550,8 @@ double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, i
return wmsedec;
}
void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty)
void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level,
int qmfbid, double stepsize, int cblksty)
{
int i, j;
int w, h;
@ -494,7 +572,8 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
}
}
cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
cblk->numbps =
max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
for (i = 0; i < sizeof(t1_flags) / sizeof(int); i++)
((int *) t1_flags)[i] = 0;
@ -511,7 +590,8 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
tcd_pass_t *pass = &cblk->passes[passno];
int correction = 3;
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2)
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
T1_TYPE_MQ;
switch (passtype) {
case 0:
@ -528,55 +608,49 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
break;
}
cumwmsedec += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize);
cumwmsedec +=
t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid,
stepsize);
/* Code switch "RESTART" (i.e. TERMALL) */
if ((cblksty & J2K_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0)))
{
if (type == T1_TYPE_RAW)
{
if ((cblksty & J2K_CCP_CBLKSTY_TERMALL)
&& !((passtype == 2) && (bpno - 1 < 0))) {
if (type == T1_TYPE_RAW) {
mqc_flush();
correction=1;
/* correction = mqc_bypass_flush_enc();*/
}
else
{ /* correction = mqc_restart_enc(); */
correction = 1;
/* correction = mqc_bypass_flush_enc(); */
} else { /* correction = mqc_restart_enc(); */
mqc_flush();
correction = 1;
}
pass->term = 1;
} else
{
if (((bpno < (cblk->numbps - 4) && (passtype > 0)) || ((bpno == (cblk->numbps - 4)) && (passtype == 2)))
&& (cblksty & J2K_CCP_CBLKSTY_LAZY))
{
if (type == T1_TYPE_RAW)
{
} else {
if (((bpno < (cblk->numbps - 4) && (passtype > 0))
|| ((bpno == (cblk->numbps - 4)) && (passtype == 2)))
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) {
if (type == T1_TYPE_RAW) {
mqc_flush();
correction=1;
/* correction = mqc_bypass_flush_enc();*/
}
else
{ /* correction = mqc_restart_enc();*/
correction = 1;
/* correction = mqc_bypass_flush_enc(); */
} else { /* correction = mqc_restart_enc(); */
mqc_flush();
correction=1;
correction = 1;
}
pass->term = 1;
} else
{
} else {
pass->term = 0;
}
}
if (++passtype == 3)
{
if (++passtype == 3) {
passtype = 0;
bpno--;
}
if (pass->term && bpno > 0) {
type = ((bpno < (cblk->numbps - 4)) && (passtype < 2)
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
T1_TYPE_MQ;
if (type == T1_TYPE_RAW)
mqc_bypass_init_enc();
else
@ -585,7 +659,8 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
pass->distortiondec = cumwmsedec;
pass->rate = mqc_numbytes() + correction; /* FIXME */
pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate);
pass->len =
pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate);
/* Code-switch "RESET" */
if (cblksty & J2K_CCP_CBLKSTY_RESET)
@ -601,7 +676,8 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
cblk->totalpasses = passno;
}
void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift, int cblksty)
void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
int cblksty)
{
int i;
int w, h;
@ -631,7 +707,8 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift, int cblksty)
/* add TONY */
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2)
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
T1_TYPE_MQ;
if (type == T1_TYPE_RAW)
raw_init_dec(seg->data, seg->len);
else
@ -687,15 +764,18 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
} else if (band->bandno == 1) {
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
} else if (band->bandno == 2) {
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} else { /* if (band->bandno == 3) */
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
}
@ -704,14 +784,26 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1_data[j][i] = tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0)] << T1_NMSEDEC_FRACBITS;
t1_data[j][i] =
tilec->data[(x + i) +
(y + j) * (tilec->x1 -
tilec->
x0)] <<
T1_NMSEDEC_FRACBITS;
}
}
} else if (tcp->tccps[compno].qmfbid == 0) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1_data[j][i] = fix_mul(tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)],
8192 * 8192 / band->stepsize) >> (13 - T1_NMSEDEC_FRACBITS);
t1_data[j][i] =
fix_mul(tilec->
data[x + i +
(y + j) * (tilec->x1 -
tilec->
x0)],
8192 * 8192 /
band->stepsize) >> (13 -
T1_NMSEDEC_FRACBITS);
}
}
}
@ -723,7 +815,8 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
}
t1_encode_cblk(cblk, orient, compno,
tilec->numresolutions - 1 - resno,
tcp->tccps[compno].qmfbid, band->stepsize,
tcp->tccps[compno].qmfbid,
band->stepsize,
tcp->tccps[compno].cblksty);
} /* cblkno */
} /* precno */
@ -737,20 +830,15 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
{
int compno, resno, bandno, precno, cblkno;
for (compno = 0; compno < tile->numcomps; compno++)
{
for (compno = 0; compno < tile->numcomps; compno++) {
tcd_tilecomp_t *tilec = &tile->comps[compno];
for (resno = 0; resno < tilec->numresolutions; resno++)
{
for (resno = 0; resno < tilec->numresolutions; resno++) {
tcd_resolution_t *res = &tilec->resolutions[resno];
for (bandno = 0; bandno < res->numbands; bandno++)
{
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
for (precno = 0; precno < res->pw * res->ph; precno++)
{
for (precno = 0; precno < res->pw * res->ph; precno++) {
tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++)
{
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int x, y, i, j, orient;
tcd_cblk_t *cblk = &prc->cblks[cblkno];
orient = band->bandno; /* FIXME */
@ -758,26 +846,30 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
orient = 1;
else if (orient == 1)
orient = 2;
t1_decode_cblk(cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty);
t1_decode_cblk(cblk, orient,
tcp->tccps[compno].roishift,
tcp->tccps[compno].cblksty);
if (band->bandno == 0) {
x = cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
} else if (band->bandno == 1) {
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = cblk->y0 - band->y0;
} else if (band->bandno == 2) {
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
} else { /* if (band->bandno == 3) */
tcd_resolution_t *pres = &tilec->resolutions[resno - 1];
tcd_resolution_t *pres =
&tilec->resolutions[resno - 1];
x = pres->x1 - pres->x0 + cblk->x0 - band->x0;
y = pres->y1 - pres->y0 + cblk->y0 - band->y0;
}
if (tcp->tccps[compno].roishift)
{
if (tcp->tccps[compno].roishift) {
int thresh, val, mag;
thresh = 1 << tcp->tccps[compno].roishift;
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
@ -785,8 +877,10 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
val = t1_data[j][i];
mag = int_abs(val);
if (mag >= thresh) {
mag >>= tcp->tccps[compno].roishift;
t1_data[j][i] = val < 0 ? -mag : mag;
mag >>= tcp->tccps[compno].
roishift;
t1_data[j][i] =
val < 0 ? -mag : mag;
}
}
}
@ -795,16 +889,28 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
if (tcp->tccps[compno].qmfbid == 1) {
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = t1_data[j][i];
tilec->data[x + i +
(y + j) * (tilec->x1 -
tilec->x0)] =
t1_data[j][i];
}
}
} else /* if (tcp->tccps[compno].qmfbid == 0)*/ {
} else { /* if (tcp->tccps[compno].qmfbid == 0) */
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
if (t1_data[j][i] == 0) {
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0;
tilec->data[x + i +
(y + j) * (tilec->x1 -
tilec->
x0)] = 0;
} else {
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = fix_mul(t1_data[j][i] << 13, band->stepsize);
tilec->data[x + i +
(y + j) * (tilec->x1 -
tilec->
x0)] =
fix_mul(t1_data[j][i] << 13,
band->stepsize);
}
}
}
@ -822,7 +928,9 @@ int t1_init_ctxno_zc(int f, int orient)
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) !=
0) + ((f & T1_SIG_SE) !=
0) + ((f & T1_SIG_SW) != 0);
switch (orient) {
case 2:
t = h;
@ -885,11 +993,17 @@ int t1_init_ctxno_sc(int f)
{
int hc, vc, n;
n = 0;
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((f & (T1_SIG_W | T1_SGN_W)) ==
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) + ((f & (T1_SIG_S | T1_SGN_S)) ==
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
if (hc < 0) {
hc = -hc;
@ -926,11 +1040,17 @@ int t1_init_ctxno_mag(int f)
int t1_init_spb(int f)
{
int hc, vc, n;
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == (T1_SIG_E | T1_SGN_E)) + ((f & (T1_SIG_W | T1_SGN_W)) ==
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == (T1_SIG_N | T1_SGN_N)) + ((f & (T1_SIG_S | T1_SGN_S)) ==
vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
if (!hc && !vc)
n = 0;
@ -966,19 +1086,33 @@ void t1_init_luts()
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;
v = t - 1.5;
t1_lut_nmsedec_sig[i] = int_max(0, (int) (floor((u * u - v * v) * pow(2,T1_NMSEDEC_FRACBITS) +
t1_lut_nmsedec_sig[i] =
int_max(0,
(int) (floor
((u * u - v * v) * pow(2,
T1_NMSEDEC_FRACBITS) +
0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
t1_lut_nmsedec_sig0[i] =
int_max(0,
(int) (floor
((u * u) * pow(2, T1_NMSEDEC_FRACBITS) +
0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
t1_lut_nmsedec_sig0[i] = int_max(0, (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) /
pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
u = t - 1.0;
if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
v = t - 1.5;
} else {
v = t - 0.5;
}
t1_lut_nmsedec_ref[i] = int_max(0, (int) (floor((u * u - v * v) * pow(2,T1_NMSEDEC_FRACBITS) +
t1_lut_nmsedec_ref[i] =
int_max(0,
(int) (floor
((u * u - v * v) * pow(2,
T1_NMSEDEC_FRACBITS) +
0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
t1_lut_nmsedec_ref0[i] =
int_max(0,
(int) (floor
((u * u) * pow(2, T1_NMSEDEC_FRACBITS) +
0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
t1_lut_nmsedec_ref0[i] = int_max(0, (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) /
pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
}
}

View File

@ -106,7 +106,8 @@ int t2_getnumpasses()
* info_IM : structure to create an index file
* tileno : number of the tile encoded
*/
int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno, int precno, int layno, unsigned char *dest,
int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno,
int resno, int precno, int layno, unsigned char *dest,
int len, info_image * info_IM, int tileno)
{
int bandno, cblkno;
@ -139,7 +140,8 @@ int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno,
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
tcd_cblk_t *cblk = &prc->cblks[cblkno];
cblk->numpasses = 0;
tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps);
tgt_setvalue(prc->imsbtree, cblkno,
band->numbps - cblk->numbps);
}
}
}
@ -188,8 +190,13 @@ int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno,
tcd_pass_t *pass = &cblk->passes[passno];
nump++;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump)));
if (pass->term
|| passno ==
(cblk->numpasses + layer->numpasses) - 1) {
increment =
int_max(increment,
int_floorlog2(len) + 1 -
(cblk->numlenbits + int_floorlog2(nump)));
len = 0;
nump = 0;
}
@ -204,7 +211,9 @@ int t2_encode_packet(tcd_tile_t * tile, j2k_tcp_t * tcp, int compno, int resno,
tcd_pass_t *pass = &cblk->passes[passno];
nump++;
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
if (pass->term
|| passno ==
(cblk->numpasses + layer->numpasses) - 1) {
bio_write(len, cblk->numlenbits + int_floorlog2(nump));
len = 0;
nump = 0;
@ -270,7 +279,8 @@ void t2_init_seg(tcd_seg_t * seg, int cblksty, int first)
if (first)
seg->maxpasses = 10;
else
seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1;
seg->maxpasses = (((seg - 1)->maxpasses == 1)
|| ((seg - 1)->maxpasses == 10)) ? 2 : 1;
} else
seg->maxpasses = 109;
}
@ -288,7 +298,9 @@ void t2_init_seg(tcd_seg_t * seg, int cblksty, int first)
* precno : Identity of the packet --> precinct value
* layno : Identity of the packet --> quality layer value
*/
int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t * cp, j2k_tcp_t * tcp, int compno, int resno, int precno, int layno)
int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
j2k_cp_t * cp, j2k_tcp_t * tcp, int compno, int resno,
int precno, int layno)
{
int bandno, cblkno;
tcd_tilecomp_t *tilec = &tile->comps[compno];
@ -296,16 +308,13 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
unsigned char *c = src;
int present;
if (layno == 0)
{
for (bandno = 0; bandno < res->numbands; bandno++)
{
if (layno == 0) {
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
tcd_precinct_t *prc = &band->precincts[precno];
tgt_reset(prc->incltree);
tgt_reset(prc->imsbtree);
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++)
{
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
tcd_cblk_t *cblk = &prc->cblks[cblkno];
cblk->numsegs = 0;
}
@ -316,21 +325,19 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
This part deal with this caracteristic
step 1: Read packet header in the saved structure
step 2: (futher) return to codestream for decoding */
if (cp->ppm == 1) /* PPM */
{
c=cp->ppm_data;
bio_init_dec(c,1000);
} else
{
if (tcp->ppt==1) /* PPT */
{
c=tcp->ppt_data;
bio_init_dec(c,1000);
} else /* Normal Case */
{
if (tcp->csty & J2K_CP_CSTY_SOP)
{
if ((*c)!=255 || (*(c+1)!=145)) {printf("Error : expected SOP marker [1]!!!\n");}
if (cp->ppm == 1) { /* PPM */
c = cp->ppm_data;
bio_init_dec(c, 1000);
} else {
if (tcp->ppt == 1) { /* PPT */
c = tcp->ppt_data;
bio_init_dec(c, 1000);
} else { /* Normal Case */
if (tcp->csty & J2K_CP_CSTY_SOP) {
if ((*c) != 255 || (*(c + 1) != 145)) {
printf("Error : expected SOP marker [1]!!!\n");
}
c += 6;
}
bio_init_dec(c, src + len - c);
@ -339,56 +346,49 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
present = bio_read(1);
if (!present)
{
if (!present) {
bio_inalign();
/* Normal case */
c += bio_numbytes();
if (tcp->csty & J2K_CP_CSTY_EPH)
{
if ((*c)!=255 || (*(c+1)!=146)) {printf("Error : expected EPH marker [1]!!!\n");}
if (tcp->csty & J2K_CP_CSTY_EPH) {
if ((*c) != 255 || (*(c + 1) != 146)) {
printf("Error : expected EPH marker [1]!!!\n");
}
c += 2;
}
/* PPT and PPM dealing */
if (cp->ppm == 1) /* PPM */
{
cp->ppm_data=c;
if (cp->ppm == 1) { /* PPM */
cp->ppm_data = c;
return 0;
}
if (tcp->ppt==1) /* PPT */
{
tcp->ppt_data=c;
if (tcp->ppt == 1) { /* PPT */
tcp->ppt_data = c;
return 0;
}
return c - src;
}
for (bandno = 0; bandno < res->numbands; bandno++)
{
for (bandno = 0; bandno < res->numbands; bandno++) {
tcd_band_t *band = &res->bands[bandno];
tcd_precinct_t *prc = &band->precincts[precno];
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++)
{
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
int included, increment, n;
tcd_cblk_t *cblk = &prc->cblks[cblkno];
tcd_seg_t *seg;
/* if cblk not yet included before --> inclusion tagtree */
if (!cblk->numsegs)
{
if (!cblk->numsegs) {
included = tgt_decode(prc->incltree, cblkno, layno + 1);
/* else one bit */
} else {
included = bio_read(1);
}
/* if cblk not included */
if (!included)
{
if (!included) {
cblk->numnewpasses = 0;
continue;
}
/* if cblk not yet included --> zero-bitplane tagtree */
if (!cblk->numsegs)
{
if (!cblk->numsegs) {
int i, numimsbs;
for (i = 0; !tgt_decode(prc->imsbtree, cblkno, i); i++) {
}
@ -413,8 +413,11 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
n = cblk->numnewpasses;
do {
seg->numnewpasses = int_min(seg->maxpasses - seg->numpasses, n);
seg->newlen = bio_read(cblk->numlenbits + int_floorlog2(seg->numnewpasses));
seg->numnewpasses =
int_min(seg->maxpasses - seg->numpasses, n);
seg->newlen =
bio_read(cblk->numlenbits +
int_floorlog2(seg->numnewpasses));
n -= seg->numnewpasses;
if (n > 0) {
t2_init_seg(++seg, tcp->tccps[compno].cblksty, 0);
@ -428,35 +431,35 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
c += bio_numbytes();
if (tcp->csty & J2K_CP_CSTY_EPH) { /* EPH marker */
if ((*c)!=255 || (*(c+1)!=146)) {
printf("Error : expected EPH marker [2]!!!\n"); }
if ((*c) != 255 || (*(c + 1) != 146)) {
printf("Error : expected EPH marker [2]!!!\n");
}
c += 2;
}
/* PPT Step 2 : see above for details */
if (cp->ppm==1)
{
cp->ppm_data=c; /* Update pointer */
if (cp->ppm == 1) {
cp->ppm_data = c; /* Update pointer */
c=src;
if (tcp->csty & J2K_CP_CSTY_SOP)
{
if ((*c)!=255 || (*(c+1)!=145)) {printf("Error : expected SOP marker [2] !!!\n"); }
c = src;
if (tcp->csty & J2K_CP_CSTY_SOP) {
if ((*c) != 255 || (*(c + 1) != 145)) {
printf("Error : expected SOP marker [2] !!!\n");
}
c += 6;
}
bio_init_dec(c,src + len - c);
} else
{
if (tcp->ppt==1)
{
tcp->ppt_data=c; /* Update pointer */
c=src;
if (tcp->csty & J2K_CP_CSTY_SOP) /* SOP marker */
{
if ((*c)!=255 || (*(c+1)!=145)) {printf("Error : expected SOP marker [2] !!!\n"); }
bio_init_dec(c, src + len - c);
} else {
if (tcp->ppt == 1) {
tcp->ppt_data = c; /* Update pointer */
c = src;
if (tcp->csty & J2K_CP_CSTY_SOP) { /* SOP marker */
if ((*c) != 255 || (*(c + 1) != 145)) {
printf("Error : expected SOP marker [2] !!!\n");
}
c += 6;
}
bio_init_dec(c,src + len - c);
bio_init_dec(c, src + len - c);
}
}
@ -480,8 +483,9 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
}
}
do {
if (c + seg->newlen > src + len){
return -999;}
if (c + seg->newlen > src + len) {
return -999;
}
memcpy(cblk->data + cblk->len, c, seg->newlen);
if (seg->numpasses == 0) {
@ -517,7 +521,9 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile, j2k_cp_t *
* len : the length of the destination buffer
* info_IM : structure to create an index file
*/
int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t * tile, int maxlayers, unsigned char *dest, int len, info_image * info_IM)
int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno,
tcd_tile_t * tile, int maxlayers,
unsigned char *dest, int len, info_image * info_IM)
{
unsigned char *c = dest;
int e = 0;
@ -529,9 +535,10 @@ int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t *
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
while (pi_next(&pi[pino])) {
if (pi[pino].layno < maxlayers) {
e = t2_encode_packet(tile, &cp->tcps[tileno], pi[pino].compno,
pi[pino].resno, pi[pino].precno, pi[pino].layno,
c, dest + len - c, info_IM, tileno);
e = t2_encode_packet(tile, &cp->tcps[tileno],
pi[pino].compno, pi[pino].resno,
pi[pino].precno, pi[pino].layno, c,
dest + len - c, info_IM, tileno);
if (e == -999) {
break;
} else
@ -585,23 +592,30 @@ int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t *
* tileno: number that identifies the tile for which to decode the packets
* tile: tile for which to decode the packets
*/
int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t * tile)
int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp, int tileno, tcd_tile_t * tile)
{
unsigned char *c = src;
pi_iterator_t *pi;
int pino, compno, e = 0;
int n=0;
int n = 0;
pi = pi_create(img, cp, tileno);
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
while (pi_next(&pi[pino]))
{
e = t2_decode_packet(c, src + len - c, tile, cp, &cp->tcps[tileno], pi[pino].compno,
pi[pino].resno, pi[pino].precno, pi[pino].layno);
while (pi_next(&pi[pino])) {
e = t2_decode_packet(c, src + len - c, tile, cp,
&cp->tcps[tileno], pi[pino].compno,
pi[pino].resno, pi[pino].precno,
pi[pino].layno);
/* progression in resolution */
img->comps[pi[pino].compno].resno_decoded = e > 0 ? int_max(pi[pino].resno, img->comps[pi[pino].compno].resno_decoded) : img->comps[pi[pino].compno].resno_decoded;
img->comps[pi[pino].compno].resno_decoded =
e > 0 ? int_max(pi[pino].resno,
img->comps[pi[pino].compno].
resno_decoded) : img->comps[pi[pino].
compno].
resno_decoded;
n++;
if (e == -999) { /* ADD */

View File

@ -44,7 +44,9 @@
* len : the length of the destination buffer
* info_IM : structure to create an index file
*/
int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t * tile, int maxlayers, unsigned char *dest, int len, info_image * info_IM);
int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno,
tcd_tile_t * tile, int maxlayers,
unsigned char *dest, int len, info_image * info_IM);
/*
* Decode the packets of a tile from a source buffer
@ -56,6 +58,7 @@ int t2_encode_packets(j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t *
* tileno: number that identifies the tile for which to decode the packets
* tile: tile for which to decode the packets
*/
int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp, int tileno, tcd_tile_t * tile);
int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp, int tileno, tcd_tile_t * tile);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -152,7 +152,8 @@ void tcd_free_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno);
* len: length of destination buffer
* info_IM: creation of index file
*/
int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len, info_image * info_IM);
int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
info_image * info_IM);
/*
@ -162,7 +163,8 @@ int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len, info_image * i
* len: length of destination buffer
* info_IM: creation of index file
*/
int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len, info_image * info_IM);
int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
info_image * info_IM);
/*
* Decode a tile from a buffer into a raw image

View File

@ -83,7 +83,8 @@ tgt_tree_t *tgt_create(int numleafsh, int numleafsv)
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];