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 */
#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)
{
return 0;
return 0;
}

View File

@ -1,11 +1,11 @@
#include <stdio.h>
int main()
{
__int64 off=0;
__int64 off=0;
_fseeki64(NULL, off, SEEK_SET);
return 0;
_fseeki64(NULL, off, SEEK_SET);
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* 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"
int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */
opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */
#define BADCH (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 */
void opj_reset_options_reading(void) {
opj_opterr = 1;
opj_optind = 1;
void opj_reset_options_reading(void)
{
opj_opterr = 1;
opj_optind = 1;
}
/*
* getopt --
* 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]
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */
if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0;
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG;
return (-1);
if (opj_optreset || !*place) { /* update scanning pointer */
opj_optreset = 0;
if (opj_optind >= nargc || *(place = nargv[opj_optind]) != '-') {
place = EMSG;
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 "--" */
++opj_optind;
place = EMSG;
return (-1);
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;
}
} /* 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 (*++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 */
return (opj_optopt); /* dump back option letter */
}
int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen) {
static int lastidx,lastofs;
const char *tmp;
int i,len;
char param = 1;
const opj_option_t *longopts, int totlen)
{
static int lastidx,lastofs;
const char *tmp;
int i,len;
char param = 1;
again:
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
return -1;
if (opj_optind >= argc || !argv[opj_optind] || *argv[opj_optind]!='-')
return -1;
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)){ /* no more input parameters */
param = 0;
}
else{ /* more input parameters */
if(argv[opj_optind + 1][0] == '-'){
param = 0; /* Missing parameter after '-' */
}
else{
param = 2;
}
}
}
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)) { /* no more input parameters */
param = 0;
} else { /* more input parameters */
if(argv[opj_optind + 1][0] == '-') {
param = 0; /* Missing parameter after '-' */
} else {
param = 2;
}
}
}
if (param == 0) {
++opj_optind;
return (BADCH);
}
if (param == 0) {
++opj_optind;
return (BADCH);
}
if (argv[opj_optind][0]=='-') { /* long option */
char* arg=argv[opj_optind]+1;
const opj_option_t* o;
o=longopts;
len=sizeof(longopts[0]);
if (argv[opj_optind][0]=='-') { /* long option */
char* arg=argv[opj_optind]+1;
const opj_option_t* o;
o=longopts;
len=sizeof(longopts[0]);
if (param > 1){
arg = argv[opj_optind+1];
opj_optind++;
}
else
arg = argv[opj_optind]+1;
if (param > 1) {
arg = argv[opj_optind+1];
opj_optind++;
} else
arg = argv[opj_optind]+1;
if(strlen(arg)>1){
for (i=0;i<totlen;i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 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]);
++opj_optind;
}
}else{
opj_optarg=argv[opj_optind+1];
if(opj_optarg){
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg && o->has_arg==1) { /* no argument there */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH);
}
}
++opj_optind;
}
++opj_optind;
if (o->flag)
*(o->flag)=o->val;
else
return o->val;
return 0;
}
}/*(end for)String not found in the list*/
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
}else{ /*Single character input parameter*/
if (*optstring==':') return ':';
if (lastidx!=opj_optind) {
lastidx=opj_optind; lastofs=0;
}
opj_optopt=argv[opj_optind][lastofs+1];
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
++opj_optind;
goto again;
}
if (tmp[1]==':') { /* argument expected */
if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
goto found;
}
opj_optarg=argv[opj_optind+1];
if(opj_optarg){
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg) { /* missing argument */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
++opj_optind;
}else {/*Argument not expected*/
++lastofs;
return opj_optopt;
}
if(strlen(arg)>1) {
for (i=0; i<totlen; i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 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]);
++opj_optind;
}
} else {
opj_optarg=argv[opj_optind+1];
if(opj_optarg) {
if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg && o->has_arg==1) { /* no argument there */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument \n",arg);
return (BADCH);
}
}
++opj_optind;
}
++opj_optind;
if (o->flag)
*(o->flag)=o->val;
else
return o->val;
return 0;
}
}/*(end for)String not found in the list*/
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
} else { /*Single character input parameter*/
if (*optstring==':') return ':';
if (lastidx!=opj_optind) {
lastidx=opj_optind;
lastofs=0;
}
opj_optopt=argv[opj_optind][lastofs+1];
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/
if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */
++opj_optind;
goto again;
}
if (tmp[1]==':') { /* argument expected */
if (tmp[2]==':' || argv[opj_optind][lastofs+2]) { /* "-foo", return "oo" as opj_optarg */
if (!*(opj_optarg=argv[opj_optind]+lastofs+2)) opj_optarg=0;
goto found;
}
opj_optarg=argv[opj_optind+1];
if(opj_optarg) {
if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
}
if (!opj_optarg) { /* missing argument */
if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH);
}
}
++opj_optind;
} else {/*Argument not expected*/
++lastofs;
return opj_optopt;
}
found:
++opj_optind;
return opj_optopt;
} else { /* not found */
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
}/*end of not found*/
}/* end of single character*/
}/*end '-'*/
fprintf(stderr,"Invalid option\n");
++opj_optind;
return (BADCH);;
++opj_optind;
return opj_optopt;
} else { /* not found */
fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind;
return (BADCH);
}/*end of not found*/
}/* end of single character*/
}/*end '-'*/
fprintf(stderr,"Invalid option\n");
++opj_optind;
return (BADCH);;
}/*end function*/

View File

@ -3,13 +3,12 @@
#ifndef _GETOPT_H_
#define _GETOPT_H_
typedef struct opj_option
{
const char *name;
int has_arg;
int *flag;
int val;
}opj_option_t;
typedef struct opj_option {
const char *name;
int has_arg;
int *flag;
int val;
} opj_option_t;
#define NO_ARG 0
#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_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);
#endif /* _GETOPT_H_ */

View File

@ -39,34 +39,34 @@
/* keep in mind there still is a buffer read overflow possible */
static size_t opj_strnlen_s(const char *src, size_t max_len)
{
size_t len;
if (src == NULL) {
return 0U;
}
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len;
size_t len;
if (src == NULL) {
return 0U;
}
for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
return len;
}
/* should be equivalent to C11 function except for the handler */
/* 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)
{
size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL;
}
if (src == NULL) {
dst[0] = '\0';
return EINVAL;
}
src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) {
return ERANGE;
}
memcpy(dst, src, src_len);
dst[src_len] = '\0';
return 0;
size_t src_len = 0U;
if ((dst == NULL) || (dst_size == 0U)) {
return EINVAL;
}
if (src == NULL) {
dst[0] = '\0';
return EINVAL;
}
src_len = opj_strnlen_s(src, dst_size);
if (src_len >= dst_size) {
return ERANGE;
}
memcpy(dst, src, src_len);
dst[src_len] = '\0';
return 0;
}
#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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -50,19 +50,19 @@ typedef struct raw_comp_cparameters {
/**@name RAW image encoding parameters */
/*@{*/
typedef struct raw_cparameters {
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** number of components of the raw image */
int rawComp;
int rawComp;
/** bit depth of the raw image */
int rawBitDepth;
/** signed/unsigned raw image */
OPJ_BOOL rawSigned;
/** raw components parameters */
raw_comp_cparameters_t *rawComps;
/*@}*/
/*@}*/
} raw_cparameters_t;
/* 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)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1;
}
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_INT32 val0 = *pSrc++;
OPJ_INT32 val1 = *pSrc++;
pDst[i] = val0 << 8 | val1;
}
}
opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
{
png_structp png = NULL;
png_infop info = NULL;
double gamma;
int bit_depth, interlace_type,compression_type, filter_type;
OPJ_UINT32 i;
png_uint_32 width, height = 0U;
int color_type;
FILE *reader = NULL;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
/* j2k: */
opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp;
OPJ_BYTE sigbuf[8];
convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
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;
}
png_structp png = NULL;
png_infop info = NULL;
double gamma;
int bit_depth, interlace_type,compression_type, filter_type;
OPJ_UINT32 i;
png_uint_32 width, height = 0U;
int color_type;
FILE *reader = NULL;
OPJ_BYTE** rows = NULL;
OPJ_INT32* row32s = NULL;
/* j2k: */
opj_image_t *image = NULL;
opj_image_cmptparm_t cmptparm[4];
OPJ_UINT32 nr_comp;
OPJ_BYTE sigbuf[8];
convert_XXx32s_C1R cvtXXTo32s = NULL;
convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4];
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;
}
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;
}
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:
if(rows)
{
for(i = 0; i < height; ++i)
free(rows[i]);
free(rows);
}
if (row32s) {
free(row32s);
}
if(png)
png_destroy_read_struct(&png, &info, NULL);
fclose(reader);
return image;
if(rows) {
for(i = 0; i < height; ++i)
free(rows[i]);
free(rows);
}
if (row32s) {
free(row32s);
}
if(png)
png_destroy_read_struct(&png, &info, NULL);
fclose(reader);
return image;
}/* pngtoimage() */
static void convert_32s16u_C1R(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length)
{
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val;
}
OPJ_SIZE_T i;
for (i = 0; i < length; i++) {
OPJ_UINT32 val = (OPJ_UINT32)pSrc[i];
*pDst++ = (OPJ_BYTE)(val >> 8);
*pDst++ = (OPJ_BYTE)val;
}
}
int imagetopng(opj_image_t * image, const char *write_idf)
{
FILE * volatile writer = NULL;
png_structp png = NULL;
png_infop info = NULL;
png_bytep volatile row_buf = NULL;
int nr_comp, color_type;
volatile int prec;
png_color_8 sig_bit;
OPJ_INT32 const* planes[4];
int i;
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;
FILE * volatile writer = NULL;
png_structp png = NULL;
png_infop info = NULL;
png_bytep volatile row_buf = NULL;
int nr_comp, color_type;
volatile int prec;
png_color_8 sig_bit;
OPJ_INT32 const* planes[4];
int i;
OPJ_INT32* volatile buffer32s = NULL;
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;
}
}
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) {
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:
if(png) {
png_destroy_write_struct(&png, &info);
}
if(row_buf) {
free(row_buf);
}
if(buffer32s) {
free(buffer32s);
}
fclose(writer);
if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
if(png) {
png_destroy_write_struct(&png, &info);
}
if(row_buf) {
free(row_buf);
}
if(buffer32s) {
free(buffer32s);
}
fclose(writer);
if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
}/* 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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -42,356 +42,357 @@
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
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;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
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;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
#endif /* USE_JPWL */
/* <<UniPG */
/* <<UniPG */
if (!cstr_info)
return 1;
if (!cstr_info)
return 1;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->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 */
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->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");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<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 (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
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;
fprintf(stream, "\n");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
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");
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\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 (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
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");
}
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
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 (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 */
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\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++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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 %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 */
if (cstr_info->prog == OPJ_LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
else if (cstr_info->prog == OPJ_RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* 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 (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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 %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_PCRL) { /* PCRL */
/* 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;
else if (cstr_info->prog == OPJ_RPCL) { /* RPCL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* 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++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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, 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 if (cstr_info->prog == OPJ_PCRL) { /* PCRL */
/* 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;
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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;
for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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, 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++) {
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;
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
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(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -40,7 +40,7 @@ extern "C" {
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* 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
* All rights reserved.
*
@ -59,26 +59,26 @@
#include "format_defs.h"
#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
char *filename_buf;
/** Pointer to the buffer*/
char **filename;
}dircnt_t;
typedef struct dircnt {
/** Buffer for holding images read from Directory*/
char *filename_buf;
/** Pointer to the buffer*/
char **filename;
} dircnt_t;
typedef struct img_folder{
/** The directory path of the folder containing input images*/
char *imgdirpath;
/** Output format*/
const char *out_format;
/** Enable option*/
char set_imgdir;
/** Enable Cod Format for output*/
char set_out_format;
typedef struct img_folder {
/** The directory path of the folder containing input images*/
char *imgdirpath;
/** Output format*/
const char *out_format;
/** Enable option*/
char set_imgdir;
/** Enable Cod Format for output*/
char set_out_format;
int flag;
}img_fol_t;
int flag;
} img_fol_t;
/* -------------------------------------------------------------------------- */
/* 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 void decode_help_display(void) {
static void decode_help_display(void)
{
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 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," -ImgDir <directory>\n");
fprintf(stdout," Image file Directory path \n");
fprintf(stdout," -i <compressed file>\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," is identified based on its suffix.\n");
fprintf(stdout," -o <output file>\n");
fprintf(stdout," OPTIONAL\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," Image file Directory path \n");
fprintf(stdout," -i <compressed file>\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," is identified based on its suffix.\n");
fprintf(stdout," -o <output file>\n");
fprintf(stdout," OPTIONAL\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," -v "); /* FIXME WIP_MSD */
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," OPTIONAL\n");
fprintf(stdout," Enable informative messages\n");
fprintf(stdout," By default verbose mode is off.\n");
fprintf(stdout,"\n");
fprintf(stdout,"\n");
}
/* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
static int get_num_images(char *imgdirpath)
{
DIR *dir;
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);
if(!dir){
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0;
}
while((content=readdir(dir))!=NULL){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
num_images++;
}
closedir(dir);
return num_images;
dir= opendir(imgdirpath);
if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0;
}
while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
num_images++;
}
closedir(dir);
return num_images;
}
/* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir;
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);
if(!dir){
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1;
}else {
fprintf(stderr,"Folder opened successfully\n");
}
while((content=readdir(dir))!=NULL){
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
dir= opendir(imgdirpath);
if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1;
} else {
fprintf(stderr,"Folder opened successfully\n");
}
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue;
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
/* -------------------------------------------------------------------------- */
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" };
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 };
const char *ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
ext++;
if(ext) {
for(i = 0; i < sizeof(format)/sizeof(*format); i++) {
if(_strnicmp(ext, extension[i], 3) == 0) {
return format[i];
}
}
}
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" };
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 };
const char *ext = strrchr(filename, '.');
if (ext == NULL)
return -1;
ext++;
if(ext) {
for(i = 0; i < sizeof(format)/sizeof(*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){
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]="";
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]="";
strcpy(image_filename,dirptr->filename[imageno]);
fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1;
}
strcpy(image_filename,dirptr->filename[imageno]);
fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename);
parameters->decod_format = get_file_format(image_filename);
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
return 1;
}
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){
strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p);
}
if(img_fol->set_out_format==1){
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) {
return 1;
}
}
return 0;
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p);
}
if(img_fol->set_out_format==1) {
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) {
return 1;
}
}
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)
{
FILE *reader;
const char *s, *magic_s;
int ext_format, magic_format;
unsigned char buf[12];
size_t l_nb_read;
FILE *reader;
const char *s, *magic_s;
int ext_format, magic_format;
unsigned char buf[12];
size_t l_nb_read;
reader = fopen(fname, "rb");
reader = fopen(fname, "rb");
if (reader == NULL)
return -1;
if (reader == NULL)
return -1;
memset(buf, 0, 12);
l_nb_read = fread(buf, 1, 12, reader);
fclose(reader);
if (l_nb_read != 12)
return -1;
memset(buf, 0, 12);
l_nb_read = fread(buf, 1, 12, reader);
fclose(reader);
if (l_nb_read != 12)
return -1;
ext_format = get_file_format(fname);
ext_format = get_file_format(fname);
if (ext_format == JPT_CFMT)
return JPT_CFMT;
if (ext_format == JPT_CFMT)
return JPT_CFMT;
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT;
magic_s = ".jp2";
}
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
magic_format = J2K_CFMT;
magic_s = ".j2k or .jpc or .j2c";
}
else
return -1;
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT;
magic_s = ".jp2";
} else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
magic_format = J2K_CFMT;
magic_s = ".j2k or .jpc or .j2c";
} else
return -1;
if (magic_format == ext_format)
return ext_format;
if (magic_format == ext_format)
return ext_format;
s = fname + strlen(fname) - 4;
s = fname + strlen(fname) - 4;
fputs("\n===========================================\n", stderr);
fprintf(stderr, "The extension of this file is incorrect.\n"
"FOUND %s. SHOULD BE %s\n", s, magic_s);
fputs("===========================================\n", stderr);
fputs("\n===========================================\n", stderr);
fprintf(stderr, "The extension of this file is incorrect.\n"
"FOUND %s. SHOULD BE %s\n", s, magic_s);
fputs("===========================================\n", stderr);
return magic_format;
return magic_format;
}
/* -------------------------------------------------------------------------- */
/**
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
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[]={
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[]= {
{"ImgDir",REQ_ARG, NULL ,'y'}
};
};
const char optlist[] = "i:o:f:hv";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': /* input file */
{
char *infile = opj_optarg;
parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
break;
case JP2_CFMT:
break;
case JPT_CFMT:
break;
default:
fprintf(stderr,
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
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);
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
if (c == -1)
break;
switch (c) {
case 'i': { /* input file */
char *infile = opj_optarg;
parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) {
case J2K_CFMT:
break;
case JP2_CFMT:
break;
case JPT_CFMT:
break;
default:
fprintf(stderr,
"[ERROR] Unknown input file format: %s \n"
" Known file formats are *.j2k, *.jp2, *.jpc or *.jpt\n",
infile);
return 1;
}
if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n");
return 1;
}
}
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 */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'f': /* flag */
img_fol->flag = atoi(opj_optarg);
break;
/* ----------------------------------------------------- */
/* ----------------------------------------------------- */
case 'h': /* display an help description */
decode_help_display();
return 1;
case 'v': /* Verbose mode */
{
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */
/* ------------------------------------------------------ */
case 'y': { /* Image Directory path */
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
break;
/* ----------------------------------------------------- */
case 'v': { /* Verbose mode */
parameters->m_verbose = 1;
}
break;
/* ----------------------------------------------------- */
default:
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break;
}
}while(c != -1);
} while(c != -1);
/* check for possible errors */
if(img_fol->set_imgdir==1){
if(!(parameters->infile[0]==0)){
/* check for possible errors */
if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1;
}
if(img_fol->set_out_format == 0){
return 1;
}
if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1;
}
if(!(parameters->outfile[0] == 0)){
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1;
}
if(!(parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n");
return 1;
}
}else{
if(parameters->infile[0] == 0) {
return 1;
}
} else {
if(parameters->infile[0] == 0) {
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]);
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
*/
static void error_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
static void error_callback(const char *msg, void *client_data)
{
(void)client_data;
fprintf(stdout, "[ERROR] %s", msg);
}
/**
sample warning debug callback expecting no client object
*/
static void warning_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
static void warning_callback(const char *msg, void *client_data)
{
(void)client_data;
fprintf(stdout, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
static void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
static void info_callback(const char *msg, void *client_data)
{
(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[])
{
FILE *fout = NULL;
FILE *fout = NULL;
opj_dparameters_t parameters; /* Decompression parameters */
opj_image_t* image = NULL; /* Image structure */
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
opj_stream_t *l_stream = NULL; /* Stream */
opj_codestream_info_v2_t* cstr_info = NULL;
opj_codestream_index_t* cstr_index = NULL;
opj_dparameters_t parameters; /* Decompression parameters */
opj_image_t* image = NULL; /* Image structure */
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
opj_stream_t *l_stream = NULL; /* Stream */
opj_codestream_info_v2_t* cstr_info = NULL;
opj_codestream_index_t* cstr_index = NULL;
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
#ifdef MSD
OPJ_BOOL l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
OPJ_BOOL l_go_on = OPJ_TRUE;
OPJ_UINT32 l_max_data_size = 1000;
OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000);
#endif
/* Set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* Set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
/* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
return EXIT_FAILURE;
}
/* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
return EXIT_FAILURE;
}
/* Initialize reading of directory */
if(img_fol.set_imgdir==1){
int it_image;
num_images=get_num_images(img_fol.imgdirpath);
/* Initialize reading of directory */
if(img_fol.set_imgdir==1) {
int it_image;
num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc((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=(dircnt_t*)malloc(sizeof(dircnt_t));
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 = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){
return EXIT_FAILURE;
}
if(!dirptr->filename_buf) {
return EXIT_FAILURE;
}
for(it_image=0;it_image<num_images;it_image++){
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1){
return EXIT_FAILURE;
}
for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
}
}
if(load_images(dirptr,img_fol.imgdirpath)==1) {
return EXIT_FAILURE;
}
if (num_images==0){
fprintf(stdout,"Folder is empty\n");
return EXIT_FAILURE;
}
}else{
num_images=1;
}
if (num_images==0) {
fprintf(stdout,"Folder is empty\n");
return EXIT_FAILURE;
}
} else {
num_images=1;
}
/* Try to open for writing the output file if necessary */
if (parameters.outfile[0] != 0){
fout = fopen(parameters.outfile,"w");
if (!fout){
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
return EXIT_FAILURE;
}
}
else
fout = stdout;
/* Try to open for writing the output file if necessary */
if (parameters.outfile[0] != 0) {
fout = fopen(parameters.outfile,"w");
if (!fout) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
return EXIT_FAILURE;
}
} else
fout = stdout;
/* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++){
/* Read the header of each image one by one */
for(imageno = 0; imageno < num_images ; imageno++) {
fprintf(stderr,"\n");
fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n");
continue;
}
}
if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n");
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);
if (!l_stream){
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
return EXIT_FAILURE;
}
l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
return EXIT_FAILURE;
}
/* Read the JPEG2000 stream */
/* ------------------------ */
/* Read the JPEG2000 stream */
/* ------------------------ */
switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
break;
}
case JP2_CFMT: /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
break;
}
case JPT_CFMT: /* JPEG 2000, JPIP */
{
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break;
}
default:
fprintf(stderr, "skipping file..\n");
opj_stream_destroy(l_stream);
continue;
}
switch(parameters.decod_format) {
case J2K_CFMT: { /* JPEG-2000 codestream */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K);
break;
}
case JP2_CFMT: { /* JPEG 2000 compressed image data */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JP2);
break;
}
case JPT_CFMT: { /* JPEG 2000, JPIP */
/* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break;
}
default:
fprintf(stderr, "skipping file..\n");
opj_stream_destroy(l_stream);
continue;
}
/* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00);
opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00);
/* catch events using our callbacks and give a local context */
opj_set_info_handler(l_codec, info_callback,00);
opj_set_warning_handler(l_codec, warning_callback,00);
opj_set_error_handler(l_codec, error_callback,00);
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ){
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
fclose(fout);
return EXIT_FAILURE;
}
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ) {
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
fclose(fout);
return EXIT_FAILURE;
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)){
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fclose(fout);
return EXIT_FAILURE;
}
/* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
fclose(fout);
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 */
opj_stream_destroy(l_stream);
/* close the byte stream */
opj_stream_destroy(l_stream);
/* free remaining structures */
if (l_codec) {
opj_destroy_codec(l_codec);
}
/* free remaining structures */
if (l_codec) {
opj_destroy_codec(l_codec);
}
/* destroy the image header */
opj_image_destroy(image);
/* destroy the image header */
opj_image_destroy(image);
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
/* destroy the codestream info */
opj_destroy_cstr_info(&cstr_info);
/* destroy the codestream info */
opj_destroy_cstr_info(&cstr_info);
}
}
/* Close the output file */
fclose(fout);
/* Close the output file */
fclose(fout);
return EXIT_SUCCESS;
return EXIT_SUCCESS;
}

View File

@ -1,9 +1,9 @@
/*
* uce-dirent.h - operating system independent dirent implementation
*
*
* Copyright (C) 1998-2002 Toni Ronkko
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
@ -11,10 +11,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -22,8 +22,8 @@
* 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
* OTHER DEALINGS IN THE SOFTWARE.
*
*
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $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
* Initial revision
*
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* 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(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#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)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif
/*** MS-DOS specifics ***/
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
@ -239,16 +239,16 @@
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
@ -261,21 +261,21 @@
struct _find_t data;
# endif
# endif
} dirent;
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
} DIR;
# ifdef __cplusplus
extern "C" {
@ -325,7 +325,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory
* 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
* in case of error as follows:
*
@ -344,46 +344,45 @@ static void _setdirname (struct DIR *dirp);
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# 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
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
}
}
return dirp;
return dirp;
}
@ -436,55 +435,55 @@ static DIR *opendir(const char *dirname)
static struct dirent *
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
@ -509,37 +508,37 @@ readdir (DIR *dirp)
*/
static int
closedir (DIR *dirp)
{
int retcode = 0;
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
}
}
#endif
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free (dirp);
return retcode;
free (dirp);
return retcode;
}
@ -566,31 +565,31 @@ closedir (DIR *dirp)
*/
static void
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
}
#endif
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
@ -600,37 +599,36 @@ rewinddir (DIR *dirp)
*/
static int
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
@ -641,14 +639,14 @@ static const char *
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
return dp->data.ff_name;
#else
return dp->data.name;
#endif
return dp->data.name;
#endif
}
@ -656,16 +654,17 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
_setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# 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) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __JP3D_CONVERT_H
#define __JP3D_CONVERT_H
/**
Load a single volume component encoded in PGX file format
@param filename Name of the PGX file to load
@param parameters *List ?*
@return Returns a greyscale volume if successful, returns NULL otherwise
*/
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __JP3D_CONVERT_H
#define __JP3D_CONVERT_H
/**
Load a single volume component encoded in PGX file format
@param filename Name of the PGX file to load
@param parameters *List ?*
@return Returns a greyscale volume if successful, returns NULL otherwise
*/
opj_volume_t* pgxtovolume(char *filename, opj_cparameters_t *parameters);
int volumetopgx(opj_volume_t *volume, char *outfile);
opj_volume_t* bintovolume(char *filename,char *fileimg, opj_cparameters_t *parameters);
int volumetobin(opj_volume_t *volume, char *outfile);
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters);
#endif /* __J2K_CONVERT_H */

View File

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

View File

@ -1,14 +1,14 @@
/* last review : october 29th, 2002 */
#ifndef _GETOPT_H_
#define _GETOPT_H_
extern int opterr;
extern int optind;
extern int optopt;
extern int optreset;
extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr);
#endif /* _GETOPT_H_ */
/* last review : october 29th, 2002 */
#ifndef _GETOPT_H_
#define _GETOPT_H_
extern int opterr;
extern int optind;
extern int optopt;
extern int optreset;
extern char *optarg;
extern int getopt(int nargc, char *const *nargv, const char *ostr);
#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
*
*
* Copyright (C) 1998-2002 Toni Ronkko
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
@ -10,10 +10,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -21,8 +21,8 @@
* 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
* OTHER DEALINGS IN THE SOFTWARE.
*
*
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $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
* Initial revision
*
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* 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(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
@ -171,7 +171,7 @@
#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)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
@ -180,7 +180,7 @@
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -188,11 +188,11 @@
# endif
/*** MS-DOS specifics ***/
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -202,7 +202,7 @@
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -210,13 +210,13 @@
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
@ -229,7 +229,7 @@
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
@ -238,16 +238,16 @@
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
@ -260,21 +260,21 @@
struct _find_t data;
# endif
# endif
} dirent;
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
} DIR;
# ifdef __cplusplus
extern "C" {
@ -324,7 +324,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory
* 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
* in case of error as follows:
*
@ -343,46 +343,45 @@ static void _setdirname (struct DIR *dirp);
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# 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
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
}
}
return dirp;
return dirp;
}
@ -435,55 +434,55 @@ static DIR *opendir(const char *dirname)
static struct dirent *
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
@ -508,37 +507,37 @@ readdir (DIR *dirp)
*/
static int
closedir (DIR *dirp)
{
int retcode = 0;
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
}
}
#endif
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free (dirp);
return retcode;
free (dirp);
return retcode;
}
@ -565,31 +564,31 @@ closedir (DIR *dirp)
*/
static void
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
}
#endif
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
@ -599,37 +598,36 @@ rewinddir (DIR *dirp)
*/
static int
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
@ -640,14 +638,14 @@ static const char *
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
return dp->data.ff_name;
#else
return dp->data.name;
#endif
return dp->data.name;
#endif
}
@ -655,16 +653,17 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
_setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# endif

View File

@ -42,7 +42,7 @@
* quit\n
* Be sure all image viewers are closed.\n
* Cache file in JPT format is stored in the working directly before it quites.
*
*
*/
#include <stdio.h>
@ -54,40 +54,41 @@
WSADATA initialisation_win32;
#endif
int main(int argc, char *argv[]){
dec_server_record_t *server_record;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
int main(int argc, char *argv[])
{
if( argc > 1)
port = atoi( argv[1]);
dec_server_record_t *server_record;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
if( argc > 1)
port = atoi( argv[1]);
#ifdef _WIN32
erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
printf( "Initialisation Winsock\n");
erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
printf( "Initialisation Winsock\n");
#endif /*_WIN32*/
server_record = init_dec_server( port);
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))
break;
terminate_dec_server( &server_record);
server_record = init_dec_server( port);
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))
break;
terminate_dec_server( &server_record);
#ifdef _WIN32
if( WSACleanup() != 0){
printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{
printf("\nWSACleanup OK\n");
}
if( WSACleanup() != 0) {
printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
} else {
printf("\nWSACleanup OK\n");
}
#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 XML file with metadata contents\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
* The following is an example of XML file contents specifying Region Of Interests with target names.\n
* <xmlbox>\n
@ -74,111 +74,111 @@ char * read_xmlfile( const char filename[], long *fsize);
int main(int argc, char *argv[])
{
FILE *fp;
char *xmldata, type[]="xml ";
long fsize, boxsize;
FILE *fp;
char *xmldata, type[]="xml ";
long fsize, boxsize;
if( argc<3){
fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
return -1;
}
if( argc<3) {
fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
return -1;
}
fp = open_jp2file( argv[1]);
if( !fp)
return -1;
xmldata = read_xmlfile( argv[2], &fsize);
if( fsize < 0 ) return -1;
boxsize = fsize + 8;
fp = open_jp2file( argv[1]);
if( !fp)
return -1;
fputc( (boxsize>>24)&0xff, fp);
fputc( (boxsize>>16)&0xff, fp);
fputc( (boxsize>>8)&0xff, fp);
fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp);
free( xmldata);
fclose(fp);
return 0;
xmldata = read_xmlfile( argv[2], &fsize);
if( fsize < 0 ) return -1;
boxsize = fsize + 8;
fputc( (boxsize>>24)&0xff, fp);
fputc( (boxsize>>16)&0xff, fp);
fputc( (boxsize>>8)&0xff, fp);
fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp);
free( xmldata);
fclose(fp);
return 0;
}
FILE * open_jp2file( const char filename[])
{
FILE *fp;
char *data;
if( !(fp = fopen( filename, "a+b"))){
fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL;
}
/* Check resource is a JP family file. */
if( fseek( fp, 0, SEEK_SET)==-1){
fclose(fp);
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL;
}
data = (char *)malloc( 12); /* size of header */
if( fread( data, 12, 1, fp) != 1){
FILE *fp;
char *data;
if( !(fp = fopen( filename, "a+b"))) {
fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL;
}
/* Check resource is a JP family file. */
if( fseek( fp, 0, SEEK_SET)==-1) {
fclose(fp);
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL;
}
data = (char *)malloc( 12); /* size of header */
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);
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);
return fp;
return fp;
}
char * read_xmlfile( const char filename[], long *fsize)
{
FILE *fp;
char *data;
/* fprintf( stderr, "open %s\n", filename);*/
if(!(fp = fopen( filename, "r"))){
fprintf( stderr, "XML file %s not found\n", filename);
return NULL;
}
FILE *fp;
char *data;
/* fprintf( stderr, "open %s\n", filename);*/
if(!(fp = fopen( filename, "r"))) {
fprintf( stderr, "XML file %s not found\n", filename);
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);
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;
}
fclose( fp);
return data;
return data;
}

