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

@@ -2,10 +2,10 @@
/* Cause a compile-time error if off_t is smaller than 64 bits */ /* Cause a compile-time error if off_t is smaller than 64 bits */
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ]; int off_t_is_large[ (LARGE_OFF_T % 2147483629 == 721 && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1 ];
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
return 0; return 0;
} }

View File

@@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 3-clauses * The copyright in this software is being made available under the 3-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -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)
{
fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
return NULL;
}
if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0)
{
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
goto fin;
}
if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL)) == NULL)
goto fin;
if((info = png_create_info_struct(png)) == NULL)
goto fin;
if(setjmp(png_jmpbuf(png)))
goto fin;
png_init_io(png, reader);
png_set_sig_bytes(png, MAGIC_SIZE);
png_read_info(png, info);
if(png_get_IHDR(png, info, &width, &height,
&bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0)
goto fin;
/* png_set_expand():
* expand paletted images to RGB, expand grayscale images of
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels.
*/
if(color_type == PNG_COLOR_TYPE_PALETTE) {
png_set_expand(png);
}
if(png_get_valid(png, info, PNG_INFO_tRNS)) {
png_set_expand(png);
}
/* We might wan't to expand background */
/*
if(png_get_valid(png, info, PNG_INFO_bKGD)) {
png_color_16p bgnd;
png_get_bKGD(png, info, &bgnd);
png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
}
*/
if( !png_get_gAMA(png, info, &gamma))
gamma = 1.0;
/* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info);
color_type = png_get_color_type(png, info);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
nr_comp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2;
break;
case PNG_COLOR_TYPE_RGB:
nr_comp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4;
break;
default:
fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type);
goto fin;
}
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) {
case 1:
case 2:
case 4:
case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break;
case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R;
break;
default:
fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth);
goto fin;
}
if((reader = fopen(read_idf, "rb")) == NULL) {
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*)); fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
for(i = 0; i < height; ++i) return NULL;
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info)); }
png_read_image(png, rows); if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
/* Create image */ fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
memset(cmptparm, 0, sizeof(cmptparm)); goto fin;
for(i = 0; i < nr_comp; ++i) }
{
cmptparm[i].prec = (OPJ_UINT32)bit_depth; if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING,
/* bits_per_pixel: 8 or 16 */ NULL, NULL, NULL)) == NULL)
cmptparm[i].bpp = (OPJ_UINT32)bit_depth; goto fin;
cmptparm[i].sgnd = 0; if((info = png_create_info_struct(png)) == NULL)
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx; goto fin;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].w = (OPJ_UINT32)width; if(setjmp(png_jmpbuf(png)))
cmptparm[i].h = (OPJ_UINT32)height; goto fin;
}
png_init_io(png, reader);
image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY); png_set_sig_bytes(png, MAGIC_SIZE);
if(image == NULL) goto fin;
image->x0 = (OPJ_UINT32)params->image_offset_x0; png_read_info(png, info);
image->y0 = (OPJ_UINT32)params->image_offset_y0;
image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)params->subsampling_dx + 1 + image->x0); if(png_get_IHDR(png, info, &width, &height,
image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)params->subsampling_dy + 1 + image->y0); &bit_depth, &color_type, &interlace_type,
&compression_type, &filter_type) == 0)
row32s = (OPJ_INT32 *)malloc((size_t)width * nr_comp * sizeof(OPJ_INT32)); goto fin;
if(row32s == NULL) goto fin;
/* png_set_expand():
/* Set alpha channel */ * expand paletted images to RGB, expand grayscale images of
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U); * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels.
for(i = 0; i < nr_comp; i++) */
{ if(color_type == PNG_COLOR_TYPE_PALETTE) {
planes[i] = image->comps[i].data; png_set_expand(png);
} }
for(i = 0; i < height; ++i) if(png_get_valid(png, info, PNG_INFO_tRNS)) {
{ png_set_expand(png);
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp); }
cvtCxToPx(row32s, planes, width); /* We might wan't to expand background */
planes[0] += width; /*
planes[1] += width; if(png_get_valid(png, info, PNG_INFO_bKGD)) {
planes[2] += width; png_color_16p bgnd;
planes[3] += width; png_get_bKGD(png, info, &bgnd);
} png_set_background(png, bgnd, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
}
*/
if( !png_get_gAMA(png, info, &gamma))
gamma = 1.0;
/* we're not displaying but converting, screen gamma == 1.0 */
png_set_gamma(png, 1.0, gamma);
png_read_update_info(png, info);
color_type = png_get_color_type(png, info);
switch (color_type) {
case PNG_COLOR_TYPE_GRAY:
nr_comp = 1;
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
nr_comp = 2;
break;
case PNG_COLOR_TYPE_RGB:
nr_comp = 3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
nr_comp = 4;
break;
default:
fprintf(stderr,"pngtoimage: colortype %d is not supported\n", color_type);
goto fin;
}
cvtCxToPx = convert_32s_CXPX_LUT[nr_comp];
bit_depth = png_get_bit_depth(png, info);
switch (bit_depth) {
case 1:
case 2:
case 4:
case 8:
cvtXXTo32s = convert_XXu32s_C1R_LUT[bit_depth];
break;
case 16: /* 16 bpp is specific to PNG */
cvtXXTo32s = convert_16u32s_C1R;
break;
default:
fprintf(stderr,"pngtoimage: bit depth %d is not supported\n", bit_depth);
goto fin;
}
rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*));
for(i = 0; i < height; ++i)
rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info));
png_read_image(png, rows);
/* Create image */
memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i) {
cmptparm[i].prec = (OPJ_UINT32)bit_depth;
/* bits_per_pixel: 8 or 16 */
cmptparm[i].bpp = (OPJ_UINT32)bit_depth;
cmptparm[i].sgnd = 0;
cmptparm[i].dx = (OPJ_UINT32)params->subsampling_dx;
cmptparm[i].dy = (OPJ_UINT32)params->subsampling_dy;
cmptparm[i].w = (OPJ_UINT32)width;
cmptparm[i].h = (OPJ_UINT32)height;
}
image = opj_image_create(nr_comp, &cmptparm[0], (nr_comp > 2U) ? OPJ_CLRSPC_SRGB : OPJ_CLRSPC_GRAY);
if(image == NULL) goto fin;
image->x0 = (OPJ_UINT32)params->image_offset_x0;
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->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));
if(row32s == NULL) goto fin;
/* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++) {
planes[i] = image->comps[i].data;
}
for(i = 0; i < height; ++i) {
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width);
planes[0] += width;
planes[1] += width;
planes[2] += 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;
memset(&sig_bit, 0, sizeof(sig_bit));
prec = (int)image->comps[0].prec;
planes[0] = image->comps[0].data;
nr_comp = (int)image->numcomps;
if (nr_comp > 4) {
nr_comp = 4;
}
for (i = 1; i < nr_comp; ++i) {
if (image->comps[0].dx != image->comps[i].dx) {
break;
}
if (image->comps[0].dy != image->comps[i].dy) {
break;
}
if (image->comps[0].prec != image->comps[i].prec) {
break;
}
if (image->comps[0].sgnd != image->comps[i].sgnd) {
break;
}
planes[i] = image->comps[i].data;
}
if (i != nr_comp) {
fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if(prec > 8 && prec < 16)
{
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16);
}
prec = 16;
}
else if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */
{
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8);
}
prec = 8;
} else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */
if ((prec == 5) || (prec == 6)) {
prec = 8;
} else {
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)
{
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
return fails;
}
writer = fopen(write_idf, "wb");
if(writer == NULL) return fails;
/* Create and initialize the png_struct with the desired error handler
* 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
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if(png == NULL) goto fin;
/* Allocate/initialize the image information data. REQUIRED
*/
info = png_create_info_struct(png);
if(info == NULL) goto fin;
/* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if(setjmp(png_jmpbuf(png))) goto fin;
/* I/O initialization functions is REQUIRED
*/
png_init_io(png, writer);
/* 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
* 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,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && 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_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) /* RGB(A) */
{
color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
}
else /* GRAY(A) */
{
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (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_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info);
/* setup conversion */
{
OPJ_SIZE_T rowStride;
png_size_t png_row_size;
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;
if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n");
goto fin;
}
row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin;
}
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin;
}
}
/* convert */
{
OPJ_SIZE_T width= image->comps[0].w;
OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s;
switch (prec) { volatile int fails = 1;
case 1:
case 2: memset(&sig_bit, 0, sizeof(sig_bit));
case 4: prec = (int)image->comps[0].prec;
case 8: planes[0] = image->comps[0].data;
cvt32sToPack = convert_32sXXu_C1R_LUT[prec]; nr_comp = (int)image->numcomps;
break;
case 16: if (nr_comp > 4) {
cvt32sToPack = convert_32s16u_C1R; nr_comp = 4;
break; }
default: for (i = 1; i < nr_comp; ++i) {
/* never here */ if (image->comps[0].dx != image->comps[i].dx) {
break; break;
} }
if (image->comps[0].dy != image->comps[i].dy) {
for(y = 0; y < image->comps[0].h; ++y) break;
{ }
cvtPxToCx(planes, buffer32s_cpy, width, adjust); if (image->comps[0].prec != image->comps[i].prec) {
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp); break;
png_write_row(png, row_buf_cpy); }
planes[0] += width; if (image->comps[0].sgnd != image->comps[i].sgnd) {
planes[1] += width; break;
planes[2] += width; }
planes[3] += width; planes[i] = image->comps[i].data;
} }
} if (i != nr_comp) {
fprintf(stderr,"imagetopng: All components shall have the same subsampling, same bit depth, same sign.\n");
fprintf(stderr,"\tAborting\n");
return 1;
}
for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec);
}
if(prec > 8 && prec < 16) {
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16);
}
prec = 16;
} else if(prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */
for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8);
}
prec = 8;
} else if((prec > 1) && (prec < 8) && ((prec == 6) || ((prec & 1)==1))) { /* GRAY with non native precision */
if ((prec == 5) || (prec == 6)) {
prec = 8;
} else {
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) {
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
return fails;
}
writer = fopen(write_idf, "wb");
if(writer == NULL) return fails;
/* Create and initialize the png_struct with the desired error handler
* 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
* the library version is compatible with the one used at compile time,
* in case we are using dynamically linked libraries. REQUIRED.
*/
png = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */
if(png == NULL) goto fin;
/* Allocate/initialize the image information data. REQUIRED
*/
info = png_create_info_struct(png);
if(info == NULL) goto fin;
/* Set error handling. REQUIRED if you are not supplying your own
* error handling functions in the png_create_write_struct() call.
*/
if(setjmp(png_jmpbuf(png))) goto fin;
/* I/O initialization functions is REQUIRED
*/
png_init_io(png, writer);
/* 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
* 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,
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && 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_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) { /* RGB(A) */
color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
} else { /* GRAY(A) */
color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (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_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_sBIT(png, info, &sig_bit);
/* png_set_gamma(png, 2.2, 1./2.2); */
/* png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); */
png_write_info(png, info);
/* setup conversion */
{
OPJ_SIZE_T rowStride;
png_size_t png_row_size;
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;
if (rowStride != (OPJ_SIZE_T)png_row_size) {
fprintf(stderr, "Invalid PNG row size\n");
goto fin;
}
row_buf = (png_bytep)malloc(png_row_size);
if (row_buf == NULL) {
fprintf(stderr, "Can't allocate memory for PNG row\n");
goto fin;
}
buffer32s = (OPJ_INT32*)malloc((OPJ_SIZE_T)image->comps[0].w * (OPJ_SIZE_T)nr_comp * sizeof(OPJ_INT32));
if (buffer32s == NULL) {
fprintf(stderr, "Can't allocate memory for interleaved 32s row\n");
goto fin;
}
}
/* convert */
{
OPJ_SIZE_T width= image->comps[0].w;
OPJ_UINT32 y;
convert_32s_PXCX cvtPxToCx = convert_32s_PXCX_LUT[nr_comp];
convert_32sXXx_C1R cvt32sToPack = NULL;
OPJ_INT32 adjust = image->comps[0].sgnd ? 1 << (prec - 1) : 0;
png_bytep row_buf_cpy = row_buf;
OPJ_INT32* buffer32s_cpy = buffer32s;
switch (prec) {
case 1:
case 2:
case 4:
case 8:
cvt32sToPack = convert_32sXXu_C1R_LUT[prec];
break;
case 16:
cvt32sToPack = convert_32s16u_C1R;
break;
default:
/* never here */
break;
}
for(y = 0; y < image->comps[0].h; ++y) {
cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
png_write_row(png, row_buf_cpy);
planes[0] += width;
planes[1] += width;
planes[2] += width;
planes[3] += width;
}
}
png_write_end(png, info);
fails = 0;
png_write_end(png, info);
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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -42,356 +42,357 @@
/** /**
Write a structured index to a file Write a structured index to a file
@param cstr_info Codestream information @param cstr_info Codestream information
@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)
disto_on = 1;
else
disto_on = 0;
if (cstr_info->tile[0].numpix) if (cstr_info->tile[0].distotile)
numpix_on = 1; disto_on = 1;
else else
numpix_on = 0; disto_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); if (cstr_info->tile[0].numpix)
fprintf(stream, "%d\n", cstr_info->prog); numpix_on = 1;
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); else
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); numpix_on = 0;
fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "[%d,%d] ", fprintf(stream, "%d\n", cstr_info->prog);
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ 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\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
fprintf(stream, "\n"); for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
/* UniPG>> */ fprintf(stream, "[%d,%d] ",
fprintf(stream, "%d\n", cstr_info->main_head_start); (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
/* <<UniPG */ }
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on)
fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { fprintf(stream, "\n");
fprintf(stream, "%4d %9d %9d %9d %9d", /* UniPG>> */
cstr_info->tile[tileno].tileno, fprintf(stream, "%d\n", cstr_info->main_head_start);
cstr_info->tile[tileno].start_pos, /* <<UniPG */
cstr_info->tile[tileno].end_header, fprintf(stream, "%d\n", cstr_info->main_head_end);
cstr_info->tile[tileno].end_pos, fprintf(stream, "%d\n", cstr_info->codestream_size);
cstr_info->tile[tileno].num_tps);
if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
OPJ_OFF_T start_pos, end_ph_pos, end_pos;
double disto = 0;
int max_numdecompos = 0;
pack_nb = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) { fprintf(stream, "\nINFO ON TILES\n");
if (max_numdecompos < cstr_info->numdecompos[compno]) fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
max_numdecompos = cstr_info->numdecompos[compno]; if (disto_on)
} fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
fprintf(stream, "\nTILE %d DETAILS\n", tileno); for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); fprintf(stream, "%4d %9d %9d %9d %9d",
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) cstr_info->tile[tileno].tileno,
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", cstr_info->tile[tileno].start_pos,
tilepartno, tileno, cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, cstr_info->tile[tileno].num_tps);
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, if (disto_on)
cstr_info->tile[tileno].tp[tilepartno].tp_end_header, fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos if (numpix_on)
); fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos"); OPJ_OFF_T start_pos, end_ph_pos, end_pos;
if (disto_on) double disto = 0;
fprintf(stream, " disto"); int max_numdecompos = 0;
fprintf(stream,"\n"); pack_nb = 0;
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) { if (max_numdecompos < cstr_info->numdecompos[compno])
for (compno = 0; compno < cstr_info->numcomps; compno++) { max_numdecompos = cstr_info->numdecompos[compno];
int prec_max; }
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */ fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
if (disto_on) for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, " disto"); fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
fprintf(stream,"\n"); tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
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_pos
);
for (resno = 0; resno < max_numdecompos + 1; resno++) { if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
for (layno = 0; layno < cstr_info->numlayers; layno++) { fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
for (compno = 0; compno < cstr_info->numcomps; compno++) { if (disto_on)
int prec_max; fprintf(stream, " disto");
if (resno > cstr_info->numdecompos[compno]) fprintf(stream,"\n");
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* RLCP */
else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */ for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
if (disto_on) fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
fprintf(stream, " disto"); if (disto_on)
fprintf(stream,"\n"); fprintf(stream, " disto");
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]; for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (precno = 0; precno < numprec; precno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */ int prec_max;
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; if (resno > cstr_info->numdecompos[compno])
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; break;
int x1 = x0 + cstr_info->tile_x; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int y1 = y0 + cstr_info->tile_y; for (precno = 0; precno < prec_max; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
int pcnx = cstr_info->tile[tileno].pw[resno]; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); disto = cstr_info->tile[tileno].packet[pack_nb].disto;
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; fprintf(stream, "%4d %6d %5d %7d %6d %6d %9" PRId64 " %9" PRId64 " %7" PRId64,
int precno_y = (int) floor( (float)precno/(float)pcnx ); pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (resno > cstr_info->numdecompos[compno]) if (disto_on)
break; fprintf(stream, " %8e", disto);
for(y = y0; y < y1; y++) { fprintf(stream, "\n");
if (precno_y*pcy == y ) { total_disto += disto;
for (x = x0; x < x1; x++) { pack_nb++;
if (precno_x*pcx == x ) { }
for (layno = 0; layno < cstr_info->numlayers; layno++) { }
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; } /* RLCP */
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */ else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */
/* 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 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 y1 = y0 + cstr_info->tile_y;
/* Count the maximum number of precincts */ fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
int max_numprec = 0; if (disto_on)
for (resno = 0; resno < max_numdecompos + 1; resno++) { fprintf(stream, " disto");
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; fprintf(stream,"\n");
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); for (resno = 0; resno < max_numdecompos + 1; resno++) {
if (disto_on) int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
fprintf(stream, " disto"); for (precno = 0; precno < numprec; precno++) {
fprintf(stream,"\n"); /* 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 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 y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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 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_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno])
break;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
for (precno = 0; precno < max_numprec; precno++) { else if (cstr_info->prog == OPJ_PCRL) { /* PCRL */
for (compno = 0; compno < cstr_info->numcomps; compno++) { /* I suppose components have same XRsiz, YRsiz */
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int pcnx = cstr_info->tile[tileno].pw[resno]; int x1 = x0 + cstr_info->tile_x;
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int y1 = y0 + cstr_info->tile_y;
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_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
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, "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 (compno = 0; compno < cstr_info->numcomps; compno++) { for (precno = 0; precno < max_numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */ for (compno = 0; compno < cstr_info->numcomps; compno++) {
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int x1 = x0 + cstr_info->tile_x; int pcnx = cstr_info->tile[tileno].pw[resno];
int y1 = y0 + cstr_info->tile_y; 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 precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
for (precno = 0; precno < max_numprec; precno++) { else { /* CPRL */
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { /* Count the maximum number of precincts */
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int max_numprec = 0;
int pcnx = cstr_info->tile[tileno].pw[resno]; for (resno = 0; resno < max_numdecompos + 1; resno++) {
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); if (numprec > max_numprec)
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; max_numprec = numprec;
int precno_y = (int) floor( (float)precno/(float)pcnx ); }
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) { fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (precno_y*pcy == y ) { if (disto_on)
for (x = x0; x < x1; x++) { fprintf(stream, " disto");
if (precno_x*pcx == x ) { fprintf(stream,"\n");
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
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);
}
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* 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 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 y1 = y0 + cstr_info->tile_y;
return 0; for (precno = 0; precno < max_numprec; precno++) {
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 pcnx = cstr_info->tile[tileno].pw[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 precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
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);
}
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index);
return 0;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -40,7 +40,7 @@ extern "C" {
/** /**
Write a structured index to a file Write a structured index to a file
@param cstr_info Codestream information @param cstr_info Codestream information
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2010, Mathieu Malaterre, GDCM * Copyright (c) 2010, Mathieu Malaterre, GDCM
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
strcpy(dirptr->filename[i],content->d_name); while((content=readdir(dir))!=NULL) {
i++; if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
} continue;
closedir(dir);
return 0; strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
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; case 'y': { /* Image Directory path */
} img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
break; 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

@@ -1,9 +1,9 @@
/* /*
* uce-dirent.h - operating system independent dirent implementation * uce-dirent.h - operating system independent dirent implementation
* *
* Copyright (C) 1998-2002 Toni Ronkko * Copyright (C) 1998-2002 Toni Ronkko
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including * ``Software''), to deal in the Software without restriction, including
@@ -11,10 +11,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -22,8 +22,8 @@
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
* *
* *
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi> * May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
* *
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $ * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
@@ -59,7 +59,7 @@
* Revision 1.1 1998/07/04 16:27:51 tr * Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision * Initial revision
* *
* *
* MSVC 1.0 scans automatic dependencies incorrectly when your project * MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle * contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered. * include directives inside #if..#endif block those are never entered.
@@ -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" {
@@ -325,7 +325,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory * internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest. * entries. The internal working area has no fields of your interest.
* *
* <ret>Returns a pointer to the internal working area or NULL in case the * <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set * directory stream could not be opened. Global `errno' variable will set
* in case of error as follows: * in case of error as follows:
* *
@@ -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;
} }
@@ -509,37 +508,37 @@ 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,31 +565,31 @@ 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,37 +599,36 @@ 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,14 +639,14 @@ 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,16 +654,17 @@ _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,
_getdirname (&dirp->current), strncpy (dirp->current.d_name,
NAME_MAX); _getdirname (&dirp->current),
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif # endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,51 +1,51 @@
/* /*
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, M<>nica D<>ez Garc<72>a, Image Processing Laboratory, University of Valladolid, Spain * Copyright (c) 2006, M<>nica D<>ez Garc<72>a, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef __JP3D_CONVERT_H #ifndef __JP3D_CONVERT_H
#define __JP3D_CONVERT_H #define __JP3D_CONVERT_H
/** /**
Load a single volume component encoded in PGX file format Load a single volume component encoded in PGX file format
@param filename Name of the PGX file to load @param filename Name of the PGX file to load
@param parameters *List ?* @param parameters *List ?*
@return Returns a greyscale volume if successful, returns NULL otherwise @return Returns a greyscale volume if successful, returns NULL otherwise
*/ */
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters); opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile); int volumetopgx(opj_volume_t *volume, char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters); opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile); int volumetobin(opj_volume_t *volume, char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters); opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */ #endif /* __J2K_CONVERT_H */

View File

@@ -1,109 +1,110 @@
/* /*
* Copyright (c) 1987, 1993, 1994 * Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software * 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement: * must display the following acknowledgement:
* This product includes software developed by the University of * This product includes software developed by the University of
* California, Berkeley and its contributors. * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors * 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* last review : october 29th, 2002 */ /* last review : october 29th, 2002 */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95"; static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#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)'?'
#define BADARG (int)':' #define BADARG (int)':'
#define EMSG "" #define EMSG ""
/* /*
* 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 */
char *oli; /* option letter list index */ static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0; if (optreset || !*place) { /* update scanning pointer */
if (optind >= nargc || *(place = nargv[optind]) != '-') { optreset = 0;
place = EMSG; if (optind >= nargc || *(place = nargv[optind]) != '-') {
return (-1); place = EMSG;
} return (-1);
if (place[1] && *++place == '-') { /* found "--" */ }
++optind; if (place[1] && *++place == '-') { /* found "--" */
place = EMSG; ++optind;
return (-1); place = EMSG;
} return (-1);
} /* option letter okay? */ }
} /* 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) *place++) == (int) ':' || !(oli = strchr(ostr, optopt))) {
if (optopt == (int) '-') /* if the user didn't specify '-' as an option, assume it means -1. */
return (-1); if (optopt == (int) '-')
if (!*place) return (-1);
++optind; if (!*place)
if (opterr && *ostr != ':') ++optind;
(void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt); if (opterr && *ostr != ':')
return (BADCH); (void) fprintf(stdout,"[ERROR] %s: illegal option -- %c\n", __progname, optopt);
} return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL; if (*++oli != ':') { /* don't need argument */
if (!*place) optarg = NULL;
++optind; if (!*place)
} else { /* need an argument */ ++optind;
if (*place) /* no white space */ } else { /* need an argument */
optarg = place; if (*place) /* no white space */
else if (nargc <= ++optind) { /* no arg */ optarg = place;
place = EMSG; else if (nargc <= ++optind) { /* no arg */
if (*ostr == ':') place = EMSG;
return (BADARG); if (*ostr == ':')
if (opterr) return (BADARG);
(void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt); if (opterr)
return (BADCH); (void) fprintf(stdout, "[ERROR] %s: option requires an argument -- %c\n", __progname, optopt);
} else /* white space */ return (BADCH);
optarg = nargv[optind]; } else /* white space */
place = EMSG; optarg = nargv[optind];
++optind; place = EMSG;
} ++optind;
return (optopt); /* dump back option letter */ }
} return (optopt); /* dump back option letter */
}

View File

@@ -1,14 +1,14 @@
/* last review : october 29th, 2002 */ /* last review : october 29th, 2002 */
#ifndef _GETOPT_H_ #ifndef _GETOPT_H_
#define _GETOPT_H_ #define _GETOPT_H_
extern int opterr; extern int opterr;
extern int optind; extern int optind;
extern int optopt; extern int optopt;
extern int optreset; extern int optreset;
extern char *optarg; extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr); extern int getopt(int nargc, char *const *nargv, const char *ostr);
#endif /* _GETOPT_H_ */ #endif /* _GETOPT_H_ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,8 @@
/* /*
* uce-dirent.h - operating system independent dirent implementation * uce-dirent.h - operating system independent dirent implementation
* *
* Copyright (C) 1998-2002 Toni Ronkko * Copyright (C) 1998-2002 Toni Ronkko
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including * ``Software''), to deal in the Software without restriction, including
@@ -10,10 +10,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -21,8 +21,8 @@
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
* *
* *
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi> * May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
* *
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $ * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
@@ -58,7 +58,7 @@
* Revision 1.1 1998/07/04 16:27:51 tr * Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision * Initial revision
* *
* *
* MSVC 1.0 scans automatic dependencies incorrectly when your project * MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle * contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered. * include directives inside #if..#endif block those are never entered.
@@ -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" {
@@ -324,7 +324,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory * internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest. * entries. The internal working area has no fields of your interest.
* *
* <ret>Returns a pointer to the internal working area or NULL in case the * <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set * directory stream could not be opened. Global `errno' variable will set
* in case of error as follows: * in case of error as follows:
* *
@@ -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;
} }
@@ -508,37 +507,37 @@ 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;
} }
@@ -565,31 +564,31 @@ 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*/;
} }
} }
@@ -599,37 +598,36 @@ 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,14 +638,14 @@ 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,16 +653,17 @@ _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,
_getdirname (&dirp->current), strncpy (dirp->current.d_name,
NAME_MAX); _getdirname (&dirp->current),
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif # endif

