Compare commits

...

5 Commits

Author SHA1 Message Date
Antonin Descampe
0febbff19e processed all c/h files through astyle with opj_astyle.cfg 2016-01-25 23:22:06 +01:00
Antonin Descampe
bede1568b1 Merge branch 'master' into codingstyle 2016-01-25 22:43:03 +01:00
Antonin Descampe
6ec68a27f8 modified astyle config 2016-01-25 15:03:21 +01:00
Antonin Descampe
4b927ecea3 modified style cfg 2016-01-24 19:00:31 +01:00
Antonin Descampe
0efb2f5293 adding astyle and uncrustify config files 2016-01-24 18:54:13 +01:00
261 changed files with 71174 additions and 71149 deletions

View File

@ -6,6 +6,6 @@ int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return 0; return 0;
} }

View File

@ -3,9 +3,9 @@
int main() int main()
{ {
__int64 off=0; __int64 off=0;
_fseeki64(NULL, off, SEEK_SET); _fseeki64(NULL, off, SEEK_SET);
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -44,212 +44,213 @@ static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
#include "opj_getopt.h" #include "opj_getopt.h"
int opj_opterr = 1, /* if error message should be printed */ int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */ opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */ opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */ opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */ char *opj_optarg; /* argument associated with option */
#define BADCH (int)'?' #define BADCH (int)'?'
#define BADARG (int)':' #define BADARG (int)':'
static char EMSG[]={""}; static char EMSG[]= {""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */ /* As this class remembers its values from one Java call to the other, reset the values before each use */
void opj_reset_options_reading(void) { void opj_reset_options_reading(void)
opj_opterr = 1; {
opj_optind = 1; opj_opterr = 1;
opj_optind = 1;
} }
/* /*
* getopt -- * getopt --
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
*/ */
int opj_getopt(int nargc, char *const *nargv, const char *ostr) { int opj_getopt(int nargc, char *const *nargv, const char *ostr)
{
# define __progname nargv[0] # define __progname nargv[0]
static char *place = EMSG; /* option letter processing */ static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */ const char *oli = NULL; /* option letter list index */
if (opj_optreset || !*place) { /* update scanning pointer */ if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0; opj_optreset = 0;
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') { if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG; place = EMSG;
return (-1); return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++opj_optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((opj_optopt = (int) *place++) == (int) ':' ||
!(oli = strchr(ostr, opj_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (opj_optopt == (int) '-')
return (-1);
if (!*place)
++opj_optind;
if (opj_opterr && *ostr != ':') {
fprintf(stderr,
"%s: illegal option -- %c\n", __progname, opj_optopt);
return (BADCH);
}
} }
if (place[1] && *++place == '-') { /* found "--" */ if (*++oli != ':') { /* don't need argument */
++opj_optind; opj_optarg = NULL;
place = EMSG; if (!*place)
return (-1); ++opj_optind;
} else { /* need an argument */
if (*place) /* no white space */
opj_optarg = place;
else if (nargc <= ++opj_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opj_opterr) {
fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, opj_optopt);
return (BADCH);
}
} else /* white space */
opj_optarg = nargv[opj_optind];
place = EMSG;
++opj_optind;
} }
} /* option letter okay? */ return (opj_optopt); /* dump back option letter */
if ((opj_optopt = (int) *place++) == (int) ':' ||
!(oli = strchr(ostr, opj_optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (opj_optopt == (int) '-')
return (-1);
if (!*place)
++opj_optind;
if (opj_opterr && *ostr != ':') {
fprintf(stderr,
"%s: illegal option -- %c\n", __progname, opj_optopt);
return (BADCH);
}
}
if (*++oli != ':') { /* don't need argument */
opj_optarg = NULL;
if (!*place)
++opj_optind;
} else { /* need an argument */
if (*place) /* no white space */
opj_optarg = place;
else if (nargc <= ++opj_optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opj_opterr) {
fprintf(stderr,
"%s: option requires an argument -- %c\n",
__progname, opj_optopt);
return (BADCH);
}
} else /* white space */
opj_optarg = nargv[opj_optind];
place = EMSG;
++opj_optind;
}
return (opj_optopt); /* dump back option letter */
} }
int opj_getopt_long(int argc, char * const argv[], const char *optstring, int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen) { const opj_option_t *longopts, int totlen)
static int lastidx,lastofs; {
const char *tmp; static int lastidx,lastofs;
int i,len; const char *tmp;
char param = 1; int i,len;
char param = 1;
again: again:
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-') if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
return -1; return -1;
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) { if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)){ /* no more input parameters */ if(opj_optind >= (argc - 1)) { /* no more input parameters */
param = 0; param = 0;
} } else { /* more input parameters */
else{ /* more input parameters */ if(argv[opj_optind + 1][0] == '-') {
if(argv[opj_optind + 1][0] == '-'){ param = 0; /* Missing parameter after '-' */
param = 0; /* Missing parameter after '-' */ } else {
} param = 2;
else{ }
param = 2; }
} }
}
}
if (param == 0) { if (param == 0) {
++opj_optind; ++opj_optind;
return (BADCH); return (BADCH);
} }
if (argv[opj_optind][0]=='-') { /* long option */ if (argv[opj_optind][0]=='-') { /* long option */
char* arg=argv[opj_optind]+1; char* arg=argv[opj_optind]+1;
const opj_option_t* o; const opj_option_t* o;
o=longopts; o=longopts;
len=sizeof(longopts[0]); len=sizeof(longopts[0]);
if (param > 1){ if (param > 1) {
arg = argv[opj_optind+1]; arg = argv[opj_optind+1];
opj_optind++; opj_optind++;
} } else
else arg = argv[opj_optind]+1;
arg = argv[opj_optind]+1;
if(strlen(arg)>1){ if(strlen(arg)>1) {
for (i=0;i<totlen;i=i+len,o++) { for (i=0; i<totlen; i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */ if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 0) { if (o->has_arg == 0) {
if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){ if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))) {
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]); fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
++opj_optind; ++opj_optind;
} }
}else{ } else {
opj_optarg=argv[opj_optind+1]; opj_optarg=argv[opj_optind+1];
if(opj_optarg){ if(opj_optarg) {
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */ if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) { if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg); fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH); return (BADCH);
} }
} }
} }
if (!opj_optarg && o->has_arg==1) { /* no argument there */ if (!opj_optarg && o->has_arg==1) { /* no argument there */
if (opj_opterr) { if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument \n",arg); fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH); return (BADCH);
} }
} }
++opj_optind; ++opj_optind;
} }
++opj_optind; ++opj_optind;
if (o->flag) if (o->flag)
*(o->flag)=o->val; *(o->flag)=o->val;
else else
return o->val; return o->val;
return 0; return 0;
} }
}/*(end for)String not found in the list*/ }/*(end for)String not found in the list*/
fprintf(stderr,"Invalid option %s\n",arg); fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind; ++opj_optind;
return (BADCH); return (BADCH);
}else{ /*Single character input parameter*/ } else { /*Single character input parameter*/
if (*optstring==':') return ':'; if (*optstring==':') return ':';
if (lastidx!=opj_optind) { if (lastidx!=opj_optind) {
lastidx=opj_optind; lastofs=0; lastidx=opj_optind;
} lastofs=0;
opj_optopt=argv[opj_optind][lastofs+1]; }
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/ opj_optopt=argv[opj_optind][lastofs+1];
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */ if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
++opj_optind; if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
goto again; ++opj_optind;
} goto again;
if (tmp[1]==':') { /* argument expected */ }
if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */ if (tmp[1]==':') { /* argument expected */
if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0; if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
goto found; if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
} goto found;
opj_optarg=argv[opj_optind+1]; }
if(opj_optarg){ opj_optarg=argv[opj_optind+1];
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */ if(opj_optarg) {
if (opj_opterr) { if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
fprintf(stderr,"%s: option requires an argument\n",arg); if (opj_opterr) {
return (BADCH); fprintf(stderr,"%s: option requires an argument\n",arg);
} return (BADCH);
} }
} }
if (!opj_optarg) { /* missing argument */ }
if (opj_opterr) { if (!opj_optarg) { /* missing argument */
fprintf(stderr,"%s: option requires an argument\n",arg); if (opj_opterr) {
return (BADCH); fprintf(stderr,"%s: option requires an argument\n",arg);
} return (BADCH);
} }
++opj_optind; }
}else {/*Argument not expected*/ ++opj_optind;
++lastofs; } else {/*Argument not expected*/
return opj_optopt; ++lastofs;
} return opj_optopt;
}
found: found:
++opj_optind; ++opj_optind;
return opj_optopt; return opj_optopt;
} else { /* not found */ } else { /* not found */
fprintf(stderr,"Invalid option %s\n",arg); fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind; ++opj_optind;
return (BADCH); return (BADCH);
}/*end of not found*/ }/*end of not found*/
}/* end of single character*/ }/* end of single character*/
}/*end '-'*/ }/*end '-'*/
fprintf(stderr,"Invalid option\n"); fprintf(stderr,"Invalid option\n");
++opj_optind; ++opj_optind;
return (BADCH);; return (BADCH);;
}/*end function*/ }/*end function*/

View File

@ -3,13 +3,12 @@
#ifndef _GETOPT_H_ #ifndef _GETOPT_H_
#define _GETOPT_H_ #define _GETOPT_H_
typedef struct opj_option typedef struct opj_option {
{ const char *name;
const char *name; int has_arg;
int has_arg; int *flag;
int *flag; int val;
int val; } opj_option_t;
}opj_option_t;
#define NO_ARG 0 #define NO_ARG 0
#define REQ_ARG 1 #define REQ_ARG 1
@ -23,7 +22,7 @@ extern char *opj_optarg;
extern int opj_getopt(int nargc, char *const *nargv, const char *ostr); extern int opj_getopt(int nargc, char *const *nargv, const char *ostr);
extern int opj_getopt_long(int argc, char * const argv[], const char *optstring, extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen); const opj_option_t *longopts, int totlen);
extern void opj_reset_options_reading(void); extern void opj_reset_options_reading(void);
#endif /* _GETOPT_H_ */ #endif /* _GETOPT_H_ */

View File

@ -39,34 +39,34 @@
/* keep in mind there still is a buffer read overflow possible */ /* keep in mind there still is a buffer read overflow possible */
static size_t opj_strnlen_s(const char *src, size_t max_len) static size_t opj_strnlen_s(const char *src, size_t max_len)
{ {
size_t len; size_t len;
if (src == NULL) { if (src == NULL) {
return 0U; return 0U;
} }
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++); for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len; return len;
} }
/* should be equivalent to C11 function except for the handler */ /* should be equivalent to C11 function except for the handler */
/* keep in mind there still is a buffer read overflow possible */ /* keep in mind there still is a buffer read overflow possible */
static int opj_strcpy_s(char* dst, size_t dst_size, const char* src) static int opj_strcpy_s(char* dst, size_t dst_size, const char* src)
{ {
size_t src_len = 0U; size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) { if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL; return EINVAL;
} }
if (src == NULL) { if (src == NULL) {
dst[0] = '\0'; dst[0] = '\0';
return EINVAL; return EINVAL;
} }
src_len = opj_strnlen_s(src, dst_size); src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) { if (src_len >= dst_size) {
return ERANGE; return ERANGE;
} }
memcpy(dst, src, src_len); memcpy(dst, src, src_len);
dst[src_len] = '\0'; dst[src_len] = '\0';
return 0; return 0;
} }
#endif /* OPJ_STRING_H */ #endif /* OPJ_STRING_H */

File diff suppressed because it is too large Load Diff

View File

@ -50,19 +50,19 @@ typedef struct raw_comp_cparameters {
/**@name RAW image encoding parameters */ /**@name RAW image encoding parameters */
/*@{*/ /*@{*/
typedef struct raw_cparameters { typedef struct raw_cparameters {
/** width of the raw image */ /** width of the raw image */
int rawWidth; int rawWidth;
/** height of the raw image */ /** height of the raw image */
int rawHeight; int rawHeight;
/** number of components of the raw image */ /** number of components of the raw image */
int rawComp; int rawComp;
/** bit depth of the raw image */ /** bit depth of the raw image */
int rawBitDepth; int rawBitDepth;
/** signed/unsigned raw image */ /** signed/unsigned raw image */
OPJ_BOOL rawSigned; OPJ_BOOL rawSigned;
/** raw components parameters */ /** raw components parameters */
raw_comp_cparameters_t *rawComps; raw_comp_cparameters_t *rawComps;
/*@}*/ /*@}*/
} raw_cparameters_t; } raw_cparameters_t;
/* Component precision clipping */ /* Component precision clipping */

File diff suppressed because it is too large Load Diff

View File

@ -56,437 +56,422 @@
static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) static void convert_16u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++; OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++; OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1; pDst[i] = val0 << 8 | val1;
} }
} }
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
{ {
png_structp png = NULL; png_structp png = NULL;
png_infop info = NULL; png_infop info = NULL;
double gamma; double gamma;
int bit_depth, interlace_type,compression_type, filter_type; int bit_depth, interlace_type,compression_type, filter_type;
OPJ_UINT32 i; OPJ_UINT32 i;
png_uint_32 width, height = 0U; png_uint_32 width, height = 0U;
int color_type; int color_type;
FILE *reader = NULL; FILE *reader = NULL;
OPJ_BYTE** rows = NULL; OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL; OPJ_INT32* row32s = NULL;
/* j2k: */ /* j2k: */
opj_image_t *image = NULL; opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4]; opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp; OPJ_UINT32 nr_comp;
OPJ_BYTE sigbuf[8]; OPJ_BYTE sigbuf[8];
convert_XXx32s_C1R cvtXXTo32s = NULL; convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL; convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4]; OPJ_INT32* planes[4];
if((reader = fopen(read_idf, "rb")) == NULL) if((reader = fopen(read_idf, "rb")) == NULL) {
{ fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); return NULL;
return NULL; }
}
if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
{ fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); goto fin;
goto fin; }
}
if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL)) == NULL) NULL, NULL, NULL)) == NULL)
goto fin; goto fin;
if((info = png_create_info_struct(png)) == NULL) if((info = png_create_info_struct(png)) == NULL)
goto fin; goto fin;
if(setjmp(png_jmpbuf(png))) if(setjmp(png_jmpbuf(png)))
goto fin; goto fin;
png_init_io(png, reader); png_init_io(png, reader);
png_set_sig_bytes(png, MAGIC_SIZE); png_set_sig_bytes(png, MAGIC_SIZE);
png_read_info(png, info); png_read_info(png, info);
if(png_get_IHDR(png, info, &width, &height, if(png_get_IHDR(png, info, &width, &height,
&bit_depth, &color_type, &interlace_type, &bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0) &compression_type, &filter_type) == 0)
goto fin; goto fin;
/* png_set_expand(): /* png_set_expand():
* expand paletted images to RGB, expand grayscale images of * expand paletted images to RGB, expand grayscale images of
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels. * to alpha channels.
*/ */
if(color_type == PNG_COLOR_TYPE_PALETTE) { if(color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png); png_set_expand(png);
} }
if(png_get_valid(png, info, PNG_INFO_tRNS)) { if(png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_expand(png); png_set_expand(png);
} }
/* We might wan't to expand background */ /* We might wan't to expand background */
/* /*
if(png_get_valid(png, info, PNG_INFO_bKGD)) { if(png_get_valid(png, info, PNG_INFO_bKGD)) {
png_color_16p bgnd; png_color_16p bgnd;
png_get_bKGD(png, info, &bgnd); png_get_bKGD(png, info, &bgnd);
png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0); png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
} }
*/ */
if( !png_get_gAMA(png, info, &gamma)) if( !png_get_gAMA(png, info, &gamma))
gamma = 1.0; gamma = 1.0;
/* we're not displaying but converting, screen gamma == 1.0 */ /* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma); png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info); png_read_update_info(png, info);
color_type = png_get_color_type(png, info); color_type = png_get_color_type(png, info);
switch (color_type) { switch (color_type) {
case PNG_COLOR_TYPE_GRAY: case PNG_COLOR_TYPE_GRAY:
nr_comp = 1; nr_comp = 1;
break; break;
case PNG_COLOR_TYPE_GRAY_ALPHA: case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2; nr_comp = 2;
break; break;
case PNG_COLOR_TYPE_RGB: case PNG_COLOR_TYPE_RGB:
nr_comp = 3; nr_comp = 3;
break; break;
case PNG_COLOR_TYPE_RGB_ALPHA: case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4; nr_comp = 4;
break; break;
default: default:
fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type); fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type);
goto fin; goto fin;
} }
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp]; cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info); bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) { switch (bit_depth) {
case 1: case 1:
case 2: case 2:
case 4: case 4:
case 8: case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth]; cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break; break;
case 16: /* 16 bpp is specific to PNG */ case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R; cvtXXTo32s = convert_16u32s_C1R;
break; break;
default: default:
fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth); fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth);
goto fin; goto fin;
} }
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*)); rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*));
for(i = 0; i < height; ++i) for(i = 0; i < height; ++i)
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info)); rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info));
png_read_image(png, rows); png_read_image(png, rows);
/* Create image */ /* Create image */
memset(cmptparm, 0, sizeof(cmptparm)); memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i) for(i = 0; i < nr_comp; ++i) {
{ cmptparm[i].prec = (OPJ_UINT32)bit_depth;
cmptparm[i].prec = (OPJ_UINT32)bit_depth; /* bits_per_pixel: 8 or 16 */
/* bits_per_pixel: 8 or 16 */ cmptparm[i].bpp = (OPJ_UINT32)bit_depth;
cmptparm[i].bpp = (OPJ_UINT32)bit_depth; cmptparm[i].sgnd = 0;
cmptparm[i].sgnd = 0; cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx; cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy; cmptparm[i].w = (OPJ_UINT32)width;
cmptparm[i].w = (OPJ_UINT32)width; cmptparm[i].h = (OPJ_UINT32)height;
cmptparm[i].h = (OPJ_UINT32)height; }
}
image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY); image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
if(image == NULL) goto fin; if(image == NULL) goto fin;
image->x0 = (OPJ_UINT32)params->image_offset_x0; image->x0 = (OPJ_UINT32)params->image_offset_x0;
image->y0 = (OPJ_UINT32)params->image_offset_y0; image->y0 = (OPJ_UINT32)params->image_offset_y0;
image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0); image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0);
image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0); image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0);
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32));
if(row32s == NULL) goto fin; if(row32s == NULL) goto fin;
/* Set alpha channel */ /* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U); image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++) for(i = 0; i < nr_comp; i++) {
{ planes[i] = image->comps[i].data;
planes[i] = image->comps[i].data; }
}
for(i = 0; i < height; ++i) for(i = 0; i < height; ++i) {
{ cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp); cvtCxToPx(row32s, planes, width);
cvtCxToPx(row32s, planes, width); planes[0] += width;
planes[0] += width; planes[1] += width;
planes[1] += width; planes[2] += width;
planes[2] += width; planes[3] += width;
planes[3] += width; }
}
fin: fin:
if(rows) if(rows) {
{ for(i = 0; i < height; ++i)
for(i = 0; i < height; ++i) free(rows[i]);
free(rows[i]); free(rows);
free(rows); }
} if (row32s) {
if (row32s) { free(row32s);
free(row32s); }
} if(png)
if(png) png_destroy_read_struct(&png, &info, NULL);
png_destroy_read_struct(&png, &info, NULL);
fclose(reader); fclose(reader);
return image; return image;
}/* pngtoimage() */ }/* pngtoimage() */
static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i]; OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8); *pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val; *pDst++ = (OPJ_BYTE)val;
} }
} }
int imagetopng(opj_image_t * image, const char *write_idf) int imagetopng(opj_image_t * image, const char *write_idf)
{ {
FILE * volatile writer = NULL; FILE * volatile writer = NULL;
png_structp png = NULL; png_structp png = NULL;
png_infop info = NULL; png_infop info = NULL;
png_bytep volatile row_buf = NULL; png_bytep volatile row_buf = NULL;
int nr_comp, color_type; int nr_comp, color_type;
volatile int prec; volatile int prec;
png_color_8 sig_bit; png_color_8 sig_bit;
OPJ_INT32 const* planes[4]; OPJ_INT32 const* planes[4];
int i; int i;
OPJ_INT32* volatile buffer32s = NULL; OPJ_INT32* volatile buffer32s = NULL;
volatile int fails = 1; volatile int fails = 1;
memset(&sig_bit, 0, sizeof(sig_bit)); memset(&sig_bit, 0, sizeof(sig_bit));
prec = (int)image->comps[0].prec; prec = (int)image->comps[0].prec;
planes[0] = image->comps[0].data; planes[0] = image->comps[0].data;
nr_comp = (int)image->numcomps; nr_comp = (int)image->numcomps;
if (nr_comp > 4) { if (nr_comp > 4) {
nr_comp = 4; nr_comp = 4;
} }
for (i = 1; i < nr_comp; ++i) { for (i = 1; i < nr_comp; ++i) {
if (image->comps[0].dx != image->comps[i].dx) { if (image->comps[0].dx != image->comps[i].dx) {
break; break;
} }
if (image->comps[0].dy != image->comps[i].dy) { if (image->comps[0].dy != image->comps[i].dy) {
break; break;
} }
if (image->comps[0].prec != image->comps[i].prec) { if (image->comps[0].prec != image->comps[i].prec) {
break; break;
} }
if (image->comps[0].sgnd != image->comps[i].sgnd) { if (image->comps[0].sgnd != image->comps[i].sgnd) {
break; break;
} }
planes[i] = image->comps[i].data; planes[i] = image->comps[i].data;
} }
if (i != nr_comp) { if (i != nr_comp) {
fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n"); fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr,"\tAborting\n"); fprintf(stderr,"\tAborting\n");
return 1; return 1;
} }
for (i = 0; i < nr_comp; ++i) { for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec); clip_component(&(image->comps[i]), image->comps[0].prec);
} }
if(prec > 8 && prec < 16) if(prec > 8 && prec < 16) {
{ for (i = 0; i < nr_comp; ++i) {
for (i = 0; i < nr_comp; ++i) { scale_component(&(image->comps[i]), 16);
scale_component(&(image->comps[i]), 16); }
} prec = 16;
prec = 16; } else if(prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */
} for (i = 0; i < nr_comp; ++i) {
else if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */ scale_component(&(image->comps[i]), 8);
{ }
for (i = 0; i < nr_comp; ++i) { prec = 8;
scale_component(&(image->comps[i]), 8); } else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */
} if ((prec == 5) || (prec == 6)) {
prec = 8; prec = 8;
} else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */ } else {
if ((prec == 5) || (prec == 6)) { prec++;
prec = 8; }
} else { for (i = 0; i < nr_comp; ++i) {
prec++; scale_component(&(image->comps[i]), (OPJ_UINT32)prec);
} }
for (i = 0; i < nr_comp; ++i) { }
scale_component(&(image->comps[i]), (OPJ_UINT32)prec);
}
}
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) {
{ fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec); return fails;
return fails; }
}
writer = fopen(write_idf, "wb"); writer = fopen(write_idf, "wb");
if(writer == NULL) return fails; if(writer == NULL) return fails;
/* Create and initialize the png_struct with the desired error handler /* Create and initialize the png_struct with the desired error handler
* functions. If you want to use the default stderr and longjump method, * functions. If you want to use the default stderr and longjump method,
* you can supply NULL for the last three parameters. We also check that * you can supply NULL for the last three parameters. We also check that
* the library version is compatible with the one used at compile time, * the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED. * in case we are using dynamically linked libraries. REQUIRED.
*/ */
png = png_create_write_struct(PNG_LIBPNG_VER_STRING, png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL); NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ /*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if(png == NULL) goto fin; if(png == NULL) goto fin;
/* Allocate/initialize the image information data. REQUIRED /* Allocate/initialize the image information data. REQUIRED
*/ */
info = png_create_info_struct(png); info = png_create_info_struct(png);
if(info == NULL) goto fin; if(info == NULL) goto fin;
/* Set error handling. REQUIRED if you are not supplying your own /* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call. * error handling functions in the png_create_write_struct() call.
*/ */
if(setjmp(png_jmpbuf(png))) goto fin; if(setjmp(png_jmpbuf(png))) goto fin;
/* I/O initialization functions is REQUIRED /* I/O initialization functions is REQUIRED
*/ */
png_init_io(png, writer); png_init_io(png, writer);
/* Set the image information here. Width and height are up to 2^31, /* Set the image information here. Width and height are up to 2^31,
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED * REQUIRED
* *
* ERRORS: * ERRORS:
* *
* color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8 * color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8
* color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8 * color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8
* color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8 * color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8
* color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8 * color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8
* *
*/ */
png_set_compression_level(png, Z_BEST_COMPRESSION); png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) /* RGB(A) */ if(nr_comp >= 3) { /* RGB(A) */
{ color_type = PNG_COLOR_TYPE_RGB;
color_type = PNG_COLOR_TYPE_RGB; sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; } else { /* GRAY(A) */
} color_type = PNG_COLOR_TYPE_GRAY;
else /* GRAY(A) */ sig_bit.gray = (png_byte)prec;
{ }
color_type = PNG_COLOR_TYPE_GRAY; if((nr_comp & 1) == 0) { /* ALPHA */
sig_bit.gray = (png_byte)prec; color_type |= PNG_COLOR_MASK_ALPHA;
} sig_bit.alpha = (png_byte)prec;
if((nr_comp & 1) == 0) /* ALPHA */ }
{
color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec;
}
png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type, png_set_IHDR(png, info, image->comps[0].w, image->comps[0].h, prec, color_type,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit); png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */ /* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */ /* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info); png_write_info(png, info);
/* setup conversion */ /* setup conversion */
{ {
OPJ_SIZE_T rowStride; OPJ_SIZE_T rowStride;
png_size_t png_row_size; png_size_t png_row_size;
png_row_size = png_get_rowbytes(png, info); png_row_size = png_get_rowbytes(png, info);
rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * (OPJ_SIZE_T)prec + 7U) / 8U; rowStride = ((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * (OPJ_SIZE_T)prec + 7U) / 8U;
if (rowStride != (OPJ_SIZE_T)png_row_size) { if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n"); fprintf(stderr, "Invalid PNG row size\n");
goto fin; goto fin;
} }
row_buf = (png_bytep)malloc(png_row_size); row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) { if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n"); fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin; goto fin;
} }
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32)); buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) { if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n"); fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin; goto fin;
} }
} }
/* convert */ /* convert */
{ {
OPJ_SIZE_T width= image->comps[0].w; OPJ_SIZE_T width= image->comps[0].w;
OPJ_UINT32 y; OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp]; convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL; convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0; OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf; png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s; OPJ_INT32* buffer32s_cpy = buffer32s;
switch (prec) { switch (prec) {
case 1: case 1:
case 2: case 2:
case 4: case 4:
case 8: case 8:
cvt32sToPack = convert_32sXXu_C1R_LUT[prec]; cvt32sToPack = convert_32sXXu_C1R_LUT[prec];
break; break;
case 16: case 16:
cvt32sToPack = convert_32s16u_C1R; cvt32sToPack = convert_32s16u_C1R;
break; break;
default: default:
/* never here */ /* never here */
break; break;
} }
for(y = 0; y < image->comps[0].h; ++y) for(y = 0; y < image->comps[0].h; ++y) {
{ cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvtPxToCx(planes, buffer32s_cpy, width, adjust); cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp); png_write_row(png, row_buf_cpy);
png_write_row(png, row_buf_cpy); planes[0] += width;
planes[0] += width; planes[1] += width;
planes[1] += width; planes[2] += width;
planes[2] += width; planes[3] += width;
planes[3] += width; }
} }
}
png_write_end(png, info); png_write_end(png, info);
fails = 0; fails = 0;
fin: fin:
if(png) { if(png) {
png_destroy_write_struct(&png, &info); png_destroy_write_struct(&png, &info);
} }
if(row_buf) { if(row_buf) {
free(row_buf); free(row_buf);
} }
if(buffer32s) { if(buffer32s) {
free(buffer32s); free(buffer32s);
} }
fclose(writer); fclose(writer);
if(fails) (void)remove(write_idf); /* ignore return value */ if(fails) (void)remove(write_idf); /* ignore return value */
return fails; return fails;
}/* imagetopng() */ }/* imagetopng() */

File diff suppressed because it is too large Load Diff

View File

@ -46,352 +46,353 @@ Write a structured index to a file
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */
int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int write_index_file(opj_codestream_info_t *cstr_info, char *index)
int tileno, compno, layno, resno, precno, pack_nb, x, y; {
FILE *stream = NULL; int tileno, compno, layno, resno, precno, pack_nb, x, y;
double total_disto = 0; FILE *stream = NULL;
/* UniPG>> */ double total_disto = 0;
int tilepartno; /* UniPG>> */
char disto_on, numpix_on; int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL #ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0; return 0;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
if (!cstr_info) if (!cstr_info)
return 1; return 1;
stream = fopen(index, "w"); stream = fopen(index, "w");
if (!stream) { if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index); fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1; return 1;
} }
if (cstr_info->tile[0].distotile) if (cstr_info->tile[0].distotile)
disto_on = 1; disto_on = 1;
else else
disto_on = 0; disto_on = 0;
if (cstr_info->tile[0].numpix) if (cstr_info->tile[0].numpix)
numpix_on = 1; numpix_on = 1;
else else
numpix_on = 0; numpix_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog); fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->numcomps); fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers); fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */ fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ", fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
} }
fprintf(stream, "\n"); fprintf(stream, "\n");
/* UniPG>> */ /* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start); fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */ /* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end); fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n"); fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts"); fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on) if (disto_on)
fprintf(stream," disto"); fprintf(stream," disto");
if (numpix_on) if (numpix_on)
fprintf(stream," nbpix"); fprintf(stream," nbpix");
if (disto_on && numpix_on) if (disto_on && numpix_on)
fprintf(stream," disto/nbpix"); fprintf(stream," disto/nbpix");
fprintf(stream, "\n"); fprintf(stream, "\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d", fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno, cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos, cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header, cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos, cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].num_tps); cstr_info->tile[tileno].num_tps);
if (disto_on) if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile); fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on) if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix); fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on) if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix); fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n"); fprintf(stream, "\n");
} }
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
OPJ_OFF_T start_pos, end_ph_pos, end_pos; OPJ_OFF_T start_pos, end_ph_pos, end_pos;
double disto = 0; double disto = 0;
int max_numdecompos = 0; int max_numdecompos = 0;
pack_nb = 0; pack_nb = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno]) if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno]; max_numdecompos = cstr_info->numdecompos[compno];
} }
fprintf(stream, "\nTILE %d DETAILS\n", tileno); fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno, tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header, cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
); );
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */ if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos"); fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max; int prec_max;
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %7d %5d %6d %6d %6" PRId64 " %6" PRId64 " %7" PRId64, fprintf(stream, "%4d %6d %7d %5d %6d %6d %6" PRId64 " %6" PRId64 " %7" PRId64,
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} /* LRCP */ } /* LRCP */
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */ else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max; int prec_max;
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64, fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} /* RLCP */ } /* RLCP */
else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */ else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) { for (precno = 0; precno < numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %6d %6d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, fprintf(stream, "%4d %6d %5d %6d %6d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* precno */ } /* precno */
} /* compno */ } /* compno */
} /* resno */ } /* resno */
} /* RPCL */ } /* RPCL */
else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */ else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
/* Count the maximum number of precincts */ /* Count the maximum number of precincts */
int max_numprec = 0; int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) if (numprec > max_numprec)
max_numprec = numprec; max_numprec = numprec;
} }
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (precno = 0; precno < max_numprec; precno++) { for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec) if (precno >= numprec)
continue; continue;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* resno */ } /* resno */
} /* compno */ } /* compno */
} /* precno */ } /* precno */
} /* PCRL */ } /* PCRL */
else { /* CPRL */ else { /* CPRL */
/* Count the maximum number of precincts */ /* Count the maximum number of precincts */
int max_numprec = 0; int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) if (numprec > max_numprec)
max_numprec = numprec; max_numprec = numprec;
} }
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos"); fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (precno = 0; precno < max_numprec; precno++) { for (precno = 0; precno < max_numprec; precno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec) if (precno >= numprec)
continue; continue;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64, fprintf(stream, "%4d %6d %6d %6d %5d %7d %9" PRId64 " %9" PRId64 " %7" PRId64,
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* resno */ } /* resno */
} /* precno */ } /* precno */
} /* compno */ } /* compno */
} /* CPRL */ } /* CPRL */
} /* tileno */ } /* tileno */
if (disto_on) { if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
} }
/* UniPG>> */ /* UniPG>> */
/* print the markers' list */ /* print the markers' list */
if (cstr_info->marknum) { if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n"); fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum); fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n"); fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++) for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len); fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
} }
/* <<UniPG */ /* <<UniPG */
fclose(stream); fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); fprintf(stderr,"Generated index file %s\n", index);
return 0; return 0;
} }

View File

@ -71,14 +71,14 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -87,9 +87,10 @@ typedef struct img_folder{
char set_imgdir; char set_imgdir;
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
char set_out_format; char set_out_format;
}img_fol_t; } img_fol_t;
static void encode_help_display(void) { static void encode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
"It compresses various image formats with the JPEG 2000 algorithm.\n" "It compresses various image formats with the JPEG 2000 algorithm.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@ -108,9 +109,9 @@ static void encode_help_display(void) {
fprintf(stdout," * No sub-sampling in x or y direction\n"); fprintf(stdout," * No sub-sampling in x or y direction\n");
fprintf(stdout," * No mode switch activated\n"); fprintf(stdout," * No mode switch activated\n");
fprintf(stdout," * Progression order: LRCP\n"); fprintf(stdout," * Progression order: LRCP\n");
#ifdef FIXME_INDEX #ifdef FIXME_INDEX
fprintf(stdout," * No index file\n"); fprintf(stdout," * No index file\n");
#endif /* FIXME_INDEX */ #endif /* FIXME_INDEX */
fprintf(stdout," * No ROI upshifted\n"); fprintf(stdout," * No ROI upshifted\n");
fprintf(stdout," * No offset of the origin of the image\n"); fprintf(stdout," * No offset of the origin of the image\n");
fprintf(stdout," * No offset of the origin of the tiles\n"); fprintf(stdout," * No offset of the origin of the tiles\n");
@ -218,10 +219,10 @@ static void encode_help_display(void) {
fprintf(stdout," Divide packets of every tile into tile-parts.\n"); fprintf(stdout," Divide packets of every tile into tile-parts.\n");
fprintf(stdout," Division is made by grouping Resolutions (R), Layers (L)\n"); fprintf(stdout," Division is made by grouping Resolutions (R), Layers (L)\n");
fprintf(stdout," or Components (C).\n"); fprintf(stdout," or Components (C).\n");
#ifdef FIXME_INDEX #ifdef FIXME_INDEX
fprintf(stdout,"-x <index file>\n"); fprintf(stdout,"-x <index file>\n");
fprintf(stdout," Create an index file.\n"); fprintf(stdout," Create an index file.\n");
#endif /*FIXME_INDEX*/ #endif /*FIXME_INDEX*/
fprintf(stdout,"-ROI c=<component index>,U=<upshifting value>\n"); fprintf(stdout,"-ROI c=<component index>,U=<upshifting value>\n");
fprintf(stdout," Quantization indices upshifted for a component. \n"); fprintf(stdout," Quantization indices upshifted for a component. \n");
fprintf(stdout," Warning: This option does not implement the usual ROI (Region of Interest).\n"); fprintf(stdout," Warning: This option does not implement the usual ROI (Region of Interest).\n");
@ -353,7 +354,8 @@ static void encode_help_display(void) {
#endif /*FIXME_INDEX*/ #endif /*FIXME_INDEX*/
} }
static OPJ_PROG_ORDER give_progression(const char progression[4]) { static OPJ_PROG_ORDER give_progression(const char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) { if(strncmp(progression, "LRCP", 4) == 0) {
return OPJ_LRCP; return OPJ_LRCP;
} }
@ -373,7 +375,8 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
return OPJ_PROG_UNKNOWN; return OPJ_PROG_UNKNOWN;
} }
static unsigned int get_num_images(char *imgdirpath){ static unsigned int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
unsigned int num_images = 0; unsigned int num_images = 0;
@ -381,13 +384,13 @@ static unsigned int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
num_images=0; num_images=0;
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -396,7 +399,8 @@ static unsigned int get_num_images(char *imgdirpath){
return num_images; return num_images;
} }
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -404,25 +408,26 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
strcpy(dirptr->filename[i],content->d_name); strcpy(dirptr->filename[i],content->d_name);
i++; i++;
} }
closedir(dir); closedir(dir);
return 0; return 0;
} }
static int get_file_format(char *filename) { static int get_file_format(char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = { static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@ -442,12 +447,14 @@ static int get_file_format(char *filename) {
return -1; return -1;
} }
static char * get_file_name(char *name){ static char * get_file_name(char *name)
{
char *fname = strtok(name,"."); char *fname = strtok(name,".");
return fname; return fname;
} }
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; 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]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -463,11 +470,11 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename)); strcpy(temp_ofname,get_file_name(image_filename));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
@ -479,10 +486,11 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/* ------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size) { img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size)
{
OPJ_UINT32 i, j; OPJ_UINT32 i, j;
int totlen, c; int totlen, c;
opj_option_t long_option[]={ opj_option_t long_option[]= {
{"cinema2K",REQ_ARG, NULL ,'w'}, {"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4K",NO_ARG, NULL ,'y'}, {"cinema4K",NO_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'z'}, {"ImgDir",REQ_ARG, NULL ,'z'},
@ -498,22 +506,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* parse the command line */ /* parse the command line */
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:" const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:"
#ifdef USE_JPWL #ifdef USE_JPWL
"W:" "W:"
#endif /* USE_JPWL */ #endif /* USE_JPWL */
"h"; "h";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format=0; img_fol->set_out_format=0;
raw_cp->rawWidth = 0; raw_cp->rawWidth = 0;
do{ do {
c = opj_getopt_long(argc, argv, optlist,long_option,totlen); c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -537,12 +544,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -557,11 +563,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* output format */ case 'O': { /* output format */
{
char outformat[50]; char outformat[50];
char *of = opj_optarg; char *of = opj_optarg;
sprintf(outformat,".%s",of); sprintf(outformat,".%s",of);
@ -577,14 +582,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */ case 'r': { /* rates rates/distorsion */
{
char *s = opj_optarg; char *s = opj_optarg;
parameters->tcp_numlayers = 0; parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@ -598,13 +602,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
parameters->cp_disto_alloc = 1; parameters->cp_disto_alloc = 1;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'F': /* Raw image format parameters */ case 'F': { /* Raw image format parameters */
{
OPJ_BOOL wrong = OPJ_FALSE; OPJ_BOOL wrong = OPJ_FALSE;
char *substr1; char *substr1;
char *substr2; char *substr2;
@ -687,12 +690,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'q': /* add fixed_quality */ case 'q': { /* add fixed_quality */
{
char *s = opj_optarg; char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++; parameters->tcp_numlayers++;
@ -705,13 +707,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
parameters->cp_fixed_quality = 1; parameters->cp_fixed_quality = 1;
} }
break; break;
/* dda */ /* dda */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */ case 'f': { /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL; int *row = NULL, *col = NULL;
OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0; OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0;
@ -753,28 +754,25 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
parameters->cp_fixed_alloc = 1; parameters->cp_fixed_alloc = 1;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* tiles */ case 't': { /* tiles */
{
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy); sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE; parameters->tile_size_on = OPJ_TRUE;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'n': /* resolution */ case 'n': { /* resolution */
{
sscanf(opj_optarg, "%d", &parameters->numresolution); sscanf(opj_optarg, "%d", &parameters->numresolution);
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'c': /* precinct dimension */ case 'c': { /* precinct dimension */
{
char sep; char sep;
int res_spec = 0; int res_spec = 0;
@ -783,26 +781,23 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
do { do {
sep = 0; sep = 0;
ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec], ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep); &parameters->prch_init[res_spec], &sep);
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) {
{ fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep);
fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep); fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n"); return 1;
return 1; }
}
parameters->csty |= 0x01; parameters->csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
} } while (sep == ',');
while (sep == ',');
parameters->res_spec = res_spec; parameters->res_spec = res_spec;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'b': /* code-block dimension */ case 'b': { /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0; int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@ -815,12 +810,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->cblockw_init = cblockw_init; parameters->cblockw_init = cblockw_init;
parameters->cblockh_init = cblockh_init; parameters->cblockh_init = cblockh_init;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* creation of index file */ case 'x': { /* creation of index file */
{
if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) { if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) {
return 1; return 1;
} }
@ -830,12 +824,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
" '-x' option ignored.\n"); " '-x' option ignored.\n");
/* << FIXME ADE INDEX */ /* << FIXME ADE INDEX */
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': { /* progression order */
{
char progression[4]; char progression[4];
strncpy(progression, opj_optarg, 4); strncpy(progression, opj_optarg, 4);
@ -846,24 +839,22 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 's': /* subsampling factor */ case 's': { /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx, if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) { &parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */ case 'd': { /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0, if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) { &parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument " fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@ -871,18 +862,17 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* display an help description */ case 'h': /* display an help description */
encode_help_display(); encode_help_display();
return 1; return 1;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'P': /* POC */ case 'P': { /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */ int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@ -905,28 +895,25 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
parameters->numpocs = (OPJ_UINT32)numpocs; parameters->numpocs = (OPJ_UINT32)numpocs;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'S': /* SOP marker */ case 'S': { /* SOP marker */
{
parameters->csty |= 0x02; parameters->csty |= 0x02;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'E': /* EPH marker */ case 'E': { /* EPH marker */
{
parameters->csty |= 0x04; parameters->csty |= 0x04;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */ case 'M': { /* Mode switch pas tous au point !! */
{
int value = 0; int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) { if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) { for (i = 0; i <= 5; i++) {
@ -936,85 +923,78 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
} }
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'R': /* ROI */ case 'R': { /* ROI */
{
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno, if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) { &parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
return 1; return 1;
} }
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'T': /* Tile offset */ case 'T': { /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) { if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1; return 1;
} }
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'C': /* add a comment */ case 'C': { /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) { if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg); strcpy(parameters->cp_comment, opj_optarg);
} }
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'I': /* reversible or not */ case 'I': { /* reversible or not */
{
parameters->irreversible = 1; parameters->irreversible = 1;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'u': /* Tile part generation*/ case 'u': { /* Tile part generation*/
{
parameters->tp_flag = opj_optarg[0]; parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1; parameters->tp_on = 1;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'z': /* Image Directory path */ case 'z': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'w': /* Digital Cinema 2K profile compliance*/ case 'w': { /* Digital Cinema 2K profile compliance*/
{
int fps=0; int fps=0;
sscanf(opj_optarg,"%d",&fps); sscanf(opj_optarg,"%d",&fps);
if(fps == 24){ if(fps == 24) {
parameters->rsiz = OPJ_PROFILE_CINEMA_2K; parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_24_COMP; parameters->max_comp_size = OPJ_CINEMA_24_COMP;
parameters->max_cs_size = OPJ_CINEMA_24_CS; parameters->max_cs_size = OPJ_CINEMA_24_CS;
}else if(fps == 48 ){ } else if(fps == 48 ) {
parameters->rsiz = OPJ_PROFILE_CINEMA_2K; parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_48_COMP; parameters->max_comp_size = OPJ_CINEMA_48_COMP;
parameters->max_cs_size = OPJ_CINEMA_48_CS; parameters->max_cs_size = OPJ_CINEMA_48_CS;
}else { } else {
fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
return 1; return 1;
} }
@ -1022,37 +1002,34 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
"Other options specified could be overriden\n"); "Other options specified could be overriden\n");
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'y': /* Digital Cinema 4K profile compliance*/ case 'y': { /* Digital Cinema 4K profile compliance*/
{
parameters->rsiz = OPJ_PROFILE_CINEMA_4K; parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
fprintf(stdout,"CINEMA 4K profile activated\n" fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overriden\n"); "Other options specified could be overriden\n");
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/ case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
{
int mct_mode=0; int mct_mode=0;
sscanf(opj_optarg,"%d",&mct_mode); sscanf(opj_optarg,"%d",&mct_mode);
if(mct_mode < 0 || mct_mode > 2){ if(mct_mode < 0 || mct_mode > 2) {
fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n"); fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n");
return 1; return 1;
} }
parameters->tcp_mct = (char) mct_mode; parameters->tcp_mct = (char) mct_mode;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'm': /* mct input file */ case 'm': { /* mct input file */
{
char *lFilename = opj_optarg; char *lFilename = opj_optarg;
char *lMatrix; char *lMatrix;
char *lCurrentPtr ; char *lCurrentPtr ;
@ -1107,14 +1084,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
lCurrentDoublePtr = lSpace; lCurrentDoublePtr = lSpace;
for (i2=0;i2<lMctComp;++i2) { for (i2=0; i2<lMctComp; ++i2) {
lStrLen = strlen(lCurrentPtr) + 1; lStrLen = strlen(lCurrentPtr) + 1;
*lCurrentDoublePtr++ = (float) atof(lCurrentPtr); *lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
lCurrentPtr += lStrLen; lCurrentPtr += lStrLen;
} }
l_int_ptr = (int*) lCurrentDoublePtr; l_int_ptr = (int*) lCurrentDoublePtr;
for (i2=0;i2<lNbComp;++i2) { for (i2=0; i2<lNbComp; ++i2) {
lStrLen = strlen(lCurrentPtr) + 1; lStrLen = strlen(lCurrentPtr) + 1;
*l_int_ptr++ = atoi(lCurrentPtr); *l_int_ptr++ = atoi(lCurrentPtr);
lCurrentPtr += lStrLen; lCurrentPtr += lStrLen;
@ -1127,17 +1104,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
free(lSpace); free(lSpace);
free(lMatrix); free(lMatrix);
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'W': /* JPWL capabilities switched on */ case 'W': { /* JPWL capabilities switched on */
{
char *token = NULL; char *token = NULL;
int hprot, pprot, sens, addr, size, range; int hprot, pprot, sens, addr, size, range;
@ -1164,7 +1140,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if(sscanf(token, "h=%d", &hprot) == 1) { if(sscanf(token, "h=%d", &hprot) == 1) {
/* Main header, specified */ /* Main header, specified */
if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) ||
((hprot >= 37) && (hprot <= 128)))) { ((hprot >= 37) && (hprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", hprot); fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", hprot);
return 1; return 1;
} }
@ -1173,7 +1149,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} else if(sscanf(token, "h%d=%d", &tile, &hprot) == 2) { } else if(sscanf(token, "h%d=%d", &tile, &hprot) == 2) {
/* Tile part header, specified */ /* Tile part header, specified */
if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) ||
((hprot >= 37) && (hprot <= 128)))) { ((hprot >= 37) && (hprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot); fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot);
return 1; return 1;
} }
@ -1219,7 +1195,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (sscanf(token, "p=%d", &pprot) == 1) { if (sscanf(token, "p=%d", &pprot) == 1) {
/* Method for all tiles and all packets */ /* Method for all tiles and all packets */
if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
((pprot >= 37) && (pprot <= 128)))) { ((pprot >= 37) && (pprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", pprot); fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", pprot);
return 1; return 1;
} }
@ -1230,7 +1206,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) { } else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) {
/* method specified from that tile on */ /* method specified from that tile on */
if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
((pprot >= 37) && (pprot <= 128)))) { ((pprot >= 37) && (pprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
return 1; return 1;
} }
@ -1247,7 +1223,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) { } else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) {
/* method fully specified from that tile and that packet on */ /* method fully specified from that tile and that packet on */
if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
((pprot >= 37) && (pprot <= 128)))) { ((pprot >= 37) && (pprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
return 1; return 1;
} }
@ -1268,7 +1244,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) { } else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) {
/* default method from that tile and that packet on */ /* default method from that tile and that packet on */
if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) ||
((pprot >= 37) && (pprot <= 128)))) { ((pprot >= 37) && (pprot <= 128)))) {
fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot);
return 1; return 1;
} }
@ -1450,51 +1426,50 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->jpwl_epc_on = OPJ_TRUE; parameters->jpwl_epc_on = OPJ_TRUE;
} }
break; break;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'J': /* jpip on */ case 'J': { /* jpip on */
{
parameters->jpip_on = OPJ_TRUE; parameters->jpip_on = OPJ_TRUE;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
default: default:
fprintf(stderr, "[WARNING] An invalid option has been ignored\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored\n");
break; break;
} }
}while(c != -1); } while(c != -1);
if(img_fol->set_imgdir == 1){ if(img_fol->set_imgdir == 1) {
if(!(parameters->infile[0] == 0)){ if(!(parameters->infile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n");
return 1; return 1;
} }
if(!((parameters->outfile[0] == 0))){ if(!((parameters->outfile[0] == 0))) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n"); fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n");
return 1; return 1;
} }
}else{ } else {
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] Required parameters are missing\n" fprintf(stderr, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.pgm -o image.j2k\n",argv[0]); "Example: %s -i image.pgm -o image.j2k\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]); fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1; return 1;
} }
} }
if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0) if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0)
|| (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) { || (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) {
fprintf(stderr,"[ERROR] invalid raw image parameters\n"); fprintf(stderr,"[ERROR] invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n"); fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
@ -1533,9 +1508,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* If subsampled image is provided, automatically disable MCT */ /* If subsampled image is provided, automatically disable MCT */
if ( ((parameters->decod_format == RAW_DFMT) || (parameters->decod_format == RAWL_DFMT)) if ( ((parameters->decod_format == RAW_DFMT) || (parameters->decod_format == RAWL_DFMT))
&& ( ((raw_cp->rawComp > 1 ) && ((raw_cp->rawComps[1].dx > 1) || (raw_cp->rawComps[1].dy > 1))) && ( ((raw_cp->rawComp > 1 ) && ((raw_cp->rawComps[1].dx > 1) || (raw_cp->rawComps[1].dy > 1)))
|| ((raw_cp->rawComp > 2 ) && ((raw_cp->rawComps[2].dx > 1) || (raw_cp->rawComps[2].dy > 1))) || ((raw_cp->rawComp > 2 ) && ((raw_cp->rawComps[2].dx > 1) || (raw_cp->rawComps[2].dy > 1)))
)) { )) {
parameters->tcp_mct = 0; parameters->tcp_mct = 0;
} }
@ -1547,43 +1522,47 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/** /**
sample error debug callback expecting no client object sample error debug callback expecting no client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[ERROR] %s", msg); fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning debug callback expecting no client object sample warning debug callback expecting no client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[WARNING] %s", msg); fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
OPJ_FLOAT64 opj_clock(void) { OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32 #ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */ /* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ; QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */ /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */ /* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ; QueryPerformanceCounter ( & t ) ;
return freq.QuadPart ? ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) : 0 ; return freq.QuadPart ? ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) : 0 ;
#else #else
/* Unix or Linux: use resource usage */ /* Unix or Linux: use resource usage */
struct rusage t; struct rusage t;
OPJ_FLOAT64 procTime; OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */ /* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t); getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */ /* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */ /* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec); procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */ /* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
@ -1596,7 +1575,8 @@ OPJ_FLOAT64 opj_clock(void) {
* OPJ_COMPRESS MAIN * OPJ_COMPRESS MAIN
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */
@ -1639,35 +1619,35 @@ int main(int argc, char **argv) {
} }
/* Read directory if necessary */ /* Read directory if necessary */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ 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*)); dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return 0; return 0;
} }
for(i=0;i<num_images;i++){ for(i=0; i<num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return 0; return 0;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return 0; return 0;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/*Encoding image one by one*/ /*Encoding image one by one*/
for(imageno=0;imageno<num_images;imageno++) { for(imageno=0; imageno<num_images; imageno++) {
image = NULL; image = NULL;
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file((int)imageno, dirptr,&img_fol, &parameters)) { if (get_next_file((int)imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
@ -1769,8 +1749,8 @@ int main(int argc, char **argv) {
} }
/* Can happen if input file is TIFF or PNG /* Can happen if input file is TIFF or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/ */
if( !image) { if( !image) {
fprintf(stderr, "Unable to load file: got no image\n"); fprintf(stderr, "Unable to load file: got no image\n");
return 1; return 1;
@ -1780,12 +1760,12 @@ int main(int argc, char **argv) {
if (parameters.tcp_mct == (char) 255) { /* mct mode has not been set in commandline */ if (parameters.tcp_mct == (char) 255) { /* mct mode has not been set in commandline */
parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0; parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0;
} else { /* mct mode has been set in commandline */ } else { /* mct mode has been set in commandline */
if ((parameters.tcp_mct == 1) && (image->numcomps < 3)){ if ((parameters.tcp_mct == 1) && (image->numcomps < 3)) {
fprintf(stderr, "RGB->YCC conversion cannot be used:\n"); fprintf(stderr, "RGB->YCC conversion cannot be used:\n");
fprintf(stderr, "Input image has less than 3 components\n"); fprintf(stderr, "Input image has less than 3 components\n");
return 1; return 1;
} }
if ((parameters.tcp_mct == 2) && (!parameters.mct_data)){ if ((parameters.tcp_mct == 2) && (!parameters.mct_data)) {
fprintf(stderr, "Custom MCT has been set but no array-based MCT\n"); fprintf(stderr, "Custom MCT has been set but no array-based MCT\n");
fprintf(stderr, "has been provided. Aborting.\n"); fprintf(stderr, "has been provided. Aborting.\n");
return 1; return 1;
@ -1796,14 +1776,12 @@ int main(int argc, char **argv) {
/* ---------------------------- */ /* ---------------------------- */
switch(parameters.cod_format) { switch(parameters.cod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_J2K); l_codec = opj_create_compress(OPJ_CODEC_J2K);
break; break;
} }
case JP2_CFMT: /* JPEG 2000 compressed image data */ case JP2_CFMT: { /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_JP2); l_codec = opj_create_compress(OPJ_CODEC_JP2);
break; break;
@ -1835,7 +1813,7 @@ int main(int argc, char **argv) {
/* open a byte stream for writing and allocate memory for all tiles */ /* open a byte stream for writing and allocate memory for all tiles */
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE); l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
if (! l_stream){ if (! l_stream) {
return 1; return 1;
} }
@ -1849,7 +1827,7 @@ int main(int argc, char **argv) {
OPJ_UINT32 l_data_size = 512*512*3; OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) calloc( 1,l_data_size); l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
assert( l_data ); assert( l_data );
for (i=0;i<l_nb_tiles;++i) { for (i=0; i<l_nb_tiles; ++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) { if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i); fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1859,8 +1837,7 @@ int main(int argc, char **argv) {
} }
} }
free(l_data); free(l_data);
} } else {
else {
bSuccess = bSuccess && opj_encode(l_codec, l_stream); bSuccess = bSuccess && opj_encode(l_codec, l_stream);
if (!bSuccess) { if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_encode\n"); fprintf(stderr, "failed to encode image: opj_encode\n");
@ -1876,11 +1853,11 @@ int main(int argc, char **argv) {
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
fprintf(stderr, "failed to encode image\n"); fprintf(stderr, "failed to encode image\n");
remove(parameters.outfile); remove(parameters.outfile);
return 1; return 1;
} }
num_compressed_files++; num_compressed_files++;
fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated outfile %s\n",parameters.outfile);
/* close and free the byte stream */ /* close and free the byte stream */
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1900,7 +1877,7 @@ int main(int argc, char **argv) {
t = opj_clock() - t; t = opj_clock() - t;
if (num_compressed_files) { if (num_compressed_files) {
fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000.0)/(OPJ_FLOAT64)num_compressed_files)); fprintf(stdout, "encode time: %d ms \n", (int)((t * 1000.0)/(OPJ_FLOAT64)num_compressed_files));
} }
return 0; return 0;

File diff suppressed because it is too large Load Diff

View File

@ -59,26 +59,26 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
const char *out_format; const char *out_format;
/** Enable option*/ /** Enable option*/
char set_imgdir; char set_imgdir;
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
char set_out_format; char set_out_format;
int flag; int flag;
}img_fol_t; } img_fol_t;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Declarations */ /* Declarations */
@ -91,7 +91,8 @@ static int infile_format(const char *fname);
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol); static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static void decode_help_display(void) { static void decode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
"It dumps JPEG 2000 codestream info to stdout or a given file.\n" "It dumps JPEG 2000 codestream info to stdout or a given file.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@ -100,120 +101,124 @@ static void decode_help_display(void) {
fprintf(stdout,"-----------\n"); fprintf(stdout,"-----------\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," -ImgDir <directory>\n"); fprintf(stdout," -ImgDir <directory>\n");
fprintf(stdout," Image file Directory path \n"); fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -i <compressed file>\n"); fprintf(stdout," -i <compressed file>\n");
fprintf(stdout," REQUIRED only if an Input image directory not specified\n"); fprintf(stdout," REQUIRED only if an Input image directory not specified\n");
fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n"); fprintf(stdout," Currently accepts J2K-files, JP2-files and JPT-files. The file type\n");
fprintf(stdout," is identified based on its suffix.\n"); fprintf(stdout," is identified based on its suffix.\n");
fprintf(stdout," -o <output file>\n"); fprintf(stdout," -o <output file>\n");
fprintf(stdout," OPTIONAL\n"); fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Output file where file info will be dump.\n"); fprintf(stdout," Output file where file info will be dump.\n");
fprintf(stdout," By default it will be in the stdout.\n"); fprintf(stdout," By default it will be in the stdout.\n");
fprintf(stdout," -v "); /* FIXME WIP_MSD */ fprintf(stdout," -v "); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n"); fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Enable informative messages\n"); fprintf(stdout," Enable informative messages\n");
fprintf(stdout," By default verbose mode is off.\n"); fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){ static int get_num_images(char *imgdirpath)
DIR *dir; {
struct dirent* content; DIR *dir;
int num_images = 0; struct dirent* content;
int num_images = 0;
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
} }
closedir(dir); closedir(dir);
return num_images; return num_images;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
DIR *dir; {
struct dirent* content; DIR *dir;
int i = 0; struct dirent* content;
int i = 0;
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
strcpy(dirptr->filename[i],content->d_name); strcpy(dirptr->filename[i],content->d_name);
i++; i++;
} }
closedir(dir); closedir(dir);
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_file_format(const char *filename) { static int get_file_format(const char *filename)
unsigned int i; {
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; unsigned int i;
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
const char *ext = strrchr(filename, '.'); static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
if (ext == NULL) const char *ext = strrchr(filename, '.');
return -1; if (ext == NULL)
ext++; return -1;
if(ext) { ext++;
for(i = 0; i < sizeof(format)/sizeof(*format); i++) { if(ext) {
if(_strnicmp(ext, extension[i], 3) == 0) { for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
return format[i]; if(_strnicmp(ext, extension[i], 3) == 0) {
} return format[i];
} }
} }
}
return -1; return -1;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ static 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]=""; 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]="";
strcpy(image_filename,dirptr->filename[imageno]); strcpy(image_filename,dirptr->filename[imageno]);
fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename); fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename); parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1) if (parameters->decod_format == -1)
return 1; return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename); sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) { if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1; return 1;
} }
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,strtok(image_filename,".")); strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
} }
} }
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -224,169 +229,164 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
static int infile_format(const char *fname) static int infile_format(const char *fname)
{ {
FILE *reader; FILE *reader;
const char *s, *magic_s; const char *s, *magic_s;
int ext_format, magic_format; int ext_format, magic_format;
unsigned char buf[12]; unsigned char buf[12];
size_t l_nb_read; size_t l_nb_read;
reader = fopen(fname, "rb"); reader = fopen(fname, "rb");
if (reader == NULL) if (reader == NULL)
return -1; return -1;
memset(buf, 0, 12); memset(buf, 0, 12);
l_nb_read = fread(buf, 1, 12, reader); l_nb_read = fread(buf, 1, 12, reader);
fclose(reader); fclose(reader);
if (l_nb_read != 12) if (l_nb_read != 12)
return -1; return -1;
ext_format = get_file_format(fname); ext_format = get_file_format(fname);
if (ext_format == JPT_CFMT) if (ext_format == JPT_CFMT)
return JPT_CFMT; return JPT_CFMT;
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT; magic_format = JP2_CFMT;
magic_s = ".jp2"; magic_s = ".jp2";
} } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) { magic_format = J2K_CFMT;
magic_format = J2K_CFMT; magic_s = ".j2k or .jpc or .j2c";
magic_s = ".j2k or .jpc or .j2c"; } else
} return -1;
else
return -1;
if (magic_format == ext_format) if (magic_format == ext_format)
return ext_format; return ext_format;
s = fname + strlen(fname) - 4; s = fname + strlen(fname) - 4;
fputs("\n===========================================\n", stderr); fputs("\n===========================================\n", stderr);
fprintf(stderr, "The extension of this file is incorrect.\n" fprintf(stderr, "The extension of this file is incorrect.\n"
"FOUND %s. SHOULD BE %s\n", s, magic_s); "FOUND %s. SHOULD BE %s\n", s, magic_s);
fputs("===========================================\n", stderr); fputs("===========================================\n", stderr);
return magic_format; return magic_format;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/** /**
* Parse the command line * Parse the command line
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol)
int totlen, c; {
opj_option_t long_option[]={ int totlen, c;
opj_option_t long_option[]= {
{"ImgDir",REQ_ARG, NULL ,'y'} {"ImgDir",REQ_ARG, NULL ,'y'}
}; };
const char optlist[] = "i:o:f:hv"; const char optlist[] = "i:o:f:hv";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
do { do {
c = opj_getopt_long(argc, argv,optlist,long_option,totlen); c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{ char *infile = opj_optarg;
char *infile = opj_optarg; parameters->decod_format = infile_format(infile);
parameters->decod_format = infile_format(infile); switch(parameters->decod_format) {
switch(parameters->decod_format) { case J2K_CFMT:
case J2K_CFMT: break;
break; case JP2_CFMT:
case JP2_CFMT: break;
break; case JPT_CFMT:
case JPT_CFMT: break;
break; default:
default: fprintf(stderr,
fprintf(stderr, "[ERROR] Unknown input file format: %s \n"
"[ERROR] Unknown input file format: %s \n" " Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n", infile);
infile); return 1;
return 1; }
} if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) { fprintf(stderr, "[ERROR] Path is too long\n");
fprintf(stderr, "[ERROR] Path is too long\n"); return 1;
return 1; }
} }
}
break;
/* ------------------------------------------------------ */
case 'o': /* output file */
{
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
}
break;
/* ----------------------------------------------------- */
case 'f': /* flag */
img_fol->flag = atoi(opj_optarg);
break; break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */ /* ------------------------------------------------------ */
decode_help_display();
return 1;
/* ------------------------------------------------------ */ case 'o': { /* output file */
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
}
break;
case 'y': /* Image Directory path */ /* ----------------------------------------------------- */
{ case 'f': /* flag */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->flag = atoi(opj_optarg);
strcpy(img_fol->imgdirpath,opj_optarg); break;
img_fol->set_imgdir=1; /* ----------------------------------------------------- */
}
break;
/* ----------------------------------------------------- */ case 'h': /* display an help description */
decode_help_display();
return 1;
case 'v': /* Verbose mode */ /* ------------------------------------------------------ */
{
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */ case 'y': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'v': { /* Verbose mode */
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */
default: default:
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break; break;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)){ if(!(parameters->infile[0]==0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1; return 1;
} }
if(!(parameters->outfile[0] == 0)){ if(!(parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n");
return 1; return 1;
} }
}else{ } else {
if(parameters->infile[0] == 0) { if(parameters->infile[0] == 0) {
fprintf(stderr, "[ERROR] Required parameter is missing\n"); fprintf(stderr, "[ERROR] Required parameter is missing\n");
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]); fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
fprintf(stderr, " Help: %s -h\n",argv[0]); fprintf(stderr, " Help: %s -h\n",argv[0]);
return 1; return 1;
} }
} }
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -394,23 +394,26 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/** /**
sample error debug callback expecting no client object sample error debug callback expecting no client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[ERROR] %s", msg); (void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning debug callback expecting no client object sample warning debug callback expecting no client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[WARNING] %s", msg); (void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
(void)client_data; {
fprintf(stdout, "[INFO] %s", msg); (void)client_data;
fprintf(stdout, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -420,178 +423,174 @@ static void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FILE *fout = NULL; FILE *fout = NULL;
opj_dparameters_t parameters; /* Decompression parameters */ opj_dparameters_t parameters; /* Decompression parameters */
opj_image_t* image = NULL; /* Image structure */ opj_image_t* image = NULL; /* Image structure */
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */ opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
opj_stream_t *l_stream = NULL; /* Stream */ opj_stream_t *l_stream = NULL; /* Stream */
opj_codestream_info_v2_t* cstr_info = NULL; opj_codestream_info_v2_t* cstr_info = NULL;
opj_codestream_index_t* cstr_index = NULL; opj_codestream_index_t* cstr_index = NULL;
OPJ_INT32 num_images, imageno; OPJ_INT32 num_images, imageno;
img_fol_t img_fol; img_fol_t img_fol;
dircnt_t *dirptr = NULL; dircnt_t *dirptr = NULL;
#ifdef MSD #ifdef MSD
OPJ_BOOL l_go_on = OPJ_TRUE; OPJ_BOOL l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000; OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000); OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
#endif #endif
/* Set decoding parameters to default values */ /* Set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters); opj_set_default_decoder_parameters(&parameters);
/* Initialize img_fol */ /* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t)); memset(&img_fol,0,sizeof(img_fol_t));
img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND; img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
/* Parse input and get user encoding parameters */ /* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) { if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Initialize reading of directory */ /* Initialize reading of directory */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
int it_image; int it_image;
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
for(it_image=0;it_image<num_images;it_image++){ for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/* Try to open for writing the output file if necessary */ /* Try to open for writing the output file if necessary */
if (parameters.outfile[0] != 0){ if (parameters.outfile[0] != 0) {
fout = fopen(parameters.outfile,"w"); fout = fopen(parameters.outfile,"w");
if (!fout){ if (!fout) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} } else
else fout = stdout;
fout = stdout;
/* Read the header of each image one by one */ /* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++){ for(imageno = 0; imageno < num_images ; imageno++) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
} }
} }
/* Read the input file and put it in memory */ /* Read the input file and put it in memory */
/* ---------------------------------------- */ /* ---------------------------------------- */
l_stream = opj_stream_create_default_file_stream(parameters.infile,1); l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){ if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Read the JPEG2000 stream */ /* Read the JPEG2000 stream */
/* ------------------------ */ /* ------------------------ */
switch(parameters.decod_format) { switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{ /* Get a decoder handle */
/* Get a decoder handle */ l_codec = opj_create_decompress(OPJ_CODEC_J2K);
l_codec = opj_create_decompress(OPJ_CODEC_J2K); break;
break; }
} case JP2_CFMT: { /* JPEG 2000 compressed image data */
case JP2_CFMT: /* JPEG 2000 compressed image data */ /* Get a decoder handle */
{ l_codec = opj_create_decompress(OPJ_CODEC_JP2);
/* Get a decoder handle */ break;
l_codec = opj_create_decompress(OPJ_CODEC_JP2); }
break; case JPT_CFMT: { /* JPEG 2000, JPIP */
} /* Get a decoder handle */
case JPT_CFMT: /* JPEG 2000, JPIP */ l_codec = opj_create_decompress(OPJ_CODEC_JPT);
{ break;
/* Get a decoder handle */ }
l_codec = opj_create_decompress(OPJ_CODEC_JPT); default:
break; fprintf(stderr, "skipping file..\n");
} opj_stream_destroy(l_stream);
default: continue;
fprintf(stderr, "skipping file..\n"); }
opj_stream_destroy(l_stream);
continue;
}
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00); opj_set_info_handler(l_codec, info_callback,00);
opj_set_warning_handler(l_codec, warning_callback,00); opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback,00);
/* Setup the decoder decoding parameters using user parameters */ /* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ){ if ( !opj_setup_decoder(l_codec, &parameters) ) {
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
fclose(fout); fclose(fout);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/* Read the main header of the codestream and if necessary the JP2 boxes*/ /* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)){ if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
opj_image_destroy(image); opj_image_destroy(image);
fclose(fout); fclose(fout);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
opj_dump_codec(l_codec, img_fol.flag, fout ); opj_dump_codec(l_codec, img_fol.flag, fout );
cstr_info = opj_get_cstr_info(l_codec); cstr_info = opj_get_cstr_info(l_codec);
cstr_index = opj_get_cstr_index(l_codec); cstr_index = opj_get_cstr_index(l_codec);
/* close the byte stream */ /* close the byte stream */
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
/* free remaining structures */ /* free remaining structures */
if (l_codec) { if (l_codec) {
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
} }
/* destroy the image header */ /* destroy the image header */
opj_image_destroy(image); opj_image_destroy(image);
/* destroy the codestream index */ /* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index); opj_destroy_cstr_index(&cstr_index);
/* destroy the codestream info */ /* destroy the codestream info */
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
} }
/* Close the output file */ /* Close the output file */
fclose(fout); fclose(fout);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -106,14 +106,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -239,16 +239,16 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data. * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be * We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -261,21 +261,21 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/ /*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -344,46 +344,45 @@ static void _setdirname (struct DIR *dirp);
*/ */
static DIR *opendir(const char *dirname) static DIR *opendir(const char *dirname)
{ {
DIR *dirp; DIR *dirp;
assert (dirname != NULL); assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR)); dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) { if (dirp != NULL) {
char *p; char *p;
/* allocate room for directory name */ /* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*")); dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) { if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */ /* failed to duplicate directory name. errno set by malloc() */
free (dirp); free (dirp);
return NULL; return NULL;
} }
/* Copy directory name while appending directory separator and "*.*". /* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with * Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be * drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */ * '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{ strcpy (p++, "\\");
strcpy (p++, "\\"); }
}
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
strcpy (p, "*"); /*scan files with and without extension in win32*/ strcpy (p, "*"); /*scan files with and without extension in win32*/
# else # else
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/ strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif # endif
/* open stream */ /* open stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed */ /* initialization failed */
free (dirp->dirname); free (dirp->dirname);
free (dirp); free (dirp);
return NULL; return NULL;
}
} }
} return dirp;
return dirp;
} }
@ -436,55 +435,55 @@ static DIR *opendir(const char *dirname)
static struct dirent * static struct dirent *
readdir (DIR *dirp) readdir (DIR *dirp)
{ {
assert(dirp != NULL); assert(dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */ /* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#endif #endif
if (dirp->dirent_filled != 0) { if (dirp->dirent_filled != 0) {
/* /*
* Directory entry has already been retrieved and there is no need to * Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance * retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so * when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading * because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream * the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to * automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to * save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry. * return the saved entry when the user tries to read the first entry.
*/ */
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
} else { } else {
/* fill in entry and return that */ /* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) { if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle); FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT; errno = ENOENT;
return NULL; return NULL;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) { if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no /* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return NULL; return NULL;
} }
# endif # endif
_setdirname (dirp); _setdirname (dirp);
assert (dirp->dirent_filled == 0); assert (dirp->dirent_filled == 0);
} }
return &dirp->current; return &dirp->current;
} }
@ -510,36 +509,36 @@ readdir (DIR *dirp)
static int static int
closedir (DIR *dirp) closedir (DIR *dirp)
{ {
int retcode = 0; int retcode = 0;
/* make sure that dirp points to legal structure */ /* make sure that dirp points to legal structure */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
/* free directory name and search handles */ /* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname); if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
retcode = -1; retcode = -1;
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* clear dirp structure to make sure that it cannot be used anymore*/ /* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp)); memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
# endif # endif
free (dirp); free (dirp);
return retcode; return retcode;
} }
@ -567,30 +566,30 @@ closedir (DIR *dirp)
static void static void
rewinddir (DIR *dirp) rewinddir (DIR *dirp)
{ {
/* make sure that dirp is legal */ /* make sure that dirp is legal */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return; return;
} }
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
/* close previous stream */ /* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* re-open previous stream */ /* re-open previous stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice /* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */ * error later when she tries to retrieve first directory enty. */
/*EMPTY*/; /*EMPTY*/;
} }
} }
@ -601,36 +600,35 @@ rewinddir (DIR *dirp)
static int static int
_initdir (DIR *dirp) _initdir (DIR *dirp)
{ {
assert (dirp != NULL); assert (dirp != NULL);
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */ /* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data); dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could /* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map * give us more information about the error, but then we should map
* the error code into errno. */ * the error code into errno. */
errno = ENOENT; errno = ENOENT;
return 0; return 0;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{ /* _dos_findfirst and findfirst will set errno to ENOENT when no
/* _dos_findfirst and findfirst will set errno to ENOENT when no * more entries could be retrieved. */
* more entries could be retrieved. */ return 0;
return 0; }
}
# endif # endif
/* initialize DIR and it's first entry */ /* initialize DIR and it's first entry */
_setdirname (dirp); _setdirname (dirp);
dirp->dirent_filled = 1; dirp->dirent_filled = 1;
return 1; return 1;
} }
@ -641,13 +639,13 @@ static const char *
_getdirname (const struct dirent *dp) _getdirname (const struct dirent *dp)
{ {
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName; return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK) #elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name; return dp->data.ff_name;
#else #else
return dp->data.name; return dp->data.name;
#endif #endif
} }
@ -656,14 +654,15 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
/* make sure that d_name is long enough */ {
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name, strncpy (dirp->current.d_name,
_getdirname (&dirp->current), _getdirname (&dirp->current),
NAME_MAX); NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -42,9 +42,9 @@ static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#include <string.h> #include <string.h>
int opterr = 1, /* if error message should be printed */ int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */ optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */ optopt, /* character checked for validity */
optreset; /* reset getopt */ optreset; /* reset getopt */
char *optarg; /* argument associated with option */ char *optarg; /* argument associated with option */
#define BADCH (int)'?' #define BADCH (int)'?'
@ -55,55 +55,56 @@ char *optarg; /* argument associated with option */
* getopt -- * getopt --
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
*/ */
int getopt(int nargc, char *const *nargv, const char *ostr) { int getopt(int nargc, char *const *nargv, const char *ostr)
{
# define __progname nargv[0] /* program name */ # define __progname nargv[0] /* program name */
static char *place = EMSG; /* option letter processing */ static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */ char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */ if (optreset || !*place) { /* update scanning pointer */
optreset = 0; optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') { if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG; place = EMSG;
return (-1); return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) {
/* if the user didn't specify '-' as an option, assume it means -1. */
if (optopt == (int) '-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt);
return (BADCH);
} }
if (place[1] && *++place == '-') { /* found "--" */
++optind; if (*++oli != ':') { /* don't need argument */
place = EMSG; optarg = NULL;
return (-1); if (!*place)
++optind;
} else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt);
return (BADCH);
} else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
} }
} /* option letter okay? */ return (optopt); /* dump back option letter */
if ((optopt = (int) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) {
/* if the user didn't specify '-' as an option, assume it means -1. */
if (optopt == (int) '-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
} else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt);
return (BADCH);
} else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
} }

File diff suppressed because it is too large Load Diff

View File

@ -48,326 +48,320 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static double calc_PSNR(opj_volume_t *original, opj_volume_t *decoded) static double calc_PSNR(opj_volume_t *original, opj_volume_t *decoded)
{ {
int max, i, k, compno = 0, size; int max, i, k, compno = 0, size;
double sum, total = 0; double sum, total = 0;
int global = 1; int global = 1;
max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1; max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1;
if (global) { if (global) {
size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0); size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0);
for (compno = 0; compno < original->numcomps; compno++) { for (compno = 0; compno < original->numcomps; compno++) {
for(sum = 0, i = 0; i < size; ++i) { for(sum = 0, i = 0; i < size; ++i) {
if ((decoded->comps[compno].data[i] < 0) || (decoded->comps[compno].data[i] > max)) if ((decoded->comps[compno].data[i] < 0) || (decoded->comps[compno].data[i] > max))
fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n"); fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n");
else else
sum += (original->comps[compno].data[i] - decoded->comps[compno].data[i]) * (original->comps[compno].data[i] - decoded->comps[compno].data[i]); sum += (original->comps[compno].data[i] - decoded->comps[compno].data[i]) * (original->comps[compno].data[i] - decoded->comps[compno].data[i]);
} }
} }
sum /= size; sum /= size;
total = ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum)); total = ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum));
} else { } else {
size = (original->x1 - original->x0) * (original->y1 - original->y0); size = (original->x1 - original->x0) * (original->y1 - original->y0);
for (k = 0; k < original->z1 - original->z0; k++) { for (k = 0; k < original->z1 - original->z0; k++) {
int offset = k * size; int offset = k * size;
for (sum = 0, compno = 0; compno < original->numcomps; compno++) { for (sum = 0, compno = 0; compno < original->numcomps; compno++) {
for(i = 0; i < size; ++i) { for(i = 0; i < size; ++i) {
if ((decoded->comps[compno].data[i + offset] < 0) || (decoded->comps[compno].data[i + offset] > max)) if ((decoded->comps[compno].data[i + offset] < 0) || (decoded->comps[compno].data[i + offset] > max))
fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n"); fprintf(stdout,"[WARNING] Data out of range during PSNR computing...\n");
else else
sum += (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]) * (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]); sum += (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]) * (original->comps[compno].data[i + offset] - decoded->comps[compno].data[i + offset]);
} }
} }
sum /= size; sum /= size;
total = total + ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum)); total = total + ((sum==0.0) ? 0.0 : 10 * log10(max * max / sum));
} }
} }
if(total == 0) /* perfect reconstruction, PSNR should return infinity */ if(total == 0) /* perfect reconstruction, PSNR should return infinity */
return -1.0; return -1.0;
return total; return total;
/*return 20 * log10((max - 1) / sqrt(sum));*/ /*return 20 * log10((max - 1) / sqrt(sum));*/
} }
static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded) static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
{ {
int max, i, compno = 0, size, sizeM; int max, i, compno = 0, size, sizeM;
double sum; double sum;
double mux = 0.0, muy = 0.0, sigmax = 0.0, sigmay = 0.0, double mux = 0.0, muy = 0.0, sigmax = 0.0, sigmay = 0.0,
sigmaxy = 0.0/*, structx = 0.0, structy = 0.0*/; sigmaxy = 0.0/*, structx = 0.0, structy = 0.0*/;
double lcomp,ccomp,scomp; double lcomp,ccomp,scomp;
double C1,C2,C3; double C1,C2,C3;
max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1; max = (original->comps[compno].prec <= 8) ? 255 : (1 << original->comps[compno].prec) - 1;
size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0); size = (original->x1 - original->x0) * (original->y1 - original->y0) * (original->z1 - original->z0);
/*MSSIM*/ /*MSSIM*/
/* sizeM = size / (original->z1 - original->z0);*/ /* sizeM = size / (original->z1 - original->z0);*/
sizeM = size; sizeM = size;
for(sum = 0, i = 0; i < sizeM; ++i) {
/* First, the luminance of each signal is compared.*/
mux += original->comps[compno].data[i];
muy += decoded->comps[compno].data[i];
}
mux /= sizeM;
muy /= sizeM;
/*We use the standard deviation (the square root of variance) as an estimate of the signal contrast.*/
for(sum = 0, i = 0; i < sizeM; ++i) { for(sum = 0, i = 0; i < sizeM; ++i) {
/* First, the luminance of each signal is compared.*/ /* First, the luminance of each signal is compared.*/
sigmax += (original->comps[compno].data[i] - mux) * (original->comps[compno].data[i] - mux); mux += original->comps[compno].data[i];
sigmay += (decoded->comps[compno].data[i] - muy) * (decoded->comps[compno].data[i] - muy); muy += decoded->comps[compno].data[i];
sigmaxy += (original->comps[compno].data[i] - mux) * (decoded->comps[compno].data[i] - muy); }
} mux /= sizeM;
sigmax /= sizeM - 1; muy /= sizeM;
sigmay /= sizeM - 1;
sigmaxy /= sizeM - 1;
sigmax = sqrt(sigmax); /*We use the standard deviation (the square root of variance) as an estimate of the signal contrast.*/
sigmay = sqrt(sigmay); for(sum = 0, i = 0; i < sizeM; ++i) {
sigmaxy = sqrt(sigmaxy); /* First, the luminance of each signal is compared.*/
sigmax += (original->comps[compno].data[i] - mux) * (original->comps[compno].data[i] - mux);
sigmay += (decoded->comps[compno].data[i] - muy) * (decoded->comps[compno].data[i] - muy);
sigmaxy += (original->comps[compno].data[i] - mux) * (decoded->comps[compno].data[i] - muy);
}
sigmax /= sizeM - 1;
sigmay /= sizeM - 1;
sigmaxy /= sizeM - 1;
/*Third, the signal is normalized (divided) by its own standard deviation, */ sigmax = sqrt(sigmax);
/*so that the two signals being compared have unit standard deviation.*/ sigmay = sqrt(sigmay);
sigmaxy = sqrt(sigmaxy);
/*Luminance comparison*/ /*Third, the signal is normalized (divided) by its own standard deviation, */
C1 = (0.01 * max) * (0.01 * max); /*so that the two signals being compared have unit standard deviation.*/
lcomp = ((2 * mux * muy) + C1)/((mux*mux) + (muy*mux) + C1);
/*Constrast comparison*/
C2 = (0.03 * max) * (0.03 * max);
ccomp = ((2 * sigmax * sigmay) + C2)/((sigmax*sigmax) + (sigmay*sigmay) + C2);
/*Structure comparison*/
C3 = C2 / 2;
scomp = (sigmaxy + C3) / (sigmax * sigmay + C3);
/*Similarity measure*/
sum = lcomp * ccomp * scomp; /*Luminance comparison*/
return sum; C1 = (0.01 * max) * (0.01 * max);
lcomp = ((2 * mux * muy) + C1)/((mux*mux) + (muy*mux) + C1);
/*Constrast comparison*/
C2 = (0.03 * max) * (0.03 * max);
ccomp = ((2 * sigmax * sigmay) + C2)/((sigmax*sigmax) + (sigmay*sigmay) + C2);
/*Structure comparison*/
C3 = C2 / 2;
scomp = (sigmaxy + C3) / (sigmax * sigmay + C3);
/*Similarity measure*/
sum = lcomp * ccomp * scomp;
return sum;
} }
void decode_help_display() { void decode_help_display()
fprintf(stdout,"HELP\n----\n\n"); {
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"HELP\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf(stdout,"List of parameters for the JPEG 2000 encoder:\n"); fprintf(stdout,"List of parameters for the JPEG 2000 encoder:\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," Required arguments \n"); fprintf(stdout," Required arguments \n");
fprintf(stdout," ---------------------------- \n"); fprintf(stdout," ---------------------------- \n");
fprintf(stdout," -i <compressed file> ( *.jp3d, *.j3d )\n"); fprintf(stdout," -i <compressed file> ( *.jp3d, *.j3d )\n");
fprintf(stdout," Currently accepts J3D-files. The file type is identified based on its suffix.\n"); fprintf(stdout," Currently accepts J3D-files. The file type is identified based on its suffix.\n");
fprintf(stdout," -o <decompressed file> ( *.pgx, *.bin )\n"); fprintf(stdout," -o <decompressed file> ( *.pgx, *.bin )\n");
fprintf(stdout," Currently accepts PGX-files and BIN-files. Binary data is written to the file (not ascii). \n"); fprintf(stdout," Currently accepts PGX-files and BIN-files. Binary data is written to the file (not ascii). \n");
fprintf(stdout," If a PGX filename is given, there will be as many output files as slices; \n"); fprintf(stdout," If a PGX filename is given, there will be as many output files as slices; \n");
fprintf(stdout," an indice starting from 0 will then be appended to the output filename,\n"); fprintf(stdout," an indice starting from 0 will then be appended to the output filename,\n");
fprintf(stdout," just before the \"pgx\" extension.\n"); fprintf(stdout," just before the \"pgx\" extension.\n");
fprintf(stdout," -m <characteristics file> ( *.img ) \n"); fprintf(stdout," -m <characteristics file> ( *.img ) \n");
fprintf(stdout," Required only for BIN-files. Ascii data of volume characteristics is written. \n"); fprintf(stdout," Required only for BIN-files. Ascii data of volume characteristics is written. \n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," Optional \n"); fprintf(stdout," Optional \n");
fprintf(stdout," ---------------------------- \n"); fprintf(stdout," ---------------------------- \n");
fprintf(stdout," -h \n "); fprintf(stdout," -h \n ");
fprintf(stdout," Display the help information\n"); fprintf(stdout," Display the help information\n");
fprintf(stdout," -r <RFx,RFy,RFz>\n"); fprintf(stdout," -r <RFx,RFy,RFz>\n");
fprintf(stdout," Set the number of highest resolution levels to be discarded on each dimension. \n"); fprintf(stdout," Set the number of highest resolution levels to be discarded on each dimension. \n");
fprintf(stdout," The volume resolution is effectively divided by 2 to the power of the\n"); fprintf(stdout," The volume resolution is effectively divided by 2 to the power of the\n");
fprintf(stdout," number of discarded levels. The reduce factor is limited by the\n"); fprintf(stdout," number of discarded levels. The reduce factor is limited by the\n");
fprintf(stdout," smallest total number of decomposition levels among tiles.\n"); fprintf(stdout," smallest total number of decomposition levels among tiles.\n");
fprintf(stdout," -l <number of quality layers to decode>\n"); fprintf(stdout," -l <number of quality layers to decode>\n");
fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n"); fprintf(stdout," Set the maximum number of quality layers to decode. If there are\n");
fprintf(stdout," less quality layers than the specified number, all the quality layers\n"); fprintf(stdout," less quality layers than the specified number, all the quality layers\n");
fprintf(stdout," are decoded. \n"); fprintf(stdout," are decoded. \n");
fprintf(stdout," -O original-file \n"); fprintf(stdout," -O original-file \n");
fprintf(stdout," This option offers the possibility to compute some quality results \n"); fprintf(stdout," This option offers the possibility to compute some quality results \n");
fprintf(stdout," for the decompressed volume, like the PSNR value achieved or the global SSIM value. \n"); fprintf(stdout," for the decompressed volume, like the PSNR value achieved or the global SSIM value. \n");
fprintf(stdout," Needs the original file in order to compare with the new one.\n"); fprintf(stdout," Needs the original file in order to compare with the new one.\n");
fprintf(stdout," NOTE: Only valid when -r option is 0,0,0 (both original and decompressed volumes have same resolutions) \n"); fprintf(stdout," NOTE: Only valid when -r option is 0,0,0 (both original and decompressed volumes have same resolutions) \n");
fprintf(stdout," NOTE: If original file is .BIN file, the volume characteristics file shall be defined with the -m option. \n"); fprintf(stdout," NOTE: If original file is .BIN file, the volume characteristics file shall be defined with the -m option. \n");
fprintf(stdout," (i.e. -O original-BIN-file -m original-IMG-file) \n"); fprintf(stdout," (i.e. -O original-BIN-file -m original-IMG-file) \n");
fprintf(stdout," -BE \n"); fprintf(stdout," -BE \n");
fprintf(stdout," Define that the recovered volume data will be saved with big endian byte order.\n"); fprintf(stdout," Define that the recovered volume data will be saved with big endian byte order.\n");
fprintf(stdout," By default, little endian byte order is used.\n"); fprintf(stdout," By default, little endian byte order is used.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int get_file_format(char *filename) { int get_file_format(char *filename)
int i; {
static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"}; int i;
static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT}; static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"};
char * ext = strrchr(filename, '.'); static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT};
if(ext) { char * ext = strrchr(filename, '.');
ext++; if(ext) {
for(i = 0; i < sizeof(format) / sizeof(format[0]); i++) { ext++;
if(strnicmp(ext, extension[i], 3) == 0) { for(i = 0; i < sizeof(format) / sizeof(format[0]); i++) {
return format[i]; if(strnicmp(ext, extension[i], 3) == 0) {
} return format[i];
} }
} }
}
return -1; return -1;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) { int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* parse the command line */ {
/* parse the command line */
while (1) { while (1) {
int c = opj_getopt(argc, argv, "i:o:O:r:l:B:m:h"); int c = opj_getopt(argc, argv, "i:o:O:r:l:B:m:h");
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{ char *infile = opj_optarg;
char *infile = opj_optarg; parameters->decod_format = get_file_format(infile);
parameters->decod_format = get_file_format(infile); switch(parameters->decod_format) {
switch(parameters->decod_format) { case J3D_CFMT:
case J3D_CFMT: case J2K_CFMT:
case J2K_CFMT: break;
break; default:
default: fprintf(stdout, "[ERROR] Unknown format for infile %s [only *.j3d]!! \n", infile);
fprintf(stdout, "[ERROR] Unknown format for infile %s [only *.j3d]!! \n", infile); return 1;
return 1; break;
break; }
} strncpy(parameters->infile, infile, MAX_PATH);
strncpy(parameters->infile, infile, MAX_PATH); fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile);
fprintf(stdout, "[INFO] Infile: %s \n", parameters->infile);
} }
break; break;
case 'm': /* img file */ case 'm': { /* img file */
{ char *imgfile = opj_optarg;
char *imgfile = opj_optarg; int imgformat = get_file_format(imgfile);
int imgformat = get_file_format(imgfile); switch(imgformat) {
switch(imgformat) { case IMG_DFMT:
case IMG_DFMT: break;
break; default:
default: fprintf(stdout, "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", imgfile);
fprintf(stdout, "[ERROR] Unrecognized format for imgfile : %s [accept only *.img] !!\n\n", imgfile); return 1;
return 1; break;
break; }
} strncpy(parameters->imgfile, imgfile, MAX_PATH);
strncpy(parameters->imgfile, imgfile, MAX_PATH); fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, imgformat);
fprintf(stdout, "[INFO] Imgfile: %s Format: %d\n", parameters->imgfile, imgformat); }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{ char *outfile = opj_optarg;
char *outfile = opj_optarg; parameters->cod_format = get_file_format(outfile);
parameters->cod_format = get_file_format(outfile); switch(parameters->cod_format) {
switch(parameters->cod_format) { case PGX_DFMT:
case PGX_DFMT: case BIN_DFMT:
case BIN_DFMT: break;
break; default:
default: fprintf(stdout, "[ERROR] Unrecognized format for outfile : %s [accept only *.pgx or *.bin] !!\n\n", outfile);
fprintf(stdout, "[ERROR] Unrecognized format for outfile : %s [accept only *.pgx or *.bin] !!\n\n", outfile); return 1;
return 1; break;
break; }
} strncpy(parameters->outfile, outfile, MAX_PATH);
strncpy(parameters->outfile, outfile, MAX_PATH); fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile);
fprintf(stdout, "[INFO] Outfile: %s \n", parameters->outfile);
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* Original image for PSNR computing */ case 'O': { /* Original image for PSNR computing */
{ char *original = opj_optarg;
char *original = opj_optarg; parameters->orig_format = get_file_format(original);
parameters->orig_format = get_file_format(original); switch(parameters->orig_format) {
switch(parameters->orig_format) { case PGX_DFMT:
case PGX_DFMT: case BIN_DFMT:
case BIN_DFMT: break;
break; default:
default: fprintf(stdout, "[ERROR] Unrecognized format for original file : %s [accept only *.pgx or *.bin] !!\n\n", original);
fprintf(stdout, "[ERROR] Unrecognized format for original file : %s [accept only *.pgx or *.bin] !!\n\n", original); return 1;
return 1; break;
break; }
} strncpy(parameters->original, original, MAX_PATH);
strncpy(parameters->original, original, MAX_PATH); fprintf(stdout, "[INFO] Original file: %s \n", parameters->original);
fprintf(stdout, "[INFO] Original file: %s \n", parameters->original); }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* reduce option */ case 'r': { /* reduce option */
{ /*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/
/*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/ int aux;
int aux; aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]); if (aux == 2)
if (aux == 2) parameters->cp_reduce[2] = 0;
parameters->cp_reduce[2] = 0; else if (aux == 1) {
else if (aux == 1) { parameters->cp_reduce[1] = parameters->cp_reduce[0];
parameters->cp_reduce[1] = parameters->cp_reduce[0]; parameters->cp_reduce[2] = 0;
parameters->cp_reduce[2] = 0; } else if (aux == 0) {
}else if (aux == 0){ parameters->cp_reduce[0] = 0;
parameters->cp_reduce[0] = 0; parameters->cp_reduce[1] = 0;
parameters->cp_reduce[1] = 0; parameters->cp_reduce[2] = 0;
parameters->cp_reduce[2] = 0; }
} }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'l': /* layering option */ case 'l': { /* layering option */
{ sscanf(opj_optarg, "%d", &parameters->cp_layer);
sscanf(opj_optarg, "%d", &parameters->cp_layer); }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'B': /* BIGENDIAN vs. LITTLEENDIAN */ case 'B': { /* BIGENDIAN vs. LITTLEENDIAN */
{ parameters->bigendian = 1;
parameters->bigendian = 1; }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'L': /* BIGENDIAN vs. LITTLEENDIAN */ case 'L': { /* BIGENDIAN vs. LITTLEENDIAN */
{ parameters->decod_format = LSE_CFMT;
parameters->decod_format = LSE_CFMT; }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* display an help description */ case 'h': { /* display an help description */
{ decode_help_display();
decode_help_display(); return 1;
return 1; }
} break;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
default: default:
fprintf(stdout,"[WARNING] This option is not valid \"-%c %s\"\n",c, opj_optarg); fprintf(stdout,"[WARNING] This option is not valid \"-%c %s\"\n",c, opj_optarg);
break; break;
} }
} }
/* check for possible errors */ /* check for possible errors */
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stdout,"[ERROR] At least one required argument is missing\n Check jp3d_to_volume -help for usage information\n"); fprintf(stdout,"[ERROR] At least one required argument is missing\n Check jp3d_to_volume -help for usage information\n");
return 1; return 1;
} }
return 0; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -375,168 +369,180 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
fprintf(stdout, "[INFO] %s", msg); {
fprintf(stdout, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_dparameters_t parameters; /* decompression parameters */ opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
opj_volume_t *volume = NULL; opj_volume_t *volume = NULL;
opj_volume_t *original = NULL; opj_volume_t *original = NULL;
opj_cparameters_t cparameters; /* original parameters */ opj_cparameters_t cparameters; /* original parameters */
FILE *fsrc = NULL; FILE *fsrc = NULL;
unsigned char *src = NULL; unsigned char *src = NULL;
int file_length; int file_length;
int decodeok; int decodeok;
double psnr, ssim; double psnr, ssim;
opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */ opj_dinfo_t* dinfo = NULL; /* handle to a decompressor */
opj_cio_t *cio = NULL; opj_cio_t *cio = NULL;
/* configure the event callbacks (not required) */ /* configure the event callbacks (not required) */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback; event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback; event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback; event_mgr.info_handler = info_callback;
/* set decoding parameters to default values */ /* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters); opj_set_default_decoder_parameters(&parameters);
/* parse input and get user decoding parameters */ /* parse input and get user decoding parameters */
strcpy(parameters.original,"NULL"); strcpy(parameters.original,"NULL");
strcpy(parameters.imgfile,"NULL"); strcpy(parameters.imgfile,"NULL");
if(parse_cmdline_decoder(argc, argv, &parameters) == 1) { if(parse_cmdline_decoder(argc, argv, &parameters) == 1) {
return 0; return 0;
} }
/* read the input file and put it in memory */ /* read the input file and put it in memory */
/* ---------------------------------------- */ /* ---------------------------------------- */
fprintf(stdout, "[INFO] Loading %s file \n",parameters.decod_format==J3D_CFMT ? ".jp3d" : ".j2k"); fprintf(stdout, "[INFO] Loading %s file \n",parameters.decod_format==J3D_CFMT ? ".jp3d" : ".j2k");
fsrc = fopen(parameters.infile, "rb"); fsrc = fopen(parameters.infile, "rb");
if (!fsrc) { if (!fsrc) {
fprintf(stdout, "[ERROR] Failed to open %s for reading\n", parameters.infile); fprintf(stdout, "[ERROR] Failed to open %s for reading\n", parameters.infile);
return 1; return 1;
} }
fseek(fsrc, 0, SEEK_END); fseek(fsrc, 0, SEEK_END);
file_length = ftell(fsrc); file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET); fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length); src = (unsigned char *) malloc(file_length);
fread(src, 1, file_length, fsrc); fread(src, 1, file_length, fsrc);
fclose(fsrc); fclose(fsrc);
/* decode the code-stream */ /* decode the code-stream */
/* ---------------------- */ /* ---------------------- */
if (parameters.decod_format == J3D_CFMT || parameters.decod_format == J2K_CFMT) { if (parameters.decod_format == J3D_CFMT || parameters.decod_format == J2K_CFMT) {
/* get a JP3D or J2K decoder handle */ /* get a JP3D or J2K decoder handle */
if (parameters.decod_format == J3D_CFMT) if (parameters.decod_format == J3D_CFMT)
dinfo = opj_create_decompress(CODEC_J3D); dinfo = opj_create_decompress(CODEC_J3D);
else if (parameters.decod_format == J2K_CFMT) else if (parameters.decod_format == J2K_CFMT)
dinfo = opj_create_decompress(CODEC_J2K); dinfo = opj_create_decompress(CODEC_J2K);
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */ /* setup the decoder decoding parameters using user parameters */
opj_setup_decoder(dinfo, &parameters); opj_setup_decoder(dinfo, &parameters);
/* open a byte stream */ /* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length); cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
/* decode the stream and fill the volume structure */ /* decode the stream and fill the volume structure */
volume = opj_decode(dinfo, cio); volume = opj_decode(dinfo, cio);
if(!volume) { if(!volume) {
fprintf(stdout, "[ERROR] jp3d_to_volume: failed to decode volume!\n"); fprintf(stdout, "[ERROR] jp3d_to_volume: failed to decode volume!\n");
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
opj_cio_close(cio); opj_cio_close(cio);
return 1; return 1;
} }
/* close the byte stream */ /* close the byte stream */
opj_cio_close(cio); opj_cio_close(cio);
} }
/* free the memory containing the code-stream */ /* free the memory containing the code-stream */
free(src); free(src);
src = NULL; src = NULL;
/* create output volume */ /* create output volume */
/* ------------------- */ /* ------------------- */
switch (parameters.cod_format) { switch (parameters.cod_format) {
case PGX_DFMT: /* PGX */ case PGX_DFMT: /* PGX */
decodeok = volumetopgx(volume, parameters.outfile); decodeok = volumetopgx(volume, parameters.outfile);
if (decodeok) if (decodeok)
fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n"); fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n");
break; break;
case BIN_DFMT: /* BMP */ case BIN_DFMT: /* BMP */
decodeok = volumetobin(volume, parameters.outfile); decodeok = volumetobin(volume, parameters.outfile);
if (decodeok) if (decodeok)
fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n"); fprintf(stdout,"[ERROR] Unable to write decoded volume into pgx files\n");
break; break;
} }
switch (parameters.orig_format) { switch (parameters.orig_format) {
case PGX_DFMT: /* PGX */ case PGX_DFMT: /* PGX */
if (strcmp("NULL",parameters.original) != 0){ if (strcmp("NULL",parameters.original) != 0) {
fprintf(stdout,"Loading original file %s \n",parameters.original); fprintf(stdout,"Loading original file %s \n",parameters.original);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1; cparameters.subsampling_dx = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0; cparameters.subsampling_dy = 1;
original = pgxtovolume(parameters.original,&cparameters); cparameters.subsampling_dz = 1;
} cparameters.volume_offset_x0 = 0;
break; cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
original = pgxtovolume(parameters.original,&cparameters);
}
break;
case BIN_DFMT: /* BMP */ case BIN_DFMT: /* BMP */
if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0){ if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0) {
fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile); fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1; cparameters.subsampling_dx = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0; cparameters.subsampling_dy = 1;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters); cparameters.subsampling_dz = 1;
} cparameters.volume_offset_x0 = 0;
break; cparameters.volume_offset_y0 = 0;
} cparameters.volume_offset_z0 = 0;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters);
}
break;
}
fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ", fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ",
(volume->comps[0].w >> volume->comps[0].factor[0]), (volume->comps[0].w >> volume->comps[0].factor[0]),
(volume->comps[0].h >> volume->comps[0].factor[1]), (volume->comps[0].h >> volume->comps[0].factor[1]),
(volume->comps[0].l >> volume->comps[0].factor[2]), (volume->comps[0].l >> volume->comps[0].factor[2]),
volume->comps[0].prec); volume->comps[0].prec);
if(original){ if(original) {
psnr = calc_PSNR(original,volume); psnr = calc_PSNR(original,volume);
ssim = calc_SSIM(original,volume); ssim = calc_SSIM(original,volume);
if (psnr < 0.0) if (psnr < 0.0)
fprintf(stdout, " PSNR: Inf , SSMI %f -- Perfect reconstruction!\n",ssim); fprintf(stdout, " PSNR: Inf , SSMI %f -- Perfect reconstruction!\n",ssim);
else else
fprintf(stdout, " PSNR: %f , SSIM %f \n",psnr,ssim); fprintf(stdout, " PSNR: %f , SSIM %f \n",psnr,ssim);
} }
/* free remaining structures */ /* free remaining structures */
if(dinfo) { if(dinfo) {
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
} }
/* free volume data structure */ /* free volume data structure */
opj_volume_destroy(volume); opj_volume_destroy(volume);
return 0; return 0;
} }

View File

@ -105,14 +105,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -171,7 +171,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -180,7 +180,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -188,11 +188,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -202,7 +202,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -210,13 +210,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -229,7 +229,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -238,16 +238,16 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data. * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be * We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -260,21 +260,21 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/ /*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -343,46 +343,45 @@ static void _setdirname (struct DIR *dirp);
*/ */
static DIR *opendir(const char *dirname) static DIR *opendir(const char *dirname)
{ {
DIR *dirp; DIR *dirp;
assert (dirname != NULL); assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR)); dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) { if (dirp != NULL) {
char *p; char *p;
/* allocate room for directory name */ /* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*")); dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) { if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */ /* failed to duplicate directory name. errno set by malloc() */
free (dirp); free (dirp);
return NULL; return NULL;
} }
/* Copy directory name while appending directory separator and "*.*". /* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with * Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be * drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */ * '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{ strcpy (p++, "\\");
strcpy (p++, "\\"); }
}
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
strcpy (p, "*"); /*scan files with and without extension in win32*/ strcpy (p, "*"); /*scan files with and without extension in win32*/
# else # else
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/ strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif # endif
/* open stream */ /* open stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed */ /* initialization failed */
free (dirp->dirname); free (dirp->dirname);
free (dirp); free (dirp);
return NULL; return NULL;
}
} }
} return dirp;
return dirp;
} }
@ -435,55 +434,55 @@ static DIR *opendir(const char *dirname)
static struct dirent * static struct dirent *
readdir (DIR *dirp) readdir (DIR *dirp)
{ {
assert(dirp != NULL); assert(dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */ /* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#endif #endif
if (dirp->dirent_filled != 0) { if (dirp->dirent_filled != 0) {
/* /*
* Directory entry has already been retrieved and there is no need to * Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance * retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so * when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading * because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream * the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to * automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to * save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry. * return the saved entry when the user tries to read the first entry.
*/ */
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
} else { } else {
/* fill in entry and return that */ /* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) { if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle); FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT; errno = ENOENT;
return NULL; return NULL;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) { if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no /* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return NULL; return NULL;
} }
# endif # endif
_setdirname (dirp); _setdirname (dirp);
assert (dirp->dirent_filled == 0); assert (dirp->dirent_filled == 0);
} }
return &dirp->current; return &dirp->current;
} }
@ -509,36 +508,36 @@ readdir (DIR *dirp)
static int static int
closedir (DIR *dirp) closedir (DIR *dirp)
{ {
int retcode = 0; int retcode = 0;
/* make sure that dirp points to legal structure */ /* make sure that dirp points to legal structure */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
/* free directory name and search handles */ /* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname); if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
retcode = -1; retcode = -1;
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* clear dirp structure to make sure that it cannot be used anymore*/ /* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp)); memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
# endif # endif
free (dirp); free (dirp);
return retcode; return retcode;
} }
@ -566,30 +565,30 @@ closedir (DIR *dirp)
static void static void
rewinddir (DIR *dirp) rewinddir (DIR *dirp)
{ {
/* make sure that dirp is legal */ /* make sure that dirp is legal */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return; return;
} }
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
/* close previous stream */ /* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* re-open previous stream */ /* re-open previous stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice /* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */ * error later when she tries to retrieve first directory enty. */
/*EMPTY*/; /*EMPTY*/;
} }
} }
@ -600,36 +599,35 @@ rewinddir (DIR *dirp)
static int static int
_initdir (DIR *dirp) _initdir (DIR *dirp)
{ {
assert (dirp != NULL); assert (dirp != NULL);
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */ /* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data); dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could /* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map * give us more information about the error, but then we should map
* the error code into errno. */ * the error code into errno. */
errno = ENOENT; errno = ENOENT;
return 0; return 0;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{ /* _dos_findfirst and findfirst will set errno to ENOENT when no
/* _dos_findfirst and findfirst will set errno to ENOENT when no * more entries could be retrieved. */
* more entries could be retrieved. */ return 0;
return 0; }
}
# endif # endif
/* initialize DIR and it's first entry */ /* initialize DIR and it's first entry */
_setdirname (dirp); _setdirname (dirp);
dirp->dirent_filled = 1; dirp->dirent_filled = 1;
return 1; return 1;
} }
@ -640,13 +638,13 @@ static const char *
_getdirname (const struct dirent *dp) _getdirname (const struct dirent *dp)
{ {
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName; return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK) #elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name; return dp->data.ff_name;
#else #else
return dp->data.name; return dp->data.name;
#endif #endif
} }
@ -655,14 +653,15 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
/* make sure that d_name is long enough */ {
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name, strncpy (dirp->current.d_name,
_getdirname (&dirp->current), _getdirname (&dirp->current),
NAME_MAX); NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus

View File

@ -54,40 +54,41 @@
WSADATA initialisation_win32; WSADATA initialisation_win32;
#endif #endif
int main(int argc, char *argv[]){ int main(int argc, char *argv[])
{
dec_server_record_t *server_record; dec_server_record_t *server_record;
client_t client; client_t client;
int port = 50000; int port = 50000;
int erreur; int erreur;
(void)erreur; (void)erreur;
if( argc > 1) if( argc > 1)
port = atoi( argv[1]); port = atoi( argv[1]);
#ifdef _WIN32 #ifdef _WIN32
erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0) if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else else
printf( "Initialisation Winsock\n"); printf( "Initialisation Winsock\n");
#endif /*_WIN32*/ #endif /*_WIN32*/
server_record = init_dec_server( port); server_record = init_dec_server( port);
while(( client = accept_connection( server_record)) != -1 ) while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record)) if(!handle_clientreq( client, server_record))
break; break;
terminate_dec_server( &server_record); terminate_dec_server( &server_record);
#ifdef _WIN32 #ifdef _WIN32
if( WSACleanup() != 0){ if( WSACleanup() != 0) {
printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{ } else {
printf("\nWSACleanup OK\n"); printf("\nWSACleanup OK\n");
} }
#endif #endif
return 0; return 0;
} }

View File

@ -74,111 +74,111 @@ char * read_xmlfile( const char filename[], long *fsize);
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FILE *fp; FILE *fp;
char *xmldata, type[]="xml "; char *xmldata, type[]="xml ";
long fsize, boxsize; long fsize, boxsize;
if( argc<3){ if( argc<3) {
fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] ); fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
return -1; return -1;
} }
fp = open_jp2file( argv[1]); fp = open_jp2file( argv[1]);
if( !fp) if( !fp)
return -1; return -1;
xmldata = read_xmlfile( argv[2], &fsize); xmldata = read_xmlfile( argv[2], &fsize);
if( fsize < 0 ) return -1; if( fsize < 0 ) return -1;
boxsize = fsize + 8; boxsize = fsize + 8;
fputc( (boxsize>>24)&0xff, fp); fputc( (boxsize>>24)&0xff, fp);
fputc( (boxsize>>16)&0xff, fp); fputc( (boxsize>>16)&0xff, fp);
fputc( (boxsize>>8)&0xff, fp); fputc( (boxsize>>8)&0xff, fp);
fputc( boxsize&0xff, fp); fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp); fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp); fwrite( xmldata, (size_t)fsize, 1, fp);
free( xmldata); free( xmldata);
fclose(fp); fclose(fp);
return 0; return 0;
} }
FILE * open_jp2file( const char filename[]) FILE * open_jp2file( const char filename[])
{ {
FILE *fp; FILE *fp;
char *data; char *data;
if( !(fp = fopen( filename, "a+b"))){ if( !(fp = fopen( filename, "a+b"))) {
fprintf( stderr, "Original JP2 %s not found\n", filename); fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL; return NULL;
} }
/* Check resource is a JP family file. */ /* Check resource is a JP family file. */
if( fseek( fp, 0, SEEK_SET)==-1){ if( fseek( fp, 0, SEEK_SET)==-1) {
fclose(fp); fclose(fp);
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename); fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL; return NULL;
} }
data = (char *)malloc( 12); /* size of header */ data = (char *)malloc( 12); /* size of header */
if( fread( data, 12, 1, fp) != 1){ if( fread( data, 12, 1, fp) != 1) {
free( data);
fclose(fp);
fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
return NULL;
}
if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)) {
free( data);
fclose(fp);
fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
return NULL;
}
free( data); free( data);
fclose(fp); return fp;
fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
return NULL;
}
if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){
free( data);
fclose(fp);
fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
return NULL;
}
free( data);
return fp;
} }
char * read_xmlfile( const char filename[], long *fsize) char * read_xmlfile( const char filename[], long *fsize)
{ {
FILE *fp; FILE *fp;
char *data; char *data;
/* fprintf( stderr, "open %s\n", filename);*/ /* fprintf( stderr, "open %s\n", filename);*/
if(!(fp = fopen( filename, "r"))){ if(!(fp = fopen( filename, "r"))) {
fprintf( stderr, "XML file %s not found\n", filename); fprintf( stderr, "XML file %s not found\n", filename);
return NULL; return NULL;
} }
if( fseek( fp, 0, SEEK_END) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
if( (*fsize = ftell( fp)) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
data = (char *)malloc( (size_t)*fsize);
if( fread( data, (size_t)*fsize, 1, fp) != 1) {
fprintf( stderr, "XML file %s broken (read error)\n", filename);
free( data);
fclose(fp);
return NULL;
}
if( fseek( fp, 0, SEEK_END) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp); fclose( fp);
return NULL;
}
if( (*fsize = ftell( fp)) == -1){ return data;
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
data = (char *)malloc( (size_t)*fsize);
if( fread( data, (size_t)*fsize, 1, fp) != 1){
fprintf( stderr, "XML file %s broken (read error)\n", filename);
free( data);
fclose(fp);
return NULL;
}
fclose( fp);
return data;
} }

View File

@ -51,23 +51,23 @@
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int fd; int fd;
index_t *jp2idx; index_t *jp2idx;
if( argc < 2 ) return 1; if( argc < 2 ) return 1;
if( (fd = open( argv[1], O_RDONLY)) == -1){ if( (fd = open( argv[1], O_RDONLY)) == -1) {
fprintf( stderr, "Error: Target %s not found\n", argv[1]); fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1; return -1;
} }
if( !(jp2idx = get_index_from_JP2file( fd))){ if( !(jp2idx = get_index_from_JP2file( fd))) {
fprintf( stderr, "JP2 file broken\n"); fprintf( stderr, "JP2 file broken\n");
return -1; return -1;
} }
output_index( jp2idx); output_index( jp2idx);
destroy_index( &jp2idx); destroy_index( &jp2idx);
close(fd); close(fd);
return 0; return 0;
} /* main */ } /* main */

View File

@ -44,23 +44,23 @@
*/ */
static int jpip_to_jp2(char *argv[]) static int jpip_to_jp2(char *argv[])
{ {
jpip_dec_param_t *dec; jpip_dec_param_t *dec;
dec = init_jpipdecoder( OPJ_TRUE); dec = init_jpipdecoder( OPJ_TRUE);
if(!( fread_jpip( argv[1], dec))) if(!( fread_jpip( argv[1], dec)))
return 1; return 1;
decode_jpip( dec); decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec))) if(!(fwrite_jp2k( argv[2], dec)))
return 1; return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */ /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */
destroy_jpipdecoder( &dec); destroy_jpipdecoder( &dec);
return 0; return 0;
} }
/*! \file /*! \file
@ -76,49 +76,46 @@ static int jpip_to_jp2(char *argv[])
*/ */
static int jpip_to_j2k(char *argv[]) static int jpip_to_j2k(char *argv[])
{ {
jpip_dec_param_t *dec; jpip_dec_param_t *dec;
dec = init_jpipdecoder( OPJ_FALSE); dec = init_jpipdecoder( OPJ_FALSE);
if(!( fread_jpip( argv[1], dec))) if(!( fread_jpip( argv[1], dec)))
return 1; return 1;
decode_jpip( dec); decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec))) if(!(fwrite_jp2k( argv[2], dec)))
return 1; return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */ /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */
destroy_jpipdecoder( &dec); destroy_jpipdecoder( &dec);
return 0; return 0;
} }
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
char *ext; char *ext;
if( argc < 3){ if( argc < 3) {
fprintf( stderr, "Too few arguments:\n"); fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n"); fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n"); fprintf( stderr, " - output j2k file\n");
return 1; return 1;
}
ext = strrchr( argv[2], '.' );
if( ext )
{
/* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 )
{
return jpip_to_jp2(argv);
}
if( strcmp(ext, ".j2k" ) == 0 )
{
return jpip_to_j2k(argv);
}
} }
fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]); ext = strrchr( argv[2], '.' );
return 1; if( ext ) {
/* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 ) {
return jpip_to_jp2(argv);
}
if( strcmp(ext, ".j2k" ) == 0 ) {
return jpip_to_j2k(argv);
}
}
fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]);
return 1;
} }

View File

@ -61,68 +61,68 @@ WSADATA initialisation_win32;
int main(void) int main(void)
{ {
server_record_t *server_record; server_record_t *server_record;
#ifdef SERVER #ifdef SERVER
char *query_string; char *query_string;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0) if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else else
fprintf( stderr, "Initialisation Winsock\n"); fprintf( stderr, "Initialisation Winsock\n");
#endif /*_WIN32*/ #endif /*_WIN32*/
server_record = init_JPIPserver( 60000, 0); server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER #ifdef SERVER
while(FCGI_Accept() >= 0) while(FCGI_Accept() >= 0)
#else #else
char query_string[128]; char query_string[128];
while( fgets( query_string, 128, stdin) && query_string[0]!='\n') while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif #endif
{ {
QR_t *qr; QR_t *qr;
OPJ_BOOL parse_status; OPJ_BOOL parse_status;
#ifdef SERVER #ifdef SERVER
query_string = getenv("QUERY_STRING"); query_string = getenv("QUERY_STRING");
#endif /*SERVER*/ #endif /*SERVER*/
if( strcmp( query_string, QUIT_SIGNAL) == 0) if( strcmp( query_string, QUIT_SIGNAL) == 0)
break; break;
qr = parse_querystring( query_string); qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr); parse_status = process_JPIPrequest( server_record, qr);
#ifndef SERVER #ifndef SERVER
local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record); local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record);
#endif #endif
if( parse_status) if( parse_status)
send_responsedata( server_record, qr); send_responsedata( server_record, qr);
else{ else {
fprintf( FCGI_stderr, "Error: JPIP request failed\n"); fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n"); fprintf( FCGI_stdout, "\r\n");
} }
end_QRprocess( server_record, &qr); end_QRprocess( server_record, &qr);
} }
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n"); fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
terminate_JPIPserver( &server_record); terminate_JPIPserver( &server_record);
#ifdef _WIN32 #ifdef _WIN32
if( WSACleanup() != 0){ if( WSACleanup() != 0) {
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{ } else {
fprintf( stderr, "\nWSACleanup OK\n"); fprintf( stderr, "\nWSACleanup OK\n");
} }
#endif #endif
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -40,17 +40,17 @@
/**@name RAW image encoding parameters */ /**@name RAW image encoding parameters */
/*@{*/ /*@{*/
typedef struct raw_cparameters { typedef struct raw_cparameters {
/** width of the raw image */ /** width of the raw image */
int rawWidth; int rawWidth;
/** height of the raw image */ /** height of the raw image */
int rawHeight; int rawHeight;
/** components of the raw image */ /** components of the raw image */
int rawComp; int rawComp;
/** bit depth of the raw image */ /** bit depth of the raw image */
int rawBitDepth; int rawBitDepth;
/** signed/unsigned raw image */ /** signed/unsigned raw image */
opj_bool rawSigned; opj_bool rawSigned;
/*@}*/ /*@}*/
} raw_cparameters_t; } raw_cparameters_t;
/* TGA conversion */ /* TGA conversion */

View File

@ -45,352 +45,353 @@ Write a structured index to a file
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */
int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int write_index_file(opj_codestream_info_t *cstr_info, char *index)
int tileno, compno, layno, resno, precno, pack_nb, x, y; {
FILE *stream = NULL; int tileno, compno, layno, resno, precno, pack_nb, x, y;
double total_disto = 0; FILE *stream = NULL;
/* UniPG>> */ double total_disto = 0;
int tilepartno; /* UniPG>> */
char disto_on, numpix_on; int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL #ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0; return 0;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
if (!cstr_info) if (!cstr_info)
return 1; return 1;
stream = fopen(index, "w"); stream = fopen(index, "w");
if (!stream) { if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index); fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1; return 1;
} }
if (cstr_info->tile[0].distotile) if (cstr_info->tile[0].distotile)
disto_on = 1; disto_on = 1;
else else
disto_on = 0; disto_on = 0;
if (cstr_info->tile[0].numpix) if (cstr_info->tile[0].numpix)
numpix_on = 1; numpix_on = 1;
else else
numpix_on = 0; numpix_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog); fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th);
fprintf(stream, "%d\n", cstr_info->numcomps); fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers); fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */ fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ", fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
} }
fprintf(stream, "\n"); fprintf(stream, "\n");
/* UniPG>> */ /* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start); fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */ /* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end); fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n"); fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts"); fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on) if (disto_on)
fprintf(stream," disto"); fprintf(stream," disto");
if (numpix_on) if (numpix_on)
fprintf(stream," nbpix"); fprintf(stream," nbpix");
if (disto_on && numpix_on) if (disto_on && numpix_on)
fprintf(stream," disto/nbpix"); fprintf(stream," disto/nbpix");
fprintf(stream, "\n"); fprintf(stream, "\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d", fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno, cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos, cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header, cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos, cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].num_tps); cstr_info->tile[tileno].num_tps);
if (disto_on) if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile); fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on) if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix); fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on) if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix); fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n"); fprintf(stream, "\n");
} }
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
int start_pos, end_ph_pos, end_pos; int start_pos, end_ph_pos, end_pos;
double disto = 0; double disto = 0;
int max_numdecompos = 0; int max_numdecompos = 0;
pack_nb = 0; pack_nb = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno]) if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno]; max_numdecompos = cstr_info->numdecompos[compno];
} }
fprintf(stream, "\nTILE %d DETAILS\n", tileno); fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
tilepartno, tileno, tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, cstr_info->tile[tileno].tp[tilepartno].tp_start_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_end_header, cstr_info->tile[tileno].tp[tilepartno].tp_end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos cstr_info->tile[tileno].tp[tilepartno].tp_end_pos
); );
if (cstr_info->prog == LRCP) { /* LRCP */ if (cstr_info->prog == LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos"); fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max; int prec_max;
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d", fprintf(stream, "%4d %6d %7d %5d %6d %6d %6d %6d %7d",
pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, layno, resno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} /* LRCP */ } /* LRCP */
else if (cstr_info->prog == RLCP) { /* RLCP */ else if (cstr_info->prog == RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max; int prec_max;
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) { for (precno = 0; precno < prec_max; precno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d", fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d",
pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
} }
} }
} /* RLCP */ } /* RLCP */
else if (cstr_info->prog == RPCL) { /* RPCL */ else if (cstr_info->prog == RPCL) { /* RPCL */
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) { for (precno = 0; precno < numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno]) if (resno > cstr_info->numdecompos[compno])
break; break;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d", fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %7d",
pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, resno, precno, compno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* precno */ } /* precno */
} /* compno */ } /* compno */
} /* resno */ } /* resno */
} /* RPCL */ } /* RPCL */
else if (cstr_info->prog == PCRL) { /* PCRL */ else if (cstr_info->prog == PCRL) { /* PCRL */
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
/* Count the maximum number of precincts */ /* Count the maximum number of precincts */
int max_numprec = 0; int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) if (numprec > max_numprec)
max_numprec = numprec; max_numprec = numprec;
} }
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (precno = 0; precno < max_numprec; precno++) { for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec) if (precno >= numprec)
continue; continue;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d", fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d",
pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, precno, compno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* resno */ } /* resno */
} /* compno */ } /* compno */
} /* precno */ } /* precno */
} /* PCRL */ } /* PCRL */
else { /* CPRL */ else { /* CPRL */
/* Count the maximum number of precincts */ /* Count the maximum number of precincts */
int max_numprec = 0; int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) { for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec) if (numprec > max_numprec)
max_numprec = numprec; max_numprec = numprec;
} }
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos"); fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on) if (disto_on)
fprintf(stream, " disto"); fprintf(stream, " disto");
fprintf(stream,"\n"); fprintf(stream,"\n");
for (compno = 0; compno < cstr_info->numcomps; compno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */ /* I suppose components have same XRsiz, YRsiz */
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int x1 = x0 + cstr_info->tile_x; int x1 = x0 + cstr_info->tile_x;
int y1 = y0 + cstr_info->tile_y; int y1 = y0 + cstr_info->tile_y;
for (precno = 0; precno < max_numprec; precno++) { for (precno = 0; precno < max_numprec; precno++) {
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcnx = cstr_info->tile[tileno].pw[resno]; int pcnx = cstr_info->tile[tileno].pw[resno];
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno );
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno );
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx ); int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec) if (precno >= numprec)
continue; continue;
for(y = y0; y < y1; y++) { for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) { if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) { for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) { if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (layno = 0; layno < cstr_info->numlayers; layno++) {
start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos; start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto; disto = cstr_info->tile[tileno].packet[pack_nb].disto;
fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d", fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %7d",
pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos); pack_nb, tileno, compno, precno, resno, layno, start_pos, end_ph_pos, end_pos);
if (disto_on) if (disto_on)
fprintf(stream, " %8e", disto); fprintf(stream, " %8e", disto);
fprintf(stream, "\n"); fprintf(stream, "\n");
total_disto += disto; total_disto += disto;
pack_nb++; pack_nb++;
} }
} }
}/* x = x0..x1 */ }/* x = x0..x1 */
} }
} /* y = y0..y1 */ } /* y = y0..y1 */
} /* resno */ } /* resno */
} /* precno */ } /* precno */
} /* compno */ } /* compno */
} /* CPRL */ } /* CPRL */
} /* tileno */ } /* tileno */
if (disto_on) { if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
} }
/* UniPG>> */ /* UniPG>> */
/* print the markers' list */ /* print the markers' list */
if (cstr_info->marknum) { if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n"); fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum); fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n"); fprintf(stream, "type\tstart_pos length\n");
for (x = 0; x < cstr_info->marknum; x++) for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len); fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
} }
/* <<UniPG */ /* <<UniPG */
fclose(stream); fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); fprintf(stderr,"Generated index file %s\n", index);
return 0; return 0;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -106,14 +106,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -239,16 +239,16 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
* as a pointer referring the name within implementation dependent data. * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be * We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -261,21 +261,21 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/ /*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -344,46 +344,45 @@ static void _setdirname (struct DIR *dirp);
*/ */
static DIR *opendir(const char *dirname) static DIR *opendir(const char *dirname)
{ {
DIR *dirp; DIR *dirp;
assert (dirname != NULL); assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR)); dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) { if (dirp != NULL) {
char *p; char *p;
/* allocate room for directory name */ /* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*")); dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) { if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */ /* failed to duplicate directory name. errno set by malloc() */
free (dirp); free (dirp);
return NULL; return NULL;
} }
/* Copy directory name while appending directory separator and "*.*". /* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with * Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be * drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */ * '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{ strcpy (p++, "\\");
strcpy (p++, "\\"); }
}
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
strcpy (p, "*"); /*scan files with and without extension in win32*/ strcpy (p, "*"); /*scan files with and without extension in win32*/
# else # else
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/ strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif # endif
/* open stream */ /* open stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed */ /* initialization failed */
free (dirp->dirname); free (dirp->dirname);
free (dirp); free (dirp);
return NULL; return NULL;
}
} }
} return dirp;
return dirp;
} }
@ -436,55 +435,55 @@ static DIR *opendir(const char *dirname)
static struct dirent * static struct dirent *
readdir (DIR *dirp) readdir (DIR *dirp)
{ {
assert(dirp != NULL); assert(dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */ /* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF; errno = EBADF;
return NULL; return NULL;
} }
#endif #endif
if (dirp->dirent_filled != 0) { if (dirp->dirent_filled != 0) {
/* /*
* Directory entry has already been retrieved and there is no need to * Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance * retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so * when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading * because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream * the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, we have to * automatically when we retrieve the first file. Therefore, we have to
* save the first file when opening the stream and later we have to * save the first file when opening the stream and later we have to
* return the saved entry when the user tries to read the first entry. * return the saved entry when the user tries to read the first entry.
*/ */
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
} else { } else {
/* fill in entry and return that */ /* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) { if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle); FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT; errno = ENOENT;
return NULL; return NULL;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) { if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no /* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return NULL; return NULL;
} }
# endif # endif
_setdirname (dirp); _setdirname (dirp);
assert (dirp->dirent_filled == 0); assert (dirp->dirent_filled == 0);
} }
return &dirp->current; return &dirp->current;
} }
@ -510,36 +509,36 @@ readdir (DIR *dirp)
static int static int
closedir (DIR *dirp) closedir (DIR *dirp)
{ {
int retcode = 0; int retcode = 0;
/* make sure that dirp points to legal structure */ /* make sure that dirp points to legal structure */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return -1; return -1;
} }
/* free directory name and search handles */ /* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname); if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
retcode = -1; retcode = -1;
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* clear dirp structure to make sure that it cannot be used anymore*/ /* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp)); memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE; dirp->search_handle = INVALID_HANDLE_VALUE;
# endif # endif
free (dirp); free (dirp);
return retcode; return retcode;
} }
@ -567,30 +566,30 @@ closedir (DIR *dirp)
static void static void
rewinddir (DIR *dirp) rewinddir (DIR *dirp)
{ {
/* make sure that dirp is legal */ /* make sure that dirp is legal */
assert (dirp != NULL); assert (dirp != NULL);
if (dirp == NULL) { if (dirp == NULL) {
errno = EBADF; errno = EBADF;
return; return;
} }
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
/* close previous stream */ /* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) { if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) { if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */ /* Unknown error */
errno = EBADF; errno = EBADF;
}
} }
}
#endif #endif
/* re-open previous stream */ /* re-open previous stream */
if (_initdir (dirp) == 0) { if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice /* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */ * error later when she tries to retrieve first directory enty. */
/*EMPTY*/; /*EMPTY*/;
} }
} }
@ -601,36 +600,35 @@ rewinddir (DIR *dirp)
static int static int
_initdir (DIR *dirp) _initdir (DIR *dirp)
{ {
assert (dirp != NULL); assert (dirp != NULL);
assert (dirp->dirname != NULL); assert (dirp->dirname != NULL);
dirp->dirent_filled = 0; dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */ /* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data); dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) { if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could /* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map * give us more information about the error, but then we should map
* the error code into errno. */ * the error code into errno. */
errno = ENOENT; errno = ENOENT;
return 0; return 0;
} }
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{ /* _dos_findfirst and findfirst will set errno to ENOENT when no
/* _dos_findfirst and findfirst will set errno to ENOENT when no * more entries could be retrieved. */
* more entries could be retrieved. */ return 0;
return 0; }
}
# endif # endif
/* initialize DIR and it's first entry */ /* initialize DIR and it's first entry */
_setdirname (dirp); _setdirname (dirp);
dirp->dirent_filled = 1; dirp->dirent_filled = 1;
return 1; return 1;
} }
@ -641,13 +639,13 @@ static const char *
_getdirname (const struct dirent *dp) _getdirname (const struct dirent *dp)
{ {
#if defined(DIRENT_WIN32_INTERFACE) #if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName; return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK) #elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name; return dp->data.ff_name;
#else #else
return dp->data.name; return dp->data.name;
#endif #endif
} }
@ -656,14 +654,15 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
/* make sure that d_name is long enough */ {
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name, strncpy (dirp->current.d_name,
_getdirname (&dirp->current), _getdirname (&dirp->current),
NAME_MAX); NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -23,23 +23,26 @@ can be bound by the Open JPEG open-source license and disclaimer, expressed else
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[INFO] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -50,263 +53,265 @@ void info_callback(const char *msg, void *client_data) {
void help_display() void help_display()
{ {
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */ /* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
fprintf(stdout," Help for the 'mj2_to_metadata' Program\n"); fprintf(stdout," Help for the 'mj2_to_metadata' Program\n");
fprintf(stdout," ======================================\n"); fprintf(stdout," ======================================\n");
fprintf(stdout,"The -h option displays this information on screen.\n\n"); fprintf(stdout,"The -h option displays this information on screen.\n\n");
fprintf(stdout,"mj2_to_metadata generates an XML file from a Motion JPEG 2000 file.\n"); fprintf(stdout,"mj2_to_metadata generates an XML file from a Motion JPEG 2000 file.\n");
fprintf(stdout,"The generated XML shows the structural, but not (yet) curatorial,\n"); fprintf(stdout,"The generated XML shows the structural, but not (yet) curatorial,\n");
fprintf(stdout,"metadata from the movie header and from the JPEG 2000 image and tile\n"); fprintf(stdout,"metadata from the movie header and from the JPEG 2000 image and tile\n");
fprintf(stdout,"headers of a sample frame. Excluded: low-level packed-bits image data.\n\n"); fprintf(stdout,"headers of a sample frame. Excluded: low-level packed-bits image data.\n\n");
fprintf(stdout,"By Default\n"); fprintf(stdout,"By Default\n");
fprintf(stdout,"----------\n"); fprintf(stdout,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n"); fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n"); fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n");
fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n"); fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n"); fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
fprintf(stdout," meaning of non-obvious tag abbreviations;\n"); fprintf(stdout," meaning of non-obvious tag abbreviations;\n");
fprintf(stdout," range and precision of valid values;\n"); fprintf(stdout," range and precision of valid values;\n");
fprintf(stdout," interpretations of values, such as enumerations; and\n"); fprintf(stdout," interpretations of values, such as enumerations; and\n");
fprintf(stdout," current implementation limitations.\n"); fprintf(stdout," current implementation limitations.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"The sample-size and chunk-offset tables, each with 1 row per frame, are not reported.\n"); fprintf(stdout,"The sample-size and chunk-offset tables, each with 1 row per frame, are not reported.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n"); fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h)\n"); fprintf(stdout,"Required Parameters (except with -h)\n");
fprintf(stdout,"------------------------------------\n"); fprintf(stdout,"------------------------------------\n");
fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n"); fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n");
fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n"); fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n");
fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n"); fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n");
fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n"); fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n");
fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n"); fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters\n"); fprintf(stdout,"Optional Parameters\n");
fprintf(stdout,"-------------------\n"); fprintf(stdout,"-------------------\n");
fprintf(stdout,"-h : Display this help information.\n"); fprintf(stdout,"-h : Display this help information.\n");
fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n"); fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n");
fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n"); fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n");
fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n"); fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n");
fprintf(stdout,"-f 0 : No jp2 header info.\n"); fprintf(stdout,"-f 0 : No jp2 header info.\n");
fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n"); fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n");
fprintf(stdout,"-d : Suppress all 'derived' data.\n"); fprintf(stdout,"-d : Suppress all 'derived' data.\n");
fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n"); fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n");
fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n"); fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n");
fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n"); fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n");
fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n"); fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n");
fprintf(stdout," the output file: -v \"SYSTEM mj2_to_metadata.dtd\"\n"); fprintf(stdout," the output file: -v \"SYSTEM mj2_to_metadata.dtd\"\n");
fprintf(stdout," \"PUBLIC\" is used with an access protocol (e.g., http:) + URL.\n"); fprintf(stdout," \"PUBLIC\" is used with an access protocol (e.g., http:) + URL.\n");
/* More to come */ /* More to come */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */ /* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
} }
/* ------------- */ /* ------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo; opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
FILE *file, *xmlout; FILE *file, *xmlout;
/* char xmloutname[50]; */ /* char xmloutname[50]; */
opj_mj2_t *movie; opj_mj2_t *movie;
char* infile = 0; char* infile = 0;
char* outfile = 0; char* outfile = 0;
char* s, S1, S2, S3; char* s, S1, S2, S3;
int len; int len;
unsigned int sampleframe = 1; /* First frame */ unsigned int sampleframe = 1; /* First frame */
char* stringDTD = NULL; char* stringDTD = NULL;
BOOL notes = TRUE; BOOL notes = TRUE;
BOOL sampletables = FALSE; BOOL sampletables = FALSE;
BOOL raw = TRUE; BOOL raw = TRUE;
BOOL derived = TRUE; BOOL derived = TRUE;
mj2_dparameters_t parameters; mj2_dparameters_t parameters;
while (TRUE) { while (TRUE) {
/* ':' after letter means it takes an argument */ /* ':' after letter means it takes an argument */
int c = getopt(argc, argv, "i:o:f:v:hntrd"); int c = getopt(argc, argv, "i:o:f:v:hntrd");
/* FUTURE: Reserve 'p' for pruning file (which will probably make -t redundant) */ /* FUTURE: Reserve 'p' for pruning file (which will probably make -t redundant) */
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* IN file */ case 'i': /* IN file */
infile = optarg; infile = optarg;
s = optarg; s = optarg;
while (*s) { s++; } /* Run to filename end */ while (*s) {
s--; s++; /* Run to filename end */
S3 = *s; }
s--; s--;
S2 = *s; S3 = *s;
s--; s--;
S1 = *s; S2 = *s;
s--;
S1 = *s;
if ((S1 == 'm' && S2 == 'j' && S3 == '2') if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (S1 == 'M' && S2 == 'J' && S3 == '2')) { || (S1 == 'M' && S2 == 'J' && S3 == '2')) {
break; break;
} }
fprintf(stderr, "Input file name must have .mj2 extension, not .%c%c%c.\n", S1, S2, S3); fprintf(stderr, "Input file name must have .mj2 extension, not .%c%c%c.\n", S1, S2, S3);
return 1; return 1;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* OUT file */ case 'o': /* OUT file */
outfile = optarg; outfile = optarg;
while (*outfile) { outfile++; } /* Run to filename end */ while (*outfile) {
outfile--; outfile++; /* Run to filename end */
S3 = *outfile; }
outfile--; outfile--;
S2 = *outfile; S3 = *outfile;
outfile--; outfile--;
S1 = *outfile; S2 = *outfile;
outfile--;
S1 = *outfile;
outfile = optarg; outfile = optarg;
if ((S1 == 'x' && S2 == 'm' && S3 == 'l') if ((S1 == 'x' && S2 == 'm' && S3 == 'l')
|| (S1 == 'X' && S2 == 'M' && S3 == 'L')) || (S1 == 'X' && S2 == 'M' && S3 == 'L'))
break; break;
fprintf(stderr, fprintf(stderr,
"Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3); "Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3);
return 1; return 1;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* Choose sample frame. 0 = none */ case 'f': /* Choose sample frame. 0 = none */
sscanf(optarg, "%u", &sampleframe); sscanf(optarg, "%u", &sampleframe);
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'v': /* Verification by DTD. */ case 'v': /* Verification by DTD. */
stringDTD = optarg; stringDTD = optarg;
/* We will not insist upon last 3 chars being "dtd", since non-file /* We will not insist upon last 3 chars being "dtd", since non-file
access protocol may be used. */ access protocol may be used. */
if(strchr(stringDTD,'"') != NULL) { if(strchr(stringDTD,'"') != NULL) {
fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n"); fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n");
return 1; return 1;
} }
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0) if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
break; break;
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n"); fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
return 1; return 1;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'n': /* Suppress comments */ case 'n': /* Suppress comments */
notes = FALSE; notes = FALSE;
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* Show sample size and chunk offset tables */ case 't': /* Show sample size and chunk offset tables */
sampletables = TRUE; sampletables = TRUE;
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* Display an help description */ case 'h': /* Display an help description */
help_display(); help_display();
return 0; return 0;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* Suppress raw data */ case 'r': /* Suppress raw data */
raw = FALSE; raw = FALSE;
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* Suppress derived data */ case 'd': /* Suppress derived data */
derived = FALSE; derived = FALSE;
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
default: default:
return 1; return 1;
} /* switch */ } /* switch */
} /* while */ } /* while */
if(!raw && !derived) if(!raw && !derived)
raw = TRUE; /* At least one of 'raw' and 'derived' must be true */ raw = TRUE; /* At least one of 'raw' and 'derived' must be true */
/* Error messages */ /* Error messages */
/* -------------- */ /* -------------- */
if (!infile || !outfile) { if (!infile || !outfile) {
fprintf(stderr,"Correct usage: mj2_to_metadata -i mj2-file -o xml-file (plus options)\n"); fprintf(stderr,"Correct usage: mj2_to_metadata -i mj2-file -o xml-file (plus options)\n");
return 1; return 1;
} }
/* was: /* was:
if (argc != 3) { if (argc != 3) {
printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n"); printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n");
printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n"); printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n");
return 1; return 1;
} }
*/ */
len = strlen(infile); len = strlen(infile);
if(infile[0] == ' ') if(infile[0] == ' ') {
{ infile++; /* There may be a leading blank if user put space after -i */
infile++; /* There may be a leading blank if user put space after -i */ }
}
file = fopen(infile, "rb"); /* was: argv[1] */ file = fopen(infile, "rb"); /* was: argv[1] */
if (!file) { if (!file) {
fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: argv[1] */ fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: argv[1] */
return 1; return 1;
} }
len = strlen(outfile); len = strlen(outfile);
if(outfile[0] == ' ') if(outfile[0] == ' ') {
{ outfile++; /* There may be a leading blank if user put space after -o */
outfile++; /* There may be a leading blank if user put space after -o */ }
}
// Checking output file // Checking output file
xmlout = fopen(outfile, "w"); /* was: argv[2] */ xmlout = fopen(outfile, "w"); /* was: argv[2] */
if (!xmlout) { if (!xmlout) {
fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */ fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */
return 1; return 1;
} }
// Leave it open // Leave it open
/* /*
configure the event callbacks (not required) configure the event callbacks (not required)
setting of each callback is optionnal setting of each callback is optionnal
*/ */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback; event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback; event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback; event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */ /* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress(); dinfo = mj2_create_decompress();
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
/* setup the decoder decoding parameters using user parameters */ /* setup the decoder decoding parameters using user parameters */
movie = (opj_mj2_t*) dinfo->mj2_handle; movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters); mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) // Creating the movie structure if (mj2_read_struct(file, movie)) { // Creating the movie structure
{ fclose(xmlout);
return 1;
}
xml_write_init(notes, sampletables, raw, derived);
xml_write_struct(file, xmlout, movie, sampleframe, stringDTD, &event_mgr);
fclose(xmlout); fclose(xmlout);
return 1;
}
xml_write_init(notes, sampletables, raw, derived); fprintf(stderr,"Metadata correctly extracted to XML file \n");;
xml_write_struct(file, xmlout, movie, sampleframe, stringDTD, &event_mgr);
fclose(xmlout);
fprintf(stderr,"Metadata correctly extracted to XML file \n");; /* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
/* free remaining structures */ return 0;
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
} }

File diff suppressed because it is too large Load Diff

View File

@ -50,196 +50,194 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
mj2_dparameters_t mj2_parameters; /* decompression parameters */ {
opj_dinfo_t* dinfo; mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_dinfo_t* dinfo;
opj_cio_t *cio = NULL; opj_event_mgr_t event_mgr; /* event manager */
unsigned int tnum, snum; opj_cio_t *cio = NULL;
opj_mj2_t *movie; unsigned int tnum, snum;
mj2_tk_t *track; opj_mj2_t *movie;
mj2_sample_t *sample; mj2_tk_t *track;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *file, *outfile; unsigned char* frame_codestream;
char outfilename[50]; FILE *file, *outfile;
opj_image_t *img = NULL; char outfilename[50];
unsigned int max_codstrm_size = 0; opj_image_t *img = NULL;
double total_time = 0; unsigned int max_codstrm_size = 0;
unsigned int numframes = 0; double total_time = 0;
unsigned int numframes = 0;
if (argc != 3) { if (argc != 3) {
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]); printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1; return 1;
} }
file = fopen(argv[1], "rb"); file = fopen(argv[1], "rb");
if (!file) { if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]); fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1; return 1;
} }
/* Checking output file */ /* Checking output file */
outfile = fopen(argv[2], "w"); outfile = fopen(argv[2], "w");
if (!file) { if (!file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]); fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1; return 1;
} }
fclose(outfile); fclose(outfile);
/* /*
configure the event callbacks (not required) configure the event callbacks (not required)
setting of each callback is optionnal setting of each callback is optionnal
*/ */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback; event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback; event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = NULL; event_mgr.info_handler = NULL;
/* get a MJ2 decompressor handle */ /* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress(); dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle; movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */ /* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t)); memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t));
/* set J2K decoding parameters to default values */ /* set J2K decoding parameters to default values */
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters); opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters);
/* setup the decoder decoding parameters using user parameters */ /* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters); mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */ if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1; return 1;
/* Decode first video track */ /* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) { for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0) if (movie->tk[tnum].track_type == 0)
break; break;
} }
if (movie->tk[tnum].track_type != 0) { if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n"); printf("Error. Movie does not contain any video track\n");
return 1; return 1;
} }
track = &movie->tk[tnum]; track = &movie->tk[tnum];
/* Output info on first video tracl */ /* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n", fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h); track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8; max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char)); frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples; numframes = track->num_samples;
for (snum=0; snum < numframes; snum++) for (snum=0; snum < numframes; snum++) {
{ double init_time = opj_clock();
double init_time = opj_clock(); double elapsed_time;
double elapsed_time;
sample = &track->sample[snum]; sample = &track->sample[snum];
if (sample->sample_size-8 > max_codstrm_size) { if (sample->sample_size-8 > max_codstrm_size) {
max_codstrm_size = sample->sample_size-8; max_codstrm_size = sample->sample_size-8;
if ((frame_codestream = (unsigned char*) if ((frame_codestream = (unsigned char*)
realloc(frame_codestream, max_codstrm_size)) == NULL) { realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n"); printf("Error reallocation memory\n");
return 1; return 1;
}; };
} }
fseek(file,sample->offset+8,SEEK_SET); fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */ fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */
/* open a byte stream */ /* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8); cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
img = opj_decode(dinfo, cio); /* Decode J2K to image */ img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB #ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC) if(img->color_space == CLRSPC_SYCC) {
{ color_sycc_to_rgb(img);
color_sycc_to_rgb(img); }
}
#endif #endif
if(img->icc_profile_buf) if(img->icc_profile_buf) {
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img); color_apply_icc_profile(img);
#endif #endif
free(img->icc_profile_buf); free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0; img->icc_profile_buf = NULL;
} img->icc_profile_len = 0;
}
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2) if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1)) && (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) { || (img->numcomps == 1)) {
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */ if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1; return 1;
} } else if ((img->numcomps == 3) &&
else if ((img->numcomps == 3) && (img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&& (img->comps[2].dx == 1)) { /* If YUV 4:4:4 input --> to bmp */
(img->comps[2].dx == 1))/* If YUV 4:4:4 input --> to bmp */ fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
{ sprintf(outfilename,"output_%d.bmp",snum);
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n"); if (imagetobmp(img, outfilename)) /* Convert image to BMP */
sprintf(outfilename,"output_%d.bmp",snum); return 1;
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1; } else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
}
/* close the byte stream */
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
} }
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
sprintf(outfilename,"output_%d.j2k",snum); free(frame_codestream);
outfile = fopen(outfilename, "wb"); fclose(file);
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename); /* free remaining structures */
return 1; if(dinfo) {
} mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
} }
/* close the byte stream */ free(dinfo);
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
} fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time);
free(frame_codestream); return 0;
fclose(file);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
free(dinfo);
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time);
return 0;
} }

View File

@ -46,110 +46,113 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[INFO] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
opj_dinfo_t* dinfo; {
opj_event_mgr_t event_mgr; /* event manager */ opj_dinfo_t* dinfo;
int tnum; opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum; int tnum;
opj_mj2_t *movie; unsigned int snum;
mj2_tk_t *track; opj_mj2_t *movie;
mj2_sample_t *sample; mj2_tk_t *track;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *file, *outfile; unsigned char* frame_codestream;
char outfilename[50]; FILE *file, *outfile;
mj2_dparameters_t parameters; char outfilename[50];
mj2_dparameters_t parameters;
if (argc != 3) { if (argc != 3) {
printf("Usage: %s mj2filename output_location\n",argv[0]); printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n",argv[0]); printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
return 1; return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* 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 */
memset(&parameters, 0, sizeof(mj2_dparameters_t));
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
return 1;
/* Decode first video track */
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++)
{
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
} }
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile); file = fopen(argv[1], "rb");
free(frame_codestream);
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
} }
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
/* free remaining structures */ /*
if(dinfo) { configure the event callbacks (not required)
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle); setting of each callback is optionnal
} */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
return 0; /* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
/* 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 */
memset(&parameters, 0, sizeof(mj2_dparameters_t));
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
return 1;
/* Decode first video track */
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++) {
sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
free(frame_codestream);
}
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
} }

View File

@ -41,8 +41,9 @@
#include "jp2.h" #include "jp2.h"
#include "mj2.h" #include "mj2.h"
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
return (a + b - 1) / b; {
return (a + b - 1) / b;
} }
/** /**
@ -56,153 +57,141 @@ Size of memory first allocated for MOOV box
static int test_image(const char *fname, mj2_cparameters_t *cp) static int test_image(const char *fname, mj2_cparameters_t *cp)
{ {
FILE *reader; FILE *reader;
opj_image_t *image; opj_image_t *image;
unsigned char *src; unsigned char *src;
opj_dinfo_t *dinfo; opj_dinfo_t *dinfo;
opj_cio_t *cio; opj_cio_t *cio;
opj_dparameters_t dparameters; opj_dparameters_t dparameters;
int success; int success;
long src_len; long src_len;
success = 0; success = 0;
if((reader = fopen(fname, "rb")) == NULL) return success; if((reader = fopen(fname, "rb")) == NULL) return success;
fseek(reader, 0, SEEK_END); fseek(reader, 0, SEEK_END);
src_len = ftell(reader); src_len = ftell(reader);
fseek(reader, 0, SEEK_SET); fseek(reader, 0, SEEK_SET);
src = (unsigned char*) malloc(src_len); src = (unsigned char*) malloc(src_len);
fread(src, 1, src_len, reader); fread(src, 1, src_len, reader);
fclose(reader); fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
{ free(src);
free(src); return success; return success;
} }
memset(&dparameters, 0, sizeof(opj_dparameters_t)); memset(&dparameters, 0, sizeof(opj_dparameters_t));
opj_set_default_decoder_parameters(&dparameters); opj_set_default_decoder_parameters(&dparameters);
dinfo = opj_create_decompress(CODEC_J2K); dinfo = opj_create_decompress(CODEC_J2K);
opj_setup_decoder(dinfo, &dparameters); opj_setup_decoder(dinfo, &dparameters);
cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len); cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len);
image = opj_decode(dinfo, cio); image = opj_decode(dinfo, cio);
free(src); cio->buffer = NULL; free(src);
opj_cio_close(cio); cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin; if(image == NULL) goto fin;
cp->numcomps = image->numcomps; cp->numcomps = image->numcomps;
cp->w = image->comps[0].w; cp->w = image->comps[0].w;
cp->h = image->comps[0].h; cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec; cp->prec = image->comps[0].prec;
if(image->numcomps > 2 ) if(image->numcomps > 2 ) {
{ if((image->comps[0].dx == 1)
if((image->comps[0].dx == 1) && (image->comps[1].dx == 2)
&& (image->comps[1].dx == 2) && (image->comps[2].dx == 2)
&& (image->comps[2].dx == 2) && (image->comps[0].dy == 1)
&& (image->comps[0].dy == 1) && (image->comps[1].dy == 2)
&& (image->comps[1].dy == 2) && (image->comps[2].dy == 2)) { /* horizontal and vertical*/
&& (image->comps[2].dy == 2))/* horizontal and vertical*/ /* Y420*/
{ cp->enumcs = ENUMCS_SYCC;
/* Y420*/ cp->CbCr_subsampling_dx = 2;
cp->enumcs = ENUMCS_SYCC; cp->CbCr_subsampling_dy = 2;
cp->CbCr_subsampling_dx = 2; } else if((image->comps[0].dx == 1)
cp->CbCr_subsampling_dy = 2; && (image->comps[1].dx == 2)
} && (image->comps[2].dx == 2)
else && (image->comps[0].dy == 1)
if((image->comps[0].dx == 1) && (image->comps[1].dy == 1)
&& (image->comps[1].dx == 2) && (image->comps[2].dy == 1)) { /* horizontal only*/
&& (image->comps[2].dx == 2) /* Y422*/
&& (image->comps[0].dy == 1) cp->enumcs = ENUMCS_SYCC;
&& (image->comps[1].dy == 1) cp->CbCr_subsampling_dx = 2;
&& (image->comps[2].dy == 1))/* horizontal only*/ cp->CbCr_subsampling_dy = 1;
{ } else if((image->comps[0].dx == 1)
/* Y422*/ && (image->comps[1].dx == 1)
cp->enumcs = ENUMCS_SYCC; && (image->comps[2].dx == 1)
cp->CbCr_subsampling_dx = 2; && (image->comps[0].dy == 1)
cp->CbCr_subsampling_dy = 1; && (image->comps[1].dy == 1)
} && (image->comps[2].dy == 1)) {
else /* Y444 or RGB */
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
/* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB) if(image->color_space == CLRSPC_SRGB) {
{ cp->enumcs = ENUMCS_SRGB;
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */ /* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */ /* cp->CbCr_subsampling_dy = 0; */
} } else {
else cp->enumcs = ENUMCS_SYCC;
{
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1; cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1; cp->CbCr_subsampling_dy = 1;
} }
} } else {
else goto fin;
{ }
goto fin; } else {
} cp->enumcs = ENUMCS_GRAY;
} /* cp->CbCr_subsampling_dx = 0; */
else /* cp->CbCr_subsampling_dy = 0; */
{ }
cp->enumcs = ENUMCS_GRAY; if(image->icc_profile_buf) {
/* cp->CbCr_subsampling_dx = 0; */ cp->meth = 2;
/* cp->CbCr_subsampling_dy = 0; */ free(image->icc_profile_buf);
} image->icc_profile_buf = NULL;
if(image->icc_profile_buf) } else cp->meth = 1;
{
cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
success = 1; success = 1;
fin: fin:
if(dinfo) if(dinfo)
opj_destroy_decompress(dinfo); opj_destroy_decompress(dinfo);
if(image) if(image)
opj_image_destroy(image); opj_image_destroy(image);
return success; return success;
} }
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[ERROR] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[WARNING] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
FILE *stream = (FILE*)client_data; {
fprintf(stream, "[INFO] %s", msg); FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -211,316 +200,311 @@ static void info_callback(const char *msg, void *client_data) {
static void read_siz_marker(FILE *file, opj_image_t *image) static void read_siz_marker(FILE *file, opj_image_t *image)
{ {
int len,i; int len,i;
char buf, buf2[2]; char buf, buf2[2];
unsigned char *siz_buffer; unsigned char *siz_buffer;
opj_cio_t *cio; opj_cio_t *cio;
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
do { do {
fread(&buf,1,1, file); fread(&buf,1,1, file);
if (buf==(char)0xff) if (buf==(char)0xff)
fread(&buf,1,1, file); fread(&buf,1,1, file);
} } while (!(buf==(char)0x51));
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */ fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1]; len = ((buf2[0])<<8) + buf2[1];
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char)); siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
fread(siz_buffer,len, 1, file); fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len); cio = opj_cio_open(NULL, siz_buffer, len);
cio_read(cio, 2); /* Rsiz (capabilities) */ cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */ image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */ image->y1 = cio_read(cio, 4); /* Ysiz */
image->x0 = cio_read(cio, 4); /* X0siz */ image->x0 = cio_read(cio, 4); /* X0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */ image->y0 = cio_read(cio, 4); /* Y0siz */
cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */ cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
image->numcomps = cio_read(cio,2); /* Csiz */ image->numcomps = cio_read(cio,2); /* Csiz */
image->comps = image->comps =
(opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t)); (opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) { for (i = 0; i < image->numcomps; i++) {
int tmp; int tmp;
tmp = cio_read(cio,1); /* Ssiz_i */ tmp = cio_read(cio,1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1; image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7; image->comps[i].sgnd = tmp >> 7;
image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */ image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */
image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */ image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */
image->comps[i].resno_decoded = 0; /* number of resolution decoded */ image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = 0; /* reducing factor by component */ image->comps[i].factor = 0; /* reducing factor by component */
} }
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
opj_cio_close(cio); opj_cio_close(cio);
free(siz_buffer); free(siz_buffer);
} }
static void setparams(opj_mj2_t *movie, opj_image_t *image) { static void setparams(opj_mj2_t *movie, opj_image_t *image)
int i, depth_0, depth, sign; {
int i, depth_0, depth, sign;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx); movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
mj2_init_stdmovie(movie); mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec; movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) { if (image->numcomps==3) {
if ((image->comps[0].dx == 1) if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1) && (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)) && (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1; movie->tk[0].CbCr_subsampling_dx = 1;
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else else
if ((image->comps[0].dx == 1) movie->tk[0].jp2_struct.meth = 2;
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else
movie->tk[0].jp2_struct.meth = 2;
if (image->numcomps == 1) if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */ movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else else
if ((image->comps[0].dx == 1) movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
opj_cinfo_t* cinfo; {
opj_event_mgr_t event_mgr; /* event manager */ opj_cinfo_t* cinfo;
unsigned int snum; opj_event_mgr_t event_mgr; /* event manager */
opj_mj2_t *movie; unsigned int snum;
mj2_sample_t *sample; opj_mj2_t *movie;
unsigned char* frame_codestream; mj2_sample_t *sample;
FILE *mj2file, *j2kfile; unsigned char* frame_codestream;
char *j2kfilename; FILE *mj2file, *j2kfile;
unsigned char *buf; char *j2kfilename;
int offset, mdat_initpos; unsigned char *buf;
opj_image_t img; int offset, mdat_initpos;
opj_cio_t *cio; opj_image_t img;
mj2_cparameters_t parameters; opj_cio_t *cio;
mj2_cparameters_t parameters;
if (argc != 3) { if (argc != 3) {
printf("Usage: %s source_location mj2_filename\n",argv[0]); printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]); printf("Example: %s input/input output.mj2\n",argv[0]);
return 1; return 1;
}
mj2file = fopen(argv[2], "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1)
{
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
}
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
} }
/* Calculating offset for samples and chunks */ mj2file = fopen(argv[2], "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1) {
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
} else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
}
/* Calculating offset for samples and chunks */
offset += cio_tell(cio);
sample->offset = offset;
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */
/* Calculating sample size */
fseek(j2kfile,0,SEEK_END);
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
if (snum==0)
read_siz_marker(j2kfile, &img);
/* Writing JP2C box header */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}
/* Writing the MDAT box length in header */
offset += cio_tell(cio); offset += cio_tell(cio);
sample->offset = offset; buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */ cio = opj_cio_open(movie->cinfo, buf, 4);
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* Calculating sample size */ /* Setting movie parameters */
fseek(j2kfile,0,SEEK_END); movie->tk[0].num_samples=snum;
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */ movie->tk[0].num_chunks=snum;
fseek(j2kfile,0,SEEK_SET); setparams(movie, &img);
/* Reading siz marker of j2k image for the first codestream */ /* Writing MOOV box */
if (snum==0) buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
read_siz_marker(j2kfile, &img); cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
/* Writing JP2C box header */ /* Ending program */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8); free(img.comps);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size); opj_cio_close(cio);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}
/* Writing the MDAT box length in header */
offset += cio_tell(cio);
buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 4);
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* Setting movie parameters */
movie->tk[0].num_samples=snum;
movie->tk[0].num_chunks=snum;
setparams(movie, &img);
/* Writing MOOV box */
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
/* Ending program */
free(img.comps);
opj_cio_close(cio);
fin: fin:
fclose(mj2file); fclose(mj2file);
mj2_destroy_compress(movie); mj2_destroy_compress(movie);
free(j2kfilename); free(j2kfilename);
return 0; return 0;
} }

View File

@ -180,73 +180,83 @@ class OPJChildFrame;
////////////////////////////////// //////////////////////////////////
class OPJViewerApp: public wxApp class OPJViewerApp: public wxApp
{ {
// public methods and variables // public methods and variables
public: public:
// class constructor // class constructor
OPJViewerApp() { m_showImages = true; m_showButtons = false; } OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
// other methods // other methods
bool OnInit(void); bool OnInit(void);
int OnExit(void); int OnExit(void);
void SetShowImages(bool show) { m_showImages = show; } void SetShowImages(bool show)
bool ShowImages() const { return m_showImages; } {
void ShowCmdLine(const wxCmdLineParser& parser); m_showImages = show;
}
bool ShowImages() const
{
return m_showImages;
}
void ShowCmdLine(const wxCmdLineParser& parser);
// all the threads currently alive - as soon as the thread terminates, it's // all the threads currently alive - as soon as the thread terminates, it's
// removed from the array // removed from the array
wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads; wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;
// crit section protects access to all of the arrays below // crit section protects access to all of the arrays below
wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect; wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;
// semaphore used to wait for the threads to exit, see OPJFrame::OnQuit() // semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone; wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;
// the last exiting thread should post to m_semAllDone if this is true // the last exiting thread should post to m_semAllDone if this is true
// (protected by the same m_critsect) // (protected by the same m_critsect)
bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone; bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone;
// the list of all filenames written in the command line // the list of all filenames written in the command line
wxArrayString m_filelist; wxArrayString m_filelist;
// displaying engine parameters // displaying engine parameters
int m_resizemethod; int m_resizemethod;
// decoding engine parameters // decoding engine parameters
bool m_enabledeco, m_enableparse; bool m_enabledeco, m_enableparse;
int m_reducefactor, m_qualitylayers, m_components, m_framenum; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl, m_enablejpwle; bool m_enablejpwl, m_enablejpwle;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
int m_framewidth, m_frameheight; int m_framewidth, m_frameheight;
// encoding engine parameters // encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality; wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
wxString m_cbsize, m_prsize, m_tsize, m_torigin, m_poc; wxString m_cbsize, m_prsize, m_tsize, m_torigin, m_poc;
bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop, m_enableeph; bool m_enablecomm, m_enableidx, m_multicomp, m_irreversible, m_enablesop, m_enableeph;
bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm; bool m_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm;
bool m_enablesegmark, m_enablepoc; bool m_enablesegmark, m_enablepoc;
bool m_enablequality; bool m_enablequality;
int m_resolutions, m_progression; int m_resolutions, m_progression;
#ifdef USE_JPWL #ifdef USE_JPWL
int m_hprotsel[MYJPWL_MAX_NO_TILESPECS], m_pprotsel[MYJPWL_MAX_NO_TILESPECS]; int m_hprotsel[MYJPWL_MAX_NO_TILESPECS], m_pprotsel[MYJPWL_MAX_NO_TILESPECS];
int m_htileval[MYJPWL_MAX_NO_TILESPECS], m_ptileval[MYJPWL_MAX_NO_TILESPECS], int m_htileval[MYJPWL_MAX_NO_TILESPECS], m_ptileval[MYJPWL_MAX_NO_TILESPECS],
m_ppackval[MYJPWL_MAX_NO_TILESPECS]; m_ppackval[MYJPWL_MAX_NO_TILESPECS];
int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS]; int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS];
#endif // USE_JPWL #endif // USE_JPWL
// some layout settings // some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker; bool m_showtoolbar, m_showbrowser, m_showpeeker;
int m_browserwidth, m_peekerheight; int m_browserwidth, m_peekerheight;
// application configuration // application configuration
wxConfig *OPJconfig; wxConfig *OPJconfig;
// private methods and variables // private methods and variables
private: private:
bool m_showImages, m_showButtons; bool m_showImages, m_showButtons;
}; };
@ -257,37 +267,38 @@ DECLARE_APP(OPJViewerApp)
/////////////////////////////////////////// ///////////////////////////////////////////
class OPJCanvas: public wxScrolledWindow class OPJCanvas: public wxScrolledWindow
{ {
// public methods and variables // public methods and variables
public: public:
// class constructor // class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size); OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
virtual void OnDraw(wxDC& dc); virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event); void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text) { void WriteText(const wxString& text)
{
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
#endif //__WXGTK__ #endif //__WXGTK__
wxLogMessage(text); wxLogMessage(text);
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiLeave(); wxMutexGuiLeave();
#endif //__WXGTK__ #endif //__WXGTK__
} }
void OnThreadSignal(wxCommandEvent& event); void OnThreadSignal(wxCommandEvent& event);
OPJDecoThread *CreateDecoThread(void); OPJDecoThread *CreateDecoThread(void);
OPJEncoThread *CreateEncoThread(void); OPJEncoThread *CreateEncoThread(void);
OPJChildFrame *m_childframe; OPJChildFrame *m_childframe;
wxBitmap m_image, m_image100; wxBitmap m_image, m_image100;
wxFileName m_fname, m_savename; wxFileName m_fname, m_savename;
long m_zooml; long m_zooml;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
@ -295,29 +306,38 @@ class OPJCanvas: public wxScrolledWindow
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
class OPJMarkerData : public wxTreeItemData class OPJMarkerData : public wxTreeItemData
{ {
// public methods and variables // public methods and variables
public: public:
// class constructor // class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; } OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname)
{
m_start = start;
m_length = length;
}
void ShowInfo(wxTreeCtrl *tree); void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const { return m_desc.c_str(); } const wxChar *GetDesc1() const
const wxChar *GetDesc2() const { return m_filestring.c_str(); } {
wxFileOffset m_start, m_length; return m_desc.c_str();
wxString m_desc; }
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
wxFileOffset m_start, m_length;
wxString m_desc;
// private methods and variables // private methods and variables
private: private:
wxString m_filestring; wxString m_filestring;
}; };
class OPJMarkerTree : public wxTreeCtrl class OPJMarkerTree : public wxTreeCtrl
{ {
public: public:
enum enum {
{
TreeCtrlIcon_File, TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected, TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder, TreeCtrlIcon_Folder,
@ -327,15 +347,20 @@ public:
OPJMarkerTree() { }; OPJMarkerTree() { };
OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style); long style);
virtual ~OPJMarkerTree(){}; virtual ~OPJMarkerTree() {};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL); OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); } void WriteText(const wxString& text)
{
wxMutexGuiEnter();
wxLogMessage(text);
wxMutexGuiLeave();
}
wxFileName m_fname; wxFileName m_fname;
wxTextCtrl *m_peektextCtrl; wxTextCtrl *m_peektextCtrl;
OPJChildFrame *m_childframe; OPJChildFrame *m_childframe;
/*void OnBeginDrag(wxTreeEvent& event); /*void OnBeginDrag(wxTreeEvent& event);
void OnBeginRDrag(wxTreeEvent& event); void OnBeginRDrag(wxTreeEvent& event);
@ -372,9 +397,15 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/ /*void DoToggleIcon(const wxTreeItemId& item);*/
/*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/ /*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
int ImageSize(void) const { return m_imageSize; } int ImageSize(void) const
{
return m_imageSize;
}
void SetLastItem(wxTreeItemId id) { m_lastItem = id; } void SetLastItem(wxTreeItemId id)
{
m_lastItem = id;
}
protected: protected:
/*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/ /*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
@ -416,12 +447,12 @@ WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual, OPJChild
// Define a new frame // Define a new frame
class OPJFrame: public wxMDIParentFrame class OPJFrame: public wxMDIParentFrame
{ {
public: public:
OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJFrame(void); ~OPJFrame(void);
void OnSize(wxSizeEvent& WXUNUSED(event)); void OnSize(wxSizeEvent& WXUNUSED(event));
void OnAbout(wxCommandEvent& WXUNUSED(event)); void OnAbout(wxCommandEvent& WXUNUSED(event));
void OnFileOpen(wxCommandEvent& WXUNUSED(event)); void OnFileOpen(wxCommandEvent& WXUNUSED(event));
void OnFileSaveAs(wxCommandEvent& WXUNUSED(event)); void OnFileSaveAs(wxCommandEvent& WXUNUSED(event));
@ -429,43 +460,43 @@ class OPJFrame: public wxMDIParentFrame
void OnQuit(wxCommandEvent& WXUNUSED(event)); void OnQuit(wxCommandEvent& WXUNUSED(event));
void OnClose(wxCommandEvent& WXUNUSED(event)); void OnClose(wxCommandEvent& WXUNUSED(event));
void OnZoom(wxCommandEvent& WXUNUSED(event)); void OnZoom(wxCommandEvent& WXUNUSED(event));
void OnFit(wxCommandEvent& event); void OnFit(wxCommandEvent& event);
void OnToggleBrowser(wxCommandEvent& WXUNUSED(event)); void OnToggleBrowser(wxCommandEvent& WXUNUSED(event));
void OnTogglePeeker(wxCommandEvent& WXUNUSED(event)); void OnTogglePeeker(wxCommandEvent& WXUNUSED(event));
void OnToggleToolbar(wxCommandEvent& WXUNUSED(event)); void OnToggleToolbar(wxCommandEvent& WXUNUSED(event));
void OnReload(wxCommandEvent& event); void OnReload(wxCommandEvent& event);
void OnPrevFrame(wxCommandEvent& event); void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event); void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event); void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event); void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event); void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event); void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event); void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event); void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event); void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event); void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event); void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event); void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event); void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event); void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event); void OnSashDrag(wxSashEvent& event);
void OpenFiles(wxArrayString paths, wxArrayString filenames); void OpenFiles(wxArrayString paths, wxArrayString filenames);
void SaveFile(wxArrayString paths, wxArrayString filenames); void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event); void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child); void Rescale(int scale, OPJChildFrame *child);
void OnThreadLogmsg(wxCommandEvent& event); void OnThreadLogmsg(wxCommandEvent& event);
OPJMarkerTreeHash m_treehash; OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash; OPJChildFrameHash m_childhash;
wxSashLayoutWindow* markerTreeWindow; wxSashLayoutWindow* markerTreeWindow;
wxSashLayoutWindow* loggingWindow; wxSashLayoutWindow* loggingWindow;
wxToolBar* tool_bar; wxToolBar* tool_bar;
void Resize(int number); void Resize(int number);
wxNotebook *m_bookCtrl; wxNotebook *m_bookCtrl;
wxNotebook *m_bookCtrlbottom; wxNotebook *m_bookCtrlbottom;
wxTextCtrl *m_textCtrlbrowse; wxTextCtrl *m_textCtrlbrowse;
private: private:
void TogStyle(int id, long flag); void TogStyle(int id, long flag);
void DoSort(bool reverse = false); void DoSort(bool reverse = false);
@ -479,70 +510,69 @@ protected:
wxSashLayoutWindow* m_topWindow; wxSashLayoutWindow* m_topWindow;
wxSashLayoutWindow* m_leftWindow2; wxSashLayoutWindow* m_leftWindow2;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class OPJChildFrame: public wxMDIChildFrame class OPJChildFrame: public wxMDIChildFrame
{ {
public: public:
OPJCanvas *m_canvas; OPJCanvas *m_canvas;
OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJChildFrame(void); ~OPJChildFrame(void);
void OnActivate(wxActivateEvent& event); void OnActivate(wxActivateEvent& event);
/*void OnQuit(wxCommandEvent& WXUNUSED(event));*/ /*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
void OnClose(wxCloseEvent& event); void OnClose(wxCloseEvent& event);
void OnGotFocus(wxFocusEvent& event); void OnGotFocus(wxFocusEvent& event);
void OnLostFocus(wxFocusEvent& event); void OnLostFocus(wxFocusEvent& event);
OPJFrame *m_frame; OPJFrame *m_frame;
wxFileName m_fname; wxFileName m_fname;
int m_winnumber; int m_winnumber;
unsigned long m_twidth, m_theight, m_tx, m_ty; unsigned long m_twidth, m_theight, m_tx, m_ty;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// frame and main menu ids // frame and main menu ids
enum { enum {
OPJFRAME_FILEEXIT = wxID_EXIT, OPJFRAME_FILEEXIT = wxID_EXIT,
OPJFRAME_HELPABOUT = wxID_ABOUT, OPJFRAME_HELPABOUT = wxID_ABOUT,
OPJFRAME_FILEOPEN, OPJFRAME_FILEOPEN,
OPJFRAME_MEMORYOPEN, OPJFRAME_MEMORYOPEN,
OPJFRAME_FILESAVEAS, OPJFRAME_FILESAVEAS,
OPJFRAME_FILETOGGLEB, OPJFRAME_FILETOGGLEB,
OPJFRAME_FILETOGGLEP, OPJFRAME_FILETOGGLEP,
OPJFRAME_FILETOGGLET, OPJFRAME_FILETOGGLET,
OPJFRAME_VIEWZOOM, OPJFRAME_VIEWZOOM,
OPJFRAME_VIEWFIT, OPJFRAME_VIEWFIT,
OPJFRAME_VIEWRELOAD, OPJFRAME_VIEWRELOAD,
OPJFRAME_VIEWPREVFRAME, OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME, OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME, OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS, OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS, OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS, OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES, OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES, OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES, OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP, OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS, OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP, OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE, OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO, OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO, OPJFRAME_SETSDECO,
OPJFRAME_BROWSEWIN = 10000, OPJFRAME_BROWSEWIN = 10000,
OPJFRAME_LOGWIN, OPJFRAME_LOGWIN,
OPJFRAME_TOOLBAR, OPJFRAME_TOOLBAR,
OPJFRAME_THREADLOGMSG, OPJFRAME_THREADLOGMSG,
OPJCANVAS_THREADSIGNAL OPJCANVAS_THREADSIGNAL
}; };
// menu and control ids // menu and control ids
enum enum {
{
TreeTest_Quit = wxID_EXIT, TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT, TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST, TreeTest_TogButtons = wxID_HIGHEST,
@ -587,8 +617,8 @@ enum
TreeTest_Unselect, TreeTest_Unselect,
TreeTest_SelectRoot, TreeTest_SelectRoot,
TreeTest_Ctrl = 1000, TreeTest_Ctrl = 1000,
BOTTOM_NOTEBOOK_ID, BOTTOM_NOTEBOOK_ID,
LEFT_NOTEBOOK_ID LEFT_NOTEBOOK_ID
}; };
class OPJEncoThread : public wxThread class OPJEncoThread : public wxThread
@ -645,19 +675,19 @@ public:
// write something to the text control // write something to the text control
void WriteText(const wxString& text); void WriteText(const wxString& text);
void LoadFile(wxFileName fname); void LoadFile(wxFileName fname);
void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid); void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid); void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
unsigned m_count; unsigned m_count;
OPJMarkerTree *m_tree; OPJMarkerTree *m_tree;
wxTreeItemId m_parentid; wxTreeItemId m_parentid;
private: private:
int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint); wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint); wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
}; };
@ -666,7 +696,10 @@ private:
class OPJDnDFile: public wxFileDropTarget class OPJDnDFile: public wxFileDropTarget
{ {
public: public:
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; } OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private: private:
@ -678,137 +711,137 @@ private:
// Property sheet dialog: encoder // Property sheet dialog: encoder
class OPJEncoderDialog: public wxPropertySheetDialog class OPJEncoderDialog: public wxPropertySheetDialog
{ {
DECLARE_CLASS(OPJEncoderDialog) DECLARE_CLASS(OPJEncoderDialog)
public: public:
OPJEncoderDialog(wxWindow* parent, int dialogType); OPJEncoderDialog(wxWindow* parent, int dialogType);
~OPJEncoderDialog(); ~OPJEncoderDialog();
wxBookCtrlBase* m_settingsNotebook; wxBookCtrlBase* m_settingsNotebook;
wxPanel* CreateMainSettingsPage(wxWindow* parent); wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1_1SettingsPage(wxWindow* parent); wxPanel* CreatePart1_1SettingsPage(wxWindow* parent);
wxPanel* CreatePart1_2SettingsPage(wxWindow* parent); wxPanel* CreatePart1_2SettingsPage(wxWindow* parent);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/ /* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event); void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event); void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event); void OnEnablePoc(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event); void OnRadioQualityRate(wxCommandEvent& event);
#ifdef USE_JPWL #ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event); void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent); wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/ /*wxCheckBox *m_enablejpwlCheck;*/
wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS]; wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS]; wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS]; wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS]; wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS]; wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS]; wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS]; wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS];
void OnHprotSelect(wxCommandEvent& event); void OnHprotSelect(wxCommandEvent& event);
void OnPprotSelect(wxCommandEvent& event); void OnPprotSelect(wxCommandEvent& event);
void OnSensiSelect(wxCommandEvent& event); void OnSensiSelect(wxCommandEvent& event);
#endif // USE_JPWL #endif // USE_JPWL
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl; wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio; wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl; wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl; wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxRadioBox *progressionBox; wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck; wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck, wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck; *m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck; wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck;
wxSpinCtrl *m_resolutionsCtrl; wxSpinCtrl *m_resolutionsCtrl;
protected: protected:
enum { enum {
OPJENCO_ENABLEJPWL = 100, OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR, OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO, OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR, OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO, OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER, OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE, OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE, OPJENCO_PRECINCTSIZE,
OPJENCO_TILESIZE, OPJENCO_TILESIZE,
OPJENCO_PROGRESSION, OPJENCO_PROGRESSION,
OPJENCO_SUBSAMPLING, OPJENCO_SUBSAMPLING,
OPJENCO_ENABLESOP, OPJENCO_ENABLESOP,
OPJENCO_ENABLEEPH, OPJENCO_ENABLEEPH,
OPJENCO_ENABLEBYPASS, OPJENCO_ENABLEBYPASS,
OPJENCO_ENABLERESET, OPJENCO_ENABLERESET,
OPJENCO_ENABLERESTART, OPJENCO_ENABLERESTART,
OPJENCO_ENABLEVSC, OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM, OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK, OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC, OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP, OPJENCO_ROICOMP,
OPJENCO_ROISHIFT, OPJENCO_ROISHIFT,
OPJENCO_IMORIG, OPJENCO_IMORIG,
OPJENCO_TILORIG, OPJENCO_TILORIG,
OPJENCO_ENABLEMCT, OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV, OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX, OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME, OPJENCO_INDEXNAME,
OPJENCO_POCSPEC, OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM, OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT, OPJENCO_COMMENTTEXT,
OPJENCO_HPROT, OPJENCO_HPROT,
OPJENCO_HTILE, OPJENCO_HTILE,
OPJENCO_PPROT, OPJENCO_PPROT,
OPJENCO_PTILE, OPJENCO_PTILE,
OPJENCO_PPACK, OPJENCO_PPACK,
OPJENCO_SENSI, OPJENCO_SENSI,
OPJENCO_STILE OPJENCO_STILE
}; };
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// Property sheet dialog: decoder // Property sheet dialog: decoder
class OPJDecoderDialog: public wxPropertySheetDialog class OPJDecoderDialog: public wxPropertySheetDialog
{ {
DECLARE_CLASS(OPJDecoderDialog) DECLARE_CLASS(OPJDecoderDialog)
public: public:
OPJDecoderDialog(wxWindow* parent, int dialogType); OPJDecoderDialog(wxWindow* parent, int dialogType);
~OPJDecoderDialog(); ~OPJDecoderDialog();
wxBookCtrlBase* m_settingsNotebook; wxBookCtrlBase* m_settingsNotebook;
wxCheckBox *m_enabledecoCheck, *m_enableparseCheck; wxCheckBox *m_enabledecoCheck, *m_enableparseCheck;
wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl; wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
wxRadioBox* m_resizeBox; wxRadioBox* m_resizeBox;
void OnEnableDeco(wxCommandEvent& event); void OnEnableDeco(wxCommandEvent& event);
wxPanel* CreateMainSettingsPage(wxWindow* parent); wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1SettingsPage(wxWindow* parent); wxPanel* CreatePart1SettingsPage(wxWindow* parent);
wxPanel* CreatePart3SettingsPage(wxWindow* parent); wxPanel* CreatePart3SettingsPage(wxWindow* parent);
#ifdef USE_JPWL #ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event); void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent); wxPanel* CreatePart11SettingsPage(wxWindow* parent);
wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl; wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
wxCheckBox *m_enablejpwlCheck; wxCheckBox *m_enablejpwlCheck;
#endif // USE_JPWL #endif // USE_JPWL
wxSpinCtrl *m_framenumCtrl; wxSpinCtrl *m_framenumCtrl;
protected: protected:
enum { enum {
OPJDECO_RESMETHOD = 100, OPJDECO_RESMETHOD = 100,
OPJDECO_REDUCEFACTOR, OPJDECO_REDUCEFACTOR,
OPJDECO_QUALITYLAYERS, OPJDECO_QUALITYLAYERS,
OPJDECO_NUMCOMPS, OPJDECO_NUMCOMPS,
OPJDECO_ENABLEDECO, OPJDECO_ENABLEDECO,
OPJDECO_ENABLEPARSE, OPJDECO_ENABLEPARSE,
OPJDECO_ENABLEJPWL, OPJDECO_ENABLEJPWL,
OPJDECO_EXPCOMPS, OPJDECO_EXPCOMPS,
OPJDECO_MAXTILES, OPJDECO_MAXTILES,
OPJDECO_FRAMENUM OPJDECO_FRAMENUM
}; };
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif //__OPJ_VIEWER_H__ #endif //__OPJ_VIEWER_H__

View File

@ -1,54 +1,54 @@
wxString htmlaboutpage = wxT( wxString htmlaboutpage = wxT(
"<html>" "<html>"
"<body bgcolor=#FFFFFF>" "<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>" "<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>" "<tr>"
"<td rowspan=3 valign=top align=center width=70>" "<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>" "<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>" "</td>"
"<td align=center>" "<td align=center>"
"<font size=+0 color=#000000><b>" "<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</b></font><br>" "</b></font><br>"
"<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>" "<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>"
"<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>" "<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>"
"</td>" "</td>"
"</tr>" "</tr>"
"<tr height=3 valign=center>" "<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>" "<td valign=center bgcolor=#cc3300></td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td align=justify>" "<td align=justify>"
"<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>" "<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>"
"<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. " "<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. "
"In addition to the basic codec, various other features are under development.</font></p><br>" "In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ") "<font size=-2 color=red>* Build: ")
#include "build.h" #include "build.h"
wxT(", " __DATE__ ", " __TIME__ "</font><br>") wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>") wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (") wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
#ifdef USE_JPWL #ifdef USE_JPWL
wxT("<font size=-2 color=green>JPWL</font> ") wxT("<font size=-2 color=green>JPWL</font> ")
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_JPSEC #ifdef USE_JPSEC
wxT("<font size=-2 color=green>JPSEC</font> ") wxT("<font size=-2 color=green>JPSEC</font> ")
#endif // USE_JPSEC #endif // USE_JPSEC
wxT(")</font><br>") wxT(")</font><br>")
#ifdef USE_MXF #ifdef USE_MXF
wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>") wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>")
#endif // USE_MXF #endif // USE_MXF
wxT("</td>" wxT("</td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>" "<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td colspan=2>" "<td colspan=2>"
"<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>" "<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>"
"<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>" "<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>"
"</td>" "</td>"
"</tr>" "</tr>"
"</table>" "</table>"
"</body>" "</body>"
"</html>" "</html>"
); );

View File

@ -64,105 +64,105 @@ public:
m_type = wxBITMAP_TYPE_JPEG2000; m_type = wxBITMAP_TYPE_JPEG2000;
m_mime = wxT("image/mj2"); m_mime = wxT("image/mj2");
/* decoding */ /* decoding */
m_reducefactor = 0; m_reducefactor = 0;
m_qualitylayers = 0; m_qualitylayers = 0;
m_components = 0; m_components = 0;
#ifdef USE_JPWL #ifdef USE_JPWL
m_enablejpwl = true; m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS; m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES; m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL #endif // USE_JPWL
/* encoding */ /* encoding */
m_subsampling = wxT("1,1"); m_subsampling = wxT("1,1");
m_origin = wxT("0,0"); m_origin = wxT("0,0");
m_rates = wxT("20,10,5"); m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40"); m_quality = wxT("30,35,40");
m_enablequality = false; m_enablequality = false;
m_multicomp = false; m_multicomp = false;
m_irreversible = false; m_irreversible = false;
m_resolutions = 6; m_resolutions = 6;
m_progression = 0; m_progression = 0;
m_cbsize = wxT("32,32"); m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]"); m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT(""); m_tsize = wxT("");
m_torigin = wxT("0,0"); m_torigin = wxT("0,0");
/*m_progression /*m_progression
m_resilience*/ m_resilience*/
m_enablesop = false; m_enablesop = false;
m_enableeph = false; m_enableeph = false;
m_enablereset = false; m_enablereset = false;
m_enablesegmark = false; m_enablesegmark = false;
m_enablevsc = false; m_enablevsc = false;
m_enablerestart = false; m_enablerestart = false;
m_enableerterm = false; m_enableerterm = false;
m_enablebypass = false; m_enablebypass = false;
/*m_roicompo /*m_roicompo
m_roiup m_roiup
m_indexfname*/ m_indexfname*/
m_enableidx = false; m_enableidx = false;
m_index = wxT("index.txt"); m_index = wxT("index.txt");
m_enablepoc = false; m_enablepoc = false;
m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL"); m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
m_enablecomm = true; m_enablecomm = true;
#if defined __WXMSW__ #if defined __WXMSW__
m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version "); m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version ");
#elif defined __WXGTK__ #elif defined __WXGTK__
m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version "); m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
#else #else
m_comment = wxT("Created by OPJViewer - OpenJPEG version "); m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
#endif #endif
#ifdef USE_JPWL #ifdef USE_JPWL
m_comment += wxString::Format(wxT("%s with JPWL"), (char *) opj_version()); m_comment += wxString::Format(wxT("%s with JPWL"), (char *) opj_version());
#else #else
m_comment += wxString::Format(wxT("%s"), (char *) opj_version()); m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
#endif #endif
} }
// decoding engine parameters // decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl; bool m_enablejpwl;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
// encoding engine parameters // encoding engine parameters
wxString m_subsampling; wxString m_subsampling;
wxString m_origin; wxString m_origin;
wxString m_rates; wxString m_rates;
wxString m_quality; wxString m_quality;
bool m_enablequality; bool m_enablequality;
bool m_multicomp; bool m_multicomp;
bool m_irreversible; bool m_irreversible;
int m_resolutions; int m_resolutions;
int m_progression; int m_progression;
wxString m_cbsize; wxString m_cbsize;
wxString m_prsize; wxString m_prsize;
wxString m_tsize; wxString m_tsize;
wxString m_torigin; wxString m_torigin;
/*m_progression /*m_progression
m_resilience*/ m_resilience*/
bool m_enablesop; bool m_enablesop;
bool m_enableeph; bool m_enableeph;
bool m_enablebypass; bool m_enablebypass;
bool m_enableerterm; bool m_enableerterm;
bool m_enablerestart; bool m_enablerestart;
bool m_enablereset; bool m_enablereset;
bool m_enablesegmark; bool m_enablesegmark;
bool m_enablevsc; bool m_enablevsc;
/*m_roicompo /*m_roicompo
m_roiup m_roiup
m_indexfname*/ m_indexfname*/
bool m_enableidx; bool m_enableidx;
wxString m_index; wxString m_index;
bool m_enablecomm; bool m_enablecomm;
wxString m_comment; wxString m_comment;
bool m_enablepoc; bool m_enablepoc;
wxString m_poc; wxString m_poc;
#if wxUSE_STREAMS #if wxUSE_STREAMS
virtual bool LoadFile(wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1); virtual bool LoadFile(wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1);
@ -172,7 +172,7 @@ protected:
#endif #endif
private: private:
OPJ_PROG_ORDER give_progression(char progression[4]); OPJ_PROG_ORDER give_progression(char progression[4]);
DECLARE_DYNAMIC_CLASS(wxJPEG2000Handler) DECLARE_DYNAMIC_CLASS(wxJPEG2000Handler)
}; };

View File

@ -66,23 +66,23 @@ public:
m_type = wxBITMAP_TYPE_MXF; m_type = wxBITMAP_TYPE_MXF;
m_mime = wxT("image/mxf"); m_mime = wxT("image/mxf");
m_reducefactor = 0; m_reducefactor = 0;
m_qualitylayers = 0; m_qualitylayers = 0;
m_components = 0; m_components = 0;
m_filename = wxT(""); m_filename = wxT("");
#ifdef USE_JPWL #ifdef USE_JPWL
m_enablejpwl = true; m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS; m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES; m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL #endif // USE_JPWL
} }
// decoding engine parameters // decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum; int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename; wxFileName m_filename;
#ifdef USE_JPWL #ifdef USE_JPWL
bool m_enablejpwl; bool m_enablejpwl;
int m_expcomps, m_maxtiles; int m_expcomps, m_maxtiles;
#endif // USE_JPWL #endif // USE_JPWL
#if wxUSE_STREAMS #if wxUSE_STREAMS

View File

@ -78,40 +78,44 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return OPJ_FALSE; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
} return OPJ_FALSE;
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8); }
return OPJ_TRUE; *bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
return OPJ_TRUE;
} }
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return OPJ_FALSE; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
} return OPJ_FALSE;
bio->buf |= *bio->bp++; }
return OPJ_TRUE; bio->buf |= *bio->bp++;
return OPJ_TRUE;
} }
static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b)
if (bio->ct == 0) { {
opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */ if (bio->ct == 0) {
} opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */
bio->ct--; }
bio->buf |= b << bio->ct; bio->ct--;
bio->buf |= b << bio->ct;
} }
static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio)
if (bio->ct == 0) { {
opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */ if (bio->ct == 0) {
} opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */
bio->ct--; }
return (bio->buf >> bio->ct) & 1; bio->ct--;
return (bio->buf >> bio->ct) & 1;
} }
/* /*
@ -120,72 +124,81 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
========================================================== ==========================================================
*/ */
opj_bio_t* opj_bio_create(void) { opj_bio_t* opj_bio_create(void)
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); {
return bio; opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
} }
void opj_bio_destroy(opj_bio_t *bio) { void opj_bio_destroy(opj_bio_t *bio)
if(bio) { {
opj_free(bio); if(bio) {
} opj_free(bio);
}
} }
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) { ptrdiff_t opj_bio_numbytes(opj_bio_t *bio)
return (bio->bp - bio->start); {
return (bio->bp - bio->start);
} }
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 8; bio->buf = 0;
bio->ct = 8;
} }
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 0; bio->buf = 0;
bio->ct = 0;
} }
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n)
OPJ_UINT32 i; {
for (i = n - 1; i < n; i--) { OPJ_UINT32 i;
opj_bio_putbit(bio, (v >> i) & 1); for (i = n - 1; i < n; i--) {
} opj_bio_putbit(bio, (v >> i) & 1);
}
} }
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
OPJ_UINT32 i; {
OPJ_UINT32 i;
OPJ_UINT32 v; OPJ_UINT32 v;
v = 0; v = 0;
for (i = n - 1; i < n; i--) { for (i = n - 1; i < n; i--) {
v += opj_bio_getbit(bio) << i; v += opj_bio_getbit(bio) << i;
} }
return v; return v;
} }
OPJ_BOOL opj_bio_flush(opj_bio_t *bio) { OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
if (! opj_bio_byteout(bio)) { {
return OPJ_FALSE; if (! opj_bio_byteout(bio)) {
} return OPJ_FALSE;
if (bio->ct == 7) { }
if (! opj_bio_byteout(bio)) { if (bio->ct == 7) {
return OPJ_FALSE; if (! opj_bio_byteout(bio)) {
} return OPJ_FALSE;
} }
return OPJ_TRUE; }
return OPJ_TRUE;
} }
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) { OPJ_BOOL opj_bio_inalign(opj_bio_t *bio)
if ((bio->buf & 0xff) == 0xff) { {
if (! opj_bio_bytein(bio)) { if ((bio->buf & 0xff) == 0xff) {
return OPJ_FALSE; if (! opj_bio_bytein(bio)) {
} return OPJ_FALSE;
} }
bio->ct = 0; }
return OPJ_TRUE; bio->ct = 0;
return OPJ_TRUE;
} }

View File

@ -54,16 +54,16 @@ The functions in BIO.C have for goal to realize an individual bit input - output
Individual bit input-output stream (BIO) Individual bit input-output stream (BIO)
*/ */
typedef struct opj_bio { typedef struct opj_bio {
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
OPJ_BYTE *start; OPJ_BYTE *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
OPJ_BYTE *end; OPJ_BYTE *end;
/** pointer to the present position in the buffer */ /** pointer to the present position in the buffer */
OPJ_BYTE *bp; OPJ_BYTE *bp;
/** temporary place where each byte is read or written */ /** temporary place where each byte is read or written */
OPJ_UINT32 buf; OPJ_UINT32 buf;
/** coder : number of bits free to write. decoder : number of bits read */ /** coder : number of bits free to write. decoder : number of bits read */
OPJ_UINT32 ct; OPJ_UINT32 ct;
} opj_bio_t; } opj_bio_t;
/** @name Exported functions */ /** @name Exported functions */

View File

@ -41,102 +41,102 @@
*/ */
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio, void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen, int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
int i; int i;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
OPJ_UINT32 len; OPJ_UINT32 len;
opj_jp2_box_t *box; opj_jp2_box_t *box;
int num_box = 0; int num_box = 0;
OPJ_BOOL EPHused; OPJ_BOOL EPHused;
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
lenp = -1; lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
for (i=0;i<2;i++){ for (i=0; i<2; i++) {
if(i) if(i)
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
lenp = opj_stream_tell (cio); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */ opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager); opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);
opj_write_manf( i, num_box, box, cio,p_manager); opj_write_manf( i, num_box, box, cio,p_manager);
num_box = 0; num_box = 0;
box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
box[num_box].type = JPIP_MHIX; box[num_box].type = JPIP_MHIX;
num_box++; num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
box[num_box].type = JPIP_TPIX; box[num_box].type = JPIP_TPIX;
num_box++; num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager); box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX; box[num_box].type = JPIP_THIX;
num_box++; num_box++;
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager); EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PPIX; box[num_box].type = JPIP_PPIX;
num_box++; num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX; box[num_box].type = JPIP_PHIX;
num_box++; num_box++;
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp); len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
} }
opj_free( box); opj_free( box);
return (int)len; return (int)len;
} }
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio, void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [3*8]; OPJ_BYTE l_data_header [3*8];
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */ opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */
opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */ opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */
opj_write_bytes( l_data_header+6, 0, 2); /* CONT */ opj_write_bytes( l_data_header+6, 0, 2); /* CONT */
opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */ opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */ opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,p_manager); opj_stream_write_data(cio,l_data_header,3*8,p_manager);
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp); len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4); /* L */ opj_write_bytes(l_data_header, len, 4); /* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
} }
@ -148,92 +148,90 @@ void opj_write_manf(int second,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int i; int i;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */ opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
if (second){ /* Write only during the second pass */ if (second) { /* Write only during the second pass */
for( i=0; i<v; i++){ for( i=0; i<v; i++) {
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */ opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */ opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
}
} }
}
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp); len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4);/* L */ opj_write_bytes(l_data_header, len, 4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio,lenp+len,p_manager); opj_stream_seek(cio,lenp+len,p_manager);
} }
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell (cio); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager); opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp); for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++) { /* Marker restricted to 1 apparition, skip SOC marker */
opj_stream_seek(cio, lenp,p_manager); opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
return (int)len; len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return (int)len;
} }
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio, OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
OPJ_BOOL EPHused = OPJ_FALSE; OPJ_BOOL EPHused = OPJ_FALSE;
int i=0; int i=0;
OPJ_OFF_T org_pos; OPJ_OFF_T org_pos;
unsigned int Scod; unsigned int Scod;
for(i = 0; i < marknum; i++) for(i = 0; i < marknum; i++) {
{ if( markers[i].type == J2K_MS_COD) {
if( markers[i].type == J2K_MS_COD) org_pos = opj_stream_tell(cio);
{ opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
opj_stream_read_data(cio,l_data_header,1,p_manager); opj_stream_read_data(cio,l_data_header,1,p_manager);
opj_read_bytes(l_data_header,&Scod,1); opj_read_bytes(l_data_header,&Scod,1);
if( ((Scod >> 2) & 1)) if( ((Scod >> 2) & 1))
EPHused = OPJ_TRUE; EPHused = OPJ_TRUE;
opj_stream_seek( cio, org_pos, p_manager); opj_stream_seek( cio, org_pos, p_manager);
break; break;
} }
} }
return EPHused; return EPHused;
} }

View File

@ -51,7 +51,7 @@
* @return length of cidx box * @return length of cidx box
*/ */
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen, int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Check if EPH option is used * Check if EPH option is used
@ -63,6 +63,6 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
* @return true if EPH is used * @return true if EPH is used
*/ */
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio, OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
#endif /* !CIDX_MANAGER_H_ */ #endif /* !CIDX_MANAGER_H_ */

View File

@ -46,599 +46,590 @@
void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) void opj_write_bytes_BE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value)+sizeof(OPJ_UINT32)-p_nb_bytes; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value)+sizeof(OPJ_UINT32)-p_nb_bytes;
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
memcpy(p_buffer,l_data_ptr,p_nb_bytes); memcpy(p_buffer,l_data_ptr,p_nb_bytes);
} }
void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes) void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1;
OPJ_UINT32 i; OPJ_UINT32 i;
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
for (i=0;i<p_nb_bytes;++i) { for (i=0; i<p_nb_bytes; ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
*p_value = 0; *p_value = 0;
memcpy(l_data_ptr+sizeof(OPJ_UINT32)-p_nb_bytes,p_buffer,p_nb_bytes); memcpy(l_data_ptr+sizeof(OPJ_UINT32)-p_nb_bytes,p_buffer,p_nb_bytes);
} }
void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes) void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT32 p_nb_bytes)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes-1; OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes-1;
OPJ_UINT32 i; OPJ_UINT32 i;
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
*p_value = 0; *p_value = 0;
for (i=0;i<p_nb_bytes;++i) { for (i=0; i<p_nb_bytes; ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value); const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value);
memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT64)); memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT64));
} }
void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT64);++i) { for (i=0; i<sizeof(OPJ_FLOAT64); ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value) void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT64)); memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT64));
} }
void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value) void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64)-1; OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64)-1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT64);++i) { for (i=0; i<sizeof(OPJ_FLOAT64); ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value) void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value); const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value);
memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT32)); memcpy(p_buffer,l_data_ptr,sizeof(OPJ_FLOAT32));
} }
void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value) void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT32) - 1; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT32) - 1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT32);++i) { for (i=0; i<sizeof(OPJ_FLOAT32); ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value) void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value);
memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT32)); memcpy(l_data_ptr,p_buffer,sizeof(OPJ_FLOAT32));
} }
void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value) void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32)-1; OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32)-1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT32);++i) { for (i=0; i<sizeof(OPJ_FLOAT32); ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input) opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l_is_input)
{ {
opj_stream_private_t * l_stream = 00; opj_stream_private_t * l_stream = 00;
l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t)); l_stream = (opj_stream_private_t*) opj_calloc(1,sizeof(opj_stream_private_t));
if (! l_stream) { if (! l_stream) {
return 00; return 00;
} }
l_stream->m_buffer_size = p_buffer_size; l_stream->m_buffer_size = p_buffer_size;
l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size); l_stream->m_stored_data = (OPJ_BYTE *) opj_malloc(p_buffer_size);
if (! l_stream->m_stored_data) { if (! l_stream->m_stored_data) {
opj_free(l_stream); opj_free(l_stream);
return 00; return 00;
} }
l_stream->m_current_data = l_stream->m_stored_data; l_stream->m_current_data = l_stream->m_stored_data;
if (l_is_input) { if (l_is_input) {
l_stream->m_status |= OPJ_STREAM_STATUS_INPUT; l_stream->m_status |= OPJ_STREAM_STATUS_INPUT;
l_stream->m_opj_skip = opj_stream_read_skip; l_stream->m_opj_skip = opj_stream_read_skip;
l_stream->m_opj_seek = opj_stream_read_seek; l_stream->m_opj_seek = opj_stream_read_seek;
} } else {
else { l_stream->m_status |= OPJ_STREAM_STATUS_OUTPUT;
l_stream->m_status |= OPJ_STREAM_STATUS_OUTPUT; l_stream->m_opj_skip = opj_stream_write_skip;
l_stream->m_opj_skip = opj_stream_write_skip; l_stream->m_opj_seek = opj_stream_write_seek;
l_stream->m_opj_seek = opj_stream_write_seek; }
}
l_stream->m_read_fn = opj_stream_default_read; l_stream->m_read_fn = opj_stream_default_read;
l_stream->m_write_fn = opj_stream_default_write; l_stream->m_write_fn = opj_stream_default_write;
l_stream->m_skip_fn = opj_stream_default_skip; l_stream->m_skip_fn = opj_stream_default_skip;
l_stream->m_seek_fn = opj_stream_default_seek; l_stream->m_seek_fn = opj_stream_default_seek;
return (opj_stream_t *) l_stream; return (opj_stream_t *) l_stream;
} }
opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL l_is_input) opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL l_is_input)
{ {
return opj_stream_create(OPJ_J2K_STREAM_CHUNK_SIZE,l_is_input); return opj_stream_create(OPJ_J2K_STREAM_CHUNK_SIZE,l_is_input);
} }
void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (l_stream) { if (l_stream) {
if (l_stream->m_free_user_data_fn) { if (l_stream->m_free_user_data_fn) {
l_stream->m_free_user_data_fn(l_stream->m_user_data); l_stream->m_free_user_data_fn(l_stream->m_user_data);
} }
opj_free(l_stream->m_stored_data); opj_free(l_stream->m_stored_data);
l_stream->m_stored_data = 00; l_stream->m_stored_data = 00;
opj_free(l_stream); opj_free(l_stream);
} }
} }
void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function) void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if ((!l_stream) || (! (l_stream->m_status & OPJ_STREAM_STATUS_INPUT))) { if ((!l_stream) || (! (l_stream->m_status & OPJ_STREAM_STATUS_INPUT))) {
return; return;
} }
l_stream->m_read_fn = p_function; l_stream->m_read_fn = p_function;
} }
void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function) void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream) { if (!l_stream) {
return; return;
} }
l_stream->m_seek_fn = p_function; l_stream->m_seek_fn = p_function;
} }
void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function) void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if ((!l_stream )|| (! (l_stream->m_status & OPJ_STREAM_STATUS_OUTPUT))) { if ((!l_stream )|| (! (l_stream->m_status & OPJ_STREAM_STATUS_OUTPUT))) {
return; return;
} }
l_stream->m_write_fn = p_function; l_stream->m_write_fn = p_function;
} }
void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function) void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (! l_stream) { if (! l_stream) {
return; return;
} }
l_stream->m_skip_fn = p_function; l_stream->m_skip_fn = p_function;
} }
void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function) void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream) if (!l_stream)
return; return;
l_stream->m_user_data = p_data; l_stream->m_user_data = p_data;
l_stream->m_free_user_data_fn = p_function; l_stream->m_free_user_data_fn = p_function;
} }
void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length) void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length)
{ {
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream) if (!l_stream)
return; return;
l_stream->m_user_data_length = data_length; l_stream->m_user_data_length = data_length;
} }
OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
OPJ_SIZE_T l_read_nb_bytes = 0; OPJ_SIZE_T l_read_nb_bytes = 0;
if (p_stream->m_bytes_in_buffer >= p_size) { if (p_stream->m_bytes_in_buffer >= p_size) {
memcpy(p_buffer,p_stream->m_current_data,p_size); memcpy(p_buffer,p_stream->m_current_data,p_size);
p_stream->m_current_data += p_size; p_stream->m_current_data += p_size;
p_stream->m_bytes_in_buffer -= p_size; p_stream->m_bytes_in_buffer -= p_size;
l_read_nb_bytes += p_size; l_read_nb_bytes += p_size;
p_stream->m_byte_offset += (OPJ_OFF_T)p_size; p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
return l_read_nb_bytes; return l_read_nb_bytes;
} }
/* we are now in the case when the remaining data if not sufficient */ /* we are now in the case when the remaining data if not sufficient */
if (p_stream->m_status & OPJ_STREAM_STATUS_END) { if (p_stream->m_status & OPJ_STREAM_STATUS_END) {
l_read_nb_bytes += p_stream->m_bytes_in_buffer; l_read_nb_bytes += p_stream->m_bytes_in_buffer;
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer); memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
p_stream->m_current_data += p_stream->m_bytes_in_buffer; p_stream->m_current_data += p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1; return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} }
/* the flag is not set, we copy data and then do an actual read on the stream */ /* the flag is not set, we copy data and then do an actual read on the stream */
if (p_stream->m_bytes_in_buffer) { if (p_stream->m_bytes_in_buffer) {
l_read_nb_bytes += p_stream->m_bytes_in_buffer; l_read_nb_bytes += p_stream->m_bytes_in_buffer;
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer); memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_buffer += p_stream->m_bytes_in_buffer; p_buffer += p_stream->m_bytes_in_buffer;
p_size -= p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} } else {
else { /* case where we are already at the end of the buffer
/* case where we are already at the end of the buffer so reset the m_current_data to point to the start of the
so reset the m_current_data to point to the start of the stored buffer to get ready to read from disk*/
stored buffer to get ready to read from disk*/ p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_current_data = p_stream->m_stored_data; }
}
for (;;) { for (;;) {
/* we should read less than a chunk -> read a chunk */ /* we should read less than a chunk -> read a chunk */
if (p_size < p_stream->m_buffer_size) { if (p_size < p_stream->m_buffer_size) {
/* we should do an actual read on the media */ /* we should do an actual read on the media */
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_stream->m_stored_data,p_stream->m_buffer_size,p_stream->m_user_data); p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_stream->m_stored_data,p_stream->m_buffer_size,p_stream->m_user_data);
if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T)-1) { if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T)-1) {
/* end of stream */ /* end of stream */
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n"); opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */ /* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1; return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} } else if (p_stream->m_bytes_in_buffer < p_size) {
else if (p_stream->m_bytes_in_buffer < p_size) { /* not enough data */
/* not enough data */ l_read_nb_bytes += p_stream->m_bytes_in_buffer;
l_read_nb_bytes += p_stream->m_bytes_in_buffer; memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer); p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_current_data = p_stream->m_stored_data; p_buffer += p_stream->m_bytes_in_buffer;
p_buffer += p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_size -= p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_bytes_in_buffer = 0;
p_stream->m_bytes_in_buffer = 0; } else {
} l_read_nb_bytes += p_size;
else { memcpy(p_buffer,p_stream->m_current_data,p_size);
l_read_nb_bytes += p_size; p_stream->m_current_data += p_size;
memcpy(p_buffer,p_stream->m_current_data,p_size); p_stream->m_bytes_in_buffer -= p_size;
p_stream->m_current_data += p_size; p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
p_stream->m_bytes_in_buffer -= p_size; return l_read_nb_bytes;
p_stream->m_byte_offset += (OPJ_OFF_T)p_size; }
return l_read_nb_bytes; } else {
} /* direct read on the dest buffer */
} p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data);
else {
/* direct read on the dest buffer */
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data);
if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T)-1) { if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T)-1) {
/* end of stream */ /* end of stream */
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n"); opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */ /* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1; return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} } else if (p_stream->m_bytes_in_buffer < p_size) {
else if (p_stream->m_bytes_in_buffer < p_size) { /* not enough data */
/* not enough data */ l_read_nb_bytes += p_stream->m_bytes_in_buffer;
l_read_nb_bytes += p_stream->m_bytes_in_buffer; p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_current_data = p_stream->m_stored_data; p_buffer += p_stream->m_bytes_in_buffer;
p_buffer += p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_size -= p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_bytes_in_buffer = 0;
p_stream->m_bytes_in_buffer = 0; } else {
} /* we have read the exact size */
else { l_read_nb_bytes += p_stream->m_bytes_in_buffer;
/* we have read the exact size */ p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
l_read_nb_bytes += p_stream->m_bytes_in_buffer; p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_bytes_in_buffer = 0;
p_stream->m_current_data = p_stream->m_stored_data; return l_read_nb_bytes;
p_stream->m_bytes_in_buffer = 0; }
return l_read_nb_bytes; }
} }
}
}
} }
OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream, OPJ_SIZE_T opj_stream_write_data (opj_stream_private_t * p_stream,
const OPJ_BYTE * p_buffer, const OPJ_BYTE * p_buffer,
OPJ_SIZE_T p_size, OPJ_SIZE_T p_size,
opj_event_mgr_t * p_event_mgr) opj_event_mgr_t * p_event_mgr)
{ {
OPJ_SIZE_T l_remaining_bytes = 0; OPJ_SIZE_T l_remaining_bytes = 0;
OPJ_SIZE_T l_write_nb_bytes = 0; OPJ_SIZE_T l_write_nb_bytes = 0;
if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) { if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) {
return (OPJ_SIZE_T)-1; return (OPJ_SIZE_T)-1;
} }
for (;;) { for (;;) {
l_remaining_bytes = p_stream->m_buffer_size - p_stream->m_bytes_in_buffer; l_remaining_bytes = p_stream->m_buffer_size - p_stream->m_bytes_in_buffer;
/* we have more memory than required */ /* we have more memory than required */
if (l_remaining_bytes >= p_size) { if (l_remaining_bytes >= p_size) {
memcpy(p_stream->m_current_data, p_buffer, p_size); memcpy(p_stream->m_current_data, p_buffer, p_size);
p_stream->m_current_data += p_size; p_stream->m_current_data += p_size;
p_stream->m_bytes_in_buffer += p_size; p_stream->m_bytes_in_buffer += p_size;
l_write_nb_bytes += p_size; l_write_nb_bytes += p_size;
p_stream->m_byte_offset += (OPJ_OFF_T)p_size; p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
return l_write_nb_bytes; return l_write_nb_bytes;
} }
/* we copy data and then do an actual read on the stream */ /* we copy data and then do an actual read on the stream */
if (l_remaining_bytes) { if (l_remaining_bytes) {
l_write_nb_bytes += l_remaining_bytes; l_write_nb_bytes += l_remaining_bytes;
memcpy(p_stream->m_current_data,p_buffer,l_remaining_bytes); memcpy(p_stream->m_current_data,p_buffer,l_remaining_bytes);
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_buffer += l_remaining_bytes; p_buffer += l_remaining_bytes;
p_size -= l_remaining_bytes; p_size -= l_remaining_bytes;
p_stream->m_bytes_in_buffer += l_remaining_bytes; p_stream->m_bytes_in_buffer += l_remaining_bytes;
p_stream->m_byte_offset += (OPJ_OFF_T)l_remaining_bytes; p_stream->m_byte_offset += (OPJ_OFF_T)l_remaining_bytes;
} }
if (! opj_stream_flush(p_stream, p_event_mgr)) { if (! opj_stream_flush(p_stream, p_event_mgr)) {
return (OPJ_SIZE_T)-1; return (OPJ_SIZE_T)-1;
} }
} }
} }
OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_event_mgr) OPJ_BOOL opj_stream_flush (opj_stream_private_t * p_stream, opj_event_mgr_t * p_event_mgr)
{ {
/* the number of bytes written on the media. */ /* the number of bytes written on the media. */
OPJ_SIZE_T l_current_write_nb_bytes = 0; OPJ_SIZE_T l_current_write_nb_bytes = 0;
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
while (p_stream->m_bytes_in_buffer) { while (p_stream->m_bytes_in_buffer) {
/* we should do an actual write on the media */ /* we should do an actual write on the media */
l_current_write_nb_bytes = p_stream->m_write_fn(p_stream->m_current_data, l_current_write_nb_bytes = p_stream->m_write_fn(p_stream->m_current_data,
p_stream->m_bytes_in_buffer, p_stream->m_bytes_in_buffer,
p_stream->m_user_data); p_stream->m_user_data);
if (l_current_write_nb_bytes == (OPJ_SIZE_T)-1) { if (l_current_write_nb_bytes == (OPJ_SIZE_T)-1) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
opj_event_msg(p_event_mgr, EVT_INFO, "Error on writing stream!\n"); opj_event_msg(p_event_mgr, EVT_INFO, "Error on writing stream!\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
p_stream->m_current_data += l_current_write_nb_bytes; p_stream->m_current_data += l_current_write_nb_bytes;
p_stream->m_bytes_in_buffer -= l_current_write_nb_bytes; p_stream->m_bytes_in_buffer -= l_current_write_nb_bytes;
} }
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_OFF_T opj_stream_read_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
OPJ_OFF_T l_skip_nb_bytes = 0; OPJ_OFF_T l_skip_nb_bytes = 0;
OPJ_OFF_T l_current_skip_nb_bytes = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0;
assert( p_size >= 0 ); assert( p_size >= 0 );
if (p_stream->m_bytes_in_buffer >= (OPJ_SIZE_T)p_size) { if (p_stream->m_bytes_in_buffer >= (OPJ_SIZE_T)p_size) {
p_stream->m_current_data += p_size; p_stream->m_current_data += p_size;
/* it is safe to cast p_size to OPJ_SIZE_T since it is <= m_bytes_in_buffer /* it is safe to cast p_size to OPJ_SIZE_T since it is <= m_bytes_in_buffer
which is of type OPJ_SIZE_T */ which is of type OPJ_SIZE_T */
p_stream->m_bytes_in_buffer -= (OPJ_SIZE_T)p_size; p_stream->m_bytes_in_buffer -= (OPJ_SIZE_T)p_size;
l_skip_nb_bytes += p_size; l_skip_nb_bytes += p_size;
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes; return l_skip_nb_bytes;
} }
/* we are now in the case when the remaining data if not sufficient */ /* we are now in the case when the remaining data if not sufficient */
if (p_stream->m_status & OPJ_STREAM_STATUS_END) { if (p_stream->m_status & OPJ_STREAM_STATUS_END) {
l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_current_data += p_stream->m_bytes_in_buffer; p_stream->m_current_data += p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T) -1; return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T) -1;
} }
/* the flag is not set, we copy data and then do an actual skip on the stream */ /* the flag is not set, we copy data and then do an actual skip on the stream */
if (p_stream->m_bytes_in_buffer) { if (p_stream->m_bytes_in_buffer) {
l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; l_skip_nb_bytes += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_size -= (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_size -= (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} }
while (p_size > 0) { while (p_size > 0) {
/* we should do an actual skip on the media */ /* we should do an actual skip on the media */
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data); l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
if (l_current_skip_nb_bytes == (OPJ_OFF_T) -1) { if (l_current_skip_nb_bytes == (OPJ_OFF_T) -1) {
opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n"); opj_event_msg(p_event_mgr, EVT_INFO, "Stream reached its end !\n");
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
/* end if stream */ /* end if stream */
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T) -1; return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T) -1;
} }
p_size -= l_current_skip_nb_bytes; p_size -= l_current_skip_nb_bytes;
l_skip_nb_bytes += l_current_skip_nb_bytes; l_skip_nb_bytes += l_current_skip_nb_bytes;
} }
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes; return l_skip_nb_bytes;
} }
OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
OPJ_BOOL l_is_written = 0; OPJ_BOOL l_is_written = 0;
OPJ_OFF_T l_current_skip_nb_bytes = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0;
OPJ_OFF_T l_skip_nb_bytes = 0; OPJ_OFF_T l_skip_nb_bytes = 0;
if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) { if (p_stream->m_status & OPJ_STREAM_STATUS_ERROR) {
return (OPJ_OFF_T) -1; return (OPJ_OFF_T) -1;
} }
/* we should flush data */ /* we should flush data */
l_is_written = opj_stream_flush (p_stream, p_event_mgr); l_is_written = opj_stream_flush (p_stream, p_event_mgr);
if (! l_is_written) { if (! l_is_written) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
return (OPJ_OFF_T) -1; return (OPJ_OFF_T) -1;
} }
/* then skip */ /* then skip */
while (p_size > 0) { while (p_size > 0) {
/* we should do an actual skip on the media */ /* we should do an actual skip on the media */
l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data); l_current_skip_nb_bytes = p_stream->m_skip_fn(p_size, p_stream->m_user_data);
if (l_current_skip_nb_bytes == (OPJ_OFF_T)-1) { if (l_current_skip_nb_bytes == (OPJ_OFF_T)-1) {
opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n"); opj_event_msg(p_event_mgr, EVT_INFO, "Stream error!\n");
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
/* end if stream */ /* end if stream */
return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T)-1; return l_skip_nb_bytes ? l_skip_nb_bytes : (OPJ_OFF_T)-1;
} }
p_size -= l_current_skip_nb_bytes; p_size -= l_current_skip_nb_bytes;
l_skip_nb_bytes += l_current_skip_nb_bytes; l_skip_nb_bytes += l_current_skip_nb_bytes;
} }
p_stream->m_byte_offset += l_skip_nb_bytes; p_stream->m_byte_offset += l_skip_nb_bytes;
return l_skip_nb_bytes; return l_skip_nb_bytes;
} }
OPJ_OFF_T opj_stream_tell (const opj_stream_private_t * p_stream) OPJ_OFF_T opj_stream_tell (const opj_stream_private_t * p_stream)
{ {
return p_stream->m_byte_offset; return p_stream->m_byte_offset;
} }
OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream) OPJ_OFF_T opj_stream_get_number_byte_left (const opj_stream_private_t * p_stream)
{ {
assert( p_stream->m_byte_offset >= 0 ); assert( p_stream->m_byte_offset >= 0 );
assert( p_stream->m_user_data_length >= (OPJ_UINT64)p_stream->m_byte_offset); assert( p_stream->m_user_data_length >= (OPJ_UINT64)p_stream->m_byte_offset);
return p_stream->m_user_data_length ? return p_stream->m_user_data_length ?
(OPJ_OFF_T)(p_stream->m_user_data_length) - p_stream->m_byte_offset : (OPJ_OFF_T)(p_stream->m_user_data_length) - p_stream->m_byte_offset :
0; 0;
} }
OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_OFF_T opj_stream_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
assert(p_size >= 0); assert(p_size >= 0);
return p_stream->m_opj_skip(p_stream,p_size,p_event_mgr); return p_stream->m_opj_skip(p_stream,p_size,p_event_mgr);
} }
OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
OPJ_ARG_NOT_USED(p_event_mgr); OPJ_ARG_NOT_USED(p_event_mgr);
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) { if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) {
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else { /* reset stream status */
/* reset stream status */ p_stream->m_status &= (~OPJ_STREAM_STATUS_END);
p_stream->m_status &= (~OPJ_STREAM_STATUS_END); p_stream->m_byte_offset = p_size;
p_stream->m_byte_offset = p_size;
} }
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr)
{ {
if (! opj_stream_flush(p_stream,p_event_mgr)) { if (! opj_stream_flush(p_stream,p_event_mgr)) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
return OPJ_FALSE; return OPJ_FALSE;
} }
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) { if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else { p_stream->m_byte_offset = p_size;
p_stream->m_byte_offset = p_size; }
}
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_BOOL opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr) OPJ_BOOL opj_stream_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr)
{ {
assert(p_size >= 0); assert(p_size >= 0);
return p_stream->m_opj_seek(p_stream,p_size,p_event_mgr); return p_stream->m_opj_seek(p_stream,p_size,p_event_mgr);
} }
OPJ_BOOL opj_stream_has_seek (const opj_stream_private_t * p_stream) OPJ_BOOL opj_stream_has_seek (const opj_stream_private_t * p_stream)
{ {
return p_stream->m_seek_fn != opj_stream_default_seek; return p_stream->m_seek_fn != opj_stream_default_seek;
} }
OPJ_SIZE_T opj_stream_default_read (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) OPJ_SIZE_T opj_stream_default_read (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
{ {
OPJ_ARG_NOT_USED(p_buffer); OPJ_ARG_NOT_USED(p_buffer);
OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_nb_bytes);
OPJ_ARG_NOT_USED(p_user_data); OPJ_ARG_NOT_USED(p_user_data);
return (OPJ_SIZE_T) -1; return (OPJ_SIZE_T) -1;
} }
OPJ_SIZE_T opj_stream_default_write (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) OPJ_SIZE_T opj_stream_default_write (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
{ {
OPJ_ARG_NOT_USED(p_buffer); OPJ_ARG_NOT_USED(p_buffer);
OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_nb_bytes);
OPJ_ARG_NOT_USED(p_user_data); OPJ_ARG_NOT_USED(p_user_data);
return (OPJ_SIZE_T) -1; return (OPJ_SIZE_T) -1;
} }
OPJ_OFF_T opj_stream_default_skip (OPJ_OFF_T p_nb_bytes, void * p_user_data) OPJ_OFF_T opj_stream_default_skip (OPJ_OFF_T p_nb_bytes, void * p_user_data)
{ {
OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_nb_bytes);
OPJ_ARG_NOT_USED(p_user_data); OPJ_ARG_NOT_USED(p_user_data);
return (OPJ_OFF_T) -1; return (OPJ_OFF_T) -1;
} }
OPJ_BOOL opj_stream_default_seek (OPJ_OFF_T p_nb_bytes, void * p_user_data) OPJ_BOOL opj_stream_default_seek (OPJ_OFF_T p_nb_bytes, void * p_user_data)
{ {
OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_nb_bytes);
OPJ_ARG_NOT_USED(p_user_data); OPJ_ARG_NOT_USED(p_user_data);
return OPJ_FALSE; return OPJ_FALSE;
} }

View File

@ -54,19 +54,19 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
#if defined(OPJ_BIG_ENDIAN) #if defined(OPJ_BIG_ENDIAN)
#define opj_write_bytes opj_write_bytes_BE #define opj_write_bytes opj_write_bytes_BE
#define opj_read_bytes opj_read_bytes_BE #define opj_read_bytes opj_read_bytes_BE
#define opj_write_double opj_write_double_BE #define opj_write_double opj_write_double_BE
#define opj_read_double opj_read_double_BE #define opj_read_double opj_read_double_BE
#define opj_write_float opj_write_float_BE #define opj_write_float opj_write_float_BE
#define opj_read_float opj_read_float_BE #define opj_read_float opj_read_float_BE
#else #else
#define opj_write_bytes opj_write_bytes_LE #define opj_write_bytes opj_write_bytes_LE
#define opj_read_bytes opj_read_bytes_LE #define opj_read_bytes opj_read_bytes_LE
#define opj_write_double opj_write_double_LE #define opj_write_double opj_write_double_LE
#define opj_read_double opj_read_double_LE #define opj_read_double opj_read_double_LE
#define opj_write_float opj_write_float_LE #define opj_write_float opj_write_float_LE
#define opj_read_float opj_read_float_LE #define opj_read_float opj_read_float_LE
#endif #endif
@ -78,87 +78,86 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/** /**
Byte input-output stream. Byte input-output stream.
*/ */
typedef struct opj_stream_private typedef struct opj_stream_private {
{ /**
/** * User data, be it files, ... The actual data depends on the type of the stream.
* User data, be it files, ... The actual data depends on the type of the stream. */
*/ void * m_user_data;
void * m_user_data;
/** /**
* Pointer to function to free m_user_data (NULL at initialization) * Pointer to function to free m_user_data (NULL at initialization)
* when destroying the stream. If pointer is NULL the function is not * when destroying the stream. If pointer is NULL the function is not
* called and the m_user_data is not freed (even if non-NULL). * called and the m_user_data is not freed (even if non-NULL).
*/ */
opj_stream_free_user_data_fn m_free_user_data_fn; opj_stream_free_user_data_fn m_free_user_data_fn;
/** /**
* User data length * User data length
*/ */
OPJ_UINT64 m_user_data_length; OPJ_UINT64 m_user_data_length;
/** /**
* Pointer to actual read function (NULL at the initialization of the cio. * Pointer to actual read function (NULL at the initialization of the cio.
*/ */
opj_stream_read_fn m_read_fn; opj_stream_read_fn m_read_fn;
/** /**
* Pointer to actual write function (NULL at the initialization of the cio. * Pointer to actual write function (NULL at the initialization of the cio.
*/ */
opj_stream_write_fn m_write_fn; opj_stream_write_fn m_write_fn;
/** /**
* Pointer to actual skip function (NULL at the initialization of the cio. * Pointer to actual skip function (NULL at the initialization of the cio.
* There is no seek function to prevent from back and forth slow procedures. * There is no seek function to prevent from back and forth slow procedures.
*/ */
opj_stream_skip_fn m_skip_fn; opj_stream_skip_fn m_skip_fn;
/** /**
* Pointer to actual seek function (if available). * Pointer to actual seek function (if available).
*/ */
opj_stream_seek_fn m_seek_fn; opj_stream_seek_fn m_seek_fn;
/** /**
* Actual data stored into the stream if readed from. Data is read by chunk of fixed size. * Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
* you should never access this data directly. * you should never access this data directly.
*/ */
OPJ_BYTE * m_stored_data; OPJ_BYTE * m_stored_data;
/** /**
* Pointer to the current read data. * Pointer to the current read data.
*/ */
OPJ_BYTE * m_current_data; OPJ_BYTE * m_current_data;
/** /**
* FIXME DOC. * FIXME DOC.
*/ */
OPJ_OFF_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_OFF_T , struct opj_event_mgr *); OPJ_OFF_T (* m_opj_skip)(struct opj_stream_private * ,OPJ_OFF_T , struct opj_event_mgr *);
/** /**
* FIXME DOC. * FIXME DOC.
*/ */
OPJ_BOOL (* m_opj_seek) (struct opj_stream_private * , OPJ_OFF_T , struct opj_event_mgr *); OPJ_BOOL (* m_opj_seek) (struct opj_stream_private * , OPJ_OFF_T , struct opj_event_mgr *);
/** /**
* number of bytes containing in the buffer. * number of bytes containing in the buffer.
*/ */
OPJ_SIZE_T m_bytes_in_buffer; OPJ_SIZE_T m_bytes_in_buffer;
/** /**
* The number of bytes read/written from the beginning of the stream * The number of bytes read/written from the beginning of the stream
*/ */
OPJ_OFF_T m_byte_offset; OPJ_OFF_T m_byte_offset;
/** /**
* The size of the buffer. * The size of the buffer.
*/ */
OPJ_SIZE_T m_buffer_size; OPJ_SIZE_T m_buffer_size;
/** /**
* Flags to tell the status of the stream. * Flags to tell the status of the stream.
* Used with OPJ_STREAM_STATUS_* defines. * Used with OPJ_STREAM_STATUS_* defines.
*/ */
OPJ_UINT32 m_status; OPJ_UINT32 m_status;
} }
opj_stream_private_t; opj_stream_private_t;

File diff suppressed because it is too large Load Diff

View File

@ -40,10 +40,11 @@
#ifdef OPJ_CODE_NOT_USED #ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32 #ifndef _WIN32
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r)
if (i/r > 0) a = i2a(i/r,a,r); {
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; if (i/r > 0) a = i2a(i/r,a,r);
return a+1; *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
} }
/** /**
@ -55,14 +56,14 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a @return Returns a
*/ */
static char * static char *
_itoa(int i, char *a, int r) { _itoa(int i, char *a, int r)
r = ((r < 2) || (r > 36)) ? 10 : r; {
if(i < 0) { r = ((r < 2) || (r > 36)) ? 10 : r;
*a = '-'; if(i < 0) {
*i2a(-i, a+1, r) = 0; *a = '-';
} *i2a(-i, a+1, r) = 0;
else *i2a(i, a, r) = 0; } else *i2a(i, a, r) = 0;
return a; return a;
} }
#endif /* !_WIN32 */ #endif /* !_WIN32 */
@ -83,64 +84,65 @@ static void opj_default_callback (const char *msg, void *client_data)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) { OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...)
{
#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = 00; opj_msg_callback msg_handler = 00;
void * l_data = 00; void * l_data = 00;
if(p_event_mgr != 00) { if(p_event_mgr != 00) {
switch(event_type) { switch(event_type) {
case EVT_ERROR: case EVT_ERROR:
msg_handler = p_event_mgr->error_handler; msg_handler = p_event_mgr->error_handler;
l_data = p_event_mgr->m_error_data; l_data = p_event_mgr->m_error_data;
break; break;
case EVT_WARNING: case EVT_WARNING:
msg_handler = p_event_mgr->warning_handler; msg_handler = p_event_mgr->warning_handler;
l_data = p_event_mgr->m_warning_data; l_data = p_event_mgr->m_warning_data;
break; break;
case EVT_INFO: case EVT_INFO:
msg_handler = p_event_mgr->info_handler; msg_handler = p_event_mgr->info_handler;
l_data = p_event_mgr->m_info_data; l_data = p_event_mgr->m_info_data;
break; break;
default: default:
break; break;
} }
if(msg_handler == 00) { if(msg_handler == 00) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} else { } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
if ((fmt != 00) && (p_event_mgr != 00)) { if ((fmt != 00) && (p_event_mgr != 00)) {
va_list arg; va_list arg;
size_t str_length/*, i, j*/; /* UniPG */ size_t str_length/*, i, j*/; /* UniPG */
char message[OPJ_MSG_SIZE]; char message[OPJ_MSG_SIZE];
memset(message, 0, OPJ_MSG_SIZE); memset(message, 0, OPJ_MSG_SIZE);
/* initialize the optional parameter list */ /* initialize the optional parameter list */
va_start(arg, fmt); va_start(arg, fmt);
/* check the length of the format string */ /* check the length of the format string */
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt); str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
(void)str_length; (void)str_length;
/* parse the format string and put the result in 'message' */ /* parse the format string and put the result in 'message' */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */ vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */ /* deinitialize the optional parameter list */
va_end(arg); va_end(arg);
/* output the message to the user program */ /* output the message to the user program */
msg_handler(message, l_data); msg_handler(message, l_data);
} }
return OPJ_TRUE; return OPJ_TRUE;
} }
void opj_set_default_event_handler(opj_event_mgr_t * p_manager) void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
{ {
p_manager->m_error_data = 00; p_manager->m_error_data = 00;
p_manager->m_warning_data = 00; p_manager->m_warning_data = 00;
p_manager->m_info_data = 00; p_manager->m_info_data = 00;
p_manager->error_handler = opj_default_callback; p_manager->error_handler = opj_default_callback;
p_manager->info_handler = opj_default_callback; p_manager->info_handler = opj_default_callback;
p_manager->warning_handler = opj_default_callback; p_manager->warning_handler = opj_default_callback;
} }

View File

@ -47,20 +47,19 @@ used for
<li>Debugging messages <li>Debugging messages
</ul> </ul>
*/ */
typedef struct opj_event_mgr typedef struct opj_event_mgr {
{ /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_error_data;
void * m_error_data; /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_warning_data;
void * m_warning_data; /** Data to call the event manager upon */
/** Data to call the event manager upon */ void * m_info_data;
void * m_info_data; /** Error message callback if available, NULL otherwise */
/** Error message callback if available, NULL otherwise */ opj_msg_callback error_handler;
opj_msg_callback error_handler; /** Warning message callback if available, NULL otherwise */
/** Warning message callback if available, NULL otherwise */ opj_msg_callback warning_handler;
opj_msg_callback warning_handler; /** Debug message callback if available, NULL otherwise */
/** Debug message callback if available, NULL otherwise */ opj_msg_callback info_handler;
opj_msg_callback info_handler;
} opj_event_mgr_t; } opj_event_mgr_t;

View File

@ -38,80 +38,72 @@
opj_procedure_list_t * opj_procedure_list_create() opj_procedure_list_t * opj_procedure_list_create()
{ {
/* memory allocation */ /* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t)); opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation) if (! l_validation) {
{ return 00;
return 00; }
} /* initialization */
/* initialization */ l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE; l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure)); if (! l_validation->m_procedures) {
if (! l_validation->m_procedures) opj_free(l_validation);
{ return 00;
opj_free(l_validation); }
return 00; return l_validation;
}
return l_validation;
} }
void opj_procedure_list_destroy(opj_procedure_list_t * p_list) void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{ {
if (! p_list) if (! p_list) {
{ return;
return; }
} /* initialization */
/* initialization */ if (p_list->m_procedures) {
if (p_list->m_procedures) opj_free(p_list->m_procedures);
{ }
opj_free(p_list->m_procedures); opj_free(p_list);
}
opj_free(p_list);
} }
OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager ) OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager )
{ {
assert(p_manager != NULL); assert(p_manager != NULL);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) {
{ opj_procedure * new_procedures;
opj_procedure * new_procedures;
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE; p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
new_procedures = (opj_procedure*)opj_realloc( new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures, p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure)); p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures) if (! new_procedures) {
{ opj_free(p_validation_list->m_procedures);
opj_free(p_validation_list->m_procedures); p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_max_procedures = 0; p_validation_list->m_nb_procedures = 0;
p_validation_list->m_nb_procedures = 0; opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); return OPJ_FALSE;
return OPJ_FALSE; } else {
} p_validation_list->m_procedures = new_procedures;
else
{
p_validation_list->m_procedures = new_procedures;
}
} }
p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure; }
++p_validation_list->m_nb_procedures; p_validation_list->m_procedures[p_validation_list->m_nb_procedures] = p_procedure;
++p_validation_list->m_nb_procedures;
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list) OPJ_UINT32 opj_procedure_list_get_nb_procedures (opj_procedure_list_t * p_validation_list)
{ {
return p_validation_list->m_nb_procedures; return p_validation_list->m_nb_procedures;
} }
opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list) opj_procedure* opj_procedure_list_get_first_procedure (opj_procedure_list_t * p_validation_list)
{ {
return p_validation_list->m_procedures; return p_validation_list->m_procedures;
} }
void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list) void opj_procedure_list_clear (opj_procedure_list_t * p_validation_list)
{ {
p_validation_list->m_nb_procedures = 0; p_validation_list->m_nb_procedures = 0;
} }

View File

@ -54,20 +54,19 @@ typedef void (*opj_procedure)(void);
/** /**
* A list of procedures. * A list of procedures.
*/ */
typedef struct opj_procedure_list typedef struct opj_procedure_list {
{ /**
/** * The number of validation procedures.
* The number of validation procedures. */
*/ OPJ_UINT32 m_nb_procedures;
OPJ_UINT32 m_nb_procedures; /**
/** * The number of the array of validation procedures.
* The number of the array of validation procedures. */
*/ OPJ_UINT32 m_nb_max_procedures;
OPJ_UINT32 m_nb_max_procedures; /**
/** * The array of procedures.
* The array of procedures. */
*/ opj_procedure * m_procedures;
opj_procedure * m_procedures;
} opj_procedure_list_t; } opj_procedure_list_t;

View File

@ -31,73 +31,76 @@
#include "opj_includes.h" #include "opj_includes.h"
opj_image_t* opj_image_create0(void) { opj_image_t* opj_image_create0(void)
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); {
return image; opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
return image;
} }
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
OPJ_UINT32 compno; {
opj_image_t *image = NULL; OPJ_UINT32 compno;
opj_image_t *image = NULL;
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
if(image) { if(image) {
image->color_space = clrspc; image->color_space = clrspc;
image->numcomps = numcmpts; image->numcomps = numcmpts;
/* allocate memory for the per-component information */ /* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t)); image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) { if(!image->comps) {
/* TODO replace with event manager, breaks API */ /* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }
/* create the individual image components */ /* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) { for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno]; opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx; comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy; comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w; comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h; comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0; comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0; comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec; comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp; comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd; comp->sgnd = cmptparms[compno].sgnd;
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32)); comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
if(!comp->data) { if(!comp->data) {
/* TODO replace with event manager, breaks API */ /* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image); opj_image_destroy(image);
return NULL; return NULL;
} }
} }
} }
return image; return image;
} }
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
if(image) { {
if(image->comps) { if(image) {
OPJ_UINT32 compno; if(image->comps) {
OPJ_UINT32 compno;
/* image components */ /* image components */
for(compno = 0; compno < image->numcomps; compno++) { for(compno = 0; compno < image->numcomps; compno++) {
opj_image_comp_t *image_comp = &(image->comps[compno]); opj_image_comp_t *image_comp = &(image->comps[compno]);
if(image_comp->data) { if(image_comp->data) {
opj_free(image_comp->data); opj_free(image_comp->data);
} }
} }
opj_free(image->comps); opj_free(image->comps);
} }
if(image->icc_profile_buf) { if(image->icc_profile_buf) {
opj_free(image->icc_profile_buf); opj_free(image->icc_profile_buf);
} }
opj_free(image); opj_free(image);
} }
} }
/** /**
@ -108,32 +111,32 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
*/ */
void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp) void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp)
{ {
OPJ_UINT32 i, l_width, l_height; OPJ_UINT32 i, l_width, l_height;
OPJ_UINT32 l_x0, l_y0, l_x1, l_y1; OPJ_UINT32 l_x0, l_y0, l_x1, l_y1;
OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1; OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
opj_image_comp_t* l_img_comp = NULL; opj_image_comp_t* l_img_comp = NULL;
l_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0); l_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0);
l_y0 = opj_uint_max(p_cp->ty0 , p_image_header->y0); l_y0 = opj_uint_max(p_cp->ty0 , p_image_header->y0);
l_x1 = p_cp->tx0 + (p_cp->tw - 1U) * p_cp->tdx; /* validity of p_cp members used here checked in opj_j2k_read_siz. Can't overflow. */ l_x1 = p_cp->tx0 + (p_cp->tw - 1U) * p_cp->tdx; /* validity of p_cp members used here checked in opj_j2k_read_siz. Can't overflow. */
l_y1 = p_cp->ty0 + (p_cp->th - 1U) * p_cp->tdy; /* can't overflow */ l_y1 = p_cp->ty0 + (p_cp->th - 1U) * p_cp->tdy; /* can't overflow */
l_x1 = opj_uint_min(opj_uint_adds(l_x1, p_cp->tdx), p_image_header->x1); /* use add saturated to prevent overflow */ l_x1 = opj_uint_min(opj_uint_adds(l_x1, p_cp->tdx), p_image_header->x1); /* use add saturated to prevent overflow */
l_y1 = opj_uint_min(opj_uint_adds(l_y1, p_cp->tdy), p_image_header->y1); /* use add saturated to prevent overflow */ l_y1 = opj_uint_min(opj_uint_adds(l_y1, p_cp->tdy), p_image_header->y1); /* use add saturated to prevent overflow */
l_img_comp = p_image_header->comps; l_img_comp = p_image_header->comps;
for (i = 0; i < p_image_header->numcomps; ++i) { for (i = 0; i < p_image_header->numcomps; ++i) {
l_comp_x0 = opj_uint_ceildiv(l_x0, l_img_comp->dx); l_comp_x0 = opj_uint_ceildiv(l_x0, l_img_comp->dx);
l_comp_y0 = opj_uint_ceildiv(l_y0, l_img_comp->dy); l_comp_y0 = opj_uint_ceildiv(l_y0, l_img_comp->dy);
l_comp_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx); l_comp_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx);
l_comp_y1 = opj_uint_ceildiv(l_y1, l_img_comp->dy); l_comp_y1 = opj_uint_ceildiv(l_y1, l_img_comp->dy);
l_width = opj_uint_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor); l_width = opj_uint_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor);
l_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor); l_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_img_comp->w = l_width; l_img_comp->w = l_width;
l_img_comp->h = l_height; l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0; l_img_comp->x0 = l_comp_x0;
l_img_comp->y0 = l_comp_y0; l_img_comp->y0 = l_comp_y0;
++l_img_comp; ++l_img_comp;
} }
} }
@ -147,96 +150,95 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj
*/ */
void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest) void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_dest)
{ {
OPJ_UINT32 compno; OPJ_UINT32 compno;
/* preconditions */ /* preconditions */
assert(p_image_src != 00); assert(p_image_src != 00);
assert(p_image_dest != 00); assert(p_image_dest != 00);
p_image_dest->x0 = p_image_src->x0; p_image_dest->x0 = p_image_src->x0;
p_image_dest->y0 = p_image_src->y0; p_image_dest->y0 = p_image_src->y0;
p_image_dest->x1 = p_image_src->x1; p_image_dest->x1 = p_image_src->x1;
p_image_dest->y1 = p_image_src->y1; p_image_dest->y1 = p_image_src->y1;
if (p_image_dest->comps){ if (p_image_dest->comps) {
for(compno = 0; compno < p_image_dest->numcomps; compno++) { for(compno = 0; compno < p_image_dest->numcomps; compno++) {
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]); opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
if(image_comp->data) { if(image_comp->data) {
opj_free(image_comp->data); opj_free(image_comp->data);
} }
} }
opj_free(p_image_dest->comps); opj_free(p_image_dest->comps);
p_image_dest->comps = NULL; p_image_dest->comps = NULL;
} }
p_image_dest->numcomps = p_image_src->numcomps; p_image_dest->numcomps = p_image_src->numcomps;
p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t)); p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
if (!p_image_dest->comps){ if (!p_image_dest->comps) {
p_image_dest->comps = NULL; p_image_dest->comps = NULL;
p_image_dest->numcomps = 0; p_image_dest->numcomps = 0;
return; return;
} }
for (compno=0; compno < p_image_dest->numcomps; compno++){ for (compno=0; compno < p_image_dest->numcomps; compno++) {
memcpy( &(p_image_dest->comps[compno]), memcpy( &(p_image_dest->comps[compno]),
&(p_image_src->comps[compno]), &(p_image_src->comps[compno]),
sizeof(opj_image_comp_t)); sizeof(opj_image_comp_t));
p_image_dest->comps[compno].data = NULL; p_image_dest->comps[compno].data = NULL;
} }
p_image_dest->color_space = p_image_src->color_space; p_image_dest->color_space = p_image_src->color_space;
p_image_dest->icc_profile_len = p_image_src->icc_profile_len; p_image_dest->icc_profile_len = p_image_src->icc_profile_len;
if (p_image_dest->icc_profile_len) { if (p_image_dest->icc_profile_len) {
p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len); p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len);
if (!p_image_dest->icc_profile_buf){ if (!p_image_dest->icc_profile_buf) {
p_image_dest->icc_profile_buf = NULL; p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_len = 0; p_image_dest->icc_profile_len = 0;
return; return;
} }
memcpy( p_image_dest->icc_profile_buf, memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf, p_image_src->icc_profile_buf,
p_image_src->icc_profile_len); p_image_src->icc_profile_len);
} } else
else p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_buf = NULL;
return; return;
} }
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
OPJ_UINT32 compno; {
opj_image_t *image = 00; OPJ_UINT32 compno;
opj_image_t *image = 00;
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t)); image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image) if (image) {
{
image->color_space = clrspc; image->color_space = clrspc;
image->numcomps = numcmpts; image->numcomps = numcmpts;
/* allocate memory for the per-component information */ /* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t)); image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) { if (!image->comps) {
opj_image_destroy(image); opj_image_destroy(image);
return 00; return 00;
} }
/* create the individual image components */ /* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) { for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno]; opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx; comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy; comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w; comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h; comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0; comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0; comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec; comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd; comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0; comp->data = 0;
} }
} }
return image; return image;
} }

View File

@ -66,7 +66,7 @@
* @return length of tpix box * @return length of tpix box
*/ */
int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio, int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
@ -91,7 +91,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
* @return length of ppix box * @return length of ppix box
*/ */
int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
@ -105,7 +105,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
* @return length of ppix box * @return length of ppix box
*/ */
int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write manifest box (box) * Write manifest box (box)
@ -131,18 +131,18 @@ void opj_write_manf(int second,
* @return length of mainmhix box * @return length of mainmhix box
*/ */
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio, int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
int opj_write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio, int opj_write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
#endif /* !INDEXBOX_MANAGER_H_ */ #endif /* !INDEXBOX_MANAGER_H_ */

View File

@ -71,28 +71,28 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo) OPJ_UINT32 nb_compo)
{ {
OPJ_BYTE * l_data = 00; OPJ_BYTE * l_data = 00;
OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32); OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32);
OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size; OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size;
OPJ_UINT32 * lPermutations = 00; OPJ_UINT32 * lPermutations = 00;
OPJ_FLOAT32 * l_double_data = 00; OPJ_FLOAT32 * l_double_data = 00;
l_data = (OPJ_BYTE *) opj_malloc(l_total_size); l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
if (l_data == 0) { if (l_data == 0) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lPermutations = (OPJ_UINT32 *) l_data; lPermutations = (OPJ_UINT32 *) l_data;
l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size); l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size);
memset(lPermutations,0,l_permutation_size); memset(lPermutations,0,l_permutation_size);
if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) { if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) {
opj_free(l_data); opj_free(l_data);
return OPJ_FALSE; return OPJ_FALSE;
} }
opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo); opj_lupInvert(pSrcMatrix,pDestMatrix,nb_compo,lPermutations,l_double_data,l_double_data + nb_compo,l_double_data + 2*nb_compo);
opj_free(l_data); opj_free(l_data);
return OPJ_TRUE; return OPJ_TRUE;
} }
@ -104,191 +104,189 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area, OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo) OPJ_UINT32 nb_compo)
{ {
OPJ_UINT32 * tmpPermutations = permutations; OPJ_UINT32 * tmpPermutations = permutations;
OPJ_UINT32 * dstPermutations; OPJ_UINT32 * dstPermutations;
OPJ_UINT32 k2=0,t; OPJ_UINT32 k2=0,t;
OPJ_FLOAT32 temp; OPJ_FLOAT32 temp;
OPJ_UINT32 i,j,k; OPJ_UINT32 i,j,k;
OPJ_FLOAT32 p; OPJ_FLOAT32 p;
OPJ_UINT32 lLastColum = nb_compo - 1; OPJ_UINT32 lLastColum = nb_compo - 1;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpMatrix = matrix; OPJ_FLOAT32 * lTmpMatrix = matrix;
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix; OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
OPJ_UINT32 offset = 1; OPJ_UINT32 offset = 1;
OPJ_UINT32 lStride = nb_compo-1; OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */ /*initialize permutations */
for (i = 0; i < nb_compo; ++i) for (i = 0; i < nb_compo; ++i) {
{ *tmpPermutations++ = i;
*tmpPermutations++ = i; }
} /* now make a pivot with column switch */
/* now make a pivot with column switch */ tmpPermutations = permutations;
tmpPermutations = permutations; for (k = 0; k < lLastColum; ++k) {
for (k = 0; k < lLastColum; ++k) { p = 0.0;
p = 0.0;
/* take the middle element */ /* take the middle element */
lColumnMatrix = lTmpMatrix + k; lColumnMatrix = lTmpMatrix + k;
/* make permutation with the biggest value in the column */ /* make permutation with the biggest value in the column */
for (i = k; i < nb_compo; ++i) { for (i = k; i < nb_compo; ++i) {
temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix)); temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix));
if (temp > p) { if (temp > p) {
p = temp; p = temp;
k2 = i; k2 = i;
} }
/* next line */ /* next line */
lColumnMatrix += nb_compo; lColumnMatrix += nb_compo;
} }
/* a whole rest of 0 -> non singular */ /* a whole rest of 0 -> non singular */
if (p == 0.0) { if (p == 0.0) {
return OPJ_FALSE; return OPJ_FALSE;
} }
/* should we permute ? */ /* should we permute ? */
if (k2 != k) { if (k2 != k) {
/*exchange of line */ /*exchange of line */
/* k2 > k */ /* k2 > k */
dstPermutations = tmpPermutations + k2 - k; dstPermutations = tmpPermutations + k2 - k;
/* swap indices */ /* swap indices */
t = *tmpPermutations; t = *tmpPermutations;
*tmpPermutations = *dstPermutations; *tmpPermutations = *dstPermutations;
*dstPermutations = t; *dstPermutations = t;
/* and swap entire line. */ /* and swap entire line. */
lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo; lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo;
memcpy(p_swap_area,lColumnMatrix,lSwapSize); memcpy(p_swap_area,lColumnMatrix,lSwapSize);
memcpy(lColumnMatrix,lTmpMatrix,lSwapSize); memcpy(lColumnMatrix,lTmpMatrix,lSwapSize);
memcpy(lTmpMatrix,p_swap_area,lSwapSize); memcpy(lTmpMatrix,p_swap_area,lSwapSize);
} }
/* now update data in the rest of the line and line after */ /* now update data in the rest of the line and line after */
lDestMatrix = lTmpMatrix + k; lDestMatrix = lTmpMatrix + k;
lColumnMatrix = lDestMatrix + nb_compo; lColumnMatrix = lDestMatrix + nb_compo;
/* take the middle element */ /* take the middle element */
temp = *(lDestMatrix++); temp = *(lDestMatrix++);
/* now compute up data (i.e. coeff up of the diagonal). */ /* now compute up data (i.e. coeff up of the diagonal). */
for (i = offset; i < nb_compo; ++i) { for (i = offset; i < nb_compo; ++i) {
/*lColumnMatrix; */ /*lColumnMatrix; */
/* divide the lower column elements by the diagonal value */ /* divide the lower column elements by the diagonal value */
/* matrix[i][k] /= matrix[k][k]; */ /* matrix[i][k] /= matrix[k][k]; */
/* p = matrix[i][k] */ /* p = matrix[i][k] */
p = *lColumnMatrix / temp; p = *lColumnMatrix / temp;
*(lColumnMatrix++) = p; *(lColumnMatrix++) = p;
for (j = /* k + 1 */ offset; j < nb_compo; ++j) { for (j = /* k + 1 */ offset; j < nb_compo; ++j) {
/* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */ /* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */
*(lColumnMatrix++) -= p * (*(lDestMatrix++)); *(lColumnMatrix++) -= p * (*(lDestMatrix++));
} }
/* come back to the k+1th element */ /* come back to the k+1th element */
lDestMatrix -= lStride; lDestMatrix -= lStride;
/* go to kth element of the next line */ /* go to kth element of the next line */
lColumnMatrix += k; lColumnMatrix += k;
} }
/* offset is now k+2 */ /* offset is now k+2 */
++offset; ++offset;
/* 1 element less for stride */ /* 1 element less for stride */
--lStride; --lStride;
/* next line */ /* next line */
lTmpMatrix+=nb_compo; lTmpMatrix+=nb_compo;
/* next permutation element */ /* next permutation element */
++tmpPermutations; ++tmpPermutations;
} }
return OPJ_TRUE; return OPJ_TRUE;
} }
static void opj_lupSolve (OPJ_FLOAT32 * pResult, static void opj_lupSolve (OPJ_FLOAT32 * pResult,
OPJ_FLOAT32 * pMatrix, OPJ_FLOAT32 * pMatrix,
OPJ_FLOAT32 * pVector, OPJ_FLOAT32 * pVector,
OPJ_UINT32* pPermutations, OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data) OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data)
{ {
OPJ_INT32 k; OPJ_INT32 k;
OPJ_UINT32 i,j; OPJ_UINT32 i,j;
OPJ_FLOAT32 sum; OPJ_FLOAT32 sum;
OPJ_FLOAT32 u; OPJ_FLOAT32 u;
OPJ_UINT32 lStride = nb_compo+1; OPJ_UINT32 lStride = nb_compo+1;
OPJ_FLOAT32 * lCurrentPtr; OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lIntermediatePtr; OPJ_FLOAT32 * lIntermediatePtr;
OPJ_FLOAT32 * lDestPtr; OPJ_FLOAT32 * lDestPtr;
OPJ_FLOAT32 * lTmpMatrix; OPJ_FLOAT32 * lTmpMatrix;
OPJ_FLOAT32 * lLineMatrix = pMatrix; OPJ_FLOAT32 * lLineMatrix = pMatrix;
OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1; OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1;
OPJ_FLOAT32 * lGeneratedData; OPJ_FLOAT32 * lGeneratedData;
OPJ_UINT32 * lCurrentPermutationPtr = pPermutations; OPJ_UINT32 * lCurrentPermutationPtr = pPermutations;
lIntermediatePtr = p_intermediate_data; lIntermediatePtr = p_intermediate_data;
lGeneratedData = p_intermediate_data + nb_compo - 1; lGeneratedData = p_intermediate_data + nb_compo - 1;
for (i = 0; i < nb_compo; ++i) { for (i = 0; i < nb_compo; ++i) {
sum = 0.0; sum = 0.0;
lCurrentPtr = p_intermediate_data; lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix; lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j) for (j = 1; j <= i; ++j) {
{ /* sum += matrix[i][j-1] * y[j-1]; */
/* sum += matrix[i][j-1] * y[j-1]; */ sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
} }
/*y[i] = pVector[pPermutations[i]] - sum; */ /*y[i] = pVector[pPermutations[i]] - sum; */
*(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum; *(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum;
lLineMatrix += nb_compo; lLineMatrix += nb_compo;
} }
/* we take the last point of the matrix */ /* we take the last point of the matrix */
lLineMatrix = pMatrix + nb_compo*nb_compo - 1; lLineMatrix = pMatrix + nb_compo*nb_compo - 1;
/* and we take after the last point of the destination vector */ /* and we take after the last point of the destination vector */
lDestPtr = pResult + nb_compo; lDestPtr = pResult + nb_compo;
assert(nb_compo != 0); assert(nb_compo != 0);
for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) { for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) {
sum = 0.0; sum = 0.0;
lTmpMatrix = lLineMatrix; lTmpMatrix = lLineMatrix;
u = *(lTmpMatrix++); u = *(lTmpMatrix++);
lCurrentPtr = lDestPtr--; lCurrentPtr = lDestPtr--;
for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) { for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) {
/* sum += matrix[k][j] * x[j] */ /* sum += matrix[k][j] * x[j] */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++)); sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
} }
/*x[k] = (y[k] - sum) / u; */ /*x[k] = (y[k] - sum) / u; */
*(lBeginPtr--) = (*(lGeneratedData--) - sum) / u; *(lBeginPtr--) = (*(lGeneratedData--) - sum) / u;
lLineMatrix -= lStride; lLineMatrix -= lStride;
} }
} }
static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix, static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo, OPJ_UINT32 nb_compo,
OPJ_UINT32 * pPermutations, OPJ_UINT32 * pPermutations,
OPJ_FLOAT32 * p_src_temp, OPJ_FLOAT32 * p_src_temp,
OPJ_FLOAT32 * p_dest_temp, OPJ_FLOAT32 * p_dest_temp,
OPJ_FLOAT32 * p_swap_area ) OPJ_FLOAT32 * p_swap_area )
{ {
OPJ_UINT32 j,i; OPJ_UINT32 j,i;
OPJ_FLOAT32 * lCurrentPtr; OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lLineMatrix = pDestMatrix; OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
for (j = 0; j < nb_compo; ++j) { for (j = 0; j < nb_compo; ++j) {
lCurrentPtr = lLineMatrix++; lCurrentPtr = lLineMatrix++;
memset(p_src_temp,0,lSwapSize); memset(p_src_temp,0,lSwapSize);
p_src_temp[j] = 1.0; p_src_temp[j] = 1.0;
opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area); opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area);
for (i = 0; i < nb_compo; ++i) { for (i = 0; i < nb_compo; ++i) {
*(lCurrentPtr) = p_dest_temp[i]; *(lCurrentPtr) = p_dest_temp[i];
lCurrentPtr+=nb_compo; lCurrentPtr+=nb_compo;
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -116,38 +116,36 @@ The functions in J2K.C have for goal to read/write the several parts of the code
* These values may be combined with a | operator. * These values may be combined with a | operator.
* */ * */
typedef enum J2K_STATUS { typedef enum J2K_STATUS {
J2K_STATE_NONE = 0x0000, /**< a SOC marker is expected */ J2K_STATE_NONE = 0x0000, /**< a SOC marker is expected */
J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */ J2K_STATE_MHSOC = 0x0001, /**< a SOC marker is expected */
J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */ J2K_STATE_MHSIZ = 0x0002, /**< a SIZ marker is expected */
J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */ J2K_STATE_MH = 0x0004, /**< the decoding process is in the main header */
J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */ J2K_STATE_TPHSOT = 0x0008, /**< the decoding process is in a tile part header and expects a SOT marker */
J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */ J2K_STATE_TPH = 0x0010, /**< the decoding process is in a tile part header */
J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */ J2K_STATE_MT = 0x0020, /**< the EOC marker has just been read */
J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */ J2K_STATE_NEOC = 0x0040, /**< the decoding process must not expect a EOC marker because the codestream is truncated */
J2K_STATE_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */ J2K_STATE_EOC = 0x0100, /**< the decoding process has encountered the EOC marker */
J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/ J2K_STATE_ERR = 0x8000 /**< the decoding process has encountered an error (FIXME warning V1 = 0x0080)*/
} J2K_STATUS; } J2K_STATUS;
/** /**
* Type of elements storing in the MCT data * Type of elements storing in the MCT data
*/ */
typedef enum MCT_ELEMENT_TYPE typedef enum MCT_ELEMENT_TYPE {
{ MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/ MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/ MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/ MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
} J2K_MCT_ELEMENT_TYPE; } J2K_MCT_ELEMENT_TYPE;
/** /**
* Type of MCT array * Type of MCT array
*/ */
typedef enum MCT_ARRAY_TYPE typedef enum MCT_ARRAY_TYPE {
{ MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DEPENDENCY = 0, MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_DECORRELATION = 1, MCT_TYPE_OFFSET = 2
MCT_TYPE_OFFSET = 2
} J2K_MCT_ARRAY_TYPE; } J2K_MCT_ARRAY_TYPE;
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -156,51 +154,50 @@ typedef enum MCT_ARRAY_TYPE
T2 encoding mode T2 encoding mode
*/ */
typedef enum T2_MODE { typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/ THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/ FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE; } J2K_T2_MODE;
/** /**
* Quantization stepsize * Quantization stepsize
*/ */
typedef struct opj_stepsize { typedef struct opj_stepsize {
/** exponent */ /** exponent */
OPJ_INT32 expn; OPJ_INT32 expn;
/** mantissa */ /** mantissa */
OPJ_INT32 mant; OPJ_INT32 mant;
} opj_stepsize_t; } opj_stepsize_t;
/** /**
Tile-component coding parameters Tile-component coding parameters
*/ */
typedef struct opj_tccp typedef struct opj_tccp {
{ /** coding style */
/** coding style */ OPJ_UINT32 csty;
OPJ_UINT32 csty; /** number of resolutions */
/** number of resolutions */ OPJ_UINT32 numresolutions;
OPJ_UINT32 numresolutions; /** code-blocks width */
/** code-blocks width */ OPJ_UINT32 cblkw;
OPJ_UINT32 cblkw; /** code-blocks height */
/** code-blocks height */ OPJ_UINT32 cblkh;
OPJ_UINT32 cblkh; /** code-block coding style */
/** code-block coding style */ OPJ_UINT32 cblksty;
OPJ_UINT32 cblksty; /** discrete wavelet transform identifier */
/** discrete wavelet transform identifier */ OPJ_UINT32 qmfbid;
OPJ_UINT32 qmfbid; /** quantisation style */
/** quantisation style */ OPJ_UINT32 qntsty;
OPJ_UINT32 qntsty; /** stepsizes used for quantization */
/** stepsizes used for quantization */ opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS];
opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS]; /** number of guard bits */
/** number of guard bits */ OPJ_UINT32 numgbits;
OPJ_UINT32 numgbits; /** Region Of Interest shift */
/** Region Of Interest shift */ OPJ_INT32 roishift;
OPJ_INT32 roishift; /** precinct width */
/** precinct width */ OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS]; /** precinct height */
/** precinct height */ OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS]; /** the dc_level_shift **/
/** the dc_level_shift **/ OPJ_INT32 m_dc_level_shift;
OPJ_INT32 m_dc_level_shift;
} }
opj_tccp_t; opj_tccp_t;
@ -209,33 +206,30 @@ opj_tccp_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_mct_data typedef struct opj_mct_data {
{ J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ELEMENT_TYPE m_element_type; J2K_MCT_ARRAY_TYPE m_array_type;
J2K_MCT_ARRAY_TYPE m_array_type; OPJ_UINT32 m_index;
OPJ_UINT32 m_index; OPJ_BYTE * m_data;
OPJ_BYTE * m_data; OPJ_UINT32 m_data_size;
OPJ_UINT32 m_data_size;
} }
opj_mct_data_t; opj_mct_data_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_simple_mcc_decorrelation_data typedef struct opj_simple_mcc_decorrelation_data {
{ OPJ_UINT32 m_index;
OPJ_UINT32 m_index; OPJ_UINT32 m_nb_comps;
OPJ_UINT32 m_nb_comps; opj_mct_data_t * m_decorrelation_array;
opj_mct_data_t * m_decorrelation_array; opj_mct_data_t * m_offset_array;
opj_mct_data_t * m_offset_array; OPJ_UINT32 m_is_irreversible : 1;
OPJ_UINT32 m_is_irreversible : 1;
} }
opj_simple_mcc_decorrelation_data_t; opj_simple_mcc_decorrelation_data_t;
typedef struct opj_ppx_struct typedef struct opj_ppx_struct {
{ OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */ OPJ_UINT32 m_data_size;
OPJ_UINT32 m_data_size;
} opj_ppx; } opj_ppx;
/** /**
@ -243,106 +237,103 @@ Tile coding parameters :
this structure is used to store coding/decoding parameters common to all this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header) tiles (information like COD, COC in main header)
*/ */
typedef struct opj_tcp typedef struct opj_tcp {
{ /** coding style */
/** coding style */ OPJ_UINT32 csty;
OPJ_UINT32 csty; /** progression order */
/** progression order */ OPJ_PROG_ORDER prg;
OPJ_PROG_ORDER prg; /** number of layers */
/** number of layers */ OPJ_UINT32 numlayers;
OPJ_UINT32 numlayers; OPJ_UINT32 num_layers_to_decode;
OPJ_UINT32 num_layers_to_decode; /** multi-component transform identifier */
/** multi-component transform identifier */ OPJ_UINT32 mct;
OPJ_UINT32 mct; /** rates of layers */
/** rates of layers */ OPJ_FLOAT32 rates[100];
OPJ_FLOAT32 rates[100]; /** number of progression order changes */
/** number of progression order changes */ OPJ_UINT32 numpocs;
OPJ_UINT32 numpocs; /** progression order changes */
/** progression order changes */ opj_poc_t pocs[32];
opj_poc_t pocs[32];
/** number of ppt markers (reserved size) */ /** number of ppt markers (reserved size) */
OPJ_UINT32 ppt_markers_count; OPJ_UINT32 ppt_markers_count;
/** ppt markers data (table indexed by Zppt) */ /** ppt markers data (table indexed by Zppt) */
opj_ppx* ppt_markers; opj_ppx* ppt_markers;
/** packet header store there for future use in t2_decode_packet */ /** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppt_data; OPJ_BYTE *ppt_data;
/** used to keep a track of the allocated memory */ /** used to keep a track of the allocated memory */
OPJ_BYTE *ppt_buffer; OPJ_BYTE *ppt_buffer;
/** Number of bytes stored inside ppt_data*/ /** Number of bytes stored inside ppt_data*/
OPJ_UINT32 ppt_data_size; OPJ_UINT32 ppt_data_size;
/** size of ppt_data*/ /** size of ppt_data*/
OPJ_UINT32 ppt_len; OPJ_UINT32 ppt_len;
/** add fixed_quality */ /** add fixed_quality */
OPJ_FLOAT32 distoratio[100]; OPJ_FLOAT32 distoratio[100];
/** tile-component coding parameters */ /** tile-component coding parameters */
opj_tccp_t *tccps; opj_tccp_t *tccps;
/** number of tile parts for the tile. */ /** number of tile parts for the tile. */
OPJ_UINT32 m_nb_tile_parts; OPJ_UINT32 m_nb_tile_parts;
/** data for the tile */ /** data for the tile */
OPJ_BYTE * m_data; OPJ_BYTE * m_data;
/** size of data */ /** size of data */
OPJ_UINT32 m_data_size; OPJ_UINT32 m_data_size;
/** encoding norms */ /** encoding norms */
OPJ_FLOAT64 * mct_norms; OPJ_FLOAT64 * mct_norms;
/** the mct decoding matrix */ /** the mct decoding matrix */
OPJ_FLOAT32 * m_mct_decoding_matrix; OPJ_FLOAT32 * m_mct_decoding_matrix;
/** the mct coding matrix */ /** the mct coding matrix */
OPJ_FLOAT32 * m_mct_coding_matrix; OPJ_FLOAT32 * m_mct_coding_matrix;
/** mct records */ /** mct records */
opj_mct_data_t * m_mct_records; opj_mct_data_t * m_mct_records;
/** the number of mct records. */ /** the number of mct records. */
OPJ_UINT32 m_nb_mct_records; OPJ_UINT32 m_nb_mct_records;
/** the max number of mct records. */ /** the max number of mct records. */
OPJ_UINT32 m_nb_max_mct_records; OPJ_UINT32 m_nb_max_mct_records;
/** mcc records */ /** mcc records */
opj_simple_mcc_decorrelation_data_t * m_mcc_records; opj_simple_mcc_decorrelation_data_t * m_mcc_records;
/** the number of mct records. */ /** the number of mct records. */
OPJ_UINT32 m_nb_mcc_records; OPJ_UINT32 m_nb_mcc_records;
/** the max number of mct records. */ /** the max number of mct records. */
OPJ_UINT32 m_nb_max_mcc_records; OPJ_UINT32 m_nb_max_mcc_records;
/***** FLAGS *******/ /***** FLAGS *******/
/** If cod == 1 --> there was a COD marker for the present tile */ /** If cod == 1 --> there was a COD marker for the present tile */
OPJ_UINT32 cod : 1; OPJ_UINT32 cod : 1;
/** If ppt == 1 --> there was a PPT marker for the present tile */ /** If ppt == 1 --> there was a PPT marker for the present tile */
OPJ_UINT32 ppt : 1; OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */ /** indicates if a POC marker has been used O:NO, 1:YES */
OPJ_UINT32 POC : 1; OPJ_UINT32 POC : 1;
} opj_tcp_t; } opj_tcp_t;
typedef struct opj_encoding_param typedef struct opj_encoding_param {
{ /** Maximum rate for each component. If == 0, component size limitation is not considered */
/** Maximum rate for each component. If == 0, component size limitation is not considered */ OPJ_UINT32 m_max_comp_size;
OPJ_UINT32 m_max_comp_size; /** Position of tile part flag in progression order*/
/** Position of tile part flag in progression order*/ OPJ_INT32 m_tp_pos;
OPJ_INT32 m_tp_pos; /** fixed layer */
/** fixed layer */ OPJ_INT32 *m_matrice;
OPJ_INT32 *m_matrice; /** Flag determining tile part generation*/
/** Flag determining tile part generation*/ OPJ_BYTE m_tp_flag;
OPJ_BYTE m_tp_flag; /** allocation by rate/distortion */
/** allocation by rate/distortion */ OPJ_UINT32 m_disto_alloc : 1;
OPJ_UINT32 m_disto_alloc : 1; /** allocation by fixed layer */
/** allocation by fixed layer */ OPJ_UINT32 m_fixed_alloc : 1;
OPJ_UINT32 m_fixed_alloc : 1; /** add fixed_quality */
/** add fixed_quality */ OPJ_UINT32 m_fixed_quality : 1;
OPJ_UINT32 m_fixed_quality : 1; /** Enabling Tile part generation*/
/** Enabling Tile part generation*/ OPJ_UINT32 m_tp_on : 1;
OPJ_UINT32 m_tp_on : 1;
} }
opj_encoding_param_t; opj_encoding_param_t;
typedef struct opj_decoding_param typedef struct opj_decoding_param {
{ /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */ OPJ_UINT32 m_reduce;
OPJ_UINT32 m_reduce; /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ OPJ_UINT32 m_layer;
OPJ_UINT32 m_layer;
} }
opj_decoding_param_t; opj_decoding_param_t;
@ -350,199 +341,195 @@ opj_decoding_param_t;
/** /**
* Coding parameters * Coding parameters
*/ */
typedef struct opj_cp typedef struct opj_cp {
{ /** Size of the image in bits*/
/** Size of the image in bits*/ /*int img_size;*/
/*int img_size;*/ /** Rsiz*/
/** Rsiz*/
OPJ_UINT16 rsiz; OPJ_UINT16 rsiz;
/** XTOsiz */ /** XTOsiz */
OPJ_UINT32 tx0; /* MSD see norm */ OPJ_UINT32 tx0; /* MSD see norm */
/** YTOsiz */ /** YTOsiz */
OPJ_UINT32 ty0; /* MSD see norm */ OPJ_UINT32 ty0; /* MSD see norm */
/** XTsiz */ /** XTsiz */
OPJ_UINT32 tdx; OPJ_UINT32 tdx;
/** YTsiz */ /** YTsiz */
OPJ_UINT32 tdy; OPJ_UINT32 tdy;
/** comment */ /** comment */
OPJ_CHAR *comment; OPJ_CHAR *comment;
/** number of tiles in width */ /** number of tiles in width */
OPJ_UINT32 tw; OPJ_UINT32 tw;
/** number of tiles in heigth */ /** number of tiles in heigth */
OPJ_UINT32 th; OPJ_UINT32 th;
/** number of ppm markers (reserved size) */ /** number of ppm markers (reserved size) */
OPJ_UINT32 ppm_markers_count; OPJ_UINT32 ppm_markers_count;
/** ppm markers data (table indexed by Zppm) */ /** ppm markers data (table indexed by Zppm) */
opj_ppx* ppm_markers; opj_ppx* ppm_markers;
/** packet header store there for future use in t2_decode_packet */ /** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppm_data; OPJ_BYTE *ppm_data;
/** size of the ppm_data*/ /** size of the ppm_data*/
OPJ_UINT32 ppm_len; OPJ_UINT32 ppm_len;
/** size of the ppm_data*/ /** size of the ppm_data*/
OPJ_UINT32 ppm_data_read; OPJ_UINT32 ppm_data_read;
OPJ_BYTE *ppm_data_current; OPJ_BYTE *ppm_data_current;
/** packet header storage original buffer */ /** packet header storage original buffer */
OPJ_BYTE *ppm_buffer; OPJ_BYTE *ppm_buffer;
/** pointer remaining on the first byte of the first header if ppm is used */ /** pointer remaining on the first byte of the first header if ppm is used */
OPJ_BYTE *ppm_data_first; OPJ_BYTE *ppm_data_first;
/** Number of bytes actually stored inside the ppm_data */ /** Number of bytes actually stored inside the ppm_data */
OPJ_UINT32 ppm_data_size; OPJ_UINT32 ppm_data_size;
/** use in case of multiple marker PPM (number of info already store) */ /** use in case of multiple marker PPM (number of info already store) */
OPJ_INT32 ppm_store; OPJ_INT32 ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */ /** use in case of multiple marker PPM (case on non-finished previous info) */
OPJ_INT32 ppm_previous; OPJ_INT32 ppm_previous;
/** tile coding parameters */ /** tile coding parameters */
opj_tcp_t *tcps; opj_tcp_t *tcps;
union union {
{ opj_decoding_param_t m_dec;
opj_decoding_param_t m_dec; opj_encoding_param_t m_enc;
opj_encoding_param_t m_enc; }
} m_specific_param;
m_specific_param;
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */ /** enables writing of EPC in MH, thus activating JPWL */
OPJ_BOOL epc_on; OPJ_BOOL epc_on;
/** enables writing of EPB, in case of activated JPWL */ /** enables writing of EPB, in case of activated JPWL */
OPJ_BOOL epb_on; OPJ_BOOL epb_on;
/** enables writing of ESD, in case of activated JPWL */ /** enables writing of ESD, in case of activated JPWL */
OPJ_BOOL esd_on; OPJ_BOOL esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */ /** enables writing of informative techniques of ESD, in case of activated JPWL */
OPJ_BOOL info_on; OPJ_BOOL info_on;
/** enables writing of RED, in case of activated JPWL */ /** enables writing of RED, in case of activated JPWL */
OPJ_BOOL red_on; OPJ_BOOL red_on;
/** error protection method for MH (0,1,16,32,37-128) */ /** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH; int hprot_MH;
/** tile number of header protection specification (>=0) */ /** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */ /** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS]; int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */ /** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS]; int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */ /** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS]; int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */ /** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS]; int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */ /** enables writing of ESD, (0/2/4 bytes) */
int sens_size; int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */ /** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr; int sens_addr;
/** sensitivity range (0-3) */ /** sensitivity range (0-3) */
int sens_range; int sens_range;
/** sensitivity method for MH (-1,0-7) */ /** sensitivity method for MH (-1,0-7) */
int sens_MH; int sens_MH;
/** tile number of sensitivity specification (>=0) */ /** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */ /** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS]; int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */ /** enables JPWL correction at the decoder */
OPJ_BOOL correct; OPJ_BOOL correct;
/** expected number of components at the decoder */ /** expected number of components at the decoder */
int exp_comps; int exp_comps;
/** maximum number of tiles at the decoder */ /** maximum number of tiles at the decoder */
OPJ_UINT32 max_tiles; OPJ_UINT32 max_tiles;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/******** FLAGS *********/ /******** FLAGS *********/
/** if ppm == 1 --> there was a PPM marker*/ /** if ppm == 1 --> there was a PPM marker*/
OPJ_UINT32 ppm : 1; OPJ_UINT32 ppm : 1;
/** tells if the parameter is a coding or decoding one */ /** tells if the parameter is a coding or decoding one */
OPJ_UINT32 m_is_decoder : 1; OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */ /* <<UniPG */
} opj_cp_t; } opj_cp_t;
typedef struct opj_j2k_dec typedef struct opj_j2k_dec {
{ /** locate in which part of the codestream the decoder is (main header, tile header, end) */
/** locate in which part of the codestream the decoder is (main header, tile header, end) */ OPJ_UINT32 m_state;
OPJ_UINT32 m_state; /**
/** * store decoding parameters common to all tiles (information like COD, COC in main header)
* store decoding parameters common to all tiles (information like COD, COC in main header) */
*/ opj_tcp_t *m_default_tcp;
opj_tcp_t *m_default_tcp; OPJ_BYTE *m_header_data;
OPJ_BYTE *m_header_data; OPJ_UINT32 m_header_data_size;
OPJ_UINT32 m_header_data_size; /** to tell the tile part length */
/** to tell the tile part length */ OPJ_UINT32 m_sot_length;
OPJ_UINT32 m_sot_length; /** Only tiles index in the correct range will be decoded.*/
/** Only tiles index in the correct range will be decoded.*/ OPJ_UINT32 m_start_tile_x;
OPJ_UINT32 m_start_tile_x; OPJ_UINT32 m_start_tile_y;
OPJ_UINT32 m_start_tile_y; OPJ_UINT32 m_end_tile_x;
OPJ_UINT32 m_end_tile_x; OPJ_UINT32 m_end_tile_y;
OPJ_UINT32 m_end_tile_y; /**
/** * Decoded area set by the user
* Decoded area set by the user */
*/ OPJ_UINT32 m_DA_x0;
OPJ_UINT32 m_DA_x0; OPJ_UINT32 m_DA_y0;
OPJ_UINT32 m_DA_y0; OPJ_UINT32 m_DA_x1;
OPJ_UINT32 m_DA_x1; OPJ_UINT32 m_DA_y1;
OPJ_UINT32 m_DA_y1;
/** Index of the tile to decode (used in get_tile) */ /** Index of the tile to decode (used in get_tile) */
OPJ_INT32 m_tile_ind_to_dec; OPJ_INT32 m_tile_ind_to_dec;
/** Position of the last SOT marker read */ /** Position of the last SOT marker read */
OPJ_OFF_T m_last_sot_read_pos; OPJ_OFF_T m_last_sot_read_pos;
/** /**
* Indicate that the current tile-part is assume as the last tile part of the codestream. * Indicate that the current tile-part is assume as the last tile part of the codestream.
* It is useful in the case of PSot is equal to zero. The sot length will be compute in the * It is useful in the case of PSot is equal to zero. The sot length will be compute in the
* SOD reader function. FIXME NOT USED for the moment * SOD reader function. FIXME NOT USED for the moment
*/ */
OPJ_BOOL m_last_tile_part; OPJ_BOOL m_last_tile_part;
/** to tell that a tile can be decoded. */ /** to tell that a tile can be decoded. */
OPJ_UINT32 m_can_decode : 1; OPJ_UINT32 m_can_decode : 1;
OPJ_UINT32 m_discard_tiles : 1; OPJ_UINT32 m_discard_tiles : 1;
OPJ_UINT32 m_skip_data : 1; OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/ /** TNsot correction : see issue 254 **/
OPJ_UINT32 m_nb_tile_parts_correction_checked : 1; OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_UINT32 m_nb_tile_parts_correction : 1; OPJ_UINT32 m_nb_tile_parts_correction : 1;
} opj_j2k_dec_t; } opj_j2k_dec_t;
typedef struct opj_j2k_enc typedef struct opj_j2k_enc {
{ /** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/
/** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/ OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
/** Tile part number currently coding, taking into account POC. m_current_tile_part_number holds the total number of tile parts while encoding the last tile part.*/ /** Tile part number currently coding, taking into account POC. m_current_tile_part_number holds the total number of tile parts while encoding the last tile part.*/
OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */ OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */
/** /**
locate the start position of the TLM marker locate the start position of the TLM marker
after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length. after encoding the tilepart, a jump (in j2k_write_sod) is done to the TLM marker to store the value of its length.
*/ */
OPJ_OFF_T m_tlm_start; OPJ_OFF_T m_tlm_start;
/** /**
* Stores the sizes of the tlm. * Stores the sizes of the tlm.
*/ */
OPJ_BYTE * m_tlm_sot_offsets_buffer; OPJ_BYTE * m_tlm_sot_offsets_buffer;
/** /**
* The current offset of the tlm buffer. * The current offset of the tlm buffer.
*/ */
OPJ_BYTE * m_tlm_sot_offsets_current; OPJ_BYTE * m_tlm_sot_offsets_current;
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/ /** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/ /** used in TLMmarker*/
OPJ_UINT32 m_total_tile_parts; /* totnum_tp */ OPJ_UINT32 m_total_tile_parts; /* totnum_tp */
/* encoded data for a tile */ /* encoded data for a tile */
OPJ_BYTE * m_encoded_tile_data; OPJ_BYTE * m_encoded_tile_data;
/* size of the encoded_data */ /* size of the encoded_data */
OPJ_UINT32 m_encoded_tile_size; OPJ_UINT32 m_encoded_tile_size;
/* encoded data for a tile */ /* encoded data for a tile */
OPJ_BYTE * m_header_tile_data; OPJ_BYTE * m_header_tile_data;
/* size of the encoded_data */ /* size of the encoded_data */
OPJ_UINT32 m_header_tile_data_size; OPJ_UINT32 m_header_tile_data_size;
} opj_j2k_enc_t; } opj_j2k_enc_t;
@ -553,42 +540,40 @@ struct opj_tcd;
/** /**
JPEG-2000 codestream reader/writer JPEG-2000 codestream reader/writer
*/ */
typedef struct opj_j2k typedef struct opj_j2k {
{ /* J2K codestream is decoded*/
/* J2K codestream is decoded*/ OPJ_BOOL m_is_decoder;
OPJ_BOOL m_is_decoder;
/* FIXME DOC*/ /* FIXME DOC*/
union union {
{ opj_j2k_dec_t m_decoder;
opj_j2k_dec_t m_decoder; opj_j2k_enc_t m_encoder;
opj_j2k_enc_t m_encoder; }
} m_specific_param;
m_specific_param;
/** pointer to the internal/private encoded / decoded image */ /** pointer to the internal/private encoded / decoded image */
opj_image_t* m_private_image; opj_image_t* m_private_image;
/* pointer to the output image (decoded)*/ /* pointer to the output image (decoded)*/
opj_image_t* m_output_image; opj_image_t* m_output_image;
/** Coding parameters */ /** Coding parameters */
opj_cp_t m_cp; opj_cp_t m_cp;
/** the list of procedures to exec **/ /** the list of procedures to exec **/
opj_procedure_list_t * m_procedure_list; opj_procedure_list_t * m_procedure_list;
/** the list of validation procedures to follow to make sure the code is valid **/ /** the list of validation procedures to follow to make sure the code is valid **/
opj_procedure_list_t * m_validation_list; opj_procedure_list_t * m_validation_list;
/** helper used to write the index file */ /** helper used to write the index file */
opj_codestream_index_t *cstr_index; opj_codestream_index_t *cstr_index;
/** number of the tile curently concern by coding/decoding */ /** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number; OPJ_UINT32 m_current_tile_number;
/** the current tile coder/decoder **/ /** the current tile coder/decoder **/
struct opj_tcd * m_tcd; struct opj_tcd * m_tcd;
} }
opj_j2k_t; opj_j2k_t;
@ -616,9 +601,9 @@ opj_j2k_t* opj_j2k_create_compress(void);
OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_cparameters_t *parameters, opj_cparameters_t *parameters,
opj_image_t *image, opj_image_t *image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
Converts an enum type progression order to string type Converts an enum type progression order to string type
@ -725,10 +710,10 @@ OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
* @return true if the area could be set. * @return true if the area could be set.
*/ */
OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
opj_image_t* p_image, opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Creates a J2K decompression structure. * Creates a J2K decompression structure.
@ -801,14 +786,14 @@ OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k,
OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
opj_event_mgr_t * p_manager, opj_event_mgr_t * p_manager,
OPJ_UINT32 tile_index ); OPJ_UINT32 tile_index );
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
OPJ_UINT32 res_factor, OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
@ -821,18 +806,18 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
* @param p_manager the user event manager. * @param p_manager the user event manager.
*/ */
OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k,
OPJ_UINT32 p_tile_index, OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data, OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size, OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Encodes an image into a JPEG-2000 codestream * Encodes an image into a JPEG-2000 codestream
*/ */
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Starts a compression scheme, i.e. validates the codec parameters, writes the header. * Starts a compression scheme, i.e. validates the codec parameters, writes the header.
@ -845,17 +830,17 @@ OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
* @return true if the codec is valid. * @return true if the codec is valid.
*/ */
OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t * p_image, opj_image_t * p_image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
* Ends the compression procedures and possibiliy add data to be read after the * Ends the compression procedures and possibiliy add data to be read after the
* codestream. * codestream.
*/ */
OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image); OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image);

File diff suppressed because it is too large Load Diff

View File

@ -70,38 +70,34 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
typedef enum typedef enum {
{ JP2_STATE_NONE = 0x0,
JP2_STATE_NONE = 0x0, JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_SIGNATURE = 0x1, JP2_STATE_FILE_TYPE = 0x2,
JP2_STATE_FILE_TYPE = 0x2, JP2_STATE_HEADER = 0x4,
JP2_STATE_HEADER = 0x4, JP2_STATE_CODESTREAM = 0x8,
JP2_STATE_CODESTREAM = 0x8, JP2_STATE_END_CODESTREAM = 0x10,
JP2_STATE_END_CODESTREAM = 0x10, JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
} }
JP2_STATE; JP2_STATE;
typedef enum typedef enum {
{ JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_NONE = 0x0, JP2_IMG_STATE_UNKNOWN = 0x7fffffff
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
} }
JP2_IMG_STATE; JP2_IMG_STATE;
/** /**
Channel description: channel index, type, association Channel description: channel index, type, association
*/ */
typedef struct opj_jp2_cdef_info typedef struct opj_jp2_cdef_info {
{
OPJ_UINT16 cn, typ, asoc; OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t; } opj_jp2_cdef_info_t;
/** /**
Channel descriptions and number of descriptions Channel descriptions and number of descriptions
*/ */
typedef struct opj_jp2_cdef typedef struct opj_jp2_cdef {
{
opj_jp2_cdef_info_t *info; opj_jp2_cdef_info_t *info;
OPJ_UINT16 n; OPJ_UINT16 n;
} opj_jp2_cdef_t; } opj_jp2_cdef_t;
@ -109,8 +105,7 @@ typedef struct opj_jp2_cdef
/** /**
Component mappings: channel index, mapping type, palette index Component mappings: channel index, mapping type, palette index
*/ */
typedef struct opj_jp2_cmap_comp typedef struct opj_jp2_cmap_comp {
{
OPJ_UINT16 cmp; OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol; OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t; } opj_jp2_cmap_comp_t;
@ -118,8 +113,7 @@ typedef struct opj_jp2_cmap_comp
/** /**
Palette data: table entries, palette columns Palette data: table entries, palette columns
*/ */
typedef struct opj_jp2_pclr typedef struct opj_jp2_pclr {
{
OPJ_UINT32 *entries; OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign; OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size; OPJ_BYTE *channel_size;
@ -131,8 +125,7 @@ typedef struct opj_jp2_pclr
/** /**
Collector for ICC profile, palette, component mapping, channel description Collector for ICC profile, palette, component mapping, channel description
*/ */
typedef struct opj_jp2_color typedef struct opj_jp2_color {
{
OPJ_BYTE *icc_profile_buf; OPJ_BYTE *icc_profile_buf;
OPJ_UINT32 icc_profile_len; OPJ_UINT32 icc_profile_len;
@ -145,54 +138,53 @@ typedef struct opj_jp2_color
JP2 component JP2 component
*/ */
typedef struct opj_jp2_comps { typedef struct opj_jp2_comps {
OPJ_UINT32 depth; OPJ_UINT32 depth;
OPJ_UINT32 sgnd; OPJ_UINT32 sgnd;
OPJ_UINT32 bpcc; OPJ_UINT32 bpcc;
} opj_jp2_comps_t; } opj_jp2_comps_t;
/** /**
JPEG-2000 file format reader/writer JPEG-2000 file format reader/writer
*/ */
typedef struct opj_jp2 typedef struct opj_jp2 {
{ /** handle to the J2K codec */
/** handle to the J2K codec */ opj_j2k_t *j2k;
opj_j2k_t *j2k; /** list of validation procedures */
/** list of validation procedures */ struct opj_procedure_list * m_validation_list;
struct opj_procedure_list * m_validation_list; /** list of execution procedures */
/** list of execution procedures */ struct opj_procedure_list * m_procedure_list;
struct opj_procedure_list * m_procedure_list;
/* width of image */ /* width of image */
OPJ_UINT32 w; OPJ_UINT32 w;
/* height of image */ /* height of image */
OPJ_UINT32 h; OPJ_UINT32 h;
/* number of components in the image */ /* number of components in the image */
OPJ_UINT32 numcomps; OPJ_UINT32 numcomps;
OPJ_UINT32 bpc; OPJ_UINT32 bpc;
OPJ_UINT32 C; OPJ_UINT32 C;
OPJ_UINT32 UnkC; OPJ_UINT32 UnkC;
OPJ_UINT32 IPR; OPJ_UINT32 IPR;
OPJ_UINT32 meth; OPJ_UINT32 meth;
OPJ_UINT32 approx; OPJ_UINT32 approx;
OPJ_UINT32 enumcs; OPJ_UINT32 enumcs;
OPJ_UINT32 precedence; OPJ_UINT32 precedence;
OPJ_UINT32 brand; OPJ_UINT32 brand;
OPJ_UINT32 minversion; OPJ_UINT32 minversion;
OPJ_UINT32 numcl; OPJ_UINT32 numcl;
OPJ_UINT32 *cl; OPJ_UINT32 *cl;
opj_jp2_comps_t *comps; opj_jp2_comps_t *comps;
/* FIXME: The following two variables are used to save offset /* FIXME: The following two variables are used to save offset
as we write out a JP2 file to disk. This mecanism is not flexible as we write out a JP2 file to disk. This mecanism is not flexible
as codec writers will need to extand those fields as new part as codec writers will need to extand those fields as new part
of the standard are implemented. of the standard are implemented.
*/ */
OPJ_OFF_T j2k_codestream_offset; OPJ_OFF_T j2k_codestream_offset;
OPJ_OFF_T jpip_iptr_offset; OPJ_OFF_T jpip_iptr_offset;
OPJ_BOOL jpip_on; OPJ_BOOL jpip_on;
OPJ_UINT32 jp2_state; OPJ_UINT32 jp2_state;
OPJ_UINT32 jp2_img_state; OPJ_UINT32 jp2_img_state;
opj_jp2_color_t color; opj_jp2_color_t color;
OPJ_BOOL ignore_pclr_cmap_cdef; OPJ_BOOL ignore_pclr_cmap_cdef;
} }
@ -207,27 +199,25 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos; OPJ_INT32 init_pos;
} opj_jp2_box_t; } opj_jp2_box_t;
typedef struct opj_jp2_header_handler typedef struct opj_jp2_header_handler {
{ /* marker value */
/* marker value */ OPJ_UINT32 id;
OPJ_UINT32 id; /* action linked to the marker */
/* action linked to the marker */ OPJ_BOOL (*handler) ( opj_jp2_t *jp2,
OPJ_BOOL (*handler) ( opj_jp2_t *jp2, OPJ_BYTE *p_header_data,
OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size,
OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager);
opj_event_mgr_t * p_manager);
} }
opj_jp2_header_handler_t; opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler typedef struct opj_jp2_img_header_writer_handler {
{ /* action to perform */
/* action to perform */ OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size); /* result of the action : data */
/* result of the action : data */ OPJ_BYTE* m_data;
OPJ_BYTE* m_data; /* size of data */
/* size of data */ OPJ_UINT32 m_size;
OPJ_UINT32 m_size;
} }
opj_jp2_img_header_writer_handler_t; opj_jp2_img_header_writer_handler_t;
@ -254,8 +244,8 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
*/ */
OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
* Setup the encoder parameters using the current image and using user parameters. * Setup the encoder parameters using the current image and using user parameters.
@ -268,9 +258,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise * @return OPJ_TRUE if successful, OPJ_FALSE otherwise
*/ */
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters, opj_cparameters_t *parameters,
opj_image_t *image, opj_image_t *image,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
Encode an image into a JPEG-2000 file stream Encode an image into a JPEG-2000 file stream
@ -280,8 +270,8 @@ Encode an image into a JPEG-2000 file stream
@return Returns true if successful, returns false otherwise @return Returns true if successful, returns false otherwise
*/ */
OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2, OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2,
opj_stream_private_t *stream, opj_stream_private_t *stream,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/** /**
@ -305,8 +295,8 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
* codestream. * codestream.
*/ */
OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2, OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -329,9 +319,9 @@ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2,
* @return true if the box is valid. * @return true if the box is valid.
*/ */
OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream, OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
opj_jp2_t *jp2, opj_jp2_t *jp2,
opj_image_t ** p_image, opj_image_t ** p_image,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Reads a tile header. * Reads a tile header.
@ -370,11 +360,11 @@ OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
* @param p_manager the user event manager. * @param p_manager the user event manager.
*/ */
OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
OPJ_UINT32 p_tile_index, OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data, OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size, OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* Decode tile data. * Decode tile data.
@ -422,14 +412,14 @@ void opj_jp2_destroy(opj_jp2_t *jp2);
* @return true if the area could be set. * @return true if the area could be set.
*/ */
OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
opj_image_t* p_image, opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* *
*/ */
OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,
@ -441,8 +431,8 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
* *
*/ */
OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2,
OPJ_UINT32 res_factor, OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
/* TODO MSD: clean these 3 functions */ /* TODO MSD: clean these 3 functions */

View File

@ -61,12 +61,12 @@ static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 };
const OPJ_FLOAT64 * opj_mct_get_mct_norms () const OPJ_FLOAT64 * opj_mct_get_mct_norms ()
{ {
return opj_mct_norms; return opj_mct_norms;
} }
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real () const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
{ {
return opj_mct_norms_real; return opj_mct_norms_real;
} }
/* <summary> */ /* <summary> */
@ -74,67 +74,67 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
/* </summary> */ /* </summary> */
#ifdef __SSE2__ #ifdef __SSE2__
void opj_mct_encode( void opj_mct_encode(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
/* buffer are aligned on 16 bytes */ /* buffer are aligned on 16 bytes */
assert( ((size_t)c0 & 0xf) == 0 ); assert( ((size_t)c0 & 0xf) == 0 );
assert( ((size_t)c1 & 0xf) == 0 ); assert( ((size_t)c1 & 0xf) == 0 );
assert( ((size_t)c2 & 0xf) == 0 ); assert( ((size_t)c2 & 0xf) == 0 );
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i y, u, v; __m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i])); __m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i])); __m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i])); __m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
y = _mm_add_epi32(g, g); y = _mm_add_epi32(g, g);
y = _mm_add_epi32(y, b); y = _mm_add_epi32(y, b);
y = _mm_add_epi32(y, r); y = _mm_add_epi32(y, r);
y = _mm_srai_epi32(y, 2); y = _mm_srai_epi32(y, 2);
u = _mm_sub_epi32(b, g); u = _mm_sub_epi32(b, g);
v = _mm_sub_epi32(r, g); v = _mm_sub_epi32(r, g);
_mm_store_si128((__m128i *)&(c0[i]), y); _mm_store_si128((__m128i *)&(c0[i]), y);
_mm_store_si128((__m128i *)&(c1[i]), u); _mm_store_si128((__m128i *)&(c1[i]), u);
_mm_store_si128((__m128i *)&(c2[i]), v); _mm_store_si128((__m128i *)&(c2[i]), v);
} }
for(; i < len; ++i) { for(; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2; OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g; OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g; OPJ_INT32 v = r - g;
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#else #else
void opj_mct_encode( void opj_mct_encode(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
for(i = 0; i < len; ++i) { for(i = 0; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2; OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g; OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g; OPJ_INT32 v = r - g;
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#endif #endif
@ -143,66 +143,67 @@ void opj_mct_encode(
/* </summary> */ /* </summary> */
#ifdef __SSE2__ #ifdef __SSE2__
void opj_mct_decode( void opj_mct_decode(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i r, g, b; __m128i r, g, b;
__m128i y = _mm_load_si128((const __m128i *)&(c0[i])); __m128i y = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i u = _mm_load_si128((const __m128i *)&(c1[i])); __m128i u = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i v = _mm_load_si128((const __m128i *)&(c2[i])); __m128i v = _mm_load_si128((const __m128i *)&(c2[i]));
g = y; g = y;
g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2)); g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2));
r = _mm_add_epi32(v, g); r = _mm_add_epi32(v, g);
b = _mm_add_epi32(u, g); b = _mm_add_epi32(u, g);
_mm_store_si128((__m128i *)&(c0[i]), r); _mm_store_si128((__m128i *)&(c0[i]), r);
_mm_store_si128((__m128i *)&(c1[i]), g); _mm_store_si128((__m128i *)&(c1[i]), g);
_mm_store_si128((__m128i *)&(c2[i]), b); _mm_store_si128((__m128i *)&(c2[i]), b);
} }
for (; i < len; ++i) { for (; i < len; ++i) {
OPJ_INT32 y = c0[i]; OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i]; OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i]; OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2); OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g; OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g; OPJ_INT32 b = u + g;
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
#else #else
void opj_mct_decode( void opj_mct_decode(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
OPJ_INT32 y = c0[i]; OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i]; OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i]; OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2); OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g; OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g; OPJ_INT32 b = u + g;
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
#endif #endif
/* <summary> */ /* <summary> */
/* Get norm of basis function of reversible MCT. */ /* Get norm of basis function of reversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
return opj_mct_norms[compno]; {
return opj_mct_norms[compno];
} }
/* <summary> */ /* <summary> */
@ -210,164 +211,164 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
/* </summary> */ /* </summary> */
#ifdef __SSE4_1__ #ifdef __SSE4_1__
void opj_mct_encode_real( void opj_mct_encode_real(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_SIZE_T i; OPJ_SIZE_T i;
const OPJ_SIZE_T len = n; const OPJ_SIZE_T len = n;
const __m128i ry = _mm_set1_epi32(2449); const __m128i ry = _mm_set1_epi32(2449);
const __m128i gy = _mm_set1_epi32(4809); const __m128i gy = _mm_set1_epi32(4809);
const __m128i by = _mm_set1_epi32(934); const __m128i by = _mm_set1_epi32(934);
const __m128i ru = _mm_set1_epi32(1382); const __m128i ru = _mm_set1_epi32(1382);
const __m128i gu = _mm_set1_epi32(2714); const __m128i gu = _mm_set1_epi32(2714);
/* const __m128i bu = _mm_set1_epi32(4096); */ /* const __m128i bu = _mm_set1_epi32(4096); */
/* const __m128i rv = _mm_set1_epi32(4096); */ /* const __m128i rv = _mm_set1_epi32(4096); */
const __m128i gv = _mm_set1_epi32(3430); const __m128i gv = _mm_set1_epi32(3430);
const __m128i bv = _mm_set1_epi32(666); const __m128i bv = _mm_set1_epi32(666);
const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0)); const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0));
for(i = 0; i < (len & ~3U); i += 4) { for(i = 0; i < (len & ~3U); i += 4) {
__m128i lo, hi; __m128i lo, hi;
__m128i y, u, v; __m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i])); __m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i])); __m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i])); __m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
lo = r; lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ry); lo = _mm_mul_epi32(lo, ry);
hi = _mm_mul_epi32(hi, ry); hi = _mm_mul_epi32(hi, ry);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_blend_epi16(lo, hi, 0xCC); y = _mm_blend_epi16(lo, hi, 0xCC);
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gy); lo = _mm_mul_epi32(lo, gy);
hi = _mm_mul_epi32(hi, gy); hi = _mm_mul_epi32(hi, gy);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
lo = b; lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, by); lo = _mm_mul_epi32(lo, by);
hi = _mm_mul_epi32(hi, by); hi = _mm_mul_epi32(hi, by);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC)); y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c0[i]), y); _mm_store_si128((__m128i *)&(c0[i]), y);
/*lo = b; /*lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround); lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/ hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0))); lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1))); hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(b, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12); lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12); hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_blend_epi16(lo, hi, 0xCC); u = _mm_blend_epi16(lo, hi, 0xCC);
lo = r; lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ru); lo = _mm_mul_epi32(lo, ru);
hi = _mm_mul_epi32(hi, ru); hi = _mm_mul_epi32(hi, ru);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gu); lo = _mm_mul_epi32(lo, gu);
hi = _mm_mul_epi32(hi, gu); hi = _mm_mul_epi32(hi, gu);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC)); u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c1[i]), u); _mm_store_si128((__m128i *)&(c1[i]), u);
/*lo = r; /*lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround); lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/ hi = _mm_mul_epi32(hi, mulround);*/
lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0))); lo = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 2, 0)));
hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1))); hi = _mm_cvtepi32_epi64(_mm_shuffle_epi32(r, _MM_SHUFFLE(3, 2, 3, 1)));
lo = _mm_slli_epi64(lo, 12); lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12); hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_blend_epi16(lo, hi, 0xCC); v = _mm_blend_epi16(lo, hi, 0xCC);
lo = g; lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gv); lo = _mm_mul_epi32(lo, gv);
hi = _mm_mul_epi32(hi, gv); hi = _mm_mul_epi32(hi, gv);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
lo = b; lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1)); hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, bv); lo = _mm_mul_epi32(lo, bv);
hi = _mm_mul_epi32(hi, bv); hi = _mm_mul_epi32(hi, bv);
lo = _mm_add_epi64(lo, mulround); lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround); hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13); lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13); hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC)); v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c2[i]), v); _mm_store_si128((__m128i *)&(c2[i]), v);
} }
for(; i < len; ++i) { for(; i < len; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934); OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934);
OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096); OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096);
OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666); OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666);
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#else #else
void opj_mct_encode_real( void opj_mct_encode_real(
OPJ_INT32* restrict c0, OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1, OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2, OPJ_INT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
OPJ_INT32 r = c0[i]; OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i]; OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i]; OPJ_INT32 b = c2[i];
OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934); OPJ_INT32 y = opj_int_fix_mul(r, 2449) + opj_int_fix_mul(g, 4809) + opj_int_fix_mul(b, 934);
OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096); OPJ_INT32 u = -opj_int_fix_mul(r, 1382) - opj_int_fix_mul(g, 2714) + opj_int_fix_mul(b, 4096);
OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666); OPJ_INT32 v = opj_int_fix_mul(r, 4096) - opj_int_fix_mul(g, 3430) - opj_int_fix_mul(b, 666);
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
} }
} }
#endif #endif
@ -375,183 +376,184 @@ void opj_mct_encode_real(
/* Inverse irreversible MCT. */ /* Inverse irreversible MCT. */
/* </summary> */ /* </summary> */
void opj_mct_decode_real( void opj_mct_decode_real(
OPJ_FLOAT32* restrict c0, OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1, OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2, OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n) OPJ_UINT32 n)
{ {
OPJ_UINT32 i; OPJ_UINT32 i;
#ifdef __SSE__ #ifdef __SSE__
__m128 vrv, vgu, vgv, vbu; __m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f); vrv = _mm_set1_ps(1.402f);
vgu = _mm_set1_ps(0.34413f); vgu = _mm_set1_ps(0.34413f);
vgv = _mm_set1_ps(0.71414f); vgv = _mm_set1_ps(0.71414f);
vbu = _mm_set1_ps(1.772f); vbu = _mm_set1_ps(1.772f);
for (i = 0; i < (n >> 3); ++i) { for (i = 0; i < (n >> 3); ++i) {
__m128 vy, vu, vv; __m128 vy, vu, vv;
__m128 vr, vg, vb; __m128 vr, vg, vb;
vy = _mm_load_ps(c0); vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1); vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2); vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr); _mm_store_ps(c0, vr);
_mm_store_ps(c1, vg); _mm_store_ps(c1, vg);
_mm_store_ps(c2, vb); _mm_store_ps(c2, vb);
c0 += 4; c0 += 4;
c1 += 4; c1 += 4;
c2 += 4; c2 += 4;
vy = _mm_load_ps(c0); vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1); vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2); vv = _mm_load_ps(c2);
vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv)); vr = _mm_add_ps(vy, _mm_mul_ps(vv, vrv));
vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv)); vg = _mm_sub_ps(_mm_sub_ps(vy, _mm_mul_ps(vu, vgu)), _mm_mul_ps(vv, vgv));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu)); vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr); _mm_store_ps(c0, vr);
_mm_store_ps(c1, vg); _mm_store_ps(c1, vg);
_mm_store_ps(c2, vb); _mm_store_ps(c2, vb);
c0 += 4; c0 += 4;
c1 += 4; c1 += 4;
c2 += 4; c2 += 4;
} }
n &= 7; n &= 7;
#endif #endif
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
OPJ_FLOAT32 y = c0[i]; OPJ_FLOAT32 y = c0[i];
OPJ_FLOAT32 u = c1[i]; OPJ_FLOAT32 u = c1[i];
OPJ_FLOAT32 v = c2[i]; OPJ_FLOAT32 v = c2[i];
OPJ_FLOAT32 r = y + (v * 1.402f); OPJ_FLOAT32 r = y + (v * 1.402f);
OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f)); OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
OPJ_FLOAT32 b = y + (u * 1.772f); OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
} }
} }
/* <summary> */ /* <summary> */
/* Get norm of basis function of irreversible MCT. */ /* Get norm of basis function of irreversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno)
return opj_mct_norms_real[compno]; {
return opj_mct_norms_real[compno];
} }
OPJ_BOOL opj_mct_encode_custom( OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * pCodingdata, OPJ_BYTE * pCodingdata,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata; OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 j; OPJ_UINT32 j;
OPJ_UINT32 k; OPJ_UINT32 k;
OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp; OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp;
OPJ_INT32 * lCurrentData = 00; OPJ_INT32 * lCurrentData = 00;
OPJ_INT32 * lCurrentMatrix = 00; OPJ_INT32 * lCurrentMatrix = 00;
OPJ_INT32 ** lData = (OPJ_INT32 **) pData; OPJ_INT32 ** lData = (OPJ_INT32 **) pData;
OPJ_UINT32 lMultiplicator = 1 << 13; OPJ_UINT32 lMultiplicator = 1 << 13;
OPJ_INT32 * lMctPtr; OPJ_INT32 * lMctPtr;
OPJ_ARG_NOT_USED(isSigned); OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32)); lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
if (! lCurrentData) { if (! lCurrentData) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lCurrentMatrix = lCurrentData + pNbComp; lCurrentMatrix = lCurrentData + pNbComp;
for (i =0;i<lNbMatCoeff;++i) { for (i =0; i<lNbMatCoeff; ++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator); lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
} }
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMctPtr = lCurrentMatrix; lMctPtr = lCurrentMatrix;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (*(lData[j])); lCurrentData[j] = (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
*(lData[j]) = 0; *(lData[j]) = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]); *(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
++lMctPtr; ++lMctPtr;
} }
++lData[j]; ++lData[j];
} }
} }
opj_free(lCurrentData); opj_free(lCurrentData);
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_BOOL opj_mct_decode_custom( OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct; OPJ_FLOAT32 * lMct;
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 j; OPJ_UINT32 j;
OPJ_UINT32 k; OPJ_UINT32 k;
OPJ_FLOAT32 * lCurrentData = 00; OPJ_FLOAT32 * lCurrentData = 00;
OPJ_FLOAT32 * lCurrentResult = 00; OPJ_FLOAT32 * lCurrentResult = 00;
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData; OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
OPJ_ARG_NOT_USED(isSigned); OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32)); lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if (! lCurrentData) { if (! lCurrentData) {
return OPJ_FALSE; return OPJ_FALSE;
} }
lCurrentResult = lCurrentData + pNbComp; lCurrentResult = lCurrentData + pNbComp;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData; lMct = (OPJ_FLOAT32 *) pDecodingData;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j])); lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentResult[j] = 0; lCurrentResult[j] = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k]; lCurrentResult[j] += *(lMct++) * lCurrentData[k];
} }
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]); *(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
} }
} }
opj_free(lCurrentData); opj_free(lCurrentData);
return OPJ_TRUE; return OPJ_TRUE;
} }
void opj_calculate_norms( OPJ_FLOAT64 * pNorms, void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 pNbComps, OPJ_UINT32 pNbComps,
OPJ_FLOAT32 * pMatrix) OPJ_FLOAT32 * pMatrix)
{ {
OPJ_UINT32 i,j,lIndex; OPJ_UINT32 i,j,lIndex;
OPJ_FLOAT32 lCurrentValue; OPJ_FLOAT32 lCurrentValue;
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms; OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix; OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
for (i=0;i<pNbComps;++i) { for (i=0; i<pNbComps; ++i) {
lNorms[i] = 0; lNorms[i] = 0;
lIndex = i; lIndex = i;
for (j=0;j<pNbComps;++j) { for (j=0; j<pNbComps; ++j) {
lCurrentValue = lMatrix[lIndex]; lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps; lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue; lNorms[i] += lCurrentValue * lCurrentValue;
} }
lNorms[i] = sqrt(lNorms[i]); lNorms[i] = sqrt(lNorms[i]);
} }
} }

View File

@ -109,11 +109,11 @@ FIXME DOC
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/ */
OPJ_BOOL opj_mct_encode_custom( OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * p_coding_data, OPJ_BYTE * p_coding_data,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** p_data, OPJ_BYTE ** p_data,
OPJ_UINT32 p_nb_comp, OPJ_UINT32 p_nb_comp,
OPJ_UINT32 is_signed); OPJ_UINT32 is_signed);
/** /**
FIXME DOC FIXME DOC
@param pDecodingData MCT data @param pDecodingData MCT data
@ -124,11 +124,11 @@ FIXME DOC
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/ */
OPJ_BOOL opj_mct_decode_custom( OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
OPJ_UINT32 n, OPJ_UINT32 n,
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned); OPJ_UINT32 isSigned);
/** /**
FIXME DOC FIXME DOC
@param pNorms MCT data @param pNorms MCT data

View File

@ -100,100 +100,100 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc);
/* This array defines all the possible states for a context. */ /* This array defines all the possible states for a context. */
/* </summary> */ /* </summary> */
static opj_mqc_state_t mqc_states[47 * 2] = { static opj_mqc_state_t mqc_states[47 * 2] = {
{0x5601, 0, &mqc_states[2], &mqc_states[3]}, {0x5601, 0, &mqc_states[2], &mqc_states[3]},
{0x5601, 1, &mqc_states[3], &mqc_states[2]}, {0x5601, 1, &mqc_states[3], &mqc_states[2]},
{0x3401, 0, &mqc_states[4], &mqc_states[12]}, {0x3401, 0, &mqc_states[4], &mqc_states[12]},
{0x3401, 1, &mqc_states[5], &mqc_states[13]}, {0x3401, 1, &mqc_states[5], &mqc_states[13]},
{0x1801, 0, &mqc_states[6], &mqc_states[18]}, {0x1801, 0, &mqc_states[6], &mqc_states[18]},
{0x1801, 1, &mqc_states[7], &mqc_states[19]}, {0x1801, 1, &mqc_states[7], &mqc_states[19]},
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, {0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, {0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
{0x0521, 0, &mqc_states[10], &mqc_states[58]}, {0x0521, 0, &mqc_states[10], &mqc_states[58]},
{0x0521, 1, &mqc_states[11], &mqc_states[59]}, {0x0521, 1, &mqc_states[11], &mqc_states[59]},
{0x0221, 0, &mqc_states[76], &mqc_states[66]}, {0x0221, 0, &mqc_states[76], &mqc_states[66]},
{0x0221, 1, &mqc_states[77], &mqc_states[67]}, {0x0221, 1, &mqc_states[77], &mqc_states[67]},
{0x5601, 0, &mqc_states[14], &mqc_states[13]}, {0x5601, 0, &mqc_states[14], &mqc_states[13]},
{0x5601, 1, &mqc_states[15], &mqc_states[12]}, {0x5601, 1, &mqc_states[15], &mqc_states[12]},
{0x5401, 0, &mqc_states[16], &mqc_states[28]}, {0x5401, 0, &mqc_states[16], &mqc_states[28]},
{0x5401, 1, &mqc_states[17], &mqc_states[29]}, {0x5401, 1, &mqc_states[17], &mqc_states[29]},
{0x4801, 0, &mqc_states[18], &mqc_states[28]}, {0x4801, 0, &mqc_states[18], &mqc_states[28]},
{0x4801, 1, &mqc_states[19], &mqc_states[29]}, {0x4801, 1, &mqc_states[19], &mqc_states[29]},
{0x3801, 0, &mqc_states[20], &mqc_states[28]}, {0x3801, 0, &mqc_states[20], &mqc_states[28]},
{0x3801, 1, &mqc_states[21], &mqc_states[29]}, {0x3801, 1, &mqc_states[21], &mqc_states[29]},
{0x3001, 0, &mqc_states[22], &mqc_states[34]}, {0x3001, 0, &mqc_states[22], &mqc_states[34]},
{0x3001, 1, &mqc_states[23], &mqc_states[35]}, {0x3001, 1, &mqc_states[23], &mqc_states[35]},
{0x2401, 0, &mqc_states[24], &mqc_states[36]}, {0x2401, 0, &mqc_states[24], &mqc_states[36]},
{0x2401, 1, &mqc_states[25], &mqc_states[37]}, {0x2401, 1, &mqc_states[25], &mqc_states[37]},
{0x1c01, 0, &mqc_states[26], &mqc_states[40]}, {0x1c01, 0, &mqc_states[26], &mqc_states[40]},
{0x1c01, 1, &mqc_states[27], &mqc_states[41]}, {0x1c01, 1, &mqc_states[27], &mqc_states[41]},
{0x1601, 0, &mqc_states[58], &mqc_states[42]}, {0x1601, 0, &mqc_states[58], &mqc_states[42]},
{0x1601, 1, &mqc_states[59], &mqc_states[43]}, {0x1601, 1, &mqc_states[59], &mqc_states[43]},
{0x5601, 0, &mqc_states[30], &mqc_states[29]}, {0x5601, 0, &mqc_states[30], &mqc_states[29]},
{0x5601, 1, &mqc_states[31], &mqc_states[28]}, {0x5601, 1, &mqc_states[31], &mqc_states[28]},
{0x5401, 0, &mqc_states[32], &mqc_states[28]}, {0x5401, 0, &mqc_states[32], &mqc_states[28]},
{0x5401, 1, &mqc_states[33], &mqc_states[29]}, {0x5401, 1, &mqc_states[33], &mqc_states[29]},
{0x5101, 0, &mqc_states[34], &mqc_states[30]}, {0x5101, 0, &mqc_states[34], &mqc_states[30]},
{0x5101, 1, &mqc_states[35], &mqc_states[31]}, {0x5101, 1, &mqc_states[35], &mqc_states[31]},
{0x4801, 0, &mqc_states[36], &mqc_states[32]}, {0x4801, 0, &mqc_states[36], &mqc_states[32]},
{0x4801, 1, &mqc_states[37], &mqc_states[33]}, {0x4801, 1, &mqc_states[37], &mqc_states[33]},
{0x3801, 0, &mqc_states[38], &mqc_states[34]}, {0x3801, 0, &mqc_states[38], &mqc_states[34]},
{0x3801, 1, &mqc_states[39], &mqc_states[35]}, {0x3801, 1, &mqc_states[39], &mqc_states[35]},
{0x3401, 0, &mqc_states[40], &mqc_states[36]}, {0x3401, 0, &mqc_states[40], &mqc_states[36]},
{0x3401, 1, &mqc_states[41], &mqc_states[37]}, {0x3401, 1, &mqc_states[41], &mqc_states[37]},
{0x3001, 0, &mqc_states[42], &mqc_states[38]}, {0x3001, 0, &mqc_states[42], &mqc_states[38]},
{0x3001, 1, &mqc_states[43], &mqc_states[39]}, {0x3001, 1, &mqc_states[43], &mqc_states[39]},
{0x2801, 0, &mqc_states[44], &mqc_states[38]}, {0x2801, 0, &mqc_states[44], &mqc_states[38]},
{0x2801, 1, &mqc_states[45], &mqc_states[39]}, {0x2801, 1, &mqc_states[45], &mqc_states[39]},
{0x2401, 0, &mqc_states[46], &mqc_states[40]}, {0x2401, 0, &mqc_states[46], &mqc_states[40]},
{0x2401, 1, &mqc_states[47], &mqc_states[41]}, {0x2401, 1, &mqc_states[47], &mqc_states[41]},
{0x2201, 0, &mqc_states[48], &mqc_states[42]}, {0x2201, 0, &mqc_states[48], &mqc_states[42]},
{0x2201, 1, &mqc_states[49], &mqc_states[43]}, {0x2201, 1, &mqc_states[49], &mqc_states[43]},
{0x1c01, 0, &mqc_states[50], &mqc_states[44]}, {0x1c01, 0, &mqc_states[50], &mqc_states[44]},
{0x1c01, 1, &mqc_states[51], &mqc_states[45]}, {0x1c01, 1, &mqc_states[51], &mqc_states[45]},
{0x1801, 0, &mqc_states[52], &mqc_states[46]}, {0x1801, 0, &mqc_states[52], &mqc_states[46]},
{0x1801, 1, &mqc_states[53], &mqc_states[47]}, {0x1801, 1, &mqc_states[53], &mqc_states[47]},
{0x1601, 0, &mqc_states[54], &mqc_states[48]}, {0x1601, 0, &mqc_states[54], &mqc_states[48]},
{0x1601, 1, &mqc_states[55], &mqc_states[49]}, {0x1601, 1, &mqc_states[55], &mqc_states[49]},
{0x1401, 0, &mqc_states[56], &mqc_states[50]}, {0x1401, 0, &mqc_states[56], &mqc_states[50]},
{0x1401, 1, &mqc_states[57], &mqc_states[51]}, {0x1401, 1, &mqc_states[57], &mqc_states[51]},
{0x1201, 0, &mqc_states[58], &mqc_states[52]}, {0x1201, 0, &mqc_states[58], &mqc_states[52]},
{0x1201, 1, &mqc_states[59], &mqc_states[53]}, {0x1201, 1, &mqc_states[59], &mqc_states[53]},
{0x1101, 0, &mqc_states[60], &mqc_states[54]}, {0x1101, 0, &mqc_states[60], &mqc_states[54]},
{0x1101, 1, &mqc_states[61], &mqc_states[55]}, {0x1101, 1, &mqc_states[61], &mqc_states[55]},
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, {0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, {0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
{0x09c1, 0, &mqc_states[64], &mqc_states[58]}, {0x09c1, 0, &mqc_states[64], &mqc_states[58]},
{0x09c1, 1, &mqc_states[65], &mqc_states[59]}, {0x09c1, 1, &mqc_states[65], &mqc_states[59]},
{0x08a1, 0, &mqc_states[66], &mqc_states[60]}, {0x08a1, 0, &mqc_states[66], &mqc_states[60]},
{0x08a1, 1, &mqc_states[67], &mqc_states[61]}, {0x08a1, 1, &mqc_states[67], &mqc_states[61]},
{0x0521, 0, &mqc_states[68], &mqc_states[62]}, {0x0521, 0, &mqc_states[68], &mqc_states[62]},
{0x0521, 1, &mqc_states[69], &mqc_states[63]}, {0x0521, 1, &mqc_states[69], &mqc_states[63]},
{0x0441, 0, &mqc_states[70], &mqc_states[64]}, {0x0441, 0, &mqc_states[70], &mqc_states[64]},
{0x0441, 1, &mqc_states[71], &mqc_states[65]}, {0x0441, 1, &mqc_states[71], &mqc_states[65]},
{0x02a1, 0, &mqc_states[72], &mqc_states[66]}, {0x02a1, 0, &mqc_states[72], &mqc_states[66]},
{0x02a1, 1, &mqc_states[73], &mqc_states[67]}, {0x02a1, 1, &mqc_states[73], &mqc_states[67]},
{0x0221, 0, &mqc_states[74], &mqc_states[68]}, {0x0221, 0, &mqc_states[74], &mqc_states[68]},
{0x0221, 1, &mqc_states[75], &mqc_states[69]}, {0x0221, 1, &mqc_states[75], &mqc_states[69]},
{0x0141, 0, &mqc_states[76], &mqc_states[70]}, {0x0141, 0, &mqc_states[76], &mqc_states[70]},
{0x0141, 1, &mqc_states[77], &mqc_states[71]}, {0x0141, 1, &mqc_states[77], &mqc_states[71]},
{0x0111, 0, &mqc_states[78], &mqc_states[72]}, {0x0111, 0, &mqc_states[78], &mqc_states[72]},
{0x0111, 1, &mqc_states[79], &mqc_states[73]}, {0x0111, 1, &mqc_states[79], &mqc_states[73]},
{0x0085, 0, &mqc_states[80], &mqc_states[74]}, {0x0085, 0, &mqc_states[80], &mqc_states[74]},
{0x0085, 1, &mqc_states[81], &mqc_states[75]}, {0x0085, 1, &mqc_states[81], &mqc_states[75]},
{0x0049, 0, &mqc_states[82], &mqc_states[76]}, {0x0049, 0, &mqc_states[82], &mqc_states[76]},
{0x0049, 1, &mqc_states[83], &mqc_states[77]}, {0x0049, 1, &mqc_states[83], &mqc_states[77]},
{0x0025, 0, &mqc_states[84], &mqc_states[78]}, {0x0025, 0, &mqc_states[84], &mqc_states[78]},
{0x0025, 1, &mqc_states[85], &mqc_states[79]}, {0x0025, 1, &mqc_states[85], &mqc_states[79]},
{0x0015, 0, &mqc_states[86], &mqc_states[80]}, {0x0015, 0, &mqc_states[86], &mqc_states[80]},
{0x0015, 1, &mqc_states[87], &mqc_states[81]}, {0x0015, 1, &mqc_states[87], &mqc_states[81]},
{0x0009, 0, &mqc_states[88], &mqc_states[82]}, {0x0009, 0, &mqc_states[88], &mqc_states[82]},
{0x0009, 1, &mqc_states[89], &mqc_states[83]}, {0x0009, 1, &mqc_states[89], &mqc_states[83]},
{0x0005, 0, &mqc_states[90], &mqc_states[84]}, {0x0005, 0, &mqc_states[90], &mqc_states[84]},
{0x0005, 1, &mqc_states[91], &mqc_states[85]}, {0x0005, 1, &mqc_states[91], &mqc_states[85]},
{0x0001, 0, &mqc_states[90], &mqc_states[86]}, {0x0001, 0, &mqc_states[90], &mqc_states[86]},
{0x0001, 1, &mqc_states[91], &mqc_states[87]}, {0x0001, 1, &mqc_states[91], &mqc_states[87]},
{0x5601, 0, &mqc_states[92], &mqc_states[92]}, {0x5601, 0, &mqc_states[92], &mqc_states[92]},
{0x5601, 1, &mqc_states[93], &mqc_states[93]}, {0x5601, 1, &mqc_states[93], &mqc_states[93]},
}; };
/* /*
@ -202,155 +202,165 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
========================================================== ==========================================================
*/ */
static void opj_mqc_byteout(opj_mqc_t *mqc) { static void opj_mqc_byteout(opj_mqc_t *mqc)
if (*mqc->bp == 0xff) { {
mqc->bp++; if (*mqc->bp == 0xff) {
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->bp++;
mqc->c &= 0xfffff; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->ct = 7; mqc->c &= 0xfffff;
} else { mqc->ct = 7;
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ } else {
mqc->bp++; if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->bp++;
mqc->c &= 0x7ffff; *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->ct = 8; mqc->c &= 0x7ffff;
} else { mqc->ct = 8;
(*mqc->bp)++; } else {
if (*mqc->bp == 0xff) { (*mqc->bp)++;
mqc->c &= 0x7ffffff; if (*mqc->bp == 0xff) {
mqc->bp++; mqc->c &= 0x7ffffff;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->bp++;
mqc->c &= 0xfffff; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->ct = 7; mqc->c &= 0xfffff;
} else { mqc->ct = 7;
mqc->bp++; } else {
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->bp++;
mqc->c &= 0x7ffff; *mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->ct = 8; mqc->c &= 0x7ffff;
} mqc->ct = 8;
} }
} }
}
} }
static void opj_mqc_renorme(opj_mqc_t *mqc) { static void opj_mqc_renorme(opj_mqc_t *mqc)
do { {
mqc->a <<= 1; do {
mqc->c <<= 1; mqc->a <<= 1;
mqc->ct--; mqc->c <<= 1;
if (mqc->ct == 0) { mqc->ct--;
opj_mqc_byteout(mqc); if (mqc->ct == 0) {
} opj_mqc_byteout(mqc);
} while ((mqc->a & 0x8000) == 0); }
} while ((mqc->a & 0x8000) == 0);
} }
static void opj_mqc_codemps(opj_mqc_t *mqc) { static void opj_mqc_codemps(opj_mqc_t *mqc)
mqc->a -= (*mqc->curctx)->qeval; {
if ((mqc->a & 0x8000) == 0) { mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) { if ((mqc->a & 0x8000) == 0) {
mqc->a = (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) {
} else { mqc->a = (*mqc->curctx)->qeval;
mqc->c += (*mqc->curctx)->qeval; } else {
} mqc->c += (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nmps; }
opj_mqc_renorme(mqc); *mqc->curctx = (*mqc->curctx)->nmps;
} else { opj_mqc_renorme(mqc);
mqc->c += (*mqc->curctx)->qeval; } else {
} mqc->c += (*mqc->curctx)->qeval;
}
} }
static void opj_mqc_codelps(opj_mqc_t *mqc) { static void opj_mqc_codelps(opj_mqc_t *mqc)
mqc->a -= (*mqc->curctx)->qeval; {
if (mqc->a < (*mqc->curctx)->qeval) { mqc->a -= (*mqc->curctx)->qeval;
mqc->c += (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) {
} else { mqc->c += (*mqc->curctx)->qeval;
mqc->a = (*mqc->curctx)->qeval; } else {
} mqc->a = (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nlps; }
opj_mqc_renorme(mqc); *mqc->curctx = (*mqc->curctx)->nlps;
opj_mqc_renorme(mqc);
} }
static void opj_mqc_setbits(opj_mqc_t *mqc) { static void opj_mqc_setbits(opj_mqc_t *mqc)
OPJ_UINT32 tempc = mqc->c + mqc->a; {
mqc->c |= 0xffff; OPJ_UINT32 tempc = mqc->c + mqc->a;
if (mqc->c >= tempc) { mqc->c |= 0xffff;
mqc->c -= 0x8000; if (mqc->c >= tempc) {
} mqc->c -= 0x8000;
}
} }
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) { static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
OPJ_INT32 d; {
if (mqc->a < (*mqc->curctx)->qeval) { OPJ_INT32 d;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); if (mqc->a < (*mqc->curctx)->qeval) {
*mqc->curctx = (*mqc->curctx)->nlps; d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
} else { *mqc->curctx = (*mqc->curctx)->nlps;
d = (OPJ_INT32)(*mqc->curctx)->mps; } else {
*mqc->curctx = (*mqc->curctx)->nmps; d = (OPJ_INT32)(*mqc->curctx)->mps;
} *mqc->curctx = (*mqc->curctx)->nmps;
}
return d; return d;
} }
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) { static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
OPJ_INT32 d; {
if (mqc->a < (*mqc->curctx)->qeval) { OPJ_INT32 d;
mqc->a = (*mqc->curctx)->qeval; if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(*mqc->curctx)->mps; mqc->a = (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nmps; d = (OPJ_INT32)(*mqc->curctx)->mps;
} else { *mqc->curctx = (*mqc->curctx)->nmps;
mqc->a = (*mqc->curctx)->qeval; } else {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); mqc->a = (*mqc->curctx)->qeval;
*mqc->curctx = (*mqc->curctx)->nlps; d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
} *mqc->curctx = (*mqc->curctx)->nlps;
}
return d; return d;
} }
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) { static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
unsigned int i = *((unsigned int *) mqc->bp); {
mqc->c += i & 0xffff00; unsigned int i = *((unsigned int *) mqc->bp);
mqc->ct = i & 0x0f; mqc->c += i & 0xffff00;
mqc->bp += (i >> 2) & 0x04; mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
} }
#else #else
static void opj_mqc_bytein(opj_mqc_t *const mqc) { static void opj_mqc_bytein(opj_mqc_t *const mqc)
if (mqc->bp != mqc->end) { {
OPJ_UINT32 c; if (mqc->bp != mqc->end) {
if (mqc->bp + 1 != mqc->end) { OPJ_UINT32 c;
c = *(mqc->bp + 1); if (mqc->bp + 1 != mqc->end) {
} else { c = *(mqc->bp + 1);
c = 0xff; } else {
} c = 0xff;
if (*mqc->bp == 0xff) { }
if (c > 0x8f) { if (*mqc->bp == 0xff) {
mqc->c += 0xff00; if (c > 0x8f) {
mqc->ct = 8; mqc->c += 0xff00;
} else { mqc->ct = 8;
mqc->bp++; } else {
mqc->c += c << 9; mqc->bp++;
mqc->ct = 7; mqc->c += c << 9;
} mqc->ct = 7;
} else { }
mqc->bp++; } else {
mqc->c += c << 8; mqc->bp++;
mqc->ct = 8; mqc->c += c << 8;
} mqc->ct = 8;
} else { }
mqc->c += 0xff00; } else {
mqc->ct = 8; mqc->c += 0xff00;
} mqc->ct = 8;
}
} }
#endif #endif
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) { static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
do { {
if (mqc->ct == 0) { do {
opj_mqc_bytein(mqc); if (mqc->ct == 0) {
} opj_mqc_bytein(mqc);
mqc->a <<= 1; }
mqc->c <<= 1; mqc->a <<= 1;
mqc->ct--; mqc->c <<= 1;
} while (mqc->a < 0x8000); mqc->ct--;
} while (mqc->a < 0x8000);
} }
/* /*
@ -359,182 +369,197 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
========================================================== ==========================================================
*/ */
opj_mqc_t* opj_mqc_create(void) { opj_mqc_t* opj_mqc_create(void)
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc) { if (mqc) {
mqc->buffer = NULL; mqc->buffer = NULL;
} }
#endif #endif
return mqc; return mqc;
} }
void opj_mqc_destroy(opj_mqc_t *mqc) { void opj_mqc_destroy(opj_mqc_t *mqc)
if(mqc) { {
if(mqc) {
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc->buffer) { if (mqc->buffer) {
opj_free(mqc->buffer); opj_free(mqc->buffer);
} }
#endif #endif
opj_free(mqc); opj_free(mqc);
} }
} }
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
const ptrdiff_t diff = mqc->bp - mqc->start; {
const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0 #if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
#endif #endif
return (OPJ_UINT32)diff; return (OPJ_UINT32)diff;
} }
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp)
{
/* TODO MSD: need to take a look to the v2 version */ /* TODO MSD: need to take a look to the v2 version */
opj_mqc_setcurctx(mqc, 0); opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
mqc->c = 0; mqc->c = 0;
mqc->bp = bp - 1; mqc->bp = bp - 1;
mqc->ct = 12; mqc->ct = 12;
if (*mqc->bp == 0xff) { if (*mqc->bp == 0xff) {
mqc->ct = 13; mqc->ct = 13;
} }
mqc->start = bp; mqc->start = bp;
} }
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
if ((*mqc->curctx)->mps == d) { {
opj_mqc_codemps(mqc); if ((*mqc->curctx)->mps == d) {
} else { opj_mqc_codemps(mqc);
opj_mqc_codelps(mqc); } else {
} opj_mqc_codelps(mqc);
}
} }
void opj_mqc_flush(opj_mqc_t *mqc) { void opj_mqc_flush(opj_mqc_t *mqc)
opj_mqc_setbits(mqc); {
mqc->c <<= mqc->ct; opj_mqc_setbits(mqc);
opj_mqc_byteout(mqc); mqc->c <<= mqc->ct;
mqc->c <<= mqc->ct; opj_mqc_byteout(mqc);
opj_mqc_byteout(mqc); mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
if (*mqc->bp != 0xff) { if (*mqc->bp != 0xff) {
mqc->bp++; mqc->bp++;
} }
} }
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
mqc->c = 0; {
mqc->ct = 8; mqc->c = 0;
/*if (*mqc->bp == 0xff) { mqc->ct = 8;
mqc->ct = 7; /*if (*mqc->bp == 0xff) {
mqc->ct = 7;
} */ } */
} }
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
mqc->ct--; {
mqc->c = mqc->c + (d << mqc->ct); mqc->ct--;
if (mqc->ct == 0) { mqc->c = mqc->c + (d << mqc->ct);
mqc->bp++; if (mqc->ct == 0) {
*mqc->bp = (OPJ_BYTE)mqc->c; mqc->bp++;
mqc->ct = 8; *mqc->bp = (OPJ_BYTE)mqc->c;
if (*mqc->bp == 0xff) { mqc->ct = 8;
mqc->ct = 7; if (*mqc->bp == 0xff) {
} mqc->ct = 7;
mqc->c = 0; }
} mqc->c = 0;
}
} }
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
OPJ_BYTE bit_padding; {
OPJ_BYTE bit_padding;
bit_padding = 0; bit_padding = 0;
if (mqc->ct != 0) { if (mqc->ct != 0) {
while (mqc->ct > 0) { while (mqc->ct > 0) {
mqc->ct--; mqc->ct--;
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct); mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
bit_padding = (bit_padding + 1) & 0x01; bit_padding = (bit_padding + 1) & 0x01;
} }
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)mqc->c; *mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8; mqc->ct = 8;
mqc->c = 0; mqc->c = 0;
} }
return 1; return 1;
} }
void opj_mqc_reset_enc(opj_mqc_t *mqc) { void opj_mqc_reset_enc(opj_mqc_t *mqc)
opj_mqc_resetstates(mqc); {
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
} }
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
OPJ_UINT32 correction = 1; {
OPJ_UINT32 correction = 1;
/* <flush part> */ /* <flush part> */
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
mqc->c <<= mqc->ct; mqc->c <<= mqc->ct;
while (n > 0) { while (n > 0) {
opj_mqc_byteout(mqc); opj_mqc_byteout(mqc);
n -= (OPJ_INT32)mqc->ct; n -= (OPJ_INT32)mqc->ct;
mqc->c <<= mqc->ct; mqc->c <<= mqc->ct;
} }
opj_mqc_byteout(mqc); opj_mqc_byteout(mqc);
return correction; return correction;
} }
void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
/* <Re-init part> */ {
opj_mqc_setcurctx(mqc, 0); /* <Re-init part> */
mqc->a = 0x8000; opj_mqc_setcurctx(mqc, 0);
mqc->c = 0; mqc->a = 0x8000;
mqc->ct = 12; mqc->c = 0;
mqc->bp--; mqc->ct = 12;
if (*mqc->bp == 0xff) { mqc->bp--;
mqc->ct = 13; if (*mqc->bp == 0xff) {
} mqc->ct = 13;
}
} }
void opj_mqc_erterm_enc(opj_mqc_t *mqc) { void opj_mqc_erterm_enc(opj_mqc_t *mqc)
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); {
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) { while (k > 0) {
mqc->c <<= mqc->ct; mqc->c <<= mqc->ct;
mqc->ct = 0; mqc->ct = 0;
opj_mqc_byteout(mqc); opj_mqc_byteout(mqc);
k -= (OPJ_INT32)mqc->ct; k -= (OPJ_INT32)mqc->ct;
} }
if (*mqc->bp != 0xff) { if (*mqc->bp != 0xff) {
opj_mqc_byteout(mqc); opj_mqc_byteout(mqc);
} }
} }
void opj_mqc_segmark_enc(opj_mqc_t *mqc) { void opj_mqc_segmark_enc(opj_mqc_t *mqc)
OPJ_UINT32 i; {
opj_mqc_setcurctx(mqc, 18); OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) { for (i = 1; i < 5; i++) {
opj_mqc_encode(mqc, i % 2); opj_mqc_encode(mqc, i % 2);
} }
} }
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) { OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
opj_mqc_setcurctx(mqc, 0); {
mqc->start = bp; opj_mqc_setcurctx(mqc, 0);
mqc->end = bp + len; mqc->start = bp;
mqc->bp = bp; mqc->end = bp + len;
if (len==0) mqc->c = 0xff << 16; mqc->bp = bp;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16); if (len==0) mqc->c = 0xff << 16;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16);
#ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */ #ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */
{ {
OPJ_UINT32 c; OPJ_UINT32 c;
OPJ_UINT32 *ip; OPJ_UINT32 *ip;
OPJ_BYTE *end = mqc->end - 1; OPJ_BYTE *end = mqc->end - 1;
void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32)); void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32));
if (! new_buffer) { if (! new_buffer) {
opj_free(mqc->buffer); opj_free(mqc->buffer);
@ -545,70 +570,73 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
ip = (OPJ_UINT32 *) mqc->buffer; ip = (OPJ_UINT32 *) mqc->buffer;
while (bp < end) { while (bp < end) {
c = *(bp + 1); c = *(bp + 1);
if (*bp == 0xff) { if (*bp == 0xff) {
if (c > 0x8f) { if (c > 0x8f) {
break; break;
} else { } else {
*ip = 0x00000017 | (c << 9); *ip = 0x00000017 | (c << 9);
} }
} else { } else {
*ip = 0x00000018 | (c << 8); *ip = 0x00000018 | (c << 8);
} }
bp++; bp++;
ip++; ip++;
} }
/* Handle last byte of data */ /* Handle last byte of data */
c = 0xff; c = 0xff;
if (*bp == 0xff) { if (*bp == 0xff) {
*ip = 0x0000ff18; *ip = 0x0000ff18;
} else { } else {
bp++; bp++;
*ip = 0x00000018 | (c << 8); *ip = 0x00000018 | (c << 8);
} }
ip++; ip++;
*ip = 0x0000ff08; *ip = 0x0000ff08;
mqc->bp = mqc->buffer; mqc->bp = mqc->buffer;
} }
#endif #endif
opj_mqc_bytein(mqc); opj_mqc_bytein(mqc);
mqc->c <<= 7; mqc->c <<= 7;
mqc->ct -= 7; mqc->ct -= 7;
mqc->a = 0x8000; mqc->a = 0x8000;
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) { OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
OPJ_INT32 d; {
mqc->a -= (*mqc->curctx)->qeval; OPJ_INT32 d;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { mqc->a -= (*mqc->curctx)->qeval;
d = opj_mqc_lpsexchange(mqc); if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
opj_mqc_renormd(mqc); d = opj_mqc_lpsexchange(mqc);
} else { opj_mqc_renormd(mqc);
mqc->c -= (*mqc->curctx)->qeval << 16; } else {
if ((mqc->a & 0x8000) == 0) { mqc->c -= (*mqc->curctx)->qeval << 16;
d = opj_mqc_mpsexchange(mqc); if ((mqc->a & 0x8000) == 0) {
opj_mqc_renormd(mqc); d = opj_mqc_mpsexchange(mqc);
} else { opj_mqc_renormd(mqc);
d = (OPJ_INT32)(*mqc->curctx)->mps; } else {
} d = (OPJ_INT32)(*mqc->curctx)->mps;
} }
}
return d; return d;
} }
void opj_mqc_resetstates(opj_mqc_t *mqc) { void opj_mqc_resetstates(opj_mqc_t *mqc)
OPJ_UINT32 i; {
for (i = 0; i < MQC_NUMCTXS; i++) { OPJ_UINT32 i;
mqc->ctxs[i] = mqc_states; for (i = 0; i < MQC_NUMCTXS; i++) {
} mqc->ctxs[i] = mqc_states;
}
} }
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) { void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; {
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
} }

View File

@ -53,14 +53,14 @@ in MQC.C are used by some function in T1.C.
This struct defines the state of a context. This struct defines the state of a context.
*/ */
typedef struct opj_mqc_state { typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
OPJ_UINT32 qeval; OPJ_UINT32 qeval;
/** the Most Probable Symbol (0 or 1) */ /** the Most Probable Symbol (0 or 1) */
OPJ_UINT32 mps; OPJ_UINT32 mps;
/** next state if the next encoded symbol is the MPS */ /** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps; struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */ /** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps; struct opj_mqc_state *nlps;
} opj_mqc_state_t; } opj_mqc_state_t;
#define MQC_NUMCTXS 19 #define MQC_NUMCTXS 19
@ -69,16 +69,16 @@ typedef struct opj_mqc_state {
MQ coder MQ coder
*/ */
typedef struct opj_mqc { typedef struct opj_mqc {
OPJ_UINT32 c; OPJ_UINT32 c;
OPJ_UINT32 a; OPJ_UINT32 a;
OPJ_UINT32 ct; OPJ_UINT32 ct;
OPJ_BYTE *bp; OPJ_BYTE *bp;
OPJ_BYTE *start; OPJ_BYTE *start;
OPJ_BYTE *end; OPJ_BYTE *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS]; opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx; opj_mqc_state_t **curctx;
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
unsigned char *buffer; unsigned char *buffer;
#endif #endif
} opj_mqc_t; } opj_mqc_t;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -39,24 +39,25 @@
#include <sys/times.h> #include <sys/times.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
OPJ_FLOAT64 opj_clock(void) { OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32 #ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */ /* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ; QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */ /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */ /* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ; QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ; return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
#else #else
/* Unix or Linux: use resource usage */ /* Unix or Linux: use resource usage */
struct rusage t; struct rusage t;
OPJ_FLOAT64 procTime; OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */ /* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t); getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */ /* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */ /* (2a) Get the seconds */
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec); procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */ /* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;

View File

@ -39,16 +39,13 @@
/** /**
* Main codec handler used for compression or decompression. * Main codec handler used for compression or decompression.
*/ */
typedef struct opj_codec_private typedef struct opj_codec_private {
{
/** FIXME DOC */ /** FIXME DOC */
union union {
{
/** /**
* Decompression handler. * Decompression handler.
*/ */
struct opj_decompression struct opj_decompression {
{
/** Main header reading function handler */ /** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio, OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec, void * p_codec,
@ -111,15 +108,14 @@ typedef struct opj_codec_private
/** Set the decoded resolution factor */ /** Set the decoded resolution factor */
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec, OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
OPJ_UINT32 res_factor, OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager); opj_event_mgr_t * p_manager);
} m_decompression; } m_decompression;
/** /**
* Compression handler. FIXME DOC * Compression handler. FIXME DOC
*/ */
struct opj_compression struct opj_compression {
{
OPJ_BOOL (* opj_start_compress) ( void *p_codec, OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio, struct opj_stream_private * cio,
struct opj_image * p_image, struct opj_image * p_image,

View File

@ -70,11 +70,11 @@
#if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \ #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
!(defined(_MSC_VER) && _MSC_VER < 1400) && \ !(defined(_MSC_VER) && _MSC_VER < 1400) && \
!(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800) !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
/* /*
Windows '95 and Borland C do not support _lseeki64 Windows '95 and Borland C do not support _lseeki64
Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release. Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release.
Without these interfaces, files over 2GB in size are not supported for Windows. Without these interfaces, files over 2GB in size are not supported for Windows.
*/ */
# define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence) # define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
# define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff) # define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
# define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream) # define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream)
@ -104,18 +104,18 @@
/* Ignore GCC attributes if this is not GCC */ /* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */ #define __attribute__(x) /* __attribute__(x) */
#endif #endif
/* Are restricted pointers available? (C99) */ /* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L) #if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */ /* Not a C99 compiler */
#ifdef __GNUC__ #ifdef __GNUC__
#define restrict __restrict__ #define restrict __restrict__
#else #else
#define restrict /* restrict */ #define restrict /* restrict */
#endif #endif
#endif #endif
@ -123,47 +123,50 @@
/* MSVC before 2013 and Borland C do not have lrintf */ /* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <intrin.h> #include <intrin.h>
static INLINE long opj_lrintf(float f){ static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64 #ifdef _M_X64
return _mm_cvt_ss2si(_mm_load_ss(&f)); return _mm_cvt_ss2si(_mm_load_ss(&f));
/* commented out line breaks many tests */ /* commented out line breaks many tests */
/* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */ /* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
#elif defined(_M_IX86) #elif defined(_M_IX86)
int i; int i;
_asm{ _asm{
fld f fld f
fistp i fistp i
}; };
return i; return i;
#else #else
return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f)); return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
#endif #endif
} }
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
static INLINE long opj_lrintf(float f) { static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64 #ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
#else #else
int i; int i;
_asm { _asm {
fld f fld f
fistp i fistp i
}; };
return i; return i;
#endif #endif
} }
#else #else
static INLINE long opj_lrintf(float f) { static INLINE long opj_lrintf(float f)
return lrintf(f); {
return lrintf(f);
} }
#endif #endif
#if defined(_MSC_VER) && (_MSC_VER < 1400) #if defined(_MSC_VER) && (_MSC_VER < 1400)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
/* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */ /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */

View File

@ -53,41 +53,46 @@ The functions in OPJ_INTMATH.H have for goal to realize operations on integers.
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b)
return a < b ? a : b; {
return a < b ? a : b;
} }
/** /**
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b)
return a < b ? a : b; {
return a < b ? a : b;
} }
/** /**
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b)
return (a > b) ? a : b; {
return (a > b) ? a : b;
} }
/** /**
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b)
return (a > b) ? a : b; {
return (a > b) ? a : b;
} }
/** /**
Get the saturated sum of two unsigned integers Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+b @return Returns saturated sum of a+b
*/ */
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b)
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; {
return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum; OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum;
} }
/** /**
@ -99,90 +104,99 @@ Clamp an integer inside an interval
<li>Returns min if (a < min) <li>Returns min if (a < min)
</ul> </ul>
*/ */
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) { static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
if (a < min) {
return min; if (a < min)
if (a > max) return min;
return max; if (a > max)
return a; return max;
return a;
} }
/** /**
@return Get absolute value of integer @return Get absolute value of integer
*/ */
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) { static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a)
return a < 0 ? -a : a; {
return a < 0 ? -a : a;
} }
/** /**
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b)
assert(b); {
return (a + b - 1) / b; assert(b);
return (a + b - 1) / b;
} }
/** /**
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b)
assert(b); {
return (a + b - 1) / b; assert(b);
return (a + b - 1) / b;
} }
/** /**
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b)
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); {
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
} }
/** /**
Divide a 64bits integer by a power of 2 and round upwards Divide a 64bits integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b)
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); {
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
} }
/** /**
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b)
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b); {
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
} }
/** /**
Divide an integer by a power of 2 and round downwards Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b)
return a >> b; {
return a >> b;
} }
/** /**
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) { static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a)
OPJ_INT32 l; {
for (l = 0; a > 1; l++) { OPJ_INT32 l;
a >>= 1; for (l = 0; a > 1; l++) {
} a >>= 1;
return l; }
return l;
} }
/** /**
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) { static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a)
OPJ_UINT32 l; {
for (l = 0; a > 1; ++l) OPJ_UINT32 l;
{ for (l = 0; a > 1; ++l) {
a >>= 1; a >>= 1;
} }
return l; return l;
} }
/** /**
@ -191,28 +205,30 @@ Multiply two fixed-precision rational numbers.
@param b @param b
@return Returns a * b @return Returns a * b
*/ */
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b); OPJ_INT64 temp = __emul(a, b);
#else #else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif #endif
temp += 4096; temp += 4096;
assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF); assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
return (OPJ_INT32) (temp >> 13); return (OPJ_INT32) (temp >> 13);
} }
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b); OPJ_INT64 temp = __emul(a, b);
#else #else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ; OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif #endif
temp += 4096; temp += 4096;
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF); assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1)); assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ; return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View File

@ -42,198 +42,196 @@
static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
{ {
void* ptr; void* ptr;
/* alignment shall be power of 2 */ /* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U)); assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */ /* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*)); assert( alignment >= sizeof(void*));
if (size == 0U) { /* prevent implementation defined behavior of realloc */ if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL; return NULL;
} }
#if defined(OPJ_HAVE_POSIX_MEMALIGN) #if defined(OPJ_HAVE_POSIX_MEMALIGN)
/* aligned_alloc requires c11, restrict to posix_memalign for now. Quote: /* aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
* This function was introduced in POSIX 1003.1d. Although this function is * This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems * superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */ * that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size)) if (posix_memalign (&ptr, alignment, size)) {
{ ptr = NULL;
ptr = NULL; }
} /* older linux */
/* older linux */
#elif defined(OPJ_HAVE_MEMALIGN) #elif defined(OPJ_HAVE_MEMALIGN)
ptr = memalign( alignment, size ); ptr = memalign( alignment, size );
/* _MSC_VER */ /* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC) #elif defined(OPJ_HAVE__ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment); ptr = _aligned_malloc(size, alignment);
#else #else
/* /*
* Generic aligned malloc implementation. * Generic aligned malloc implementation.
* Uses size_t offset for the integer manipulation of the pointer, * Uses size_t offset for the integer manipulation of the pointer,
* as uintptr_t is not available in C89 to do * as uintptr_t is not available in C89 to do
* bitwise operations on the pointer itself. * bitwise operations on the pointer itself.
*/ */
alignment--; alignment--;
{ {
size_t offset; size_t offset;
OPJ_UINT8 *mem; OPJ_UINT8 *mem;
/* Room for padding and extra pointer stored in front of allocated area */ /* Room for padding and extra pointer stored in front of allocated area */
size_t overhead = alignment + sizeof(void *); size_t overhead = alignment + sizeof(void *);
/* let's be extra careful */ /* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *))); assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* Avoid integer overflow */ /* Avoid integer overflow */
if (size > (SIZE_MAX - overhead)) { if (size > (SIZE_MAX - overhead)) {
return NULL; return NULL;
}
mem = (OPJ_UINT8*)malloc(size + overhead);
if (mem == NULL) {
return mem;
}
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
offset = ((alignment ^ ((size_t)(mem + sizeof(void*)) & alignment)) + 1U) & alignment;
ptr = (void *)(mem + sizeof(void*) + offset);
((void**) ptr)[-1] = mem;
} }
mem = (OPJ_UINT8*)malloc(size + overhead);
if (mem == NULL) {
return mem;
}
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
offset = ((alignment ^ ((size_t)(mem + sizeof(void*)) & alignment)) + 1U) & alignment;
ptr = (void *)(mem + sizeof(void*) + offset);
((void**) ptr)[-1] = mem;
}
#endif #endif
return ptr; return ptr;
} }
static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t new_size) static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t new_size)
{ {
void *r_ptr; void *r_ptr;
/* alignment shall be power of 2 */ /* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U)); assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */ /* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*)); assert( alignment >= sizeof(void*));
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */ if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL; return NULL;
} }
/* no portable aligned realloc */ /* no portable aligned realloc */
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN) #if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
/* glibc doc states one can mix aligned malloc with realloc */ /* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */ r_ptr = realloc( ptr, new_size ); /* fast path */
/* we simply use `size_t` to cast, since we are only interest in binary AND /* we simply use `size_t` to cast, since we are only interest in binary AND
* operator */ * operator */
if( ((size_t)r_ptr & (alignment - 1U)) != 0U ) { if( ((size_t)r_ptr & (alignment - 1U)) != 0U ) {
/* this is non-trivial to implement a portable aligned realloc, so use a /* this is non-trivial to implement a portable aligned realloc, so use a
* simple approach where we do not need a function that return the size of an * simple approach where we do not need a function that return the size of an
* allocated array (eg. _msize on Windows, malloc_size on MacOS, * allocated array (eg. _msize on Windows, malloc_size on MacOS,
* malloc_usable_size on systems with glibc) */ * malloc_usable_size on systems with glibc) */
void *a_ptr = opj_aligned_alloc_n(alignment, new_size); void *a_ptr = opj_aligned_alloc_n(alignment, new_size);
if (a_ptr != NULL) { if (a_ptr != NULL) {
memcpy(a_ptr, r_ptr, new_size); memcpy(a_ptr, r_ptr, new_size);
}
free( r_ptr );
r_ptr = a_ptr;
} }
free( r_ptr ); /* _MSC_VER */
r_ptr = a_ptr;
}
/* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC) #elif defined(OPJ_HAVE__ALIGNED_MALLOC)
r_ptr = _aligned_realloc( ptr, new_size, alignment ); r_ptr = _aligned_realloc( ptr, new_size, alignment );
#else #else
if (ptr == NULL) { if (ptr == NULL) {
return opj_aligned_alloc_n(alignment, new_size); return opj_aligned_alloc_n(alignment, new_size);
}
alignment--;
{
void *oldmem;
OPJ_UINT8 *newmem;
size_t overhead = alignment + sizeof(void *);
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* Avoid integer overflow */
if (new_size > SIZE_MAX - overhead) {
return NULL;
} }
alignment--;
{
void *oldmem;
OPJ_UINT8 *newmem;
size_t overhead = alignment + sizeof(void *);
oldmem = ((void**) ptr)[-1]; /* let's be extra careful */
newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead); assert(alignment <= (SIZE_MAX - sizeof(void *)));
if (newmem == NULL) {
return newmem; /* Avoid integer overflow */
if (new_size > SIZE_MAX - overhead) {
return NULL;
}
oldmem = ((void**) ptr)[-1];
newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead);
if (newmem == NULL) {
return newmem;
}
if (newmem == oldmem) {
r_ptr = ptr;
} else {
size_t old_offset;
size_t new_offset;
/* realloc created a new copy, realign the copied memory block */
old_offset = (size_t)((OPJ_UINT8*)ptr - (OPJ_UINT8*)oldmem);
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
new_offset = ((alignment ^ ((size_t)(newmem + sizeof(void*)) & alignment)) + 1U) & alignment;
new_offset += sizeof(void*);
r_ptr = (void *)(newmem + new_offset);
if (new_offset != old_offset) {
memmove(newmem + new_offset, newmem + old_offset, new_size);
}
((void**) r_ptr)[-1] = newmem;
}
} }
if (newmem == oldmem) {
r_ptr = ptr;
}
else {
size_t old_offset;
size_t new_offset;
/* realloc created a new copy, realign the copied memory block */
old_offset = (size_t)((OPJ_UINT8*)ptr - (OPJ_UINT8*)oldmem);
/* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */
/* Use the fact that alignment + 1U is a power of 2 */
new_offset = ((alignment ^ ((size_t)(newmem + sizeof(void*)) & alignment)) + 1U) & alignment;
new_offset += sizeof(void*);
r_ptr = (void *)(newmem + new_offset);
if (new_offset != old_offset) {
memmove(newmem + new_offset, newmem + old_offset, new_size);
}
((void**) r_ptr)[-1] = newmem;
}
}
#endif #endif
return r_ptr; return r_ptr;
} }
void * opj_malloc(size_t size) void * opj_malloc(size_t size)
{ {
if (size == 0U) { /* prevent implementation defined behavior of realloc */ if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL; return NULL;
} }
return malloc(size); return malloc(size);
} }
void * opj_calloc(size_t num, size_t size) void * opj_calloc(size_t num, size_t size)
{ {
if (size == 0U) { /* prevent implementation defined behavior of realloc */ if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL; return NULL;
} }
/* according to C89 standard, num == 0 shall return a valid pointer */ /* according to C89 standard, num == 0 shall return a valid pointer */
return calloc(num, size); return calloc(num, size);
} }
void *opj_aligned_malloc(size_t size) void *opj_aligned_malloc(size_t size)
{ {
return opj_aligned_alloc_n(16U, size); return opj_aligned_alloc_n(16U, size);
} }
void * opj_aligned_realloc(void *ptr, size_t size) void * opj_aligned_realloc(void *ptr, size_t size)
{ {
return opj_aligned_realloc_n(ptr, 16U, size); return opj_aligned_realloc_n(ptr, 16U, size);
} }
void opj_aligned_free(void* ptr) void opj_aligned_free(void* ptr)
{ {
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN) #if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
free( ptr ); free( ptr );
#elif defined(OPJ_HAVE__ALIGNED_MALLOC) #elif defined(OPJ_HAVE__ALIGNED_MALLOC)
_aligned_free( ptr ); _aligned_free( ptr );
#else #else
/* Generic implementation has malloced pointer stored in front of used area */ /* Generic implementation has malloced pointer stored in front of used area */
if (ptr != NULL) { if (ptr != NULL) {
free(((void**) ptr)[-1]); free(((void**) ptr)[-1]);
} }
#endif #endif
} }
void * opj_realloc(void *ptr, size_t new_size) void * opj_realloc(void *ptr, size_t new_size)
{ {
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */ if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL; return NULL;
} }
return realloc(ptr, new_size); return realloc(ptr, new_size);
} }
void opj_free(void *ptr) void opj_free(void *ptr)
{ {
free(ptr); free(ptr);
} }

View File

@ -49,143 +49,142 @@
*/ */
int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_UINT32 len, compno, i; OPJ_UINT32 len, compno, i;
opj_jp2_box_t *box; opj_jp2_box_t *box;
OPJ_OFF_T lenp = 0; OPJ_OFF_T lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for( i=0;i<2;i++){ for( i=0; i<2; i++) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */ opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager ); opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager );
for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++){ for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++) {
box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager); box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX; box[compno].type = JPIP_FAIX;
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, 4, p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek( cio, lenp+len,p_manager);
} }
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); opj_free(box);
opj_stream_seek(cio, 4, p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek( cio, lenp+len,p_manager);
}
opj_free(box); return (int)len;
return (int)len;
} }
int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8 */ OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
opj_tile_info_t *tile_Idx; opj_tile_info_t *tile_Idx;
opj_packet_info_t packet; opj_packet_info_t packet;
int resno, precno, layno; int resno, precno, layno;
OPJ_UINT32 num_packet; OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers; int numOfres, numOfprec, numOflayers;
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
OPJ_UINT32 len; OPJ_UINT32 len;
packet.end_ph_pos = packet.start_pos = -1; packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */ (void)EPHused; /* unused ? */
if( j2klen > pow( 2, 32)){ if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = 1; version = 1;
} } else {
else{ size_of_coding = 4;
size_of_coding = 4; version = 0;
version = 0;
}
lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,1,p_manager);
nmax = 0;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){
tile_Idx = &cstr_info.tile[ tileno];
num_packet = 0;
numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++){
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++){
numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++){
switch ( cstr_info.prog){
case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RLCP:
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RPCL:
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
break;
case OPJ_PCRL:
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
break;
case OPJ_CPRL:
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
break;
default:
fprintf( stderr, "failed to ppix indexing\n");
}
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_ph_pos-packet.start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
}
} }
/* PADDING */ lenp = opj_stream_tell(cio);
while( num_packet < nmax){ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */ opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,1,p_manager);
num_packet++;
nmax = 0;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++) {
tile_Idx = &cstr_info.tile[ tileno];
num_packet = 0;
numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++) {
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++) {
numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++) {
switch ( cstr_info.prog) {
case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RLCP:
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RPCL:
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
break;
case OPJ_PCRL:
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
break;
case OPJ_CPRL:
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
break;
default:
fprintf( stderr, "failed to ppix indexing\n");
}
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_ph_pos-packet.start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
}
}
/* PADDING */
while( num_packet < nmax) {
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
} }
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
return (int)len; return (int)len;
} }

File diff suppressed because it is too large Load Diff

View File

@ -53,58 +53,58 @@ by some function in T2.C.
FIXME DOC FIXME DOC
*/ */
typedef struct opj_pi_resolution { typedef struct opj_pi_resolution {
OPJ_UINT32 pdx, pdy; OPJ_UINT32 pdx, pdy;
OPJ_UINT32 pw, ph; OPJ_UINT32 pw, ph;
} opj_pi_resolution_t; } opj_pi_resolution_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_pi_comp { typedef struct opj_pi_comp {
OPJ_UINT32 dx, dy; OPJ_UINT32 dx, dy;
/** number of resolution levels */ /** number of resolution levels */
OPJ_UINT32 numresolutions; OPJ_UINT32 numresolutions;
opj_pi_resolution_t *resolutions; opj_pi_resolution_t *resolutions;
} opj_pi_comp_t; } opj_pi_comp_t;
/** /**
Packet iterator Packet iterator
*/ */
typedef struct opj_pi_iterator { typedef struct opj_pi_iterator {
/** Enabling Tile part generation*/ /** Enabling Tile part generation*/
OPJ_BYTE tp_on; OPJ_BYTE tp_on;
/** precise if the packet has been already used (useful for progression order change) */ /** precise if the packet has been already used (useful for progression order change) */
OPJ_INT16 *include; OPJ_INT16 *include;
/** layer step used to localize the packet in the include vector */ /** layer step used to localize the packet in the include vector */
OPJ_UINT32 step_l; OPJ_UINT32 step_l;
/** resolution step used to localize the packet in the include vector */ /** resolution step used to localize the packet in the include vector */
OPJ_UINT32 step_r; OPJ_UINT32 step_r;
/** component step used to localize the packet in the include vector */ /** component step used to localize the packet in the include vector */
OPJ_UINT32 step_c; OPJ_UINT32 step_c;
/** precinct step used to localize the packet in the include vector */ /** precinct step used to localize the packet in the include vector */
OPJ_UINT32 step_p; OPJ_UINT32 step_p;
/** component that identify the packet */ /** component that identify the packet */
OPJ_UINT32 compno; OPJ_UINT32 compno;
/** resolution that identify the packet */ /** resolution that identify the packet */
OPJ_UINT32 resno; OPJ_UINT32 resno;
/** precinct that identify the packet */ /** precinct that identify the packet */
OPJ_UINT32 precno; OPJ_UINT32 precno;
/** layer that identify the packet */ /** layer that identify the packet */
OPJ_UINT32 layno; OPJ_UINT32 layno;
/** 0 if the first packet */ /** 0 if the first packet */
OPJ_BOOL first; OPJ_BOOL first;
/** progression order change information */ /** progression order change information */
opj_poc_t poc; opj_poc_t poc;
/** number of components in the image */ /** number of components in the image */
OPJ_UINT32 numcomps; OPJ_UINT32 numcomps;
/** Components*/ /** Components*/
opj_pi_comp_t *comps; opj_pi_comp_t *comps;
/** FIXME DOC*/ /** FIXME DOC*/
OPJ_INT32 tx0, ty0, tx1, ty1; OPJ_INT32 tx0, ty0, tx1, ty1;
/** FIXME DOC*/ /** FIXME DOC*/
OPJ_INT32 x, y; OPJ_INT32 x, y;
/** FIXME DOC*/ /** FIXME DOC*/
OPJ_UINT32 dx, dy; OPJ_UINT32 dx, dy;
} opj_pi_iterator_t; } opj_pi_iterator_t;
/** @name Exported functions */ /** @name Exported functions */
@ -121,9 +121,9 @@ typedef struct opj_pi_iterator {
* @return a list of packet iterator that points to the first packet of the tile (not true). * @return a list of packet iterator that points to the first packet of the tile (not true).
*/ */
opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image, opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image,
opj_cp_t *cp, opj_cp_t *cp,
OPJ_UINT32 tileno, OPJ_UINT32 tileno,
J2K_T2_MODE t2_mode); J2K_T2_MODE t2_mode);
/** /**
* Updates the encoding parameters of the codec. * Updates the encoding parameters of the codec.

View File

@ -49,146 +49,145 @@
int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int compno, i; int compno, i;
opj_jp2_box_t *box; opj_jp2_box_t *box;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
OPJ_UINT32 len; OPJ_UINT32 len;
/* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */ /* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
lenp = -1; lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for (i=0;i<2;i++){ for (i=0; i<2; i++) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
lenp = (OPJ_UINT32)(opj_stream_tell(cio)); lenp = (OPJ_UINT32)(opj_stream_tell(cio));
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */ opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager); opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager);
for (compno=0; compno<cstr_info.numcomps; compno++){ for (compno=0; compno<cstr_info.numcomps; compno++) {
box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager); box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX; box[compno].type = JPIP_FAIX;
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
} }
opj_free(box);
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); return (int)len;
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
}
opj_free(box);
return (int)len;
} }
int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8*/ OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
opj_tile_info_t *tile_Idx; opj_tile_info_t *tile_Idx;
opj_packet_info_t packet; opj_packet_info_t packet;
int resno, precno, layno; int resno, precno, layno;
OPJ_UINT32 num_packet; OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers; int numOfres, numOfprec, numOflayers;
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1; packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */ (void)EPHused; /* unused ? */
if( j2klen > pow( 2, 32)){ if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = 1; version = 1;
} } else {
else{ size_of_coding = 4;
size_of_coding = 4; version = 0;
version = 0;
}
lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_write_bytes(l_data_header,version,1);
opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
nmax = 0;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){
tile_Idx = &cstr_info.tile[ tileno];
num_packet=0;
numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++){
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++){
numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++){
switch ( cstr_info.prog){
case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RLCP:
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RPCL:
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
break;
case OPJ_PCRL:
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
break;
case OPJ_CPRL:
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
break;
default:
fprintf( stderr, "failed to ppix indexing\n");
}
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_pos-packet.start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
}
} }
while( num_packet < nmax){ /* PADDING */ lenp = opj_stream_tell(cio);
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,version,1);
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
num_packet++;
nmax = 0;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++) {
tile_Idx = &cstr_info.tile[ tileno];
num_packet=0;
numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++) {
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++) {
numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++) {
switch ( cstr_info.prog) {
case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RLCP:
packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
break;
case OPJ_RPCL:
packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
break;
case OPJ_PCRL:
packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
break;
case OPJ_CPRL:
packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
break;
default:
fprintf( stderr, "failed to ppix indexing\n");
}
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_pos-packet.start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
}
}
while( num_packet < nmax) { /* PADDING */
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
num_packet++;
}
} }
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
return (int)len; return (int)len;
} }

View File

@ -48,48 +48,53 @@
========================================================== ==========================================================
*/ */
opj_raw_t* opj_raw_create(void) { opj_raw_t* opj_raw_create(void)
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); {
return raw; opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
} }
void opj_raw_destroy(opj_raw_t *raw) { void opj_raw_destroy(opj_raw_t *raw)
if(raw) { {
opj_free(raw); if(raw) {
} opj_free(raw);
}
} }
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) { OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw)
const ptrdiff_t diff = raw->bp - raw->start; {
assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */ const ptrdiff_t diff = raw->bp - raw->start;
return (OPJ_UINT32)diff; assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */
return (OPJ_UINT32)diff;
} }
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
raw->start = bp; {
raw->lenmax = len; raw->start = bp;
raw->len = 0; raw->lenmax = len;
raw->c = 0; raw->len = 0;
raw->ct = 0; raw->c = 0;
raw->ct = 0;
} }
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) { OPJ_UINT32 opj_raw_decode(opj_raw_t *raw)
OPJ_UINT32 d; {
if (raw->ct == 0) { OPJ_UINT32 d;
raw->ct = 8; if (raw->ct == 0) {
if (raw->len == raw->lenmax) { raw->ct = 8;
raw->c = 0xff; if (raw->len == raw->lenmax) {
} else { raw->c = 0xff;
if (raw->c == 0xff) { } else {
raw->ct = 7; if (raw->c == 0xff) {
} raw->ct = 7;
raw->c = *(raw->start + raw->len); }
raw->len++; raw->c = *(raw->start + raw->len);
} raw->len++;
} }
raw->ct--; }
d = (raw->c >> raw->ct) & 0x01; raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d; return d;
} }

View File

@ -50,20 +50,20 @@ with the corresponding mode switch.
RAW encoding operations RAW encoding operations
*/ */
typedef struct opj_raw { typedef struct opj_raw {
/** temporary buffer where bits are coded or decoded */ /** temporary buffer where bits are coded or decoded */
OPJ_BYTE c; OPJ_BYTE c;
/** number of bits already read or free to write */ /** number of bits already read or free to write */
OPJ_UINT32 ct; OPJ_UINT32 ct;
/** maximum length to decode */ /** maximum length to decode */
OPJ_UINT32 lenmax; OPJ_UINT32 lenmax;
/** length decoded */ /** length decoded */
OPJ_UINT32 len; OPJ_UINT32 len;
/** pointer to the current position in the buffer */ /** pointer to the current position in the buffer */
OPJ_BYTE *bp; OPJ_BYTE *bp;
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
OPJ_BYTE *start; OPJ_BYTE *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
OPJ_BYTE *end; OPJ_BYTE *end;
} opj_raw_t; } opj_raw_t;
/** @name Exported functions */ /** @name Exported functions */

File diff suppressed because it is too large Load Diff

View File

@ -98,20 +98,20 @@ Tier-1 coding (coding of code-block coefficients)
*/ */
typedef struct opj_t1 { typedef struct opj_t1 {
/** MQC component */ /** MQC component */
opj_mqc_t *mqc; opj_mqc_t *mqc;
/** RAW component */ /** RAW component */
opj_raw_t *raw; opj_raw_t *raw;
OPJ_INT32 *data; OPJ_INT32 *data;
opj_flag_t *flags; opj_flag_t *flags;
OPJ_UINT32 w; OPJ_UINT32 w;
OPJ_UINT32 h; OPJ_UINT32 h;
OPJ_UINT32 datasize; OPJ_UINT32 datasize;
OPJ_UINT32 flagssize; OPJ_UINT32 flagssize;
OPJ_UINT32 flags_stride; OPJ_UINT32 flags_stride;
OPJ_UINT32 data_stride; OPJ_UINT32 data_stride;
OPJ_BOOL encoder; OPJ_BOOL encoder;
} opj_t1_t; } opj_t1_t;
#define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)] #define MACRO_t1_flags(x,y) t1->flags[((x)*(t1->flags_stride))+(y)]

View File

@ -38,245 +38,250 @@
#include "opj_includes.h" #include "opj_includes.h"
static int t1_init_ctxno_zc(int f, int orient) { static int t1_init_ctxno_zc(int f, int orient)
int h, v, d, n, t, hv; {
n = 0; int h, v, d, n, t, hv;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); n = 0;
v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0); h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0); v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0);
d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0);
switch (orient) { switch (orient) {
case 2: case 2:
t = h; t = h;
h = v; h = v;
v = t; v = t;
case 0: case 0:
case 1: case 1:
if (!h) { if (!h) {
if (!v) { if (!v) {
if (!d) if (!d)
n = 0; n = 0;
else if (d == 1) else if (d == 1)
n = 1; n = 1;
else else
n = 2; n = 2;
} else if (v == 1) { } else if (v == 1) {
n = 3; n = 3;
} else { } else {
n = 4; n = 4;
} }
} else if (h == 1) { } else if (h == 1) {
if (!v) { if (!v) {
if (!d) if (!d)
n = 5; n = 5;
else else
n = 6; n = 6;
} else { } else {
n = 7; n = 7;
} }
} else } else
n = 8; n = 8;
break; break;
case 3: case 3:
hv = h + v; hv = h + v;
if (!d) { if (!d) {
if (!hv) { if (!hv) {
n = 0; n = 0;
} else if (hv == 1) { } else if (hv == 1) {
n = 1; n = 1;
} else { } else {
n = 2; n = 2;
} }
} else if (d == 1) { } else if (d == 1) {
if (!hv) { if (!hv) {
n = 3; n = 3;
} else if (hv == 1) { } else if (hv == 1) {
n = 4; n = 4;
} else { } else {
n = 5; n = 5;
} }
} else if (d == 2) { } else if (d == 2) {
if (!hv) { if (!hv) {
n = 6; n = 6;
} else { } else {
n = 7; n = 7;
} }
} else { } else {
n = 8; n = 8;
} }
break; break;
} }
return (T1_CTXNO_ZC + n); return (T1_CTXNO_ZC + n);
} }
static int t1_init_ctxno_sc(int f) { static int t1_init_ctxno_sc(int f)
int hc, vc, n; {
n = 0; int hc, vc, n;
n = 0;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) == hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) == 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) + (T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) == ((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1); (T1_SIG_W | T1_SGN_W)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) == vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) == 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) + (T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) == ((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1); (T1_SIG_S | T1_SGN_S)), 1);
if (hc < 0) { if (hc < 0) {
hc = -hc; hc = -hc;
vc = -vc; vc = -vc;
} }
if (!hc) { if (!hc) {
if (vc == -1) if (vc == -1)
n = 1; n = 1;
else if (!vc) else if (!vc)
n = 0; n = 0;
else else
n = 1; n = 1;
} else if (hc == 1) { } else if (hc == 1) {
if (vc == -1) if (vc == -1)
n = 2; n = 2;
else if (!vc) else if (!vc)
n = 3; n = 3;
else else
n = 4; n = 4;
} }
return (T1_CTXNO_SC + n); return (T1_CTXNO_SC + n);
} }
static int t1_init_spb(int f) { static int t1_init_spb(int f)
int hc, vc, n; {
int hc, vc, n;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) == hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) == 1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) + (T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) == ((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1); (T1_SIG_W | T1_SGN_W)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) == vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) == 1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) + (T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) == ((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1); (T1_SIG_S | T1_SGN_S)), 1);
if (!hc && !vc) if (!hc && !vc)
n = 0; n = 0;
else else
n = (!(hc > 0 || (!hc && vc > 0))); n = (!(hc > 0 || (!hc && vc > 0)));
return n; return n;
} }
static void dump_array16(int array[],int size){ static void dump_array16(int array[],int size)
int i; {
--size; int i;
for (i = 0; i < size; ++i) { --size;
printf("0x%04x, ", array[i]); for (i = 0; i < size; ++i) {
if(!((i+1)&0x7)) printf("0x%04x, ", array[i]);
printf("\n "); if(!((i+1)&0x7))
} printf("\n ");
printf("0x%04x\n};\n\n", array[size]); }
printf("0x%04x\n};\n\n", array[size]);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i, j; int i, j;
double u, v, t; double u, v, t;
int lut_ctxno_zc[1024]; int lut_ctxno_zc[1024];
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc; (void)argv; (void)argc;
(void)argv;
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n"); printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");
/* lut_ctxno_zc */ /* lut_ctxno_zc */
for (j = 0; j < 4; ++j) { for (j = 0; j < 4; ++j) {
for (i = 0; i < 256; ++i) { for (i = 0; i < 256; ++i) {
int orient = j; int orient = j;
if (orient == 2) { if (orient == 2) {
orient = 1; orient = 1;
} else if (orient == 1) { } else if (orient == 1) {
orient = 2; orient = 2;
} }
lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j); lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
} }
} }
printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n "); printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
for (i = 0; i < 1023; ++i) { for (i = 0; i < 1023; ++i) {
printf("%i, ", lut_ctxno_zc[i]); printf("%i, ", lut_ctxno_zc[i]);
if(!((i+1)&0x1f)) if(!((i+1)&0x1f))
printf("\n "); printf("\n ");
} }
printf("%i\n};\n\n", lut_ctxno_zc[1023]); printf("%i\n};\n\n", lut_ctxno_zc[1023]);
/* lut_ctxno_sc */ /* lut_ctxno_sc */
printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n "); printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
for (i = 0; i < 255; ++i) { for (i = 0; i < 255; ++i) {
printf("0x%x, ", t1_init_ctxno_sc(i << 4)); printf("0x%x, ", t1_init_ctxno_sc(i << 4));
if(!((i+1)&0xf)) if(!((i+1)&0xf))
printf("\n "); printf("\n ");
} }
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4)); printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
/* lut_spb */ /* lut_spb */
printf("static OPJ_BYTE lut_spb[256] = {\n "); printf("static OPJ_BYTE lut_spb[256] = {\n ");
for (i = 0; i < 255; ++i) { for (i = 0; i < 255; ++i) {
printf("%i, ", t1_init_spb(i << 4)); printf("%i, ", t1_init_spb(i << 4));
if(!((i+1)&0x1f)) if(!((i+1)&0x1f))
printf("\n "); printf("\n ");
} }
printf("%i\n};\n\n", t1_init_spb(255 << 4)); printf("%i\n};\n\n", t1_init_spb(255 << 4));
/* FIXME FIXME FIXME */ /* FIXME FIXME FIXME */
/* fprintf(stdout,"nmsedec luts:\n"); */ /* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) { for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
t = i / pow(2, T1_NMSEDEC_FRACBITS); t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t; u = t;
v = t - 1.5; v = t - 1.5;
lut_nmsedec_sig[i] = lut_nmsedec_sig[i] =
opj_int_max(0, opj_int_max(0,
(int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
lut_nmsedec_sig0[i] = lut_nmsedec_sig0[i] =
opj_int_max(0, opj_int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
u = t - 1.0; u = t - 1.0;
if (i & (1 << (T1_NMSEDEC_BITS - 1))) { if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
v = t - 1.5; v = t - 1.5;
} else { } else {
v = t - 0.5; v = t - 0.5;
} }
lut_nmsedec_ref[i] = lut_nmsedec_ref[i] =
opj_int_max(0, opj_int_max(0,
(int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
lut_nmsedec_ref0[i] = lut_nmsedec_ref0[i] =
opj_int_max(0, opj_int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
} }
printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n "); printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS); dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n "); printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS); dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n "); printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS); dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n "); printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS); dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);
return 0; return 0;
} }

View File

@ -1,143 +1,143 @@
/* This file was automatically generated by t1_generate_luts.c */ /* This file was automatically generated by t1_generate_luts.c */
static OPJ_BYTE lut_ctxno_zc[1024] = { static OPJ_BYTE lut_ctxno_zc[1024] = {
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 1, 1, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
0, 3, 3, 6, 3, 6, 6, 8, 3, 6, 6, 8, 6, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 0, 3, 3, 6, 3, 6, 6, 8, 3, 6, 6, 8, 6, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 1, 4, 4, 7, 4, 7, 7, 8, 4, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8,
2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8, 2, 5, 5, 7, 5, 7, 7, 8, 5, 7, 7, 8, 7, 8, 8, 8
}; };
static OPJ_BYTE lut_ctxno_sc[256] = { static OPJ_BYTE lut_ctxno_sc[256] = {
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd, 0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc, 0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa, 0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9, 0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc, 0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb, 0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9, 0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa, 0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa, 0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xb, 0x9, 0xa, 0xb, 0xb, 0xa, 0xa,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9, 0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xd, 0x9, 0xa, 0xb, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb, 0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xb, 0xc, 0xb, 0xb, 0xb, 0xb, 0xb,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc, 0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xd, 0xc, 0xd, 0xb, 0xc, 0xb, 0xc,
0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9, 0x9, 0xa, 0xc, 0xd, 0xa, 0x9, 0xb, 0xc, 0xc, 0xb, 0x9, 0xa, 0xd, 0xc, 0xa, 0x9,
0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa, 0x9, 0xa, 0xc, 0xb, 0xa, 0xa, 0xb, 0xb, 0xc, 0xd, 0x9, 0xa, 0xd, 0xd, 0xa, 0xa,
0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc, 0x9, 0xa, 0xc, 0xb, 0xa, 0x9, 0xd, 0xc, 0xc, 0xb, 0xc, 0xb, 0xd, 0xc, 0xd, 0xc,
0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd 0x9, 0xa, 0xc, 0xd, 0xa, 0xa, 0xd, 0xd, 0xc, 0xd, 0xc, 0xd, 0xd, 0xd, 0xd, 0xd
}; };
static OPJ_BYTE lut_spb[256] = { static OPJ_BYTE lut_spb[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0,
0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1,
0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
}; };
static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = { static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0180, 0x0300, 0x0480, 0x0600, 0x0780, 0x0900, 0x0a80, 0x0000, 0x0180, 0x0300, 0x0480, 0x0600, 0x0780, 0x0900, 0x0a80,
0x0c00, 0x0d80, 0x0f00, 0x1080, 0x1200, 0x1380, 0x1500, 0x1680, 0x0c00, 0x0d80, 0x0f00, 0x1080, 0x1200, 0x1380, 0x1500, 0x1680,
0x1800, 0x1980, 0x1b00, 0x1c80, 0x1e00, 0x1f80, 0x2100, 0x2280, 0x1800, 0x1980, 0x1b00, 0x1c80, 0x1e00, 0x1f80, 0x2100, 0x2280,
0x2400, 0x2580, 0x2700, 0x2880, 0x2a00, 0x2b80, 0x2d00, 0x2e80, 0x2400, 0x2580, 0x2700, 0x2880, 0x2a00, 0x2b80, 0x2d00, 0x2e80,
0x3000, 0x3180, 0x3300, 0x3480, 0x3600, 0x3780, 0x3900, 0x3a80, 0x3000, 0x3180, 0x3300, 0x3480, 0x3600, 0x3780, 0x3900, 0x3a80,
0x3c00, 0x3d80, 0x3f00, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680, 0x3c00, 0x3d80, 0x3f00, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5100, 0x5280, 0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5100, 0x5280,
0x5400, 0x5580, 0x5700, 0x5880, 0x5a00, 0x5b80, 0x5d00, 0x5e80, 0x5400, 0x5580, 0x5700, 0x5880, 0x5a00, 0x5b80, 0x5d00, 0x5e80,
0x6000, 0x6180, 0x6300, 0x6480, 0x6600, 0x6780, 0x6900, 0x6a80, 0x6000, 0x6180, 0x6300, 0x6480, 0x6600, 0x6780, 0x6900, 0x6a80,
0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680 0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680
}; };
static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = { static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200, 0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400, 0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780, 0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00, 0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180, 0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780, 0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00, 0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00,
0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2680, 0x2780, 0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2680, 0x2780,
0x2880, 0x2980, 0x2b00, 0x2c00, 0x2d00, 0x2e80, 0x2f80, 0x3100, 0x2880, 0x2980, 0x2b00, 0x2c00, 0x2d00, 0x2e80, 0x2f80, 0x3100,
0x3200, 0x3380, 0x3480, 0x3600, 0x3700, 0x3880, 0x3a00, 0x3b00, 0x3200, 0x3380, 0x3480, 0x3600, 0x3700, 0x3880, 0x3a00, 0x3b00,
0x3c80, 0x3e00, 0x3f80, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680, 0x3c80, 0x3e00, 0x3f80, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5180, 0x5300, 0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5180, 0x5300,
0x5480, 0x5600, 0x5800, 0x5980, 0x5b00, 0x5d00, 0x5e80, 0x6080, 0x5480, 0x5600, 0x5800, 0x5980, 0x5b00, 0x5d00, 0x5e80, 0x6080,
0x6200, 0x6400, 0x6580, 0x6780, 0x6900, 0x6b00, 0x6d00, 0x6e80, 0x6200, 0x6400, 0x6580, 0x6780, 0x6900, 0x6b00, 0x6d00, 0x6e80,
0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00 0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00
}; };
static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = { static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {
0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480, 0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480,
0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080, 0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080,
0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80, 0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80,
0x0c00, 0x0b80, 0x0b00, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880, 0x0c00, 0x0b80, 0x0b00, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0500, 0x0480, 0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0500, 0x0480,
0x0400, 0x0380, 0x0300, 0x0280, 0x0200, 0x0180, 0x0100, 0x0080, 0x0400, 0x0380, 0x0300, 0x0280, 0x0200, 0x0180, 0x0100, 0x0080,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380, 0x0000, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780, 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b00, 0x0b80, 0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b00, 0x0b80,
0x0c00, 0x0c80, 0x0d00, 0x0d80, 0x0e00, 0x0e80, 0x0f00, 0x0f80, 0x0c00, 0x0c80, 0x0d00, 0x0d80, 0x0e00, 0x0e80, 0x0f00, 0x0f80,
0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380, 0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380,
0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780 0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780
}; };
static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = { static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {
0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980, 0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980,
0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300, 0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300,
0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00, 0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00,
0x0c80, 0x0c00, 0x0b80, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880, 0x0c80, 0x0c00, 0x0b80, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0580, 0x0500, 0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0580, 0x0500,
0x0480, 0x0400, 0x0400, 0x0380, 0x0300, 0x0300, 0x0280, 0x0280, 0x0480, 0x0400, 0x0400, 0x0380, 0x0300, 0x0300, 0x0280, 0x0280,
0x0200, 0x0200, 0x0180, 0x0180, 0x0100, 0x0100, 0x0100, 0x0080, 0x0200, 0x0200, 0x0180, 0x0180, 0x0100, 0x0100, 0x0100, 0x0080,
0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200, 0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400, 0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780, 0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00, 0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180, 0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780, 0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00 0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00
}; };

File diff suppressed because it is too large Load Diff

View File

@ -52,10 +52,10 @@ Tier-2 coding
*/ */
typedef struct opj_t2 { typedef struct opj_t2 {
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */ /** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
opj_image_t *image; opj_image_t *image;
/** pointer to the image coding parameters */ /** pointer to the image coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
} opj_t2_t; } opj_t2_t;
/** @name Exported functions */ /** @name Exported functions */
@ -78,17 +78,17 @@ Encode the packets of a tile to a destination buffer
@param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass @param t2_mode If == 0 In Threshold calculation ,If == 1 Final pass
*/ */
OPJ_BOOL opj_t2_encode_packets( opj_t2_t* t2, OPJ_BOOL opj_t2_encode_packets( opj_t2_t* t2,
OPJ_UINT32 tileno, OPJ_UINT32 tileno,
opj_tcd_tile_t *tile, opj_tcd_tile_t *tile,
OPJ_UINT32 maxlayers, OPJ_UINT32 maxlayers,
OPJ_BYTE *dest, OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written, OPJ_UINT32 * p_data_written,
OPJ_UINT32 len, OPJ_UINT32 len,
opj_codestream_info_t *cstr_info, opj_codestream_info_t *cstr_info,
OPJ_UINT32 tpnum, OPJ_UINT32 tpnum,
OPJ_INT32 tppos, OPJ_INT32 tppos,
OPJ_UINT32 pino, OPJ_UINT32 pino,
J2K_T2_MODE t2_mode); J2K_T2_MODE t2_mode);
/** /**
Decode the packets of a tile from a source buffer Decode the packets of a tile from a source buffer

File diff suppressed because it is too large Load Diff

View File

@ -53,120 +53,119 @@ each other. The functions in TCD.C are used by other functions in J2K.C.
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_seg { typedef struct opj_tcd_seg {
OPJ_BYTE ** data; OPJ_BYTE ** data;
OPJ_UINT32 dataindex; OPJ_UINT32 dataindex;
OPJ_UINT32 numpasses; OPJ_UINT32 numpasses;
OPJ_UINT32 real_num_passes; OPJ_UINT32 real_num_passes;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_UINT32 maxpasses; OPJ_UINT32 maxpasses;
OPJ_UINT32 numnewpasses; OPJ_UINT32 numnewpasses;
OPJ_UINT32 newlen; OPJ_UINT32 newlen;
} opj_tcd_seg_t; } opj_tcd_seg_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_pass { typedef struct opj_tcd_pass {
OPJ_UINT32 rate; OPJ_UINT32 rate;
OPJ_FLOAT64 distortiondec; OPJ_FLOAT64 distortiondec;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_UINT32 term : 1; OPJ_UINT32 term : 1;
} opj_tcd_pass_t; } opj_tcd_pass_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_layer { typedef struct opj_tcd_layer {
OPJ_UINT32 numpasses; /* Number of passes in the layer */ OPJ_UINT32 numpasses; /* Number of passes in the layer */
OPJ_UINT32 len; /* len of information */ OPJ_UINT32 len; /* len of information */
OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */ OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */
OPJ_BYTE *data; /* data */ OPJ_BYTE *data; /* data */
} opj_tcd_layer_t; } opj_tcd_layer_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_cblk_enc { typedef struct opj_tcd_cblk_enc {
OPJ_BYTE* data; /* Data */ OPJ_BYTE* data; /* Data */
opj_tcd_layer_t* layers; /* layer information */ opj_tcd_layer_t* layers; /* layer information */
opj_tcd_pass_t* passes; /* information about the passes */ opj_tcd_pass_t* passes; /* information about the passes */
OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numbps; OPJ_UINT32 numbps;
OPJ_UINT32 numlenbits; OPJ_UINT32 numlenbits;
OPJ_UINT32 data_size; /* Size of allocated data buffer */ OPJ_UINT32 data_size; /* Size of allocated data buffer */
OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */ OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */
OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */ OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */
OPJ_UINT32 totalpasses; /* total number of passes */ OPJ_UINT32 totalpasses; /* total number of passes */
} opj_tcd_cblk_enc_t; } opj_tcd_cblk_enc_t;
typedef struct opj_tcd_cblk_dec { typedef struct opj_tcd_cblk_dec {
OPJ_BYTE * data; /* Data */ OPJ_BYTE * data; /* Data */
opj_tcd_seg_t* segs; /* segments information */ opj_tcd_seg_t* segs; /* segments information */
OPJ_INT32 x0, y0, x1, y1; /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numbps; OPJ_UINT32 numbps;
OPJ_UINT32 numlenbits; OPJ_UINT32 numlenbits;
OPJ_UINT32 data_max_size; /* Size of allocated data buffer */ OPJ_UINT32 data_max_size; /* Size of allocated data buffer */
OPJ_UINT32 data_current_size; /* Size of used data buffer */ OPJ_UINT32 data_current_size; /* Size of used data buffer */
OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */ OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */
OPJ_UINT32 numsegs; /* number of segments */ OPJ_UINT32 numsegs; /* number of segments */
OPJ_UINT32 real_num_segs; OPJ_UINT32 real_num_segs;
OPJ_UINT32 m_current_max_segs; OPJ_UINT32 m_current_max_segs;
} opj_tcd_cblk_dec_t; } opj_tcd_cblk_dec_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_precinct { typedef struct opj_tcd_precinct {
OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 cw, ch; /* number of precinct in width and height */ OPJ_UINT32 cw, ch; /* number of precinct in width and height */
union{ /* code-blocks information */ union { /* code-blocks information */
opj_tcd_cblk_enc_t* enc; opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec; opj_tcd_cblk_dec_t* dec;
void* blocks; void* blocks;
} cblks; } cblks;
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */ OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
opj_tgt_tree_t *incltree; /* inclusion tree */ opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */ opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_t; } opj_tcd_precinct_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_band { typedef struct opj_tcd_band {
OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 bandno; OPJ_UINT32 bandno;
opj_tcd_precinct_t *precincts; /* precinct information */ opj_tcd_precinct_t *precincts; /* precinct information */
OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */ OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
OPJ_INT32 numbps; OPJ_INT32 numbps;
OPJ_FLOAT32 stepsize; OPJ_FLOAT32 stepsize;
} opj_tcd_band_t; } opj_tcd_band_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_resolution { typedef struct opj_tcd_resolution {
OPJ_INT32 x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the resolution level : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 pw, ph; OPJ_UINT32 pw, ph;
OPJ_UINT32 numbands; /* number sub-band for the resolution level */ OPJ_UINT32 numbands; /* number sub-band for the resolution level */
opj_tcd_band_t bands[3]; /* subband information */ opj_tcd_band_t bands[3]; /* subband information */
} opj_tcd_resolution_t; } opj_tcd_resolution_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_tilecomp typedef struct opj_tcd_tilecomp {
{ OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_UINT32 numresolutions; /* number of resolutions level */
OPJ_UINT32 numresolutions; /* number of resolutions level */ OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/ opj_tcd_resolution_t *resolutions; /* resolutions information */
opj_tcd_resolution_t *resolutions; /* resolutions information */ OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */ OPJ_INT32 *data; /* data of the component */
OPJ_INT32 *data; /* data of the component */ OPJ_BOOL ownsData; /* if true, then need to free after usage, otherwise do not free */
OPJ_BOOL ownsData; /* if true, then need to free after usage, otherwise do not free */ OPJ_UINT32 data_size_needed; /* we may either need to allocate this amount of data, or re-use image data and ignore this value */
OPJ_UINT32 data_size_needed; /* we may either need to allocate this amount of data, or re-use image data and ignore this value */ OPJ_UINT32 data_size; /* size of the data of the component */
OPJ_UINT32 data_size; /* size of the data of the component */ OPJ_INT32 numpix; /* add fixed_quality */
OPJ_INT32 numpix; /* add fixed_quality */
} opj_tcd_tilecomp_t; } opj_tcd_tilecomp_t;
@ -174,21 +173,20 @@ typedef struct opj_tcd_tilecomp
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_tile { typedef struct opj_tcd_tile {
OPJ_INT32 x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the tile : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numcomps; /* number of components in tile */ OPJ_UINT32 numcomps; /* number of components in tile */
opj_tcd_tilecomp_t *comps; /* Components information */ opj_tcd_tilecomp_t *comps; /* Components information */
OPJ_INT32 numpix; /* add fixed_quality */ OPJ_INT32 numpix; /* add fixed_quality */
OPJ_FLOAT64 distotile; /* add fixed_quality */ OPJ_FLOAT64 distotile; /* add fixed_quality */
OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */ OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */
OPJ_UINT32 packno; /* packet number */ OPJ_UINT32 packno; /* packet number */
} opj_tcd_tile_t; } opj_tcd_tile_t;
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_image typedef struct opj_tcd_image {
{ opj_tcd_tile_t *tiles; /* Tiles information */
opj_tcd_tile_t *tiles; /* Tiles information */
} }
opj_tcd_image_t; opj_tcd_image_t;
@ -196,30 +194,29 @@ opj_tcd_image_t;
/** /**
Tile coder/decoder Tile coder/decoder
*/ */
typedef struct opj_tcd typedef struct opj_tcd {
{ /** Position of the tilepart flag in Progression order*/
/** Position of the tilepart flag in Progression order*/ OPJ_INT32 tp_pos;
OPJ_INT32 tp_pos; /** Tile part number*/
/** Tile part number*/ OPJ_UINT32 tp_num;
OPJ_UINT32 tp_num; /** Current tile part number*/
/** Current tile part number*/ OPJ_UINT32 cur_tp_num;
OPJ_UINT32 cur_tp_num; /** Total number of tileparts of the current tile*/
/** Total number of tileparts of the current tile*/ OPJ_UINT32 cur_totnum_tp;
OPJ_UINT32 cur_totnum_tp; /** Current Packet iterator number */
/** Current Packet iterator number */ OPJ_UINT32 cur_pino;
OPJ_UINT32 cur_pino; /** info on each image tile */
/** info on each image tile */ opj_tcd_image_t *tcd_image;
opj_tcd_image_t *tcd_image; /** image header */
/** image header */ opj_image_t *image;
opj_image_t *image; /** coding parameters */
/** coding parameters */ opj_cp_t *cp;
opj_cp_t *cp; /** coding/decoding parameters common to all tiles */
/** coding/decoding parameters common to all tiles */ opj_tcp_t *tcp;
opj_tcp_t *tcp; /** current encoded/decoded tile */
/** current encoded/decoded tile */ OPJ_UINT32 tcd_tileno;
OPJ_UINT32 tcd_tileno; /** tell if the tcd is a decoder. */
/** tell if the tcd is a decoder. */ OPJ_UINT32 m_is_decoder : 1;
OPJ_UINT32 m_is_decoder : 1;
} opj_tcd_t; } opj_tcd_t;
/** @name Exported functions */ /** @name Exported functions */
@ -253,8 +250,8 @@ void opj_tcd_destroy(opj_tcd_t *tcd);
* @return true if the encoding values could be set (false otherwise). * @return true if the encoding values could be set (false otherwise).
*/ */
OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image, opj_image_t * p_image,
opj_cp_t * p_cp ); opj_cp_t * p_cp );
/** /**
* Allocates memory for decoding a specific tile. * Allocates memory for decoding a specific tile.
@ -273,15 +270,15 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd); void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd);
void opj_tcd_makelayer( opj_tcd_t *tcd, void opj_tcd_makelayer( opj_tcd_t *tcd,
OPJ_UINT32 layno, OPJ_UINT32 layno,
OPJ_FLOAT64 thresh, OPJ_FLOAT64 thresh,
OPJ_UINT32 final); OPJ_UINT32 final);
OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
OPJ_BYTE *dest, OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written, OPJ_UINT32 * p_data_written,
OPJ_UINT32 len, OPJ_UINT32 len,
opj_codestream_info_t *cstr_info); opj_codestream_info_t *cstr_info);
/** /**
* Gets the maximum tile size that will be taken by the tile once decoded. * Gets the maximum tile size that will be taken by the tile once decoded.
@ -299,11 +296,11 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size (opj_tcd_t *p_tcd );
* @return true if the coding is successful. * @return true if the coding is successful.
*/ */
OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
OPJ_UINT32 p_tile_no, OPJ_UINT32 p_tile_no,
OPJ_BYTE *p_dest, OPJ_BYTE *p_dest,
OPJ_UINT32 * p_data_written, OPJ_UINT32 * p_data_written,
OPJ_UINT32 p_len, OPJ_UINT32 p_len,
struct opj_codestream_info *p_cstr_info); struct opj_codestream_info *p_cstr_info);
/** /**
@ -316,19 +313,19 @@ Decode a tile from a buffer into a raw image
@param manager the event manager. @param manager the event manager.
*/ */
OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *tcd, OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *tcd,
OPJ_BYTE *src, OPJ_BYTE *src,
OPJ_UINT32 len, OPJ_UINT32 len,
OPJ_UINT32 tileno, OPJ_UINT32 tileno,
opj_codestream_index_t *cstr_info, opj_codestream_index_t *cstr_info,
opj_event_mgr_t *manager); opj_event_mgr_t *manager);
/** /**
* Copies tile data from the system onto the given memory block. * Copies tile data from the system onto the given memory block.
*/ */
OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
OPJ_BYTE * p_dest, OPJ_BYTE * p_dest,
OPJ_UINT32 p_dest_length ); OPJ_UINT32 p_dest_length );
/** /**
* *
@ -345,7 +342,7 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd );
* @return true if the encoding values could be set (false otherwise). * @return true if the encoding values could be set (false otherwise).
*/ */
OPJ_BOOL opj_tcd_init_encode_tile ( opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_init_encode_tile ( opj_tcd_t *p_tcd,
OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager ); OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager );
/** /**
* Copies tile data from the given memory block onto the system. * Copies tile data from the given memory block onto the system.

View File

@ -45,81 +45,82 @@
========================================================== ==========================================================
*/ */
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager) { opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager)
OPJ_INT32 nplh[32]; {
OPJ_INT32 nplv[32]; OPJ_INT32 nplh[32];
opj_tgt_node_t *node = 00; OPJ_INT32 nplv[32];
opj_tgt_node_t *l_parent_node = 00; opj_tgt_node_t *node = 00;
opj_tgt_node_t *l_parent_node0 = 00; opj_tgt_node_t *l_parent_node = 00;
opj_tgt_tree_t *tree = 00; opj_tgt_node_t *l_parent_node0 = 00;
OPJ_UINT32 i; opj_tgt_tree_t *tree = 00;
OPJ_INT32 j,k; OPJ_UINT32 i;
OPJ_UINT32 numlvls; OPJ_INT32 j,k;
OPJ_UINT32 n; OPJ_UINT32 numlvls;
OPJ_UINT32 n;
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t)); tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) { if(!tree) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n"); opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n");
return 00; return 00;
} }
tree->numleafsh = numleafsh; tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv; tree->numleafsv = numleafsv;
numlvls = 0; numlvls = 0;
nplh[0] = (OPJ_INT32)numleafsh; nplh[0] = (OPJ_INT32)numleafsh;
nplv[0] = (OPJ_INT32)numleafsv; nplv[0] = (OPJ_INT32)numleafsv;
tree->numnodes = 0; tree->numnodes = 0;
do { do {
n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]); n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]);
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n; tree->numnodes += n;
++numlvls; ++numlvls;
} while (n > 1); } while (n > 1);
/* ADD */ /* ADD */
if (tree->numnodes == 0) { if (tree->numnodes == 0) {
opj_free(tree); opj_free(tree);
opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n"); opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
return 00; return 00;
} }
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t)); tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) { if(!tree->nodes) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n"); opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
opj_free(tree); opj_free(tree);
return 00; return 00;
} }
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes; node = tree->nodes;
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv]; l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
l_parent_node0 = l_parent_node; l_parent_node0 = l_parent_node;
for (i = 0; i < numlvls - 1; ++i) { for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) { for (j = 0; j < nplv[i]; ++j) {
k = nplh[i]; k = nplh[i];
while (--k >= 0) { while (--k >= 0) {
node->parent = l_parent_node; node->parent = l_parent_node;
++node; ++node;
if (--k >= 0) { if (--k >= 0) {
node->parent = l_parent_node; node->parent = l_parent_node;
++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];
}
} }
++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; }
opj_tgt_reset(tree); node->parent = 0;
return tree; opj_tgt_reset(tree);
return tree;
} }
/** /**
@ -132,204 +133,202 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_e
*/ */
opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager) opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager)
{ {
OPJ_INT32 l_nplh[32]; OPJ_INT32 l_nplh[32];
OPJ_INT32 l_nplv[32]; OPJ_INT32 l_nplv[32];
opj_tgt_node_t *l_node = 00; opj_tgt_node_t *l_node = 00;
opj_tgt_node_t *l_parent_node = 00; opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00; opj_tgt_node_t *l_parent_node0 = 00;
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_INT32 j,k; OPJ_INT32 j,k;
OPJ_UINT32 l_num_levels; OPJ_UINT32 l_num_levels;
OPJ_UINT32 n; OPJ_UINT32 n;
OPJ_UINT32 l_node_size; OPJ_UINT32 l_node_size;
if (! p_tree){ if (! p_tree) {
return 00;
}
if ((p_tree->numleafsh != p_num_leafs_h) || (p_tree->numleafsv != p_num_leafs_v)) {
p_tree->numleafsh = p_num_leafs_h;
p_tree->numleafsv = p_num_leafs_v;
l_num_levels = 0;
l_nplh[0] = (OPJ_INT32)p_num_leafs_h;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v;
p_tree->numnodes = 0;
do {
n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]);
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
p_tree->numnodes += n;
++l_num_levels;
} while (n > 1);
/* ADD */
if (p_tree->numnodes == 0) {
opj_tgt_destroy(p_tree);
return 00;
}
l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
if (l_node_size > p_tree->nodes_size) {
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
if (! new_nodes) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to reinitialize the tag tree\n");
opj_tgt_destroy(p_tree);
return 00; return 00;
}
p_tree->nodes = new_nodes;
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
p_tree->nodes_size = l_node_size;
} }
l_node = p_tree->nodes;
l_parent_node = &p_tree->nodes[p_tree->numleafsh * p_tree->numleafsv];
l_parent_node0 = l_parent_node;
if ((p_tree->numleafsh != p_num_leafs_h) || (p_tree->numleafsv != p_num_leafs_v)) { for (i = 0; i < l_num_levels - 1; ++i) {
p_tree->numleafsh = p_num_leafs_h; for (j = 0; j < l_nplv[i]; ++j) {
p_tree->numleafsv = p_num_leafs_v; k = l_nplh[i];
while (--k >= 0) {
l_num_levels = 0; l_node->parent = l_parent_node;
l_nplh[0] = (OPJ_INT32)p_num_leafs_h; ++l_node;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v; if (--k >= 0) {
p_tree->numnodes = 0; l_node->parent = l_parent_node;
do ++l_node;
{ }
n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]); ++l_parent_node;
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
p_tree->numnodes += n;
++l_num_levels;
} }
while (n > 1); if ((j & 1) || j == l_nplv[i] - 1) {
l_parent_node0 = l_parent_node;
/* ADD */ } else {
if (p_tree->numnodes == 0) { l_parent_node = l_parent_node0;
opj_tgt_destroy(p_tree); l_parent_node0 += l_nplh[i];
return 00;
} }
l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); }
if (l_node_size > p_tree->nodes_size) {
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);
if (! new_nodes) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to reinitialize the tag tree\n");
opj_tgt_destroy(p_tree);
return 00;
}
p_tree->nodes = new_nodes;
memset(((char *) p_tree->nodes) + p_tree->nodes_size, 0 , l_node_size - p_tree->nodes_size);
p_tree->nodes_size = l_node_size;
}
l_node = p_tree->nodes;
l_parent_node = &p_tree->nodes[p_tree->numleafsh * p_tree->numleafsv];
l_parent_node0 = l_parent_node;
for (i = 0; i < l_num_levels - 1; ++i) {
for (j = 0; j < l_nplv[i]; ++j) {
k = l_nplh[i];
while (--k >= 0) {
l_node->parent = l_parent_node;
++l_node;
if (--k >= 0) {
l_node->parent = l_parent_node;
++l_node;
}
++l_parent_node;
}
if ((j & 1) || j == l_nplv[i] - 1)
{
l_parent_node0 = l_parent_node;
}
else
{
l_parent_node = l_parent_node0;
l_parent_node0 += l_nplh[i];
}
}
}
l_node->parent = 0;
} }
opj_tgt_reset(p_tree); l_node->parent = 0;
}
opj_tgt_reset(p_tree);
return p_tree; return p_tree;
} }
void opj_tgt_destroy(opj_tgt_tree_t *p_tree) void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
{ {
if (! p_tree) { if (! p_tree) {
return; return;
} }
if (p_tree->nodes) { if (p_tree->nodes) {
opj_free(p_tree->nodes); opj_free(p_tree->nodes);
p_tree->nodes = 00; p_tree->nodes = 00;
} }
opj_free(p_tree); opj_free(p_tree);
} }
void opj_tgt_reset(opj_tgt_tree_t *p_tree) { void opj_tgt_reset(opj_tgt_tree_t *p_tree)
OPJ_UINT32 i; {
opj_tgt_node_t * l_current_node = 00;; OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
if (! p_tree) { if (! p_tree) {
return; return;
} }
l_current_node = p_tree->nodes; l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i) for (i = 0; i < p_tree->numnodes; ++i) {
{ l_current_node->value = 999;
l_current_node->value = 999; l_current_node->low = 0;
l_current_node->low = 0; l_current_node->known = 0;
l_current_node->known = 0; ++l_current_node;
++l_current_node; }
}
} }
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) { void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
opj_tgt_node_t *node; {
node = &tree->nodes[leafno]; opj_tgt_node_t *node;
while (node && node->value > value) { node = &tree->nodes[leafno];
node->value = value; while (node && node->value > value) {
node = node->parent; node->value = value;
} node = node->parent;
}
} }
void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) { void opj_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 *stk[31];
opj_tgt_node_t *node; opj_tgt_node_t **stkptr;
OPJ_INT32 low; opj_tgt_node_t *node;
OPJ_INT32 low;
stkptr = stk; stkptr = stk;
node = &tree->nodes[leafno]; node = &tree->nodes[leafno];
while (node->parent) { while (node->parent) {
*stkptr++ = node; *stkptr++ = node;
node = node->parent; node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
} }
low = 0; while (low < threshold) {
for (;;) { if (low >= node->value) {
if (low > node->low) { if (!node->known) {
node->low = low; opj_bio_write(bio, 1, 1);
} else { node->known = 1;
low = node->low;
} }
break;
while (low < threshold) { }
if (low >= node->value) { opj_bio_write(bio, 0, 1);
if (!node->known) { ++low;
opj_bio_write(bio, 1, 1);
node->known = 1;
}
break;
}
opj_bio_write(bio, 0, 1);
++low;
}
node->low = low;
if (stkptr == stk)
break;
node = *--stkptr;
} }
node->low = low;
if (stkptr == stk)
break;
node = *--stkptr;
}
} }
OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) { OPJ_UINT32 opj_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 *stk[31];
opj_tgt_node_t *node; opj_tgt_node_t **stkptr;
OPJ_INT32 low; opj_tgt_node_t *node;
OPJ_INT32 low;
stkptr = stk; stkptr = stk;
node = &tree->nodes[leafno]; node = &tree->nodes[leafno];
while (node->parent) { while (node->parent) {
*stkptr++ = node; *stkptr++ = node;
node = node->parent; node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
} }
while (low < threshold && low < node->value) {
low = 0; if (opj_bio_read(bio, 1)) {
for (;;) { node->value = low;
if (low > node->low) { } else {
node->low = low; ++low;
} else { }
low = node->low;
}
while (low < threshold && low < node->value) {
if (opj_bio_read(bio, 1)) {
node->value = low;
} else {
++low;
}
}
node->low = low;
if (stkptr == stk) {
break;
}
node = *--stkptr;
} }
node->low = low;
if (stkptr == stk) {
break;
}
node = *--stkptr;
}
return (node->value < threshold) ? 1 : 0; return (node->value < threshold) ? 1 : 0;
} }

View File

@ -64,13 +64,12 @@ typedef struct opj_tgt_node {
/** /**
Tag tree Tag tree
*/ */
typedef struct opj_tgt_tree typedef struct opj_tgt_tree {
{ OPJ_UINT32 numleafsh;
OPJ_UINT32 numleafsh; OPJ_UINT32 numleafsv;
OPJ_UINT32 numleafsv; OPJ_UINT32 numnodes;
OPJ_UINT32 numnodes; opj_tgt_node_t *nodes;
opj_tgt_node_t *nodes; OPJ_UINT32 nodes_size; /* maximum size taken by nodes */
OPJ_UINT32 nodes_size; /* maximum size taken by nodes */
} opj_tgt_tree_t; } opj_tgt_tree_t;

View File

@ -38,45 +38,45 @@
int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int i; int i;
int tileno; int tileno;
opj_jp2_box_t *box; opj_jp2_box_t *box;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = 0; lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t));
for ( i = 0; i < 2 ; i++ ){ for ( i = 0; i < 2 ; i++ ) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_THIX,4); /* THIX */ opj_write_bytes(l_data_header,JPIP_THIX,4); /* THIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager); opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager);
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++) {
box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].type = JPIP_MHIX;
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp, p_manager);
opj_write_bytes(l_data_header,len,4); /* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek( cio, lenp+len,p_manager);
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].type = JPIP_MHIX;
} }
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); opj_free(box);
opj_stream_seek(cio, lenp, p_manager);
opj_write_bytes(l_data_header,len,4); /* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek( cio, lenp+len,p_manager);
} return (int)len;
opj_free(box);
return (int)len;
} }
/* /*
@ -89,46 +89,46 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
* @return length of mhix box * @return length of mhix box
*/ */
int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio, int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
int i; int i;
opj_tile_info_t tile; opj_tile_info_t tile;
opj_tp_info_t tp; opj_tp_info_t tp;
opj_marker_info_t *marker; opj_marker_info_t *marker;
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell (cio); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
tile = cstr_info.tile[tileno];
tp = tile.tp[0];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_header-tp.tp_start_pos+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
marker = cstr_info.tile[tileno].marker;
for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */
opj_write_bytes( l_data_header, marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)(marker[i].pos-coff), 8);
tile = cstr_info.tile[tileno];
tp = tile.tp[0];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_header-tp.tp_start_pos+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager); opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
/* free( marker);*/ marker = cstr_info.tile[tileno].marker;
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); for( i=0; i<cstr_info.tile[tileno].marknum; i++) { /* Marker restricted to 1 apparition */
opj_stream_seek(cio, lenp,p_manager); opj_write_bytes( l_data_header, marker[i].type, 2);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_write_bytes( l_data_header, (OPJ_UINT32)(marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
return (int)len; /* free( marker);*/
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return (int)len;
} }

View File

@ -62,25 +62,25 @@ int opj_write_tpix( int coff,
int j2klen, opj_stream_private_t *cio, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); opj_stream_skip(cio, 4, p_manager);
opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */ opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_tpixfaix( coff, 0, cstr_info, j2klen, cio,p_manager); opj_write_tpixfaix( coff, 0, cstr_info, j2klen, cio,p_manager);
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_skip(cio, lenp, p_manager); opj_stream_skip(cio, lenp, p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
return (int)len; return (int)len;
} }
int opj_write_tpixfaix( int coff, int opj_write_tpixfaix( int coff,
@ -90,96 +90,91 @@ int opj_write_tpixfaix( int coff,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_UINT32 len; OPJ_UINT32 len;
OPJ_OFF_T lenp; OPJ_OFF_T lenp;
OPJ_UINT32 i, j; OPJ_UINT32 i, j;
OPJ_UINT32 Aux; OPJ_UINT32 Aux;
OPJ_UINT32 num_max_tile_parts; OPJ_UINT32 num_max_tile_parts;
OPJ_UINT32 size_of_coding; /* 4 or 8 */ OPJ_UINT32 size_of_coding; /* 4 or 8 */
opj_tp_info_t tp; opj_tp_info_t tp;
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_UINT32 version; OPJ_UINT32 version;
num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info); num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info);
if( j2klen > pow( 2, 32)){ if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = num_max_tile_parts == 1 ? 1:3; version = num_max_tile_parts == 1 ? 1:3;
} } else {
else{ size_of_coding = 4;
size_of_coding = 4; version = num_max_tile_parts == 1 ? 0:2;
version = num_max_tile_parts == 1 ? 0:2;
}
lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,1,p_manager);
opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++)
{
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
{
tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02)
{
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else
Aux = j + 1;
opj_write_bytes(l_data_header,Aux,4);
opj_stream_write_data(cio,l_data_header,4,p_manager);
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
/* fprintf(stderr,"AUX value %d\n",Aux);*/
}
/*cio_write(0,4);*/
}
/* PADDING */
while (j < num_max_tile_parts)
{
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02)
opj_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */
opj_stream_write_data(cio,l_data_header,4,p_manager);
j++;
}
} }
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); lenp = opj_stream_tell(cio);
opj_stream_seek(cio, lenp,p_manager); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,1,p_manager);
return (int)len; opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) {
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++) {
tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02) {
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else
Aux = j + 1;
opj_write_bytes(l_data_header,Aux,4);
opj_stream_write_data(cio,l_data_header,4,p_manager);
/*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
/* fprintf(stderr,"AUX value %d\n",Aux);*/
}
/*cio_write(0,4);*/
}
/* PADDING */
while (j < num_max_tile_parts) {
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02)
opj_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */
opj_stream_write_data(cio,l_data_header,4,p_manager);
j++;
}
}
len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return (int)len;
} }
int get_num_max_tile_parts( opj_codestream_info_t cstr_info) int get_num_max_tile_parts( opj_codestream_info_t cstr_info)
{ {
int num_max_tp = 0, i; int num_max_tp = 0, i;
for( i=0; i<cstr_info.tw*cstr_info.th; i++) for( i=0; i<cstr_info.tw*cstr_info.th; i++)
num_max_tp = MAX( cstr_info.tile[i].num_tps, num_max_tp); num_max_tp = MAX( cstr_info.tile[i].num_tps, num_max_tp);
return num_max_tp; return num_max_tp;
} }

View File

@ -77,42 +77,46 @@ static int bio_bytein(opj_bio_t *bio);
========================================================== ==========================================================
*/ */
static int bio_byteout(opj_bio_t *bio) { static int bio_byteout(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if (bio->bp >= bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return 1; if (bio->bp >= bio->end) {
} return 1;
*bio->bp++ = bio->buf >> 8; }
return 0; *bio->bp++ = bio->buf >> 8;
return 0;
} }
static int bio_bytein(opj_bio_t *bio) { static int bio_bytein(opj_bio_t *bio)
bio->buf = (bio->buf << 8) & 0xffff; {
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->buf = (bio->buf << 8) & 0xffff;
if (bio->bp >= bio->end) { bio->ct = bio->buf == 0xff00 ? 7 : 8;
return 1; if (bio->bp >= bio->end) {
} return 1;
bio->buf |= *bio->bp++; }
return 0; bio->buf |= *bio->bp++;
return 0;
} }
static void bio_putbit(opj_bio_t *bio, int b) { static void bio_putbit(opj_bio_t *bio, int b)
if (bio->ct == 0) { {
bio_byteout(bio); if (bio->ct == 0) {
} bio_byteout(bio);
bio->ct--; }
bio->buf |= b << bio->ct; bio->ct--;
bio->buf |= b << bio->ct;
} }
/* MOD antonin */ /* MOD antonin */
static int bio_getbit(opj_bio_t *bio) { static int bio_getbit(opj_bio_t *bio)
/* DOM */ {
if (bio->ct == 0) { /* DOM */
bio_bytein(bio); if (bio->ct == 0) {
} bio_bytein(bio);
bio->ct--; }
return (bio->buf >> bio->ct) & 1; bio->ct--;
return (bio->buf >> bio->ct) & 1;
} }
/* /*
@ -121,74 +125,83 @@ static int bio_getbit(opj_bio_t *bio) {
========================================================== ==========================================================
*/ */
opj_bio_t* bio_create() { opj_bio_t* bio_create()
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); {
return bio; opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
} }
void bio_destroy(opj_bio_t *bio) { void bio_destroy(opj_bio_t *bio)
if(bio) { {
opj_free(bio); if(bio) {
} opj_free(bio);
}
} }
int bio_numbytes(opj_bio_t *bio) { int bio_numbytes(opj_bio_t *bio)
return (bio->bp - bio->start); {
return (bio->bp - bio->start);
} }
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 8; bio->buf = 0;
bio->ct = 8;
} }
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len)
bio->start = bp; {
bio->end = bp + len; bio->start = bp;
bio->bp = bp; bio->end = bp + len;
bio->buf = 0; bio->bp = bp;
bio->ct = 0; bio->buf = 0;
bio->ct = 0;
} }
void bio_write(opj_bio_t *bio, int v, int n) { void bio_write(opj_bio_t *bio, int v, int n)
int i; {
for (i = n - 1; i >= 0; i--) { int i;
bio_putbit(bio, (v >> i) & 1); for (i = n - 1; i >= 0; i--) {
} bio_putbit(bio, (v >> i) & 1);
}
} }
int bio_read(opj_bio_t *bio, int n) { int bio_read(opj_bio_t *bio, int n)
int i, v; {
v = 0; int i, v;
for (i = n - 1; i >= 0; i--) { v = 0;
v += bio_getbit(bio) << i; for (i = n - 1; i >= 0; i--) {
} v += bio_getbit(bio) << i;
return v; }
return v;
} }
int bio_flush(opj_bio_t *bio) { int bio_flush(opj_bio_t *bio)
bio->ct = 0; {
if (bio_byteout(bio)) { bio->ct = 0;
return 1; if (bio_byteout(bio)) {
} return 1;
if (bio->ct == 7) { }
bio->ct = 0; if (bio->ct == 7) {
if (bio_byteout(bio)) { bio->ct = 0;
return 1; if (bio_byteout(bio)) {
} return 1;
} }
return 0; }
return 0;
} }
int bio_inalign(opj_bio_t *bio) { int bio_inalign(opj_bio_t *bio)
bio->ct = 0; {
if ((bio->buf & 0xff) == 0xff) { bio->ct = 0;
if (bio_bytein(bio)) { if ((bio->buf & 0xff) == 0xff) {
return 1; if (bio_bytein(bio)) {
} return 1;
bio->ct = 0; }
} bio->ct = 0;
return 0; }
return 0;
} }

View File

@ -49,16 +49,16 @@ The functions in BIO.C have for goal to realize an individual bit input - output
Individual bit input-output stream (BIO) Individual bit input-output stream (BIO)
*/ */
typedef struct opj_bio { typedef struct opj_bio {
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
unsigned char *start; unsigned char *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
unsigned char *end; unsigned char *end;
/** pointer to the present position in the buffer */ /** pointer to the present position in the buffer */
unsigned char *bp; unsigned char *bp;
/** temporary place where each byte is read or written */ /** temporary place where each byte is read or written */
unsigned int buf; unsigned int buf;
/** coder : number of bits free to write. decoder : number of bits read */ /** coder : number of bits free to write. decoder : number of bits read */
int ct; int ct;
} opj_bio_t; } opj_bio_t;
/** @name Funciones generales */ /** @name Funciones generales */

View File

@ -37,59 +37,59 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
opj_cp_t *cp = NULL; {
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); opj_cp_t *cp = NULL;
if(!cio) return NULL; opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
cio->cinfo = cinfo; if(!cio) return NULL;
if(buffer && length) { cio->cinfo = cinfo;
/* wrap a user buffer containing the encoded image */ if(buffer && length) {
cio->openmode = OPJ_STREAM_READ; /* wrap a user buffer containing the encoded image */
cio->buffer = buffer; cio->openmode = OPJ_STREAM_READ;
cio->length = length; cio->buffer = buffer;
} cio->length = length;
else if(!buffer && !length && cinfo) { } else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */ /* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE; cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
case CODEC_J3D: case CODEC_J3D:
case CODEC_J2K: case CODEC_J2K:
cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp; cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp;
break; break;
default: default:
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4; cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4;
cio->buffer = (unsigned char *)opj_malloc(cio->length); cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) { if(!cio->buffer) {
opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n"); opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n");
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
} } else {
else { opj_free(cio);
opj_free(cio); return NULL;
return NULL; }
}
/* Initialize byte IO */ /* Initialize byte IO */
cio->start = cio->buffer; cio->start = cio->buffer;
cio->end = cio->buffer + cio->length; cio->end = cio->buffer + cio->length;
cio->bp = cio->buffer; cio->bp = cio->buffer;
return cio; return cio;
} }
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio)
if(cio) { {
if(cio->openmode == OPJ_STREAM_WRITE) { if(cio) {
/* destroy the allocated buffer */ if(cio->openmode == OPJ_STREAM_WRITE) {
opj_free(cio->buffer); /* destroy the allocated buffer */
} opj_free(cio->buffer);
/* destroy the cio */ }
opj_free(cio); /* destroy the cio */
} opj_free(cio);
}
} }
@ -98,8 +98,9 @@ void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
/* /*
* Get position in byte stream. * Get position in byte stream.
*/ */
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { int OPJ_CALLCONV cio_tell(opj_cio_t *cio)
return cio->bp - cio->start; {
return cio->bp - cio->start;
} }
/* /*
@ -107,45 +108,50 @@ int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
* *
* pos : position, in number of bytes, from the beginning of the stream * pos : position, in number of bytes, from the beginning of the stream
*/ */
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos)
cio->bp = cio->start + pos; {
cio->bp = cio->start + pos;
} }
/* /*
* Number of bytes left before the end of the stream. * Number of bytes left before the end of the stream.
*/ */
int cio_numbytesleft(opj_cio_t *cio) { int cio_numbytesleft(opj_cio_t *cio)
return cio->end - cio->bp; {
return cio->end - cio->bp;
} }
/* /*
* Get pointer to the current position in the stream. * Get pointer to the current position in the stream.
*/ */
unsigned char *cio_getbp(opj_cio_t *cio) { unsigned char *cio_getbp(opj_cio_t *cio)
return cio->bp; {
return cio->bp;
} }
/* /*
* Write a byte. * Write a byte.
*/ */
static bool cio_byteout(opj_cio_t *cio, unsigned char v) { static bool cio_byteout(opj_cio_t *cio, unsigned char v)
if (cio->bp >= cio->end) { {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); if (cio->bp >= cio->end) {
return false; opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
} return false;
*cio->bp++ = v; }
return true; *cio->bp++ = v;
return true;
} }
/* /*
* Read a byte. * Read a byte.
*/ */
static unsigned char cio_bytein(opj_cio_t *cio) { static unsigned char cio_bytein(opj_cio_t *cio)
if (cio->bp >= cio->end) { {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n"); if (cio->bp >= cio->end) {
return 0; opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
} return 0;
return *cio->bp++; }
return *cio->bp++;
} }
/* /*
@ -154,13 +160,14 @@ static unsigned char cio_bytein(opj_cio_t *cio) {
* v : value to write * v : value to write
* n : number of bytes to write * n : number of bytes to write
*/ */
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) { unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n)
int i; {
for (i = n - 1; i >= 0; i--) { int i;
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) for (i = n - 1; i >= 0; i--) {
return 0; if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
} return 0;
return n; }
return n;
} }
/* /*
@ -170,14 +177,15 @@ unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
* *
* return : value of the n bytes read * return : value of the n bytes read
*/ */
unsigned int cio_read(opj_cio_t *cio, int n) { unsigned int cio_read(opj_cio_t *cio, int n)
int i; {
unsigned int v; int i;
v = 0; unsigned int v;
for (i = n - 1; i >= 0; i--) { v = 0;
v += cio_bytein(cio) << (i << 3); for (i = n - 1; i >= 0; i--) {
} v += cio_bytein(cio) << (i << 3);
return v; }
return v;
} }
/* /*
@ -185,8 +193,9 @@ unsigned int cio_read(opj_cio_t *cio, int n) {
* *
* n : number of bytes to skip * n : number of bytes to skip
*/ */
void cio_skip(opj_cio_t *cio, int n) { void cio_skip(opj_cio_t *cio, int n)
cio->bp += n; {
cio->bp += n;
} }
/* /*
@ -195,13 +204,14 @@ void cio_skip(opj_cio_t *cio, int n) {
* v : value to write * v : value to write
* n : number of bytes to write * n : number of bytes to write
*/ */
int cio_write_int(opj_cio_t *cio, int v, int n) { int cio_write_int(opj_cio_t *cio, int v, int n)
int i; {
for (i = n - 1; i >= 0; i--) { int i;
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) ) for (i = n - 1; i >= 0; i--) {
return 0; if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
} return 0;
return n; }
return n;
} }
/* /*
@ -211,13 +221,14 @@ int cio_write_int(opj_cio_t *cio, int v, int n) {
* *
* return : value of the n bytes read * return : value of the n bytes read
*/ */
int cio_read_int(opj_cio_t *cio, int n) { int cio_read_int(opj_cio_t *cio, int n)
int i; {
int v; int i;
v = 0; int v;
for (i = n - 1; i >= 0; i--) { v = 0;
v += cio_bytein(cio) << (i << 3); for (i = n - 1; i >= 0; i--) {
} v += cio_bytein(cio) << (i << 3);
return v; }
return v;
} }

File diff suppressed because it is too large Load Diff

View File

@ -54,10 +54,10 @@ DCCS-LIWT properties
typedef struct opj_wtfilt { typedef struct opj_wtfilt {
double *LPS; double *LPS;
int lenLPS; int lenLPS;
double *HPS; double *HPS;
int lenHPS; int lenHPS;
} opj_wtfilt_t; } opj_wtfilt_t;
/** @name Funciones generales */ /** @name Funciones generales */
/*@{*/ /*@{*/

View File

@ -37,10 +37,11 @@
#ifndef _WIN32 #ifndef _WIN32
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r)
if (i/r > 0) a = i2a(i/r,a,r); {
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; if (i/r > 0) a = i2a(i/r,a,r);
return a+1; *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
} }
/** /**
@ -52,135 +53,132 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a @return Returns a
*/ */
static char * static char *
_itoa(int i, char *a, int r) { _itoa(int i, char *a, int r)
r = ((r < 2) || (r > 36)) ? 10 : r; {
if(i < 0) { r = ((r < 2) || (r > 36)) ? 10 : r;
*a = '-'; if(i < 0) {
*i2a(-i, a+1, r) = 0; *a = '-';
} *i2a(-i, a+1, r) = 0;
else *i2a(i, a, r) = 0; } else *i2a(i, a, r) = 0;
return a; return a;
} }
#endif /* !_WIN32 */ #endif /* !_WIN32 */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context)
if(cinfo) { {
opj_event_mgr_t *previous = cinfo->event_mgr; if(cinfo) {
cinfo->event_mgr = event_mgr; opj_event_mgr_t *previous = cinfo->event_mgr;
cinfo->client_data = context; cinfo->event_mgr = event_mgr;
return previous; cinfo->client_data = context;
} return previous;
}
return NULL; return NULL;
} }
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...)
{
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL; opj_msg_callback msg_handler = NULL;
opj_event_mgr_t *event_mgr = cinfo->event_mgr; opj_event_mgr_t *event_mgr = cinfo->event_mgr;
if(event_mgr != NULL) { if(event_mgr != NULL) {
switch(event_type) { switch(event_type) {
case EVT_ERROR: case EVT_ERROR:
msg_handler = event_mgr->error_handler; msg_handler = event_mgr->error_handler;
break; break;
case EVT_WARNING: case EVT_WARNING:
msg_handler = event_mgr->warning_handler; msg_handler = event_mgr->warning_handler;
break; break;
case EVT_INFO: case EVT_INFO:
msg_handler = event_mgr->info_handler; msg_handler = event_mgr->info_handler;
break; break;
default: default:
break; break;
} }
if(msg_handler == NULL) { if(msg_handler == NULL) {
return false; return false;
} }
} else { } else {
return false; return false;
} }
if ((fmt != NULL) && (event_mgr != NULL)) { if ((fmt != NULL) && (event_mgr != NULL)) {
va_list arg; va_list arg;
int str_length, i, j; int str_length, i, j;
char message[MSG_SIZE]; char message[MSG_SIZE];
memset(message, 0, MSG_SIZE); memset(message, 0, MSG_SIZE);
/* initialize the optional parameter list */ /* initialize the optional parameter list */
va_start(arg, fmt); va_start(arg, fmt);
/* check the length of the format string */ /* check the length of the format string */
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt); str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
/* parse the format string and put the result in 'message' */ /* parse the format string and put the result in 'message' */
for (i = 0, j = 0; i < str_length; ++i) { for (i = 0, j = 0; i < str_length; ++i) {
if (fmt[i] == '%') { if (fmt[i] == '%') {
if (i + 1 < str_length) { if (i + 1 < str_length) {
switch(tolower(fmt[i + 1])) { switch(tolower(fmt[i + 1])) {
case '%' : case '%' :
message[j++] = '%'; message[j++] = '%';
break; break;
case 'o' : /* octal numbers */ case 'o' : { /* octal numbers */
{ char tmp[16];
char tmp[16]; _itoa(va_arg(arg, int), tmp, 8);
_itoa(va_arg(arg, int), tmp, 8); strcat(message, tmp);
strcat(message, tmp); j += strlen(tmp);
j += strlen(tmp); ++i;
++i; break;
break; }
} case 'i' : /* decimal numbers */
case 'i' : /* decimal numbers */ case 'd' : {
case 'd' : char tmp[16];
{ _itoa(va_arg(arg, int), tmp, 10);
char tmp[16]; strcat(message, tmp);
_itoa(va_arg(arg, int), tmp, 10); j += strlen(tmp);
strcat(message, tmp); ++i;
j += strlen(tmp); break;
++i; }
break; case 'x' : { /* hexadecimal numbers */
} char tmp[16];
case 'x' : /* hexadecimal numbers */ _itoa(va_arg(arg, int), tmp, 16);
{ strcat(message, tmp);
char tmp[16]; j += strlen(tmp);
_itoa(va_arg(arg, int), tmp, 16); ++i;
strcat(message, tmp); break;
j += strlen(tmp); }
++i; case 's' : { /* strings */
break; char *tmp = va_arg(arg, char*);
} strcat(message, tmp);
case 's' : /* strings */ j += strlen(tmp);
{ ++i;
char *tmp = va_arg(arg, char*); break;
strcat(message, tmp); }
j += strlen(tmp); case 'f' : { /* floats */
++i; char tmp[16];
break; double value = va_arg(arg, double);
} sprintf(tmp, "%f", value);
case 'f' : /* floats */ strcat(message, tmp);
{ j += strlen(tmp);
char tmp[16]; ++i;
double value = va_arg(arg, double); break;
sprintf(tmp, "%f", value); }
strcat(message, tmp); };
j += strlen(tmp); } else {
++i; message[j++] = fmt[i];
break; }
} } else {
}; message[j++] = fmt[i];
} else { };
message[j++] = fmt[i]; }
} /* deinitialize the optional parameter list */
} else { va_end(arg);
message[j++] = fmt[i];
};
}
/* deinitialize the optional parameter list */
va_end(arg);
/* output the message to the user program */ /* output the message to the user program */
msg_handler(message, cinfo->client_data); msg_handler(message, cinfo->client_data);
} }
return true; return true;
} }

View File

@ -57,7 +57,8 @@ Multiply two fixed-precision rational numbers.
@param b @param b
@return Returns a * b @return Returns a * b
*/ */
static int fix_mul(int a, int b) { static int fix_mul(int a, int b)
{
int64 temp = (int64) a * (int64) b >> 12; int64 temp = (int64) a * (int64) b >> 12;
return (int) ((temp >> 1) + (temp & 1)) ; return (int) ((temp >> 1) + (temp & 1)) ;
} }

View File

@ -51,15 +51,17 @@ The functions in INT.H have for goal to realize operations on integers.
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static int int_min(int a, int b) { static int int_min(int a, int b)
return a < b ? a : b; {
return a < b ? a : b;
} }
/** /**
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static int int_max(int a, int b) { static int int_max(int a, int b)
return (a > b) ? a : b; {
return (a > b) ? a : b;
} }
/** /**
Clamp an integer inside an interval Clamp an integer inside an interval
@ -70,54 +72,61 @@ Clamp an integer inside an interval
<li>Returns min if (a < min) <li>Returns min if (a < min)
</ul> </ul>
*/ */
static int int_clamp(int a, int min, int max) { static int int_clamp(int a, int min, int max)
if (a < min) {
return min; if (a < min)
if (a > max) return min;
return max; if (a > max)
return a; return max;
return a;
} }
/** /**
@return Get absolute value of integer @return Get absolute value of integer
*/ */
static int int_abs(int a) { static int int_abs(int a)
return a < 0 ? -a : a; {
return a < 0 ? -a : a;
} }
static double dbl_abs(double a) { static double dbl_abs(double a)
return a < 0 ? -a : a; {
return a < 0 ? -a : a;
} }
/** /**
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
return (a + b - 1) / b; {
return (a + b - 1) / b;
} }
/** /**
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static int int_ceildivpow2(int a, int b) { static int int_ceildivpow2(int a, int b)
return (a + (1 << b) - 1) >> b; {
return (a + (1 << b) - 1) >> b;
} }
/** /**
Divide an integer by a power of 2 and round downwards Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static int int_floordivpow2(int a, int b) { static int int_floordivpow2(int a, int b)
return a >> b; {
return a >> b;
} }
/** /**
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static int int_floorlog2(int a) { static int int_floorlog2(int a)
int l; {
for (l = 0; a > 1; l++) { int l;
a >>= 1; for (l = 0; a > 1; l++) {
} a >>= 1;
return l; }
return l;
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

File diff suppressed because it is too large Load Diff

View File

@ -131,20 +131,20 @@ Values that specify the status of the decoding process when decoding the main he
These values may be combined with a | operator. These values may be combined with a | operator.
*/ */
typedef enum J3D_STATUS { typedef enum J3D_STATUS {
/**< a SOC marker is expected */ /**< a SOC marker is expected */
J3D_STATE_MHSOC = 0x0001, J3D_STATE_MHSOC = 0x0001,
/**< a SIZ marker is expected */ /**< a SIZ marker is expected */
J3D_STATE_MHSIZ = 0x0002, J3D_STATE_MHSIZ = 0x0002,
/**< the decoding process is in the main header */ /**< the decoding process is in the main header */
J3D_STATE_MH = 0x0004, J3D_STATE_MH = 0x0004,
/**< the decoding process is in a tile part header and expects a SOT marker */ /**< the decoding process is in a tile part header and expects a SOT marker */
J3D_STATE_TPHSOT = 0x0008, J3D_STATE_TPHSOT = 0x0008,
/**< the decoding process is in a tile part header */ /**< the decoding process is in a tile part header */
J3D_STATE_TPH = 0x0010, J3D_STATE_TPH = 0x0010,
/**< the EOC marker has just been read */ /**< the EOC marker has just been read */
J3D_STATE_MT = 0x0020, J3D_STATE_MT = 0x0020,
/**< the decoding process must not expect a EOC marker because the codestream is truncated */ /**< the decoding process must not expect a EOC marker because the codestream is truncated */
J3D_STATE_NEOC = 0x0040 J3D_STATE_NEOC = 0x0040
} J3D_STATUS; } J3D_STATUS;
@ -153,32 +153,32 @@ typedef enum J3D_STATUS {
Arbitrary transformation kernel Arbitrary transformation kernel
*/ */
typedef struct opj_atk { typedef struct opj_atk {
/** index of wavelet kernel */ /** index of wavelet kernel */
int index; int index;
/** Numerical type of scaling factor and lifting step parameters */ /** Numerical type of scaling factor and lifting step parameters */
int coeff_typ; int coeff_typ;
/** Wavelet filter category */ /** Wavelet filter category */
int filt_cat; int filt_cat;
/** Wavelet transformation type (REV/IRR) */ /** Wavelet transformation type (REV/IRR) */
int wt_typ; int wt_typ;
/** Initial odd/even subsequence */ /** Initial odd/even subsequence */
int minit; int minit;
/** Boundary extension method (constant CON / whole-sample symmetric WS) */ /** Boundary extension method (constant CON / whole-sample symmetric WS) */
int exten; int exten;
/** Scaling factor. Only for wt_typ=IRR */ /** Scaling factor. Only for wt_typ=IRR */
double Katk; double Katk;
/** Number of lifting steps */ /** Number of lifting steps */
int Natk; int Natk;
/** Offset for lifting step s. Only for filt_cat=ARB */ /** Offset for lifting step s. Only for filt_cat=ARB */
int Oatk[256]; int Oatk[256];
/** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */ /** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */
int Eatk[256]; int Eatk[256];
/** Additive residue for lifting step s. Only for wt_typ=REV */ /** Additive residue for lifting step s. Only for wt_typ=REV */
int Batk[256]; int Batk[256];
/** Number of lifting coefficients signaled for lifting step s */ /** Number of lifting coefficients signaled for lifting step s */
int LCatk[256]; int LCatk[256];
/** Lifting coefficient k for lifting step s */ /** Lifting coefficient k for lifting step s */
double Aatk[256][256]; double Aatk[256][256];
} opj_atk_t; } opj_atk_t;
@ -186,42 +186,42 @@ typedef struct opj_atk {
Quantization stepsize Quantization stepsize
*/ */
typedef struct opj_stepsize { typedef struct opj_stepsize {
/** exponent */ /** exponent */
int expn; int expn;
/** mantissa */ /** mantissa */
int mant; int mant;
} opj_stepsize_t; } opj_stepsize_t;
/** /**
Tile-component coding parameters Tile-component coding parameters
*/ */
typedef struct opj_tccp { typedef struct opj_tccp {
/** coding style */ /** coding style */
int csty; int csty;
/** number of resolutions of x, y and z-axis */ /** number of resolutions of x, y and z-axis */
int numresolution[3]; int numresolution[3];
/** code-blocks width height & depth*/ /** code-blocks width height & depth*/
int cblk[3]; int cblk[3];
/** code-block coding style */ /** code-block coding style */
int cblksty; int cblksty;
/** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/ /** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/
int atk_wt[3]; int atk_wt[3];
/** Arbitrary transformation kernel (15444-2)*/ /** Arbitrary transformation kernel (15444-2)*/
opj_atk_t *atk; opj_atk_t *atk;
/** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */ /** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */
int dwtid[3]; int dwtid[3];
/** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/ /** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/
int reversible; int reversible;
/** quantisation style */ /** quantisation style */
int qntsty; int qntsty;
/** stepsizes used for quantization */ /** stepsizes used for quantization */
opj_stepsize_t stepsizes[J3D_MAXBANDS]; opj_stepsize_t stepsizes[J3D_MAXBANDS];
/** number of guard bits. Table A28 de 15444-1*/ /** number of guard bits. Table A28 de 15444-1*/
int numgbits; int numgbits;
/** Region Of Interest shift */ /** Region Of Interest shift */
int roishift; int roishift;
/** precinct width heigth & depth*/ /** precinct width heigth & depth*/
int prctsiz[3][J3D_MAXRLVLS]; int prctsiz[3][J3D_MAXRLVLS];
} opj_tccp_t; } opj_tccp_t;
/** /**
@ -229,140 +229,140 @@ Tile coding parameters : coding/decoding parameters common to all tiles
(information like COD, COC in main header) (information like COD, COC in main header)
*/ */
typedef struct opj_tcp { typedef struct opj_tcp {
/** 1 : first part-tile of a tile */ /** 1 : first part-tile of a tile */
int first; int first;
/** coding style */ /** coding style */
int csty; int csty;
/** progression order */ /** progression order */
OPJ_PROG_ORDER prg; OPJ_PROG_ORDER prg;
/** number of layers */ /** number of layers */
int numlayers; int numlayers;
/** multi-component transform identifier */ /** multi-component transform identifier */
int mct; int mct;
/** rates of layers */ /** rates of layers */
float rates[100]; float rates[100];
/** number of progression order changes */ /** number of progression order changes */
int numpocs; int numpocs;
/** indicates if a POC marker has been used O:NO, 1:YES */ /** indicates if a POC marker has been used O:NO, 1:YES */
int POC; int POC;
/** progression order changes */ /** progression order changes */
opj_poc_t pocs[J3D_MAXRLVLS - 1]; opj_poc_t pocs[J3D_MAXRLVLS - 1];
/** add fixed_quality */ /** add fixed_quality */
float distoratio[100]; float distoratio[100];
/** tile-component coding parameters */ /** tile-component coding parameters */
opj_tccp_t *tccps; opj_tccp_t *tccps;
/** packet header store there for futur use in t2_decode_packet */ /** packet header store there for futur use in t2_decode_packet */
unsigned char *ppt_data; unsigned char *ppt_data;
/** pointer remaining on the first byte of the first header if ppt is used */ /** pointer remaining on the first byte of the first header if ppt is used */
unsigned char *ppt_data_first; unsigned char *ppt_data_first;
/** If ppt == 1 --> there was a PPT marker for the present tile */ /** If ppt == 1 --> there was a PPT marker for the present tile */
int ppt; int ppt;
/** used in case of multiple marker PPT (number of info already stored) */ /** used in case of multiple marker PPT (number of info already stored) */
int ppt_store; int ppt_store;
int ppt_len; int ppt_len;
} opj_tcp_t; } opj_tcp_t;
/** /**
Coding parameters Coding parameters
*/ */
typedef struct opj_cp { typedef struct opj_cp {
/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
OPJ_TRANSFORM transform_format; OPJ_TRANSFORM transform_format;
/** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/
OPJ_ENTROPY_CODING encoding_format; OPJ_ENTROPY_CODING encoding_format;
/** allocation by rate/distortion */ /** allocation by rate/distortion */
int disto_alloc; int disto_alloc;
/** allocation by fixed layer */ /** allocation by fixed layer */
int fixed_alloc; int fixed_alloc;
/** add fixed_quality */ /** add fixed_quality */
int fixed_quality; int fixed_quality;
/** Rsiz: capabilities */ /** Rsiz: capabilities */
int rsiz; int rsiz;
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */
int reduce[3]; int reduce[3];
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
int layer; int layer;
/** 0 = no index || 1 = index */ /** 0 = no index || 1 = index */
int index_on; int index_on;
/** Big-Endian/Little-endian order */ /** Big-Endian/Little-endian order */
int bigendian; int bigendian;
/** XTOsiz */ /** XTOsiz */
int tx0; int tx0;
/** YTOsiz */ /** YTOsiz */
int ty0; int ty0;
/** ZTOsiz */ /** ZTOsiz */
int tz0; int tz0;
/** XTsiz */ /** XTsiz */
int tdx; int tdx;
/** YTsiz */ /** YTsiz */
int tdy; int tdy;
/** ZTsiz */ /** ZTsiz */
int tdz; int tdz;
/** comment for coding */ /** comment for coding */
char *comment; char *comment;
/** number of tiles in width, heigth and depth */ /** number of tiles in width, heigth and depth */
int tw; int tw;
int th; int th;
int tl; int tl;
/** ID number of the tiles present in the codestream */ /** ID number of the tiles present in the codestream */
int *tileno; int *tileno;
/** size of the vector tileno */ /** size of the vector tileno */
int tileno_size; int tileno_size;
/** tile coding parameters */ /** tile coding parameters */
opj_tcp_t *tcps; opj_tcp_t *tcps;
/** fixed layer */ /** fixed layer */
int *matrice; int *matrice;
/** packet header store there for futur use in t2_decode_packet */ /** packet header store there for futur use in t2_decode_packet */
unsigned char *ppm_data; unsigned char *ppm_data;
/** pointer remaining on the first byte of the first header if ppm is used */ /** pointer remaining on the first byte of the first header if ppm is used */
unsigned char *ppm_data_first; unsigned char *ppm_data_first;
/** if ppm == 1 --> there was a PPM marker for the present tile */ /** if ppm == 1 --> there was a PPM marker for the present tile */
int ppm; int ppm;
/** use in case of multiple marker PPM (number of info already store) */ /** use in case of multiple marker PPM (number of info already store) */
int ppm_store; int ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */ /** use in case of multiple marker PPM (case on non-finished previous info) */
int ppm_previous; int ppm_previous;
int ppm_len; int ppm_len;
} opj_cp_t; } opj_cp_t;
/** /**
Information concerning a packet inside tile Information concerning a packet inside tile
*/ */
typedef struct opj_packet_info { typedef struct opj_packet_info {
/** start position */ /** start position */
int start_pos; int start_pos;
/** end position */ /** end position */
int end_pos; int end_pos;
/** distorsion introduced */ /** distorsion introduced */
double disto; double disto;
} opj_packet_info_t; } opj_packet_info_t;
/** /**
Index structure : information regarding tiles inside volume Index structure : information regarding tiles inside volume
*/ */
typedef struct opj_tile_info { typedef struct opj_tile_info {
/** value of thresh for each layer by tile cfr. Marcela */ /** value of thresh for each layer by tile cfr. Marcela */
double *thresh; double *thresh;
/** number of tile */ /** number of tile */
int num_tile; int num_tile;
/** start position */ /** start position */
int start_pos; int start_pos;
/** end position of the header */ /** end position of the header */
int end_header; int end_header;
/** end position */ /** end position */
int end_pos; int end_pos;
/** precinct number for each resolution level (width, heigth and depth) */ /** precinct number for each resolution level (width, heigth and depth) */
int prctno[3][J3D_MAXRLVLS]; int prctno[3][J3D_MAXRLVLS];
/** precinct size (in power of 2), in X for each resolution level */ /** precinct size (in power of 2), in X for each resolution level */
int prctsiz[3][J3D_MAXRLVLS]; int prctsiz[3][J3D_MAXRLVLS];
/** information concerning packets inside tile */ /** information concerning packets inside tile */
opj_packet_info_t *packet; opj_packet_info_t *packet;
/** add fixed_quality */ /** add fixed_quality */
int nbpix; int nbpix;
/** add fixed_quality */ /** add fixed_quality */
double distotile; double distotile;
} opj_tile_info_t; } opj_tile_info_t;
/** /**
@ -370,85 +370,85 @@ Index structure
*/ */
typedef struct opj_volume_info { typedef struct opj_volume_info {
/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
OPJ_TRANSFORM transform_format; OPJ_TRANSFORM transform_format;
/** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/
OPJ_ENTROPY_CODING encoding_format; /** 0 = no index || 1 = index */ OPJ_ENTROPY_CODING encoding_format; /** 0 = no index || 1 = index */
int index_on; int index_on;
/** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */ /** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */
int dwtid[3]; int dwtid[3];
/** maximum distortion reduction on the whole volume (add for Marcela) */ /** maximum distortion reduction on the whole volume (add for Marcela) */
double D_max; double D_max;
/** packet number */ /** packet number */
int num; int num;
/** writing the packet in the index with t2_encode_packets */ /** writing the packet in the index with t2_encode_packets */
int index_write; int index_write;
/** volume width, height and depth */ /** volume width, height and depth */
int volume_w; int volume_w;
int volume_h; int volume_h;
int volume_l; int volume_l;
/** progression order */ /** progression order */
OPJ_PROG_ORDER prog; OPJ_PROG_ORDER prog;
/** tile size in x, y and z */ /** tile size in x, y and z */
int tile_x; int tile_x;
int tile_y; int tile_y;
int tile_z; int tile_z;
/** tile origin in x, y and z */ /** tile origin in x, y and z */
int tile_Ox; int tile_Ox;
int tile_Oy; int tile_Oy;
int tile_Oz; int tile_Oz;
/** number of tiles in X, Y and Z */ /** number of tiles in X, Y and Z */
int tw; int tw;
int th; int th;
int tl; int tl;
/** component numbers */ /** component numbers */
int comp; int comp;
/** number of layer */ /** number of layer */
int layer; int layer;
/** number of decomposition in X, Y and Z*/ /** number of decomposition in X, Y and Z*/
int decomposition[3]; int decomposition[3];
/** DC offset (15444-2) */ /** DC offset (15444-2) */
int dcoffset; int dcoffset;
/** main header position */ /** main header position */
int main_head_end; int main_head_end;
/** codestream's size */ /** codestream's size */
int codestream_size; int codestream_size;
/** information regarding tiles inside volume */ /** information regarding tiles inside volume */
opj_tile_info_t *tile; opj_tile_info_t *tile;
} opj_volume_info_t; } opj_volume_info_t;
/** /**
JPEG-2000 codestream reader/writer JPEG-2000 codestream reader/writer
*/ */
typedef struct opj_j3d { typedef struct opj_j3d {
/** codec context */ /** codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
/** locate in which part of the codestream the decoder is (main header, tile header, end) */ /** locate in which part of the codestream the decoder is (main header, tile header, end) */
int state; int state;
/** number of the tile curently concern by coding/decoding */ /** number of the tile curently concern by coding/decoding */
int curtileno; int curtileno;
/** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod) */ /** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod) */
unsigned char *eot; unsigned char *eot;
/** locate the start position of the SOT marker of the current coded tile: */ /** locate the start position of the SOT marker of the current coded tile: */
int sot_start; int sot_start;
/* after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */ /* after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */
int sod_start; int sod_start;
/** as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell */ /** as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell */
int pos_correction; int pos_correction;
/** array used to store the data of each tile */ /** array used to store the data of each tile */
unsigned char **tile_data; unsigned char **tile_data;
/** array used to store the length of each tile */ /** array used to store the length of each tile */
int *tile_len; int *tile_len;
/** decompression only : store decoding parameters common to all tiles */ /** decompression only : store decoding parameters common to all tiles */
opj_tcp_t *default_tcp; opj_tcp_t *default_tcp;
/** pointer to the encoded / decoded volume */ /** pointer to the encoded / decoded volume */
opj_volume_t *volume; opj_volume_t *volume;
/** pointer to the coding parameters */ /** pointer to the coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
/** helper used to write the index file */ /** helper used to write the index file */
opj_volume_info_t *volume_info; opj_volume_info_t *volume_info;
/** pointer to the byte i/o stream */ /** pointer to the byte i/o stream */
opj_cio_t *cio; opj_cio_t *cio;
} opj_j3d_t; } opj_j3d_t;

View File

@ -38,44 +38,48 @@
#endif /* _WIN32 */ #endif /* _WIN32 */
#include "opj_includes.h" #include "opj_includes.h"
double opj_clock() { double opj_clock()
{
#ifdef _WIN32 #ifdef _WIN32
/* WIN32: use QueryPerformance (very accurate) */ /* WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */ /* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ; QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */ /* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */ /* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ; QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(double) freq.QuadPart ) ; return ( t.QuadPart /(double) freq.QuadPart ) ;
#else #else
/* Unix or Linux: use resource usage */ /* Unix or Linux: use resource usage */
struct rusage t; struct rusage t;
double procTime; double procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */ /* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t); getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */ /* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */ /* (2a) Get the seconds */
procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec;
/* (2b) More precisely! Get the microseconds part ! */ /* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
void* opj_malloc( size_t size ) { void* opj_malloc( size_t size )
void *memblock = malloc(size); {
if(memblock) { void *memblock = malloc(size);
memset(memblock, 0, size); if(memblock) {
} memset(memblock, 0, size);
return memblock; }
return memblock;
} }
void* opj_realloc( void *memblock, size_t size ) { void* opj_realloc( void *memblock, size_t size )
return realloc(memblock, size); {
return realloc(memblock, size);
} }
void opj_free( void *memblock ) { void opj_free( void *memblock )
free(memblock); {
free(memblock);
} }

Some files were not shown because too many files have changed in this diff Show More