View File

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

View File

@ -44,23 +44,23 @@
*/
static int jpip_to_jp2(char *argv[])
{
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;
jpip_dec_param_t *dec;
/* 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
@ -76,49 +76,46 @@ static int jpip_to_jp2(char *argv[])
*/
static int jpip_to_j2k(char *argv[])
{
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);
jpip_dec_param_t *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[])
{
char *ext;
if( argc < 3){
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n");
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);
}
char *ext;
if( argc < 3) {
fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n");
return 1;
}
fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]);
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]);
return 1;
}

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* 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
* All rights reserved.
*
@ -41,7 +41,7 @@
*
* Note: JP2 files are stored in the working directory of opj_server\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.
*/
@ -60,69 +60,69 @@ WSADATA initialisation_win32;
#endif /*_WIN32*/
int main(void)
{
server_record_t *server_record;
{
server_record_t *server_record;
#ifdef SERVER
char *query_string;
char *query_string;
#endif
#ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
fprintf( stderr, "Initialisation Winsock\n");
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
fprintf( stderr, "Initialisation Winsock\n");
#endif /*_WIN32*/
server_record = init_JPIPserver( 60000, 0);
server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER
while(FCGI_Accept() >= 0)
while(FCGI_Accept() >= 0)
#else
char query_string[128];
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
char query_string[128];
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif
{
QR_t *qr;
OPJ_BOOL parse_status;
QR_t *qr;
OPJ_BOOL parse_status;
#ifdef SERVER
query_string = getenv("QUERY_STRING");
#ifdef SERVER
query_string = getenv("QUERY_STRING");
#endif /*SERVER*/
if( strcmp( query_string, QUIT_SIGNAL) == 0)
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");
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
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
if( WSACleanup() != 0){
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{
fprintf( stderr, "\nWSACleanup OK\n");
}
if( WSACleanup() != 0) {
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
} else {
fprintf( stderr, "\nWSACleanup OK\n");
}
#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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -40,17 +40,17 @@
/**@name RAW image encoding parameters */
/*@{*/
typedef struct raw_cparameters {
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** components of the raw image */
int rawComp;
/** bit depth of the raw image */
int rawBitDepth;
/** signed/unsigned raw image */
opj_bool rawSigned;
/*@}*/
/** width of the raw image */
int rawWidth;
/** height of the raw image */
int rawHeight;
/** components of the raw image */
int rawComp;
/** bit depth of the raw image */
int rawBitDepth;
/** signed/unsigned raw image */
opj_bool rawSigned;
/*@}*/
} raw_cparameters_t;
/* TGA conversion */

View File

@ -1,12 +1,12 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -41,356 +41,357 @@
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@return Returns 0 if successful, returns 1 otherwise
*/
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;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
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;
double total_disto = 0;
/* UniPG>> */
int tilepartno;
char disto_on, numpix_on;
#ifdef USE_JPWL
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0;
#endif /* USE_JPWL */
/* <<UniPG */
/* <<UniPG */
if (!cstr_info)
return 1;
if (!cstr_info)
return 1;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;
stream = fopen(index, "w");
if (!stream) {
fprintf(stderr, "failed to open index file [%s] for writing\n", index);
return 1;
}
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
if (cstr_info->tile[0].distotile)
disto_on = 1;
else
disto_on = 0;
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->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 */
if (cstr_info->tile[0].numpix)
numpix_on = 1;
else
numpix_on = 0;
for (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
fprintf(stream, "%d %d\n", cstr_info->image_w, cstr_info->image_h);
fprintf(stream, "%d\n", cstr_info->prog);
fprintf(stream, "%d %d\n", cstr_info->tile_x, cstr_info->tile_y);
fprintf(stream, "%d %d\n", cstr_info->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");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<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 (resno = cstr_info->numdecompos[0]; resno >= 0; resno--) {
fprintf(stream, "[%d,%d] ",
(1 << cstr_info->tile[0].pdx[resno]), (1 << cstr_info->tile[0].pdx[resno])); /* based on tile 0 and component 0 */
}
for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
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;
fprintf(stream, "\n");
/* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size);
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
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");
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\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 (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
fprintf(stream, "%4d %9d %9d %9d %9d",
cstr_info->tile[tileno].tileno,
cstr_info->tile[tileno].start_pos,
cstr_info->tile[tileno].end_header,
cstr_info->tile[tileno].end_pos,
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");
}
if (cstr_info->prog == LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
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 (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 */
for (compno = 0; compno < cstr_info->numcomps; compno++) {
if (max_numdecompos < cstr_info->numdecompos[compno])
max_numdecompos = cstr_info->numdecompos[compno];
}
else if (cstr_info->prog == RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "\nTILE %d DETAILS\n", tileno);
fprintf(stream, "part_nb tileno start_pack num_packs start_pos end_tph_pos end_pos\n");
for (tilepartno = 0; tilepartno < cstr_info->tile[tileno].num_tps; tilepartno++)
fprintf(stream, "%4d %9d %9d %9d %9d %11d %9d\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++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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 %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 */
if (cstr_info->prog == LRCP) { /* LRCP */
fprintf(stream, "LRCP\npack_nb tileno layno resno compno precno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
else if (cstr_info->prog == RLCP) { /* RLCP */
fprintf(stream, "RLCP\npack_nb tileno resno layno compno precno start_pos end_ph_pos end_pos\n");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* 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 (resno = 0; resno < max_numdecompos + 1; resno++) {
for (layno = 0; layno < cstr_info->numlayers; layno++) {
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 %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 == PCRL) { /* PCRL */
/* 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;
else if (cstr_info->prog == RPCL) { /* RPCL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "RPCL\npack_nb tileno resno precno compno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
for (precno = 0; precno < numprec; precno++) {
/* 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++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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, 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 if (cstr_info->prog == PCRL) { /* PCRL */
/* 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;
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
fprintf(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
fprintf(stream, "PCRL\npack_nb tileno precno compno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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;
for (precno = 0; precno < max_numprec; precno++) {
for (compno = 0; compno < cstr_info->numcomps; compno++) {
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, 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++) {
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;
else { /* CPRL */
/* Count the maximum number of precincts */
int max_numprec = 0;
for (resno = 0; resno < max_numdecompos + 1; resno++) {
int numprec = cstr_info->tile[tileno].pw[resno] * cstr_info->tile[tileno].ph[resno];
if (numprec > max_numprec)
max_numprec = numprec;
}
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(stream, "CPRL\npack_nb tileno compno precno resno layno start_pos end_ph_pos end_pos");
if (disto_on)
fprintf(stream, " disto");
fprintf(stream,"\n");
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -40,7 +40,7 @@ extern "C" {
/**
Write a structured index to a file
@param cstr_info Codestream information
@param cstr_info Codestream information
@param index Index filename
@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
*
*
* Copyright (C) 1998-2002 Toni Ronkko
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* ``Software''), to deal in the Software without restriction, including
@ -11,10 +11,10 @@
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@ -22,8 +22,8 @@
* 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
* OTHER DEALINGS IN THE SOFTWARE.
*
*
*
*
* May 28 1998, Toni Ronkko <tronkko@messi.uku.fi>
*
* $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
* Initial revision
*
*
*
* MSVC 1.0 scans automatic dependencies incorrectly when your project
* contains this very header. The problem is that MSVC cannot handle
* 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(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */
/* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */
/* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H
# define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */
/* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#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)
# define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface"
# endif
/*** WIN32 specifics ***/
/*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif
/*** MS-DOS specifics ***/
/*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h>
/* Borland defines file length macros in dir.h */
/* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t
# endif
/* Turbo C defines ffblk structure in dir.h */
/* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__)
# include <dir.h>
# if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif
# define DIRENT_USE_FFBLK
/* MSVC */
/* MSVC */
# elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12)
# endif
/* Watcom */
/* Watcom */
# elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif
# endif
/*** generic MS-DOS and MS-Windows stuff ***/
/*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN
# endif
@ -239,16 +239,16 @@
# endif
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
/*
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
* 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
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
*/
typedef struct dirent {
char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/
@ -261,21 +261,21 @@
struct _find_t data;
# endif
# endif
} dirent;
} dirent;
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
/* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */
typedef struct DIR {
char *dirname; /* directory being scanned */
dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */
/*** Operating system specific part ***/
/*** Operating system specific part ***/
# if defined(DIRENT_WIN32_INTERFACE)
HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE)
# endif
} DIR;
} DIR;
# ifdef __cplusplus
extern "C" {
@ -325,7 +325,7 @@ static void _setdirname (struct DIR *dirp);
* internal working area that is used for retrieving individual directory
* 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
* in case of error as follows:
*
@ -344,46 +344,45 @@ static void _setdirname (struct DIR *dirp);
*/
static DIR *opendir(const char *dirname)
{
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':')
{
strcpy (p++, "\\");
}
DIR *dirp;
assert (dirname != NULL);
dirp = (DIR*)malloc (sizeof (struct DIR));
if (dirp != NULL) {
char *p;
/* allocate room for directory name */
dirp->dirname = (char*) malloc (strlen (dirname) + 1 + strlen ("\\*.*"));
if (dirp->dirname == NULL) {
/* failed to duplicate directory name. errno set by malloc() */
free (dirp);
return NULL;
}
/* Copy directory name while appending directory separator and "*.*".
* Directory separator is not appended if the name already ends with
* drive or directory separator. Directory separator is assumed to be
* '/' or '\' and drive separator is assumed to be ':'. */
strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
strcpy (p++, "\\");
}
# 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
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
strcpy (p, "*.*"); /*scan files with and without extension in DOS*/
# endif
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
/* open stream */
if (_initdir (dirp) == 0) {
/* initialization failed */
free (dirp->dirname);
free (dirp);
return NULL;
}
}
}
return dirp;
return dirp;
}
@ -436,55 +435,55 @@ static DIR *opendir(const char *dirname)
static struct dirent *
readdir (DIR *dirp)
{
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
assert(dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return NULL;
}
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* directory stream was opened/rewound incorrectly or it ended normally */
errno = EBADF;
return NULL;
}
#endif
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
if (dirp->dirent_filled != 0) {
/*
* Directory entry has already been retrieved and there is no need to
* retrieve a new one. Directory entry will be retrieved in advance
* when the user calls readdir function for the first time. This is so
* because real dirent has separate functions for opening and reading
* the stream whereas Win32 and DOS dirents open the stream
* automatically when we retrieve the first file. Therefore, 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.
*/
dirp->dirent_filled = 0;
} else {
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
/* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
return NULL;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
if (_dos_findnext (&dirp->current.data) != 0) {
/* _dos_findnext and findnext will set errno to ENOENT when no
* more entries could be retrieved. */
return NULL;
}
# endif
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
_setdirname (dirp);
assert (dirp->dirent_filled == 0);
}
return &dirp->current;
}
@ -509,37 +508,37 @@ readdir (DIR *dirp)
*/
static int
closedir (DIR *dirp)
{
int retcode = 0;
{
int retcode = 0;
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
/* make sure that dirp points to legal structure */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return -1;
}
/* free directory name and search handles */
if (dirp->dirname != NULL) free (dirp->dirname);
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
retcode = -1;
errno = EBADF;
}
}
}
#endif
#endif
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
/* clear dirp structure to make sure that it cannot be used anymore*/
memset (dirp, 0, sizeof (*dirp));
# if defined(DIRENT_WIN32_INTERFACE)
dirp->search_handle = INVALID_HANDLE_VALUE;
dirp->search_handle = INVALID_HANDLE_VALUE;
# endif
free (dirp);
return retcode;
free (dirp);
return retcode;
}
@ -566,31 +565,31 @@ closedir (DIR *dirp)
*/
static void
rewinddir (DIR *dirp)
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
{
/* make sure that dirp is legal */
assert (dirp != NULL);
if (dirp == NULL) {
errno = EBADF;
return;
}
assert (dirp->dirname != NULL);
/* close previous stream */
#if defined(DIRENT_WIN32_INTERFACE)
if (dirp->search_handle != INVALID_HANDLE_VALUE) {
if (FindClose (dirp->search_handle) == FALSE) {
/* Unknown error */
errno = EBADF;
}
}
}
#endif
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
/* re-open previous stream */
if (_initdir (dirp) == 0) {
/* initialization failed but we cannot deal with error. User will notice
* error later when she tries to retrieve first directory enty. */
/*EMPTY*/;
}
}
@ -600,37 +599,36 @@ rewinddir (DIR *dirp)
*/
static int
_initdir (DIR *dirp)
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
{
assert (dirp != NULL);
assert (dirp->dirname != NULL);
dirp->dirent_filled = 0;
# if defined(DIRENT_WIN32_INTERFACE)
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
/* Open stream and retrieve first file */
dirp->search_handle = FindFirstFile (dirp->dirname, &dirp->current.data);
if (dirp->search_handle == INVALID_HANDLE_VALUE) {
/* something went wrong but we don't know what. GetLastError() could
* give us more information about the error, but then we should map
* the error code into errno. */
errno = ENOENT;
return 0;
}
# elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0)
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) {
/* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */
return 0;
}
# endif
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
/* initialize DIR and it's first entry */
_setdirname (dirp);
dirp->dirent_filled = 1;
return 1;
}
@ -641,14 +639,14 @@ static const char *
_getdirname (const struct dirent *dp)
{
#if defined(DIRENT_WIN32_INTERFACE)
return dp->data.cFileName;
return dp->data.cFileName;
#elif defined(DIRENT_USE_FFBLK)
return dp->data.ff_name;
return dp->data.ff_name;
#else
return dp->data.name;
#endif
return dp->data.name;
#endif
}
@ -656,16 +654,17 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field.
*/
static void
_setdirname (struct DIR *dirp) {
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
_setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);
strncpy (dirp->current.d_name,
_getdirname (&dirp->current),
NAME_MAX);
dirp->current.d_name[NAME_MAX] = '\0'; /*char d_name[NAME_MAX+1]*/
}
# ifdef __cplusplus
}
# 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.
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.
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
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
void info_callback(const char *msg, void *client_data)
{
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()
{
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
fprintf(stdout," Help for the 'mj2_to_metadata' Program\n");
fprintf(stdout," ======================================\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");
/* "1234567890123456789012345678901234567890123456789012345678901234567890123456789" */
fprintf(stdout," Help for the 'mj2_to_metadata' Program\n");
fprintf(stdout," ======================================\n");
fprintf(stdout,"The -h option displays this information on screen.\n\n");
fprintf(stdout,"By Default\n");
fprintf(stdout,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\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,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
fprintf(stdout," meaning of non-obvious tag abbreviations;\n");
fprintf(stdout," range and precision of valid values;\n");
fprintf(stdout," interpretations of values, such as enumerations; and\n");
fprintf(stdout," current implementation limitations.\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,"\n");
fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h)\n");
fprintf(stdout,"------------------------------------\n");
fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n");
fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n");
fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n");
fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n");
fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters\n");
fprintf(stdout,"-------------------\n");
fprintf(stdout,"-h : Display this help information.\n");
fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n");
fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n");
fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n");
fprintf(stdout,"-f 0 : No jp2 header info.\n");
fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n");
fprintf(stdout,"-d : Suppress all 'derived' data.\n");
fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n");
fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n");
fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n");
fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n");
fprintf(stdout," 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" */
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,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\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,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
fprintf(stdout," meaning of non-obvious tag abbreviations;\n");
fprintf(stdout," range and precision of valid values;\n");
fprintf(stdout," interpretations of values, such as enumerations; and\n");
fprintf(stdout," current implementation limitations.\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,"\n");
fprintf(stdout,"The file is self-contained and no verification (e.g., against a DTD) is requested.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Required Parameters (except with -h)\n");
fprintf(stdout,"------------------------------------\n");
fprintf(stdout,"[Caution: file strings that contain spaces should be wrapped with quotes.]\n");
fprintf(stdout,"-i input.mj2 : where 'input' is any source file name or path.\n");
fprintf(stdout," MJ2 files created with 'frames_to_mj2' are supported so far.\n");
fprintf(stdout," These are silent, single-track, 'MJ2 Simple Profile' videos.\n");
fprintf(stdout,"-o output.xml : where 'output' is any destination file name or path.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Optional Parameters\n");
fprintf(stdout,"-------------------\n");
fprintf(stdout,"-h : Display this help information.\n");
fprintf(stdout,"-n : Suppress all mj2_to_metadata notes.\n");
fprintf(stdout,"-t : Include sample-size and chunk-offset tables.\n");
fprintf(stdout,"-f n : where n > 0. Include jp2 header info for frame n [default=1].\n");
fprintf(stdout,"-f 0 : No jp2 header info.\n");
fprintf(stdout,"-r : Suppress all 'raw' data for which a 'derived' form exists.\n");
fprintf(stdout,"-d : Suppress all 'derived' data.\n");
fprintf(stdout," (If both -r and -d given, -r will be ignored.)\n");
fprintf(stdout,"-v string : Verify against the DTD file located by the string.\n");
fprintf(stdout," Prepend quoted 'string' with either SYSTEM or PUBLIC keyword.\n");
fprintf(stdout," Thus, for the distributed DTD placed in the same directory as\n");
fprintf(stdout," 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_event_mgr_t event_mgr; /* event manager */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
FILE *file, *xmlout;
/* char xmloutname[50]; */
opj_mj2_t *movie;
FILE *file, *xmlout;
/* char xmloutname[50]; */
opj_mj2_t *movie;
char* infile = 0;
char* outfile = 0;
char* s, S1, S2, S3;
int len;
unsigned int sampleframe = 1; /* First frame */
char* stringDTD = NULL;
BOOL notes = TRUE;
BOOL sampletables = FALSE;
BOOL raw = TRUE;
BOOL derived = TRUE;
mj2_dparameters_t parameters;
char* infile = 0;
char* outfile = 0;
char* s, S1, S2, S3;
int len;
unsigned int sampleframe = 1; /* First frame */
char* stringDTD = NULL;
BOOL notes = TRUE;
BOOL sampletables = FALSE;
BOOL raw = TRUE;
BOOL derived = TRUE;
mj2_dparameters_t parameters;
while (TRUE) {
/* ':' after letter means it takes an argument */
int c = getopt(argc, argv, "i:o:f:v:hntrd");
/* FUTURE: Reserve 'p' for pruning file (which will probably make -t redundant) */
if (c == -1)
break;
switch (c) {
case 'i': /* IN file */
infile = optarg;
s = optarg;
while (*s) { s++; } /* Run to filename end */
s--;
S3 = *s;
s--;
S2 = *s;
s--;
S1 = *s;
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (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;
while (TRUE) {
/* ':' after letter means it takes an argument */
int c = getopt(argc, argv, "i:o:f:v:hntrd");
/* FUTURE: Reserve 'p' for pruning file (which will probably make -t redundant) */
if (c == -1)
break;
switch (c) {
case 'i': /* IN file */
infile = optarg;
s = optarg;
while (*s) {
s++; /* Run to filename end */
}
s--;
S3 = *s;
s--;
S2 = *s;
s--;
S1 = *s;
/* ----------------------------------------------------- */
case 'o': /* OUT file */
outfile = optarg;
while (*outfile) { outfile++; } /* Run to filename end */
outfile--;
S3 = *outfile;
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;
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|| (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;
/* ----------------------------------------------------- */
case 'f': /* Choose sample frame. 0 = none */
sscanf(optarg, "%u", &sampleframe);
break;
/* ----------------------------------------------------- */
case 'o': /* OUT file */
outfile = optarg;
while (*outfile) {
outfile++; /* Run to filename end */
}
outfile--;
S3 = *outfile;
outfile--;
S2 = *outfile;
outfile--;
S1 = *outfile;
/* ----------------------------------------------------- */
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;
}
outfile = optarg;
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
break;
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
return 1;
if ((S1 == 'x' && S2 == 'm' && S3 == 'l')
|| (S1 == 'X' && S2 == 'M' && S3 == 'L'))
break;
/* ----------------------------------------------------- */
case 'n': /* Suppress comments */
notes = FALSE;
break;
fprintf(stderr,
"Output file name must have .xml extension, not .%c%c%c\n", S1, S2, S3);
return 1;
/* ----------------------------------------------------- */
case 't': /* Show sample size and chunk offset tables */
sampletables = TRUE;
break;
/* ----------------------------------------------------- */
case 'f': /* Choose sample frame. 0 = none */
sscanf(optarg, "%u", &sampleframe);
break;
/* ----------------------------------------------------- */
case 'h': /* Display an help description */
help_display();
return 0;
/* ----------------------------------------------------- */
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;
}
/* ----------------------------------------------------- */
case 'r': /* Suppress raw data */
raw = FALSE;
break;
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
break;
/* ----------------------------------------------------- */
case 'd': /* Suppress derived data */
derived = FALSE;
break;
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
return 1;
/* ----------------------------------------------------- */
default:
return 1;
} /* switch */
} /* while */
/* ----------------------------------------------------- */
case 'n': /* Suppress comments */
notes = FALSE;
break;
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 */
/* -------------- */
if (!infile || !outfile) {
fprintf(stderr,"Correct usage: mj2_to_metadata -i mj2-file -o xml-file (plus options)\n");
return 1;
}
/* -------------- */
if (!infile || !outfile) {
fprintf(stderr,"Correct usage: mj2_to_metadata -i mj2-file -o xml-file (plus options)\n");
return 1;
}
/* was:
if (argc != 3) {
printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n");
printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n");
return 1;
}
*/
len = strlen(infile);
if(infile[0] == ' ')
{
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;
}
/* was:
if (argc != 3) {
printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n");
printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n");
return 1;
}
*/
len = strlen(infile);
if(infile[0] == ' ') {
infile++; /* There may be a leading blank if user put space after -i */
}
len = strlen(outfile);
if(outfile[0] == ' ')
{
outfile++; /* There may be a leading blank if user put space after -o */
}
file = fopen(infile, "rb"); /* was: argv[1] */
// Checking output file
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
if (!file) {
fprintf(stderr, "Failed to open %s for reading.\n", infile); /* was: 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;
len = strlen(outfile);
if(outfile[0] == ' ') {
outfile++; /* There may be a leading blank if user put space after -o */
}
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
// Checking output file
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 */
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters);
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
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);
return 1;
}
xml_write_init(notes, sampletables, raw, derived);
xml_write_struct(file, xmlout, movie, sampleframe, stringDTD, &event_mgr);
fclose(xmlout);
fprintf(stderr,"Metadata correctly extracted to XML file \n");;
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 */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
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
*/
static void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio = NULL;
unsigned int tnum, snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
opj_image_t *img = NULL;
unsigned int max_codstrm_size = 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);
int main(int argc, char *argv[])
{
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio = NULL;
unsigned int tnum, snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
opj_image_t *img = NULL;
unsigned int max_codstrm_size = 0;
double total_time = 0;
unsigned int numframes = 0;
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));
if (argc != 3) {
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1;
}
numframes = track->num_samples;
for (snum=0; snum < numframes; snum++)
{
double init_time = opj_clock();
double elapsed_time;
file = fopen(argv[1], "rb");
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 */
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));
/* 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
if(img->color_space == CLRSPC_SYCC)
{
color_sycc_to_rgb(img);
}
if(img->color_space == CLRSPC_SYCC) {
color_sycc_to_rgb(img);
}
#endif
if(img->icc_profile_buf)
{
if(img->icc_profile_buf) {
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img);
color_apply_icc_profile(img);
#endif
free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0;
}
free(img->icc_profile_buf);
img->icc_profile_buf = NULL;
img->icc_profile_len = 0;
}
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->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 (((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->numcomps == 1)) {
}
free(frame_codestream);
fclose(file);
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;
/* 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;
} 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;
}
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -46,110 +46,113 @@
/**
sample error callback expecting a FILE* client object
*/
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum;
unsigned int snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
mj2_dparameters_t parameters;
int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum;
unsigned int snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *file, *outfile;
char outfilename[50];
mj2_dparameters_t parameters;
if (argc != 3) {
printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\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;
}
/*
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;
if (argc != 3) {
printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
free(frame_codestream);
file = fopen(argv[1], "rb");
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return 0;
/*
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);
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -41,14 +41,15 @@
#include "jp2.h"
#include "mj2.h"
static int int_ceildiv(int a, int b) {
return (a + b - 1) / b;
static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b;
}
/**
Size of memory first allocated for MOOV box
*/
#define TEMP_BUF 10000
#define TEMP_BUF 10000
#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)
{
FILE *reader;
opj_image_t *image;
unsigned char *src;
opj_dinfo_t *dinfo;
opj_cio_t *cio;
opj_dparameters_t dparameters;
int success;
long src_len;
FILE *reader;
opj_image_t *image;
unsigned char *src;
opj_dinfo_t *dinfo;
opj_cio_t *cio;
opj_dparameters_t dparameters;
int success;
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);
src_len = ftell(reader);
fseek(reader, 0, SEEK_SET);
src = (unsigned char*) malloc(src_len);
fread(src, 1, src_len, reader);
fclose(reader);
fseek(reader, 0, SEEK_END);
src_len = ftell(reader);
fseek(reader, 0, SEEK_SET);
src = (unsigned char*) malloc(src_len);
fread(src, 1, src_len, reader);
fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0)
{
free(src); return success;
}
memset(&dparameters, 0, sizeof(opj_dparameters_t));
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
free(src);
return success;
}
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;
opj_cio_close(cio);
free(src);
cio->buffer = NULL;
opj_cio_close(cio);
if(image == NULL) goto fin;
if(image == NULL) goto fin;
cp->numcomps = image->numcomps;
cp->w = image->comps[0].w;
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
cp->numcomps = image->numcomps;
cp->w = image->comps[0].w;
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
if(image->numcomps > 2 )
{
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))/* horizontal and vertical*/
{
/* Y420*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))/* horizontal only*/
{
/* Y422*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
/* Y444 or RGB */
if(image->numcomps > 2 ) {
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2)) { /* horizontal and vertical*/
/* Y420*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
} else if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) { /* horizontal only*/
/* Y422*/
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
} else if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) {
/* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB)
{
cp->enumcs = ENUMCS_SRGB;
if(image->color_space == CLRSPC_SRGB) {
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
else
{
cp->enumcs = ENUMCS_SYCC;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
} else {
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
}
else
{
goto fin;
}
}
else
{
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
if(image->icc_profile_buf)
{
cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL;
}
else cp->meth = 1;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
} else {
goto fin;
}
} else {
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
}
if(image->icc_profile_buf) {
cp->meth = 2;
free(image->icc_profile_buf);
image->icc_profile_buf = NULL;
} else cp->meth = 1;
success = 1;
success = 1;
fin:
if(dinfo)
opj_destroy_decompress(dinfo);
if(dinfo)
opj_destroy_decompress(dinfo);
if(image)
opj_image_destroy(image);
if(image)
opj_image_destroy(image);
return success;
return success;
}
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
static void info_callback(const char *msg, void *client_data)
{
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)
{
int len,i;
char buf, buf2[2];
unsigned char *siz_buffer;
opj_cio_t *cio;
fseek(file, 0, SEEK_SET);
do {
fread(&buf,1,1, file);
if (buf==(char)0xff)
fread(&buf,1,1, file);
}
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len);
cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */
image->x0 = cio_read(cio, 4); /* X0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */
cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
image->numcomps = cio_read(cio,2); /* Csiz */
image->comps =
(opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp;
tmp = cio_read(cio,1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7;
image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */
image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = 0; /* reducing factor by component */
}
fseek(file, 0, SEEK_SET);
opj_cio_close(cio);
free(siz_buffer);
int len,i;
char buf, buf2[2];
unsigned char *siz_buffer;
opj_cio_t *cio;
fseek(file, 0, SEEK_SET);
do {
fread(&buf,1,1, file);
if (buf==(char)0xff)
fread(&buf,1,1, file);
} while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len);
cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */
image->x0 = cio_read(cio, 4); /* X0siz */
image->y0 = cio_read(cio, 4); /* Y0siz */
cio_skip(cio, 16); /* XTsiz, YTsiz, XT0siz, YT0siz */
image->numcomps = cio_read(cio,2); /* Csiz */
image->comps =
(opj_image_comp_t *) malloc(image->numcomps * sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp;
tmp = cio_read(cio,1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7;
image->comps[i].dx = cio_read(cio,1); /* XRsiz_i */
image->comps[i].dy = cio_read(cio,1); /* YRsiz_i */
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = 0; /* reducing factor by component */
}
fseek(file, 0, SEEK_SET);
opj_cio_close(cio);
free(siz_buffer);
}
static void setparams(opj_mj2_t *movie, opj_image_t *image) {
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);
mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) {
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
static void setparams(opj_mj2_t *movie, opj_image_t *image)
{
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);
mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) {
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps; /* NC */
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
movie->tk[0].jp2_struct.IPR = 0; /* IPR, no intellectual property*/
movie->tk[0].jp2_struct.w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].jp2_struct.h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
depth_0 = image->comps[0].prec - 1;
sign = image->comps[0].sgnd;
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
movie->tk[0].jp2_struct.bpc = 255;
}
for (i = 0; i < image->numcomps; i++)
movie->tk[0].jp2_struct.comps[i].bpcc =
image->comps[i].prec - 1 + (image->comps[i].sgnd << 7);
if ((image->numcomps == 1 || image->numcomps == 3)
&& (movie->tk[0].jp2_struct.bpc != 255))
movie->tk[0].jp2_struct.meth = 1;
else
movie->tk[0].jp2_struct.meth = 2;
movie->tk[0].jp2_struct.meth = 2;
if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
}
int main(int argc, char *argv[]) {
opj_cinfo_t* cinfo;
opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum;
opj_mj2_t *movie;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *mj2file, *j2kfile;
char *j2kfilename;
unsigned char *buf;
int offset, mdat_initpos;
opj_image_t img;
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;
int main(int argc, char *argv[])
{
opj_cinfo_t* cinfo;
opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum;
opj_mj2_t *movie;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *mj2file, *j2kfile;
char *j2kfilename;
unsigned char *buf;
int offset, mdat_initpos;
opj_image_t img;
opj_cio_t *cio;
mj2_cparameters_t parameters;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1)
{
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
}
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
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;
}
/* 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;
mj2file = fopen(argv[2], "wb");
if (!mj2file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
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);
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
setting of each callback is optionnal
*/
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
/* setup the decoder encoding parameters using user parameters */
memset(&parameters, 0, sizeof(mj2_cparameters_t));
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
parameters.frame_rate = 25; /* DEFAULT */
mj2_setup_encoder(movie, &parameters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
cio_skip(cio, 4);
cio_write(cio,MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
snum=0;
offset = 0;
while(1) {
mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
} else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
}
/* Calculating offset for samples and chunks */
offset += cio_tell(cio);
sample->offset = offset;
movie->tk[0].chunk[snum].offset = offset; /* There will be one sample per chunk */
/* Calculating sample size */
fseek(j2kfile,0,SEEK_END);
sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
if (snum==0)
read_siz_marker(j2kfile, &img);
/* Writing JP2C box header */
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); /* Sample size */
cio_write(cio,JP2_JP2C, 4); /* JP2C */
/* Writing codestream from J2K file to MJ2 file */
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
/* Ending loop */
fclose(j2kfile);
snum++;
new_sample = (mj2_sample_t*)
realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
new_chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
if (new_sample && new_chunk) {
movie->tk[0].sample = new_sample;
movie->tk[0].chunk = new_chunk;
} else {
fprintf(stderr, "Failed to allocate enough memory to read %s\n", j2kfilename);
return 1;
}
free(frame_codestream);
}
/* Writing the MDAT box length in header */
offset += cio_tell(cio);
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:
fclose(mj2file);
mj2_destroy_compress(movie);
free(j2kfilename);
fclose(mj2file);
mj2_destroy_compress(movie);
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -180,73 +180,83 @@ class OPJChildFrame;
//////////////////////////////////
class OPJViewerApp: public wxApp
{
// public methods and variables
public:
// public methods and variables
public:
// class constructor
OPJViewerApp() { m_showImages = true; m_showButtons = false; }
// class constructor
OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show) { m_showImages = show; }
bool ShowImages() const { return m_showImages; }
void ShowCmdLine(const wxCmdLineParser& parser);
// other methods
bool OnInit(void);
int OnExit(void);
void SetShowImages(bool show)
{
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
// removed from the array
wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;
// all the threads currently alive - as soon as the thread terminates, it's
// removed from the array
wxArrayThread m_deco_threads, m_parse_threads, m_enco_threads;
// crit section protects access to all of the arrays below
wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;
// crit section protects access to all of the arrays below
wxCriticalSection m_deco_critsect, m_parse_critsect, m_enco_critsect;
// semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;
// semaphore used to wait for the threads to exit, see OPJFrame::OnQuit()
wxSemaphore m_deco_semAllDone, m_parse_semAllDone, m_enco_semAllDone;
// the last exiting thread should post to m_semAllDone if this is true
// (protected by the same m_critsect)
bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone;
// the last exiting thread should post to m_semAllDone if this is true
// (protected by the same m_critsect)
bool m_deco_waitingUntilAllDone, m_parse_waitingUntilAllDone, m_enco_waitingUntilAllDone;
// the list of all filenames written in the command line
wxArrayString m_filelist;
// the list of all filenames written in the command line
wxArrayString m_filelist;
// displaying engine parameters
int m_resizemethod;
// displaying engine parameters
int m_resizemethod;
// decoding engine parameters
bool m_enabledeco, m_enableparse;
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
// decoding engine parameters
bool m_enabledeco, m_enableparse;
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL
bool m_enablejpwl, m_enablejpwle;
int m_expcomps, m_maxtiles;
bool m_enablejpwl, m_enablejpwle;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
int m_framewidth, m_frameheight;
int m_framewidth, m_frameheight;
// encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
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_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm;
bool m_enablesegmark, m_enablepoc;
bool m_enablequality;
int m_resolutions, m_progression;
// encoding engine parameters
wxString m_subsampling, m_origin, m_rates, m_comment, m_index, m_quality;
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_enablebypass, m_enablereset, m_enablerestart, m_enablevsc, m_enableerterm;
bool m_enablesegmark, m_enablepoc;
bool m_enablequality;
int m_resolutions, m_progression;
#ifdef USE_JPWL
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],
m_ppackval[MYJPWL_MAX_NO_TILESPECS];
int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[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],
m_ppackval[MYJPWL_MAX_NO_TILESPECS];
int m_sensisel[MYJPWL_MAX_NO_TILESPECS], m_stileval[MYJPWL_MAX_NO_TILESPECS];
#endif // USE_JPWL
// some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker;
int m_browserwidth, m_peekerheight;
// some layout settings
bool m_showtoolbar, m_showbrowser, m_showpeeker;
int m_browserwidth, m_peekerheight;
// application configuration
wxConfig *OPJconfig;
// application configuration
wxConfig *OPJconfig;
// private methods and variables
private:
bool m_showImages, m_showButtons;
// private methods and variables
private:
bool m_showImages, m_showButtons;
};
@ -257,37 +267,38 @@ DECLARE_APP(OPJViewerApp)
///////////////////////////////////////////
class OPJCanvas: public wxScrolledWindow
{
// public methods and variables
public:
// public methods and variables
public:
// class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
// class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text) {
#ifndef __WXGTK__
wxMutexGuiEnter();
virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text)
{
#ifndef __WXGTK__
wxMutexGuiEnter();
#endif //__WXGTK__
wxLogMessage(text);
#ifndef __WXGTK__
wxMutexGuiLeave();
wxLogMessage(text);
#ifndef __WXGTK__
wxMutexGuiLeave();
#endif //__WXGTK__
}
}
void OnThreadSignal(wxCommandEvent& event);
void OnThreadSignal(wxCommandEvent& event);
OPJDecoThread *CreateDecoThread(void);
OPJEncoThread *CreateEncoThread(void);
OPJDecoThread *CreateDecoThread(void);
OPJEncoThread *CreateEncoThread(void);
OPJChildFrame *m_childframe;
OPJChildFrame *m_childframe;
wxBitmap m_image, m_image100;
wxFileName m_fname, m_savename;
long m_zooml;
wxBitmap m_image, m_image100;
wxFileName m_fname, m_savename;
long m_zooml;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
///////////////////////////////////////////////////
@ -295,29 +306,38 @@ class OPJCanvas: public wxScrolledWindow
///////////////////////////////////////////////////
class OPJMarkerData : public wxTreeItemData
{
// public methods and variables
public:
// public methods and variables
public:
// 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; }
// 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;
}
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const { return m_desc.c_str(); }
const wxChar *GetDesc2() const { return m_filestring.c_str(); }
wxFileOffset m_start, m_length;
wxString m_desc;
void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const
{
return m_desc.c_str();
}
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
wxFileOffset m_start, m_length;
wxString m_desc;
// private methods and variables
private:
wxString m_filestring;
// private methods and variables
private:
wxString m_filestring;
};
class OPJMarkerTree : public wxTreeCtrl
{
public:
enum
{
enum {
TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder,
@ -327,15 +347,20 @@ public:
OPJMarkerTree() { };
OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style);
virtual ~OPJMarkerTree(){};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); }
const wxPoint& pos, const wxSize& size,
long style);
virtual ~OPJMarkerTree() {};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text)
{
wxMutexGuiEnter();
wxLogMessage(text);
wxMutexGuiLeave();
}
wxFileName m_fname;
wxTextCtrl *m_peektextCtrl;
OPJChildFrame *m_childframe;
wxFileName m_fname;
wxTextCtrl *m_peektextCtrl;
OPJChildFrame *m_childframe;
/*void OnBeginDrag(wxTreeEvent& event);
void OnBeginRDrag(wxTreeEvent& event);
@ -372,9 +397,15 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/
/*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:
/*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
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(void);
void OnSize(wxSizeEvent& WXUNUSED(event));
void OnSize(wxSizeEvent& WXUNUSED(event));
void OnAbout(wxCommandEvent& WXUNUSED(event));
void OnFileOpen(wxCommandEvent& WXUNUSED(event));
void OnFileSaveAs(wxCommandEvent& WXUNUSED(event));
@ -429,43 +460,43 @@ class OPJFrame: public wxMDIParentFrame
void OnQuit(wxCommandEvent& WXUNUSED(event));
void OnClose(wxCommandEvent& WXUNUSED(event));
void OnZoom(wxCommandEvent& WXUNUSED(event));
void OnFit(wxCommandEvent& event);
void OnToggleBrowser(wxCommandEvent& WXUNUSED(event));
void OnTogglePeeker(wxCommandEvent& WXUNUSED(event));
void OnToggleToolbar(wxCommandEvent& WXUNUSED(event));
void OnReload(wxCommandEvent& event);
void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event);
void OpenFiles(wxArrayString paths, wxArrayString filenames);
void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child);
void OnThreadLogmsg(wxCommandEvent& event);
void OnFit(wxCommandEvent& event);
void OnToggleBrowser(wxCommandEvent& WXUNUSED(event));
void OnTogglePeeker(wxCommandEvent& WXUNUSED(event));
void OnToggleToolbar(wxCommandEvent& WXUNUSED(event));
void OnReload(wxCommandEvent& event);
void OnPrevFrame(wxCommandEvent& event);
void OnHomeFrame(wxCommandEvent& event);
void OnNextFrame(wxCommandEvent& event);
void OnLessLayers(wxCommandEvent& event);
void OnAllLayers(wxCommandEvent& event);
void OnMoreLayers(wxCommandEvent& event);
void OnLessRes(wxCommandEvent& event);
void OnFullRes(wxCommandEvent& event);
void OnMoreRes(wxCommandEvent& event);
void OnPrevComp(wxCommandEvent& event);
void OnAllComps(wxCommandEvent& event);
void OnNextComp(wxCommandEvent& event);
void OnSetsEnco(wxCommandEvent& event);
void OnSetsDeco(wxCommandEvent& event);
void OnSashDrag(wxSashEvent& event);
void OpenFiles(wxArrayString paths, wxArrayString filenames);
void SaveFile(wxArrayString paths, wxArrayString filenames);
void OnNotebook(wxNotebookEvent& event);
void Rescale(int scale, OPJChildFrame *child);
void OnThreadLogmsg(wxCommandEvent& event);
OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash;
OPJMarkerTreeHash m_treehash;
OPJChildFrameHash m_childhash;
wxSashLayoutWindow* markerTreeWindow;
wxSashLayoutWindow* loggingWindow;
wxToolBar* tool_bar;
wxToolBar* tool_bar;
void Resize(int number);
wxNotebook *m_bookCtrl;
wxNotebook *m_bookCtrlbottom;
wxNotebook *m_bookCtrl;
wxNotebook *m_bookCtrlbottom;
wxTextCtrl *m_textCtrlbrowse;
private:
private:
void TogStyle(int id, long flag);
void DoSort(bool reverse = false);
@ -479,70 +510,69 @@ protected:
wxSashLayoutWindow* m_topWindow;
wxSashLayoutWindow* m_leftWindow2;
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
class OPJChildFrame: public wxMDIChildFrame
{
public:
public:
OPJCanvas *m_canvas;
OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJChildFrame(void);
void OnActivate(wxActivateEvent& event);
/*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
void OnClose(wxCloseEvent& event);
void OnGotFocus(wxFocusEvent& event);
void OnLostFocus(wxFocusEvent& event);
/*void OnQuit(wxCommandEvent& WXUNUSED(event));*/
void OnClose(wxCloseEvent& event);
void OnGotFocus(wxFocusEvent& event);
void OnLostFocus(wxFocusEvent& event);
OPJFrame *m_frame;
wxFileName m_fname;
int m_winnumber;
wxFileName m_fname;
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
enum {
OPJFRAME_FILEEXIT = wxID_EXIT,
OPJFRAME_HELPABOUT = wxID_ABOUT,
OPJFRAME_FILEOPEN,
OPJFRAME_MEMORYOPEN,
OPJFRAME_FILESAVEAS,
OPJFRAME_FILETOGGLEB,
OPJFRAME_FILETOGGLEP,
OPJFRAME_FILETOGGLET,
OPJFRAME_VIEWZOOM,
OPJFRAME_VIEWFIT,
OPJFRAME_VIEWRELOAD,
OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO,
OPJFRAME_FILEEXIT = wxID_EXIT,
OPJFRAME_HELPABOUT = wxID_ABOUT,
OPJFRAME_FILEOPEN,
OPJFRAME_MEMORYOPEN,
OPJFRAME_FILESAVEAS,
OPJFRAME_FILETOGGLEB,
OPJFRAME_FILETOGGLEP,
OPJFRAME_FILETOGGLET,
OPJFRAME_VIEWZOOM,
OPJFRAME_VIEWFIT,
OPJFRAME_VIEWRELOAD,
OPJFRAME_VIEWPREVFRAME,
OPJFRAME_VIEWHOMEFRAME,
OPJFRAME_VIEWNEXTFRAME,
OPJFRAME_VIEWLESSLAYERS,
OPJFRAME_VIEWALLLAYERS,
OPJFRAME_VIEWMORELAYERS,
OPJFRAME_VIEWLESSRES,
OPJFRAME_VIEWFULLRES,
OPJFRAME_VIEWMORERES,
OPJFRAME_VIEWPREVCOMP,
OPJFRAME_VIEWALLCOMPS,
OPJFRAME_VIEWNEXTCOMP,
OPJFRAME_FILECLOSE,
OPJFRAME_SETSENCO,
OPJFRAME_SETSDECO,
OPJFRAME_BROWSEWIN = 10000,
OPJFRAME_LOGWIN,
OPJFRAME_TOOLBAR,
OPJFRAME_BROWSEWIN = 10000,
OPJFRAME_LOGWIN,
OPJFRAME_TOOLBAR,
OPJFRAME_THREADLOGMSG,
OPJCANVAS_THREADSIGNAL
OPJFRAME_THREADLOGMSG,
OPJCANVAS_THREADSIGNAL
};
// menu and control ids
enum
{
enum {
TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST,
@ -587,8 +617,8 @@ enum
TreeTest_Unselect,
TreeTest_SelectRoot,
TreeTest_Ctrl = 1000,
BOTTOM_NOTEBOOK_ID,
LEFT_NOTEBOOK_ID
BOTTOM_NOTEBOOK_ID,
LEFT_NOTEBOOK_ID
};
class OPJEncoThread : public wxThread
@ -645,19 +675,19 @@ public:
// write something to the text control
void WriteText(const wxString& text);
void LoadFile(wxFileName fname);
void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
void LoadFile(wxFileName fname);
void ParseJ2KFile(wxFile *m_file, wxFileOffset offset, wxFileOffset length, wxTreeItemId parentid);
void ParseJP2File(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit, wxTreeItemId parentid);
unsigned m_count;
OPJMarkerTree *m_tree;
wxTreeItemId m_parentid;
wxTreeItemId m_parentid;
private:
int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int jpeg2000parse(wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
int box_handler_function(int boxtype, wxFile *fileid, wxFileOffset filepoint, wxFileOffset filelimit,
wxTreeItemId parentid, int level, char *scansign, unsigned long int *scanpoint);
};
@ -666,7 +696,10 @@ private:
class OPJDnDFile: public wxFileDropTarget
{
public:
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; }
OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private:
@ -678,137 +711,137 @@ private:
// Property sheet dialog: encoder
class OPJEncoderDialog: public wxPropertySheetDialog
{
DECLARE_CLASS(OPJEncoderDialog)
DECLARE_CLASS(OPJEncoderDialog)
public:
OPJEncoderDialog(wxWindow* parent, int dialogType);
~OPJEncoderDialog();
wxBookCtrlBase* m_settingsNotebook;
wxBookCtrlBase* m_settingsNotebook;
wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1_1SettingsPage(wxWindow* parent);
wxPanel* CreatePart1_2SettingsPage(wxWindow* parent);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event);
void OnRadioQualityRate(wxCommandEvent& event);
#ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/
wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS];
void OnHprotSelect(wxCommandEvent& event);
void OnPprotSelect(wxCommandEvent& event);
void OnSensiSelect(wxCommandEvent& event);
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
/*wxCheckBox *m_enablejpwlCheck;*/
wxChoice *m_hprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_htileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_pprotChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ptileCtrl[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_ppackCtrl[MYJPWL_MAX_NO_TILESPECS];
wxChoice *m_sensiChoice[MYJPWL_MAX_NO_TILESPECS];
wxSpinCtrl *m_stileCtrl[MYJPWL_MAX_NO_TILESPECS];
void OnHprotSelect(wxCommandEvent& event);
void OnPprotSelect(wxCommandEvent& event);
void OnSensiSelect(wxCommandEvent& event);
#endif // USE_JPWL
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck;
wxSpinCtrl *m_resolutionsCtrl;
wxTextCtrl *m_subsamplingCtrl, *m_originCtrl, *m_rateCtrl, *m_commentCtrl;
wxRadioButton *m_rateRadio, *m_qualityRadio;
wxTextCtrl *m_indexCtrl, *m_qualityCtrl, *m_cbsizeCtrl, *m_prsizeCtrl, *m_pocCtrl;
wxTextCtrl *m_tsizeCtrl, *m_toriginCtrl;
wxRadioBox *progressionBox;
wxCheckBox *m_enablecommCheck, *m_enableidxCheck, *m_mctCheck, *m_irrevCheck;
wxCheckBox *m_sopCheck, *m_ephCheck, *m_enablebypassCheck, *m_enableresetCheck,
*m_enablerestartCheck, *m_enablevscCheck, *m_enableertermCheck, *m_enablesegmarkCheck;
wxCheckBox *m_enablepocCheck, *m_enablejpwlCheck;
wxSpinCtrl *m_resolutionsCtrl;
protected:
enum {
OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE,
OPJENCO_TILESIZE,
OPJENCO_PROGRESSION,
OPJENCO_SUBSAMPLING,
OPJENCO_ENABLESOP,
OPJENCO_ENABLEEPH,
OPJENCO_ENABLEBYPASS,
OPJENCO_ENABLERESET,
OPJENCO_ENABLERESTART,
OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP,
OPJENCO_ROISHIFT,
OPJENCO_IMORIG,
OPJENCO_TILORIG,
OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME,
OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT,
OPJENCO_HPROT,
OPJENCO_HTILE,
OPJENCO_PPROT,
OPJENCO_PTILE,
OPJENCO_PPACK,
OPJENCO_SENSI,
OPJENCO_STILE
OPJENCO_ENABLEJPWL = 100,
OPJENCO_RATEFACTOR,
OPJENCO_RATERADIO,
OPJENCO_QUALITYFACTOR,
OPJENCO_QUALITYRADIO,
OPJENCO_RESNUMBER,
OPJENCO_CODEBLOCKSIZE,
OPJENCO_PRECINCTSIZE,
OPJENCO_TILESIZE,
OPJENCO_PROGRESSION,
OPJENCO_SUBSAMPLING,
OPJENCO_ENABLESOP,
OPJENCO_ENABLEEPH,
OPJENCO_ENABLEBYPASS,
OPJENCO_ENABLERESET,
OPJENCO_ENABLERESTART,
OPJENCO_ENABLEVSC,
OPJENCO_ENABLEERTERM,
OPJENCO_ENABLESEGMARK,
OPJENCO_ENABLEPOC,
OPJENCO_ROICOMP,
OPJENCO_ROISHIFT,
OPJENCO_IMORIG,
OPJENCO_TILORIG,
OPJENCO_ENABLEMCT,
OPJENCO_ENABLEIRREV,
OPJENCO_ENABLEINDEX,
OPJENCO_INDEXNAME,
OPJENCO_POCSPEC,
OPJENCO_ENABLECOMM,
OPJENCO_COMMENTTEXT,
OPJENCO_HPROT,
OPJENCO_HTILE,
OPJENCO_PPROT,
OPJENCO_PTILE,
OPJENCO_PPACK,
OPJENCO_SENSI,
OPJENCO_STILE
};
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
// Property sheet dialog: decoder
class OPJDecoderDialog: public wxPropertySheetDialog
{
DECLARE_CLASS(OPJDecoderDialog)
DECLARE_CLASS(OPJDecoderDialog)
public:
OPJDecoderDialog(wxWindow* parent, int dialogType);
~OPJDecoderDialog();
wxBookCtrlBase* m_settingsNotebook;
wxCheckBox *m_enabledecoCheck, *m_enableparseCheck;
wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
wxRadioBox* m_resizeBox;
wxBookCtrlBase* m_settingsNotebook;
wxCheckBox *m_enabledecoCheck, *m_enableparseCheck;
wxSpinCtrl *m_reduceCtrl, *m_layerCtrl, *m_numcompsCtrl;
wxRadioBox* m_resizeBox;
void OnEnableDeco(wxCommandEvent& event);
void OnEnableDeco(wxCommandEvent& event);
wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1SettingsPage(wxWindow* parent);
wxPanel* CreatePart3SettingsPage(wxWindow* parent);
#ifdef USE_JPWL
void OnEnableJPWL(wxCommandEvent& event);
void OnEnableJPWL(wxCommandEvent& event);
wxPanel* CreatePart11SettingsPage(wxWindow* parent);
wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
wxCheckBox *m_enablejpwlCheck;
wxSpinCtrl *m_expcompsCtrl, *m_maxtilesCtrl;
wxCheckBox *m_enablejpwlCheck;
#endif // USE_JPWL
wxSpinCtrl *m_framenumCtrl;
wxSpinCtrl *m_framenumCtrl;
protected:
enum {
OPJDECO_RESMETHOD = 100,
OPJDECO_REDUCEFACTOR,
OPJDECO_QUALITYLAYERS,
OPJDECO_NUMCOMPS,
OPJDECO_ENABLEDECO,
OPJDECO_ENABLEPARSE,
OPJDECO_ENABLEJPWL,
OPJDECO_EXPCOMPS,
OPJDECO_MAXTILES,
OPJDECO_FRAMENUM
OPJDECO_RESMETHOD = 100,
OPJDECO_REDUCEFACTOR,
OPJDECO_QUALITYLAYERS,
OPJDECO_NUMCOMPS,
OPJDECO_ENABLEDECO,
OPJDECO_ENABLEPARSE,
OPJDECO_ENABLEJPWL,
OPJDECO_EXPCOMPS,
OPJDECO_MAXTILES,
OPJDECO_FRAMENUM
};
DECLARE_EVENT_TABLE()
DECLARE_EVENT_TABLE()
};
#endif //__OPJ_VIEWER_H__

View File

@ -1,54 +1,54 @@
wxString htmlaboutpage = wxT(
"<html>"
"<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>"
"<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>"
"<td align=center>"
"<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</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>"
"</td>"
"</tr>"
"<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>"
"</tr>"
"<tr>"
"<td align=justify>"
"<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. "
"In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ")
"<html>"
"<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>"
"<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>"
"<td align=center>"
"<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</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>"
"</td>"
"</tr>"
"<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>"
"</tr>"
"<tr>"
"<td align=justify>"
"<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. "
"In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ")
#include "build.h"
wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
#ifdef USE_JPWL
wxT("<font size=-2 color=green>JPWL</font> ")
wxT("<font size=-2 color=green>JPWL</font> ")
#endif // USE_JPWL
#ifdef USE_JPSEC
wxT("<font size=-2 color=green>JPSEC</font> ")
wxT("<font size=-2 color=green>JPSEC</font> ")
#endif // USE_JPSEC
wxT(")</font><br>")
wxT(")</font><br>")
#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
wxT("</td>"
"</tr>"
"<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>"
"<tr>"
"<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>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>"
"</tr>"
"</table>"
"</body>"
"</html>"
);
wxT("</td>"
"</tr>"
"<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>"
"<tr>"
"<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>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>"
"</tr>"
"</table>"
"</body>"
"</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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -64,105 +64,105 @@ public:
m_type = wxBITMAP_TYPE_JPEG2000;
m_mime = wxT("image/mj2");
/* decoding */
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
/* decoding */
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
/* encoding */
m_subsampling = wxT("1,1");
m_origin = wxT("0,0");
m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40");
m_enablequality = false;
m_multicomp = false;
m_irreversible = false;
m_resolutions = 6;
m_progression = 0;
m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT("");
m_torigin = wxT("0,0");
/*m_progression
m_resilience*/
m_enablesop = false;
m_enableeph = false;
m_enablereset = false;
m_enablesegmark = false;
m_enablevsc = false;
m_enablerestart = false;
m_enableerterm = false;
m_enablebypass = false;
/*m_roicompo
m_roiup
m_indexfname*/
m_enableidx = false;
m_index = wxT("index.txt");
m_enablepoc = false;
m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
m_enablecomm = true;
/* encoding */
m_subsampling = wxT("1,1");
m_origin = wxT("0,0");
m_rates = wxT("20,10,5");
m_quality = wxT("30,35,40");
m_enablequality = false;
m_multicomp = false;
m_irreversible = false;
m_resolutions = 6;
m_progression = 0;
m_cbsize = wxT("32,32");
m_prsize = wxT("[128,128],[128,128]");
m_tsize = wxT("");
m_torigin = wxT("0,0");
/*m_progression
m_resilience*/
m_enablesop = false;
m_enableeph = false;
m_enablereset = false;
m_enablesegmark = false;
m_enablevsc = false;
m_enablerestart = false;
m_enableerterm = false;
m_enablebypass = false;
/*m_roicompo
m_roiup
m_indexfname*/
m_enableidx = false;
m_index = wxT("index.txt");
m_enablepoc = false;
m_poc = wxT("T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL");
m_enablecomm = true;
#if defined __WXMSW__
m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer Win32 - OpenJPEG version ");
#elif defined __WXGTK__
m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer Lin32 - OpenJPEG version ");
#else
m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
m_comment = wxT("Created by OPJViewer - OpenJPEG version ");
#endif
#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
m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
m_comment += wxString::Format(wxT("%s"), (char *) opj_version());
#endif
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
// encoding engine parameters
wxString m_subsampling;
wxString m_origin;
wxString m_rates;
wxString m_quality;
bool m_enablequality;
bool m_multicomp;
bool m_irreversible;
int m_resolutions;
int m_progression;
wxString m_cbsize;
wxString m_prsize;
wxString m_tsize;
wxString m_torigin;
/*m_progression
m_resilience*/
bool m_enablesop;
bool m_enableeph;
bool m_enablebypass;
bool m_enableerterm;
bool m_enablerestart;
bool m_enablereset;
bool m_enablesegmark;
bool m_enablevsc;
/*m_roicompo
m_roiup
m_indexfname*/
bool m_enableidx;
wxString m_index;
bool m_enablecomm;
wxString m_comment;
bool m_enablepoc;
wxString m_poc;
// encoding engine parameters
wxString m_subsampling;
wxString m_origin;
wxString m_rates;
wxString m_quality;
bool m_enablequality;
bool m_multicomp;
bool m_irreversible;
int m_resolutions;
int m_progression;
wxString m_cbsize;
wxString m_prsize;
wxString m_tsize;
wxString m_torigin;
/*m_progression
m_resilience*/
bool m_enablesop;
bool m_enableeph;
bool m_enablebypass;
bool m_enableerterm;
bool m_enablerestart;
bool m_enablereset;
bool m_enablesegmark;
bool m_enablevsc;
/*m_roicompo
m_roiup
m_indexfname*/
bool m_enableidx;
wxString m_index;
bool m_enablecomm;
wxString m_comment;
bool m_enablepoc;
wxString m_poc;
#if wxUSE_STREAMS
virtual bool LoadFile(wxImage *image, wxInputStream& stream, bool verbose=true, int index=-1);
@ -172,7 +172,7 @@ protected:
#endif
private:
OPJ_PROG_ORDER give_progression(char progression[4]);
OPJ_PROG_ORDER give_progression(char progression[4]);
DECLARE_DYNAMIC_CLASS(wxJPEG2000Handler)
};

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -66,23 +66,23 @@ public:
m_type = wxBITMAP_TYPE_MXF;
m_mime = wxT("image/mxf");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
m_filename = wxT("");
m_reducefactor = 0;
m_qualitylayers = 0;
m_components = 0;
m_filename = wxT("");
#ifdef USE_JPWL
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
m_enablejpwl = true;
m_expcomps = JPWL_EXPECTED_COMPONENTS;
m_maxtiles = JPWL_MAXIMUM_TILES;
#endif // USE_JPWL
}
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename;
// decoding engine parameters
int m_reducefactor, m_qualitylayers, m_components, m_framenum;
wxFileName m_filename;
#ifdef USE_JPWL
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
bool m_enablejpwl;
int m_expcomps, m_maxtiles;
#endif // USE_JPWL
#if wxUSE_STREAMS

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -72,120 +72,133 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
/*@}*/
/*
/*
==========================================================
local functions
==========================================================
*/
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
return OPJ_TRUE;
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
return OPJ_TRUE;
}
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
bio->buf |= *bio->bp++;
return OPJ_TRUE;
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
return OPJ_FALSE;
}
bio->buf |= *bio->bp++;
return OPJ_TRUE;
}
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 ? */
}
bio->ct--;
bio->buf |= b << bio->ct;
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 ? */
}
bio->ct--;
bio->buf |= b << bio->ct;
}
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 ? */
}
bio->ct--;
return (bio->buf >> bio->ct) & 1;
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 ? */
}
bio->ct--;
return (bio->buf >> bio->ct) & 1;
}
/*
/*
==========================================================
Bit Input/Output interface
==========================================================
*/
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* opj_bio_create(void)
{
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void opj_bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
void opj_bio_destroy(opj_bio_t *bio)
{
if(bio) {
opj_free(bio);
}
}
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) {
return (bio->bp - bio->start);
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio)
{
return (bio->bp - bio->start);
}
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 8;
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 8;
}
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 0;
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 0;
}
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_bio_putbit(bio, (v >> i) & 1);
}
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_bio_putbit(bio, (v >> i) & 1);
}
}
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
OPJ_UINT32 i;
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
{
OPJ_UINT32 i;
OPJ_UINT32 v;
v = 0;
for (i = n - 1; i < n; i--) {
v += opj_bio_getbit(bio) << i;
}
return v;
v = 0;
for (i = n - 1; i < n; i--) {
v += opj_bio_getbit(bio) << i;
}
return v;
}
OPJ_BOOL opj_bio_flush(opj_bio_t *bio) {
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
if (bio->ct == 7) {
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
}
return OPJ_TRUE;
OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
{
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
if (bio->ct == 7) {
if (! opj_bio_byteout(bio)) {
return OPJ_FALSE;
}
}
return OPJ_TRUE;
}
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) {
if ((bio->buf & 0xff) == 0xff) {
if (! opj_bio_bytein(bio)) {
return OPJ_FALSE;
}
}
bio->ct = 0;
return OPJ_TRUE;
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio)
{
if ((bio->buf & 0xff) == 0xff) {
if (! opj_bio_bytein(bio)) {
return OPJ_FALSE;
}
}
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -40,7 +40,7 @@
#include <stddef.h> /* ptrdiff_t */
/**
/**
@file bio.h
@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)
*/
typedef struct opj_bio {
/** pointer to the start of the buffer */
OPJ_BYTE *start;
/** pointer to the end of the buffer */
OPJ_BYTE *end;
/** pointer to the present position in the buffer */
OPJ_BYTE *bp;
/** temporary place where each byte is read or written */
OPJ_UINT32 buf;
/** coder : number of bits free to write. decoder : number of bits read */
OPJ_UINT32 ct;
/** pointer to the start of the buffer */
OPJ_BYTE *start;
/** pointer to the end of the buffer */
OPJ_BYTE *end;
/** pointer to the present position in the buffer */
OPJ_BYTE *bp;
/** temporary place where each byte is read or written */
OPJ_UINT32 buf;
/** coder : number of bits free to write. decoder : number of bits read */
OPJ_UINT32 ct;
} opj_bio_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new BIO handle
Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise
*/
opj_bio_t* opj_bio_create(void);
@ -89,14 +89,14 @@ ptrdiff_t opj_bio_numbytes(opj_bio_t *bio);
Init encoder
@param bio BIO handle
@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);
/**
Init decoder
@param bio BIO handle
@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);
/**
@ -109,7 +109,7 @@ void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
/**
Read bits
@param bio BIO handle
@param n Number of bits to read
@param n Number of bits to read
@return Returns the corresponding read number
*/
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n);