View File

@@ -42,7 +42,7 @@
* quit\n * quit\n
* Be sure all image viewers are closed.\n * Be sure all image viewers are closed.\n
* Cache file in JPT format is stored in the working directly before it quites. * Cache file in JPT format is stored in the working directly before it quites.
* *
*/ */
#include <stdio.h> #include <stdio.h>
@@ -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;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
if( argc > 1) dec_server_record_t *server_record;
port = atoi( argv[1]); client_t client;
int port = 50000;
int erreur;
(void)erreur;
if( argc > 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

@@ -36,7 +36,7 @@
* -# Input/output image file in JP2 format, this JP2 file is being modified * -# Input/output image file in JP2 format, this JP2 file is being modified
* -# Input XML file with metadata contents\n * -# Input XML file with metadata contents\n
* % ./addXMLinJP2 image.jp2 metadata.xml\n * % ./addXMLinJP2 image.jp2 metadata.xml\n
* *
* Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n * Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n
* The following is an example of XML file contents specifying Region Of Interests with target names.\n * The following is an example of XML file contents specifying Region Of Interests with target names.\n
* <xmlbox>\n * <xmlbox>\n
@@ -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);
if( fsize < 0 ) return -1;
boxsize = fsize + 8;
fputc( (boxsize>>24)&0xff, fp); xmldata = read_xmlfile( argv[2], &fsize);
fputc( (boxsize>>16)&0xff, fp); if( fsize < 0 ) return -1;
fputc( (boxsize>>8)&0xff, fp); boxsize = fsize + 8;
fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp); fputc( (boxsize>>24)&0xff, fp);
fwrite( xmldata, (size_t)fsize, 1, fp); fputc( (boxsize>>16)&0xff, fp);
fputc( (boxsize>>8)&0xff, fp);
free( xmldata); fputc( boxsize&0xff, fp);
fclose(fp); fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp);
return 0;
free( xmldata);
fclose(fp);
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){
fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp);
return NULL;
}
assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1){ return data;
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){
fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1;
}
if( !(jp2idx = get_index_from_JP2file( fd))){ if( (fd = open( argv[1], O_RDONLY)) == -1) {
fprintf( stderr, "JP2 file broken\n"); fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1; return -1;
} }
output_index( jp2idx);
destroy_index( &jp2idx);
close(fd);
return 0; if( !(jp2idx = get_index_from_JP2file( fd))) {
fprintf( stderr, "JP2 file broken\n");
return -1;
}
output_index( jp2idx);
destroy_index( &jp2idx);
close(fd);
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);
if(!( fread_jpip( argv[1], dec)))
return 1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */ dec = init_jpipdecoder( OPJ_TRUE);
destroy_jpipdecoder( &dec); if(!( fread_jpip( argv[1], dec)))
return 1;
return 0; decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */
destroy_jpipdecoder( &dec);
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);
if(!( fread_jpip( argv[1], dec)))
return 1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */
destroy_jpipdecoder( &dec);
return 0; dec = init_jpipdecoder( OPJ_FALSE);
if(!( fread_jpip( argv[1], dec)))
return 1;
decode_jpip( dec);
if(!(fwrite_jp2k( argv[2], dec)))
return 1;
/* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */
destroy_jpipdecoder( &dec);
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

