This commit is contained in:
Francois-Olivier Devaux 2007-07-13 13:07:07 +00:00
parent 4a50efe542
commit 5dec8bbbe9
7 changed files with 239 additions and 212 deletions

View File

@ -5,6 +5,11 @@ What's New for OpenJPEG
! : changed
+ : added
July 13, 2007
! [FOD] Modified the memory allocation for codestreams containing multiple tiles. The memory is now allocated for each tile indenpendently, leading to an important decrease of the virtual memory needed. [j2k.c tcd.h tcd.c]
! [FOD] Modified old comments about the ability to decode mega-images and comments about the disk size necessary to do this. [image_to_j2k.c and frames_to_mj2.c]
* [FOD] Added 2000 bytes for the memory allocation in cio.c for the minimum size of headers (useful in case of very small images) [cio.c]
July 12, 2007
* [GB] fixed a bug in JPWL module, which prevented to exploit the full error correction capability of RS codes (e.g. it gave up at 5 errors, even if 6 were correctable); defined a JPWL_MAXIMUM_EPB_ROOM for better customization of the maximum dimension of EPBs (the dimension is pre-calculated on an hypothesis, if it goes beyond 65535 there will be problems, thus we give a little less than the max, let's say 65450)

View File

@ -98,10 +98,6 @@ void encode_help_display() {
fprintf(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
fprintf(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf(stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
fprintf(stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
fprintf(stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
fprintf(stdout,"\n");
fprintf(stdout,"By default:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");

View File

@ -58,7 +58,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
opj_free(cio);
return NULL;
}
cio->length = (int) (0.1625 * cp->img_size); /* 0.1625 = 1.3/8 */
cio->length = (int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */
cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) {
opj_free(cio);

View File

@ -1484,10 +1484,12 @@ static void j2k_read_eoc(opj_j2k_t *j2k) {
opj_tcd_t *tcd = tcd_create(j2k->cinfo);
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
for (i = 0; i < j2k->cp->tileno_size; i++) {
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i);
tileno = j2k->cp->tileno[i];
tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno);
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
tcd_free_decode_tile(tcd, i);
}
tcd_free_decode(tcd);
tcd_destroy(tcd);

View File

@ -573,21 +573,43 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int cur
}
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
int tileno, compno, resno, bandno, precno, cblkno, i, j, p, q;
int i, j, tileno, p, q;
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h;
tcd->image = image;
tcd->cp = cp;
tcd->tcd_image->tw = cp->tw;
tcd->tcd_image->th = cp->th;
tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * sizeof(opj_tcd_tile_t));
for (i = 0; i < cp->tileno_size; i++) {
opj_tcp_t *tcp = &(cp->tcps[cp->tileno[i]]);
opj_tcd_tile_t *tile = &(tcd->tcd_image->tiles[cp->tileno[i]]);
/*
Allocate place to store the decoded data = final image
Place limited by the tile really present in the codestream
*/
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tile->numcomps = image->numcomps;
tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t));
}
for (i = 0; i < image->numcomps; i++) {
for (j = 0; j < cp->tileno_size; j++) {
opj_tcd_tile_t *tile;
opj_tcd_tilecomp_t *tilec;
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
tileno = cp->tileno[i];
tileno = cp->tileno[j];
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tilec = &tile->comps[i];
p = tileno % cp->tw; /* si numerotation matricielle .. */
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
@ -597,8 +619,42 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
tile->numcomps = image->numcomps;
tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(image->numcomps * sizeof(opj_tcd_tilecomp_t));
tilec->x0 = int_ceildiv(tile->x0, image->comps[i].dx);
tilec->y0 = int_ceildiv(tile->y0, image->comps[i].dy);
tilec->x1 = int_ceildiv(tile->x1, image->comps[i].dx);
tilec->y1 = int_ceildiv(tile->y1, image->comps[i].dy);
x0 = j == 0 ? tilec->x0 : int_min(x0, (unsigned int) tilec->x0);
y0 = j == 0 ? tilec->y0 : int_min(y0, (unsigned int) tilec->x0);
x1 = j == 0 ? tilec->x1 : int_max(x1, (unsigned int) tilec->x1);
y1 = j == 0 ? tilec->y1 : int_max(y1, (unsigned int) tilec->y1);
}
w = x1 - x0;
h = y1 - y0;
image->comps[i].data = (int *) opj_malloc(w * h * sizeof(int));
image->comps[i].w = w;
image->comps[i].h = h;
image->comps[i].x0 = x0;
image->comps[i].y0 = y0;
}
}
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno) {
int compno, resno, bandno, precno, cblkno;
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0;
opj_tcp_t *tcp;
opj_tcd_tile_t *tile;
tcd->cp = cp;
tcp = &(cp->tcps[cp->tileno[tileno]]);
tile = &(tcd->tcd_image->tiles[cp->tileno[tileno]]);
tileno = cp->tileno[tileno];
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tccp_t *tccp = &tcp->tccps[compno];
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
@ -742,37 +798,8 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp) {
} /* bandno */
} /* resno */
} /* compno */
} /* i = 0..cp->tileno_size */
/* tcd_dump(stdout, tcd, &tcd->tcd_image); */
/*
Allocate place to store the decoded data = final image
Place limited by the tile really present in the codestream
*/
for (i = 0; i < image->numcomps; i++) {
for (j = 0; j < cp->tileno_size; j++) {
tileno = cp->tileno[j];
x0 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].x0 : int_min(x0,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].x0);
y0 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].y0 : int_min(y0,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].y0);
x1 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].x1 : int_max(x1,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].x1);
y1 = j == 0 ? tcd->tcd_image->tiles[tileno].comps[i].y1 : int_max(y1,
(unsigned int) tcd->tcd_image->tiles[tileno].comps[i].y1);
}
w = x1 - x0;
h = y1 - y0;
image->comps[i].data = (int *) opj_malloc(w * h * sizeof(int));
image->comps[i].w = w;
image->comps[i].h = h;
image->comps[i].x0 = x0;
image->comps[i].y0 = y0;
}
}
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) {
@ -1378,11 +1405,15 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
}
void tcd_free_decode(opj_tcd_t *tcd) {
int tileno,compno,resno,bandno,precno;
opj_tcd_image_t *tcd_image = tcd->tcd_image;
if (tcd_image->tiles != NULL) opj_free(tcd_image->tiles);
}
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
int compno,resno,bandno,precno;
opj_tcd_image_t *tcd_image = tcd->tcd_image;
for (tileno = 0; tileno < tcd_image->tw * tcd_image->th; tileno++) {
opj_tcd_tile_t *tile = &tcd_image->tiles[tileno];
for (compno = 0; compno < tile->numcomps; compno++) {
opj_tcd_tilecomp_t *tilec = &tile->comps[compno];
@ -1402,8 +1433,6 @@ void tcd_free_decode(opj_tcd_t *tcd) {
if (tilec->resolutions != NULL) opj_free(tilec->resolutions);
}
if (tile->comps != NULL) opj_free(tile->comps);
}
if (tcd_image->tiles != NULL) opj_free(tcd_image->tiles);
}

View File

@ -234,6 +234,7 @@ Initialize the tile decoder
@param cp Coding parameters
*/
void tcd_malloc_decode(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp);
void tcd_malloc_decode_tile(opj_tcd_t *tcd, opj_image_t * image, opj_cp_t * cp, int tileno);
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final);
void tcd_rateallocate_fixed(opj_tcd_t *tcd);
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final);
@ -261,6 +262,7 @@ Free the memory allocated for decoding
@param tcd TCD handle
*/
void tcd_free_decode(opj_tcd_t *tcd);
void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno);
/* ----------------------------------------------------------------------- */
/*@}*/

View File

@ -78,13 +78,6 @@ void help_display()
fprintf
(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
fprintf
(stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
fprintf
(stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
fprintf
(stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
fprintf(stdout,"\n");
fprintf(stdout,"By default:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");