View File

@ -32,7 +32,7 @@
#include "opj_includes.h"
/*
/*
* Write CPTR Codestream finder box
*
* @param[in] coff offset of j2k codestream
@ -41,199 +41,197 @@
*/
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,
opj_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
int i;
OPJ_OFF_T lenp;
OPJ_UINT32 len;
opj_jp2_box_t *box;
int num_box = 0;
OPJ_BOOL EPHused;
OPJ_BYTE l_data_header [4];
int i;
OPJ_OFF_T lenp;
OPJ_UINT32 len;
opj_jp2_box_t *box;
int num_box = 0;
OPJ_BOOL EPHused;
OPJ_BYTE l_data_header [4];
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, 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)
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_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
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);
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++;
opj_write_manf( i, num_box, box, 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;
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++;
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++;
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);
}
box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
box[num_box].type = JPIP_TPIX;
num_box++;
opj_free( box);
return (int)len;
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_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,
opj_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [3*8];
OPJ_UINT32 len;
OPJ_OFF_T lenp;
OPJ_BYTE l_data_header [3*8];
OPJ_UINT32 len;
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_CPTR, 4); /* T */
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+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,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_CPTR, 4); /* T */
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+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,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);
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);
}
void opj_write_manf(int second,
int v,
opj_jp2_box_t *box,
void opj_write_manf(int second,
int v,
opj_jp2_box_t *box,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [4];
int i;
OPJ_UINT32 len;
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);
OPJ_BYTE l_data_header [4];
int i;
OPJ_UINT32 len;
OPJ_OFF_T lenp;
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);
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 */
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);
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_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);
}
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_UINT32 i;
OPJ_UINT32 len;
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_BYTE l_data_header [8];
OPJ_UINT32 i;
OPJ_UINT32 len;
OPJ_OFF_T lenp;
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
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.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_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++) { /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_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_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [4];
OPJ_BOOL EPHused = OPJ_FALSE;
int i=0;
OPJ_OFF_T org_pos;
unsigned int Scod;
OPJ_BYTE l_data_header [4];
OPJ_BOOL EPHused = OPJ_FALSE;
int i=0;
OPJ_OFF_T org_pos;
unsigned int Scod;
for(i = 0; i < marknum; i++)
{
if( markers[i].type == J2K_MS_COD)
{
org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
for(i = 0; i < marknum; i++) {
if( markers[i].type == J2K_MS_COD) {
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_read_bytes(l_data_header,&Scod,1);
if( ((Scod >> 2) & 1))
EPHused = OPJ_TRUE;
opj_stream_seek( cio, org_pos, p_manager);
opj_stream_read_data(cio,l_data_header,1,p_manager);
opj_read_bytes(l_data_header,&Scod,1);
if( ((Scod >> 2) & 1))
EPHused = OPJ_TRUE;
opj_stream_seek( cio, org_pos, p_manager);
break;
}
}
return EPHused;
break;
}
}
return EPHused;
}