@@ -3,7 +3,7 @@
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2010-2011, Kaori Hagihara * Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011, Lucian Corlaciu, GSoC * Copyright (c) 2011, Lucian Corlaciu, GSoC
* All rights reserved. * All rights reserved.
* *
@@ -41,7 +41,7 @@
* *
* Note: JP2 files are stored in the working directory of opj_server\n * Note: JP2 files are stored in the working directory of opj_server\n
* Check README for the JP2 Encoding\n * Check README for the JP2 Encoding\n
* *
* We tested this software with a virtual server running on the same Linux machine as the clients. * We tested this software with a virtual server running on the same Linux machine as the clients.
*/ */
@@ -60,69 +60,69 @@ WSADATA initialisation_win32;
#endif /*_WIN32*/ #endif /*_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);
parse_status = process_JPIPrequest( server_record, qr);
#ifndef SERVER
local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record);
#endif
if( parse_status)
send_responsedata( server_record, qr);
else{
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n");
}
end_QRprocess( server_record, &qr);
}
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
terminate_JPIPserver( &server_record); qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr);
#ifndef SERVER
local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record);
#endif
if( parse_status)
send_responsedata( server_record, qr);
else {
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n");
}
end_QRprocess( server_record, &qr);
}
fprintf( FCGI_stderr, "JPIP server terminated by a client request\n");
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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -41,356 +41,357 @@
/** /**
Write a structured index to a file Write a structured index to a file
@param cstr_info Codestream information @param cstr_info Codestream information
@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)
disto_on = 1;
else
disto_on = 0;
if (cstr_info->tile[0].numpix) if (cstr_info->tile[0].distotile)
numpix_on = 1; disto_on = 1;
else else
numpix_on = 0; disto_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h); if (cstr_info->tile[0].numpix)
fprintf(stream, "%d\n", cstr_info->prog); numpix_on = 1;
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y); else
fprintf(stream, "%d %d\n", cstr_info->tw, cstr_info->th); numpix_on = 0;
fprintf(stream, "%d\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) { fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "[%d,%d] ", fprintf(stream, "%d\n", cstr_info->prog);
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */ 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\n", cstr_info->numcomps);
fprintf(stream, "%d\n", cstr_info->numlayers);
fprintf(stream, "%d\n", cstr_info->numdecompos[0]); /* based on component 0 */
fprintf(stream, "\n"); for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
/* UniPG>> */ fprintf(stream, "[%d,%d] ",
fprintf(stream, "%d\n", cstr_info->main_head_start); (1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
/* <<UniPG */ }
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
fprintf(stream, "\nINFO ON TILES\n");
fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
if (disto_on)
fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) { fprintf(stream, "\n");
fprintf(stream, "%4d %9d %9d %9d %9d", /* UniPG>> */
cstr_info->tile[tileno].tileno, fprintf(stream, "%d\n", cstr_info->main_head_start);
cstr_info->tile[tileno].start_pos, /* <<UniPG */
cstr_info->tile[tileno].end_header, fprintf(stream, "%d\n", cstr_info->main_head_end);
cstr_info->tile[tileno].end_pos, fprintf(stream, "%d\n", cstr_info->codestream_size);
cstr_info->tile[tileno].num_tps);
if (disto_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
if (numpix_on)
fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
int start_pos, end_ph_pos, end_pos;
double disto = 0;
int max_numdecompos = 0;
pack_nb = 0;
for (compno = 0; compno < cstr_info->numcomps; compno++) { fprintf(stream, "\nINFO ON TILES\n");
if (max_numdecompos < cstr_info->numdecompos[compno]) fprintf(stream, "tileno start_pos end_hd end_tile nbparts");
max_numdecompos = cstr_info->numdecompos[compno]; if (disto_on)
} fprintf(stream," disto");
if (numpix_on)
fprintf(stream," nbpix");
if (disto_on && numpix_on)
fprintf(stream," disto/nbpix");
fprintf(stream, "\n");
fprintf(stream, "\nTILE %d DETAILS\n", tileno); for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n"); fprintf(stream, "%4d %9d %9d %9d %9d",
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++) cstr_info->tile[tileno].tileno,
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n", cstr_info->tile[tileno].start_pos,
tilepartno, tileno, cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack, cstr_info->tile[tileno].end_pos,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks, cstr_info->tile[tileno].num_tps);
cstr_info->tile[tileno].tp[tilepartno].tp_start_pos, if (disto_on)
cstr_info->tile[tileno].tp[tilepartno].tp_end_header, fprintf(stream," %9e", cstr_info->tile[tileno].distotile);
cstr_info->tile[tileno].tp[tilepartno].tp_end_pos if (numpix_on)
); fprintf(stream," %9d", cstr_info->tile[tileno].numpix);
if (disto_on && numpix_on)
fprintf(stream," %9e", cstr_info->tile[tileno].distotile / cstr_info->tile[tileno].numpix);
fprintf(stream, "\n");
}
if (cstr_info->prog == LRCP) { /* LRCP */ for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos"); int start_pos, end_ph_pos, end_pos;
if (disto_on) double disto = 0;
fprintf(stream, " disto"); int max_numdecompos = 0;
fprintf(stream,"\n"); pack_nb = 0;
for (layno = 0; layno < cstr_info->numlayers; layno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) { if (max_numdecompos < cstr_info->numdecompos[compno])
for (compno = 0; compno < cstr_info->numcomps; compno++) { max_numdecompos = cstr_info->numdecompos[compno];
int prec_max; }
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
else if (cstr_info->prog == RLCP) { /* RLCP */ fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n"); fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
if (disto_on) for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, " disto"); fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\n",
fprintf(stream,"\n"); tilepartno, tileno,
cstr_info->tile[tileno].tp[tilepartno].tp_start_pack,
cstr_info->tile[tileno].tp[tilepartno].tp_numpacks,
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_pos
);
for (resno = 0; resno < max_numdecompos + 1; resno++) { if (cstr_info->prog == LRCP) { /* LRCP */
for (layno = 0; layno < cstr_info->numlayers; layno++) { fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
for (compno = 0; compno < cstr_info->numcomps; compno++) { if (disto_on)
int prec_max; fprintf(stream, " disto");
if (resno > cstr_info->numdecompos[compno]) fprintf(stream,"\n");
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* RLCP */
else if (cstr_info->prog == RPCL) { /* RPCL */ for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (resno = 0; resno < max_numdecompos + 1; resno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
int prec_max;
if (resno > cstr_info->numdecompos[compno])
break;
prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < prec_max; precno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}
}
} /* LRCP */
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos"); else if (cstr_info->prog == RLCP) { /* RLCP */
if (disto_on) fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
fprintf(stream, " disto"); if (disto_on)
fprintf(stream,"\n"); fprintf(stream, " disto");
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]; for (layno = 0; layno < cstr_info->numlayers; layno++) {
for (precno = 0; precno < numprec; precno++) { for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* I suppose components have same XRsiz, YRsiz */ int prec_max;
int x0 = cstr_info->tile_Ox + tileno - (int)floor((float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; if (resno > cstr_info->numdecompos[compno])
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; break;
int x1 = x0 + cstr_info->tile_x; prec_max = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int y1 = y0 + cstr_info->tile_y; for (precno = 0; precno < prec_max; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) { start_pos = cstr_info->tile[tileno].packet[pack_nb].start_pos;
int pcnx = cstr_info->tile[tileno].pw[resno]; end_ph_pos = cstr_info->tile[tileno].packet[pack_nb].end_ph_pos;
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); end_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); disto = cstr_info->tile[tileno].packet[pack_nb].disto;
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %7d",
int precno_y = (int) floor( (float)precno/(float)pcnx ); pack_nb, tileno, resno, layno, compno, precno, start_pos, end_ph_pos, end_pos);
if (resno > cstr_info->numdecompos[compno]) if (disto_on)
break; fprintf(stream, " %8e", disto);
for(y = y0; y < y1; y++) { fprintf(stream, "\n");
if (precno_y*pcy == y ) { total_disto += disto;
for (x = x0; x < x1; x++) { pack_nb++;
if (precno_x*pcx == x ) { }
for (layno = 0; layno < cstr_info->numlayers; layno++) { }
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos; } /* RLCP */
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
else if (cstr_info->prog == PCRL) { /* PCRL */ else if (cstr_info->prog == RPCL) { /* RPCL */
/* 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 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 y1 = y0 + cstr_info->tile_y;
/* Count the maximum number of precincts */ fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
int max_numprec = 0; if (disto_on)
for (resno = 0; resno < max_numdecompos + 1; resno++) { fprintf(stream, " disto");
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; fprintf(stream,"\n");
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos"); for (resno = 0; resno < max_numdecompos + 1; resno++) {
if (disto_on) int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
fprintf(stream, " disto"); for (precno = 0; precno < numprec; precno++) {
fprintf(stream,"\n"); /* 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 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 y1 = y0 + cstr_info->tile_y;
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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 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_y = (int) floor( (float)precno/(float)pcnx );
if (resno > cstr_info->numdecompos[compno])
break;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* precno */
} /* compno */
} /* resno */
} /* RPCL */
for (precno = 0; precno < max_numprec; precno++) { else if (cstr_info->prog == PCRL) { /* PCRL */
for (compno = 0; compno < cstr_info->numcomps; compno++) { /* I suppose components have same XRsiz, YRsiz */
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x;
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y;
int pcnx = cstr_info->tile[tileno].pw[resno]; int x1 = x0 + cstr_info->tile_x;
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int y1 = y0 + cstr_info->tile_y;
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_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
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, "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 (compno = 0; compno < cstr_info->numcomps; compno++) { for (precno = 0; precno < max_numprec; precno++) {
/* I suppose components have same XRsiz, YRsiz */ for (compno = 0; compno < cstr_info->numcomps; compno++) {
int x0 = cstr_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tw * cstr_info->tile_x; for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) {
int y0 = cstr_info->tile_Ox + (int)floor( (float)tileno/(float)cstr_info->tw ) * cstr_info->tile_y; int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int x1 = x0 + cstr_info->tile_x; int pcnx = cstr_info->tile[tileno].pw[resno];
int y1 = y0 + cstr_info->tile_y; 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 precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* compno */
} /* precno */
} /* PCRL */
for (precno = 0; precno < max_numprec; precno++) { else { /* CPRL */
for (resno = 0; resno < cstr_info->numdecompos[compno] + 1; resno++) { /* Count the maximum number of precincts */
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno]; int max_numprec = 0;
int pcnx = cstr_info->tile[tileno].pw[resno]; for (resno = 0; resno < max_numdecompos + 1; resno++) {
int pcx = (int) pow( 2, cstr_info->tile[tileno].pdx[resno] + cstr_info->numdecompos[compno] - resno ); int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
int pcy = (int) pow( 2, cstr_info->tile[tileno].pdy[resno] + cstr_info->numdecompos[compno] - resno ); if (numprec > max_numprec)
int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; max_numprec = numprec;
int precno_y = (int) floor( (float)precno/(float)pcnx ); }
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) { fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (precno_y*pcy == y ) { if (disto_on)
for (x = x0; x < x1; x++) { fprintf(stream, " disto");
if (precno_x*pcx == x ) { fprintf(stream,"\n");
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
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);
}
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); for (compno = 0; compno < cstr_info->numcomps; compno++) {
/* 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 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 y1 = y0 + cstr_info->tile_y;
return 0; for (precno = 0; precno < max_numprec; precno++) {
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 pcnx = cstr_info->tile[tileno].pw[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 precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx;
int precno_y = (int) floor( (float)precno/(float)pcnx );
if (precno >= numprec)
continue;
for(y = y0; y < y1; y++) {
if (precno_y*pcy == y ) {
for (x = x0; x < x1; x++) {
if (precno_x*pcx == x ) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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_pos = cstr_info->tile[tileno].packet[pack_nb].end_pos;
disto = cstr_info->tile[tileno].packet[pack_nb].disto;
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);
if (disto_on)
fprintf(stream, " %8e", disto);
fprintf(stream, "\n");
total_disto += disto;
pack_nb++;
}
}
}/* x = x0..x1 */
}
} /* y = y0..y1 */
} /* resno */
} /* precno */
} /* compno */
} /* CPRL */
} /* tileno */
if (disto_on) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */
}
/* UniPG>> */
/* print the markers' list */
if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n");
fprintf(stream, "%d\n", cstr_info->marknum);
fprintf(stream, "type\tstart_pos length\n");
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);
}
/* <<UniPG */
fclose(stream);
fprintf(stderr,"Generated index file %s\n", index);
return 0;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -40,7 +40,7 @@ extern "C" {
/** /**
Write a structured index to a file Write a structured index to a file
@param cstr_info Codestream information @param cstr_info Codestream information
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
/* /*
* uce-dirent.h - operating system independent dirent implementation * uce-dirent.h - operating system independent dirent implementation
* *
* Copyright (C) 1998-2002 Toni Ronkko * Copyright (C) 1998-2002 Toni Ronkko
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the * a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including * ``Software''), to deal in the Software without restriction, including
@@ -11,10 +11,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to * distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to * permit persons to whom the Software is furnished to do so, subject to
* the following conditions: * the following conditions:
* *
* The above copyright notice and this permission notice shall be included * The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software. * in all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -22,8 +22,8 @@
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
* *
* *
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi> * May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
* *
* $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $ * $Id: uce-dirent.h,v 1.7 2002/05/13 10:48:35 tr Exp $
@@ -59,7 +59,7 @@
* Revision 1.1 1998/07/04 16:27:51 tr * Revision 1.1 1998/07/04 16:27:51 tr
* Initial revision * Initial revision
* *
* *
* MSVC 1.0 scans automatic dependencies incorrectly when your project * MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle * contains this very header. The problem is that MSVC cannot handle
* include directives inside #if..#endif block those are never entered. * include directives inside #if..#endif block those are never entered.
@@ -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" {
@@ -325,7 +325,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory * internal working area that is used for retrieving individual directory
* entries. The internal working area has no fields of your interest. * entries. The internal working area has no fields of your interest.
* *
* <ret>Returns a pointer to the internal working area or NULL in case the * <ret>Returns a pointer to the internal working area or NULL in case the
* directory stream could not be opened. Global `errno' variable will set * directory stream could not be opened. Global `errno' variable will set
* in case of error as follows: * in case of error as follows:
* *
@@ -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;
} }
@@ -509,37 +508,37 @@ 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,31 +565,31 @@ 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,37 +599,36 @@ 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,14 +639,14 @@ 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,16 +654,17 @@ _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,
_getdirname (&dirp->current), strncpy (dirp->current.d_name,
NAME_MAX); _getdirname (&dirp->current),
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/ NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
} }
# ifdef __cplusplus # ifdef __cplusplus
} }
# endif # endif

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
/* Contributed to Open JPEG by Glenn Pearson, contract software developer, U.S. National Library of Medicine. /* Contributed to Open JPEG by Glenn Pearson, contract software developer, U.S. National Library of Medicine.
The base code in this file was developed by the author as part of a video archiving The base code in this file was developed by the author as part of a video archiving
project for the U.S. National Library of Medicine, Bethesda, MD. project for the U.S. National Library of Medicine, Bethesda, MD.
It is the policy of NLM (and U.S. government) to not assert copyright. It is the policy of NLM (and U.S. government) to not assert copyright.
A non-exclusive copy of this code has been contributed to the Open JPEG project. A non-exclusive copy of this code has been contributed to the Open JPEG project.
@@ -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,"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,"headers of a sample frame. Excluded: low-level packed-bits image data.\n\n");
fprintf(stdout,"By Default\n"); fprintf(stdout,"mj2_to_metadata generates an XML file from a Motion JPEG 2000 file.\n");
fprintf(stdout,"----------\n"); fprintf(stdout,"The generated XML shows the structural, but not (yet) curatorial,\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n"); fprintf(stdout,"metadata from the movie header and from the JPEG 2000 image and tile\n");
fprintf(stdout,"\n"); fprintf(stdout,"headers of a sample frame. Excluded: low-level packed-bits image data.\n\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,"By Default\n");
fprintf(stdout,"\n"); fprintf(stdout,"----------\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n"); fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout," meaning of non-obvious tag abbreviations;\n"); fprintf(stdout,"\n");
fprintf(stdout," range and precision of valid values;\n"); fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n");
fprintf(stdout," interpretations of values, such as enumerations; and\n"); fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n");
fprintf(stdout," current implementation limitations.\n"); fprintf(stdout,"\n");
fprintf(stdout,"\n"); fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
fprintf(stdout,"The sample-size and chunk-offset tables, each with 1 row per frame, are not reported.\n"); fprintf(stdout," meaning of non-obvious tag abbreviations;\n");
fprintf(stdout,"\n"); fprintf(stdout," range and precision of valid values;\n");
fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n"); fprintf(stdout," interpretations of values, such as enumerations; and\n");
fprintf(stdout,"\n"); fprintf(stdout," current implementation limitations.\n");
fprintf(stdout,"Required Parameters (except with -h)\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,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n"); fprintf(stdout,"\n");
fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n"); fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n");
fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n"); fprintf(stdout,"\n");
fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n"); fprintf(stdout,"Required Parameters (except with -h)\n");
fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n"); fprintf(stdout,"------------------------------------\n");
fprintf(stdout,"\n"); fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n");
fprintf(stdout,"Optional Parameters\n"); fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n");
fprintf(stdout,"-------------------\n"); fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n");
fprintf(stdout,"-h : Display this help information.\n"); fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n");
fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n"); fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n");
fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n"); fprintf(stdout,"\n");
fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n"); fprintf(stdout,"Optional Parameters\n");
fprintf(stdout,"-f 0 : No jp2 header info.\n"); fprintf(stdout,"-------------------\n");
fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n"); fprintf(stdout,"-h : Display this help information.\n");
fprintf(stdout,"-d : Suppress all 'derived' data.\n"); fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n");
fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n"); fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n");
fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n"); fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n");
fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n"); fprintf(stdout,"-f 0 : No jp2 header info.\n");
fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n"); fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n");
fprintf(stdout," the output file: -v \"SYSTEM mj2_to_metadata.dtd\"\n"); fprintf(stdout,"-d : Suppress all 'derived' data.\n");
fprintf(stdout," \"PUBLIC\" is used with an access protocol (e.g., http:) + URL.\n"); fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n");
/* More to come */ fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n");
fprintf(stdout,"\n"); fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n");
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */ 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," \"PUBLIC\" is used with an access protocol (e.g., http:) + URL.\n");
/* More to come */
fprintf(stdout,"\n");
/* "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--;
if ((S1 == 'm' && S2 == 'j' && S3 == '2') S1 = *s;
|| (S1 == 'M' && S2 == 'J' && S3 == '2')) {
break;
}
fprintf(stderr, "Input file name must have .mj2 extension, not .%c%c%c.\n", S1, S2, S3);
return 1;
/* ----------------------------------------------------- */ if ((S1 == 'm' && S2 == 'j' && S3 == '2')
case 'o': /* OUT file */ || (S1 == 'M' && S2 == 'J' && S3 == '2')) {
outfile = optarg; break;
while (*outfile) { outfile++; } /* Run to filename end */ }
outfile--; fprintf(stderr, "Input file name must have .mj2 extension, not .%c%c%c.\n", S1, S2, S3);
S3 = *outfile; return 1;
outfile--;
S2 = *outfile;
outfile--;
S1 = *outfile;
outfile = optarg;
if ((S1 == 'x' && S2 == 'm' && S3 == 'l')
|| (S1 == 'X' && S2 == 'M' && S3 == 'L'))
break;
fprintf(stderr,
"Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3);
return 1;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* Choose sample frame. 0 = none */ case 'o': /* OUT file */
sscanf(optarg, "%u", &sampleframe); outfile = optarg;
break; while (*outfile) {
outfile++; /* Run to filename end */
}
outfile--;
S3 = *outfile;
outfile--;
S2 = *outfile;
outfile--;
S1 = *outfile;
/* ----------------------------------------------------- */ outfile = optarg;
case 'v': /* Verification by DTD. */
stringDTD = optarg;
/* We will not insist upon last 3 chars being "dtd", since non-file
access protocol may be used. */
if(strchr(stringDTD,'"') != NULL) {
fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n");
return 1;
}
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0) if ((S1 == 'x' && S2 == 'm' && S3 == 'l')
break; || (S1 == 'X' && S2 == 'M' && S3 == 'L'))
break;
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
return 1;
/* ----------------------------------------------------- */ fprintf(stderr,
case 'n': /* Suppress comments */ "Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3);
notes = FALSE; return 1;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* Show sample size and chunk offset tables */ case 'f': /* Choose sample frame. 0 = none */
sampletables = TRUE; sscanf(optarg, "%u", &sampleframe);
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* Display an help description */ case 'v': /* Verification by DTD. */
help_display(); stringDTD = optarg;
return 0; /* We will not insist upon last 3 chars being "dtd", since non-file
access protocol may be used. */
if(strchr(stringDTD,'"') != NULL) {
fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n");
return 1;
}
/* ----------------------------------------------------- */ if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
case 'r': /* Suppress raw data */ break;
raw = FALSE;
break;
/* ----------------------------------------------------- */ fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
case 'd': /* Suppress derived data */ return 1;
derived = FALSE;
break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
default: case 'n': /* Suppress comments */
return 1; notes = FALSE;
} /* switch */ break;
} /* while */
if(!raw && !derived) /* ----------------------------------------------------- */
raw = TRUE; /* At least one of 'raw' and 'derived' must be true */ case 't': /* Show sample size and chunk offset tables */
sampletables = TRUE;
break;
/* ----------------------------------------------------- */
case 'h': /* Display an help description */
help_display();
return 0;
/* ----------------------------------------------------- */
case 'r': /* Suppress raw data */
raw = FALSE;
break;
/* ----------------------------------------------------- */
case 'd': /* Suppress derived data */
derived = FALSE;
break;
/* ----------------------------------------------------- */
default:
return 1;
} /* switch */
} /* while */
if(!raw && !derived)
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] */
if (!file) {
fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: argv[1] */
return 1;
}
len = strlen(outfile); file = fopen(infile, "rb"); /* was: argv[1] */
if(outfile[0] == ' ')
{
outfile++; /* There may be a leading blank if user put space after -o */
}
// Checking output file if (!file) {
xmlout = fopen(outfile, "w"); /* was: argv[2] */ fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: argv[1] */
if (!xmlout) { return 1;
fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */ }
return 1;
}
// Leave it open
/* len = strlen(outfile);
configure the event callbacks (not required) if(outfile[0] == ' ') {
setting of each callback is optionnal outfile++; /* There may be a leading blank if user put space after -o */
*/ }
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 */ // Checking output file
dinfo = mj2_create_decompress(); xmlout = fopen(outfile, "w"); /* was: argv[2] */
if (!xmlout) {
fprintf(stderr, "Failed to open %s for writing.\n", outfile); /* was: argv[2] */
return 1;
}
// Leave it open
/* catch events using our callbacks and give a local context */ /*
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr); 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;
/* setup the decoder decoding parameters using user parameters */ /* get a MJ2 decompressor handle */
movie = (opj_mj2_t*) dinfo->mj2_handle; dinfo = mj2_create_decompress();
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) // Creating the movie structure /* 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 */
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
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) {
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1;
}
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
/* Checking output file */
outfile = fopen(argv[2], "w");
if (!file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
fclose(outfile);
/*
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 = NULL;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t)); if (argc != 3) {
/* set J2K decoding parameters to default values */ printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters); return 1;
}
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1;
/* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
}
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
return 1;
}
track = &movie->tk[tnum];
/* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples; file = fopen(argv[1], "rb");
for (snum=0; snum < numframes; snum++)
{
double init_time = opj_clock();
double elapsed_time;
sample = &track->sample[snum]; if (!file) {
if (sample->sample_size-8 > max_codstrm_size) { fprintf(stderr, "failed to open %s for reading\n", argv[1]);
max_codstrm_size = sample->sample_size-8; return 1;
if ((frame_codestream = (unsigned char*) }
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n"); /* Checking output file */
return 1; outfile = fopen(argv[2], "w");
}; if (!file) {
} fprintf(stderr, "failed to open %s for writing\n", argv[2]);
fseek(file,sample->offset+8,SEEK_SET); return 1;
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */ }
fclose(outfile);
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8); /*
configure the event callbacks (not required)
img = opj_decode(dinfo, cio); /* Decode J2K to image */ 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 = NULL;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t));
/* set J2K decoding parameters to default values */
opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters);
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
if (mj2_read_struct(file, movie)) /* Creating the movie structure */
return 1;
/* Decode first video track */
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
}
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
return 1;
}
track = &movie->tk[tnum];
/* Output info on first video tracl */
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++) {
double init_time = opj_clock();
double elapsed_time;
sample = &track->sample[snum];
if (sample->sample_size-8 > max_codstrm_size) {
max_codstrm_size = sample->sample_size-8;
if ((frame_codestream = (unsigned char*)
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n");
return 1;
};
}
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream, sample->sample_size-8, 1, file); /* Assuming that jp and ftyp markers size do */
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
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 */
return 1;
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(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);
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;
} if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1;
free(frame_codestream); } else if ((img->numcomps == 3) &&
fclose(file); (img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(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);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1;
/* free remaining structures */ } else {
if(dinfo) { fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle); fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
}
free(dinfo); sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum); if (!outfile) {
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time); fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
return 0; }
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;
}
free(frame_codestream);
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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -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); /*
configure the event callbacks (not required)
/* free remaining structures */ setting of each callback is optionnal
if(dinfo) { */
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
} event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
return 0; 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);
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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -41,14 +41,15 @@
#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;
} }
/** /**
Size of memory first allocated for MOOV box Size of memory first allocated for MOOV box
*/ */
#define TEMP_BUF 10000 #define TEMP_BUF 10000
#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51" #define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
@@ -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].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy); movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
mj2_init_stdmovie(movie); movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
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->comps[0].dx == 1) if (image->numcomps==3) {
&& (image->comps[1].dx == 1) if ((image->comps[0].dx == 1)
&& (image->comps[2].dx == 1)) && (image->comps[1].dx == 1)
movie->tk[0].CbCr_subsampling_dx = 1; && (image->comps[2].dx == 1))
else movie->tk[0].CbCr_subsampling_dx = 1;
if ((image->comps[0].dx == 1) else 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))
movie->tk[0].CbCr_subsampling_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
fprintf(stderr,"Image component sizes are incoherent\n"); movie->tk[0].jp2_struct.meth = 2;
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 else 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) && (image->comps[0].dy == 1)
&& (image->comps[0].dy == 1) && (image->comps[1].dy == 1)
&& (image->comps[1].dy == 1) && (image->comps[2].dy == 1))
&& (image->comps[2].dy == 1)) movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else if ((image->comps[0].dx == 1)
else && (image->comps[1].dx == 2)
if ((image->comps[0].dx == 1) && (image->comps[2].dx == 2)
&& (image->comps[1].dx == 2) && (image->comps[0].dy == 1)
&& (image->comps[2].dx == 2) && (image->comps[1].dy == 2)
&& (image->comps[0].dy == 1) && (image->comps[2].dy == 2))
&& (image->comps[1].dy == 2) movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */ else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
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) {
printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
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 */ if (argc != 3) {
cinfo = mj2_create_compress(); printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
/* catch events using our callbacks and give a local context */ return 1;
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");
offset += cio_tell(cio);
sample->offset = offset; if (!mj2file) {
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */ fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
/* 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); memset(&img, 0, sizeof(opj_image_t));
} /*
configure the event callbacks (not required)
/* Writing the MDAT box length in header */ setting of each callback is optionnal
offset += cio_tell(cio); */
buf = (unsigned char*) malloc (4 * sizeof(unsigned char)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
cio = opj_cio_open(movie->cinfo, buf, 4); event_mgr.error_handler = error_callback;
cio_write(cio,offset-mdat_initpos,4); event_mgr.warning_handler = warning_callback;
fseek(mj2file,(long)mdat_initpos,SEEK_SET); event_mgr.info_handler = info_callback;
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END); /* get a MJ2 decompressor handle */
free(buf); cinfo = mj2_create_compress();
/* Setting movie parameters */ /* catch events using our callbacks and give a local context */
movie->tk[0].num_samples=snum; opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
movie->tk[0].num_chunks=snum;
setparams(movie, &img); /* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
/* Writing MOOV box */ movie = (opj_mj2_t*) cinfo->mj2_handle;
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20)); j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
mj2_write_moov(movie, cio); sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
fwrite(buf,cio_tell(cio),1,mj2file);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
/* Ending program */
free(img.comps); parameters.frame_rate = 25; /* DEFAULT */
opj_cio_close(cio);
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);
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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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__ {
wxMutexGuiEnter(); #ifndef __WXGTK__
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

@@ -1 +1 @@
wxT("491") wxT("491")

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -72,120 +72,133 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
/*@}*/ /*@}*/
/* /*
========================================================== ==========================================================
local functions local functions
========================================================== ==========================================================
*/ */
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;
} }
/* /*
========================================================== ==========================================================
Bit Input/Output interface Bit Input/Output interface
========================================================== ==========================================================
*/ */
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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -40,7 +40,7 @@
#include <stddef.h> /* ptrdiff_t */ #include <stddef.h> /* ptrdiff_t */
/** /**
@file bio.h @file bio.h
@brief Implementation of an individual bit input-output (BIO) @brief Implementation of an individual bit input-output (BIO)
@@ -54,23 +54,23 @@ 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 */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Create a new BIO handle Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise @return Returns a new BIO handle if successful, returns NULL otherwise
*/ */
opj_bio_t* opj_bio_create(void); opj_bio_t* opj_bio_create(void);
@@ -89,14 +89,14 @@ ptrdiff_t opj_bio_numbytes(opj_bio_t *bio);
Init encoder Init encoder
@param bio BIO handle @param bio BIO handle
@param bp Output buffer @param bp Output buffer
@param len Output buffer length @param len Output buffer length
*/ */
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);
/** /**
Init decoder Init decoder
@param bio BIO handle @param bio BIO handle
@param bp Input buffer @param bp Input buffer
@param len Input buffer length @param len Input buffer length
*/ */
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);
/** /**
@@ -109,7 +109,7 @@ void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
/** /**
Read bits Read bits
@param bio BIO handle @param bio BIO handle
@param n Number of bits to read @param n Number of bits to read
@return Returns the corresponding read number @return Returns the corresponding read number
*/ */
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n); OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n);

