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) 2002-2004, Yannick Verschueren
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* 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
* POSSIBILITY OF SUCH DAMAGE.
*/
* Copyright (c) 2001-2002, David Janssens
* Copyright (c) 2002-2004, Yannick Verschueren
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* 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
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
@ -107,7 +107,7 @@ void j2k_dump_image(j2k_image_t * img)
int compno;
fprintf(stdout, "image {\n");
fprintf(stdout, " x0=%d, y0=%d, x1=%d, y1=%d\n", img->x0, img->y0,
img->x1, img->y1);
img->x1, img->y1);
fprintf(stdout, " numcomps=%d\n", img->numcomps);
for (compno = 0; compno < img->numcomps; compno++) {
j2k_comp_t *comp = &img->comps[compno];
@ -157,7 +157,7 @@ void j2k_dump_cp(j2k_image_t * img, j2k_cp_t * cp)
J2K_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolutions * 3 - 2;
for (bandno = 0; bandno < numbands; bandno++) {
fprintf(stdout, "(%d,%d) ", tccp->stepsizes[bandno].mant,
tccp->stepsizes[bandno].expn);
tccp->stepsizes[bandno].expn);
}
fprintf(stdout, "\n");
@ -479,8 +479,8 @@ void j2k_read_qcx(int compno, int len)
tccp->numgbits = tmp >> 5;
numbands =
tccp->qntsty == J2K_CCP_QNTSTY_SIQNT ? 1 : (tccp->qntsty ==
J2K_CCP_QNTSTY_NOQNT ?
len - 1 : (len - 1) / 2);
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) {
@ -507,7 +507,7 @@ void j2k_read_qcx(int compno, int len)
tccp->stepsizes[bandno].expn =
((tccp->stepsizes[0].expn) - ((bandno - 1) / 3) >
0) ? (tccp->stepsizes[0].expn) - ((bandno - 1) / 3) : 0;
0) ? (tccp->stepsizes[0].expn) - ((bandno - 1) / 3) : 0;
tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant;
@ -724,9 +724,9 @@ void j2k_read_ppm()
} 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));
(N_ppm +
j2k_cp->ppm_store) *
sizeof(unsigned char));
j2k_cp->ppm_len = N_ppm + j2k_cp->ppm_store; //Add antonin : ppmbug1
@ -763,8 +763,8 @@ void j2k_read_ppt()
} else { /* NON-first PPT marker */
tcp->ppt_data =
(unsigned char *) realloc(tcp->ppt_data,
(len - 3 +
tcp->ppt_store) * sizeof(unsigned char));
(len - 3 +
tcp->ppt_store) * sizeof(unsigned char));
tcp->ppt_len = len - 3 + tcp->ppt_store; //Add antonin : ppmbug1
@ -867,8 +867,8 @@ void j2k_write_sod()
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.Decomposition + 1) * 100,
sizeof(info_packet));
}
/* << INDEX */
@ -880,10 +880,10 @@ 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);
cio_numbytesleft() - 2, &info_IM);
else
l = tcd_encode_tile_pgx(j2k_curtileno, cio_getbp(),
cio_numbytesleft() - 2, &info_IM);
cio_numbytesleft() - 2, &info_IM);
/* Writing Psot in SOT marker */
totlen = cio_tell() + l - j2k_sot_start;
@ -903,7 +903,7 @@ void j2k_read_sod()
data =
(unsigned char *) malloc((j2k_tile_len[j2k_curtileno] + len) *
sizeof(unsigned char));
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++)
@ -976,7 +976,7 @@ LIBJ2K_API int
j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
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;
FILE *INDEX = 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.Tile_x = j2k_cp->tdx; /* 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.Layer = (&j2k_cp->tcps[0])->numlayers;
info_IM.Decomposition = (&j2k_cp->tcps[0])->tccps->numresolutions - 1;
@ -1086,23 +1088,23 @@ j2k_encode(j2k_image_t * img, j2k_cp_t * cp, char *output,
/* << INDEX */
/*
if (tile->PPT) BAD PPT !!!
{
FILE *PPT_file;
if (tile->PPT) BAD PPT !!!
{
FILE *PPT_file;
int i;
PPT_file=fopen("PPT","rb");
fprintf(stderr,"%c%c%c%c",255,97,tile->len_ppt/256,tile->len_ppt%256);
for (i=0;i<tile->len_ppt;i++)
{
unsigned char elmt;
fread(&elmt, 1, 1, PPT_file);
fwrite(&elmt,1,1,f);
}
fclose(PPT_file);
unlink("PPT");
}
*/
int i;
PPT_file=fopen("PPT","rb");
fprintf(stderr,"%c%c%c%c",255,97,tile->len_ppt/256,tile->len_ppt%256);
for (i=0;i<tile->len_ppt;i++)
{
unsigned char elmt;
fread(&elmt, 1, 1, PPT_file);
fwrite(&elmt,1,1,f);
}
fclose(PPT_file);
unlink("PPT");
}
*/
if (cp->intermed_file == 1) {
fwrite(dest, 1, cio_tell(), f);
pos_correction = cio_tell() + pos_correction;
@ -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\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"); */
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 (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[resno] *
info_IM.tile[tileno].ph[resno]; precno++) {
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;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
fprintf(INDEX, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno, precno,
start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
}
}
}
}
} 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 (layno = 0; layno < info_IM.Layer; layno++) {
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;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
fprintf(INDEX, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, resno, layno, compno, precno,
start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
}
}
}
}
} 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 (precno = 0;
precno <
info_IM.tile[tileno].pw[resno] *
info_IM.tile[tileno].ph[resno]; precno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
/* 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 (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
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++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n",
pack_nb, tileno, resno, precno, compno, layno,
start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
}
}
}
}
}
}
}
}
} 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;
precno <
info_IM.tile[tileno].pw[resno] *
info_IM.tile[tileno].ph[resno]; precno++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
//fprintf(INDEX, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n");
for (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
for (compno = 0; compno < info_IM.Comp; compno++) {
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++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
pack_nb, tileno, precno, compno, resno, layno,
start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
}
}
}
}
}
}
}
}
} 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 (precno = 0;
precno <
info_IM.tile[tileno].pw[resno] *
info_IM.tile[tileno].ph[resno]; precno++) {
for (resno = 0; resno < info_IM.Decomposition + 1; resno++) {
for (layno = 0; layno < info_IM.Layer; layno++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX,
"%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",
pack_nb, tileno, layno, resno, compno,
precno, start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
/* 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 (y=y0; y<y1; y++) {
for (x=x0; x<x1; x++) {
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++) {
start_pos = info_IM.tile[tileno].packet[pack_nb].start_pos;
end_pos = info_IM.tile[tileno].packet[pack_nb].end_pos;
disto = info_IM.tile[tileno].packet[pack_nb].disto;
fprintf(INDEX, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n",
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto);
DistoTotal += disto;
pack_nb++;
}
}
}
}
}
}
}
}
}
}
fprintf(INDEX, "SE max : %8e\n", info_IM.D_max);
fprintf(INDEX, "%8e\n", info_IM.D_max); //SE max
fprintf(INDEX, "SE total : %.8e\n", DistoTotal);
fprintf(INDEX, "%.8e\n", DistoTotal); // SE totale
fclose(INDEX);
@ -1464,7 +1431,7 @@ j2k_decode(unsigned char *src, int len, j2k_image_t * img, j2k_cp_t * cp)
int id = cio_read(2);
if (id >> 8 != 0xff) {
fprintf(stderr, "%.8x: expected a marker instead of %x\n",
cio_tell() - 2, id);
cio_tell() - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);
@ -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
j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
j2k_cp_t * cp)
@ -1520,8 +1487,8 @@ j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
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);
"[JPT-stream] : Expecting Main header first [class_Id %d] !\n",
header.Class_Id);
return 0;
}
@ -1546,7 +1513,7 @@ j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
id = cio_read(2);
if (id >> 8 != 0xff) {
fprintf(stderr, "%.8x: expected a marker instead of %x\n",
cio_tell() - 2, id);
cio_tell() - 2, id);
return 0;
}
e = j2k_dec_mstab_lookup(id);

View File

@ -176,6 +176,7 @@ typedef struct {
int Im_w, Im_h; /* Image width and Height */
int Prog; /* progression order */
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 Comp; /* Component numbers */
int Layer; /* number of layer */