View File

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

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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* 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)
#define opj_write_bytes opj_write_bytes_BE
#define opj_read_bytes opj_read_bytes_BE
#define opj_write_double opj_write_double_BE
#define opj_read_double opj_read_double_BE
#define opj_write_float opj_write_float_BE
#define opj_read_float opj_read_float_BE
#define opj_write_bytes opj_write_bytes_BE
#define opj_read_bytes opj_read_bytes_BE
#define opj_write_double opj_write_double_BE
#define opj_read_double opj_read_double_BE
#define opj_write_float opj_write_float_BE
#define opj_read_float opj_read_float_BE
#else
#define opj_write_bytes opj_write_bytes_LE
#define opj_read_bytes opj_read_bytes_LE
#define opj_write_double opj_write_double_LE
#define opj_read_double opj_read_double_LE
#define opj_write_float opj_write_float_LE
#define opj_read_float opj_read_float_LE
#define opj_write_bytes opj_write_bytes_LE
#define opj_read_bytes opj_read_bytes_LE
#define opj_write_double opj_write_double_LE
#define opj_read_double opj_read_double_LE
#define opj_write_float opj_write_float_LE
#define opj_read_float opj_read_float_LE
#endif
@ -78,87 +78,86 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/**
Byte input-output stream.
*/
typedef struct opj_stream_private
{
/**
* User data, be it files, ... The actual data depends on the type of the stream.
*/
void * m_user_data;
typedef struct opj_stream_private {
/**
* User data, be it files, ... The actual data depends on the type of the stream.
*/
void * m_user_data;
/**
* Pointer to function to free m_user_data (NULL at initialization)
* 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).
*/
opj_stream_free_user_data_fn m_free_user_data_fn;
/**
* Pointer to function to free m_user_data (NULL at initialization)
* 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).
*/
opj_stream_free_user_data_fn m_free_user_data_fn;
/**
* User data length
*/
OPJ_UINT64 m_user_data_length;
/**
* User data length
*/
OPJ_UINT64 m_user_data_length;
/**
* Pointer to actual read function (NULL at the initialization of the cio.
*/
opj_stream_read_fn m_read_fn;
/**
* Pointer to actual read function (NULL at the initialization of the cio.
*/
opj_stream_read_fn m_read_fn;
/**
* Pointer to actual write function (NULL at the initialization of the cio.
*/
opj_stream_write_fn m_write_fn;
/**
* Pointer to actual write function (NULL at the initialization of the cio.
*/
opj_stream_write_fn m_write_fn;
/**
* 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.
*/
opj_stream_skip_fn m_skip_fn;
/**
* 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.
*/
opj_stream_skip_fn m_skip_fn;
/**
* Pointer to actual seek function (if available).
*/
opj_stream_seek_fn m_seek_fn;
/**
* Pointer to actual seek function (if available).
*/
opj_stream_seek_fn m_seek_fn;
/**
* Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
* you should never access this data directly.
*/
OPJ_BYTE * m_stored_data;
/**
* Actual data stored into the stream if readed from. Data is read by chunk of fixed size.
* you should never access this data directly.
*/
OPJ_BYTE * m_stored_data;
/**
* Pointer to the current read data.
*/
OPJ_BYTE * m_current_data;
/**
* Pointer to the current read data.
*/
OPJ_BYTE * m_current_data;
/**
* 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.
*/
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.
*/
OPJ_SIZE_T m_bytes_in_buffer;
/**
* number of bytes containing in the buffer.
*/
OPJ_SIZE_T m_bytes_in_buffer;
/**
* The number of bytes read/written from the beginning of the stream
*/
OPJ_OFF_T m_byte_offset;
/**
* The number of bytes read/written from the beginning of the stream
*/
OPJ_OFF_T m_byte_offset;
/**
* The size of the buffer.
*/
OPJ_SIZE_T m_buffer_size;
/**
* The size of the buffer.
*/
OPJ_SIZE_T m_buffer_size;
/**
* Flags to tell the status of the stream.
* Used with OPJ_STREAM_STATUS_* defines.
*/
OPJ_UINT32 m_status;
/**
* Flags to tell the status of the stream.
* Used with OPJ_STREAM_STATUS_* defines.
*/
OPJ_UINT32 m_status;
}
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* 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);
/**
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.
@param tilec Tile component information (current tile)
*/
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.
@param tilec Tile component information (current tile)
@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);
/**
Explicit calculation of the Quantization Stepsizes
Explicit calculation of the Quantization Stepsizes
@param tccp Tile-component coding parameters
@param prec Precint analyzed
*/

View File