View File

@@ -32,7 +32,7 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
* Write CPTR Codestream finder box * Write CPTR Codestream finder box
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -41,199 +41,197 @@
*/ */
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;
box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
box[num_box].type = JPIP_MHIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); num_box = 0;
box[num_box].type = JPIP_TPIX; box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
num_box++; box[num_box].type = JPIP_MHIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX;
num_box++;
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, 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].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); num_box++;
box[num_box].type = JPIP_PPIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX;
num_box++;
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); box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX;
return (int)len; num_box++;
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].type = JPIP_PPIX;
num_box++;
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX;
num_box++;
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);
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);
} }
void opj_write_manf(int second, void opj_write_manf(int second,
int v, int v,
opj_jp2_box_t *box, opj_jp2_box_t *box,
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);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager);
if (second){ /* Write only during the second pass */ lenp = opj_stream_tell(cio);
for( i=0; i<v; i++){ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */ 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);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
opj_stream_write_data(cio,l_data_header,4,p_manager); if (second) { /* Write only during the second pass */
for( i=0; i<v; i++) {
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
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);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
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 */ lenp = opj_stream_tell (cio);
opj_stream_write_data(cio,l_data_header,8,p_manager); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
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_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); opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_seek(cio, lenp,p_manager); opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++) { /* Marker restricted to 1 apparition, skip SOC marker */
opj_stream_seek(cio, lenp+len,p_manager); opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
return (int)len; 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_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);
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

