Index structure adpated for other progression orders than LRCP

(thanks to Stefano Pensa)
This commit is contained in:
Antonin Descampe 2004-11-29 14:48:20 +00:00
parent 0ddef9b2db
commit eb1b017ec7
2 changed files with 351 additions and 383 deletions

View File

@ -1,30 +1,30 @@
/* /*
* Copyright (c) 2001-2002, David Janssens * Copyright (c) 2001-2002, David Janssens
* Copyright (c) 2002-2004, Yannick Verschueren * Copyright (c) 2002-2004, Yannick Verschueren
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -976,7 +976,7 @@ LIBJ2K_API int
j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output, j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
int len, char *index) int len, char *index)
{ {
int tileno, compno, layno, resno, precno, pack_nb; int tileno, compno, layno, resno, precno, pack_nb, x, y;
char *dest = NULL; char *dest = NULL;
FILE *INDEX = NULL; FILE *INDEX = NULL;
FILE *f = NULL; FILE *f = NULL;
@ -1011,6 +1011,8 @@ j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
info_IM.th = j2k_cp->th; info_IM.th = j2k_cp->th;
info_IM.Tile_x = j2k_cp->tdx; /* new version parser */ info_IM.Tile_x = j2k_cp->tdx; /* new version parser */
info_IM.Tile_y = j2k_cp->tdy; /* new version parser */ info_IM.Tile_y = j2k_cp->tdy; /* new version parser */
info_IM.Tile_Ox = j2k_cp->tx0; /* new version parser */
info_IM.Tile_Oy = j2k_cp->ty0; /* new version parser */
info_IM.Comp = j2k_img->numcomps; info_IM.Comp = j2k_img->numcomps;
info_IM.Layer = (&j2k_cp->tcps[0])->numlayers; 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;
@ -1144,8 +1146,6 @@ j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
} }
fprintf(INDEX, "%d %d\n", info_IM.Im_w, info_IM.Im_h); fprintf(INDEX, "%d %d\n", info_IM.Im_w, info_IM.Im_h);
fprintf(INDEX, "%d\n", info_IM.Prog); fprintf(INDEX, "%d\n", info_IM.Prog);
@ -1197,194 +1197,161 @@ j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
"pkno tileno layerno resno compno precno start_pos end_pos deltaSE \n"); */ "pkno tileno layerno resno compno precno start_pos end_pos deltaSE \n"); */
if (info_IM.Prog == 0) { /* LRCP */ if (info_IM.Prog == 0) { /* LRCP */
//fprintf(INDEX, "pack_nb tileno layno resno compno precno start_pos end_pos disto");
for (layno = 0; layno < info_IM.Layer; layno++) { 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 (compno = 0; compno < info_IM.Comp; compno++) {
for (precno = 0; for (precno = 0;
precno < precno <
info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].ph[resno];
info_IM.tile[tileno].ph[resno]; precno++) { precno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos; start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos; end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto; disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
fprintf(INDEX, pack_nb, tileno, layno, resno, compno, precno,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n", start_pos, end_pos, disto);
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto; DistoTotal += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} else if (info_IM.Prog == 1) { /* RLCP */ } else if (info_IM.Prog == 1) { /* RLCP */
//fprintf(INDEX, "pack_nb tileno resno layno compno precno start_pos end_pos disto");
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++) { for (layno = 0; layno < info_IM.Layer; layno++) {
for (compno = 0; compno < info_IM.Comp; compno++) { for (compno = 0; compno < info_IM.Comp; compno++) {
for (precno = 0; precno < info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].ph[resno]; precno++) {
for (precno = 0;
precno <
info_IM.tile[tileno].pw[resno] *
info_IM.tile[tileno].ph[resno]; precno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos; start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos; end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto; disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n",
fprintf(INDEX, pack_nb, tileno, resno, layno, compno, precno,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n", start_pos, end_pos, disto);
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto; DistoTotal += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} else if (info_IM.Prog == 2) { /* RPCL */ } else if (info_IM.Prog == 2) { /* RPCL */
//fprintf(INDEX, "\npack_nb tileno resno precno compno layno start_pos end_pos disto\n");
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) { for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
/* I suppose components have same XRsiz, YRsiz */
for (precno = 0; int x0 = info_IM.Tile_Ox + tileno - (int)floor( tileno/info_IM.tw ) * info_IM.tw * info_IM.Tile_x;
precno < int y0 = info_IM.Tile_Ox + (int)floor( tileno/info_IM.tw ) * info_IM.Tile_y;
info_IM.tile[tileno].pw[resno] * int x1 = x0 + info_IM.Tile_x;
info_IM.tile[tileno].ph[resno]; precno++) { int y1 = y0 + info_IM.Tile_y;
for (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
for (compno = 0; compno < info_IM.Comp; compno++) { for (compno = 0; compno < info_IM.Comp; compno++) {
int prec_max = info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
int pcnx = info_IM.tile[tileno].pw[resno];
int pcx = (int) pow( 2, info_IM.tile[tileno].pdx[resno] + info_IM.Decomposition - resno );
int pcy = (int) pow( 2, info_IM.tile[tileno].pdy[resno] + info_IM.Decomposition - resno );
int precno_x = precno - (int) floor( precno/pcnx ) * pcnx;
int precno_y = (int) floor( precno/pcnx );
if (precno_y*pcy == y ) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < info_IM.Layer; layno++) { for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos; start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos; end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto; disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n",
fprintf(INDEX, pack_nb, tileno, resno, precno, compno, layno,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n", start_pos, end_pos, disto);
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto; DistoTotal += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
}
}
}
}
} else if (info_IM.Prog == 3) { /* PCRL */ } else if (info_IM.Prog == 3) { /* PCRL */
// I suppose components have same XRsiz, YRsiz
int x0 = info_IM.Tile_Ox + tileno - (int)floor( tileno/info_IM.tw ) * info_IM.tw * info_IM.Tile_x;
int y0 = info_IM.Tile_Ox + (int)floor( tileno/info_IM.tw ) * info_IM.Tile_y;
int x1 = x0 + info_IM.Tile_x;
int y1 = y0 + info_IM.Tile_y;
for (precno = 0; //fprintf(INDEX, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n");
precno < for (y=y0; y<y1; y++) {
info_IM.tile[tileno].pw[resno] * for (x=x0; x<x1; x++) {
info_IM.tile[tileno].ph[resno]; precno++) {
for (compno = 0; compno < info_IM.Comp; compno++) { 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++) {
int prec_max = info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
int pcnx = info_IM.tile[tileno].pw[resno];
int pcx = (int) pow( 2, info_IM.tile[tileno].pdx[resno] + info_IM.Decomposition - resno );
int pcy = (int) pow( 2, info_IM.tile[tileno].pdy[resno] + info_IM.Decomposition - resno );
int precno_x = precno - (int) floor( precno/pcnx ) * pcnx;
int precno_y = (int) floor( precno/pcnx );
if (precno_y*pcy == y ) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < info_IM.Layer; layno++) { for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos; start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos; end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto; disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
fprintf(INDEX, pack_nb, tileno, precno, compno, resno, layno,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n", start_pos, end_pos, disto);
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto; DistoTotal += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
}
}
}
}
} else { /* CPRL */ } else { /* CPRL */
//fprintf(INDEX, "\npack_nb tileno compno precno resno layno start_pos end_pos disto\n");
for (compno = 0; compno < info_IM.Comp; compno++) { for (compno = 0; compno < info_IM.Comp; compno++) {
/* I suppose components have same XRsiz, YRsiz */
for (precno = 0; int x0 = info_IM.Tile_Ox + tileno - (int)floor( tileno/info_IM.tw ) * info_IM.tw * info_IM.Tile_x;
precno < int y0 = info_IM.Tile_Ox + (int)floor( tileno/info_IM.tw ) * info_IM.Tile_y;
info_IM.tile[tileno].pw[resno] * int x1 = x0 + info_IM.Tile_x;
info_IM.tile[tileno].ph[resno]; precno++) { int y1 = y0 + info_IM.Tile_y;
for (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) { for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
int prec_max = info_IM.tile[tileno].pw[resno] * info_IM.tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
int pcnx = info_IM.tile[tileno].pw[resno];
int pcx = (int) pow( 2, info_IM.tile[tileno].pdx[resno] + info_IM.Decomposition - resno );
int pcy = (int) pow( 2, info_IM.tile[tileno].pdy[resno] + info_IM.Decomposition - resno );
int precno_x = precno - (int) floor( precno/pcnx ) * pcnx;
int precno_y = (int) floor( precno/pcnx );
if (precno_y*pcy == y ) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < info_IM.Layer; layno++) { for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos; start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos; end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto; disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
fprintf(INDEX, pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto);
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto; DistoTotal += disto;
pack_nb++; pack_nb++;
}
}
}
}
}
}
}
}
}
} }
} fprintf(INDEX, "%8e\n", info_IM.D_max); //SE max
} fprintf(INDEX, "%.8e\n", DistoTotal); // SE totale
}
}
}
fprintf(INDEX, "SE max : %8e\n", info_IM.D_max);
fprintf(INDEX, "SE total : %.8e\n", DistoTotal);
fclose(INDEX); fclose(INDEX);
@ -1487,9 +1454,9 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
} }
/* /*
* Read a JPT-stream and decode file * Read a JPT-stream and decode file
* *
*/ */
int int
j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img, j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp) j2k_cp_t * cp)

View File

@ -176,6 +176,7 @@ typedef struct {
int Im_w, Im_h; /* Image width and Height */ int Im_w, Im_h; /* Image width and Height */
int Prog; /* progression order */ int Prog; /* progression order */
int Tile_x, Tile_y; /* Tile size in x and y */ int Tile_x, Tile_y; /* Tile size in x and y */
int Tile_Ox, Tile_Oy;
int tw, th; /* Number of Tile in X and Y */ int tw, th; /* Number of Tile in X and Y */
int Comp; /* Component numbers */ int Comp; /* Component numbers */
int Layer; /* number of layer */ int Layer; /* number of layer */