@ -1,11 +1,11 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* 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
* All rights reserved.
*
@ -40,14 +40,15 @@
#ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32
static char*
i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
i2a(unsigned i, char *a, unsigned r)
{
if (i/r > 0) a = i2a(i/r,a,r);
*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.
@param i Number to be converted
@param a String result
@ -55,14 +56,14 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a
*/
static char *
_itoa(int i, char *a, int r) {
r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) {
*a = '-';
*i2a(-i, a+1, r) = 0;
}
else *i2a(i, a, r) = 0;
return a;
_itoa(int i, char *a, int r)
{
r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) {
*a = '-';
*i2a(-i, a+1, r) = 0;
} else *i2a(i, a, r) = 0;
return a;
}
#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 */
opj_msg_callback msg_handler = 00;
void * l_data = 00;
opj_msg_callback msg_handler = 00;
void * l_data = 00;
if(p_event_mgr != 00) {
switch(event_type) {
case EVT_ERROR:
msg_handler = p_event_mgr->error_handler;
l_data = p_event_mgr->m_error_data;
break;
case EVT_WARNING:
msg_handler = p_event_mgr->warning_handler;
l_data = p_event_mgr->m_warning_data;
break;
case EVT_INFO:
msg_handler = p_event_mgr->info_handler;
l_data = p_event_mgr->m_info_data;
break;
default:
break;
}
if(msg_handler == 00) {
return OPJ_FALSE;
}
} else {
return OPJ_FALSE;
}
if(p_event_mgr != 00) {
switch(event_type) {
case EVT_ERROR:
msg_handler = p_event_mgr->error_handler;
l_data = p_event_mgr->m_error_data;
break;
case EVT_WARNING:
msg_handler = p_event_mgr->warning_handler;
l_data = p_event_mgr->m_warning_data;
break;
case EVT_INFO:
msg_handler = p_event_mgr->info_handler;
l_data = p_event_mgr->m_info_data;
break;
default:
break;
}
if(msg_handler == 00) {
return OPJ_FALSE;
}
} else {
return OPJ_FALSE;
}
if ((fmt != 00) && (p_event_mgr != 00)) {
va_list arg;
size_t str_length/*, i, j*/; /* UniPG */
char message[OPJ_MSG_SIZE];
memset(message, 0, OPJ_MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
if ((fmt != 00) && (p_event_mgr != 00)) {
va_list arg;
size_t str_length/*, i, j*/; /* UniPG */
char message[OPJ_MSG_SIZE];
memset(message, 0, OPJ_MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
(void)str_length;
/* parse the format string and put the result in 'message' */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */
va_end(arg);
/* parse the format string and put the result in 'message' */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */
va_end(arg);
/* output the message to the user program */
msg_handler(message, l_data);
}
/* output the message to the user program */
msg_handler(message, l_data);
}
return OPJ_TRUE;
return OPJ_TRUE;
}
void opj_set_default_event_handler(opj_event_mgr_t * p_manager)
{
p_manager->m_error_data = 00;
p_manager->m_warning_data = 00;
p_manager->m_info_data = 00;
p_manager->error_handler = opj_default_callback;
p_manager->info_handler = opj_default_callback;
p_manager->warning_handler = opj_default_callback;
p_manager->m_error_data = 00;
p_manager->m_warning_data = 00;
p_manager->m_info_data = 00;
p_manager->error_handler = opj_default_callback;
p_manager->info_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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* 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
* All rights reserved.
*
@ -40,27 +40,26 @@ The functions in EVENT.C have for goal to send output messages (errors, warnings
*/
/**
Message handler object
used for
used for
<ul>
<li>Error messages
<li>Warning messages
<li>Debugging messages
</ul>
*/
typedef struct opj_event_mgr
{
/** Data to call the event manager upon */
void * m_error_data;
/** Data to call the event manager upon */
void * m_warning_data;
/** Data to call the event manager upon */
void * m_info_data;
/** Error message callback if available, NULL otherwise */
opj_msg_callback error_handler;
/** Warning message callback if available, NULL otherwise */
opj_msg_callback warning_handler;
/** Debug message callback if available, NULL otherwise */
opj_msg_callback info_handler;
typedef struct opj_event_mgr {
/** Data to call the event manager upon */
void * m_error_data;
/** Data to call the event manager upon */
void * m_warning_data;
/** Data to call the event manager upon */
void * m_info_data;
/** Error message callback if available, NULL otherwise */
opj_msg_callback error_handler;
/** Warning message callback if available, NULL otherwise */
opj_msg_callback warning_handler;
/** Debug message callback if available, NULL otherwise */
opj_msg_callback info_handler;
} opj_event_mgr_t;

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -38,80 +38,72 @@
opj_procedure_list_t * opj_procedure_list_create()
{
/* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation)
{
return 00;
}
/* initialization */
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures)
{
opj_free(l_validation);
return 00;
}
return l_validation;
/* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation) {
return 00;
}
/* initialization */
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures) {
opj_free(l_validation);
return 00;
}
return l_validation;
}
void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{
if (! p_list)
{
return;
}
/* initialization */
if (p_list->m_procedures)
{
opj_free(p_list->m_procedures);
}
opj_free(p_list);
if (! p_list) {
return;
}
/* initialization */
if (p_list->m_procedures) {
opj_free(p_list->m_procedures);
}
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 )
{
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;
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures)
{
opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
return OPJ_FALSE;
}
else
{
p_validation_list->m_procedures = new_procedures;
}
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;
new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures) {
opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
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)
{
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)
{
return p_validation_list->m_procedures;
return p_validation_list->m_procedures;
}
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -32,7 +32,7 @@
#ifndef __FUNCTION_LIST_H
#define __FUNCTION_LIST_H
/**
/**
* @file function_list.h
* @brief Implementation of a list of procedures.
@ -54,20 +54,19 @@ typedef void (*opj_procedure)(void);
/**
* A list of procedures.
*/
typedef struct opj_procedure_list
{
/**
* The number of validation procedures.
*/
OPJ_UINT32 m_nb_procedures;
/**
* The number of the array of validation procedures.
*/
OPJ_UINT32 m_nb_max_procedures;
/**
* The array of procedures.
*/
opj_procedure * m_procedures;
typedef struct opj_procedure_list {
/**
* The number of validation procedures.
*/
OPJ_UINT32 m_nb_procedures;
/**
* The number of the array of validation procedures.
*/
OPJ_UINT32 m_nb_max_procedures;
/**
* The array of procedures.
*/
opj_procedure * m_procedures;
} opj_procedure_list_t;

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -31,73 +31,76 @@
#include "opj_includes.h"
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* opj_image_create0(void)
{
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_UINT32 compno;
opj_image_t *image = NULL;
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;
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
if(image) {
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image);
return NULL;
}
/* 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->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
if(!comp->data) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image);
return NULL;
}
}
}
image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
if(image) {
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image);
return NULL;
}
/* 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->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
comp->data = (OPJ_INT32*) opj_calloc(comp->w * comp->h, sizeof(OPJ_INT32));
if(!comp->data) {
/* TODO replace with event manager, breaks API */
/* fprintf(stderr,"Unable to allocate memory for image.\n"); */
opj_image_destroy(image);
return NULL;
}
}
}
return image;
return image;
}
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) {
if(image) {
if(image->comps) {
OPJ_UINT32 compno;
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
{
if(image) {
if(image->comps) {
OPJ_UINT32 compno;
/* image components */
for(compno = 0; compno < image->numcomps; compno++) {
opj_image_comp_t *image_comp = &(image->comps[compno]);
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(image->comps);
}
/* image components */
for(compno = 0; compno < image->numcomps; compno++) {
opj_image_comp_t *image_comp = &(image->comps[compno]);
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(image->comps);
}
if(image->icc_profile_buf) {
opj_free(image->icc_profile_buf);
}
if(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)
{
OPJ_UINT32 i, l_width, l_height;
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_image_comp_t* l_img_comp = NULL;
OPJ_UINT32 i, l_width, l_height;
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_image_comp_t* l_img_comp = NULL;
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_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_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_x0 = opj_uint_max(p_cp->tx0 , p_image_header->x0);
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_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_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;
for (i = 0; i < p_image_header->numcomps; ++i) {
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_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx);
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_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_img_comp->w = l_width;
l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0;
l_img_comp->y0 = l_comp_y0;
++l_img_comp;
}
l_img_comp = p_image_header->comps;
for (i = 0; i < p_image_header->numcomps; ++i) {
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_x1 = opj_uint_ceildiv(l_x1, l_img_comp->dx);
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_height = opj_uint_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_img_comp->w = l_width;
l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0;
l_img_comp->y0 = l_comp_y0;
++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)
{
OPJ_UINT32 compno;
OPJ_UINT32 compno;
/* preconditions */
assert(p_image_src != 00);
assert(p_image_dest != 00);
/* preconditions */
assert(p_image_src != 00);
assert(p_image_dest != 00);
p_image_dest->x0 = p_image_src->x0;
p_image_dest->y0 = p_image_src->y0;
p_image_dest->x1 = p_image_src->x1;
p_image_dest->y1 = p_image_src->y1;
p_image_dest->x0 = p_image_src->x0;
p_image_dest->y0 = p_image_src->y0;
p_image_dest->x1 = p_image_src->x1;
p_image_dest->y1 = p_image_src->y1;
if (p_image_dest->comps){
for(compno = 0; compno < p_image_dest->numcomps; compno++) {
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(p_image_dest->comps);
p_image_dest->comps = NULL;
}
if (p_image_dest->comps) {
for(compno = 0; compno < p_image_dest->numcomps; compno++) {
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
if(image_comp->data) {
opj_free(image_comp->data);
}
}
opj_free(p_image_dest->comps);
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));
if (!p_image_dest->comps){
p_image_dest->comps = NULL;
p_image_dest->numcomps = 0;
return;
}
p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
if (!p_image_dest->comps) {
p_image_dest->comps = NULL;
p_image_dest->numcomps = 0;
return;
}
for (compno=0; compno < p_image_dest->numcomps; compno++){
memcpy( &(p_image_dest->comps[compno]),
&(p_image_src->comps[compno]),
sizeof(opj_image_comp_t));
p_image_dest->comps[compno].data = NULL;
}
for (compno=0; compno < p_image_dest->numcomps; compno++) {
memcpy( &(p_image_dest->comps[compno]),
&(p_image_src->comps[compno]),
sizeof(opj_image_comp_t));
p_image_dest->comps[compno].data = NULL;
}
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->color_space = p_image_src->color_space;
p_image_dest->icc_profile_len = p_image_src->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);
if (!p_image_dest->icc_profile_buf){
p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_len = 0;
return;
}
memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf,
p_image_src->icc_profile_len);
}
else
p_image_dest->icc_profile_buf = NULL;
if (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) {
p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_len = 0;
return;
}
memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf,
p_image_src->icc_profile_len);
} else
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_UINT32 compno;
opj_image_t *image = 00;
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;
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
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;
}
}
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image) {
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*

View File

@ -56,7 +56,7 @@
#define JPIP_PHLD 0x70686c64 /* Place holder */
/*
/*
* Write tile-part Index table box (superbox)
*
* @param[in] coff offset of j2k codestream
@ -66,10 +66,10 @@
* @return length of tpix box
*/
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)
*
* @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 );
/*
/*
* Write precinct packet index table box (superbox)
*
* @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
*/
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)
*
* @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
*/
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)
*
* @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
*/
void opj_write_manf(int second,
int v,
opj_jp2_box_t *box,
void opj_write_manf(int second,
int v,
opj_jp2_box_t *box,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager );
/*
/*
* Write main header index table (box)
*
* @param[in] coff offset of j2k codestream
@ -131,18 +131,18 @@ void opj_write_manf(int second,
* @return length of mainmhix box
*/
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,
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,
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,
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,
opj_event_mgr_t * p_manager );
opj_event_mgr_t * p_manager );
#endif /* !INDEXBOX_MANAGER_H_ */

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -31,24 +31,24 @@
#include "opj_includes.h"
/**
/**
* LUP decomposition
*/
static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,
OPJ_UINT32 * permutations,
OPJ_UINT32 * permutations,
OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo);
/**
/**
* LUP solving
*/
static void opj_lupSolve(OPJ_FLOAT32 * pResult,
OPJ_FLOAT32* pMatrix,
OPJ_FLOAT32* pVector,
OPJ_UINT32* pPermutations,
static void opj_lupSolve(OPJ_FLOAT32 * pResult,
OPJ_FLOAT32* pMatrix,
OPJ_FLOAT32* pVector,
OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo,
OPJ_FLOAT32 * p_intermediate_data);
/**
/**
*LUP inversion (call with the result of lupDecompose)
*/
static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
@ -68,32 +68,32 @@ static void opj_lupInvert ( OPJ_FLOAT32 * pSrcMatrix,
* Matrix inversion.
*/
OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix,
OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo)
{
OPJ_BYTE * l_data = 00;
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_total_size = l_permutation_size + 3 * l_swap_size;
OPJ_UINT32 * lPermutations = 00;
OPJ_FLOAT32 * l_double_data = 00;
OPJ_BYTE * l_data = 00;
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_total_size = l_permutation_size + 3 * l_swap_size;
OPJ_UINT32 * lPermutations = 00;
OPJ_FLOAT32 * l_double_data = 00;
l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
if (l_data == 0) {
return OPJ_FALSE;
}
lPermutations = (OPJ_UINT32 *) l_data;
l_double_data = (OPJ_FLOAT32 *) (l_data + l_permutation_size);
memset(lPermutations,0,l_permutation_size);
l_data = (OPJ_BYTE *) opj_malloc(l_total_size);
if (l_data == 0) {
return OPJ_FALSE;
}
lPermutations = (OPJ_UINT32 *) l_data;
l_double_data = (OPJ_FLOAT32 *) (l_data + 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_free(l_data);
opj_free(l_data);
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,
OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo)
OPJ_FLOAT32 * p_swap_area,
OPJ_UINT32 nb_compo)
{
OPJ_UINT32 * tmpPermutations = permutations;
OPJ_UINT32 * dstPermutations;
OPJ_UINT32 k2=0,t;
OPJ_FLOAT32 temp;
OPJ_UINT32 i,j,k;
OPJ_FLOAT32 p;
OPJ_UINT32 lLastColum = nb_compo - 1;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpMatrix = matrix;
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
OPJ_UINT32 offset = 1;
OPJ_UINT32 lStride = nb_compo-1;
OPJ_UINT32 * tmpPermutations = permutations;
OPJ_UINT32 * dstPermutations;
OPJ_UINT32 k2=0,t;
OPJ_FLOAT32 temp;
OPJ_UINT32 i,j,k;
OPJ_FLOAT32 p;
OPJ_UINT32 lLastColum = nb_compo - 1;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpMatrix = matrix;
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
OPJ_UINT32 offset = 1;
OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */
for (i = 0; i < nb_compo; ++i)
{
*tmpPermutations++ = i;
}
/* now make a pivot with column switch */
tmpPermutations = permutations;
for (k = 0; k < lLastColum; ++k) {
p = 0.0;
/*initialize permutations */
for (i = 0; i < nb_compo; ++i) {
*tmpPermutations++ = i;
}
/* now make a pivot with column switch */
tmpPermutations = permutations;
for (k = 0; k < lLastColum; ++k) {
p = 0.0;
/* take the middle element */
lColumnMatrix = lTmpMatrix + k;
/* make permutation with the biggest value in the column */
/* take the middle element */
lColumnMatrix = lTmpMatrix + k;
/* make permutation with the biggest value in the column */
for (i = k; i < nb_compo; ++i) {
temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix));
if (temp > p) {
p = temp;
k2 = i;
}
/* next line */
lColumnMatrix += nb_compo;
}
temp = ((*lColumnMatrix > 0) ? *lColumnMatrix : -(*lColumnMatrix));
if (temp > p) {
p = temp;
k2 = i;
}
/* next line */
lColumnMatrix += nb_compo;
}
/* a whole rest of 0 -> non singular */
if (p == 0.0) {
return OPJ_FALSE;
}
/* a whole rest of 0 -> non singular */
if (p == 0.0) {
return OPJ_FALSE;
}
/* should we permute ? */
if (k2 != k) {
/*exchange of line */
/* k2 > k */
dstPermutations = tmpPermutations + k2 - k;
/* swap indices */
t = *tmpPermutations;
*tmpPermutations = *dstPermutations;
*dstPermutations = t;
/* should we permute ? */
if (k2 != k) {
/*exchange of line */
/* k2 > k */
dstPermutations = tmpPermutations + k2 - k;
/* swap indices */
t = *tmpPermutations;
*tmpPermutations = *dstPermutations;
*dstPermutations = t;
/* and swap entire line. */
lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo;
memcpy(p_swap_area,lColumnMatrix,lSwapSize);
memcpy(lColumnMatrix,lTmpMatrix,lSwapSize);
memcpy(lTmpMatrix,p_swap_area,lSwapSize);
}
/* and swap entire line. */
lColumnMatrix = lTmpMatrix + (k2 - k) * nb_compo;
memcpy(p_swap_area,lColumnMatrix,lSwapSize);
memcpy(lColumnMatrix,lTmpMatrix,lSwapSize);
memcpy(lTmpMatrix,p_swap_area,lSwapSize);
}
/* now update data in the rest of the line and line after */
lDestMatrix = lTmpMatrix + k;
lColumnMatrix = lDestMatrix + nb_compo;
/* take the middle element */
temp = *(lDestMatrix++);
/* now update data in the rest of the line and line after */
lDestMatrix = lTmpMatrix + k;
lColumnMatrix = lDestMatrix + nb_compo;
/* take the middle element */
temp = *(lDestMatrix++);
/* now compute up data (i.e. coeff up of the diagonal). */
for (i = offset; i < nb_compo; ++i) {
/*lColumnMatrix; */
/* divide the lower column elements by the diagonal value */
/* now compute up data (i.e. coeff up of the diagonal). */
for (i = offset; i < nb_compo; ++i) {
/*lColumnMatrix; */
/* 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) {
/* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */
*(lColumnMatrix++) -= p * (*(lDestMatrix++));
}
/* come back to the k+1th element */
lDestMatrix -= lStride;
/* go to kth element of the next line */
lColumnMatrix += k;
}
/* matrix[i][j] -= matrix[i][k] * matrix[k][j]; */
*(lColumnMatrix++) -= p * (*(lDestMatrix++));
}
/* come back to the k+1th element */
lDestMatrix -= lStride;
/* go to kth element of the next line */
lColumnMatrix += k;
}
/* offset is now k+2 */
++offset;
/* 1 element less for stride */
--lStride;
/* next line */
lTmpMatrix+=nb_compo;
/* next permutation element */
++tmpPermutations;
}
/* offset is now k+2 */
++offset;
/* 1 element less for stride */
--lStride;
/* next line */
lTmpMatrix+=nb_compo;
/* next permutation element */
++tmpPermutations;
}
return OPJ_TRUE;
}
static void opj_lupSolve (OPJ_FLOAT32 * pResult,
OPJ_FLOAT32 * pMatrix,
OPJ_FLOAT32 * pVector,
OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data)
OPJ_FLOAT32 * pMatrix,
OPJ_FLOAT32 * pVector,
OPJ_UINT32* pPermutations,
OPJ_UINT32 nb_compo,OPJ_FLOAT32 * p_intermediate_data)
{
OPJ_INT32 k;
OPJ_INT32 k;
OPJ_UINT32 i,j;
OPJ_FLOAT32 sum;
OPJ_FLOAT32 u;
OPJ_FLOAT32 sum;
OPJ_FLOAT32 u;
OPJ_UINT32 lStride = nb_compo+1;
OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lIntermediatePtr;
OPJ_FLOAT32 * lDestPtr;
OPJ_FLOAT32 * lTmpMatrix;
OPJ_FLOAT32 * lLineMatrix = pMatrix;
OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1;
OPJ_FLOAT32 * lGeneratedData;
OPJ_UINT32 * lCurrentPermutationPtr = pPermutations;
OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lIntermediatePtr;
OPJ_FLOAT32 * lDestPtr;
OPJ_FLOAT32 * lTmpMatrix;
OPJ_FLOAT32 * lLineMatrix = pMatrix;
OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1;
OPJ_FLOAT32 * lGeneratedData;
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) {
sum = 0.0;
lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j)
{
/* sum += matrix[i][j-1] * y[j-1]; */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
sum = 0.0;
lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j) {
/* sum += matrix[i][j-1] * y[j-1]; */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}
/*y[i] = pVector[pPermutations[i]] - sum; */
/*y[i] = pVector[pPermutations[i]] - sum; */
*(lIntermediatePtr++) = pVector[*(lCurrentPermutationPtr++)] - sum;
lLineMatrix += nb_compo;
}
lLineMatrix += nb_compo;
}
/* we take the last point of the matrix */
lLineMatrix = pMatrix + nb_compo*nb_compo - 1;
/* we take the last point of the matrix */
lLineMatrix = pMatrix + nb_compo*nb_compo - 1;
/* and we take after the last point of the destination vector */
lDestPtr = pResult + nb_compo;
/* and we take after the last point of the destination vector */
lDestPtr = pResult + nb_compo;
assert(nb_compo != 0);
for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) {
sum = 0.0;
lTmpMatrix = lLineMatrix;
for (k = (OPJ_INT32)nb_compo - 1; k != -1 ; --k) {
sum = 0.0;
lTmpMatrix = lLineMatrix;
u = *(lTmpMatrix++);
lCurrentPtr = lDestPtr--;
lCurrentPtr = lDestPtr--;
for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) {
/* sum += matrix[k][j] * x[j] */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}
/*x[k] = (y[k] - sum) / u; */
/* sum += matrix[k][j] * x[j] */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}
/*x[k] = (y[k] - sum) / u; */
*(lBeginPtr--) = (*(lGeneratedData--) - sum) / u;
lLineMatrix -= lStride;
}
}
static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo,
OPJ_UINT32 * pPermutations,
OPJ_FLOAT32 * p_src_temp,
OPJ_FLOAT32 * p_dest_temp,
OPJ_FLOAT32 * p_swap_area )
{
OPJ_UINT32 j,i;
OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
for (j = 0; j < nb_compo; ++j) {
lCurrentPtr = lLineMatrix++;
memset(p_src_temp,0,lSwapSize);
p_src_temp[j] = 1.0;
opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area);
for (i = 0; i < nb_compo; ++i) {
*(lCurrentPtr) = p_dest_temp[i];
lCurrentPtr+=nb_compo;
}
lLineMatrix -= lStride;
}
}
static void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_FLOAT32 * pDestMatrix,
OPJ_UINT32 nb_compo,
OPJ_UINT32 * pPermutations,
OPJ_FLOAT32 * p_src_temp,
OPJ_FLOAT32 * p_dest_temp,
OPJ_FLOAT32 * p_swap_area )
{
OPJ_UINT32 j,i;
OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
for (j = 0; j < nb_compo; ++j) {
lCurrentPtr = lLineMatrix++;
memset(p_src_temp,0,lSwapSize);
p_src_temp[j] = 1.0;
opj_lupSolve(p_dest_temp,pSrcMatrix,p_src_temp, pPermutations, nb_compo , p_swap_area);
for (i = 0; i < nb_compo; ++i) {
*(lCurrentPtr) = p_dest_temp[i];
lCurrentPtr+=nb_compo;
}
}
}

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* 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.
*
* @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
* @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_FLOAT32 * pDestMatrix,
OPJ_FLOAT32 * pDestMatrix,
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,12 +8,12 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan
* 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
*
* 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>> */
#ifdef USE_JPWL
#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_ESD 0xff67 /**< ESD 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_RED 0xff69 /**< RED marker value (Part 11: JPEG 2000 for Wireless) */
#endif /* USE_JPWL */
#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.
* */
typedef enum J2K_STATUS {
J2K_STATE_NONE = 0x0000, /**< 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_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_TPH = 0x0010, /**< the decoding process is in a tile part header */
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_NONE = 0x0000, /**< 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_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_TPH = 0x0010, /**< the decoding process is in a tile part header */
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_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_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_STATUS;
/**
* Type of elements storing in the MCT data
*/
typedef enum MCT_ELEMENT_TYPE
{
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
typedef enum MCT_ELEMENT_TYPE {
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
MCT_TYPE_DOUBLE = 3 /** MCT data is stored as doubles*/
} J2K_MCT_ELEMENT_TYPE;
/**
* Type of MCT array
*/
typedef enum MCT_ARRAY_TYPE
{
MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_OFFSET = 2
typedef enum MCT_ARRAY_TYPE {
MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_OFFSET = 2
} J2K_MCT_ARRAY_TYPE;
/* ----------------------------------------------------------------------- */
/**
T2 encoding mode
/**
T2 encoding mode
*/
typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE;
THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/
} J2K_T2_MODE;
/**
* Quantization stepsize
*/
typedef struct opj_stepsize {
/** exponent */
OPJ_INT32 expn;
/** mantissa */
OPJ_INT32 mant;
/** exponent */
OPJ_INT32 expn;
/** mantissa */
OPJ_INT32 mant;
} opj_stepsize_t;
/**
Tile-component coding parameters
*/
typedef struct opj_tccp
{
/** coding style */
OPJ_UINT32 csty;
/** number of resolutions */
OPJ_UINT32 numresolutions;
/** code-blocks width */
OPJ_UINT32 cblkw;
/** code-blocks height */
OPJ_UINT32 cblkh;
/** code-block coding style */
OPJ_UINT32 cblksty;
/** discrete wavelet transform identifier */
OPJ_UINT32 qmfbid;
/** quantisation style */
OPJ_UINT32 qntsty;
/** stepsizes used for quantization */
opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS];
/** number of guard bits */
OPJ_UINT32 numgbits;
/** Region Of Interest shift */
OPJ_INT32 roishift;
/** precinct width */
OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
/** precinct height */
OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
/** the dc_level_shift **/
OPJ_INT32 m_dc_level_shift;
typedef struct opj_tccp {
/** coding style */
OPJ_UINT32 csty;
/** number of resolutions */
OPJ_UINT32 numresolutions;
/** code-blocks width */
OPJ_UINT32 cblkw;
/** code-blocks height */
OPJ_UINT32 cblkh;
/** code-block coding style */
OPJ_UINT32 cblksty;
/** discrete wavelet transform identifier */
OPJ_UINT32 qmfbid;
/** quantisation style */
OPJ_UINT32 qntsty;
/** stepsizes used for quantization */
opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS];
/** number of guard bits */
OPJ_UINT32 numgbits;
/** Region Of Interest shift */
OPJ_INT32 roishift;
/** precinct width */
OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
/** precinct height */
OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
/** the dc_level_shift **/
OPJ_INT32 m_dc_level_shift;
}
opj_tccp_t;
@ -209,33 +206,30 @@ opj_tccp_t;
/**
* FIXME DOC
*/
typedef struct opj_mct_data
{
J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ARRAY_TYPE m_array_type;
OPJ_UINT32 m_index;
OPJ_BYTE * m_data;
OPJ_UINT32 m_data_size;
typedef struct opj_mct_data {
J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ARRAY_TYPE m_array_type;
OPJ_UINT32 m_index;
OPJ_BYTE * m_data;
OPJ_UINT32 m_data_size;
}
opj_mct_data_t;
/**
* FIXME DOC
*/
typedef struct opj_simple_mcc_decorrelation_data
{
OPJ_UINT32 m_index;
OPJ_UINT32 m_nb_comps;
opj_mct_data_t * m_decorrelation_array;
opj_mct_data_t * m_offset_array;
OPJ_UINT32 m_is_irreversible : 1;
typedef struct opj_simple_mcc_decorrelation_data {
OPJ_UINT32 m_index;
OPJ_UINT32 m_nb_comps;
opj_mct_data_t * m_decorrelation_array;
opj_mct_data_t * m_offset_array;
OPJ_UINT32 m_is_irreversible : 1;
}
opj_simple_mcc_decorrelation_data_t;
typedef struct opj_ppx_struct
{
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_UINT32 m_data_size;
typedef struct opj_ppx_struct {
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_UINT32 m_data_size;
} opj_ppx;
/**
@ -243,106 +237,103 @@ Tile coding parameters :
this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header)
*/
typedef struct opj_tcp
{
/** coding style */
OPJ_UINT32 csty;
/** progression order */
OPJ_PROG_ORDER prg;
/** number of layers */
OPJ_UINT32 numlayers;
OPJ_UINT32 num_layers_to_decode;
/** multi-component transform identifier */
OPJ_UINT32 mct;
/** rates of layers */
OPJ_FLOAT32 rates[100];
/** number of progression order changes */
OPJ_UINT32 numpocs;
/** progression order changes */
opj_poc_t pocs[32];
/** number of ppt markers (reserved size) */
OPJ_UINT32 ppt_markers_count;
/** ppt markers data (table indexed by Zppt) */
opj_ppx* ppt_markers;
/** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppt_data;
/** used to keep a track of the allocated memory */
OPJ_BYTE *ppt_buffer;
/** Number of bytes stored inside ppt_data*/
OPJ_UINT32 ppt_data_size;
/** size of ppt_data*/
OPJ_UINT32 ppt_len;
/** add fixed_quality */
OPJ_FLOAT32 distoratio[100];
/** tile-component coding parameters */
opj_tccp_t *tccps;
/** number of tile parts for the tile. */
OPJ_UINT32 m_nb_tile_parts;
/** data for the tile */
OPJ_BYTE * m_data;
/** size of data */
OPJ_UINT32 m_data_size;
/** encoding norms */
OPJ_FLOAT64 * mct_norms;
/** the mct decoding matrix */
OPJ_FLOAT32 * m_mct_decoding_matrix;
/** the mct coding matrix */
OPJ_FLOAT32 * m_mct_coding_matrix;
/** mct records */
opj_mct_data_t * m_mct_records;
/** the number of mct records. */
OPJ_UINT32 m_nb_mct_records;
/** the max number of mct records. */
OPJ_UINT32 m_nb_max_mct_records;
/** mcc records */
opj_simple_mcc_decorrelation_data_t * m_mcc_records;
/** the number of mct records. */
OPJ_UINT32 m_nb_mcc_records;
/** the max number of mct records. */
OPJ_UINT32 m_nb_max_mcc_records;
typedef struct opj_tcp {
/** coding style */
OPJ_UINT32 csty;
/** progression order */
OPJ_PROG_ORDER prg;
/** number of layers */
OPJ_UINT32 numlayers;
OPJ_UINT32 num_layers_to_decode;
/** multi-component transform identifier */
OPJ_UINT32 mct;
/** rates of layers */
OPJ_FLOAT32 rates[100];
/** number of progression order changes */
OPJ_UINT32 numpocs;
/** progression order changes */
opj_poc_t pocs[32];
/** number of ppt markers (reserved size) */
OPJ_UINT32 ppt_markers_count;
/** ppt markers data (table indexed by Zppt) */
opj_ppx* ppt_markers;
/** packet header store there for future use in t2_decode_packet */
OPJ_BYTE *ppt_data;
/** used to keep a track of the allocated memory */
OPJ_BYTE *ppt_buffer;
/** Number of bytes stored inside ppt_data*/
OPJ_UINT32 ppt_data_size;
/** size of ppt_data*/
OPJ_UINT32 ppt_len;
/** add fixed_quality */
OPJ_FLOAT32 distoratio[100];
/** tile-component coding parameters */
opj_tccp_t *tccps;
/** number of tile parts for the tile. */
OPJ_UINT32 m_nb_tile_parts;
/** data for the tile */
OPJ_BYTE * m_data;
/** size of data */
OPJ_UINT32 m_data_size;
/** encoding norms */
OPJ_FLOAT64 * mct_norms;
/** the mct decoding matrix */
OPJ_FLOAT32 * m_mct_decoding_matrix;
/** the mct coding matrix */
OPJ_FLOAT32 * m_mct_coding_matrix;
/** mct records */
opj_mct_data_t * m_mct_records;
/** the number of mct records. */
OPJ_UINT32 m_nb_mct_records;
/** the max number of mct records. */
OPJ_UINT32 m_nb_max_mct_records;
/** mcc records */
opj_simple_mcc_decorrelation_data_t * m_mcc_records;
/** the number of mct records. */
OPJ_UINT32 m_nb_mcc_records;
/** the max number of mct records. */
OPJ_UINT32 m_nb_max_mcc_records;
/***** FLAGS *******/
/** If cod == 1 --> there was a COD marker for the present tile */
OPJ_UINT32 cod : 1;
/** If ppt == 1 --> there was a PPT marker for the present tile */
OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */
OPJ_UINT32 POC : 1;
/***** FLAGS *******/
/** If cod == 1 --> there was a COD marker for the present tile */
OPJ_UINT32 cod : 1;
/** If ppt == 1 --> there was a PPT marker for the present tile */
OPJ_UINT32 ppt : 1;
/** indicates if a POC marker has been used O:NO, 1:YES */
OPJ_UINT32 POC : 1;
} opj_tcp_t;
typedef struct opj_encoding_param
{
/** Maximum rate for each component. If == 0, component size limitation is not considered */
OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/
OPJ_INT32 m_tp_pos;
/** fixed layer */
OPJ_INT32 *m_matrice;
/** Flag determining tile part generation*/
OPJ_BYTE m_tp_flag;
/** allocation by rate/distortion */
OPJ_UINT32 m_disto_alloc : 1;
/** allocation by fixed layer */
OPJ_UINT32 m_fixed_alloc : 1;
/** add fixed_quality */
OPJ_UINT32 m_fixed_quality : 1;
/** Enabling Tile part generation*/
OPJ_UINT32 m_tp_on : 1;
typedef struct opj_encoding_param {
/** Maximum rate for each component. If == 0, component size limitation is not considered */
OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/
OPJ_INT32 m_tp_pos;
/** fixed layer */
OPJ_INT32 *m_matrice;
/** Flag determining tile part generation*/
OPJ_BYTE m_tp_flag;
/** allocation by rate/distortion */
OPJ_UINT32 m_disto_alloc : 1;
/** allocation by fixed layer */
OPJ_UINT32 m_fixed_alloc : 1;
/** add fixed_quality */
OPJ_UINT32 m_fixed_quality : 1;
/** Enabling Tile part generation*/
OPJ_UINT32 m_tp_on : 1;
}
opj_encoding_param_t;
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 */
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 */
OPJ_UINT32 m_layer;
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 */
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 */
OPJ_UINT32 m_layer;
}
opj_decoding_param_t;
@ -350,199 +341,195 @@ opj_decoding_param_t;
/**
* Coding parameters
*/
typedef struct opj_cp
{
/** Size of the image in bits*/
/*int img_size;*/
/** Rsiz*/
typedef struct opj_cp {
/** Size of the image in bits*/
/*int img_size;*/
/** Rsiz*/
OPJ_UINT16 rsiz;
/** XTOsiz */
OPJ_UINT32 tx0; /* MSD see norm */
/** YTOsiz */
OPJ_UINT32 ty0; /* MSD see norm */
/** XTsiz */
OPJ_UINT32 tdx;
/** YTsiz */
OPJ_UINT32 tdy;
/** comment */
OPJ_CHAR *comment;
/** number of tiles in width */
OPJ_UINT32 tw;
/** number of tiles in heigth */
OPJ_UINT32 th;
/** XTOsiz */
OPJ_UINT32 tx0; /* MSD see norm */
/** YTOsiz */
OPJ_UINT32 ty0; /* MSD see norm */
/** XTsiz */
OPJ_UINT32 tdx;
/** YTsiz */
OPJ_UINT32 tdy;
/** comment */
OPJ_CHAR *comment;
/** number of tiles in width */
OPJ_UINT32 tw;
/** number of tiles in heigth */
OPJ_UINT32 th;
/** number of ppm markers (reserved size) */
OPJ_UINT32 ppm_markers_count;
/** ppm markers data (table indexed by Zppm) */
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;
/** number of ppm markers (reserved size) */
OPJ_UINT32 ppm_markers_count;
/** ppm markers data (table indexed by Zppm) */
opj_ppx* ppm_markers;
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_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;
OPJ_BYTE *ppm_data_current;
/** tile coding parameters */
opj_tcp_t *tcps;
/** packet header storage original buffer */
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
{
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc;
}
m_specific_param;
/** tile coding parameters */
opj_tcp_t *tcps;
union {
opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc;
}
m_specific_param;
/* UniPG>> */
/* UniPG>> */
#ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */
OPJ_BOOL epc_on;
/** enables writing of EPB, in case of activated JPWL */
OPJ_BOOL epb_on;
/** enables writing of ESD, in case of activated JPWL */
OPJ_BOOL esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */
OPJ_BOOL info_on;
/** enables writing of RED, in case of activated JPWL */
OPJ_BOOL red_on;
/** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH;
/** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */
int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr;
/** sensitivity range (0-3) */
int sens_range;
/** sensitivity method for MH (-1,0-7) */
int sens_MH;
/** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */
OPJ_BOOL correct;
/** expected number of components at the decoder */
int exp_comps;
/** maximum number of tiles at the decoder */
OPJ_UINT32 max_tiles;
/** enables writing of EPC in MH, thus activating JPWL */
OPJ_BOOL epc_on;
/** enables writing of EPB, in case of activated JPWL */
OPJ_BOOL epb_on;
/** enables writing of ESD, in case of activated JPWL */
OPJ_BOOL esd_on;
/** enables writing of informative techniques of ESD, in case of activated JPWL */
OPJ_BOOL info_on;
/** enables writing of RED, in case of activated JPWL */
OPJ_BOOL red_on;
/** error protection method for MH (0,1,16,32,37-128) */
int hprot_MH;
/** tile number of header protection specification (>=0) */
int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** error protection methods for TPHs (0,1,16,32,37-128) */
int hprot_TPH[JPWL_MAX_NO_TILESPECS];
/** tile number of packet protection specification (>=0) */
int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
/** packet number of packet protection specification (>=0) */
int pprot_packno[JPWL_MAX_NO_PACKSPECS];
/** error protection methods for packets (0,1,16,32,37-128) */
int pprot[JPWL_MAX_NO_PACKSPECS];
/** enables writing of ESD, (0/2/4 bytes) */
int sens_size;
/** sensitivity addressing size (0=auto/2/4 bytes) */
int sens_addr;
/** sensitivity range (0-3) */
int sens_range;
/** sensitivity method for MH (-1,0-7) */
int sens_MH;
/** tile number of sensitivity specification (>=0) */
int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
/** sensitivity methods for TPHs (-1,0-7) */
int sens_TPH[JPWL_MAX_NO_TILESPECS];
/** enables JPWL correction at the decoder */
OPJ_BOOL correct;
/** expected number of components at the decoder */
int exp_comps;
/** maximum number of tiles at the decoder */
OPJ_UINT32 max_tiles;
#endif /* USE_JPWL */
/******** FLAGS *********/
/** if ppm == 1 --> there was a PPM marker*/
OPJ_UINT32 ppm : 1;
/** tells if the parameter is a coding or decoding one */
OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */
/******** FLAGS *********/
/** if ppm == 1 --> there was a PPM marker*/
OPJ_UINT32 ppm : 1;
/** tells if the parameter is a coding or decoding one */
OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */
} opj_cp_t;
typedef struct opj_j2k_dec
{
/** locate in which part of the codestream the decoder is (main header, tile header, end) */
OPJ_UINT32 m_state;
/**
* store decoding parameters common to all tiles (information like COD, COC in main header)
*/
opj_tcp_t *m_default_tcp;
OPJ_BYTE *m_header_data;
OPJ_UINT32 m_header_data_size;
/** to tell the tile part length */
OPJ_UINT32 m_sot_length;
/** Only tiles index in the correct range will be decoded.*/
OPJ_UINT32 m_start_tile_x;
OPJ_UINT32 m_start_tile_y;
OPJ_UINT32 m_end_tile_x;
OPJ_UINT32 m_end_tile_y;
/**
* Decoded area set by the user
*/
OPJ_UINT32 m_DA_x0;
OPJ_UINT32 m_DA_y0;
OPJ_UINT32 m_DA_x1;
OPJ_UINT32 m_DA_y1;
typedef struct opj_j2k_dec {
/** locate in which part of the codestream the decoder is (main header, tile header, end) */
OPJ_UINT32 m_state;
/**
* store decoding parameters common to all tiles (information like COD, COC in main header)
*/
opj_tcp_t *m_default_tcp;
OPJ_BYTE *m_header_data;
OPJ_UINT32 m_header_data_size;
/** to tell the tile part length */
OPJ_UINT32 m_sot_length;
/** Only tiles index in the correct range will be decoded.*/
OPJ_UINT32 m_start_tile_x;
OPJ_UINT32 m_start_tile_y;
OPJ_UINT32 m_end_tile_x;
OPJ_UINT32 m_end_tile_y;
/**
* Decoded area set by the user
*/
OPJ_UINT32 m_DA_x0;
OPJ_UINT32 m_DA_y0;
OPJ_UINT32 m_DA_x1;
OPJ_UINT32 m_DA_y1;
/** Index of the tile to decode (used in get_tile) */
OPJ_INT32 m_tile_ind_to_dec;
/** Position of the last SOT marker read */
OPJ_OFF_T m_last_sot_read_pos;
/** Index of the tile to decode (used in get_tile) */
OPJ_INT32 m_tile_ind_to_dec;
/** Position of the last SOT marker read */
OPJ_OFF_T m_last_sot_read_pos;
/**
* 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
* SOD reader function. FIXME NOT USED for the moment
*/
OPJ_BOOL m_last_tile_part;
/** to tell that a tile can be decoded. */
OPJ_UINT32 m_can_decode : 1;
OPJ_UINT32 m_discard_tiles : 1;
OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/
OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_UINT32 m_nb_tile_parts_correction : 1;
/**
* 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
* SOD reader function. FIXME NOT USED for the moment
*/
OPJ_BOOL m_last_tile_part;
/** to tell that a tile can be decoded. */
OPJ_UINT32 m_can_decode : 1;
OPJ_UINT32 m_discard_tiles : 1;
OPJ_UINT32 m_skip_data : 1;
/** TNsot correction : see issue 254 **/
OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
OPJ_UINT32 m_nb_tile_parts_correction : 1;
} opj_j2k_dec_t;
typedef struct opj_j2k_enc
{
/** 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 */
typedef struct opj_j2k_enc {
/** 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 */
/** 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 */
/** 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 */
/**
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.
*/
/**
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.
*/
OPJ_OFF_T m_tlm_start;
/**
* Stores the sizes of the tlm.
*/
OPJ_BYTE * m_tlm_sot_offsets_buffer;
/**
* The current offset of the tlm buffer.
*/
OPJ_BYTE * m_tlm_sot_offsets_current;
/**
* Stores the sizes of the tlm.
*/
OPJ_BYTE * m_tlm_sot_offsets_buffer;
/**
* The current offset of the tlm buffer.
*/
OPJ_BYTE * m_tlm_sot_offsets_current;
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/
OPJ_UINT32 m_total_tile_parts; /* totnum_tp */
/** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/
/** used in TLMmarker*/
OPJ_UINT32 m_total_tile_parts; /* totnum_tp */
/* encoded data for a tile */
OPJ_BYTE * m_encoded_tile_data;
/* encoded data for a tile */
OPJ_BYTE * m_encoded_tile_data;
/* size of the encoded_data */
OPJ_UINT32 m_encoded_tile_size;
/* size of the encoded_data */
OPJ_UINT32 m_encoded_tile_size;
/* encoded data for a tile */
OPJ_BYTE * m_header_tile_data;
/* encoded data for a tile */
OPJ_BYTE * m_header_tile_data;
/* size of the encoded_data */
OPJ_UINT32 m_header_tile_data_size;
/* size of the encoded_data */
OPJ_UINT32 m_header_tile_data_size;
} opj_j2k_enc_t;
@ -553,42 +540,40 @@ struct opj_tcd;
/**
JPEG-2000 codestream reader/writer
*/
typedef struct opj_j2k
{
/* J2K codestream is decoded*/
OPJ_BOOL m_is_decoder;
typedef struct opj_j2k {
/* J2K codestream is decoded*/
OPJ_BOOL m_is_decoder;
/* FIXME DOC*/
union
{
opj_j2k_dec_t m_decoder;
opj_j2k_enc_t m_encoder;
}
m_specific_param;
/* FIXME DOC*/
union {
opj_j2k_dec_t m_decoder;
opj_j2k_enc_t m_encoder;
}
m_specific_param;
/** pointer to the internal/private encoded / decoded image */
opj_image_t* m_private_image;
/** pointer to the internal/private encoded / decoded image */
opj_image_t* m_private_image;
/* pointer to the output image (decoded)*/
opj_image_t* m_output_image;
/* pointer to the output image (decoded)*/
opj_image_t* m_output_image;
/** Coding parameters */
opj_cp_t m_cp;
/** Coding parameters */
opj_cp_t m_cp;
/** the list of procedures to exec **/
opj_procedure_list_t * m_procedure_list;
/** the list of procedures to exec **/
opj_procedure_list_t * m_procedure_list;
/** the list of validation procedures to follow to make sure the code is valid **/
opj_procedure_list_t * m_validation_list;
/** the list of validation procedures to follow to make sure the code is valid **/
opj_procedure_list_t * m_validation_list;
/** helper used to write the index file */
opj_codestream_index_t *cstr_index;
/** helper used to write the index file */
opj_codestream_index_t *cstr_index;
/** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number;
/** number of the tile curently concern by coding/decoding */
OPJ_UINT32 m_current_tile_number;
/** the current tile coder/decoder **/
struct opj_tcd * m_tcd;
/** the current tile coder/decoder **/
struct opj_tcd * m_tcd;
}
opj_j2k_t;
@ -601,7 +586,7 @@ opj_j2k_t;
/**
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 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_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);
/**
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.
*/
OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager );
opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager );
/**
* 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_stream_private_t *p_stream,
opj_image_t* p_image,
opj_event_mgr_t * p_manager,
OPJ_UINT32 tile_index );
opj_stream_private_t *p_stream,
opj_image_t* p_image,
opj_event_mgr_t * p_manager,
OPJ_UINT32 tile_index );
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k,
OPJ_UINT32 res_factor,
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.
*/
OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager );
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager );
/**
* Encodes an image into a JPEG-2000 codestream
*/
OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager );
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager );
/**
* 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.
*/
OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream,
opj_image_t * p_image,
opj_event_mgr_t * p_manager);
opj_stream_private_t *p_stream,
opj_image_t * p_image,
opj_event_mgr_t * p_manager);
/**
* Ends the compression procedures and possibiliy add data to be read after the
* codestream.
*/
OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager);
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager);
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2002-2003, Yannick Verschueren
* 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
* All rights reserved.
*
@ -70,56 +70,50 @@
/* ----------------------------------------------------------------------- */
typedef enum
{
JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2,
JP2_STATE_HEADER = 0x4,
JP2_STATE_CODESTREAM = 0x8,
JP2_STATE_END_CODESTREAM = 0x10,
JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
typedef enum {
JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2,
JP2_STATE_HEADER = 0x4,
JP2_STATE_CODESTREAM = 0x8,
JP2_STATE_END_CODESTREAM = 0x10,
JP2_STATE_UNKNOWN = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
}
JP2_STATE;
typedef enum
{
JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
typedef enum {
JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_UNKNOWN = 0x7fffffff
}
JP2_IMG_STATE;
/**
/**
Channel description: channel index, type, association
*/
typedef struct opj_jp2_cdef_info
{
typedef struct opj_jp2_cdef_info {
OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t;
/**
/**
Channel descriptions and number of descriptions
*/
typedef struct opj_jp2_cdef
{
typedef struct opj_jp2_cdef {
opj_jp2_cdef_info_t *info;
OPJ_UINT16 n;
} opj_jp2_cdef_t;
/**
/**
Component mappings: channel index, mapping type, palette index
*/
typedef struct opj_jp2_cmap_comp
{
typedef struct opj_jp2_cmap_comp {
OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t;
/**
/**
Palette data: table entries, palette columns
*/
typedef struct opj_jp2_pclr
{
typedef struct opj_jp2_pclr {
OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size;
@ -128,11 +122,10 @@ typedef struct opj_jp2_pclr
OPJ_BYTE nr_channels;
} 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_UINT32 icc_profile_len;
@ -141,59 +134,58 @@ typedef struct opj_jp2_color
OPJ_BYTE jp2_has_colr;
} opj_jp2_color_t;
/**
/**
JP2 component
*/
typedef struct opj_jp2_comps {
OPJ_UINT32 depth;
OPJ_UINT32 sgnd;
OPJ_UINT32 bpcc;
OPJ_UINT32 depth;
OPJ_UINT32 sgnd;
OPJ_UINT32 bpcc;
} opj_jp2_comps_t;
/**
JPEG-2000 file format reader/writer
*/
typedef struct opj_jp2
{
/** handle to the J2K codec */
opj_j2k_t *j2k;
/** list of validation procedures */
struct opj_procedure_list * m_validation_list;
/** list of execution procedures */
struct opj_procedure_list * m_procedure_list;
typedef struct opj_jp2 {
/** handle to the J2K codec */
opj_j2k_t *j2k;
/** list of validation procedures */
struct opj_procedure_list * m_validation_list;
/** list of execution procedures */
struct opj_procedure_list * m_procedure_list;
/* width of image */
OPJ_UINT32 w;
/* height of image */
OPJ_UINT32 h;
/* number of components in the image */
OPJ_UINT32 numcomps;
OPJ_UINT32 bpc;
OPJ_UINT32 C;
OPJ_UINT32 UnkC;
OPJ_UINT32 IPR;
OPJ_UINT32 meth;
OPJ_UINT32 approx;
OPJ_UINT32 enumcs;
OPJ_UINT32 precedence;
OPJ_UINT32 brand;
OPJ_UINT32 minversion;
OPJ_UINT32 numcl;
OPJ_UINT32 *cl;
opj_jp2_comps_t *comps;
/* 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 codec writers will need to extand those fields as new part
of the standard are implemented.
*/
/* width of image */
OPJ_UINT32 w;
/* height of image */
OPJ_UINT32 h;
/* number of components in the image */
OPJ_UINT32 numcomps;
OPJ_UINT32 bpc;
OPJ_UINT32 C;
OPJ_UINT32 UnkC;
OPJ_UINT32 IPR;
OPJ_UINT32 meth;
OPJ_UINT32 approx;
OPJ_UINT32 enumcs;
OPJ_UINT32 precedence;
OPJ_UINT32 brand;
OPJ_UINT32 minversion;
OPJ_UINT32 numcl;
OPJ_UINT32 *cl;
opj_jp2_comps_t *comps;
/* 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 codec writers will need to extand those fields as new part
of the standard are implemented.
*/
OPJ_OFF_T j2k_codestream_offset;
OPJ_OFF_T jpip_iptr_offset;
OPJ_BOOL jpip_on;
OPJ_UINT32 jp2_state;
OPJ_UINT32 jp2_img_state;
OPJ_BOOL jpip_on;
OPJ_UINT32 jp2_state;
OPJ_UINT32 jp2_img_state;
opj_jp2_color_t color;
opj_jp2_color_t color;
OPJ_BOOL ignore_pclr_cmap_cdef;
}
opj_jp2_t;
@ -207,28 +199,26 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos;
} opj_jp2_box_t;
typedef struct opj_jp2_header_handler
{
/* marker value */
OPJ_UINT32 id;
/* action linked to the marker */
OPJ_BOOL (*handler) ( opj_jp2_t *jp2,
OPJ_BYTE *p_header_data,
OPJ_UINT32 p_header_size,
opj_event_mgr_t * p_manager);
typedef struct opj_jp2_header_handler {
/* marker value */
OPJ_UINT32 id;
/* action linked to the marker */
OPJ_BOOL (*handler) ( opj_jp2_t *jp2,
OPJ_BYTE *p_header_data,
OPJ_UINT32 p_header_size,
opj_event_mgr_t * p_manager);
}
opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler
{
/* action to perform */
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
/* result of the action : data */
OPJ_BYTE* m_data;
/* size of data */
OPJ_UINT32 m_size;
}
typedef struct opj_jp2_img_header_writer_handler {
/* action to perform */
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
/* result of the action : data */
OPJ_BYTE* m_data;
/* size of data */
OPJ_UINT32 m_size;
}
opj_jp2_img_header_writer_handler_t;
/** @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_stream_private_t *p_stream,
opj_image_t* p_image,
opj_event_mgr_t * p_manager);
opj_image_t* p_image,
opj_event_mgr_t * p_manager);
/**
* Setup the encoder parameters using the current image and using user parameters.
* Coding parameters are returned in jp2->j2k->cp.
* Setup the encoder parameters using the current image and using user parameters.
* Coding parameters are returned in jp2->j2k->cp.
*
* @param jp2 JP2 compressor handle
* @param parameters compression parameters
@ -267,10 +257,10 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
* @param p_manager FIXME DOC
* @return OPJ_TRUE if successful, OPJ_FALSE otherwise
*/
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);
OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_cparameters_t *parameters,
opj_image_t *image,
opj_event_mgr_t * p_manager);
/**
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
@return Returns true if successful, returns false otherwise
*/
OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2,
opj_stream_private_t *stream,
opj_event_mgr_t * p_manager);
OPJ_BOOL opj_jp2_encode( opj_jp2_t *jp2,
opj_stream_private_t *stream,
opj_event_mgr_t * p_manager);
/**
@ -305,8 +295,8 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
* codestream.
*/
OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager);
opj_stream_private_t *cio,
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
* 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_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.
*/
OPJ_BOOL opj_jp2_read_header( opj_stream_private_t *p_stream,
opj_jp2_t *jp2,
opj_image_t ** p_image,
opj_event_mgr_t * p_manager );
opj_jp2_t *jp2,
opj_image_t ** p_image,
opj_event_mgr_t * p_manager );
/**
* 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.
*/
OPJ_BOOL opj_jp2_write_tile ( opj_jp2_t *p_jp2,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager );
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager );
/**
* Decode tile data.
@ -422,14 +412,14 @@ void opj_jp2_destroy(opj_jp2_t *jp2);
* @return true if the area could be set.
*/
OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager );
opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager );
/**
*
*/
/**
*
*/
OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_stream_private_t *p_stream,
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_UINT32 res_factor,
opj_event_mgr_t * p_manager);
OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
/* 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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* 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 ()
{
return opj_mct_norms;
return opj_mct_norms;
}
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
{
return opj_mct_norms_real;
return opj_mct_norms_real;
}
/* <summary> */
@ -74,67 +74,67 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
/* </summary> */
#ifdef __SSE2__
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
/* buffer are aligned on 16 bytes */
assert( ((size_t)c0 & 0xf) == 0 );
assert( ((size_t)c1 & 0xf) == 0 );
assert( ((size_t)c2 & 0xf) == 0 );
for(i = 0; i < (len & ~3U); i += 4) {
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
y = _mm_add_epi32(g, g);
y = _mm_add_epi32(y, b);
y = _mm_add_epi32(y, r);
y = _mm_srai_epi32(y, 2);
u = _mm_sub_epi32(b, g);
v = _mm_sub_epi32(r, g);
_mm_store_si128((__m128i *)&(c0[i]), y);
_mm_store_si128((__m128i *)&(c1[i]), u);
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
/* buffer are aligned on 16 bytes */
assert( ((size_t)c0 & 0xf) == 0 );
assert( ((size_t)c1 & 0xf) == 0 );
assert( ((size_t)c2 & 0xf) == 0 );
for(i = 0; i < (len & ~3U); i += 4) {
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
y = _mm_add_epi32(g, g);
y = _mm_add_epi32(y, b);
y = _mm_add_epi32(y, r);
y = _mm_srai_epi32(y, 2);
u = _mm_sub_epi32(b, g);
v = _mm_sub_epi32(r, g);
_mm_store_si128((__m128i *)&(c0[i]), y);
_mm_store_si128((__m128i *)&(c1[i]), u);
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#else
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#endif
@ -143,66 +143,67 @@ void opj_mct_encode(
/* </summary> */
#ifdef __SSE2__
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < (len & ~3U); i += 4) {
__m128i r, g, b;
__m128i y = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i u = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i v = _mm_load_si128((const __m128i *)&(c2[i]));
g = y;
g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2));
r = _mm_add_epi32(v, g);
b = _mm_add_epi32(u, g);
_mm_store_si128((__m128i *)&(c0[i]), r);
_mm_store_si128((__m128i *)&(c1[i]), g);
_mm_store_si128((__m128i *)&(c2[i]), b);
}
for (; i < len; ++i) {
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
for(i = 0; i < (len & ~3U); i += 4) {
__m128i r, g, b;
__m128i y = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i u = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i v = _mm_load_si128((const __m128i *)&(c2[i]));
g = y;
g = _mm_sub_epi32(g, _mm_srai_epi32(_mm_add_epi32(u, v), 2));
r = _mm_add_epi32(v, g);
b = _mm_add_epi32(u, g);
_mm_store_si128((__m128i *)&(c0[i]), r);
_mm_store_si128((__m128i *)&(c1[i]), g);
_mm_store_si128((__m128i *)&(c2[i]), b);
}
for (; i < len; ++i) {
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
#else
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
for (i = 0; i < n; ++i) {
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
OPJ_UINT32 i;
for (i = 0; i < n; ++i) {
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
#endif
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
return opj_mct_norms[compno];
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
{
return opj_mct_norms[compno];
}
/* <summary> */
@ -210,164 +211,164 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
/* </summary> */
#ifdef __SSE4_1__
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
const __m128i ry = _mm_set1_epi32(2449);
const __m128i gy = _mm_set1_epi32(4809);
const __m128i by = _mm_set1_epi32(934);
const __m128i ru = _mm_set1_epi32(1382);
const __m128i gu = _mm_set1_epi32(2714);
/* const __m128i bu = _mm_set1_epi32(4096); */
/* const __m128i rv = _mm_set1_epi32(4096); */
const __m128i gv = _mm_set1_epi32(3430);
const __m128i bv = _mm_set1_epi32(666);
const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0));
for(i = 0; i < (len & ~3U); i += 4) {
__m128i lo, hi;
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ry);
hi = _mm_mul_epi32(hi, ry);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gy);
hi = _mm_mul_epi32(hi, gy);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, by);
hi = _mm_mul_epi32(hi, by);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c0[i]), y);
/*lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
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)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_blend_epi16(lo, hi, 0xCC);
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ru);
hi = _mm_mul_epi32(hi, ru);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gu);
hi = _mm_mul_epi32(hi, gu);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c1[i]), u);
/*lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
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)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gv);
hi = _mm_mul_epi32(hi, gv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, bv);
hi = _mm_mul_epi32(hi, bv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[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 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);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
OPJ_SIZE_T i;
const OPJ_SIZE_T len = n;
const __m128i ry = _mm_set1_epi32(2449);
const __m128i gy = _mm_set1_epi32(4809);
const __m128i by = _mm_set1_epi32(934);
const __m128i ru = _mm_set1_epi32(1382);
const __m128i gu = _mm_set1_epi32(2714);
/* const __m128i bu = _mm_set1_epi32(4096); */
/* const __m128i rv = _mm_set1_epi32(4096); */
const __m128i gv = _mm_set1_epi32(3430);
const __m128i bv = _mm_set1_epi32(666);
const __m128i mulround = _mm_shuffle_epi32(_mm_cvtsi32_si128(4096), _MM_SHUFFLE(1, 0, 1, 0));
for(i = 0; i < (len & ~3U); i += 4) {
__m128i lo, hi;
__m128i y, u, v;
__m128i r = _mm_load_si128((const __m128i *)&(c0[i]));
__m128i g = _mm_load_si128((const __m128i *)&(c1[i]));
__m128i b = _mm_load_si128((const __m128i *)&(c2[i]));
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ry);
hi = _mm_mul_epi32(hi, ry);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gy);
hi = _mm_mul_epi32(hi, gy);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, by);
hi = _mm_mul_epi32(hi, by);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
y = _mm_add_epi32(y, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c0[i]), y);
/*lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
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)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_blend_epi16(lo, hi, 0xCC);
lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, ru);
hi = _mm_mul_epi32(hi, ru);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gu);
hi = _mm_mul_epi32(hi, gu);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
u = _mm_sub_epi32(u, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c1[i]), u);
/*lo = r;
hi = _mm_shuffle_epi32(r, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, mulround);
hi = _mm_mul_epi32(hi, mulround);*/
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)));
lo = _mm_slli_epi64(lo, 12);
hi = _mm_slli_epi64(hi, 12);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_blend_epi16(lo, hi, 0xCC);
lo = g;
hi = _mm_shuffle_epi32(g, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, gv);
hi = _mm_mul_epi32(hi, gv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
lo = b;
hi = _mm_shuffle_epi32(b, _MM_SHUFFLE(3, 3, 1, 1));
lo = _mm_mul_epi32(lo, bv);
hi = _mm_mul_epi32(hi, bv);
lo = _mm_add_epi64(lo, mulround);
hi = _mm_add_epi64(hi, mulround);
lo = _mm_srli_epi64(lo, 13);
hi = _mm_slli_epi64(hi, 32-13);
v = _mm_sub_epi32(v, _mm_blend_epi16(lo, hi, 0xCC));
_mm_store_si128((__m128i *)&(c2[i]), v);
}
for(; i < len; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[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 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);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#else
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
for(i = 0; i < n; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[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 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);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
OPJ_UINT32 i;
for(i = 0; i < n; ++i) {
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[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 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);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
#endif
@ -375,183 +376,184 @@ void opj_mct_encode_real(
/* Inverse irreversible MCT. */
/* </summary> */
void opj_mct_decode_real(
OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n)
OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n)
{
OPJ_UINT32 i;
OPJ_UINT32 i;
#ifdef __SSE__
__m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f);
vgu = _mm_set1_ps(0.34413f);
vgv = _mm_set1_ps(0.71414f);
vbu = _mm_set1_ps(1.772f);
for (i = 0; i < (n >> 3); ++i) {
__m128 vy, vu, vv;
__m128 vr, vg, vb;
__m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f);
vgu = _mm_set1_ps(0.34413f);
vgv = _mm_set1_ps(0.71414f);
vbu = _mm_set1_ps(1.772f);
for (i = 0; i < (n >> 3); ++i) {
__m128 vy, vu, vv;
__m128 vr, vg, vb;
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
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));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
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));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
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));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
}
n &= 7;
vy = _mm_load_ps(c0);
vu = _mm_load_ps(c1);
vv = _mm_load_ps(c2);
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));
vb = _mm_add_ps(vy, _mm_mul_ps(vu, vbu));
_mm_store_ps(c0, vr);
_mm_store_ps(c1, vg);
_mm_store_ps(c2, vb);
c0 += 4;
c1 += 4;
c2 += 4;
}
n &= 7;
#endif
for(i = 0; i < n; ++i) {
OPJ_FLOAT32 y = c0[i];
OPJ_FLOAT32 u = c1[i];
OPJ_FLOAT32 v = c2[i];
OPJ_FLOAT32 r = y + (v * 1.402f);
OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
for(i = 0; i < n; ++i) {
OPJ_FLOAT32 y = c0[i];
OPJ_FLOAT32 u = c1[i];
OPJ_FLOAT32 v = c2[i];
OPJ_FLOAT32 r = y + (v * 1.402f);
OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
return opj_mct_norms_real[compno];
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno)
{
return opj_mct_norms_real[compno];
}
OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * pCodingdata,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned)
OPJ_BYTE * pCodingdata,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned)
{
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
OPJ_UINT32 i;
OPJ_UINT32 j;
OPJ_UINT32 k;
OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp;
OPJ_INT32 * lCurrentData = 00;
OPJ_INT32 * lCurrentMatrix = 00;
OPJ_INT32 ** lData = (OPJ_INT32 **) pData;
OPJ_UINT32 lMultiplicator = 1 << 13;
OPJ_INT32 * lMctPtr;
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
OPJ_UINT32 i;
OPJ_UINT32 j;
OPJ_UINT32 k;
OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp;
OPJ_INT32 * lCurrentData = 00;
OPJ_INT32 * lCurrentMatrix = 00;
OPJ_INT32 ** lData = (OPJ_INT32 **) pData;
OPJ_UINT32 lMultiplicator = 1 << 13;
OPJ_INT32 * lMctPtr;
OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
if (! lCurrentData) {
return OPJ_FALSE;
}
lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof(OPJ_INT32));
if (! lCurrentData) {
return OPJ_FALSE;
}
lCurrentMatrix = lCurrentData + pNbComp;
lCurrentMatrix = lCurrentData + pNbComp;
for (i =0;i<lNbMatCoeff;++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
}
for (i =0; i<lNbMatCoeff; ++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
}
for (i = 0; i < n; ++i) {
lMctPtr = lCurrentMatrix;
for (j=0;j<pNbComp;++j) {
lCurrentData[j] = (*(lData[j]));
}
for (i = 0; i < n; ++i) {
lMctPtr = lCurrentMatrix;
for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (*(lData[j]));
}
for (j=0;j<pNbComp;++j) {
*(lData[j]) = 0;
for (k=0;k<pNbComp;++k) {
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
++lMctPtr;
}
for (j=0; j<pNbComp; ++j) {
*(lData[j]) = 0;
for (k=0; k<pNbComp; ++k) {
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
++lMctPtr;
}
++lData[j];
}
}
++lData[j];
}
}
opj_free(lCurrentData);
opj_free(lCurrentData);
return OPJ_TRUE;
return OPJ_TRUE;
}
OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned)
OPJ_BYTE * pDecodingData,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned)
{
OPJ_FLOAT32 * lMct;
OPJ_UINT32 i;
OPJ_UINT32 j;
OPJ_UINT32 k;
OPJ_FLOAT32 * lMct;
OPJ_UINT32 i;
OPJ_UINT32 j;
OPJ_UINT32 k;
OPJ_FLOAT32 * lCurrentData = 00;
OPJ_FLOAT32 * lCurrentResult = 00;
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
OPJ_FLOAT32 * lCurrentData = 00;
OPJ_FLOAT32 * lCurrentResult = 00;
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
OPJ_ARG_NOT_USED(isSigned);
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if (! lCurrentData) {
return OPJ_FALSE;
}
lCurrentResult = lCurrentData + pNbComp;
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if (! lCurrentData) {
return OPJ_FALSE;
}
lCurrentResult = lCurrentData + pNbComp;
for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData;
for (j=0;j<pNbComp;++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
}
for (j=0;j<pNbComp;++j) {
lCurrentResult[j] = 0;
for (k=0;k<pNbComp;++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k];
}
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
}
}
opj_free(lCurrentData);
return OPJ_TRUE;
for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData;
for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
}
for (j=0; j<pNbComp; ++j) {
lCurrentResult[j] = 0;
for (k=0; k<pNbComp; ++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k];
}
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
}
}
opj_free(lCurrentData);
return OPJ_TRUE;
}
void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 pNbComps,
OPJ_FLOAT32 * pMatrix)
OPJ_UINT32 pNbComps,
OPJ_FLOAT32 * pMatrix)
{
OPJ_UINT32 i,j,lIndex;
OPJ_FLOAT32 lCurrentValue;
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
OPJ_UINT32 i,j,lIndex;
OPJ_FLOAT32 lCurrentValue;
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
for (i=0;i<pNbComps;++i) {
lNorms[i] = 0;
lIndex = i;
for (i=0; i<pNbComps; ++i) {
lNorms[i] = 0;
lIndex = i;
for (j=0;j<pNbComps;++j) {
lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue;
}
lNorms[i] = sqrt(lNorms[i]);
}
for (j=0; j<pNbComps; ++j) {
lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue;
}
lNorms[i] = sqrt(lNorms[i]);
}
}

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* 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
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
@return
*/
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
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
@return
*/
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
*/
OPJ_BOOL opj_mct_encode_custom(
OPJ_BYTE * p_coding_data,
OPJ_UINT32 n,
OPJ_BYTE ** p_data,
OPJ_UINT32 p_nb_comp,
OPJ_UINT32 is_signed);
OPJ_BYTE * p_coding_data,
OPJ_UINT32 n,
OPJ_BYTE ** p_data,
OPJ_UINT32 p_nb_comp,
OPJ_UINT32 is_signed);
/**
FIXME DOC
@param pDecodingData MCT data
@ -124,27 +124,27 @@ FIXME DOC
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/
OPJ_BOOL opj_mct_decode_custom(
OPJ_BYTE * pDecodingData,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned);
OPJ_BYTE * pDecodingData,
OPJ_UINT32 n,
OPJ_BYTE ** pData,
OPJ_UINT32 pNbComp,
OPJ_UINT32 isSigned);
/**
FIXME DOC
@param pNorms MCT data
@param p_nb_comps size of components
@param pMatrix components
@return
@return
*/
void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 p_nb_comps,
OPJ_FLOAT32 * pMatrix);
/**
FIXME DOC
FIXME DOC
*/
const OPJ_FLOAT64 * opj_mct_get_mct_norms (void);
/**
FIXME DOC
FIXME DOC
*/
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* 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
@param mqc MQC handle
@return
@return
*/
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc);
/**
FIXME DOC
@param mqc MQC handle
@return
@return
*/
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. */
/* </summary> */
static opj_mqc_state_t mqc_states[47 * 2] = {
{0x5601, 0, &mqc_states[2], &mqc_states[3]},
{0x5601, 1, &mqc_states[3], &mqc_states[2]},
{0x3401, 0, &mqc_states[4], &mqc_states[12]},
{0x3401, 1, &mqc_states[5], &mqc_states[13]},
{0x1801, 0, &mqc_states[6], &mqc_states[18]},
{0x1801, 1, &mqc_states[7], &mqc_states[19]},
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
{0x0521, 0, &mqc_states[10], &mqc_states[58]},
{0x0521, 1, &mqc_states[11], &mqc_states[59]},
{0x0221, 0, &mqc_states[76], &mqc_states[66]},
{0x0221, 1, &mqc_states[77], &mqc_states[67]},
{0x5601, 0, &mqc_states[14], &mqc_states[13]},
{0x5601, 1, &mqc_states[15], &mqc_states[12]},
{0x5401, 0, &mqc_states[16], &mqc_states[28]},
{0x5401, 1, &mqc_states[17], &mqc_states[29]},
{0x4801, 0, &mqc_states[18], &mqc_states[28]},
{0x4801, 1, &mqc_states[19], &mqc_states[29]},
{0x3801, 0, &mqc_states[20], &mqc_states[28]},
{0x3801, 1, &mqc_states[21], &mqc_states[29]},
{0x3001, 0, &mqc_states[22], &mqc_states[34]},
{0x3001, 1, &mqc_states[23], &mqc_states[35]},
{0x2401, 0, &mqc_states[24], &mqc_states[36]},
{0x2401, 1, &mqc_states[25], &mqc_states[37]},
{0x1c01, 0, &mqc_states[26], &mqc_states[40]},
{0x1c01, 1, &mqc_states[27], &mqc_states[41]},
{0x1601, 0, &mqc_states[58], &mqc_states[42]},
{0x1601, 1, &mqc_states[59], &mqc_states[43]},
{0x5601, 0, &mqc_states[30], &mqc_states[29]},
{0x5601, 1, &mqc_states[31], &mqc_states[28]},
{0x5401, 0, &mqc_states[32], &mqc_states[28]},
{0x5401, 1, &mqc_states[33], &mqc_states[29]},
{0x5101, 0, &mqc_states[34], &mqc_states[30]},
{0x5101, 1, &mqc_states[35], &mqc_states[31]},
{0x4801, 0, &mqc_states[36], &mqc_states[32]},
{0x4801, 1, &mqc_states[37], &mqc_states[33]},
{0x3801, 0, &mqc_states[38], &mqc_states[34]},
{0x3801, 1, &mqc_states[39], &mqc_states[35]},
{0x3401, 0, &mqc_states[40], &mqc_states[36]},
{0x3401, 1, &mqc_states[41], &mqc_states[37]},
{0x3001, 0, &mqc_states[42], &mqc_states[38]},
{0x3001, 1, &mqc_states[43], &mqc_states[39]},
{0x2801, 0, &mqc_states[44], &mqc_states[38]},
{0x2801, 1, &mqc_states[45], &mqc_states[39]},
{0x2401, 0, &mqc_states[46], &mqc_states[40]},
{0x2401, 1, &mqc_states[47], &mqc_states[41]},
{0x2201, 0, &mqc_states[48], &mqc_states[42]},
{0x2201, 1, &mqc_states[49], &mqc_states[43]},
{0x1c01, 0, &mqc_states[50], &mqc_states[44]},
{0x1c01, 1, &mqc_states[51], &mqc_states[45]},
{0x1801, 0, &mqc_states[52], &mqc_states[46]},
{0x1801, 1, &mqc_states[53], &mqc_states[47]},
{0x1601, 0, &mqc_states[54], &mqc_states[48]},
{0x1601, 1, &mqc_states[55], &mqc_states[49]},
{0x1401, 0, &mqc_states[56], &mqc_states[50]},
{0x1401, 1, &mqc_states[57], &mqc_states[51]},
{0x1201, 0, &mqc_states[58], &mqc_states[52]},
{0x1201, 1, &mqc_states[59], &mqc_states[53]},
{0x1101, 0, &mqc_states[60], &mqc_states[54]},
{0x1101, 1, &mqc_states[61], &mqc_states[55]},
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
{0x09c1, 0, &mqc_states[64], &mqc_states[58]},
{0x09c1, 1, &mqc_states[65], &mqc_states[59]},
{0x08a1, 0, &mqc_states[66], &mqc_states[60]},
{0x08a1, 1, &mqc_states[67], &mqc_states[61]},
{0x0521, 0, &mqc_states[68], &mqc_states[62]},
{0x0521, 1, &mqc_states[69], &mqc_states[63]},
{0x0441, 0, &mqc_states[70], &mqc_states[64]},
{0x0441, 1, &mqc_states[71], &mqc_states[65]},
{0x02a1, 0, &mqc_states[72], &mqc_states[66]},
{0x02a1, 1, &mqc_states[73], &mqc_states[67]},
{0x0221, 0, &mqc_states[74], &mqc_states[68]},
{0x0221, 1, &mqc_states[75], &mqc_states[69]},
{0x0141, 0, &mqc_states[76], &mqc_states[70]},
{0x0141, 1, &mqc_states[77], &mqc_states[71]},
{0x0111, 0, &mqc_states[78], &mqc_states[72]},
{0x0111, 1, &mqc_states[79], &mqc_states[73]},
{0x0085, 0, &mqc_states[80], &mqc_states[74]},
{0x0085, 1, &mqc_states[81], &mqc_states[75]},
{0x0049, 0, &mqc_states[82], &mqc_states[76]},
{0x0049, 1, &mqc_states[83], &mqc_states[77]},
{0x0025, 0, &mqc_states[84], &mqc_states[78]},
{0x0025, 1, &mqc_states[85], &mqc_states[79]},
{0x0015, 0, &mqc_states[86], &mqc_states[80]},
{0x0015, 1, &mqc_states[87], &mqc_states[81]},
{0x0009, 0, &mqc_states[88], &mqc_states[82]},
{0x0009, 1, &mqc_states[89], &mqc_states[83]},
{0x0005, 0, &mqc_states[90], &mqc_states[84]},
{0x0005, 1, &mqc_states[91], &mqc_states[85]},
{0x0001, 0, &mqc_states[90], &mqc_states[86]},
{0x0001, 1, &mqc_states[91], &mqc_states[87]},
{0x5601, 0, &mqc_states[92], &mqc_states[92]},
{0x5601, 1, &mqc_states[93], &mqc_states[93]},
{0x5601, 0, &mqc_states[2], &mqc_states[3]},
{0x5601, 1, &mqc_states[3], &mqc_states[2]},
{0x3401, 0, &mqc_states[4], &mqc_states[12]},
{0x3401, 1, &mqc_states[5], &mqc_states[13]},
{0x1801, 0, &mqc_states[6], &mqc_states[18]},
{0x1801, 1, &mqc_states[7], &mqc_states[19]},
{0x0ac1, 0, &mqc_states[8], &mqc_states[24]},
{0x0ac1, 1, &mqc_states[9], &mqc_states[25]},
{0x0521, 0, &mqc_states[10], &mqc_states[58]},
{0x0521, 1, &mqc_states[11], &mqc_states[59]},
{0x0221, 0, &mqc_states[76], &mqc_states[66]},
{0x0221, 1, &mqc_states[77], &mqc_states[67]},
{0x5601, 0, &mqc_states[14], &mqc_states[13]},
{0x5601, 1, &mqc_states[15], &mqc_states[12]},
{0x5401, 0, &mqc_states[16], &mqc_states[28]},
{0x5401, 1, &mqc_states[17], &mqc_states[29]},
{0x4801, 0, &mqc_states[18], &mqc_states[28]},
{0x4801, 1, &mqc_states[19], &mqc_states[29]},
{0x3801, 0, &mqc_states[20], &mqc_states[28]},
{0x3801, 1, &mqc_states[21], &mqc_states[29]},
{0x3001, 0, &mqc_states[22], &mqc_states[34]},
{0x3001, 1, &mqc_states[23], &mqc_states[35]},
{0x2401, 0, &mqc_states[24], &mqc_states[36]},
{0x2401, 1, &mqc_states[25], &mqc_states[37]},
{0x1c01, 0, &mqc_states[26], &mqc_states[40]},
{0x1c01, 1, &mqc_states[27], &mqc_states[41]},
{0x1601, 0, &mqc_states[58], &mqc_states[42]},
{0x1601, 1, &mqc_states[59], &mqc_states[43]},
{0x5601, 0, &mqc_states[30], &mqc_states[29]},
{0x5601, 1, &mqc_states[31], &mqc_states[28]},
{0x5401, 0, &mqc_states[32], &mqc_states[28]},
{0x5401, 1, &mqc_states[33], &mqc_states[29]},
{0x5101, 0, &mqc_states[34], &mqc_states[30]},
{0x5101, 1, &mqc_states[35], &mqc_states[31]},
{0x4801, 0, &mqc_states[36], &mqc_states[32]},
{0x4801, 1, &mqc_states[37], &mqc_states[33]},
{0x3801, 0, &mqc_states[38], &mqc_states[34]},
{0x3801, 1, &mqc_states[39], &mqc_states[35]},
{0x3401, 0, &mqc_states[40], &mqc_states[36]},
{0x3401, 1, &mqc_states[41], &mqc_states[37]},
{0x3001, 0, &mqc_states[42], &mqc_states[38]},
{0x3001, 1, &mqc_states[43], &mqc_states[39]},
{0x2801, 0, &mqc_states[44], &mqc_states[38]},
{0x2801, 1, &mqc_states[45], &mqc_states[39]},
{0x2401, 0, &mqc_states[46], &mqc_states[40]},
{0x2401, 1, &mqc_states[47], &mqc_states[41]},
{0x2201, 0, &mqc_states[48], &mqc_states[42]},
{0x2201, 1, &mqc_states[49], &mqc_states[43]},
{0x1c01, 0, &mqc_states[50], &mqc_states[44]},
{0x1c01, 1, &mqc_states[51], &mqc_states[45]},
{0x1801, 0, &mqc_states[52], &mqc_states[46]},
{0x1801, 1, &mqc_states[53], &mqc_states[47]},
{0x1601, 0, &mqc_states[54], &mqc_states[48]},
{0x1601, 1, &mqc_states[55], &mqc_states[49]},
{0x1401, 0, &mqc_states[56], &mqc_states[50]},
{0x1401, 1, &mqc_states[57], &mqc_states[51]},
{0x1201, 0, &mqc_states[58], &mqc_states[52]},
{0x1201, 1, &mqc_states[59], &mqc_states[53]},
{0x1101, 0, &mqc_states[60], &mqc_states[54]},
{0x1101, 1, &mqc_states[61], &mqc_states[55]},
{0x0ac1, 0, &mqc_states[62], &mqc_states[56]},
{0x0ac1, 1, &mqc_states[63], &mqc_states[57]},
{0x09c1, 0, &mqc_states[64], &mqc_states[58]},
{0x09c1, 1, &mqc_states[65], &mqc_states[59]},
{0x08a1, 0, &mqc_states[66], &mqc_states[60]},
{0x08a1, 1, &mqc_states[67], &mqc_states[61]},
{0x0521, 0, &mqc_states[68], &mqc_states[62]},
{0x0521, 1, &mqc_states[69], &mqc_states[63]},
{0x0441, 0, &mqc_states[70], &mqc_states[64]},
{0x0441, 1, &mqc_states[71], &mqc_states[65]},
{0x02a1, 0, &mqc_states[72], &mqc_states[66]},
{0x02a1, 1, &mqc_states[73], &mqc_states[67]},
{0x0221, 0, &mqc_states[74], &mqc_states[68]},
{0x0221, 1, &mqc_states[75], &mqc_states[69]},
{0x0141, 0, &mqc_states[76], &mqc_states[70]},
{0x0141, 1, &mqc_states[77], &mqc_states[71]},
{0x0111, 0, &mqc_states[78], &mqc_states[72]},
{0x0111, 1, &mqc_states[79], &mqc_states[73]},
{0x0085, 0, &mqc_states[80], &mqc_states[74]},
{0x0085, 1, &mqc_states[81], &mqc_states[75]},
{0x0049, 0, &mqc_states[82], &mqc_states[76]},
{0x0049, 1, &mqc_states[83], &mqc_states[77]},
{0x0025, 0, &mqc_states[84], &mqc_states[78]},
{0x0025, 1, &mqc_states[85], &mqc_states[79]},
{0x0015, 0, &mqc_states[86], &mqc_states[80]},
{0x0015, 1, &mqc_states[87], &mqc_states[81]},
{0x0009, 0, &mqc_states[88], &mqc_states[82]},
{0x0009, 1, &mqc_states[89], &mqc_states[83]},
{0x0005, 0, &mqc_states[90], &mqc_states[84]},
{0x0005, 1, &mqc_states[91], &mqc_states[85]},
{0x0001, 0, &mqc_states[90], &mqc_states[86]},
{0x0001, 1, &mqc_states[91], &mqc_states[87]},
{0x5601, 0, &mqc_states[92], &mqc_states[92]},
{0x5601, 1, &mqc_states[93], &mqc_states[93]},
};
/*
/*
==========================================================
local functions
==========================================================
*/
static void opj_mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
} else {
(*mqc->bp)++;
if (*mqc->bp == 0xff) {
mqc->c &= 0x7ffffff;
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
}
}
static void opj_mqc_byteout(opj_mqc_t *mqc)
{
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
} else {
(*mqc->bp)++;
if (*mqc->bp == 0xff) {
mqc->c &= 0x7ffffff;
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
}
}
}
static void opj_mqc_renorme(opj_mqc_t *mqc) {
do {
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
if (mqc->ct == 0) {
opj_mqc_byteout(mqc);
}
} while ((mqc->a & 0x8000) == 0);
static void opj_mqc_renorme(opj_mqc_t *mqc)
{
do {
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
if (mqc->ct == 0) {
opj_mqc_byteout(mqc);
}
} while ((mqc->a & 0x8000) == 0);
}
static void opj_mqc_codemps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
} else {
mqc->c += (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nmps;
opj_mqc_renorme(mqc);
} else {
mqc->c += (*mqc->curctx)->qeval;
}
static void opj_mqc_codemps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
} else {
mqc->c += (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nmps;
opj_mqc_renorme(mqc);
} else {
mqc->c += (*mqc->curctx)->qeval;
}
}
static void opj_mqc_codelps(opj_mqc_t *mqc) {
mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval;
} else {
mqc->a = (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nlps;
opj_mqc_renorme(mqc);
static void opj_mqc_codelps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval;
} else {
mqc->a = (*mqc->curctx)->qeval;
}
*mqc->curctx = (*mqc->curctx)->nlps;
opj_mqc_renorme(mqc);
}
static void opj_mqc_setbits(opj_mqc_t *mqc) {
OPJ_UINT32 tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
mqc->c -= 0x8000;
}
static void opj_mqc_setbits(opj_mqc_t *mqc)
{
OPJ_UINT32 tempc = mqc->c + mqc->a;
mqc->c |= 0xffff;
if (mqc->c >= tempc) {
mqc->c -= 0x8000;
}
}
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
return d;
}
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
}
return d;
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
}
return d;
}
#ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) {
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
{
unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04;
}
#else
static void opj_mqc_bytein(opj_mqc_t *const mqc) {
if (mqc->bp != mqc->end) {
OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
c = 0xff;
}
if (*mqc->bp == 0xff) {
if (c > 0x8f) {
mqc->c += 0xff00;
mqc->ct = 8;
} else {
mqc->bp++;
mqc->c += c << 9;
mqc->ct = 7;
}
} else {
mqc->bp++;
mqc->c += c << 8;
mqc->ct = 8;
}
} else {
mqc->c += 0xff00;
mqc->ct = 8;
}
static void opj_mqc_bytein(opj_mqc_t *const mqc)
{
if (mqc->bp != mqc->end) {
OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) {
c = *(mqc->bp + 1);
} else {
c = 0xff;
}
if (*mqc->bp == 0xff) {
if (c > 0x8f) {
mqc->c += 0xff00;
mqc->ct = 8;
} else {
mqc->bp++;
mqc->c += c << 9;
mqc->ct = 7;
}
} else {
mqc->bp++;
mqc->c += c << 8;
mqc->ct = 8;
}
} else {
mqc->c += 0xff00;
mqc->ct = 8;
}
}
#endif
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
do {
if (mqc->ct == 0) {
opj_mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
} while (mqc->a < 0x8000);
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
{
do {
if (mqc->ct == 0) {
opj_mqc_bytein(mqc);
}
mqc->a <<= 1;
mqc->c <<= 1;
mqc->ct--;
} while (mqc->a < 0x8000);
}
/*
/*
==========================================================
MQ-Coder interface
==========================================================
*/
opj_mqc_t* opj_mqc_create(void) {
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
opj_mqc_t* opj_mqc_create(void)
{
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT
if (mqc) {
mqc->buffer = NULL;
}
if (mqc) {
mqc->buffer = NULL;
}
#endif
return mqc;
return mqc;
}
void opj_mqc_destroy(opj_mqc_t *mqc) {
if(mqc) {
void opj_mqc_destroy(opj_mqc_t *mqc)
{
if(mqc) {
#ifdef MQC_PERF_OPT
if (mqc->buffer) {
opj_free(mqc->buffer);
}
if (mqc->buffer) {
opj_free(mqc->buffer);
}
#endif
opj_free(mqc);
}
opj_free(mqc);
}
}
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
const ptrdiff_t diff = mqc->bp - mqc->start;
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
{
const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
#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 */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
mqc->ct = 12;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
mqc->start = bp;
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->bp = bp - 1;
mqc->ct = 12;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
mqc->start = bp;
}
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
if ((*mqc->curctx)->mps == d) {
opj_mqc_codemps(mqc);
} else {
opj_mqc_codelps(mqc);
}
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
{
if ((*mqc->curctx)->mps == d) {
opj_mqc_codemps(mqc);
} else {
opj_mqc_codelps(mqc);
}
}
void opj_mqc_flush(opj_mqc_t *mqc) {
opj_mqc_setbits(mqc);
mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
if (*mqc->bp != 0xff) {
mqc->bp++;
}
void opj_mqc_flush(opj_mqc_t *mqc)
{
opj_mqc_setbits(mqc);
mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc);
if (*mqc->bp != 0xff) {
mqc->bp++;
}
}
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
mqc->c = 0;
mqc->ct = 8;
/*if (*mqc->bp == 0xff) {
mqc->ct = 7;
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
{
mqc->c = 0;
mqc->ct = 8;
/*if (*mqc->bp == 0xff) {
mqc->ct = 7;
} */
}
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
if (*mqc->bp == 0xff) {
mqc->ct = 7;
}
mqc->c = 0;
}
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
{
mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
mqc->bp++;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
if (*mqc->bp == 0xff) {
mqc->ct = 7;
}
mqc->c = 0;
}
}
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
OPJ_BYTE bit_padding;
bit_padding = 0;
if (mqc->ct != 0) {
while (mqc->ct > 0) {
mqc->ct--;
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
bit_padding = (bit_padding + 1) & 0x01;
}
mqc->bp++;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
mqc->c = 0;
}
return 1;
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
{
OPJ_BYTE bit_padding;
bit_padding = 0;
if (mqc->ct != 0) {
while (mqc->ct > 0) {
mqc->ct--;
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
bit_padding = (bit_padding + 1) & 0x01;
}
mqc->bp++;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
mqc->c = 0;
}
return 1;
}
void opj_mqc_reset_enc(opj_mqc_t *mqc) {
opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
void opj_mqc_reset_enc(opj_mqc_t *mqc)
{
opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
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 correction = 1;
/* <flush part> */
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
mqc->c <<= mqc->ct;
while (n > 0) {
opj_mqc_byteout(mqc);
n -= (OPJ_INT32)mqc->ct;
mqc->c <<= mqc->ct;
}
opj_mqc_byteout(mqc);
return correction;
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 correction = 1;
/* <flush part> */
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
mqc->c <<= mqc->ct;
while (n > 0) {
opj_mqc_byteout(mqc);
n -= (OPJ_INT32)mqc->ct;
mqc->c <<= mqc->ct;
}
opj_mqc_byteout(mqc);
return correction;
}
void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
/* <Re-init part> */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->ct = 12;
mqc->bp--;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
{
/* <Re-init part> */
opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000;
mqc->c = 0;
mqc->ct = 12;
mqc->bp--;
if (*mqc->bp == 0xff) {
mqc->ct = 13;
}
}
void opj_mqc_erterm_enc(opj_mqc_t *mqc) {
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) {
mqc->c <<= mqc->ct;
mqc->ct = 0;
opj_mqc_byteout(mqc);
k -= (OPJ_INT32)mqc->ct;
}
if (*mqc->bp != 0xff) {
opj_mqc_byteout(mqc);
}
void opj_mqc_erterm_enc(opj_mqc_t *mqc)
{
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) {
mqc->c <<= mqc->ct;
mqc->ct = 0;
opj_mqc_byteout(mqc);
k -= (OPJ_INT32)mqc->ct;
}
if (*mqc->bp != 0xff) {
opj_mqc_byteout(mqc);
}
}
void opj_mqc_segmark_enc(opj_mqc_t *mqc) {
OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18);
for (i = 1; i < 5; i++) {
opj_mqc_encode(mqc, i % 2);
}
void opj_mqc_segmark_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18);
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_mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
mqc->bp = bp;
if (len==0) mqc->c = 0xff << 16;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16);
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
{
opj_mqc_setcurctx(mqc, 0);
mqc->start = bp;
mqc->end = bp + len;
mqc->bp = bp;
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 */
{
{
OPJ_UINT32 c;
OPJ_UINT32 *ip;
OPJ_BYTE *end = mqc->end - 1;
OPJ_UINT32 *ip;
OPJ_BYTE *end = mqc->end - 1;
void* new_buffer = opj_realloc(mqc->buffer, (len + 1) * sizeof(OPJ_UINT32));
if (! new_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;
}
mqc->buffer = new_buffer;
ip = (OPJ_UINT32 *) mqc->buffer;
while (bp < end) {
c = *(bp + 1);
if (*bp == 0xff) {
if (c > 0x8f) {
break;
} else {
*ip = 0x00000017 | (c << 9);
}
} else {
*ip = 0x00000018 | (c << 8);
}
bp++;
ip++;
}
while (bp < end) {
c = *(bp + 1);
if (*bp == 0xff) {
if (c > 0x8f) {
break;
} else {
*ip = 0x00000017 | (c << 9);
}
} else {
*ip = 0x00000018 | (c << 8);
}
bp++;
ip++;
}
/* Handle last byte of data */
c = 0xff;
if (*bp == 0xff) {
*ip = 0x0000ff18;
} else {
bp++;
*ip = 0x00000018 | (c << 8);
}
ip++;
/* Handle last byte of data */
c = 0xff;
if (*bp == 0xff) {
*ip = 0x0000ff18;
} else {
bp++;
*ip = 0x00000018 | (c << 8);
}
ip++;
*ip = 0x0000ff08;
mqc->bp = mqc->buffer;
}
*ip = 0x0000ff08;
mqc->bp = mqc->buffer;
}
#endif
opj_mqc_bytein(mqc);
mqc->c <<= 7;
mqc->ct -= 7;
mqc->a = 0x8000;
return OPJ_TRUE;
opj_mqc_bytein(mqc);
mqc->c <<= 7;
mqc->ct -= 7;
mqc->a = 0x8000;
return OPJ_TRUE;
}
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = opj_mqc_lpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
d = opj_mqc_mpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
}
}
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
{
OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
d = opj_mqc_lpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
mqc->c -= (*mqc->curctx)->qeval << 16;
if ((mqc->a & 0x8000) == 0) {
d = opj_mqc_mpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
d = (OPJ_INT32)(*mqc->curctx)->mps;
}
}
return d;
return d;
}
void opj_mqc_resetstates(opj_mqc_t *mqc) {
OPJ_UINT32 i;
for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states;
}
void opj_mqc_resetstates(opj_mqc_t *mqc)
{
OPJ_UINT32 i;
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) {
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
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)];
}

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* 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.
*/
typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
OPJ_UINT32 qeval;
/** the Most Probable Symbol (0 or 1) */
OPJ_UINT32 mps;
/** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps;
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
OPJ_UINT32 qeval;
/** the Most Probable Symbol (0 or 1) */
OPJ_UINT32 mps;
/** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps;
} opj_mqc_state_t;
#define MQC_NUMCTXS 19
@ -69,16 +69,16 @@ typedef struct opj_mqc_state {
MQ coder
*/
typedef struct opj_mqc {
OPJ_UINT32 c;
OPJ_UINT32 a;
OPJ_UINT32 ct;
OPJ_BYTE *bp;
OPJ_BYTE *start;
OPJ_BYTE *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
OPJ_UINT32 c;
OPJ_UINT32 a;
OPJ_UINT32 ct;
OPJ_BYTE *bp;
OPJ_BYTE *start;
OPJ_BYTE *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
#ifdef MQC_PERF_OPT
unsigned char *buffer;
unsigned char *buffer;
#endif
} 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
*/
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);
/**
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)
@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);
/**
BYPASS mode switch, initialization operation.
JPEG 2000 p 505.
BYPASS mode switch, initialization operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
*/
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc);
/**
BYPASS mode switch, coding operation.
JPEG 2000 p 505.
BYPASS mode switch, coding operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -39,24 +39,25 @@
#include <sys/times.h>
#endif /* _WIN32 */
OPJ_FLOAT64 opj_clock(void) {
OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */
/* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(OPJ_FLOAT64) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
/* Unix or Linux: use resource usage */
struct rusage t;
OPJ_FLOAT64 procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (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);
/* (2b) More precisely! Get the microseconds part ! */
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -39,16 +39,13 @@
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private
{
typedef struct opj_codec_private {
/** FIXME DOC */
union
{
union {
/**
* Decompression handler.
*/
struct opj_decompression
{
struct opj_decompression {
/** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
@ -111,15 +108,14 @@ typedef struct opj_codec_private
/** Set the decoded resolution factor */
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
} m_decompression;
/**
* Compression handler. FIXME DOC
*/
struct opj_compression
{
struct opj_compression {
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio,
struct opj_image * p_image,

View File

@ -1,11 +1,11 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* 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
* All rights reserved.
*
@ -70,11 +70,11 @@
#if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
!(defined(_MSC_VER) && _MSC_VER < 1400) && \
!(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
/*
Windows '95 and Borland C do not support _lseeki64
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.
*/
/*
Windows '95 and Borland C do not support _lseeki64
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.
*/
# 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_FTELL(stream) /* __int64 */ _ftelli64(stream)
@ -104,18 +104,18 @@
/* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */
#define __attribute__(x) /* __attribute__(x) */
#endif
/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */
#ifdef __GNUC__
#define restrict __restrict__
#else
#define restrict /* restrict */
#endif
/* Not a C99 compiler */
#ifdef __GNUC__
#define restrict __restrict__
#else
#define restrict /* restrict */
#endif
#endif
@ -123,47 +123,50 @@
/* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER)
#include <intrin.h>
static INLINE long opj_lrintf(float f){
static INLINE long opj_lrintf(float f)
{
#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 */
/* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
/* commented out line breaks many tests */
/* return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); */
#elif defined(_M_IX86)
int i;
_asm{
_asm{
fld f
fistp i
};
return i;
#else
return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
#else
return (long)((f>0.0f) ? (f + 0.5f) : (f - 0.5f));
#endif
}
#elif defined(__BORLANDC__)
static INLINE long opj_lrintf(float f) {
static INLINE long opj_lrintf(float f)
{
#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
int i;
int i;
_asm {
fld f
fistp i
};
_asm {
fld f
fistp i
};
return i;
return i;
#endif
}
#else
static INLINE long opj_lrintf(float f) {
return lrintf(f);
static INLINE long opj_lrintf(float f)
{
return lrintf(f);
}
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1400)
#define vsnprintf _vsnprintf
#define vsnprintf _vsnprintf
#endif
/* 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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* 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
@return Returns a if a < b else b
*/
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
return a < b ? a : b;
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b)
{
return a < b ? a : b;
}
/**
Get the minimum of two integers
@return Returns a if a < b else b
*/
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
return a < b ? a : b;
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b)
{
return a < b ? a : b;
}
/**
Get the maximum of two integers
@return Returns a if a > b else b
*/
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
return (a > b) ? a : b;
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b)
{
return (a > b) ? a : b;
}
/**
Get the maximum of two integers
@return Returns a if a > b else b
*/
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
return (a > b) ? a : b;
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (a > b) ? a : b;
}
/**
Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+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;
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;
}
/**
@ -96,93 +101,102 @@ Clamp an integer inside an interval
<ul>
<li>Returns a if (min < a < max)
<li>Returns max if (a > max)
<li>Returns min if (a < min)
<li>Returns min if (a < min)
</ul>
*/
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) {
if (a < min)
return min;
if (a > max)
return max;
return a;
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
{
if (a < min)
return min;
if (a > max)
return max;
return a;
}
/**
@return Get absolute value of integer
*/
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) {
return a < 0 ? -a : a;
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a)
{
return a < 0 ? -a : a;
}
/**
Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
assert(b);
return (a + b - 1) / b;
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b)
{
assert(b);
return (a + b - 1) / b;
}
/**
Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
assert(b);
return (a + b - 1) / b;
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b)
{
assert(b);
return (a + b - 1) / b;
}
/**
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
}
/**
Divide a 64bits integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) {
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
}
/**
Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) {
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
}
/**
Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) {
return a >> b;
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return a >> b;
}
/**
Get logarithm of an integer and round downwards
@return Returns log2(a)
*/
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) {
OPJ_INT32 l;
for (l = 0; a > 1; l++) {
a >>= 1;
}
return l;
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a)
{
OPJ_INT32 l;
for (l = 0; a > 1; l++) {
a >>= 1;
}
return l;
}
/**
Get logarithm of an integer and round downwards
@return Returns log2(a)
*/
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) {
OPJ_UINT32 l;
for (l = 0; a > 1; ++l)
{
a >>= 1;
}
return l;
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a)
{
OPJ_UINT32 l;
for (l = 0; a > 1; ++l) {
a >>= 1;
}
return l;
}
/**
@ -191,28 +205,30 @@ Multiply two fixed-precision rational numbers.
@param 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)
OPJ_INT64 temp = __emul(a, b);
OPJ_INT64 temp = __emul(a, b);
#else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096;
assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
return (OPJ_INT32) (temp >> 13);
temp += 4096;
assert((temp >> 13) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> 13) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
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)
OPJ_INT64 temp = __emul(a, b);
OPJ_INT64 temp = __emul(a, b);
#else
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
OPJ_INT64 temp = (OPJ_INT64) a * (OPJ_INT64) b ;
#endif
temp += 4096;
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
return (OPJ_INT32) (temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ;
temp += 4096;
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF);
assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - (OPJ_INT64)1));
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*

View File

@ -42,198 +42,196 @@
static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
{
void* ptr;
void* ptr;
/* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
/* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
#if defined(OPJ_HAVE_POSIX_MEMALIGN)
/* aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
* This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size))
{
ptr = NULL;
}
/* older linux */
/* aligned_alloc requires c11, restrict to posix_memalign for now. Quote:
* This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size)) {
ptr = NULL;
}
/* older linux */
#elif defined(OPJ_HAVE_MEMALIGN)
ptr = memalign( alignment, size );
/* _MSC_VER */
ptr = memalign( alignment, size );
/* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment);
ptr = _aligned_malloc(size, alignment);
#else
/*
* Generic aligned malloc implementation.
* Uses size_t offset for the integer manipulation of the pointer,
* as uintptr_t is not available in C89 to do
* bitwise operations on the pointer itself.
*/
alignment--;
{
size_t offset;
OPJ_UINT8 *mem;
/*
* Generic aligned malloc implementation.
* Uses size_t offset for the integer manipulation of the pointer,
* as uintptr_t is not available in C89 to do
* bitwise operations on the pointer itself.
*/
alignment--;
{
size_t offset;
OPJ_UINT8 *mem;
/* Room for padding and extra pointer stored in front of allocated area */
size_t overhead = alignment + sizeof(void *);
/* Room for padding and extra pointer stored in front of allocated area */
size_t overhead = alignment + sizeof(void *);
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* Avoid integer overflow */
if (size > (SIZE_MAX - overhead)) {
return NULL;
/* Avoid integer overflow */
if (size > (SIZE_MAX - overhead)) {
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
return ptr;
return ptr;
}
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 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
/* alignment shall be power of 2 */
assert( (alignment != 0U) && ((alignment & (alignment - 1U)) == 0U));
/* alignment shall be at least sizeof(void*) */
assert( alignment >= sizeof(void*));
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* no portable aligned realloc */
/* no portable aligned realloc */
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
/* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */
/* we simply use `size_t` to cast, since we are only interest in binary AND
* operator */
if( ((size_t)r_ptr & (alignment - 1U)) != 0U ) {
/* 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
* allocated array (eg. _msize on Windows, malloc_size on MacOS,
* malloc_usable_size on systems with glibc) */
void *a_ptr = opj_aligned_alloc_n(alignment, new_size);
if (a_ptr != NULL) {
memcpy(a_ptr, r_ptr, new_size);
/* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */
/* we simply use `size_t` to cast, since we are only interest in binary AND
* operator */
if( ((size_t)r_ptr & (alignment - 1U)) != 0U ) {
/* 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
* allocated array (eg. _msize on Windows, malloc_size on MacOS,
* malloc_usable_size on systems with glibc) */
void *a_ptr = opj_aligned_alloc_n(alignment, new_size);
if (a_ptr != NULL) {
memcpy(a_ptr, r_ptr, new_size);
}
free( r_ptr );
r_ptr = a_ptr;
}
free( r_ptr );
r_ptr = a_ptr;
}
/* _MSC_VER */
/* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
r_ptr = _aligned_realloc( ptr, new_size, alignment );
r_ptr = _aligned_realloc( ptr, new_size, alignment );
#else
if (ptr == NULL) {
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;
if (ptr == NULL) {
return opj_aligned_alloc_n(alignment, new_size);
}
alignment--;
{
void *oldmem;
OPJ_UINT8 *newmem;
size_t overhead = alignment + sizeof(void *);
oldmem = ((void**) ptr)[-1];
newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead);
if (newmem == NULL) {
return newmem;
/* let's be extra careful */
assert(alignment <= (SIZE_MAX - sizeof(void *)));
/* 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
return r_ptr;
return r_ptr;
}
void * opj_malloc(size_t size)
{
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return malloc(size);
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return malloc(size);
}
void * opj_calloc(size_t num, size_t size)
{
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* according to C89 standard, num == 0 shall return a valid pointer */
return calloc(num, size);
if (size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
/* according to C89 standard, num == 0 shall return a valid pointer */
return calloc(num, 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)
{
return opj_aligned_realloc_n(ptr, 16U, size);
return opj_aligned_realloc_n(ptr, 16U, size);
}
void opj_aligned_free(void* ptr)
{
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
free( ptr );
free( ptr );
#elif defined(OPJ_HAVE__ALIGNED_MALLOC)
_aligned_free( ptr );
_aligned_free( ptr );
#else
/* Generic implementation has malloced pointer stored in front of used area */
if (ptr != NULL) {
free(((void**) ptr)[-1]);
}
/* Generic implementation has malloced pointer stored in front of used area */
if (ptr != NULL) {
free(((void**) ptr)[-1]);
}
#endif
}
void * opj_realloc(void *ptr, size_t new_size)
{
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return realloc(ptr, new_size);
if (new_size == 0U) { /* prevent implementation defined behavior of realloc */
return NULL;
}
return realloc(ptr, new_size);
}
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*

View File

@ -36,7 +36,7 @@
#include "opj_includes.h"
/*
/*
* Write faix box of phix
*
* @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,
opj_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [8];
OPJ_UINT32 len, compno, i;
opj_jp2_box_t *box;
OPJ_OFF_T lenp = 0;
OPJ_BYTE l_data_header [8];
OPJ_UINT32 len, compno, i;
opj_jp2_box_t *box;
OPJ_OFF_T lenp = 0;
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 );
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
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;
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++) {
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_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);
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,
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_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
OPJ_BYTE l_data_header [8];
OPJ_OFF_T lenp;
OPJ_UINT32 len;
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
OPJ_BYTE l_data_header [8];
OPJ_OFF_T lenp;
OPJ_UINT32 len;
packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */
packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = 1;
}
else{
size_of_coding = 4;
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++;
}
}
if( j2klen > pow( 2, 32)) {
size_of_coding = 8;
version = 1;
} else {
size_of_coding = 4;
version = 0;
}
/* 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++;
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 */
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);
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_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;
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -53,58 +53,58 @@ by some function in T2.C.
FIXME DOC
*/
typedef struct opj_pi_resolution {
OPJ_UINT32 pdx, pdy;
OPJ_UINT32 pw, ph;
OPJ_UINT32 pdx, pdy;
OPJ_UINT32 pw, ph;
} opj_pi_resolution_t;
/**
FIXME DOC
*/
typedef struct opj_pi_comp {
OPJ_UINT32 dx, dy;
/** number of resolution levels */
OPJ_UINT32 numresolutions;
opj_pi_resolution_t *resolutions;
OPJ_UINT32 dx, dy;
/** number of resolution levels */
OPJ_UINT32 numresolutions;
opj_pi_resolution_t *resolutions;
} opj_pi_comp_t;
/**
Packet iterator
*/
typedef struct opj_pi_iterator {
/** Enabling Tile part generation*/
OPJ_BYTE tp_on;
/** precise if the packet has been already used (useful for progression order change) */
OPJ_INT16 *include;
/** layer step used to localize the packet in the include vector */
OPJ_UINT32 step_l;
/** resolution step used to localize the packet in the include vector */
OPJ_UINT32 step_r;
/** component step used to localize the packet in the include vector */
OPJ_UINT32 step_c;
/** precinct step used to localize the packet in the include vector */
OPJ_UINT32 step_p;
/** component that identify the packet */
OPJ_UINT32 compno;
/** resolution that identify the packet */
OPJ_UINT32 resno;
/** precinct that identify the packet */
OPJ_UINT32 precno;
/** layer that identify the packet */
OPJ_UINT32 layno;
/** 0 if the first packet */
OPJ_BOOL first;
/** progression order change information */
opj_poc_t poc;
/** number of components in the image */
OPJ_UINT32 numcomps;
/** Components*/
opj_pi_comp_t *comps;
/** FIXME DOC*/
OPJ_INT32 tx0, ty0, tx1, ty1;
/** FIXME DOC*/
OPJ_INT32 x, y;
/** FIXME DOC*/
OPJ_UINT32 dx, dy;
/** Enabling Tile part generation*/
OPJ_BYTE tp_on;
/** precise if the packet has been already used (useful for progression order change) */
OPJ_INT16 *include;
/** layer step used to localize the packet in the include vector */
OPJ_UINT32 step_l;
/** resolution step used to localize the packet in the include vector */
OPJ_UINT32 step_r;
/** component step used to localize the packet in the include vector */
OPJ_UINT32 step_c;
/** precinct step used to localize the packet in the include vector */
OPJ_UINT32 step_p;
/** component that identify the packet */
OPJ_UINT32 compno;
/** resolution that identify the packet */
OPJ_UINT32 resno;
/** precinct that identify the packet */
OPJ_UINT32 precno;
/** layer that identify the packet */
OPJ_UINT32 layno;
/** 0 if the first packet */
OPJ_BOOL first;
/** progression order change information */
opj_poc_t poc;
/** number of components in the image */
OPJ_UINT32 numcomps;
/** Components*/
opj_pi_comp_t *comps;
/** FIXME DOC*/
OPJ_INT32 tx0, ty0, tx1, ty1;
/** FIXME DOC*/
OPJ_INT32 x, y;
/** FIXME DOC*/
OPJ_UINT32 dx, dy;
} opj_pi_iterator_t;
/** @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).
*/
opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image,
opj_cp_t *cp,
OPJ_UINT32 tileno,
J2K_T2_MODE t2_mode);
opj_cp_t *cp,
OPJ_UINT32 tileno,
J2K_T2_MODE t2_mode);
/**
* 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 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_UINT32 tileno,
OPJ_UINT32 tileno,
OPJ_UINT32 pino,
OPJ_UINT32 tpnum,
OPJ_INT32 tppos,
OPJ_UINT32 tpnum,
OPJ_INT32 tppos,
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
@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_UINT32 tileno);
/**

View File

@ -35,7 +35,7 @@
#include "opj_includes.h"
/*
/*
* Write faix box of ppix
*
* @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,
opj_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [4];
int compno, i;
opj_jp2_box_t *box;
OPJ_OFF_T lenp;
OPJ_UINT32 len;
OPJ_BYTE l_data_header [4];
int compno, i;
opj_jp2_box_t *box;
OPJ_OFF_T lenp;
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;
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)
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
opj_stream_seek( cio, lenp, p_manager);
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);
for (i=0; i<2; i++) {
if (i)
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;
opj_stream_seek( cio, lenp, p_manager);
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);
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_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);
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,
opj_event_mgr_t * p_manager )
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [8];
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
OPJ_UINT32 len;
OPJ_OFF_T lenp;
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */
OPJ_BYTE l_data_header [8];
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
OPJ_UINT32 len;
OPJ_OFF_T lenp;
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
version = 1;
}
else{
size_of_coding = 4;
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++;
}
}
if( j2klen > pow( 2, 32)) {
size_of_coding = 8;
version = 1;
} else {
size_of_coding = 4;
version = 0;
}
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);
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 */
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -35,61 +35,66 @@
#include "opj_includes.h"
/*
/*
==========================================================
local functions
==========================================================
*/
/*
/*
==========================================================
RAW encoding interface
==========================================================
*/
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* opj_raw_create(void)
{
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void opj_raw_destroy(opj_raw_t *raw) {
if(raw) {
opj_free(raw);
}
void opj_raw_destroy(opj_raw_t *raw)
{
if(raw) {
opj_free(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 */
return (OPJ_UINT32)diff;
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 */
return (OPJ_UINT32)diff;
}
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
raw->c = 0;
raw->ct = 0;
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
{
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
raw->c = 0;
raw->ct = 0;
}
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) {
OPJ_UINT32 d;
if (raw->ct == 0) {
raw->ct = 8;
if (raw->len == raw->lenmax) {
raw->c = 0xff;
} else {
if (raw->c == 0xff) {
raw->ct = 7;
}
raw->c = *(raw->start + raw->len);
raw->len++;
}
}
raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d;
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw)
{
OPJ_UINT32 d;
if (raw->ct == 0) {
raw->ct = 8;
if (raw->len == raw->lenmax) {
raw->c = 0xff;
} else {
if (raw->c == 0xff) {
raw->ct = 7;
}
raw->c = *(raw->start + raw->len);
raw->len++;
}
}
raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d;
}

View File

@ -1,12 +1,12 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -50,27 +50,27 @@ with the corresponding mode switch.
RAW encoding operations
*/
typedef struct opj_raw {
/** temporary buffer where bits are coded or decoded */
OPJ_BYTE c;
/** number of bits already read or free to write */
OPJ_UINT32 ct;
/** maximum length to decode */
OPJ_UINT32 lenmax;
/** length decoded */
OPJ_UINT32 len;
/** pointer to the current position in the buffer */
OPJ_BYTE *bp;
/** pointer to the start of the buffer */
OPJ_BYTE *start;
/** pointer to the end of the buffer */
OPJ_BYTE *end;
/** temporary buffer where bits are coded or decoded */
OPJ_BYTE c;
/** number of bits already read or free to write */
OPJ_UINT32 ct;
/** maximum length to decode */
OPJ_UINT32 lenmax;
/** length decoded */
OPJ_UINT32 len;
/** pointer to the current position in the buffer */
OPJ_BYTE *bp;
/** pointer to the start of the buffer */
OPJ_BYTE *start;
/** pointer to the end of the buffer */
OPJ_BYTE *end;
} opj_raw_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new RAW handle
Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise
*/
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
@ -98,20 +98,20 @@ Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1 {
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
OPJ_INT32 *data;
opj_flag_t *flags;
OPJ_UINT32 w;
OPJ_UINT32 h;
OPJ_UINT32 datasize;
OPJ_UINT32 flagssize;
OPJ_UINT32 flags_stride;
OPJ_UINT32 data_stride;
OPJ_BOOL encoder;
OPJ_INT32 *data;
opj_flag_t *flags;
OPJ_UINT32 w;
OPJ_UINT32 h;
OPJ_UINT32 datasize;
OPJ_UINT32 flagssize;
OPJ_UINT32 flags_stride;
OPJ_UINT32 data_stride;
OPJ_BOOL encoder;
} opj_t1_t;
#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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,7 +8,7 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2007, Callum Lerwick <seg@haxxed.com>
@ -38,245 +38,250 @@
#include "opj_includes.h"
static int t1_init_ctxno_zc(int f, int orient) {
int h, v, d, n, t, hv;
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 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);
static int t1_init_ctxno_zc(int f, int orient)
{
int h, v, d, n, t, hv;
n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 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) {
case 2:
t = h;
h = v;
v = t;
case 0:
case 1:
if (!h) {
if (!v) {
if (!d)
n = 0;
else if (d == 1)
n = 1;
else
n = 2;
} else if (v == 1) {
n = 3;
} else {
n = 4;
}
} else if (h == 1) {
if (!v) {
if (!d)
n = 5;
else
n = 6;
} else {
n = 7;
}
} else
n = 8;
break;
case 3:
hv = h + v;
if (!d) {
if (!hv) {
n = 0;
} else if (hv == 1) {
n = 1;
} else {
n = 2;
}
} else if (d == 1) {
if (!hv) {
n = 3;
} else if (hv == 1) {
n = 4;
} else {
n = 5;
}
} else if (d == 2) {
if (!hv) {
n = 6;
} else {
n = 7;
}
} else {
n = 8;
}
break;
}
switch (orient) {
case 2:
t = h;
h = v;
v = t;
case 0:
case 1:
if (!h) {
if (!v) {
if (!d)
n = 0;
else if (d == 1)
n = 1;
else
n = 2;
} else if (v == 1) {
n = 3;
} else {
n = 4;
}
} else if (h == 1) {
if (!v) {
if (!d)
n = 5;
else
n = 6;
} else {
n = 7;
}
} else
n = 8;
break;
case 3:
hv = h + v;
if (!d) {
if (!hv) {
n = 0;
} else if (hv == 1) {
n = 1;
} else {
n = 2;
}
} else if (d == 1) {
if (!hv) {
n = 3;
} else if (hv == 1) {
n = 4;
} else {
n = 5;
}
} else if (d == 2) {
if (!hv) {
n = 6;
} else {
n = 7;
}
} else {
n = 8;
}
break;
}
return (T1_CTXNO_ZC + n);
return (T1_CTXNO_ZC + n);
}
static int t1_init_ctxno_sc(int f) {
int hc, vc, n;
n = 0;
static int t1_init_ctxno_sc(int f)
{
int hc, vc, n;
n = 0;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
if (hc < 0) {
hc = -hc;
vc = -vc;
}
if (!hc) {
if (vc == -1)
n = 1;
else if (!vc)
n = 0;
else
n = 1;
} else if (hc == 1) {
if (vc == -1)
n = 2;
else if (!vc)
n = 3;
else
n = 4;
}
if (hc < 0) {
hc = -hc;
vc = -vc;
}
if (!hc) {
if (vc == -1)
n = 1;
else if (!vc)
n = 0;
else
n = 1;
} else if (hc == 1) {
if (vc == -1)
n = 2;
else if (!vc)
n = 3;
else
n = 4;
}
return (T1_CTXNO_SC + n);
return (T1_CTXNO_SC + n);
}
static int t1_init_spb(int f) {
int hc, vc, n;
static int t1_init_spb(int f)
{
int hc, vc, n;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W),
1) - opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
(T1_SIG_E | T1_SGN_E)) +
((f & (T1_SIG_W | T1_SGN_W)) ==
(T1_SIG_W | T1_SGN_W)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
vc = opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S),
1) - opj_int_min(((f & (T1_SIG_N | T1_SGN_N)) ==
(T1_SIG_N | T1_SGN_N)) +
((f & (T1_SIG_S | T1_SGN_S)) ==
(T1_SIG_S | T1_SGN_S)), 1);
if (!hc && !vc)
n = 0;
else
n = (!(hc > 0 || (!hc && vc > 0)));
if (!hc && !vc)
n = 0;
else
n = (!(hc > 0 || (!hc && vc > 0)));
return n;
return n;
}
static void dump_array16(int array[],int size){
int i;
--size;
for (i = 0; i < size; ++i) {
printf("0x%04x, ", array[i]);
if(!((i+1)&0x7))
printf("\n ");
}
printf("0x%04x\n};\n\n", array[size]);
static void dump_array16(int array[],int size)
{
int i;
--size;
for (i = 0; i < size; ++i) {
printf("0x%04x, ", array[i]);
if(!((i+1)&0x7))
printf("\n ");
}
printf("0x%04x\n};\n\n", array[size]);
}
int main(int argc, char **argv)
{
int i, j;
double u, v, t;
int i, j;
double u, v, t;
int lut_ctxno_zc[1024];
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc; (void)argv;
int lut_ctxno_zc[1024];
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(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 */
for (j = 0; j < 4; ++j) {
for (i = 0; i < 256; ++i) {
int orient = j;
if (orient == 2) {
orient = 1;
} else if (orient == 1) {
orient = 2;
}
lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
}
}
/* lut_ctxno_zc */
for (j = 0; j < 4; ++j) {
for (i = 0; i < 256; ++i) {
int orient = j;
if (orient == 2) {
orient = 1;
} else if (orient == 1) {
orient = 2;
}
lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
}
}
printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
for (i = 0; i < 1023; ++i) {
printf("%i, ", lut_ctxno_zc[i]);
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", lut_ctxno_zc[1023]);
printf("static OPJ_BYTE lut_ctxno_zc[1024] = {\n ");
for (i = 0; i < 1023; ++i) {
printf("%i, ", lut_ctxno_zc[i]);
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", lut_ctxno_zc[1023]);
/* lut_ctxno_sc */
printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("0x%x, ", t1_init_ctxno_sc(i << 4));
if(!((i+1)&0xf))
printf("\n ");
}
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
/* lut_ctxno_sc */
printf("static OPJ_BYTE lut_ctxno_sc[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("0x%x, ", t1_init_ctxno_sc(i << 4));
if(!((i+1)&0xf))
printf("\n ");
}
printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));
/* lut_spb */
printf("static OPJ_BYTE lut_spb[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("%i, ", t1_init_spb(i << 4));
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", t1_init_spb(255 << 4));
/* lut_spb */
printf("static OPJ_BYTE lut_spb[256] = {\n ");
for (i = 0; i < 255; ++i) {
printf("%i, ", t1_init_spb(i << 4));
if(!((i+1)&0x1f))
printf("\n ");
}
printf("%i\n};\n\n", t1_init_spb(255 << 4));
/* FIXME FIXME FIXME */
/* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;
v = t - 1.5;
lut_nmsedec_sig[i] =
opj_int_max(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] =
opj_int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
u = t - 1.0;
if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
v = t - 1.5;
} else {
v = t - 0.5;
}
lut_nmsedec_ref[i] =
opj_int_max(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] =
opj_int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
}
/* FIXME FIXME FIXME */
/* fprintf(stdout,"nmsedec luts:\n"); */
for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
t = i / pow(2, T1_NMSEDEC_FRACBITS);
u = t;
v = t - 1.5;
lut_nmsedec_sig[i] =
opj_int_max(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] =
opj_int_max(0,
(int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
u = t - 1.0;
if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
v = t - 1.5;
} else {
v = t - 0.5;
}
lut_nmsedec_ref[i] =
opj_int_max(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] =
opj_int_max(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 ");
dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);
printf("static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n ");
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 */
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,
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,
7, 7, 7, 7, 7, 7, 7, 7, 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,
8, 8, 8, 8, 8, 8, 8, 8, 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,
8, 8, 8, 8, 8, 8, 8, 8, 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,
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,
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,
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,
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,
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,
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,
7, 7, 7, 7, 7, 7, 7, 7, 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,
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,
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,
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
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,
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,
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,
7, 7, 7, 7, 7, 7, 7, 7, 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,
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,
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,
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,
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,
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,
7, 7, 7, 7, 7, 7, 7, 7, 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,
8, 8, 8, 8, 8, 8, 8, 8, 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,
8, 8, 8, 8, 8, 8, 8, 8, 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,
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,
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
};
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, 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, 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, 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, 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, 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, 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, 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,
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, 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, 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, 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, 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, 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, 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
};
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, 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, 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, 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, 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, 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, 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, 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, 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
};
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, 0x0180, 0x0300, 0x0480, 0x0600, 0x0780, 0x0900, 0x0a80,
0x0c00, 0x0d80, 0x0f00, 0x1080, 0x1200, 0x1380, 0x1500, 0x1680,
0x1800, 0x1980, 0x1b00, 0x1c80, 0x1e00, 0x1f80, 0x2100, 0x2280,
0x2400, 0x2580, 0x2700, 0x2880, 0x2a00, 0x2b80, 0x2d00, 0x2e80,
0x3000, 0x3180, 0x3300, 0x3480, 0x3600, 0x3780, 0x3900, 0x3a80,
0x3c00, 0x3d80, 0x3f00, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5100, 0x5280,
0x5400, 0x5580, 0x5700, 0x5880, 0x5a00, 0x5b80, 0x5d00, 0x5e80,
0x6000, 0x6180, 0x6300, 0x6480, 0x6600, 0x6780, 0x6900, 0x6a80,
0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680
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,
0x0c00, 0x0d80, 0x0f00, 0x1080, 0x1200, 0x1380, 0x1500, 0x1680,
0x1800, 0x1980, 0x1b00, 0x1c80, 0x1e00, 0x1f80, 0x2100, 0x2280,
0x2400, 0x2580, 0x2700, 0x2880, 0x2a00, 0x2b80, 0x2d00, 0x2e80,
0x3000, 0x3180, 0x3300, 0x3480, 0x3600, 0x3780, 0x3900, 0x3a80,
0x3c00, 0x3d80, 0x3f00, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5100, 0x5280,
0x5400, 0x5580, 0x5700, 0x5880, 0x5a00, 0x5b80, 0x5d00, 0x5e80,
0x6000, 0x6180, 0x6300, 0x6480, 0x6600, 0x6780, 0x6900, 0x6a80,
0x6c00, 0x6d80, 0x6f00, 0x7080, 0x7200, 0x7380, 0x7500, 0x7680
};
static OPJ_INT16 lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00,
0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2680, 0x2780,
0x2880, 0x2980, 0x2b00, 0x2c00, 0x2d00, 0x2e80, 0x2f80, 0x3100,
0x3200, 0x3380, 0x3480, 0x3600, 0x3700, 0x3880, 0x3a00, 0x3b00,
0x3c80, 0x3e00, 0x3f80, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5180, 0x5300,
0x5480, 0x5600, 0x5800, 0x5980, 0x5b00, 0x5d00, 0x5e80, 0x6080,
0x6200, 0x6400, 0x6580, 0x6780, 0x6900, 0x6b00, 0x6d00, 0x6e80,
0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00,
0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2680, 0x2780,
0x2880, 0x2980, 0x2b00, 0x2c00, 0x2d00, 0x2e80, 0x2f80, 0x3100,
0x3200, 0x3380, 0x3480, 0x3600, 0x3700, 0x3880, 0x3a00, 0x3b00,
0x3c80, 0x3e00, 0x3f80, 0x4080, 0x4200, 0x4380, 0x4500, 0x4680,
0x4800, 0x4980, 0x4b00, 0x4c80, 0x4e00, 0x4f80, 0x5180, 0x5300,
0x5480, 0x5600, 0x5800, 0x5980, 0x5b00, 0x5d00, 0x5e80, 0x6080,
0x6200, 0x6400, 0x6580, 0x6780, 0x6900, 0x6b00, 0x6d00, 0x6e80,
0x7080, 0x7280, 0x7480, 0x7600, 0x7800, 0x7a00, 0x7c00, 0x7e00
};
static OPJ_INT16 lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {
0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480,
0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080,
0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80,
0x0c00, 0x0b80, 0x0b00, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0500, 0x0480,
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, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b00, 0x0b80,
0x0c00, 0x0c80, 0x0d00, 0x0d80, 0x0e00, 0x0e80, 0x0f00, 0x0f80,
0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380,
0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780
0x1800, 0x1780, 0x1700, 0x1680, 0x1600, 0x1580, 0x1500, 0x1480,
0x1400, 0x1380, 0x1300, 0x1280, 0x1200, 0x1180, 0x1100, 0x1080,
0x1000, 0x0f80, 0x0f00, 0x0e80, 0x0e00, 0x0d80, 0x0d00, 0x0c80,
0x0c00, 0x0b80, 0x0b00, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0500, 0x0480,
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, 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b00, 0x0b80,
0x0c00, 0x0c80, 0x0d00, 0x0d80, 0x0e00, 0x0e80, 0x0f00, 0x0f80,
0x1000, 0x1080, 0x1100, 0x1180, 0x1200, 0x1280, 0x1300, 0x1380,
0x1400, 0x1480, 0x1500, 0x1580, 0x1600, 0x1680, 0x1700, 0x1780
};
static OPJ_INT16 lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {
0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980,
0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300,
0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00,
0x0c80, 0x0c00, 0x0b80, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0580, 0x0500,
0x0480, 0x0400, 0x0400, 0x0380, 0x0300, 0x0300, 0x0280, 0x0280,
0x0200, 0x0200, 0x0180, 0x0180, 0x0100, 0x0100, 0x0100, 0x0080,
0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
0x1880, 0x1980, 0x1a80, 0x1b00, 0x1c00, 0x1d00, 0x1e00, 0x1f00
0x2000, 0x1f00, 0x1e00, 0x1d00, 0x1c00, 0x1b00, 0x1a80, 0x1980,
0x1880, 0x1780, 0x1700, 0x1600, 0x1500, 0x1480, 0x1380, 0x1300,
0x1200, 0x1180, 0x1080, 0x1000, 0x0f00, 0x0e80, 0x0e00, 0x0d00,
0x0c80, 0x0c00, 0x0b80, 0x0a80, 0x0a00, 0x0980, 0x0900, 0x0880,
0x0800, 0x0780, 0x0700, 0x0680, 0x0600, 0x0580, 0x0580, 0x0500,
0x0480, 0x0400, 0x0400, 0x0380, 0x0300, 0x0300, 0x0280, 0x0280,
0x0200, 0x0200, 0x0180, 0x0180, 0x0100, 0x0100, 0x0100, 0x0080,
0x0080, 0x0080, 0x0080, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0080, 0x0080,
0x0080, 0x0080, 0x0100, 0x0100, 0x0100, 0x0180, 0x0180, 0x0200,
0x0200, 0x0280, 0x0280, 0x0300, 0x0300, 0x0380, 0x0400, 0x0400,
0x0480, 0x0500, 0x0580, 0x0580, 0x0600, 0x0680, 0x0700, 0x0780,
0x0800, 0x0880, 0x0900, 0x0980, 0x0a00, 0x0a80, 0x0b80, 0x0c00,
0x0c80, 0x0d00, 0x0e00, 0x0e80, 0x0f00, 0x1000, 0x1080, 0x1180,
0x1200, 0x1300, 0x1380, 0x1480, 0x1500, 0x1600, 0x1700, 0x1780,
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* All rights reserved.
*
@ -52,10 +52,10 @@ Tier-2 coding
*/
typedef struct opj_t2 {
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
opj_image_t *image;
/** pointer to the image coding parameters */
opj_cp_t *cp;
/** Encoding: pointer to the src image. Decoding: pointer to the dst image. */
opj_image_t *image;
/** pointer to the image coding parameters */
opj_cp_t *cp;
} opj_t2_t;
/** @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
*/
OPJ_BOOL opj_t2_encode_packets( opj_t2_t* t2,
OPJ_UINT32 tileno,
opj_tcd_tile_t *tile,
OPJ_UINT32 maxlayers,
OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 len,
opj_codestream_info_t *cstr_info,
OPJ_UINT32 tpnum,
OPJ_INT32 tppos,
OPJ_UINT32 pino,
J2K_T2_MODE t2_mode);
OPJ_UINT32 tileno,
opj_tcd_tile_t *tile,
OPJ_UINT32 maxlayers,
OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 len,
opj_codestream_info_t *cstr_info,
OPJ_UINT32 tpnum,
OPJ_INT32 tppos,
OPJ_UINT32 pino,
J2K_T2_MODE t2_mode);
/**
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
* BSD License, included below. This software may be subject to other third
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* All rights reserved.
*
@ -53,120 +53,119 @@ each other. The functions in TCD.C are used by other functions in J2K.C.
FIXME DOC
*/
typedef struct opj_tcd_seg {
OPJ_BYTE ** data;
OPJ_UINT32 dataindex;
OPJ_UINT32 numpasses;
OPJ_UINT32 real_num_passes;
OPJ_UINT32 len;
OPJ_UINT32 maxpasses;
OPJ_UINT32 numnewpasses;
OPJ_UINT32 newlen;
OPJ_BYTE ** data;
OPJ_UINT32 dataindex;
OPJ_UINT32 numpasses;
OPJ_UINT32 real_num_passes;
OPJ_UINT32 len;
OPJ_UINT32 maxpasses;
OPJ_UINT32 numnewpasses;
OPJ_UINT32 newlen;
} opj_tcd_seg_t;
/**
FIXME DOC
*/
typedef struct opj_tcd_pass {
OPJ_UINT32 rate;
OPJ_FLOAT64 distortiondec;
OPJ_UINT32 len;
OPJ_UINT32 term : 1;
OPJ_UINT32 rate;
OPJ_FLOAT64 distortiondec;
OPJ_UINT32 len;
OPJ_UINT32 term : 1;
} opj_tcd_pass_t;
/**
FIXME DOC
*/
typedef struct opj_tcd_layer {
OPJ_UINT32 numpasses; /* Number of passes in the layer */
OPJ_UINT32 len; /* len of information */
OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */
OPJ_BYTE *data; /* data */
OPJ_UINT32 numpasses; /* Number of passes in the layer */
OPJ_UINT32 len; /* len of information */
OPJ_FLOAT64 disto; /* add for index (Cfr. Marcela) */
OPJ_BYTE *data; /* data */
} opj_tcd_layer_t;
/**
FIXME DOC
*/
typedef struct opj_tcd_cblk_enc {
OPJ_BYTE* data; /* Data */
opj_tcd_layer_t* layers; /* layer information */
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_UINT32 numbps;
OPJ_UINT32 numlenbits;
OPJ_UINT32 data_size; /* Size of allocated data buffer */
OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */
OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */
OPJ_UINT32 totalpasses; /* total number of passes */
OPJ_BYTE* data; /* Data */
opj_tcd_layer_t* layers; /* layer information */
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_UINT32 numbps;
OPJ_UINT32 numlenbits;
OPJ_UINT32 data_size; /* Size of allocated data buffer */
OPJ_UINT32 numpasses; /* number of pass already done for the code-blocks */
OPJ_UINT32 numpassesinlayers; /* number of passes in the layer */
OPJ_UINT32 totalpasses; /* total number of passes */
} opj_tcd_cblk_enc_t;
typedef struct opj_tcd_cblk_dec {
OPJ_BYTE * data; /* Data */
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_UINT32 numbps;
OPJ_UINT32 numlenbits;
OPJ_UINT32 data_max_size; /* Size of allocated 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 numsegs; /* number of segments */
OPJ_UINT32 real_num_segs;
OPJ_UINT32 m_current_max_segs;
OPJ_BYTE * data; /* Data */
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_UINT32 numbps;
OPJ_UINT32 numlenbits;
OPJ_UINT32 data_max_size; /* Size of allocated 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 numsegs; /* number of segments */
OPJ_UINT32 real_num_segs;
OPJ_UINT32 m_current_max_segs;
} opj_tcd_cblk_dec_t;
/**
FIXME DOC
*/
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_UINT32 cw, ch; /* number of precinct in width and height */
union{ /* code-blocks information */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
void* blocks;
} cblks;
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */
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 */
union { /* code-blocks information */
opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec;
void* blocks;
} cblks;
OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */
opj_tgt_tree_t *incltree; /* inclusion tree */
opj_tgt_tree_t *imsbtree; /* IMSB tree */
} opj_tcd_precinct_t;
/**
FIXME DOC
*/
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_UINT32 bandno;
opj_tcd_precinct_t *precincts; /* precinct information */
OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
OPJ_INT32 numbps;
OPJ_FLOAT32 stepsize;
OPJ_INT32 x0, y0, x1, y1; /* dimension of the subband : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 bandno;
opj_tcd_precinct_t *precincts; /* precinct information */
OPJ_UINT32 precincts_data_size; /* size of data taken by precincts */
OPJ_INT32 numbps;
OPJ_FLOAT32 stepsize;
} opj_tcd_band_t;
/**
FIXME DOC
*/
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_UINT32 pw, ph;
OPJ_UINT32 numbands; /* number sub-band for the resolution level */
opj_tcd_band_t bands[3]; /* subband information */
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 numbands; /* number sub-band for the resolution level */
opj_tcd_band_t bands[3]; /* subband information */
} opj_tcd_resolution_t;
/**
FIXME DOC
*/
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_UINT32 numresolutions; /* number of resolutions level */
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
opj_tcd_resolution_t *resolutions; /* resolutions information */
OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
OPJ_INT32 *data; /* data of the component */
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; /* size of the data of the component */
OPJ_INT32 numpix; /* add fixed_quality */
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_UINT32 numresolutions; /* number of resolutions level */
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
opj_tcd_resolution_t *resolutions; /* resolutions information */
OPJ_UINT32 resolutions_size; /* size of data for resolutions (in bytes) */
OPJ_INT32 *data; /* data of the component */
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; /* size of the data of the component */
OPJ_INT32 numpix; /* add fixed_quality */
} opj_tcd_tilecomp_t;
@ -174,21 +173,20 @@ typedef struct opj_tcd_tilecomp
FIXME DOC
*/
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_UINT32 numcomps; /* number of components in tile */
opj_tcd_tilecomp_t *comps; /* Components information */
OPJ_INT32 numpix; /* add fixed_quality */
OPJ_FLOAT64 distotile; /* add fixed_quality */
OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */
OPJ_UINT32 packno; /* packet number */
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_tcd_tilecomp_t *comps; /* Components information */
OPJ_INT32 numpix; /* add fixed_quality */
OPJ_FLOAT64 distotile; /* add fixed_quality */
OPJ_FLOAT64 distolayer[100]; /* add fixed_quality */
OPJ_UINT32 packno; /* packet number */
} opj_tcd_tile_t;
/**
FIXME DOC
*/
typedef struct opj_tcd_image
{
opj_tcd_tile_t *tiles; /* Tiles information */
typedef struct opj_tcd_image {
opj_tcd_tile_t *tiles; /* Tiles information */
}
opj_tcd_image_t;
@ -196,30 +194,29 @@ opj_tcd_image_t;
/**
Tile coder/decoder
*/
typedef struct opj_tcd
{
/** Position of the tilepart flag in Progression order*/
OPJ_INT32 tp_pos;
/** Tile part number*/
OPJ_UINT32 tp_num;
/** Current tile part number*/
OPJ_UINT32 cur_tp_num;
/** Total number of tileparts of the current tile*/
OPJ_UINT32 cur_totnum_tp;
/** Current Packet iterator number */
OPJ_UINT32 cur_pino;
/** info on each image tile */
opj_tcd_image_t *tcd_image;
/** image header */
opj_image_t *image;
/** coding parameters */
opj_cp_t *cp;
/** coding/decoding parameters common to all tiles */
opj_tcp_t *tcp;
/** current encoded/decoded tile */
OPJ_UINT32 tcd_tileno;
/** tell if the tcd is a decoder. */
OPJ_UINT32 m_is_decoder : 1;
typedef struct opj_tcd {
/** Position of the tilepart flag in Progression order*/
OPJ_INT32 tp_pos;
/** Tile part number*/
OPJ_UINT32 tp_num;
/** Current tile part number*/
OPJ_UINT32 cur_tp_num;
/** Total number of tileparts of the current tile*/
OPJ_UINT32 cur_totnum_tp;
/** Current Packet iterator number */
OPJ_UINT32 cur_pino;
/** info on each image tile */
opj_tcd_image_t *tcd_image;
/** image header */
opj_image_t *image;
/** coding parameters */
opj_cp_t *cp;
/** coding/decoding parameters common to all tiles */
opj_tcp_t *tcp;
/** current encoded/decoded tile */
OPJ_UINT32 tcd_tileno;
/** tell if the tcd is a decoder. */
OPJ_UINT32 m_is_decoder : 1;
} opj_tcd_t;
/** @name Exported functions */
@ -229,7 +226,7 @@ typedef struct opj_tcd
/**
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
@ -253,8 +250,8 @@ void opj_tcd_destroy(opj_tcd_t *tcd);
* @return true if the encoding values could be set (false otherwise).
*/
OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
opj_image_t * p_image,
opj_cp_t * p_cp );
opj_image_t * p_image,
opj_cp_t * p_cp );
/**
* 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_makelayer( opj_tcd_t *tcd,
OPJ_UINT32 layno,
OPJ_FLOAT64 thresh,
OPJ_UINT32 final);
OPJ_UINT32 layno,
OPJ_FLOAT64 thresh,
OPJ_UINT32 final);
OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 len,
opj_codestream_info_t *cstr_info);
OPJ_BYTE *dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 len,
opj_codestream_info_t *cstr_info);
/**
* 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.
*/
OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
OPJ_UINT32 p_tile_no,
OPJ_BYTE *p_dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 p_len,
struct opj_codestream_info *p_cstr_info);
OPJ_UINT32 p_tile_no,
OPJ_BYTE *p_dest,
OPJ_UINT32 * p_data_written,
OPJ_UINT32 p_len,
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.
*/
OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *tcd,
OPJ_BYTE *src,
OPJ_UINT32 len,
OPJ_UINT32 tileno,
opj_codestream_index_t *cstr_info,
opj_event_mgr_t *manager);
OPJ_BYTE *src,
OPJ_UINT32 len,
OPJ_UINT32 tileno,
opj_codestream_index_t *cstr_info,
opj_event_mgr_t *manager);
/**
* Copies tile data from the system onto the given memory block.
*/
OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
OPJ_BYTE * p_dest,
OPJ_UINT32 p_dest_length );
OPJ_BYTE * p_dest,
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).
*/
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.