@@ -40,7 +40,7 @@
#include "openjpeg.h" #include "openjpeg.h"
/* /*
* Write Codestream index box (superbox) * Write Codestream index box (superbox)
* *
* @param[in] offset offset of j2k codestream * @param[in] offset offset of j2k codestream
@@ -51,9 +51,9 @@
* @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
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -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_ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -82,13 +82,13 @@ Get the norm of a wavelet function of a subband at a specified level for the rev
*/ */
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient); OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient);
/** /**
Forward 9-7 wavelet transform in 2-D. Forward 9-7 wavelet transform in 2-D.
Apply an irreversible DWT transform to a component of an image. Apply an irreversible DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
*/ */
OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec); OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec);
/** /**
Inverse 9-7 wavelet transform in 2-D. Inverse 9-7 wavelet transform in 2-D.
Apply an irreversible inverse DWT transform to a component of an image. Apply an irreversible inverse DWT transform to a component of an image.
@param tilec Tile component information (current tile) @param tilec Tile component information (current tile)
@param numres Number of resolution levels to decode @param numres Number of resolution levels to decode
@@ -109,7 +109,7 @@ Get the norm of a wavelet function of a subband at a specified level for the irr
*/ */
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient); OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient);
/** /**
Explicit calculation of the Quantization Stepsizes Explicit calculation of the Quantization Stepsizes
@param tccp Tile-component coding parameters @param tccp Tile-component coding parameters
@param prec Precint analyzed @param prec Precint analyzed
*/ */

