[trunk] WIP: fix the decoding process with conformance files and V2 framework

This commit is contained in:
Mickael Savinaud 2011-10-05 16:27:16 +00:00
parent f4734d6b4d
commit ee0e8a3aad
20 changed files with 1073 additions and 605 deletions

View File

@ -5,15 +5,18 @@ What's New for OpenJPEG
! : changed
+ : added
October 05, 2011
+ [mickael] WIP: fix the decoding process with conformance files and V2 framework
September 30, 2011
* [vincent] fix autotools for various compilation problems
* [vincent] fix indexer compilation. Patch from Winfried
* [kaori] modified indexer for JPIP, JPP-stream
September 27, 2011
+ (mickael] WIP: enhance the event management into the new API
* (mickael] WIP: fix some warnings about a static function and j2k_read_unk_v2
+ (mickael] WIP: add basis for a new output management of the codestream information and index
+ [mickael] WIP: enhance the event management into the new API
* [mickael] WIP: fix some warnings about a static function and j2k_read_unk_v2
+ [mickael] WIP: add basis for a new output management of the codestream information and index
* [mickael] WIP: fix some warnings from j2k_dump and index.c
September 22, 2011

View File

@ -46,8 +46,6 @@
#endif /* _WIN32 */
#include "openjpeg.h"
#include "j2k.h"
#include "jp2.h"
#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
@ -374,7 +372,7 @@ int main(int argc, char *argv[])
opj_dparameters_t parameters; /* Decompression parameters */
opj_event_mgr_t event_mgr; /* Event manager */
opj_image_header_t img_header; /* Image info structure */
opj_image_t image; /* Image structure */
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
opj_stream_t *cio = NULL; /* Stream */
opj_codestream_info_v2_t* cstr_info;
@ -465,6 +463,7 @@ int main(int argc, char *argv[])
cio = opj_stream_create_default_file_stream(fsrc,1);
if (!cio){
fclose(fsrc);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return EXIT_FAILURE;
}
@ -508,7 +507,7 @@ int main(int argc, char *argv[])
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(cio, dinfo, &img_header)){
if(! opj_read_header(cio, dinfo, &image)){
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
opj_stream_destroy(cio);
fclose(fsrc);
@ -523,10 +522,11 @@ int main(int argc, char *argv[])
cstr_index = opj_get_cstr_index(dinfo);
#ifdef MSD
fprintf(stdout,"Setting decoding area to %d,%d,%d,%d\n",
parameters.DA_x0, parameters.DA_y0, parameters.DA_x1, parameters.DA_y1);
#ifdef MSD
/* FIXME WIP_MSD <*/
if (! opj_set_decode_area( dinfo,
parameters.DA_x0, parameters.DA_y0,
@ -603,7 +603,7 @@ int main(int argc, char *argv[])
}
/* destroy the image header */
opj_image_header_destroy(&img_header);
opj_image_destroy(&image);
}

View File

@ -50,7 +50,6 @@
#define _strnicmp strncasecmp
#endif /* _WIN32 */
#include "opj_config.h"
#include "openjpeg.h"
#include "opj_getopt.h"
#include "convert.h"
@ -86,6 +85,17 @@ typedef struct img_folder{
}img_fol_t;
/* -------------------------------------------------------------------------- */
/* Declarations */
int get_num_images(char *imgdirpath);
int load_images(dircnt_t *dirptr, char *imgdirpath);
int get_file_format(char *filename);
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename);
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1);
/* -------------------------------------------------------------------------- */
void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -166,6 +176,7 @@ int get_num_images(char *imgdirpath){
return num_images;
}
/* -------------------------------------------------------------------------- */
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
@ -191,6 +202,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0;
}
/* -------------------------------------------------------------------------- */
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
@ -210,6 +222,7 @@ int get_file_format(char *filename) {
return -1;
}
/* -------------------------------------------------------------------------- */
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -235,6 +248,10 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
return 0;
}
/* -------------------------------------------------------------------------- */
/**
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */
@ -265,7 +282,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
break;
case JP2_CFMT:
break;
case JPT_CFMT:
break;
default:
@ -286,11 +305,17 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) {
case PGX_DFMT:
break;
case PXM_DFMT:
break;
case BMP_DFMT:
break;
case TIF_DFMT:
break;
case RAW_DFMT:
break;
case TGA_DFMT:
break;
case PNG_DFMT:
break;
default:
@ -486,6 +511,36 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
return 0;
}
/* -------------------------------------------------------------------------- */
/**
* Parse decoding area input values
* separator = ","
*/
/* -------------------------------------------------------------------------- */
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1)
{
int it = 0;
int values[4];
char delims[] = ",";
char *result = NULL;
result = strtok( inArg, delims );
while( (result != NULL) && (it < 4 ) ) {
values[it] = atoi(result);
result = strtok( NULL, delims );
it++;
}
if (it != 4) {
return EXIT_FAILURE;
}
else{
*DA_x0 = values[0]; *DA_y0 = values[1];
*DA_x1 = values[2]; *DA_y1 = values[3];
return EXIT_SUCCESS;
}
}
/* -------------------------------------------------------------------------- */
/**
@ -511,23 +566,28 @@ void info_callback(const char *msg, void *client_data) {
}
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv) {
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t *image = NULL;
/**
* J2K_TO_IMAGE MAIN
*/
/* -------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
FILE *fsrc = NULL;
unsigned char *src = NULL;
int file_length;
int num_images;
int i,imageno;
dircnt_t *dirptr = NULL;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL;
opj_codestream_info_t cstr_info; /* Codestream information structure */
opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_image_t image;
opj_stream_t *cio = NULL; /* Stream */
opj_codec_t* dinfo = NULL; /* Handle to a decompressor */
char indexfilename[OPJ_PATH_LEN]; /* index file name */
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
/* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
@ -537,45 +597,51 @@ int main(int argc, char **argv) {
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* Initialize indexfilename and img_fol */
/* FIXME Initialize indexfilename and img_fol */
*indexfilename = 0;
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
return 1;
return EXIT_FAILURE;
}
/* Set default event mgr */
opj_initialize_default_event_handler(&event_mgr, 1);
/* Initialize reading of directory */
if(img_fol.set_imgdir==1){
int it_image;
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); // Stores at max 10 image file names
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names */
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){
return 1;
return EXIT_FAILURE;
}
for(i=0;i<num_images;i++){
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
for(it_image=0;it_image<num_images;it_image++){
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1){
return 1;
return EXIT_FAILURE;
}
if (num_images==0){
fprintf(stdout,"Folder is empty\n");
return 1;
return EXIT_FAILURE;
}
}else{
num_images=1;
}
/*Encoding image one by one*/
/*Decoding image one by one*/
for(imageno = 0; imageno < num_images ; imageno++) {
image = NULL;
fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){
@ -590,180 +656,99 @@ int main(int argc, char **argv) {
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
return 1;
return EXIT_FAILURE;
}
fseek(fsrc, 0, SEEK_END);
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
if (fread(src, 1, file_length, fsrc) != (size_t)file_length)
{
free(src);
fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
return 1;
}
fclose(fsrc);
/* decode the code-stream */
cio = opj_stream_create_default_file_stream(fsrc,1);
if (!cio){
fclose(fsrc);
fprintf(stderr, "ERROR -> failed to create the stream from the file\n");
return EXIT_FAILURE;
}
/* decode the JPEG2000 stream */
/* ---------------------- */
switch(parameters.decod_format) {
case J2K_CFMT:
{
/* JPEG-2000 codestream */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) // If need to extract codestream information
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
return 1;
case J2K_CFMT: /* JPEG-2000 codestream */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_J2K);
break;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
case JP2_CFMT: /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_JP2);
break;
}
case JPT_CFMT: /* JPEG 2000, JPIP */
{
/* Get a decoder handle */
dinfo = opj_create_decompress_v2(CODEC_JPT);
break;
}
default:
fprintf(stderr, "skipping file..\n");
opj_stream_destroy(cio);
continue;
}
break;
case JP2_CFMT:
{
/* JPEG 2000 compressed image data */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JP2);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using the current image and user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) // If need to extract codestream information
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
}
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder_v2(dinfo, &parameters, &event_mgr) ){
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
return EXIT_FAILURE;
}
break;
case JPT_CFMT:
{
/* JPEG 2000, JPIP */
/* get a decoder handle */
dinfo = opj_create_decompress(CODEC_JPT);
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the image structure */
if (*indexfilename) // If need to extract codestream information
image = opj_decode_with_info(dinfo, cio, &cstr_info);
else
image = opj_decode(dinfo, cio);
if(!image) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
return 1;
}
/* close the byte stream */
opj_cio_close(cio);
/* Write the index to disk */
if (*indexfilename) {
opj_bool bSuccess;
bSuccess = write_index_file(&cstr_info, indexfilename);
if (bSuccess) {
fprintf(stderr, "Failed to output index file\n");
}
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(cio, dinfo, &image)){
fprintf(stderr, "ERROR -> j2k_dump: failed to read the header\n");
opj_stream_destroy(cio);
fclose(fsrc);
opj_destroy_codec(dinfo);
return EXIT_FAILURE;
}
break;
default:
fprintf(stderr, "skipping file..\n");
continue;
}
/* free the memory containing the code-stream */
free(src);
src = NULL;
/* Get the decoded image */
opj_bool bRes1 = opj_decode_v2(dinfo, cio, &image);
opj_bool bRes2 = opj_end_decompress(dinfo,cio);
if(image->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(image);
}
/*if ( !(opj_decode_v2(dinfo, cio, &image)) || !(opj_end_decompress(dinfo,cio)) ) {*/
if ( !bRes1 || !bRes2) {
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_codec(dinfo);
opj_stream_destroy(cio);
fclose(fsrc);
return EXIT_FAILURE;
}
if(image->icc_profile_buf)
{
/* Close the byte stream */
opj_stream_destroy(cio);
fclose(fsrc);
if(image.color_space == CLRSPC_SYCC){
color_sycc_to_rgb(&image); /* FIXME */
}
if(image.icc_profile_buf) {
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
color_apply_icc_profile(image);
color_apply_icc_profile(&image); /* FIXME */
#endif
free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0;
}
free(image.icc_profile_buf);
image.icc_profile_buf = NULL; image.icc_profile_len = 0;
}
/* create output image */
/* ------------------- */
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
if (imagetopnm(&image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
@ -772,7 +757,7 @@ int main(int argc, char **argv) {
break;
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
if(imagetopgx(&image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
@ -781,7 +766,7 @@ int main(int argc, char **argv) {
break;
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
if(imagetobmp(&image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
@ -790,7 +775,7 @@ int main(int argc, char **argv) {
break;
#ifdef HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
if(imagetotif(&image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
}
else {
@ -799,7 +784,7 @@ int main(int argc, char **argv) {
break;
#endif /* HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
if(imagetoraw(&image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
}
else {
@ -808,7 +793,7 @@ int main(int argc, char **argv) {
break;
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
if(imagetotga(&image, parameters.outfile)){
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
}
else {
@ -817,7 +802,7 @@ int main(int argc, char **argv) {
break;
#ifdef HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
if(imagetopng(&image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
}
else {
@ -833,14 +818,13 @@ int main(int argc, char **argv) {
}
/* free remaining structures */
if(dinfo) {
opj_destroy_decompress(dinfo);
if (dinfo) {
opj_destroy_codec(dinfo);
}
/* free codestream information structure */
if (*indexfilename)
opj_destroy_cstr_info(&cstr_info);
/* free image data structure */
opj_image_destroy(image);
opj_image_destroy(&image);
}
return 0;

View File

@ -764,8 +764,10 @@ static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, in
float* restrict bi = (float*) (w->wavelet + w->cas);
int count = w->sn;
int i, k;
for(k = 0; k < 2; ++k){
if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
if (count + 3 * x < size && ((size_t) a & 0x0f) == 0 &&
((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0) {
/* Fast code path */
for(i = 0; i < count; ++i){
int j = i;
@ -777,22 +779,24 @@ static void v4dwt_interleave_h(v4dwt_t* restrict w, float* restrict a, int x, in
j += x;
bi[i*8 + 3] = a[j];
}
} else {
}
else {
/* Slow code path */
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 1] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 2] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 3] = a[j];
}
for(i = 0; i < count; ++i){
int j = i;
bi[i*8 ] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 1] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 2] = a[j];
j += x;
if(j > size) continue;
bi[i*8 + 3] = a[j];
}
}
bi = (float*) (w->wavelet + 1 - w->cas);
a += w->sn;
size -= w->sn;
@ -1087,58 +1091,66 @@ opj_bool dwt_decode_real_v2(opj_tcd_tilecomp_v2_t* restrict tilec, OPJ_UINT32 nu
rh = res->y1 - res->y0; /* height of the resolution level computed */
h.dn = rw - h.sn;
h.cas = res->x0 & 1;
h.cas = res->x0 % 2;
for(j = rh; j > 0; j -= 4) {
for(j = rh; j > 3; j -= 4) {
OPJ_INT32 k;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
if(j >= 4){
OPJ_INT32 k = rw;
while (--k >= 0) {
aj[k ] = h.wavelet[k].f[0];
aj[k+w ] = h.wavelet[k].f[1];
aj[k+w*2] = h.wavelet[k].f[2];
aj[k+w*3] = h.wavelet[k].f[3];
}
}
else {
OPJ_INT32 k = rw;
while (--k >= 0) {
switch(j) {
case 3: aj[k+w*2] = h.wavelet[k].f[2];
case 2: aj[k+w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
for(k = rw; --k >= 0;){
aj[k ] = h.wavelet[k].f[0];
aj[k+w ] = h.wavelet[k].f[1];
aj[k+w*2] = h.wavelet[k].f[2];
aj[k+w*3] = h.wavelet[k].f[3];
}
aj += w*4;
bufsize -= w*4;
}
if (rh & 0x03) {
int k;
j = rh & 0x03;
v4dwt_interleave_h(&h, aj, w, bufsize);
v4dwt_decode(&h);
for(k = rw; --k >= 0;){
switch(j) {
case 3: aj[k+w*2] = h.wavelet[k].f[2];
case 2: aj[k+w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
}
v.dn = rh - v.sn;
v.cas = res->y0 % 2;
aj = (OPJ_FLOAT32*) tilec->data;
for(j = rw; j > 0; j -= 4){
for(j = rw; j > 3; j -= 4){
OPJ_INT32 k;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
if(j >= 4){
OPJ_UINT32 k;
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32));
}
}else{
OPJ_UINT32 k;
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32));
}
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32));
}
aj += 4;
}
if (rw & 0x03){
OPJ_INT32 k;
j = rw & 0x03;
v4dwt_interleave_v(&v, aj, w);
v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32));
}
}
}
opj_aligned_free(h.wavelet);

View File

@ -31,11 +31,6 @@ opj_image_t* opj_image_create0(void) {
return image;
}
opj_image_header_t* opj_image_header_create0(void) {
opj_image_header_t *image_header = (opj_image_header_t*)opj_calloc(1, sizeof(opj_image_header_t));
return image_header;
}
opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
int compno;
opj_image_t *image = NULL;
@ -75,35 +70,24 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
return image;
}
// TODO remove this one
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
int i;
if(image) {
if(image->comps) {
OPJ_UINT32 compno;
/* image components */
for(i = 0; i < image->numcomps; i++) {
opj_image_comp_t *image_comp = &image->comps[i];
for(compno = 0; compno < image->numcomps; compno++) {
opj_image_comp_t *image_comp = &(image->comps[compno]);
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(image->comps);
}
opj_free(image);
}
}
void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header) {
if(image_header) {
if(image_header->comps) {
/* image components */
opj_free(image_header->comps);
if(image->icc_profile_buf) {
opj_free(image->icc_profile_buf);
}
if(image_header->icc_profile_buf) {
opj_free(image_header->icc_profile_buf);
}
opj_free(image_header);
//FIXME opj_free(image);
}
}
@ -113,12 +97,12 @@ void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header) {
* @param p_image_header the image header to update.
* @param p_cp the coding parameters from which to update the image.
*/
void opj_image_comp_header_update(opj_image_header_t * p_image_header, const opj_cp_v2_t * p_cp)
void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp_v2 * p_cp)
{
OPJ_UINT32 i, l_width, l_height;
OPJ_INT32 l_x0, l_y0, l_x1, l_y1;
OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
opj_image_comp_header_t* l_img_comp = NULL;
opj_image_comp_t* l_img_comp = NULL;
l_x0 = int_max(p_cp->tx0 , p_image_header->x0);
l_y0 = int_max(p_cp->ty0 , p_image_header->y0);
@ -135,8 +119,8 @@ void opj_image_comp_header_update(opj_image_header_t * p_image_header, const opj
l_height = int_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_img_comp->w = l_width;
l_img_comp->h = l_height;
l_img_comp->x0 = l_x0;
l_img_comp->y0 = l_y0;
l_img_comp->x0 = l_comp_x0/*l_x0*/;
l_img_comp->y0 = l_comp_y0/*l_y0*/;
++l_img_comp;
}
}

View File

@ -39,26 +39,21 @@ struct opj_cp_v2;
/*@{*/
/**
Create an empty image
@todo this function should be removed
@return returns an empty image if successful, returns NULL otherwise
*/
* Create an empty image
*
* @return returns an empty image if successful, returns NULL otherwise
*/
opj_image_t* opj_image_create0(void);
/**
Create an empty image header
@return returns an image header if successful, returns NULL otherwise
*/
opj_image_header_t* opj_image_header_create0(void);
/**
* Updates the components characteristics of the image from the coding parameters.
*
* @param p_image_header the image header to update.
* @param p_cp the coding parameters from which to update the image.
* @param p_cp the coding parameters from which to update the image.
*/
void opj_image_comp_header_update(struct opj_image_header * p_image_header, const struct opj_cp_v2* p_cp);
void opj_image_comp_header_update(opj_image_t * p_image, const struct opj_cp_v2* p_cp);
/*@}*/

View File

@ -190,6 +190,16 @@ static void j2k_copy_tile_quantization_parameters(
opj_j2k_v2_t *p_j2k
);
/**
* Reads the tiles.
*/
opj_bool j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager);
static opj_bool j2k_update_image_data (opj_tcd_v2_t * p_tcd, OPJ_BYTE * p_data);
/*
* -----------------------------------------------------------------------
* -----------------------------------------------------------------------
@ -697,7 +707,7 @@ static opj_bool j2k_read_unk_v2 ( opj_j2k_v2_t *p_j2k,
*
* @return true if the image header is correctly copy.
*/
static opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_header_t* p_img_header);
static opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t* p_image);
static void j2k_dump_MH_info(opj_j2k_v2_t* p_j2k, FILE* out_stream);
@ -1212,9 +1222,9 @@ opj_bool j2k_read_siz_v2 (
OPJ_UINT32 l_remaining_size;
OPJ_UINT32 l_nb_tiles;
OPJ_UINT32 l_tmp;
opj_image_header_t *l_image = 00;
opj_image_t *l_image = 00;
opj_cp_v2_t *l_cp = 00;
opj_image_comp_header_t * l_img_comp = 00;
opj_image_comp_t * l_img_comp = 00;
opj_tcp_v2_t * l_current_tile_param = 00;
// preconditions
@ -1222,7 +1232,7 @@ opj_bool j2k_read_siz_v2 (
assert(p_manager != 00);
assert(p_header_data != 00);
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_cp = &(p_j2k->m_cp);
// minimum size == 39 - 3 (= minimum component parameter)
@ -1317,14 +1327,14 @@ opj_bool j2k_read_siz_v2 (
#endif /* USE_JPWL */
// Allocate the resulting image components
l_image->comps = (opj_image_comp_header_t*) opj_calloc(l_image->numcomps, sizeof(opj_image_comp_header_t));
l_image->comps = (opj_image_comp_t*) opj_calloc(l_image->numcomps, sizeof(opj_image_comp_t));
if (l_image->comps == 00){
l_image->numcomps = 0;
opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n");
return OPJ_FALSE;
}
memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_header_t));
memset(l_image->comps,0,l_image->numcomps * sizeof(opj_image_comp_t));
l_img_comp = l_image->comps;
// Read the component information
@ -1715,14 +1725,14 @@ opj_bool j2k_read_cod_v2 (
OPJ_UINT32 l_tmp;
opj_cp_v2_t *l_cp = 00;
opj_tcp_v2_t *l_tcp = 00;
opj_image_header_t *l_image = 00;
opj_image_t *l_image = 00;
/* preconditions */
assert(p_header_data != 00);
assert(p_j2k != 00);
assert(p_manager != 00);
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_cp = &(p_j2k->m_cp);
/* If we are in the first tile-part header of the current tile */
@ -1839,7 +1849,7 @@ opj_bool j2k_read_coc_v2 (
{
opj_cp_v2_t *l_cp = NULL;
opj_tcp_v2_t *l_tcp = NULL;
opj_image_header_t *l_image = NULL;
opj_image_t *l_image = NULL;
OPJ_UINT32 l_comp_room;
OPJ_UINT32 l_comp_no;
@ -1852,7 +1862,7 @@ opj_bool j2k_read_coc_v2 (
l_tcp = (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_TPH ) ? /*FIXME J2K_DEC_STATE_TPH*/
&l_cp->tcps[p_j2k->m_current_tile_number] :
p_j2k->m_specific_param.m_decoder.m_default_tcp;
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_comp_room = l_image->numcomps <= 256 ? 1 : 2;
@ -2122,7 +2132,7 @@ opj_bool j2k_read_qcc_v2( opj_j2k_v2_t *p_j2k,
assert(p_j2k != 00);
assert(p_manager != 00);
l_num_comp = p_j2k->m_image_header->numcomps;
l_num_comp = p_j2k->m_image->numcomps;
if (l_num_comp <= 256) {
if (p_header_size < 1) {
@ -2255,7 +2265,7 @@ opj_bool j2k_read_poc_v2 (
struct opj_event_mgr * p_manager)
{
OPJ_UINT32 i, l_nb_comp, l_tmp;
opj_image_header_t * l_image = 00;
opj_image_t * l_image = 00;
OPJ_UINT32 l_old_poc_nb, l_current_poc_nb, l_current_poc_remaining;
OPJ_UINT32 l_chunk_size, l_comp_room;
@ -2268,7 +2278,7 @@ opj_bool j2k_read_poc_v2 (
assert(p_j2k != 00);
assert(p_manager != 00);
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_nb_comp = l_image->numcomps;
if (l_nb_comp <= 256) {
l_comp_room = 1;
@ -2355,7 +2365,7 @@ opj_bool j2k_read_crg_v2 (
assert(p_j2k != 00);
assert(p_manager != 00);
l_nb_comp = p_j2k->m_image_header->numcomps;
l_nb_comp = p_j2k->m_image->numcomps;
if (p_header_size != l_nb_comp *4) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Error reading CRG marker\n");
@ -3562,6 +3572,7 @@ opj_bool j2k_read_sod_v2 (
return OPJ_FALSE;
}
#ifdef TODO_MSD /* FIXME */
l_cstr_index = p_j2k->cstr_index;
/* Index */
@ -3571,6 +3582,7 @@ opj_bool j2k_read_sod_v2 (
l_cstr_index->packno = 0;
}
#endif
l_current_read_size = opj_stream_read_data( p_stream,
*l_current_data + *l_tile_len,
@ -3662,7 +3674,7 @@ opj_bool j2k_read_rgn_v2 (
)
{
OPJ_UINT32 l_nb_comp;
opj_image_header_t * l_image = 00;
opj_image_t * l_image = 00;
opj_cp_v2_t *l_cp = 00;
opj_tcp_v2_t *l_tcp = 00;
@ -3673,7 +3685,7 @@ opj_bool j2k_read_rgn_v2 (
assert(p_j2k != 00);
assert(p_manager != 00);
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_nb_comp = l_image->numcomps;
if (l_nb_comp <= 256) {
@ -4857,14 +4869,14 @@ static void j2k_add_mhmarker_v2(opj_codestream_index_t *cstr_index, OPJ_UINT32 t
/* expand the list? */
if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) {
cstr_index->maxmarknum = 100 + (int) ((float) cstr_index ->maxmarknum * 1.0F);
cstr_index->marker = (opj_marker_info_t*)opj_realloc(cstr_index->marker, cstr_index->maxmarknum);
cstr_index->maxmarknum = 100 + (int) ((float) cstr_index->maxmarknum * 1.0F);
cstr_index->marker = (opj_marker_info_t*)opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t));
}
/* add the marker */
cstr_index->marker[cstr_index->marknum].type = type;
cstr_index->marker[cstr_index->marknum].pos = pos;
cstr_index->marker[cstr_index->marknum].len = len;
cstr_index->marker[cstr_index->marknum].type = (OPJ_UINT16)type;
cstr_index->marker[cstr_index->marknum].pos = (OPJ_INT32)pos;
cstr_index->marker[cstr_index->marknum].len = (OPJ_INT32)len;
cstr_index->marknum++;
}
@ -4925,18 +4937,18 @@ opj_bool j2k_end_decompress(
*/
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
opj_j2k_v2_t* p_j2k,
opj_image_header_t* p_img_header,
opj_image_t* p_image,
struct opj_event_mgr* p_manager )
{
/* preconditions */
assert(p_j2k != 00);
assert(p_stream != 00);
assert(p_img_header != 00);
assert(p_image != 00);
assert(p_manager != 00);
/* create an empty image header */
p_j2k->m_image_header = opj_image_header_create0();
if (! p_j2k->m_image_header) {
p_j2k->m_image = opj_image_create0();
if (! p_j2k->m_image) {
return OPJ_FALSE;
}
@ -4945,8 +4957,8 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
/* validation of the parameters codec */
if (! j2k_exec(p_j2k, p_j2k->m_validation_list, p_stream,p_manager)) {
opj_image_header_destroy(p_j2k->m_image_header);
p_j2k->m_image_header = NULL;
opj_image_destroy(p_j2k->m_image);
p_j2k->m_image = NULL;
return OPJ_FALSE;
}
@ -4955,14 +4967,14 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
/* read header */
if (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
opj_image_header_destroy(p_j2k->m_image_header);
p_j2k->m_image_header = NULL;
opj_image_destroy(p_j2k->m_image);
p_j2k->m_image = NULL;
return OPJ_FALSE;
}
if (! j2k_copy_img_header(p_j2k, p_img_header)){
opj_image_header_destroy(p_j2k->m_image_header);
p_j2k->m_image_header = NULL;
if (! j2k_copy_img_header(p_j2k, p_image)){
opj_image_destroy(p_j2k->m_image);
p_j2k->m_image = NULL;
return OPJ_FALSE;
}
@ -4970,37 +4982,42 @@ opj_bool j2k_read_header( struct opj_stream_private *p_stream,
return OPJ_TRUE;
}
opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_header_t* p_img_header)
opj_bool j2k_copy_img_header(opj_j2k_v2_t* p_j2k, opj_image_t* p_image)
{
OPJ_UINT16 compno;
/* preconditions */
assert(p_j2k != 00);
assert(p_img_header != 00);
assert(p_image != 00);
p_img_header->x0 = p_j2k->m_image_header->x0;
p_img_header->y0 = p_j2k->m_image_header->y0;
p_img_header->x1 = p_j2k->m_image_header->x1;
p_img_header->y1 = p_j2k->m_image_header->y1;
p_image->x0 = p_j2k->m_image->x0;
p_image->y0 = p_j2k->m_image->y0;
p_image->x1 = p_j2k->m_image->x1;
p_image->y1 = p_j2k->m_image->y1;
p_img_header->numcomps = p_j2k->m_image_header->numcomps;
p_img_header->comps = (opj_image_comp_header_t*)opj_malloc(p_img_header->numcomps * sizeof(opj_image_comp_header_t));
if (!p_img_header->comps)
p_image->numcomps = p_j2k->m_image->numcomps;
p_image->comps = (opj_image_comp_t*)opj_malloc(p_image->numcomps * sizeof(opj_image_comp_t));
if (!p_image->comps)
return OPJ_FALSE;
for (compno=0; compno < p_img_header->numcomps; compno++){
memcpy( &(p_img_header->comps[compno]),
&(p_j2k->m_image_header->comps[compno]),
sizeof(opj_image_comp_header_t));
for (compno=0; compno < p_image->numcomps; compno++){
memcpy( &(p_image->comps[compno]),
&(p_j2k->m_image->comps[compno]),
sizeof(opj_image_comp_t));
}
p_img_header->color_space = p_j2k->m_image_header->color_space;
p_img_header->icc_profile_len = p_j2k->m_image_header->icc_profile_len;
p_img_header->icc_profile_buf = (unsigned char*)opj_malloc(p_img_header->icc_profile_len);
if (!p_img_header->icc_profile_buf)
return OPJ_FALSE;
memcpy( p_img_header->icc_profile_buf,
p_j2k->m_image_header->icc_profile_buf,
p_j2k->m_image_header->icc_profile_len);
p_image->color_space = p_j2k->m_image->color_space;
p_image->icc_profile_len = p_j2k->m_image->icc_profile_len;
if (!p_image->icc_profile_len) {
p_image->icc_profile_buf = (unsigned char*)opj_malloc(p_image->icc_profile_len);
if (!p_image->icc_profile_buf)
return OPJ_FALSE;
memcpy( p_image->icc_profile_buf,
p_j2k->m_image->icc_profile_buf,
p_j2k->m_image->icc_profile_len);
}
else
p_image->icc_profile_buf = NULL;
return OPJ_TRUE;
}
@ -5267,7 +5284,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
opj_tccp_t *l_current_tccp = 00;
OPJ_UINT32 l_tccp_size;
OPJ_UINT32 l_mct_size;
opj_image_header_t * l_image;
opj_image_t * l_image;
OPJ_UINT32 l_mcc_records_size,l_mct_records_size;
opj_mct_data_t * l_src_mct_rec, *l_dest_mct_rec;
opj_simple_mcc_decorrelation_data_t * l_src_mcc_rec, *l_dest_mcc_rec;
@ -5278,7 +5295,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
assert(p_stream != 00);
assert(p_manager != 00);
l_image = p_j2k->m_image_header;
l_image = p_j2k->m_image;
l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
l_tcp = p_j2k->m_cp.tcps;
l_tccp_size = l_image->numcomps * sizeof(opj_tccp_t);
@ -5287,12 +5304,17 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
/* For each tile */
for (i=0; i<l_nb_tiles; ++i) {
/* keep the tile-compo coding parameters pointer of the current tile coding parameters*/
l_current_tccp = l_tcp->tccps;
/*Copy default coding parameters into the current tile coding parameters*/
memcpy(l_tcp, l_default_tcp, sizeof(opj_tcp_v2_t));
/* Initialize some values of the current tile coding parameters*/
l_tcp->ppt = 0;
l_tcp->ppt_data = 00;
/* Reconnect the tile-compo coding parameters pointer to the current tile coding parameters*/
l_tcp->tccps = l_current_tccp;
/* Get the mct_decoding_matrix of the dflt_tile_cp and copy them into the current tile cp*/
if (l_default_tcp->m_mct_decoding_matrix) {
l_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(l_mct_size);
if (! l_tcp->m_mct_decoding_matrix ) {
@ -5301,6 +5323,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
memcpy(l_tcp->m_mct_decoding_matrix,l_default_tcp->m_mct_decoding_matrix,l_mct_size);
}
/* Get the mct_record of the dflt_tile_cp and copy them into the current tile cp*/
l_mct_records_size = l_default_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t);
l_tcp->m_mct_records = (opj_mct_data_t*)opj_malloc(l_mct_records_size);
if (! l_tcp->m_mct_records) {
@ -5308,6 +5331,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
}
memcpy(l_tcp->m_mct_records, l_default_tcp->m_mct_records,l_mct_records_size);
/* Copy the mct record data from dflt_tile_cp to the current tile*/
l_src_mct_rec = l_default_tcp->m_mct_records;
l_dest_mct_rec = l_tcp->m_mct_records;
@ -5326,6 +5350,7 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
++l_dest_mct_rec;
}
/* Get the mcc_record of the dflt_tile_cp and copy them into the current tile cp*/
l_mcc_records_size = l_default_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t);
l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*) opj_malloc(l_mcc_records_size);
if (! l_tcp->m_mcc_records) {
@ -5333,8 +5358,10 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
}
memcpy(l_tcp->m_mcc_records,l_default_tcp->m_mcc_records,l_mcc_records_size);
/* Copy the mcc record data from dflt_tile_cp to the current tile*/
l_src_mcc_rec = l_default_tcp->m_mcc_records;
l_dest_mcc_rec = l_tcp->m_mcc_records;
for (j=0;j<l_default_tcp->m_nb_max_mcc_records;++j) {
if (l_src_mcc_rec->m_decorrelation_array) {
@ -5351,10 +5378,14 @@ opj_bool j2k_copy_default_tcp_and_create_tcd
++l_dest_mcc_rec;
}
/* Copy all the dflt_tile_compo_cp to the current tile cp */
memcpy(l_current_tccp,l_default_tcp->tccps,l_tccp_size);
/* Move to next tile cp*/
++l_tcp;
}
/* Create the current tile decoder*/
p_j2k->m_tcd = (opj_tcd_v2_t*)tcd_create_v2(OPJ_TRUE); // FIXME why a cast ?
if (! p_j2k->m_tcd ) {
return OPJ_FALSE;
@ -5707,6 +5738,17 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
if (! j2k_read_sod_v2(p_j2k, p_stream, p_manager)) {
return OPJ_FALSE;
}
if (! p_j2k->m_specific_param.m_decoder.m_can_decode){
/* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Stream too short\n");
return OPJ_FALSE;
}
/* Read 2 bytes from buffer as the new marker ID */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
}
}
else {
/* Indicate we will try to read a new tile-part header*/
@ -5733,7 +5775,7 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
}
}
/* FIXME ???*/
/* FIXME DOC ???*/
if ( ! p_j2k->m_specific_param.m_decoder.m_can_decode) {
l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number;
l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
@ -5755,6 +5797,9 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k,
return OPJ_FALSE;
}
opj_event_msg_v2(p_manager, EVT_INFO, "Header of tile %d / %d has been read.\n",
p_j2k->m_current_tile_number +1, p_j2k->m_cp.th * p_j2k->m_cp.tw);
*p_tile_index = p_j2k->m_current_tile_number;
*p_go_on = OPJ_TRUE;
*p_data_size = tcd_get_decoded_tile_size(p_j2k->m_tcd);
@ -5840,6 +5885,129 @@ opj_bool j2k_decode_tile ( opj_j2k_v2_t * p_j2k,
}
opj_bool j2k_update_image_data (opj_tcd_v2_t * p_tcd, OPJ_BYTE * p_data)
{
OPJ_UINT32 i,j,k = 0;
OPJ_UINT32 l_width,l_height,l_offset_x,l_offset_y;
opj_image_comp_t * l_img_comp = 00;
opj_tcd_tilecomp_v2_t * l_tilec = 00;
opj_image_t * l_image = 00;
OPJ_UINT32 l_size_comp, l_remaining;
OPJ_UINT32 l_dest_stride;
OPJ_INT32 * l_dest_ptr;
opj_tcd_resolution_v2_t* l_res= 00;
l_tilec = p_tcd->tcd_image->tiles->comps;
l_image = p_tcd->image;
l_img_comp = l_image->comps;
for (i=0;i<p_tcd->image->numcomps;++i) {
if (!l_img_comp->data) {
l_img_comp->data = (OPJ_INT32*) opj_malloc(l_img_comp->w * l_img_comp->h * sizeof(OPJ_INT32));
if (! l_img_comp->data) {
return OPJ_FALSE;
}
memset(l_img_comp->data,0,l_img_comp->w * l_img_comp->h * sizeof(OPJ_INT32));
}
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
if (l_remaining) {
++l_size_comp;
}
if (l_size_comp == 3) {
l_size_comp = 4;
}
l_width = (l_res->x1 - l_res->x0);
l_height = (l_res->y1 - l_res->y0);
l_dest_stride = (l_img_comp->w) - l_width;
l_offset_x = int_ceildivpow2(l_img_comp->x0, l_img_comp->factor);
l_offset_y = int_ceildivpow2(l_img_comp->y0, l_img_comp->factor);
l_dest_ptr = l_img_comp->data + (l_res->x0 - l_offset_x) + (l_res->y0 - l_offset_y) * l_img_comp->w;
switch (l_size_comp) {
case 1:
{
OPJ_CHAR * l_src_ptr = (OPJ_CHAR*) p_data;
if (l_img_comp->sgnd) {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++));
}
l_dest_ptr += l_dest_stride;
}
}
else {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (OPJ_INT32) ((*(l_src_ptr++))&0xff);
}
l_dest_ptr += l_dest_stride;
}
}
p_data = (OPJ_BYTE*) l_src_ptr;
}
break;
case 2:
{
OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_data;
if (l_img_comp->sgnd) {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = *(l_src_ptr++);
}
l_dest_ptr += l_dest_stride;
}
}
else {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xffff;
}
l_dest_ptr += l_dest_stride;
}
}
p_data = (OPJ_BYTE*) l_src_ptr;
}
break;
case 4:
{
OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_data;
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (*(l_src_ptr++));
}
l_dest_ptr += l_dest_stride;
}
p_data = (OPJ_BYTE*) l_src_ptr;
}
break;
}
++l_img_comp;
++l_tilec;
}
return OPJ_TRUE;
}
/**
* Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
*
@ -6011,6 +6179,7 @@ opj_codestream_index_t* j2k_create_cstr_index(void)
return NULL;
cstr_index->maxmarknum = 100;
cstr_index->marknum = 0;
cstr_index->marker = (opj_marker_info_t*)
opj_calloc(cstr_index->maxmarknum, sizeof(opj_marker_info_t));
if (!cstr_index-> marker)
@ -6053,7 +6222,7 @@ opj_bool j2k_read_SPCod_SPCoc(
p_j2k->m_specific_param.m_decoder.m_default_tcp;
/* precondition again */
assert(compno < p_j2k->m_image_header->numcomps);
assert(compno < p_j2k->m_image->numcomps);
l_tccp = &l_tcp->tccps[compno];
l_current_ptr = p_header_data;
@ -6163,7 +6332,7 @@ void j2k_copy_tile_component_parameters( opj_j2k_v2_t *p_j2k )
l_copied_tccp = l_ref_tccp + 1;
l_prc_size = l_ref_tccp->numresolutions * sizeof(OPJ_UINT32);
for (i=1; i<p_j2k->m_image_header->numcomps; ++i) {
for (i=1; i<p_j2k->m_image->numcomps; ++i) {
l_copied_tccp->numresolutions = l_ref_tccp->numresolutions;
l_copied_tccp->cblkw = l_ref_tccp->cblkw;
l_copied_tccp->cblkh = l_ref_tccp->cblkh;
@ -6212,7 +6381,7 @@ opj_bool j2k_read_SQcd_SQcc(
p_j2k->m_specific_param.m_decoder.m_default_tcp;
// precondition again
assert(p_comp_no < p_j2k->m_image_header->numcomps);
assert(p_comp_no < p_j2k->m_image->numcomps);
l_tccp = &l_tcp->tccps[p_comp_no];
l_current_ptr = p_header_data;
@ -6328,7 +6497,7 @@ void j2k_copy_tile_quantization_parameters( opj_j2k_v2_t *p_j2k )
l_copied_tccp = l_ref_tccp + 1;
l_size = J2K_MAXBANDS * sizeof(opj_stepsize_t);
for (i=1;i<p_j2k->m_image_header->numcomps;++i) {
for (i=1;i<p_j2k->m_image->numcomps;++i) {
l_copied_tccp->qntsty = l_ref_tccp->qntsty;
l_copied_tccp->numgbits = l_ref_tccp->numgbits;
memcpy(l_copied_tccp->stepsizes,l_ref_tccp->stepsizes,l_size);
@ -6354,8 +6523,8 @@ void j2k_dump (opj_j2k_v2_t* p_j2k, OPJ_INT32 flag, FILE* out_stream)
/* Dump the image_header */
if (flag & OPJ_IMG_INFO){
if (p_j2k->m_image_header)
j2k_dump_image_header(p_j2k->m_image_header, 0, out_stream);
if (p_j2k->m_image)
j2k_dump_image_header(p_j2k->m_image, 0, out_stream);
}
/* Dump the codestream info from main header */
@ -6432,7 +6601,7 @@ void j2k_dump_MH_info(opj_j2k_v2_t* p_j2k, FILE* out_stream)
if (l_default_tile)
{
OPJ_INT32 compno;
OPJ_INT32 numcomps = p_j2k->m_image_header->numcomps;
OPJ_INT32 numcomps = p_j2k->m_image->numcomps;
fprintf(out_stream, "\t default tile {\n");
fprintf(out_stream, "\t\t csty=%#x\n", l_default_tile->csty);
@ -6490,7 +6659,7 @@ void j2k_dump_MH_info(opj_j2k_v2_t* p_j2k, FILE* out_stream)
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
*@param out_stream output stream where dump the elements.
*/
void j2k_dump_image_header(opj_image_header_t* img_header, opj_bool dev_dump_flag, FILE* out_stream)
void j2k_dump_image_header(opj_image_t* img_header, opj_bool dev_dump_flag, FILE* out_stream)
{
char tab[2];
@ -6526,7 +6695,7 @@ void j2k_dump_image_header(opj_image_header_t* img_header, opj_bool dev_dump_fla
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
*@param out_stream output stream where dump the elements.
*/
void j2k_dump_image_comp_header(opj_image_comp_header_t* comp_header, opj_bool dev_dump_flag, FILE* out_stream)
void j2k_dump_image_comp_header(opj_image_comp_t* comp_header, opj_bool dev_dump_flag, FILE* out_stream)
{
char tab[3];
@ -6556,11 +6725,11 @@ void j2k_dump_image_comp_header(opj_image_comp_header_t* comp_header, opj_bool d
opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_v2_t* p_j2k)
{
OPJ_UINT16 compno;
OPJ_UINT16 numcomps = p_j2k->m_image_header->numcomps;
OPJ_UINT16 numcomps = p_j2k->m_image->numcomps;
opj_tcp_v2_t *l_default_tile;
opj_codestream_info_v2_t* cstr_info = (opj_codestream_info_v2_t*) opj_calloc(1,sizeof(opj_codestream_info_v2_t));
cstr_info->nbcomps = p_j2k->m_image_header->numcomps;
cstr_info->nbcomps = p_j2k->m_image->numcomps;
cstr_info->tx0 = p_j2k->m_cp.tx0;
cstr_info->ty0 = p_j2k->m_cp.ty0;
@ -6645,3 +6814,112 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_v2_t* p_j2k)
return l_cstr_index;
}
/**
* Reads the tiles.
*/
opj_bool j2k_decode_tiles ( opj_j2k_v2_t *p_j2k,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager)
{
opj_bool l_go_on = OPJ_TRUE;
OPJ_UINT32 l_current_tile_no;
OPJ_UINT32 l_data_size,l_max_data_size;
OPJ_INT32 l_tile_x0,l_tile_y0,l_tile_x1,l_tile_y1;
OPJ_UINT32 l_nb_comps;
OPJ_BYTE * l_current_data;
l_current_data = (OPJ_BYTE*)opj_malloc(1000);
if (! l_current_data) {
return OPJ_FALSE;
}
l_max_data_size = 1000;
while (OPJ_TRUE) {
if (! j2k_read_tile_header( p_j2k,
&l_current_tile_no,
&l_data_size,
&l_tile_x0, &l_tile_y0,
&l_tile_x1, &l_tile_y1,
&l_nb_comps,
&l_go_on,
p_stream,
p_manager)) {
return OPJ_FALSE;
}
if (! l_go_on) {
break;
}
if (l_data_size > l_max_data_size) {
l_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_data_size);
if (! l_current_data) {
return OPJ_FALSE;
}
l_max_data_size = l_data_size;
}
if (! j2k_decode_tile(p_j2k,l_current_tile_no,l_current_data,l_data_size,p_stream,p_manager)) {
opj_free(l_current_data);
return OPJ_FALSE;
}
opj_event_msg_v2(p_manager, EVT_INFO, "Tile %d/%d has been decode.\n", l_current_tile_no +1, p_j2k->m_cp.th * p_j2k->m_cp.tw);
if (! j2k_update_image_data(p_j2k->m_tcd,l_current_data)) {
opj_free(l_current_data);
return OPJ_FALSE;
}
opj_event_msg_v2(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no + 1);
}
opj_free(l_current_data);
return OPJ_TRUE;
}
/**
* Sets up the procedures to do on decoding data. Developpers wanting to extend the library can add their own reading procedures.
*/
void j2k_setup_decoding (opj_j2k_v2_t *p_j2k)
{
// preconditions
assert(p_j2k != 00);
opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(void*)j2k_decode_tiles);
/* DEVELOPER CORNER, add your custom procedures */
}
/**
* Decodes the tiles of the stream.
*/
opj_bool j2k_decode_v2( opj_j2k_v2_t * p_j2k,
opj_stream_private_t * p_stream,
opj_image_t * p_image,
opj_event_mgr_t * p_manager)
{
OPJ_UINT32 compno;
/* customization of the decoding */
j2k_setup_decoding(p_j2k);
/* write header */
if (! j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
opj_image_destroy(p_j2k->m_image);
p_j2k->m_image = NULL;
return OPJ_FALSE;
}
for (compno = 0; compno < p_image->numcomps; compno++) {
p_image->comps[compno].data = p_j2k->m_image->comps[compno].data;
p_j2k->m_image->comps[compno].data = NULL;
}
return OPJ_TRUE /*p_j2k->m_image*/;
}

View File

@ -553,6 +553,7 @@ typedef struct opj_cp_v2
/** tile coding parameters */
opj_tcp_v2_t *tcps;
union
{
opj_decoding_param_t m_dec;
@ -756,12 +757,9 @@ typedef struct opj_j2k_v2
}
m_specific_param;
/** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number;
/** pointer to the encoded / decoded image */
//opj_image_t *m_image;
opj_image_header_t* m_image_header;
opj_image_t* m_image;
/** Coding parameters */
opj_cp_v2_t m_cp;
@ -775,6 +773,9 @@ typedef struct opj_j2k_v2
/** helper used to write the index file */
opj_codestream_index_t *cstr_index;
/** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number;
/** the current tile coder/decoder **/
struct opj_tcd_v2 * m_tcd;
//opj_tcd_v2_t * m_tcd;
@ -890,7 +891,7 @@ opj_bool j2k_end_decompress(opj_j2k_v2_t *j2k, struct opj_stream_private *cio, s
*/
opj_bool j2k_read_header( struct opj_stream_private *p_stream,
opj_j2k_v2_t* p_j2k,
opj_image_header_t* p_img_header,
opj_image_t* p_image,
struct opj_event_mgr* p_manager );
@ -981,7 +982,7 @@ void j2k_dump (opj_j2k_v2_t* p_j2k, OPJ_INT32 flag, FILE* out_stream);
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
*@param out_stream output stream where dump the elements.
*/
void j2k_dump_image_header(opj_image_header_t* img_header, opj_bool dev_dump_flag, FILE* out_stream);
void j2k_dump_image_header(opj_image_t* image, opj_bool dev_dump_flag, FILE* out_stream);
/**
* Dump a component image header structure.
@ -990,7 +991,7 @@ void j2k_dump_image_header(opj_image_header_t* img_header, opj_bool dev_dump_fla
*@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function
*@param out_stream output stream where dump the elements.
*/
void j2k_dump_image_comp_header(opj_image_comp_header_t* comp_header, opj_bool dev_dump_flag, FILE* out_stream);
void j2k_dump_image_comp_header(opj_image_comp_t* comp, opj_bool dev_dump_flag, FILE* out_stream);
/**
* Get the codestream info from a JPEG2000 codec.
@ -1010,6 +1011,14 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_v2_t* p_j2k);
*/
opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_v2_t* p_j2k);
/**
* Decode an image from a JPEG-2000 codestream
* @param j2k J2K decompressor handle
* @param cio Input buffer stream
* @param cstr_info Codestream information structure if required, NULL otherwise
* @return Returns a decoded image if successful, returns NULL otherwise
*/
opj_bool j2k_decode_v2(opj_j2k_v2_t *j2k, struct opj_stream_private *cio, opj_image_t* p_image, opj_event_mgr_t * p_manager);
#endif /* __J2K_H */

View File

@ -191,7 +191,7 @@ Apply collected palette data
@param color Collector for profile, cdef and pclr data
@param image
*/
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image);
static void jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color);
/**
Collect palette data
@param jp2 JP2 handle
@ -763,16 +763,17 @@ static void free_color_data(opj_jp2_color_t *color)
if(color->icc_profile_buf) opj_free(color->icc_profile_buf);
}
static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image)
static void jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
{
opj_image_comp_t *old_comps, *new_comps;
unsigned char *channel_size, *channel_sign;
unsigned int *entries;
OPJ_BYTE *channel_size, *channel_sign;
OPJ_UINT32 *entries;
opj_jp2_cmap_comp_t *cmap;
int *src, *dst;
unsigned int j, max;
unsigned short i, nr_channels, cmp, pcol;
int k, top_k;
OPJ_INT32 *src, *dst;
OPJ_UINT32 j, max;
OPJ_UINT16 i, nr_channels, cmp, pcol;
OPJ_INT32 k, top_k;
channel_size = color->jp2_pclr->channel_size;
channel_sign = color->jp2_pclr->channel_sign;
@ -782,50 +783,52 @@ static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image)
old_comps = image->comps;
new_comps = (opj_image_comp_t*)
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
opj_malloc(nr_channels * sizeof(opj_image_comp_t));
for(i = 0; i < nr_channels; ++i)
{
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
new_comps[pcol] = old_comps[cmp];
new_comps[pcol] = old_comps[cmp];
/* Direct use */
if(cmap[i].mtyp == 0){
old_comps[cmp].data = NULL; continue;
}
/* Palette mapping: */
new_comps[pcol].data = (int*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int));
new_comps[pcol].prec = channel_size[i];
new_comps[pcol].sgnd = channel_sign[i];
}
if(cmap[i].mtyp == 0) /* Direct use */
{
old_comps[cmp].data = NULL; continue;
}
/* Palette mapping: */
new_comps[pcol].data = (int*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(int));
new_comps[pcol].prec = channel_size[i];
new_comps[pcol].sgnd = channel_sign[i];
}
top_k = color->jp2_pclr->nr_entries - 1;
for(i = 0; i < nr_channels; ++i)
{
/* Direct use: */
if(cmap[i].mtyp == 0) continue;
for(i = 0; i < nr_channels; ++i) {
/* Direct use: */
if(cmap[i].mtyp == 0) continue;
/* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
src = old_comps[cmp].data;
dst = new_comps[pcol].data;
max = new_comps[pcol].w * new_comps[pcol].h;
/* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
src = old_comps[cmp].data;
dst = new_comps[pcol].data;
max = new_comps[pcol].w * new_comps[pcol].h;
for(j = 0; j < max; ++j)
{
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
/* The colour */
dst[j] = entries[k * nr_channels + pcol];
}
}
for(j = 0; j < max; ++j)
{
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
/* The colour */
dst[j] = entries[k * nr_channels + pcol];
}
}
max = image->numcomps;
for(i = 0; i < max; ++i)
{
if(old_comps[i].data) opj_free(old_comps[i].data);
}
for(i = 0; i < max; ++i) {
if(old_comps[i].data) opj_free(old_comps[i].data);
}
opj_free(old_comps);
image->comps = new_comps;
image->numcomps = nr_channels;
@ -834,6 +837,7 @@ static void jp2_apply_pclr(opj_jp2_color_t *color, opj_image_t *image)
}/* apply_pclr() */
static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
opj_jp2_box_t *box, opj_jp2_color_t *color)
{
@ -1062,32 +1066,33 @@ static opj_bool jp2_read_cmap_v2( opj_jp2_v2_t * jp2,
static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
{
opj_jp2_cdef_info_t *info;
int color_space;
unsigned short i, n, cn, typ, asoc, acn;
OPJ_INT32 color_space;
OPJ_UINT16 i, n, cn, typ, asoc, acn;
color_space = image->color_space;
info = color->jp2_cdef->info;
n = color->jp2_cdef->n;
for(i = 0; i < n; ++i)
{
/* WATCH: acn = asoc - 1 ! */
if((asoc = info[i].asoc) == 0) continue;
{
/* WATCH: acn = asoc - 1 ! */
if((asoc = info[i].asoc) == 0) continue;
cn = info[i].cn; typ = info[i].typ; acn = asoc - 1;
cn = info[i].cn; typ = info[i].typ; acn = asoc - 1;
if(cn != acn)
{
opj_image_comp_t saved;
if(cn != acn)
{
opj_image_comp_t saved;
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_t));
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
info[i].asoc = cn + 1;
info[acn].asoc = info[acn].cn + 1;
}
}
info[i].asoc = cn + 1;
info[acn].asoc = info[acn].cn + 1;
}
}
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
opj_free(color->jp2_cdef); color->jp2_cdef = NULL;
@ -1467,7 +1472,7 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
if( !color.jp2_pclr->cmap)
jp2_free_pclr(&color);
else
jp2_apply_pclr(&color, image);
jp2_apply_pclr(image, &color);
}
if(color.icc_profile_buf)
{
@ -1479,6 +1484,48 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
}/* opj_jp2_decode() */
opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2,
struct opj_stream_private *cio,
opj_image_t* p_image,
struct opj_event_mgr * p_manager)
{
/* J2K decoding */
if( j2k_decode_v2(jp2->j2k, cio, p_image, p_manager) ) {
opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to decode J2K image\n");
return OPJ_FALSE;
}
/* Set Image Color Space */
if (jp2->enumcs == 16)
p_image->color_space = CLRSPC_SRGB;
else if (jp2->enumcs == 17)
p_image->color_space = CLRSPC_GRAY;
else if (jp2->enumcs == 18)
p_image->color_space = CLRSPC_SYCC;
else
p_image->color_space = CLRSPC_UNKNOWN;
/* Apply the color space if needed */
if(jp2->color.jp2_cdef) {
jp2_apply_cdef(p_image, &(jp2->color));
}
if(jp2->color.jp2_pclr) {
/* Part 1, I.5.3.4: Either both or none : */
if( !jp2->color.jp2_pclr->cmap)
jp2_free_pclr(&(jp2->color));
else
jp2_apply_pclr(p_image, &(jp2->color));
}
if(jp2->color.icc_profile_buf) {
p_image->icc_profile_buf = jp2->color.icc_profile_buf;
p_image->icc_profile_len = jp2->color.icc_profile_len;
}
return OPJ_TRUE;
}
void jp2_write_jp2h(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_jp2_box_t box;
@ -2390,7 +2437,7 @@ static opj_bool jp2_read_boxhdr_char(
*/
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
opj_jp2_v2_t *jp2,
opj_image_header_t* p_img_header,
opj_image_t* p_image,
struct opj_event_mgr * p_manager
)
{
@ -2417,7 +2464,7 @@ opj_bool jp2_read_header( struct opj_stream_private *p_stream,
return j2k_read_header( p_stream,
jp2->j2k,
p_img_header,
p_image,
p_manager);
}

View File

@ -285,6 +285,20 @@ Decode an image from a JPEG-2000 file stream
@return Returns a decoded image if successful, returns NULL otherwise
*/
opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio, opj_codestream_info_t *cstr_info);
/**
* Decode an image from a JPEG-2000 file stream
* @param jp2 JP2 decompressor handle
* @param cio Input buffer stream
* @param cstr_info Codestream information structure if required, NULL otherwise
* @return Returns a decoded image if successful, returns NULL otherwise
*/
opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2,
struct opj_stream_private *cio,
opj_image_t* p_image,
struct opj_event_mgr * p_manager);
/**
Creates a JP2 compression structure
@param cinfo Codec context info
@ -334,7 +348,7 @@ opj_bool jp2_end_decompress(opj_jp2_v2_t *jp2, struct opj_stream_private *cio, s
*/
opj_bool jp2_read_header( struct opj_stream_private *p_stream,
opj_jp2_v2_t *jp2,
opj_image_header_t * p_img_header,
opj_image_t * p_img_header,
struct opj_event_mgr * p_manager
);

View File

@ -40,12 +40,13 @@ typedef struct opj_decompression
/** Main header reading function handler*/
opj_bool (* opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
opj_image_header_t *p_img_header,
opj_image_t *p_image,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
opj_image_t* (* opj_decode) ( void * p_codec,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
opj_bool (* opj_decode) ( void * p_codec,
struct opj_stream_private *p_cio,
opj_image_t *p_image,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
opj_bool (*opj_read_tile_header)( void * p_codec,
OPJ_UINT32 * p_tile_index,
@ -235,20 +236,26 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
l_info->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;
l_info->m_codec_data.m_decompression.opj_decode =
(opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
(opj_bool (*) ( void *,
struct opj_stream_private *,
opj_image_t*, struct opj_event_mgr * )) j2k_decode_v2;
l_info->m_codec_data.m_decompression.opj_end_decompress =
(opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress;
(opj_bool (*) ( void *,
struct opj_stream_private *,
struct opj_event_mgr *)) j2k_end_decompress;
l_info->m_codec_data.m_decompression.opj_read_header =
(opj_bool (*) ( struct opj_stream_private *,
void *,
opj_image_header_t *,
opj_image_t *,
struct opj_event_mgr * )) j2k_read_header;
l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
l_info->m_codec_data.m_decompression.opj_destroy =
(void (*) (void *))j2k_destroy;
l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
l_info->m_codec_data.m_decompression.opj_setup_decoder =
(void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
l_info->m_codec_data.m_decompression.opj_read_tile_header =
(opj_bool (*) ( void *,
@ -278,14 +285,18 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
case CODEC_JP2:
/* get a JP2 decoder handle */
l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode; // TODO MSD
l_info->m_codec_data.m_decompression.opj_decode =
(opj_bool (*) ( void *,
struct opj_stream_private *,
opj_image_t*,
struct opj_event_mgr * )) opj_jp2_decode_v2;
l_info->m_codec_data.m_decompression.opj_end_decompress = (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
l_info->m_codec_data.m_decompression.opj_read_header = (opj_bool (*) (
struct opj_stream_private *,
void *,
opj_image_header_t *,
opj_image_t *,
struct opj_event_mgr * )) jp2_read_header;
l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
@ -695,7 +706,7 @@ opj_bool OPJ_CALLCONV opj_read_header (
opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
opj_codec_t *p_codec,
opj_image_header_t *p_img_header )
opj_image_t *p_image )
{
if (p_codec && p_cio) {
opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
@ -709,7 +720,7 @@ opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
return l_info->m_codec_data.m_decompression.opj_read_header(
l_cio,
l_info->m_codec,
p_img_header,
p_image,
l_info->m_event_mgr);
}
@ -906,3 +917,41 @@ opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
return NULL;
}
opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_info,
opj_stream_t *cio,
opj_image_t* p_image)
{
if (p_info && cio) {
opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
opj_stream_private_t * l_cio = (opj_stream_private_t *) cio;
if (! l_info->is_decompressor) {
return OPJ_FALSE;
}
return l_info->m_codec_data.m_decompression.opj_decode( l_info->m_codec,
l_cio,
p_image,
l_info->m_event_mgr);
}
return OPJ_FALSE;
}
opj_bool OPJ_CALLCONV opj_end_decompress (opj_codec_t *p_codec,opj_stream_t *p_cio)
{
if (p_codec && p_cio) {
opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
opj_stream_private_t * l_cio = (opj_stream_private_t *) p_cio;
if (! l_info->is_decompressor) {
return OPJ_FALSE;
}
return l_info->m_codec_data.m_decompression.opj_end_decompress( l_info->m_codec,
l_cio,
l_info->m_event_mgr);
}
return OPJ_FALSE;
}

View File

@ -563,29 +563,29 @@ Defines a single image component
*/
typedef struct opj_image_comp {
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
int dx;
OPJ_UINT32 dx;
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dy;
OPJ_UINT32 dy;
/** data width */
int w;
OPJ_UINT32 w;
/** data height */
int h;
OPJ_UINT32 h;
/** x component offset compared to the whole image */
int x0;
OPJ_UINT32 x0;
/** y component offset compared to the whole image */
int y0;
OPJ_UINT32 y0;
/** precision */
int prec;
OPJ_UINT32 prec;
/** image depth in bits */
int bpp;
OPJ_UINT32 bpp;
/** signed (1) / unsigned (0) */
int sgnd;
OPJ_UINT32 sgnd;
/** number of decoded resolution */
int resno_decoded;
OPJ_UINT32 resno_decoded;
/** number of division by 2 of the out image compared to the original size of image */
int factor;
OPJ_UINT32 factor;
/** image component data */
int *data;
OPJ_INT32 *data;
} opj_image_comp_t;
/**
@ -601,15 +601,15 @@ typedef struct opj_image {
/** Ysiz: height of the reference grid */
OPJ_UINT32 y1;
/** number of components in the image */
OPJ_UINT16 numcomps;
OPJ_UINT32 numcomps;
/** color space: sRGB, Greyscale or YUV */
OPJ_COLOR_SPACE color_space;
/** image components */
opj_image_comp_t *comps;
/** 'restricted' ICC profile */
unsigned char *icc_profile_buf;
OPJ_BYTE *icc_profile_buf;
/** size of ICC profile */
int icc_profile_len;
OPJ_INT32 icc_profile_len;
} opj_image_t;
@ -639,58 +639,6 @@ typedef struct opj_image_comptparm {
/**
Defines a single image component characteristics (uses in new API)
*/
typedef struct opj_image_comp_header {
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
int dx;
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dy;
/** data width */
int w;
/** data height */
int h;
/** x component offset compared to the whole image */
int x0;
/** y component offset compared to the whole image */
int y0;
/** precision */
int prec;
/** image depth in bits */
int bpp;
/** signed (1) / unsigned (0) */
int sgnd;
/** number of decoded resolution */
int resno_decoded;
/** number of division by 2 of the out image compared to the original size of image */
int factor;
} opj_image_comp_header_t;
/**
Defines image characteristics (uses in new API)
*/
typedef struct opj_image_header {
/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
OPJ_UINT32 x0;
/** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
OPJ_UINT32 y0;
/** Xsiz: width of the reference grid */
OPJ_UINT32 x1;
/** Ysiz: height of the reference grid */
OPJ_UINT32 y1;
/** number of components in the image */
OPJ_UINT16 numcomps;
/** color space: sRGB, Greyscale or YUV */
OPJ_COLOR_SPACE color_space;
/** image components */
opj_image_comp_header_t *comps;
/** 'restricted' ICC profile */
unsigned char *icc_profile_buf;
/** size of ICC profile */
int icc_profile_len;
} opj_image_header_t;
/*
@ -1036,19 +984,12 @@ Create an image
OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
/**
Deallocate any resources associated with an image
@param image image to be destroyed
*/
* Deallocate any resources associated with an image
* @param image image to be destroyed
*/
OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
/**
* Deallocate any resources associated with an image header
*
* @param image_header image header to be destroyed
*/
OPJ_API void OPJ_CALLCONV opj_image_header_destroy(opj_image_header_t *image_header);
/*
==========================================================
stream functions definitions
@ -1320,13 +1261,13 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info
*
* @param p_cio the jpeg2000 stream.
* @param p_codec the jpeg2000 codec to read.
* @param p_image header of the image hold in the codestream.
* @param p_image the image structure initialized with the characteristics of encoded image.
*
* @return true if the main header of the codestream and the JP2 header is correctly read.
*/
OPJ_API opj_bool OPJ_CALLCONV opj_read_header ( opj_stream_t *p_cio,
opj_codec_t *p_codec,
opj_image_header_t * p_img_header);
opj_image_t *p_image);
/**
* Destroy a decompressor handle
@ -1458,6 +1399,19 @@ OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_cod
*/
OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
/**
Decode an image from a JPEG-2000 codestream
@param dinfo decompressor handle
@param cio Input buffer stream
@return Returns a decoded image if successful, returns NULL otherwise
*/
OPJ_API opj_bool OPJ_CALLCONV opj_decode_v2(opj_codec_t *p_decompressor,
opj_stream_t * cio,
opj_image_t *p_image);
OPJ_API opj_bool OPJ_CALLCONV opj_end_decompress ( opj_codec_t *p_codec,
opj_stream_t *p_cio);
#ifdef __cplusplus
}

View File

@ -92,7 +92,7 @@ static opj_bool pi_next_cprl(opj_pi_iterator_t * pi);
* @param p_resolutions pointer to an area corresponding to the one described above.
*/
void get_all_encoding_parameters(
const opj_image_header_t *p_image,
const opj_image_t *p_image,
const opj_cp_v2_t *p_cp,
OPJ_UINT32 tileno,
OPJ_INT32 * p_tx0,
@ -115,11 +115,9 @@ void get_all_encoding_parameters(
* @param p_cp the coding parameters.
* @param p_tile_no the index of the tile from which creating the packet iterator.
*/
opj_pi_iterator_t * pi_create(
const opj_image_header_t *image,
opj_pi_iterator_t * pi_create( const opj_image_t *image,
const opj_cp_v2_t *cp,
OPJ_UINT32 tileno
);
OPJ_UINT32 tileno );
void pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
void pi_update_decode_poc (opj_pi_iterator_t * p_pi,opj_tcp_v2_t * p_tcp,OPJ_UINT32 p_max_precision,OPJ_UINT32 p_max_res);
@ -596,8 +594,7 @@ opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno
}
opj_pi_iterator_t *pi_create_decode_v2(
opj_image_header_t *p_image,
opj_pi_iterator_t *pi_create_decode_v2( opj_image_t *p_image,
opj_cp_v2_t *p_cp,
OPJ_UINT32 p_tile_no
)
@ -624,7 +621,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
opj_tcp_v2_t *l_tcp = 00;
const opj_tccp_t *l_tccp = 00;
opj_pi_comp_t *l_current_comp = 00;
opj_image_comp_header_t * l_img_comp = 00;
opj_image_comp_t * l_img_comp = 00;
opj_pi_iterator_t * l_current_pi = 00;
OPJ_UINT32 * l_encoding_value_ptr = 00;
@ -741,7 +738,7 @@ opj_pi_iterator_t *pi_create_decode_v2(
(pino = 1 ; pino<l_bound ; ++pino )
{
opj_pi_comp_t *l_current_comp = l_current_pi->comps;
opj_image_comp_header_t * l_img_comp = p_image->comps;
opj_image_comp_t * l_img_comp = p_image->comps;
l_tccp = l_tcp->tccps;
l_current_pi->tx0 = l_tx0;
@ -1242,7 +1239,7 @@ opj_bool pi_create_encode( opj_pi_iterator_t *pi, opj_cp_t *cp,int tileno, int p
* @param p_resolutions pointer to an area corresponding to the one described above.
*/
void get_all_encoding_parameters(
const opj_image_header_t *p_image,
const opj_image_t *p_image,
const opj_cp_v2_t *p_cp,
OPJ_UINT32 tileno,
OPJ_INT32 * p_tx0,
@ -1262,7 +1259,7 @@ void get_all_encoding_parameters(
// pointers
const opj_tcp_v2_t *tcp = 00;
const opj_tccp_t * l_tccp = 00;
const opj_image_comp_header_t * l_img_comp = 00;
const opj_image_comp_t * l_img_comp = 00;
// to store l_dx, l_dy, w and h for each resolution and component.
OPJ_UINT32 * lResolutionPtr;
@ -1374,11 +1371,9 @@ void get_all_encoding_parameters(
* @param p_cp the coding parameters.
* @param p_tile_no the index of the tile from which creating the packet iterator.
*/
opj_pi_iterator_t * pi_create(
const opj_image_header_t *image,
opj_pi_iterator_t * pi_create( const opj_image_t *image,
const opj_cp_v2_t *cp,
OPJ_UINT32 tileno
)
OPJ_UINT32 tileno )
{
// loop
OPJ_UINT32 pino, compno;

View File

@ -142,7 +142,7 @@ Create a packet iterator for Decoder
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_create_decode_v2(struct opj_image_header * image, struct opj_cp_v2 * cp, OPJ_UINT32 tileno);
opj_pi_iterator_t *pi_create_decode_v2(struct opj_image * image, struct opj_cp_v2 * cp, OPJ_UINT32 tileno);
/**

View File

@ -849,7 +849,7 @@ opj_bool t2_decode_packets_v2(
OPJ_BYTE *l_current_data = p_src;
opj_pi_iterator_t *l_pi = 00;
OPJ_UINT32 pino;
opj_image_header_t *l_image = p_t2->image;
opj_image_t *l_image = p_t2->image;
opj_cp_v2_t *l_cp = p_t2->cp;
opj_cp_v2_t *cp = p_t2->cp;
opj_tcp_v2_t *l_tcp = &(p_t2->cp->tcps[p_tile_no]);
@ -859,7 +859,7 @@ opj_bool t2_decode_packets_v2(
OPJ_UINT32 curtp = 0;
OPJ_UINT32 tp_start_packno;
opj_packet_info_t *l_pack_info = 00;
opj_image_comp_header_t* l_img_comp = 00;
opj_image_comp_t* l_img_comp = 00;
#ifdef TODO_MSD
if (p_cstr_index) {
@ -962,20 +962,19 @@ opj_t2_t* t2_create(opj_common_ptr cinfo, opj_image_t *image, opj_cp_t *cp) {
* @param p_cp Image coding parameters.
* @return a new T2 handle if successful, NULL otherwise.
*/
opj_t2_v2_t* t2_create_v2(
opj_image_header_t *p_image,
opj_cp_v2_t *p_cp)
opj_t2_v2_t* t2_create_v2( opj_image_t *p_image,
opj_cp_v2_t *p_cp)
{
/* create the tcd structure */
opj_t2_v2_t *l_t2 = (opj_t2_v2_t*)opj_malloc(sizeof(opj_t2_v2_t));
if
(!l_t2)
{
return 00;
if (!l_t2) {
return NULL;
}
memset(l_t2,0,sizeof(opj_t2_t));
l_t2->image = p_image;
l_t2->cp = p_cp;
return l_t2;
}

View File

@ -60,7 +60,7 @@ typedef struct opj_t2_v2 {
opj_common_ptr cinfo;
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
opj_image_header_t *image;
opj_image_t *image;
/** pointer to the image coding parameters */
opj_cp_v2_t *cp;
} opj_t2_v2_t;
@ -118,7 +118,7 @@ opj_bool t2_decode_packets_v2( opj_t2_v2_t *t2,
* @param p_cp Image coding parameters.
* @return a new T2 handle if successful, NULL otherwise.
*/
opj_t2_v2_t* t2_create_v2(struct opj_image_header *p_image, opj_cp_v2_t *p_cp);
opj_t2_v2_t* t2_create_v2(opj_image_t *p_image, opj_cp_v2_t *p_cp);
/**
Create a T2 handle

View File

@ -167,7 +167,7 @@ opj_tcd_v2_t* tcd_create_v2(opj_bool p_is_decoder)
opj_free(l_tcd);
return 00;
}
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_t));
memset(l_tcd->tcd_image,0,sizeof(opj_tcd_image_v2_t));
return l_tcd;
}
@ -1583,28 +1583,28 @@ void tcd_free_decode_tile(opj_tcd_t *tcd, int tileno) {
opj_bool tcd_init_v2( opj_tcd_v2_t *p_tcd,
opj_image_header_t * p_image_header,
opj_image_t * p_image,
opj_cp_v2_t * p_cp )
{
OPJ_UINT32 l_tile_comp_size;
p_tcd->image_header = p_image_header;
p_tcd->image = p_image;
p_tcd->cp = p_cp;
p_tcd->tcd_image->tiles = (opj_tcd_tile_v2_t *) opj_malloc(sizeof(opj_tcd_tile_v2_t));
p_tcd->tcd_image->tiles = (opj_tcd_tile_v2_t *) opj_malloc(sizeof(opj_tcd_tile_v2_t));
if (! p_tcd->tcd_image->tiles) {
return OPJ_FALSE;
}
memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_v2_t));
l_tile_comp_size = p_image_header->numcomps * sizeof(opj_tcd_tilecomp_v2_t);
l_tile_comp_size = p_image->numcomps * sizeof(opj_tcd_tilecomp_v2_t);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_v2_t *) opj_malloc(l_tile_comp_size);
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
}
memset( p_tcd->tcd_image->tiles->comps , 0 , l_tile_comp_size);
p_tcd->tcd_image->tiles->numcomps = p_image_header->numcomps;
p_tcd->tcd_image->tiles->numcomps = p_image->numcomps;
p_tcd->tp_pos = p_cp->m_specific_param.m_enc.m_tp_pos;
return OPJ_TRUE;
@ -1647,13 +1647,13 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
opj_tcd_tile_v2_t * l_tile = 00; \
opj_tccp_t *l_tccp = 00; \
opj_tcd_tilecomp_v2_t *l_tilec = 00; \
opj_image_comp_header_t * l_image_comp = 00; \
opj_image_comp_t * l_image_comp = 00; \
opj_tcd_resolution_v2_t *l_res = 00; \
opj_tcd_band_v2_t *l_band = 00; \
opj_stepsize_t * l_step_size = 00; \
opj_tcd_precinct_v2_t *l_current_precinct = 00; \
TYPE* l_code_block = 00; \
opj_image_header_t *l_image = 00; \
opj_image_t *l_image = 00; \
OPJ_UINT32 p,q; \
OPJ_UINT32 l_level_no; \
OPJ_UINT32 l_pdx, l_pdy; \
@ -1677,26 +1677,30 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
l_tile = p_tcd->tcd_image->tiles; \
l_tccp = l_tcp->tccps; \
l_tilec = l_tile->comps; \
l_image = p_tcd->image_header; \
l_image_comp = p_tcd->image_header->comps; \
l_image = p_tcd->image; \
l_image_comp = p_tcd->image->comps; \
\
p = p_tile_no % l_cp->tw; /* tile coordinates */ \
q = p_tile_no / l_cp->tw; \
/*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ \
\
/* 4 borders of the tile rescale on the image if necessary */ \
l_tile->x0 = int_max(l_cp->tx0 + p * l_cp->tdx, l_image->x0); \
l_tile->y0 = int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
l_tile->x1 = int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
l_tile->y1 = int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
/*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,l_tile->x1,l_tile->y1);*/\
\
/*tile->numcomps = image->numcomps; */ \
for(compno = 0; compno < l_tile->numcomps; ++compno) { \
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
\
/* border of each l_tile component (global) */ \
l_tilec->x0 = int_ceildiv(l_tile->x0, l_image_comp->dx); \
l_tilec->y0 = int_ceildiv(l_tile->y0, l_image_comp->dy); \
l_tilec->x1 = int_ceildiv(l_tile->x1, l_image_comp->dx); \
l_tilec->y1 = int_ceildiv(l_tile->y1, l_image_comp->dy); \
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/\
\
l_data_size = (l_tilec->x1 - l_tilec->x0) \
* (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 ); \
@ -1714,7 +1718,8 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_tilec->data ) { \
return OPJ_FALSE; \
} \
\
/*fprintf(stderr, "\tAllocate data of tilec (int): %d x OPJ_UINT32\n",l_data_size);*/ \
\
l_tilec->data_size = l_data_size; \
} \
else if (l_data_size > l_tilec->data_size) { \
@ -1722,7 +1727,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_tilec->data) { \
return OPJ_FALSE; \
} \
\
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->data_size, l_data_size);*/ \
l_tilec->data_size = l_data_size; \
} \
\
@ -1733,7 +1738,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_tilec->resolutions ) { \
return OPJ_FALSE; \
} \
\
/*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_v2_t): %d\n",l_data_size);*/ \
l_tilec->resolutions_size = l_data_size; \
memset(l_tilec->resolutions,0,l_data_size); \
} \
@ -1742,22 +1747,24 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_tilec->resolutions) { \
return OPJ_FALSE; \
} \
\
/*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ \
memset(((OPJ_BYTE*) l_tilec->resolutions)+l_tilec->resolutions_size,0,l_data_size - l_tilec->resolutions_size); \
l_tilec->resolutions_size = l_data_size; \
} \
\
\
l_level_no = l_tilec->numresolutions - 1; \
l_res = l_tilec->resolutions; \
l_step_size = l_tccp->stepsizes; \
if (l_tccp->qmfbid == 0) { \
l_gain_ptr = &dwt_getgain_real_v2; \
l_gain_ptr = &dwt_getgain_real_v2; \
} \
else { \
l_gain_ptr = &dwt_getgain_v2; \
l_gain_ptr = &dwt_getgain_v2; \
} \
/*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ \
\
for(resno = 0; resno < l_tilec->numresolutions; ++resno) { \
/*fprintf(stderr, "\t\tresno = %d/%d\n", resno, l_tilec->numresolutions);*/ \
OPJ_INT32 tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend; \
OPJ_UINT32 cbgwidthexpn, cbgheightexpn; \
OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \
@ -1767,17 +1774,21 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
l_res->y0 = int_ceildivpow2(l_tilec->y0, l_level_no); \
l_res->x1 = int_ceildivpow2(l_tilec->x1, l_level_no); \
l_res->y1 = int_ceildivpow2(l_tilec->y1, l_level_no); \
/*fprintf(stderr, "\t\t\tres_x0= %d, res_y0 =%d, res_x1=%d, res_y1=%d\n", l_res->x0, l_res->y0, l_res->x1, l_res->y1);*/ \
/* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ \
l_pdx = l_tccp->prcw[resno]; \
l_pdy = l_tccp->prch[resno]; \
/*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy);*/ \
/* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ \
l_tl_prc_x_start = int_floordivpow2(l_res->x0, l_pdx) << l_pdx; \
l_tl_prc_y_start = int_floordivpow2(l_res->y0, l_pdy) << l_pdy; \
l_br_prc_x_end = int_ceildivpow2(l_res->x1, l_pdx) << l_pdx; \
l_br_prc_y_end = int_ceildivpow2(l_res->y1, l_pdy) << l_pdy; \
/*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ \
\
l_res->pw = (l_res->x0 == l_res->x1) ? 0 : ((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \
l_res->ph = (l_res->y0 == l_res->y1) ? 0 : ((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \
/*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/ \
\
l_nb_precincts = l_res->pw * l_res->ph; \
l_nb_precinct_size = l_nb_precincts * sizeof(opj_tcd_precinct_v2_t); \
@ -1805,7 +1816,8 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
l_band = l_res->bands; \
\
for (bandno = 0; bandno < l_res->numbands; ++bandno) { \
OPJ_INT32 numbps; \
OPJ_INT32 numbps;\
/*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandno, l_res->numbands );*/ \
\
if (resno == 0) { \
l_band->bandno = 0 ; \
@ -1838,7 +1850,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_band->precincts) { \
return OPJ_FALSE; \
} \
\
/*fprintf(stderr, "\t\t\t\tAllocate precincts of a band (opj_tcd_precinct_v2_t): %d\n",l_nb_precinct_size); */ \
memset(l_band->precincts,0,l_nb_precinct_size); \
l_band->precincts_data_size = l_nb_precinct_size; \
} \
@ -1848,6 +1860,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_band->precincts) { \
return OPJ_FALSE; \
} \
/*fprintf(stderr, "\t\t\t\tReallocate precincts of a band (opj_tcd_precinct_v2_t): from %d to %d\n",l_band->precincts_data_size, l_nb_precinct_size);*/\
memset(((OPJ_BYTE *) l_band->precincts) + l_band->precincts_data_size,0,l_nb_precinct_size - l_band->precincts_data_size);\
l_band->precincts_data_size = l_nb_precinct_size; \
} \
@ -1859,19 +1872,31 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \
OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
/*fprintf(stderr, "\t precno=%d; bandno=%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/\
/*fprintf(stderr, "\t tlcbgxstart(=%d) + (precno(=%d) percent res->pw(=%d)) * (1 << cbgwidthexpn(=%d)) \n",tlcbgxstart,precno,l_res->pw,cbgwidthexpn);*/\
\
/* precinct size (global) */ \
/*fprintf(stderr, "\t cbgxstart=%d, l_band->x0 = %d \n",cbgxstart, l_band->x0);*/ \
\
l_current_precinct->x0 = int_max(cbgxstart, l_band->x0); \
l_current_precinct->y0 = int_max(cbgystart, l_band->y0); \
l_current_precinct->x1 = int_min(cbgxend, l_band->x1); \
l_current_precinct->y1 = int_min(cbgyend, l_band->y1); \
/*fprintf(stderr, "\t prc_x0=%d; prc_y0=%d, prc_x1=%d; prc_y1=%d\n",l_current_precinct->x0, l_current_precinct->y0 ,l_current_precinct->x1, l_current_precinct->y1);*/ \
\
tlcblkxstart = int_floordivpow2(l_current_precinct->x0, cblkwidthexpn) << cblkwidthexpn; \
/*fprintf(stderr, "\t tlcblkxstart =%d\n",tlcblkxstart );*/ \
tlcblkystart = int_floordivpow2(l_current_precinct->y0, cblkheightexpn) << cblkheightexpn; \
/*fprintf(stderr, "\t tlcblkystart =%d\n",tlcblkystart );*/ \
brcblkxend = int_ceildivpow2(l_current_precinct->x1, cblkwidthexpn) << cblkwidthexpn; \
/*fprintf(stderr, "\t brcblkxend =%d\n",brcblkxend );*/ \
brcblkyend = int_ceildivpow2(l_current_precinct->y1, cblkheightexpn) << cblkheightexpn; \
/*fprintf(stderr, "\t brcblkyend =%d\n",brcblkyend );*/ \
l_current_precinct->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; \
l_current_precinct->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; \
\
l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; \
/*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ \
l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \
\
if (! l_current_precinct->cblks.ELEMENT) { \
@ -1879,6 +1904,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_current_precinct->cblks.ELEMENT ) { \
return OPJ_FALSE; \
} \
/*fprintf(stderr, "\t\t\t\tAllocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): %d\n",l_nb_code_blocks_size);*/ \
\
memset(l_current_precinct->cblks.ELEMENT,0,l_nb_code_blocks_size);\
\
@ -1890,6 +1916,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
if (! l_current_precinct->cblks.ELEMENT ) { \
return OPJ_FALSE; \
} \
/*fprintf(stderr, "\t\t\t\tReallocate cblks of a precinct (opj_tcd_cblk_dec_v2_t): from %d to %d\n",l_current_precinct->block_size, l_nb_code_blocks_size); */ \
\
memset(((OPJ_BYTE *) l_current_precinct->cblks.ELEMENT) + l_current_precinct->block_size \
,0 \
@ -1899,7 +1926,7 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
} \
\
if (! l_current_precinct->incltree) { \
l_current_precinct->incltree = tgt_create(l_current_precinct->cw, \
l_current_precinct->incltree = tgt_create_v2(l_current_precinct->cw, \
l_current_precinct->ch); \
} \
else{ \
@ -1909,11 +1936,12 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
} \
\
if (! l_current_precinct->incltree) { \
return OPJ_FALSE; \
fprintf(stderr, "WARNING: No incltree created.\n");\
/*return OPJ_FALSE;*/ \
} \
\
if (! l_current_precinct->imsbtree) { \
l_current_precinct->imsbtree = tgt_create( \
l_current_precinct->imsbtree = tgt_create_v2( \
l_current_precinct->cw, \
l_current_precinct->ch);\
} \
@ -1925,7 +1953,8 @@ opj_bool FUNCTION ( opj_tcd_v2_t *p_tcd, \
} \
\
if (! l_current_precinct->imsbtree) { \
return OPJ_FALSE; \
fprintf(stderr, "WARNING: No imsbtree created.\n");\
/*return OPJ_FALSE;*/ \
} \
\
l_code_block = l_current_precinct->cblks.ELEMENT; \
@ -1973,15 +2002,15 @@ OPJ_UINT32 tcd_get_decoded_tile_size ( opj_tcd_v2_t *p_tcd )
{
OPJ_UINT32 i;
OPJ_UINT32 l_data_size = 0;
opj_image_comp_header_t * l_img_comp = 00;
opj_image_comp_t * l_img_comp = 00;
opj_tcd_tilecomp_v2_t * l_tile_comp = 00;
opj_tcd_resolution_v2_t * l_res = 00;
OPJ_UINT32 l_size_comp, l_remaining;
l_tile_comp = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image_header->comps;
l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image_header->numcomps;++i) {
for (i=0;i<p_tcd->image->numcomps;++i) {
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
@ -2096,7 +2125,7 @@ opj_bool tcd_update_tile_data (
)
{
OPJ_UINT32 i,j,k,l_data_size = 0;
opj_image_comp_header_t * l_img_comp = 00;
opj_image_comp_t * l_img_comp = 00;
opj_tcd_tilecomp_v2_t * l_tilec = 00;
opj_tcd_resolution_v2_t * l_res;
OPJ_UINT32 l_size_comp, l_remaining;
@ -2108,9 +2137,9 @@ opj_bool tcd_update_tile_data (
}
l_tilec = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image_header->comps;
l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image_header->numcomps;++i) {
for (i=0;i<p_tcd->image->numcomps;++i) {
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
@ -2242,14 +2271,14 @@ void tcd_free_tile(opj_tcd_v2_t *p_tcd)
l_res = l_tile_comp->resolutions;
if (l_res) {
l_nb_resolutions = l_tile_comp->resolutions_size / sizeof(opj_tcd_resolution_t);
l_nb_resolutions = l_tile_comp->resolutions_size / sizeof(opj_tcd_resolution_v2_t);
for (resno = 0; resno < l_nb_resolutions; ++resno) {
l_band = l_res->bands;
for (bandno = 0; bandno < 3; ++bandno) {
l_precinct = l_band->precincts;
if (l_precinct) {
l_nb_precincts = l_band->precincts_data_size / sizeof(opj_tcd_precinct_t);
l_nb_precincts = l_band->precincts_data_size / sizeof(opj_tcd_precinct_v2_t);
for (precno = 0; precno < l_nb_precincts; ++precno) {
tgt_destroy(l_precinct->incltree);
l_precinct->incltree = 00;
@ -2298,6 +2327,7 @@ opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_v2_t * p_code_block)
if (! p_code_block->data) {
return OPJ_FALSE;
}
/*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/
l_seg_size = J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t);
p_code_block->segs = (opj_tcd_seg_t *) opj_malloc(l_seg_size);
@ -2305,8 +2335,10 @@ opj_bool tcd_code_block_dec_allocate (opj_tcd_cblk_dec_v2_t * p_code_block)
return OPJ_FALSE;
}
memset(p_code_block->segs,0,l_seg_size);
/*fprintf(stderr, "Allocate %d elements of code_block->data\n", J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t));*/
p_code_block->m_current_max_segs = J2K_DEFAULT_NB_SEGS;
/*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/
}
// TODO
//p_code_block->numsegs = 0;
@ -2324,26 +2356,23 @@ opj_bool tcd_t2_decode (
{
opj_t2_v2_t * l_t2;
l_t2 = t2_create_v2(p_tcd->image_header, p_tcd->cp);
if
(l_t2 == 00)
{
l_t2 = t2_create_v2(p_tcd->image, p_tcd->cp);
if (l_t2 == 00) {
return OPJ_FALSE;
}
if
(! t2_decode_packets_v2(
if (! t2_decode_packets_v2(
l_t2,
p_tcd->tcd_tileno,
p_tcd->tcd_image->tiles,
p_src_data,
p_data_read,
p_max_src_size,
p_cstr_index))
{
p_cstr_index)) {
t2_destroy_v2(l_t2);
return OPJ_FALSE;
}
t2_destroy_v2(l_t2);
/*---------------CLEAN-------------------*/
@ -2383,7 +2412,7 @@ opj_bool tcd_dwt_decode ( opj_tcd_v2_t *p_tcd )
opj_tcd_tile_v2_t * l_tile = p_tcd->tcd_image->tiles;
opj_tcd_tilecomp_v2_t * l_tile_comp = l_tile->comps;
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
opj_image_comp_header_t * l_img_comp = p_tcd->image_header->comps;
opj_image_comp_t * l_img_comp = p_tcd->image->comps;
for (compno = 0; compno < l_tile->numcomps; compno++) {
/*
@ -2455,7 +2484,7 @@ opj_bool tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
// nb of components (i.e. size of pData)
l_tile->numcomps,
// tells if the data is signed
p_tcd->image_header->comps->sgnd)) {
p_tcd->image->comps->sgnd)) {
opj_free(l_data);
return OPJ_FALSE;
}
@ -2486,7 +2515,7 @@ opj_bool tcd_dc_level_shift_decode ( opj_tcd_v2_t *p_tcd )
OPJ_UINT32 compno;
opj_tcd_tilecomp_v2_t * l_tile_comp = 00;
opj_tccp_t * l_tccp = 00;
opj_image_comp_header_t * l_img_comp = 00;
opj_image_comp_t * l_img_comp = 00;
opj_tcd_resolution_v2_t* l_res = 00;
opj_tcp_v2_t * l_tcp = 00;
opj_tcd_tile_v2_t * l_tile;
@ -2499,7 +2528,7 @@ opj_bool tcd_dc_level_shift_decode ( opj_tcd_v2_t *p_tcd )
l_tile_comp = l_tile->comps;
l_tcp = p_tcd->tcp;
l_tccp = p_tcd->tcp->tccps;
l_img_comp = p_tcd->image_header->comps;
l_img_comp = p_tcd->image->comps;
for (compno = 0; compno < l_tile->numcomps; compno++) {
l_res = l_tile_comp->resolutions + l_img_comp->resno_decoded;
@ -2557,8 +2586,15 @@ void tcd_code_block_dec_deallocate (opj_tcd_precinct_v2_t * p_precinct)
opj_tcd_cblk_dec_v2_t * l_code_block = p_precinct->cblks.dec;
if (l_code_block) {
/*fprintf(stderr,"deallocate codeblock:{\n");*/
/*fprintf(stderr,"\t x0=%d, y0=%d, x1=%d, y1=%d\n",l_code_block->x0, l_code_block->y0, l_code_block->x1, l_code_block->y1);*/
/*fprintf(stderr,"\t numbps=%d, numlenbits=%d, len=%d, numnewpasses=%d, real_num_segs=%d, m_current_max_segs=%d\n ",
l_code_block->numbps, l_code_block->numlenbits, l_code_block->len, l_code_block->numnewpasses, l_code_block->real_num_segs, l_code_block->m_current_max_segs );*/
l_nb_code_blocks = p_precinct->block_size / sizeof(opj_tcd_cblk_dec_v2_t);
/*fprintf(stderr,"nb_code_blocks =%d\t}\n", l_nb_code_blocks);*/
l_nb_code_blocks = p_precinct->block_size / sizeof(opj_tcd_cblk_dec_t);
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
if (l_code_block->data) {

View File

@ -172,8 +172,8 @@ typedef struct opj_tcd_precinct_v2 {
opj_tcd_cblk_dec_v2_t* dec;
} cblks;
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
struct opj_tgt_tree *incltree; /* inclusion tree */
struct opj_tgt_tree *imsbtree; /* IMSB tree */
opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_v2_t;
/**
@ -331,7 +331,7 @@ typedef struct opj_tcd_v2
/** info on each image tile */
opj_tcd_image_v2_t *tcd_image;
/** image header */
struct opj_image_header *image_header;
opj_image_t *image;
/** coding parameters */
struct opj_cp_v2 *cp;
/** coding/decoding parameters common to all tiles */
@ -379,11 +379,8 @@ void tcd_destroy_v2(opj_tcd_v2_t *tcd);
*
* @return true if the encoding values could be set (false otherwise).
*/
opj_bool tcd_init_v2(
opj_tcd_v2_t *p_tcd,
//struct opj_image * p_image,
opj_image_header_t * p_image_header,
//struct opj_cp * p_cp
opj_bool tcd_init_v2( opj_tcd_v2_t *p_tcd,
opj_image_t * p_image,
opj_cp_v2_t * p_cp
);

View File

@ -108,8 +108,87 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
return tree;
}
opj_tgt_tree_t *tgt_create_v2(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
OPJ_INT32 nplh[32];
OPJ_INT32 nplv[32];
opj_tgt_node_t *node = 00;
opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00;
opj_tgt_tree_t *tree = 00;
OPJ_UINT32 i;
OPJ_INT32 j,k;
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
if(!tree) {
fprintf(stderr, "ERROR in tgt_create_v2 while allocating tree\n");
return 00;
}
memset(tree,0,sizeof(opj_tgt_tree_t));
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
numlvls = 0;
nplh[0] = numleafsh;
nplv[0] = numleafsv;
tree->numnodes = 0;
do {
n = nplh[numlvls] * nplv[numlvls];
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
fprintf(stderr, "WARNING in tgt_create_v2 tree->numnodes == 0, no tree created.\n");
return 00;
}
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
fprintf(stderr, "ERROR in tgt_create_v2 while allocating node of the tree\n");
opj_free(tree);
return 00;
}
memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
tree->nodes_size = tree->numnodes * sizeof(opj_tgt_node_t);
node = tree->nodes;
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
l_parent_node0 = l_parent_node;
for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i];
while (--k >= 0) {
node->parent = l_parent_node;
++node;
if (--k >= 0) {
node->parent = l_parent_node;
++node;
}
++l_parent_node;
}
if ((j & 1) || j == nplv[i] - 1) {
l_parent_node0 = l_parent_node;
} else {
l_parent_node = l_parent_node0;
l_parent_node0 += nplh[i];
}
}
}
node->parent = 0;
tgt_reset(tree);
return tree;
}
/**
* Reinitialises a tag-tree from an exixting one.
* Reinitialises a tag-tree from an exixting one. (V2 framevork)
*
* @param p_tree the tree to reinitialize.
* @param p_num_leafs_h the width of the array of leafs of the tree
@ -216,12 +295,25 @@ opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_U
return p_tree;
}
void tgt_destroy(opj_tgt_tree_t *tree) {
/*void tgt_destroy(opj_tgt_tree_t *tree) {
opj_free(tree->nodes);
opj_free(tree);
}*/
void tgt_destroy(opj_tgt_tree_t *p_tree)
{
if (! p_tree) {
return;
}
if (p_tree->nodes) {
opj_free(p_tree->nodes);
p_tree->nodes = 00;
}
opj_free(p_tree);
}
void tgt_reset(opj_tgt_tree_t *tree) {
/*void tgt_reset(opj_tgt_tree_t *tree) {
int i;
if (NULL == tree)
@ -232,9 +324,27 @@ void tgt_reset(opj_tgt_tree_t *tree) {
tree->nodes[i].low = 0;
tree->nodes[i].known = 0;
}
}*/
void tgt_reset(opj_tgt_tree_t *p_tree) {
OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
if (! p_tree) {
return;
}
l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i)
{
l_current_node->value = 999;
l_current_node->low = 0;
l_current_node->known = 0;
++l_current_node;
}
}
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
void tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) {
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
@ -243,11 +353,11 @@ void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
}
}
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
OPJ_INT32 low;
stkptr = stk;
node = &tree->nodes[leafno];
@ -283,11 +393,11 @@ void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold)
}
}
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
OPJ_UINT32 tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
OPJ_INT32 low;
stkptr = stk;
node = &tree->nodes[leafno];

View File

@ -5,6 +5,7 @@
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -47,9 +48,9 @@ Tag node
*/
typedef struct opj_tgt_node {
struct opj_tgt_node *parent;
int value;
int low;
int known;
OPJ_INT32 value;
OPJ_INT32 low;
OPJ_UINT32 known;
} opj_tgt_node_t;
///** OPJ_V1
@ -85,6 +86,7 @@ Create a tag-tree
@return Returns a new tag-tree if successful, returns NULL otherwise
*/
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
opj_tgt_tree_t *tgt_create_v2(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv);
/**
* Reinitialises a tag-tree from an exixting one.
@ -94,7 +96,7 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
* @param p_num_leafs_v the height of the array of leafs of the tree
* @return a new tag-tree if successful, NULL otherwise
*/
opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v);
opj_tgt_tree_t *tgt_init(opj_tgt_tree_t * p_tree, OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v);
/**
@ -113,7 +115,7 @@ Set the value of a leaf of a tag-tree
@param leafno Number that identifies the leaf to modify
@param value New value of the leaf
*/
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
void tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value);
/**
Encode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@ -121,7 +123,7 @@ Encode the value of a leaf of the tag-tree up to a given threshold
@param leafno Number that identifies the leaf to encode
@param threshold Threshold to use when encoding value of the leaf
*/
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold);
/**
Decode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@ -130,7 +132,7 @@ Decode the value of a leaf of the tag-tree up to a given threshold
@param threshold Threshold to use when decoding value of the leaf
@return Returns 1 if the node's value < threshold, returns 0 otherwise
*/
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
OPJ_UINT32 tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold);
/* ----------------------------------------------------------------------- */
/*@}*/