View File

@ -1,6 +1,6 @@
/*
* 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
* 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
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
@ -8,10 +8,10 @@
* Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens
* 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) 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
* All rights reserved.
*
@ -39,87 +39,88 @@
#include "opj_includes.h"
/*
/*
==========================================================
Tag-tree coder interface
==========================================================
*/
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_tgt_node_t *node = 00;
opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00;
opj_tgt_tree_t *tree = 00;
OPJ_UINT32 i;
OPJ_INT32 j,k;
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
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_tgt_node_t *node = 00;
opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00;
opj_tgt_tree_t *tree = 00;
OPJ_UINT32 i;
OPJ_INT32 j,k;
OPJ_UINT32 numlvls;
OPJ_UINT32 n;
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n");
return 00;
}
tree = (opj_tgt_tree_t *) opj_calloc(1,sizeof(opj_tgt_tree_t));
if(!tree) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree\n");
return 00;
}
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
numlvls = 0;
nplh[0] = (OPJ_INT32)numleafsh;
nplv[0] = (OPJ_INT32)numleafsv;
tree->numnodes = 0;
do {
n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]);
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
numlvls = 0;
nplh[0] = (OPJ_INT32)numleafsh;
nplv[0] = (OPJ_INT32)numleafsv;
tree->numnodes = 0;
do {
n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]);
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
return 00;
}
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
opj_event_msg(manager, EVT_WARNING, "tgt_create tree->numnodes == 0, no tree created.\n");
return 00;
}
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
opj_free(tree);
return 00;
}
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n");
opj_free(tree);
return 00;
}
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes;
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
l_parent_node0 = l_parent_node;
node = tree->nodes;
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
l_parent_node0 = l_parent_node;
for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i];
while (--k >= 0) {
node->parent = l_parent_node;
++node;
if (--k >= 0) {
node->parent = l_parent_node;
++node;
}
++l_parent_node;
}
if ((j & 1) || j == nplv[i] - 1) {
l_parent_node0 = l_parent_node;
} else {
l_parent_node = l_parent_node0;
l_parent_node0 += nplh[i];
}
for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i];
while (--k >= 0) {
node->parent = l_parent_node;
++node;
if (--k >= 0) {
node->parent = l_parent_node;
++node;
}
++l_parent_node;
}
if ((j & 1) || j == nplv[i] - 1) {
l_parent_node0 = l_parent_node;
} else {
l_parent_node = l_parent_node0;
l_parent_node0 += nplh[i];
}
}
node->parent = 0;
opj_tgt_reset(tree);
return tree;
}
node->parent = 0;
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_INT32 l_nplh[32];
OPJ_INT32 l_nplv[32];
opj_tgt_node_t *l_node = 00;
opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00;
OPJ_UINT32 i;
OPJ_INT32 j,k;
OPJ_UINT32 l_num_levels;
OPJ_UINT32 n;
OPJ_UINT32 l_node_size;
OPJ_INT32 l_nplh[32];
OPJ_INT32 l_nplv[32];
opj_tgt_node_t *l_node = 00;
opj_tgt_node_t *l_parent_node = 00;
opj_tgt_node_t *l_parent_node0 = 00;
OPJ_UINT32 i;
OPJ_INT32 j,k;
OPJ_UINT32 l_num_levels;
OPJ_UINT32 n;
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;
}
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)) {
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;
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;
}
while (n > 1);
/* ADD */
if (p_tree->numnodes == 0) {
opj_tgt_destroy(p_tree);
return 00;
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_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)
{
if (! p_tree) {
return;
}
if (! p_tree) {
return;
}
if (p_tree->nodes) {
opj_free(p_tree->nodes);
p_tree->nodes = 00;
}
opj_free(p_tree);
if (p_tree->nodes) {
opj_free(p_tree->nodes);
p_tree->nodes = 00;
}
opj_free(p_tree);
}
void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
void opj_tgt_reset(opj_tgt_tree_t *p_tree)
{
OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;;
if (! p_tree) {
return;
}
if (! p_tree) {
return;
}
l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i)
{
l_current_node->value = 999;
l_current_node->low = 0;
l_current_node->known = 0;
++l_current_node;
}
l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i) {
l_current_node->value = 999;
l_current_node->low = 0;
l_current_node->known = 0;
++l_current_node;
}
}
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) {
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
node->value = value;
node = node->parent;
}
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
{
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
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) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
OPJ_INT32 low;
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 *node;
OPJ_INT32 low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
while (low < threshold) {
if (low >= node->value) {
if (!node->known) {
opj_bio_write(bio, 1, 1);
node->known = 1;
}
while (low < threshold) {
if (low >= node->value) {
if (!node->known) {
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;
break;
}
opj_bio_write(bio, 0, 1);
++low;
}
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_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
OPJ_INT32 low;
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 *node;
OPJ_INT32 low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
low = 0;
for (;;) {
if (low > node->low) {
node->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;
while (low < threshold && low < node->value) {
if (opj_bio_read(bio, 1)) {
node->value = low;
} else {
++low;
}
}
return (node->value < threshold) ? 1 : 0;
node->low = low;
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