View File

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -40,14 +40,15 @@
#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;
} }
/** /**
Transforms integer i into an ascii string and stores the result in a; Transforms integer i into an ascii string and stores the result in a;
string is encoded in the base indicated by r. string is encoded in the base indicated by r.
@param i Number to be converted @param i Number to be converted
@param a String result @param a String result
@@ -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

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -40,27 +40,26 @@ The functions in EVENT.C have for goal to send output messages (errors, warnings
*/ */
/** /**
Message handler object Message handler object
used for used for
<ul> <ul>
<li>Error messages <li>Error messages
<li>Warning messages <li>Warning messages
<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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures)
{
opj_procedure * new_procedures;
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE; assert(p_manager != NULL);
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures, if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) {
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure)); opj_procedure * new_procedures;
if (! new_procedures)
{ p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
opj_free(p_validation_list->m_procedures); new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_nb_max_procedures = 0; p_validation_list->m_procedures,
p_validation_list->m_nb_procedures = 0; p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); if (! new_procedures) {
return OPJ_FALSE; opj_free(p_validation_list->m_procedures);
} p_validation_list->m_nb_max_procedures = 0;
else p_validation_list->m_nb_procedures = 0;
{ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
p_validation_list->m_procedures = new_procedures; return OPJ_FALSE;
} } 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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -32,7 +32,7 @@
#ifndef __FUNCTION_LIST_H #ifndef __FUNCTION_LIST_H
#define __FUNCTION_LIST_H #define __FUNCTION_LIST_H
/** /**
* @file function_list.h * @file function_list.h
* @brief Implementation of a list of procedures. * @brief Implementation of a list of procedures.
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0;
}
}
return image; image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
if (!image->comps) {
opj_image_destroy(image);
return 00;
}
/* create the individual image components */
for(compno = 0; compno < numcmpts; compno++) {
opj_image_comp_t *comp = &image->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->prec = cmptparms[compno].prec;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = 0;
}
}
return image;
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

View File

@@ -56,7 +56,7 @@
#define JPIP_PHLD 0x70686c64 /* Place holder */ #define JPIP_PHLD 0x70686c64 /* Place holder */
/* /*
* Write tile-part Index table box (superbox) * Write tile-part Index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -66,10 +66,10 @@
* @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 );
/* /*
* Write tile header index table box (superbox) * Write tile header index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -80,7 +80,7 @@ int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_s
int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ); int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager );
/* /*
* Write precinct packet index table box (superbox) * Write precinct packet index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -91,10 +91,10 @@ 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 );
/* /*
* Write packet header index table box (superbox) * Write packet header index table box (superbox)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -105,9 +105,9 @@ 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)
* *
* @param[in] second number to be visited * @param[in] second number to be visited
@@ -116,13 +116,13 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
* @param[in] cio file output handle * @param[in] cio file output handle
*/ */
void opj_write_manf(int second, void opj_write_manf(int second,
int v, int v,
opj_jp2_box_t *box, opj_jp2_box_t *box,
opj_stream_private_t *cio, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/* /*
* Write main header index table (box) * Write main header index table (box)
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -31,24 +31,24 @@
#include "opj_includes.h" #include "opj_includes.h"
/** /**
* LUP decomposition * LUP decomposition
*/ */
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix, static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,
OPJ_UINT32 * permutations, OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area, OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo); OPJ_UINT32 nb_compo);
/** /**
* LUP solving * LUP solving
*/ */
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_UINT32 nb_compo,
OPJ_FLOAT32 * p_intermediate_data); OPJ_FLOAT32 * p_intermediate_data);
/** /**
*LUP inversion (call with the result of lupDecompose) *LUP inversion (call with the result of lupDecompose)
*/ */
static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix, static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
@@ -68,32 +68,32 @@ static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
* Matrix inversion. * Matrix inversion.
*/ */
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, 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)) {
opj_free(l_data);
return OPJ_FALSE;
}
if(! opj_lupDecompose(pSrcMatrix,lPermutations,l_double_data,nb_compo)) {
opj_free(l_data);
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]; */
/* p = matrix[i][k] */
p = *lColumnMatrix / temp;
*(lColumnMatrix++) = p;
/* matrix[i][k] /= matrix[k][k]; */
/* p = matrix[i][k] */
p = *lColumnMatrix / temp;
*(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;
lGeneratedData = p_intermediate_data + nb_compo - 1;
lIntermediatePtr = p_intermediate_data;
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;
} }
} }
} }

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -49,16 +49,16 @@ The function in INVERT.H compute a matrix inversion with a LUP method
* The function does not take ownership of any memory block, data must be fred by the user. * The function does not take ownership of any memory block, data must be fred by the user.
* *
* @param pSrcMatrix the matrix to invert. * @param pSrcMatrix the matrix to invert.
* @param pDestMatrix data to store the inverted matrix. * @param pDestMatrix data to store the inverted matrix.
* @param n size of the matrix * @param n size of the matrix
* @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular. * @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular.
*/ */
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix, OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo); OPJ_UINT32 nb_compo);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/
/*@}*/ /*@}*/
#endif /* __INVERT_H */ #endif /* __INVERT_H */

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,12 +8,12 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan * Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* *
* All rights reserved. * All rights reserved.
@@ -99,8 +99,8 @@ The functions in J2K.C have for goal to read/write the several parts of the code
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
#define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */ #define J2K_MS_EPC 0xff68 /**< EPC marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */ #define J2K_MS_EPB 0xff66 /**< EPB marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */ #define J2K_MS_ESD 0xff67 /**< ESD marker value (Part 11: JPEG 2000 for Wireless) */
#define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */ #define J2K_MS_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
#endif /* USE_JPWL */ #endif /* USE_JPWL */
#ifdef USE_JPSEC #ifdef USE_JPSEC
@@ -116,91 +116,88 @@ 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;
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
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 */
OPJ_BYTE *ppm_data;
/** size of the ppm_data*/
OPJ_UINT32 ppm_len;
/** size of the ppm_data*/
OPJ_UINT32 ppm_data_read;
OPJ_BYTE *ppm_data_current; /** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppm_data;
/** size of the ppm_data*/
OPJ_UINT32 ppm_len;
/** size of the ppm_data*/
OPJ_UINT32 ppm_data_read;
/** packet header storage original buffer */ OPJ_BYTE *ppm_data_current;
OPJ_BYTE *ppm_buffer;
/** pointer remaining on the first byte of the first header if ppm is used */
OPJ_BYTE *ppm_data_first;
/** Number of bytes actually stored inside the ppm_data */
OPJ_UINT32 ppm_data_size;
/** use in case of multiple marker PPM (number of info already store) */
OPJ_INT32 ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */
OPJ_INT32 ppm_previous;
/** tile coding parameters */ /** packet header storage original buffer */
opj_tcp_t *tcps; OPJ_BYTE *ppm_buffer;
/** pointer remaining on the first byte of the first header if ppm is used */
OPJ_BYTE *ppm_data_first;
/** Number of bytes actually stored inside the ppm_data */
OPJ_UINT32 ppm_data_size;
/** use in case of multiple marker PPM (number of info already store) */
OPJ_INT32 ppm_store;
/** use in case of multiple marker PPM (case on non-finished previous info) */
OPJ_INT32 ppm_previous;
union /** tile coding parameters */
{ opj_tcp_t *tcps;
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc; union {
} opj_decoding_param_t m_dec;
m_specific_param; opj_encoding_param_t m_enc;
}
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;
@@ -601,7 +586,7 @@ opj_j2k_t;
/** /**
Setup the decoder decoding parameters using user parameters. Setup the decoder decoding parameters using user parameters.
Decoding parameters are returned in j2k->cp. Decoding parameters are returned in j2k->cp.
@param j2k J2K decompressor handle @param j2k J2K decompressor handle
@param parameters decompression parameters @param parameters decompression parameters
*/ */
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -70,56 +70,50 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
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;
/** /**
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;
/** /**
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;
@@ -128,11 +122,10 @@ typedef struct opj_jp2_pclr
OPJ_BYTE nr_channels; OPJ_BYTE nr_channels;
} opj_jp2_pclr_t; } opj_jp2_pclr_t;
/** /**
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;
@@ -141,59 +134,58 @@ typedef struct opj_jp2_color
OPJ_BYTE jp2_has_colr; OPJ_BYTE jp2_has_colr;
} opj_jp2_color_t; } opj_jp2_color_t;
/** /**
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;
} }
opj_jp2_t; opj_jp2_t;
@@ -207,28 +199,26 @@ 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;
/** @name Exported functions */ /** @name Exported functions */
@@ -254,12 +244,12 @@ 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.
* Coding parameters are returned in jp2->j2k->cp. * Coding parameters are returned in jp2->j2k->cp.
* *
* @param jp2 JP2 compressor handle * @param jp2 JP2 compressor handle
* @param parameters compression parameters * @param parameters compression parameters
@@ -267,10 +257,10 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @param p_manager FIXME DOC * @param p_manager FIXME DOC
* @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
@@ -279,9 +269,9 @@ Encode an image into a JPEG-2000 file stream
@param p_manager event manager @param p_manager event manager
@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);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@@ -314,7 +304,7 @@ OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
* Ends the decompression procedures and possibiliy add data to be read after the * Ends the decompression procedures and possibiliy add data to be read after the
* codestream. * codestream.
*/ */
OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_end_decompress(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,
@@ -438,11 +428,11 @@ 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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -72,7 +72,7 @@ void opj_mct_decode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Get norm of the basis function used for the reversible multi-component transform Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno); OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno);
@@ -95,7 +95,7 @@ void opj_mct_decode_real(OPJ_FLOAT32* c0, OPJ_FLOAT32* c1, OPJ_FLOAT32* c2, OPJ_
/** /**
Get norm of the basis function used for the irreversible multi-component transform Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno); OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno);
@@ -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,27 +124,27 @@ 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
@param p_nb_comps size of components @param p_nb_comps size of components
@param pMatrix components @param pMatrix components
@return @return
*/ */
void opj_calculate_norms( OPJ_FLOAT64 * pNorms, void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 p_nb_comps, OPJ_UINT32 p_nb_comps,
OPJ_FLOAT32 * pMatrix); OPJ_FLOAT32 * pMatrix);
/** /**
FIXME DOC FIXME DOC
*/ */
const OPJ_FLOAT64 * opj_mct_get_mct_norms (void); const OPJ_FLOAT64 * opj_mct_get_mct_norms (void);
/** /**
FIXME DOC FIXME DOC
*/ */
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real (void); const OPJ_FLOAT64 * opj_mct_get_mct_norms_real (void);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
@@ -73,13 +73,13 @@ static void opj_mqc_setbits(opj_mqc_t *mqc);
/** /**
FIXME DOC FIXME DOC
@param mqc MQC handle @param mqc MQC handle
@return @return
*/ */
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc); static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
/** /**
FIXME DOC FIXME DOC
@param mqc MQC handle @param mqc MQC handle
@return @return
*/ */
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc); static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc);
/** /**
@@ -100,441 +100,466 @@ 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]},
}; };
/* /*
========================================================== ==========================================================
local functions local functions
========================================================== ==========================================================
*/ */
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);
} }
/* /*
========================================================== ==========================================================
MQ-Coder interface MQ-Coder interface
========================================================== ==========================================================
*/ */
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) {
mqc->bp++; if (*mqc->bp != 0xff) {
} 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) {
while (mqc->ct > 0) { if (mqc->ct != 0) {
mqc->ct--; while (mqc->ct > 0) {
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct); mqc->ct--;
bit_padding = (bit_padding + 1) & 0x01; mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
} bit_padding = (bit_padding + 1) & 0x01;
mqc->bp++; }
*mqc->bp = (OPJ_BYTE)mqc->c; mqc->bp++;
mqc->ct = 8; *mqc->bp = (OPJ_BYTE)mqc->c;
mqc->c = 0; mqc->ct = 8;
} 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> */
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); /* <flush part> */
mqc->c <<= mqc->ct; OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
while (n > 0) { mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); while (n > 0) {
n -= (OPJ_INT32)mqc->ct; opj_mqc_byteout(mqc);
mqc->c <<= mqc->ct; n -= (OPJ_INT32)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) {
mqc->c <<= mqc->ct; while (k > 0) {
mqc->ct = 0; mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); mqc->ct = 0;
k -= (OPJ_INT32)mqc->ct; opj_mqc_byteout(mqc);
} k -= (OPJ_INT32)mqc->ct;
}
if (*mqc->bp != 0xff) {
opj_mqc_byteout(mqc); if (*mqc->bp != 0xff) {
} 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++) {
opj_mqc_encode(mqc, i % 2); for (i = 1; i < 5; i++) {
} 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);
@@ -542,73 +567,76 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
return OPJ_FALSE; return OPJ_FALSE;
} }
mqc->buffer = new_buffer; mqc->buffer = new_buffer;
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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
@@ -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;
@@ -86,7 +86,7 @@ typedef struct opj_mqc {
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Create a new MQC handle Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise @return Returns a new MQC handle if successful, returns NULL otherwise
*/ */
opj_mqc_t* opj_mqc_create(void); opj_mqc_t* opj_mqc_create(void);
@@ -102,7 +102,7 @@ Return the number of bytes written/read since initialisation
*/ */
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc); OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc);
/** /**
Reset the states of all the context of the coder/decoder Reset the states of all the context of the coder/decoder
(each context is set to a state where 0 and 1 are more or less equiprobable) (each context is set to a state where 0 and 1 are more or less equiprobable)
@param mqc MQC handle @param mqc MQC handle
*/ */
@@ -139,15 +139,15 @@ Flush the encoder, so that all remaining data is written
*/ */
void opj_mqc_flush(opj_mqc_t *mqc); void opj_mqc_flush(opj_mqc_t *mqc);
/** /**
BYPASS mode switch, initialization operation. BYPASS mode switch, initialization operation.
JPEG 2000 p 505. JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2> <h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle @param mqc MQC handle
*/ */
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc); void opj_mqc_bypass_init_enc(opj_mqc_t *mqc);
/** /**
BYPASS mode switch, coding operation. BYPASS mode switch, coding operation.
JPEG 2000 p 505. JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2> <h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle @param mqc MQC handle
@param d The symbol to be encoded (0 or 1) @param d The symbol to be encoded (0 or 1)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -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

@@ -1,11 +1,11 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -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;
} }
/** /**
@@ -96,93 +101,102 @@ Clamp an integer inside an interval
<ul> <ul>
<li>Returns a if (min < a < max) <li>Returns a if (min < a < max)
<li>Returns max if (a > max) <li>Returns max if (a > max)
<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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *

View File

@@ -36,7 +36,7 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
* Write faix box of phix * Write faix box of phix
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -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++){
if (i)
opj_stream_seek( cio, lenp, p_manager);
lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
opj_stream_write_data(cio,l_data_header,4,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( i=0; i<2; i++) {
box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager); if (i)
box[compno].type = JPIP_FAIX; opj_stream_seek( cio, lenp, p_manager);
lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager );
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].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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -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.
@@ -146,12 +146,12 @@ Modify the packet iterator for enabling tile part generation
@param tppos The position of the tile part flag in the progression order @param tppos The position of the tile part flag in the progression order
@param t2_mode FIXME DOC @param t2_mode FIXME DOC
*/ */
void opj_pi_create_encode( opj_pi_iterator_t *pi, void opj_pi_create_encode( opj_pi_iterator_t *pi,
opj_cp_t *cp, opj_cp_t *cp,
OPJ_UINT32 tileno, OPJ_UINT32 tileno,
OPJ_UINT32 pino, OPJ_UINT32 pino,
OPJ_UINT32 tpnum, OPJ_UINT32 tpnum,
OPJ_INT32 tppos, OPJ_INT32 tppos,
J2K_T2_MODE t2_mode); J2K_T2_MODE t2_mode);
/** /**
@@ -162,7 +162,7 @@ Create a packet iterator for Decoder
@return Returns a packet iterator that points to the first packet of the tile @return Returns a packet iterator that points to the first packet of the tile
@see opj_pi_destroy @see opj_pi_destroy
*/ */
opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image, opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image,
opj_cp_t * cp, opj_cp_t * cp,
OPJ_UINT32 tileno); OPJ_UINT32 tileno);
/** /**

View File

@@ -35,7 +35,7 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
* Write faix box of ppix * Write faix box of ppix
* *
* @param[in] coff offset of j2k codestream * @param[in] coff offset of j2k codestream
@@ -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++){
if (i)
opj_stream_seek( cio, lenp, p_manager); for (i=0; i<2; i++) {
if (i)
lenp = (OPJ_UINT32)(opj_stream_tell(cio));
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager); opj_stream_seek( cio, lenp, p_manager);
for (compno=0; compno<cstr_info.numcomps; compno++){ lenp = (OPJ_UINT32)(opj_stream_tell(cio));
box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager); opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
box[compno].type = JPIP_FAIX; opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager);
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].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);
} }
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);
}
opj_free(box);
return (int)len; 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 */
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); 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_write_bytes(l_data_header,version,1);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
return (int)len; 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);
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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -35,61 +35,66 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
========================================================== ==========================================================
local functions local functions
========================================================== ==========================================================
*/ */
/* /*
========================================================== ==========================================================
RAW encoding interface RAW encoding interface
========================================================== ==========================================================
*/ */
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

@@ -1,12 +1,12 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -50,27 +50,27 @@ 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 */
/*@{*/ /*@{*/
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/** /**
Create a new RAW handle Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise @return Returns a new RAW handle if successful, returns NULL otherwise
*/ */
opj_raw_t* opj_raw_create(void); opj_raw_t* opj_raw_create(void);

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved. * All rights reserved.
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com> * Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -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 */
@@ -229,7 +226,7 @@ typedef struct opj_tcd
/** /**
Dump the content of a tcd structure Dump the content of a tcd structure
*/ */
/*void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);*/ /* TODO MSD shoul use the new v2 structures */ /*void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img);*/ /* TODO MSD shoul use the new v2 structures */
/** /**
Create a new TCD handle Create a new TCD handle
@@ -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

@@ -1,6 +1,6 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
@@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
@@ -39,87 +39,88 @@
#include "opj_includes.h" #include "opj_includes.h"
/* /*
========================================================== ==========================================================
Tag-tree coder interface Tag-tree coder interface
========================================================== ==========================================================
*/ */
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;
return (node->value < threshold) ? 1 : 0; if (stkptr == stk) {
break;
}
node = *--stkptr;
}
return (node->value < threshold) ? 1 : 0;
} }

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