Compare commits
112 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd3d73f678 | ||
|
|
4458ef921c | ||
|
|
c9ac67cd05 | ||
|
|
cff5df73d9 | ||
|
|
e398154212 | ||
|
|
0ea26e7ba6 | ||
|
|
8f3bd54c3d | ||
|
|
18a9bcb882 | ||
|
|
7ee36c3a4c | ||
|
|
7f8f47566f | ||
|
|
d6a523e091 | ||
|
|
ac634b1639 | ||
|
|
a0513798bb | ||
|
|
8f4d6bbeba | ||
|
|
cd98a4f740 | ||
|
|
e25e7e767e | ||
|
|
de75303c38 | ||
|
|
32ba9920db | ||
|
|
7ae6a670fa | ||
|
|
cf4f8be5f0 | ||
|
|
ec1b970a32 | ||
|
|
ee6d0cfba9 | ||
|
|
789f6f8e7a | ||
|
|
3d2a52cd82 | ||
|
|
384068ce8c | ||
|
|
7e518596e0 | ||
|
|
f9eb8f93c2 | ||
|
|
d54925f777 | ||
|
|
eae26f958e | ||
|
|
ee7c2c28f1 | ||
|
|
8a2e6ecd8b | ||
|
|
1b0a585256 | ||
|
|
29b6a4307a | ||
|
|
ad4857df94 | ||
|
|
a73e37301a | ||
|
|
255e296113 | ||
|
|
e4696a445d | ||
|
|
81f688433d | ||
|
|
0130af0ff4 | ||
|
|
2cbcbb25b0 | ||
|
|
5197135a0a | ||
|
|
4c67811f65 | ||
|
|
8e8afafae6 | ||
|
|
370cfc43a2 | ||
|
|
d101633cfa | ||
|
|
128bcc4f62 | ||
|
|
050737bea0 | ||
|
|
63e17a19eb | ||
|
|
61e85ded8b | ||
|
|
1cc9fa6815 | ||
|
|
7bdb0331a6 | ||
|
|
623f1d96cf | ||
|
|
1de9535b8c | ||
|
|
68ebc572fc | ||
|
|
5f44ec7d01 | ||
|
|
10aee43cbc | ||
|
|
7e2e09e2a9 | ||
|
|
86ce4d4c18 | ||
|
|
361edd25b7 | ||
|
|
85691a02a6 | ||
|
|
1f96f0e92a | ||
|
|
34a6c13a2d | ||
|
|
542f06007c | ||
|
|
fdbca0fc9d | ||
|
|
632902d7e3 | ||
|
|
9310f1b4a9 | ||
|
|
ed0a46eff5 | ||
|
|
8323900f73 | ||
|
|
c83ae7397d | ||
|
|
3b1bee0eec | ||
|
|
ba1cf545df | ||
|
|
bfb2f9f58b | ||
|
|
13b8ecfe44 | ||
|
|
9e9e188ebf | ||
|
|
5034581e69 | ||
|
|
85ec5eccf7 | ||
|
|
9c8fcc3616 | ||
|
|
7976b61c89 | ||
|
|
43a6b92345 | ||
|
|
f25acae0bc | ||
|
|
9225f53d62 | ||
|
|
eb1b017ec7 | ||
|
|
0ddef9b2db | ||
|
|
1bdb07cefe | ||
|
|
0a879e2207 | ||
|
|
f3c3eab744 | ||
|
|
08209f1d23 | ||
|
|
3ec116ae08 | ||
|
|
3b600a986c | ||
|
|
0d4a38f3a5 | ||
|
|
2410db2ae7 | ||
|
|
e1278bc691 | ||
|
|
899439a906 | ||
|
|
02e3a4ec77 | ||
|
|
7250ce0668 | ||
|
|
2ebe5f2c92 | ||
|
|
3c730a804b | ||
|
|
313975debf | ||
|
|
0abe8e1997 | ||
|
|
bc5c5115cb | ||
|
|
61ac18531a | ||
|
|
0ee21bdbfe | ||
|
|
d116ca5d10 | ||
|
|
26a630dad2 | ||
|
|
2c2730280e | ||
|
|
2e2ba14c53 | ||
|
|
9fa68ca811 | ||
|
|
d38080aa00 | ||
|
|
aa6c1d28ad | ||
|
|
ba4fd784f5 | ||
|
|
3d67d80d49 | ||
|
|
25e97927f9 |
@@ -1,13 +0,0 @@
|
|||||||
# The "checkoutlist" file is used to support additional version controlled
|
|
||||||
# administrative files in $CVSROOT/CVSROOT, such as template files.
|
|
||||||
#
|
|
||||||
# The first entry on a line is a filename which will be checked out from
|
|
||||||
# the corresponding RCS file in the $CVSROOT/CVSROOT directory.
|
|
||||||
# The remainder of the line is an error message to use if the file cannot
|
|
||||||
# be checked out.
|
|
||||||
#
|
|
||||||
# File format:
|
|
||||||
#
|
|
||||||
# [<whitespace>]<filename><whitespace><error message><end-of-line>
|
|
||||||
#
|
|
||||||
# comment lines begin with '#'
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# The "commitinfo" file is used to control pre-commit checks.
|
|
||||||
# The filter on the right is invoked with the repository and a list
|
|
||||||
# of files to check. A non-zero exit of the filter program will
|
|
||||||
# cause the commit to be aborted.
|
|
||||||
#
|
|
||||||
# The first entry on a line is a regular expression which is tested
|
|
||||||
# against the directory that the change is being committed to, relative
|
|
||||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
|
||||||
# of the line is the name of the filter to run.
|
|
||||||
#
|
|
||||||
# If the repository name does not match any of the regular expressions in this
|
|
||||||
# file, the "DEFAULT" line is used, if it is specified.
|
|
||||||
#
|
|
||||||
# If the name "ALL" appears as a regular expression it is always used
|
|
||||||
# in addition to the first matching regex or "DEFAULT".
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
# Set this to "no" if pserver shouldn't check system users/passwords
|
|
||||||
#SystemAuth=no
|
|
||||||
|
|
||||||
# Put CVS lock files in this directory rather than directly in the repository.
|
|
||||||
#LockDir=/var/lock/cvs
|
|
||||||
|
|
||||||
# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top
|
|
||||||
# level of the new working directory when using the `cvs checkout'
|
|
||||||
# command.
|
|
||||||
#TopLevelAdmin=no
|
|
||||||
|
|
||||||
# Set `LogHistory' to `all' or `TOFEWGCMAR' to log all transactions to the
|
|
||||||
# history file, or a subset as needed (ie `TMAR' logs all write operations)
|
|
||||||
#LogHistory=TOFEWGCMAR
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
# This file affects handling of files based on their names.
|
|
||||||
#
|
|
||||||
# The -t/-f options allow one to treat directories of files
|
|
||||||
# as a single file, or to transform a file in other ways on
|
|
||||||
# its way in and out of CVS.
|
|
||||||
#
|
|
||||||
# The -m option specifies whether CVS attempts to merge files.
|
|
||||||
#
|
|
||||||
# The -k option specifies keyword expansion (e.g. -kb for binary).
|
|
||||||
#
|
|
||||||
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
|
|
||||||
#
|
|
||||||
# wildcard [option value][option value]...
|
|
||||||
#
|
|
||||||
# where option is one of
|
|
||||||
# -f from cvs filter value: path to filter
|
|
||||||
# -t to cvs filter value: path to filter
|
|
||||||
# -m update methodology value: MERGE or COPY
|
|
||||||
# -k expansion mode value: b, o, kkv, &c
|
|
||||||
#
|
|
||||||
# and value is a single-quote delimited value.
|
|
||||||
# For example:
|
|
||||||
#*.gif -k 'b'
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# The "editinfo" file is used to allow verification of logging
|
|
||||||
# information. It works best when a template (as specified in the
|
|
||||||
# rcsinfo file) is provided for the logging procedure. Given a
|
|
||||||
# template with locations for, a bug-id number, a list of people who
|
|
||||||
# reviewed the code before it can be checked in, and an external
|
|
||||||
# process to catalog the differences that were code reviewed, the
|
|
||||||
# following test can be applied to the code:
|
|
||||||
#
|
|
||||||
# Making sure that the entered bug-id number is correct.
|
|
||||||
# Validating that the code that was reviewed is indeed the code being
|
|
||||||
# checked in (using the bug-id number or a seperate review
|
|
||||||
# number to identify this particular code set.).
|
|
||||||
#
|
|
||||||
# If any of the above test failed, then the commit would be aborted.
|
|
||||||
#
|
|
||||||
# Actions such as mailing a copy of the report to each reviewer are
|
|
||||||
# better handled by an entry in the loginfo file.
|
|
||||||
#
|
|
||||||
# One thing that should be noted is the the ALL keyword is not
|
|
||||||
# supported. There can be only one entry that matches a given
|
|
||||||
# repository.
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# The "loginfo" file controls where "cvs commit" log information
|
|
||||||
# is sent. The first entry on a line is a regular expression which must match
|
|
||||||
# the directory that the change is being made to, relative to the
|
|
||||||
# $CVSROOT. If a match is found, then the remainder of the line is a filter
|
|
||||||
# program that should expect log information on its standard input.
|
|
||||||
#
|
|
||||||
# If the repository name does not match any of the regular expressions in this
|
|
||||||
# file, the "DEFAULT" line is used, if it is specified.
|
|
||||||
#
|
|
||||||
# If the name ALL appears as a regular expression it is always used
|
|
||||||
# in addition to the first matching regex or DEFAULT.
|
|
||||||
#
|
|
||||||
# You may specify a format string as part of the
|
|
||||||
# filter. The string is composed of a `%' followed
|
|
||||||
# by a single format character, or followed by a set of format
|
|
||||||
# characters surrounded by `{' and `}' as separators. The format
|
|
||||||
# characters are:
|
|
||||||
#
|
|
||||||
# s = file name
|
|
||||||
# V = old version number (pre-checkin)
|
|
||||||
# v = new version number (post-checkin)
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog
|
|
||||||
# or
|
|
||||||
#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
# Three different line formats are valid:
|
|
||||||
# key -a aliases...
|
|
||||||
# key [options] directory
|
|
||||||
# key [options] directory files...
|
|
||||||
#
|
|
||||||
# Where "options" are composed of:
|
|
||||||
# -i prog Run "prog" on "cvs commit" from top-level of module.
|
|
||||||
# -o prog Run "prog" on "cvs checkout" of module.
|
|
||||||
# -e prog Run "prog" on "cvs export" of module.
|
|
||||||
# -t prog Run "prog" on "cvs rtag" of module.
|
|
||||||
# -u prog Run "prog" on "cvs update" of module.
|
|
||||||
# -d dir Place module in directory "dir" instead of module name.
|
|
||||||
# -l Top-level directory only -- do not recurse.
|
|
||||||
#
|
|
||||||
# NOTE: If you change any of the "Run" options above, you'll have to
|
|
||||||
# release and re-checkout any working directories of these modules.
|
|
||||||
#
|
|
||||||
# And "directory" is a path to a directory relative to $CVSROOT.
|
|
||||||
#
|
|
||||||
# The "-a" option specifies an alias. An alias is interpreted as if
|
|
||||||
# everything on the right of the "-a" had been typed on the command line.
|
|
||||||
#
|
|
||||||
# You can encode a module within a module by using the special '&'
|
|
||||||
# character to interpose another module into the current module. This
|
|
||||||
# can be useful for creating a module that consists of many directories
|
|
||||||
# spread out over the entire source repository.
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# The "notify" file controls where notifications from watches set by
|
|
||||||
# "cvs watch add" or "cvs edit" are sent. The first entry on a line is
|
|
||||||
# a regular expression which is tested against the directory that the
|
|
||||||
# change is being made to, relative to the $CVSROOT. If it matches,
|
|
||||||
# then the remainder of the line is a filter program that should contain
|
|
||||||
# one occurrence of %s for the user to notify, and information on its
|
|
||||||
# standard input.
|
|
||||||
#
|
|
||||||
# "ALL" or "DEFAULT" can be used in place of the regular expression.
|
|
||||||
#
|
|
||||||
# For example:
|
|
||||||
#ALL mail %s -s "CVS notification"
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
# The "rcsinfo" file is used to control templates with which the editor
|
|
||||||
# is invoked on commit and import.
|
|
||||||
#
|
|
||||||
# The first entry on a line is a regular expression which is tested
|
|
||||||
# against the directory that the change is being made to, relative to the
|
|
||||||
# $CVSROOT. For the first match that is found, then the remainder of the
|
|
||||||
# line is the name of the file that contains the template.
|
|
||||||
#
|
|
||||||
# If the repository name does not match any of the regular expressions in this
|
|
||||||
# file, the "DEFAULT" line is used, if it is specified.
|
|
||||||
#
|
|
||||||
# If the name "ALL" appears as a regular expression it is always used
|
|
||||||
# in addition to the first matching regex or "DEFAULT".
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# The "taginfo" file is used to control pre-tag checks.
|
|
||||||
# The filter on the right is invoked with the following arguments:
|
|
||||||
#
|
|
||||||
# $1 -- tagname
|
|
||||||
# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d
|
|
||||||
# $3 -- repository
|
|
||||||
# $4-> file revision [file revision ...]
|
|
||||||
#
|
|
||||||
# A non-zero exit of the filter program will cause the tag to be aborted.
|
|
||||||
#
|
|
||||||
# The first entry on a line is a regular expression which is tested
|
|
||||||
# against the directory that the change is being committed to, relative
|
|
||||||
# to the $CVSROOT. For the first match that is found, then the remainder
|
|
||||||
# of the line is the name of the filter to run.
|
|
||||||
#
|
|
||||||
# If the repository name does not match any of the regular expressions in this
|
|
||||||
# file, the "DEFAULT" line is used, if it is specified.
|
|
||||||
#
|
|
||||||
# If the name "ALL" appears as a regular expression it is always used
|
|
||||||
# in addition to the first matching regex or "DEFAULT".
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# The "verifymsg" file is used to allow verification of logging
|
|
||||||
# information. It works best when a template (as specified in the
|
|
||||||
# rcsinfo file) is provided for the logging procedure. Given a
|
|
||||||
# template with locations for, a bug-id number, a list of people who
|
|
||||||
# reviewed the code before it can be checked in, and an external
|
|
||||||
# process to catalog the differences that were code reviewed, the
|
|
||||||
# following test can be applied to the code:
|
|
||||||
#
|
|
||||||
# Making sure that the entered bug-id number is correct.
|
|
||||||
# Validating that the code that was reviewed is indeed the code being
|
|
||||||
# checked in (using the bug-id number or a seperate review
|
|
||||||
# number to identify this particular code set.).
|
|
||||||
#
|
|
||||||
# If any of the above test failed, then the commit would be aborted.
|
|
||||||
#
|
|
||||||
# Actions such as mailing a copy of the report to each reviewer are
|
|
||||||
# better handled by an entry in the loginfo file.
|
|
||||||
#
|
|
||||||
# One thing that should be noted is the the ALL keyword is not
|
|
||||||
# supported. There can be only one entry that matches a given
|
|
||||||
# repository.
|
|
||||||
197
codec/convert.c
197
codec/convert.c
@@ -96,7 +96,7 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx,
|
|||||||
File_h.bfType = (getc(IN) << 8) + File_h.bfType;
|
File_h.bfType = (getc(IN) << 8) + File_h.bfType;
|
||||||
|
|
||||||
if (File_h.bfType != 19778) {
|
if (File_h.bfType != 19778) {
|
||||||
printf("Error, not a BMP file!\n");
|
fprintf(stderr,"Error, not a BMP file!\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
/* FILE HEADER */
|
/* FILE HEADER */
|
||||||
@@ -458,7 +458,7 @@ int bmptoimage(char *filename, j2k_image_t * img, int subsampling_dx,
|
|||||||
not_end_file = 0;
|
not_end_file = 0;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
printf("No Delta supported\n");
|
fprintf(stderr,"No Delta supported\n");
|
||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -556,8 +556,12 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
int w, h, prec;
|
int w, h, prec;
|
||||||
int i, compno, bandno;
|
int i, compno, bandno;
|
||||||
char str[256], endian[16];
|
char str[256];
|
||||||
char sign;
|
|
||||||
|
char endian1,endian2,sign;
|
||||||
|
char signtmp[32];
|
||||||
|
|
||||||
|
char temp[32];
|
||||||
int bigendian;
|
int bigendian;
|
||||||
j2k_comp_t *comp;
|
j2k_comp_t *comp;
|
||||||
|
|
||||||
@@ -569,93 +573,126 @@ int pgxtoimage(char *filename, j2k_image_t * img, int tdy,
|
|||||||
char tmp[16];
|
char tmp[16];
|
||||||
int max = 0;
|
int max = 0;
|
||||||
int Y1;
|
int Y1;
|
||||||
|
|
||||||
|
|
||||||
comp = &img->comps[compno];
|
comp = &img->comps[compno];
|
||||||
sprintf(str, "%s", filename);
|
sprintf(str, "%s", filename);
|
||||||
|
|
||||||
|
|
||||||
f = fopen(str, "rb");
|
f = fopen(str, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "Failed to open %s for reading !\n", str);
|
fprintf(stderr, "Failed to open %s for reading !\n", str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (fscanf(f, "PG %s %c %d %d %d", endian, &sign, &prec, &w, &h) == 5) {
|
|
||||||
fgetc(f);
|
|
||||||
if (!strcmp(endian, "ML"))
|
|
||||||
bigendian = 1;
|
|
||||||
else
|
|
||||||
bigendian = 0;
|
|
||||||
if (compno == 0) {
|
|
||||||
img->x0 = Dim[0];
|
|
||||||
img->y0 = Dim[1];
|
|
||||||
img->x1 =
|
|
||||||
!Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
|
|
||||||
1) *
|
|
||||||
subsampling_dx + 1;
|
|
||||||
img->y1 =
|
|
||||||
!Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
|
|
||||||
1) *
|
|
||||||
subsampling_dy + 1;
|
|
||||||
} else {
|
|
||||||
if (w != img->x1 || h != img->y1)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign == '-') {
|
|
||||||
comp->sgnd = 1;
|
|
||||||
} else {
|
|
||||||
comp->sgnd = 0;
|
|
||||||
}
|
|
||||||
comp->prec = prec;
|
|
||||||
comp->dx = subsampling_dx;
|
|
||||||
comp->dy = subsampling_dy;
|
|
||||||
bandno = 1;
|
|
||||||
|
|
||||||
Y1 = cp.ty0 + bandno * cp.tdy <
|
|
||||||
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
|
|
||||||
Y1 -= img->y0;
|
|
||||||
|
|
||||||
sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
|
fseek(f, 0, SEEK_SET);
|
||||||
src = fopen(tmp, "wb");
|
|
||||||
if (!src) {
|
fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h);
|
||||||
fprintf(stderr, "failed to open %s for writing !\n", tmp);
|
|
||||||
}
|
|
||||||
for (i = 0; i < w * h; i++) {
|
|
||||||
int v;
|
i=0;
|
||||||
if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
|
|
||||||
fclose(src);
|
sign='+';
|
||||||
bandno++;
|
|
||||||
sprintf(tmp, "bandtile%d", bandno);
|
while (signtmp[i]!='\0') {
|
||||||
src = fopen(tmp, "wb");
|
|
||||||
if (!src) {
|
if (signtmp[i]=='-') sign='-';
|
||||||
fprintf(stderr, "failed to open %s for writing !\n", tmp);
|
|
||||||
}
|
i++;
|
||||||
Y1 = cp.ty0 + bandno * cp.tdy <
|
|
||||||
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
|
}
|
||||||
Y1 -= img->y0;
|
|
||||||
}
|
|
||||||
if (comp->prec <= 8) {
|
|
||||||
if (!comp->sgnd) {
|
fgetc(f);
|
||||||
v = readuchar(f);
|
if (endian1=='M' && endian2=='L')
|
||||||
} else {
|
bigendian = 1;
|
||||||
v = (char) readuchar(f);
|
else if (endian2=='M' && endian1=='L')
|
||||||
}
|
bigendian = 0;
|
||||||
} else if (comp->prec <= 16) {
|
|
||||||
if (!comp->sgnd) {
|
else {
|
||||||
v = readushort(f, bigendian);
|
|
||||||
} else {
|
fprintf(stderr, "Bad pgx header, please check input file\n");
|
||||||
v = (short) readushort(f, bigendian);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!comp->sgnd) {
|
|
||||||
v = readuint(f, bigendian);
|
|
||||||
} else {
|
|
||||||
v = (int) readuint(f, bigendian);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (v > max)
|
|
||||||
max = v;
|
|
||||||
fprintf(src, "%d ", v);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (compno == 0) {
|
||||||
|
img->x0 = Dim[0];
|
||||||
|
img->y0 = Dim[1];
|
||||||
|
img->x1 =
|
||||||
|
!Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
|
||||||
|
1) *
|
||||||
|
subsampling_dx + 1;
|
||||||
|
img->y1 =
|
||||||
|
!Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
|
||||||
|
1) *
|
||||||
|
subsampling_dy + 1;
|
||||||
|
} else {
|
||||||
|
if (w != img->x1 || h != img->y1)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sign == '-') {
|
||||||
|
comp->sgnd = 1;
|
||||||
|
} else {
|
||||||
|
comp->sgnd = 0;
|
||||||
|
}
|
||||||
|
comp->prec = prec;
|
||||||
|
comp->dx = subsampling_dx;
|
||||||
|
comp->dy = subsampling_dy;
|
||||||
|
bandno = 1;
|
||||||
|
|
||||||
|
Y1 = cp.ty0 + bandno * cp.tdy <
|
||||||
|
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
|
||||||
|
Y1 -= img->y0;
|
||||||
|
|
||||||
|
sprintf(tmp, "bandtile%d", bandno); /* bandtile file */
|
||||||
|
src = fopen(tmp, "wb");
|
||||||
|
if (!src) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing !\n", tmp);
|
||||||
|
}
|
||||||
|
for (i = 0; i < w * h; i++) {
|
||||||
|
int v;
|
||||||
|
if (i == Y1 * w / subsampling_dy && tdy != -1) { /* bandtile is full */
|
||||||
|
fclose(src);
|
||||||
|
bandno++;
|
||||||
|
sprintf(tmp, "bandtile%d", bandno);
|
||||||
|
src = fopen(tmp, "wb");
|
||||||
|
if (!src) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing !\n", tmp);
|
||||||
|
}
|
||||||
|
Y1 = cp.ty0 + bandno * cp.tdy <
|
||||||
|
img->y1 ? cp.ty0 + bandno * cp.tdy : img->y1;
|
||||||
|
Y1 -= img->y0;
|
||||||
|
}
|
||||||
|
if (comp->prec <= 8) {
|
||||||
|
if (!comp->sgnd) {
|
||||||
|
v = readuchar(f);
|
||||||
|
} else {
|
||||||
|
v = (char) readuchar(f);
|
||||||
|
}
|
||||||
|
} else if (comp->prec <= 16) {
|
||||||
|
if (!comp->sgnd) {
|
||||||
|
v = readushort(f, bigendian);
|
||||||
|
} else {
|
||||||
|
v = (short) readushort(f, bigendian);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!comp->sgnd) {
|
||||||
|
v = readuint(f, bigendian);
|
||||||
|
} else {
|
||||||
|
v = (int) readuint(f, bigendian);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (v > max)
|
||||||
|
max = v;
|
||||||
|
fprintf(src, "%d ", v);
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
fclose(src);
|
fclose(src);
|
||||||
|
|||||||
@@ -26,6 +26,22 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
|
||||||
|
#include <crtdbg.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//MEM
|
||||||
|
|
||||||
#include <openjpeg.h>
|
#include <openjpeg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -40,126 +56,152 @@
|
|||||||
|
|
||||||
void help_display()
|
void help_display()
|
||||||
{
|
{
|
||||||
printf("HELP\n----\n\n");
|
fprintf(stdout,"HELP\n----\n\n");
|
||||||
printf("- the option -help displays the readme.txt file on screen\n\n");
|
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
|
||||||
|
|
||||||
|
|
||||||
printf("List of parameters for the coder JPEG 2000 :\n");
|
fprintf(stdout,"List of parameters for the coder JPEG 2000:\n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf
|
fprintf(stdout,"REMARKS:\n");
|
||||||
("- The markers COD and QCD are writed both of two in the main_header and never appear in the tile_header. The markers in the main header are : SOC SIZ COD QCD COM.\n");
|
fprintf(stdout,"---------\n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf
|
fprintf
|
||||||
("- This coder can encode mega image, a test was made on a 24000x24000 pixels color image. You need enough disk space memory (twice the original) to encode the image. (i.e. for a 1.5 Gb image you need a minimum of 3Gb of disk memory)\n");
|
(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf("REMARKS :\n");
|
(stdout,"COD and QCD never appear in the tile_header.\n");
|
||||||
printf("---------\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf
|
(stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
|
||||||
("* the value of rate enter in the code line is the compression factor !\n");
|
fprintf
|
||||||
printf("exemple :\n");
|
(stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf
|
(stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
|
||||||
("-r 20,10,1 means quality 1 : compress 20x, quality 2 : compress 10x and quality 3 : compress 1x = lossless\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf(stdout,"By default:\n");
|
||||||
printf("By default :\n");
|
fprintf(stdout,"------------\n");
|
||||||
printf("------------\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf(stdout," * Lossless\n");
|
||||||
printf(" * lossless\n");
|
fprintf(stdout," * 1 tile\n");
|
||||||
printf(" * 1 tile\n");
|
fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n");
|
||||||
printf(" * size of precinct 2^15 x 2^15 (means 1 precinct)\n");
|
fprintf(stdout," * Size of code-block : 64 x 64\n");
|
||||||
printf(" * size of code-block 64 x 64\n");
|
fprintf(stdout," * Number of resolutions: 6\n");
|
||||||
printf(" * Number of resolution : 6\n");
|
fprintf(stdout," * No SOP marker in the codestream\n");
|
||||||
printf(" * No SOP marker in the codestream\n");
|
fprintf(stdout," * No EPH marker in the codestream\n");
|
||||||
printf(" * No EPH marker in the codestream\n");
|
fprintf(stdout," * No sub-sampling in x or y direction\n");
|
||||||
printf(" * No sub-sampling in x and y direction\n");
|
fprintf(stdout," * No mode switch activated\n");
|
||||||
printf(" * No mode switch activated\n");
|
fprintf(stdout," * Progression order: LRCP\n");
|
||||||
printf(" * progression order : LRCP\n");
|
fprintf(stdout," * No index file\n");
|
||||||
printf(" * No index file\n");
|
fprintf(stdout," * No ROI upshifted\n");
|
||||||
printf(" * No ROI upshifted\n");
|
fprintf(stdout," * No offset of the origin of the image\n");
|
||||||
printf(" * No offset of the origin of the image\n");
|
fprintf(stdout," * No offset of the origin of the tiles\n");
|
||||||
printf(" * No offset of the origin of the tiles\n");
|
fprintf(stdout," * Reversible DWT 5-3\n");
|
||||||
printf(" * Reversible DWT 5-3\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf(stdout,"Parameters:\n");
|
||||||
printf("Parameters :\n");
|
fprintf(stdout,"------------\n");
|
||||||
printf("------------\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf
|
(stdout,"Required Parameters (except with -h):\n");
|
||||||
("-i : source file (-i source.pnm also *.pgm, *.ppm) required\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf("-o : destination file (-o dest.j2k or .jp2) required\n");
|
(stdout,"-i : source file (-i source.pnm also *.pgm, *.ppm) \n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf("-help : Display the help information optional\n ");
|
fprintf
|
||||||
printf("\n");
|
(stdout,"-o : destination file (-o dest.j2k or .jp2) \n");
|
||||||
printf("-r : different rates (-r 20,10,5) optional\n ");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf("-n : Number of resolution (-n 3) optional\n");
|
(stdout,"Optional Parameters:\n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf("-b : size of code block (-b 32,32) optional\n");
|
fprintf(stdout,"-h : display the help information \n ");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf("-c : size of precinct (-c 128,128) optional\n");
|
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n ");
|
||||||
printf("\n");
|
fprintf(stdout," - The rate specified for each quality level is the desired \n");
|
||||||
printf("-t : size of tile (-t 512,512) optional\n");
|
fprintf(stdout," compression factor.\n");
|
||||||
printf("\n");
|
fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n");
|
||||||
printf
|
fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n");
|
||||||
("-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] optional\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf(stdout," (options -r and -q cannot be used together)\n ");
|
||||||
printf
|
fprintf(stdout,"\n");
|
||||||
("-s : subsampling factor (-s 2,2) [-s X,Y] optional\n");
|
|
||||||
printf("\n");
|
fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n ");
|
||||||
printf
|
|
||||||
("-SOP : write SOP marker before each packet optional\n");
|
fprintf(stdout," (options -r and -q cannot be used together)\n ");
|
||||||
printf("\n");
|
|
||||||
printf
|
fprintf(stdout,"\n");
|
||||||
("-EPH : write EPH marker after each header packet optional\n");
|
fprintf(stdout,"-n : number of resolutions (-n 3) \n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf
|
fprintf(stdout,"-b : size of code block (-b 32,32) \n");
|
||||||
("-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] optional\n");
|
fprintf(stdout,"\n");
|
||||||
printf
|
fprintf(stdout,"-c : size of precinct (-c 128,128) \n");
|
||||||
(" for several mode switch you have to add the value of each mode you want\n");
|
fprintf(stdout,"\n");
|
||||||
printf
|
fprintf(stdout,"-t : size of tile (-t 512,512) \n");
|
||||||
(" ex : RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf
|
(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
|
||||||
("-x : Create an index file *.Idx (-x index_name.Idx) optional\n");
|
fprintf(stdout,"\n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf
|
(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n");
|
||||||
("-ROI:c=%%d,U=%%d : quantization indices upshifted for component c=%%d [%%d = 0,1,2]\n");
|
fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n");
|
||||||
printf
|
fprintf(stdout,"\n");
|
||||||
(" with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) optional\n");
|
fprintf
|
||||||
printf("\n");
|
(stdout,"-SOP : write SOP marker before each packet \n");
|
||||||
printf
|
fprintf(stdout,"\n");
|
||||||
("-d : offset of the origin of the image (-d 150,300) optional\n");
|
fprintf
|
||||||
printf("\n");
|
(stdout,"-EPH : write EPH marker after each header packet \n");
|
||||||
printf
|
fprintf(stdout,"\n");
|
||||||
("-T : offset of the origin of the tiles (-T 100,75) optional\n");
|
fprintf
|
||||||
printf("\n");
|
(stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
|
||||||
printf("-I : Use the irreversible DWT 9-7 (-I) optional\n");
|
fprintf
|
||||||
printf("\n");
|
(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n");
|
||||||
printf("IMPORTANT :\n");
|
fprintf
|
||||||
printf("-----------\n");
|
(stdout," Indicate multiple modes by adding their values. \n");
|
||||||
printf("\n");
|
fprintf
|
||||||
printf("* subsampling bigger than 2 can produce error\n");
|
(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf("The index file respect the structure below :\n");
|
fprintf
|
||||||
printf("---------------------------------------------\n");
|
(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
|
||||||
printf("\n");
|
fprintf(stdout,"\n");
|
||||||
printf("Image_height Image_width\n");
|
fprintf
|
||||||
printf("progression order\n");
|
(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
|
||||||
printf("Tiles_size_X Tiles_size_Y\n");
|
fprintf
|
||||||
printf("Components_nb\n");
|
(stdout," for component c=%%d [%%d = 0,1,2]\n");
|
||||||
printf("Layers_nb\n");
|
fprintf
|
||||||
printf("decomposition_levels\n");
|
(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n");
|
||||||
printf("Precincts_size_X Precincts_size_Y\n");
|
fprintf(stdout,"\n");
|
||||||
printf("Main_header_end_position\n");
|
fprintf
|
||||||
printf("Codestream_size\n");
|
(stdout,"-d : offset of the origin of the image (-d 150,300) \n");
|
||||||
printf("Tile0 start_pos end_Theader end_pos\n");
|
fprintf(stdout,"\n");
|
||||||
printf("Tile1 '' '' ''\n");
|
fprintf
|
||||||
printf("...\n");
|
(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n");
|
||||||
printf("TileN '' '' ''\n");
|
fprintf(stdout,"\n");
|
||||||
printf("Tpacket_0 Tile layer res. comp. prec. start_pos end_pos\n");
|
fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n");
|
||||||
printf("...\n");
|
fprintf(stdout,"\n");
|
||||||
printf("Tpacket_M '' '' '' '' '' '' ''\n");
|
fprintf(stdout,"IMPORTANT:\n");
|
||||||
|
fprintf(stdout,"-----------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"The index file has the structure below:\n");
|
||||||
|
fprintf(stdout,"---------------------------------------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"Image_height Image_width\n");
|
||||||
|
fprintf(stdout,"progression order\n");
|
||||||
|
fprintf(stdout,"Tiles_size_X Tiles_size_Y\n");
|
||||||
|
fprintf(stdout,"Components_nb\n");
|
||||||
|
fprintf(stdout,"Layers_nb\n");
|
||||||
|
fprintf(stdout,"decomposition_levels\n");
|
||||||
|
fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
|
||||||
|
fprintf(stdout," [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
|
||||||
|
fprintf(stdout,"Main_header_end_position\n");
|
||||||
|
fprintf(stdout,"Codestream_size\n");
|
||||||
|
fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
|
||||||
|
fprintf(stdout,"Tile_1 '' '' '' '' '' ''\n");
|
||||||
|
fprintf(stdout,"...\n");
|
||||||
|
fprintf(stdout,"Tile_Nt '' '' '' '' '' ''\n");
|
||||||
|
fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
|
||||||
|
fprintf(stdout,"...\n");
|
||||||
|
fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n");
|
||||||
|
|
||||||
|
fprintf(stdout,"MaxDisto\n");
|
||||||
|
|
||||||
|
fprintf(stdout,"TotalDisto\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int give_progression(char progression[4])
|
int give_progression(char progression[4])
|
||||||
@@ -208,12 +250,13 @@ int floorlog2(int a)
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
void encode_stepsize(int stepsize, int numbps, int *expn, int *mant)
|
void encode_stepsize(float stepsize, int numbps, int *expn, int *mant)
|
||||||
{
|
{
|
||||||
int p, n;
|
int p, n, stepsizeTMP;
|
||||||
p = floorlog2(stepsize) - 13;
|
stepsizeTMP=(int) floor(stepsize * 8192.0);
|
||||||
n = 11 - floorlog2(stepsize);
|
p = floorlog2(stepsizeTMP) - 13;
|
||||||
*mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
|
n = 11 - floorlog2(stepsizeTMP);
|
||||||
|
*mant = (n < 0 ? stepsizeTMP >> -n : stepsizeTMP << n) & 0x7ff;
|
||||||
*expn = numbps - p;
|
*expn = numbps - p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,7 +265,7 @@ void calc_explicit_stepsizes(j2k_tccp_t * tccp, int prec)
|
|||||||
int numbands, bandno;
|
int numbands, bandno;
|
||||||
numbands = 3 * tccp->numresolutions - 2;
|
numbands = 3 * tccp->numresolutions - 2;
|
||||||
for (bandno = 0; bandno < numbands; bandno++) {
|
for (bandno = 0; bandno < numbands; bandno++) {
|
||||||
double stepsize;
|
float stepsize;
|
||||||
|
|
||||||
int resno, level, orient, gain;
|
int resno, level, orient, gain;
|
||||||
resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
|
resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
|
||||||
@@ -238,7 +281,7 @@ void calc_explicit_stepsizes(j2k_tccp_t * tccp, int prec)
|
|||||||
double norm = dwt_norms_97[orient][level];
|
double norm = dwt_norms_97[orient][level];
|
||||||
stepsize = (1 << (gain + 1)) / norm;
|
stepsize = (1 << (gain + 1)) / norm;
|
||||||
}
|
}
|
||||||
encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
|
encode_stepsize(stepsize, prec + gain,
|
||||||
&tccp->stepsizes[bandno].expn,
|
&tccp->stepsizes[bandno].expn,
|
||||||
&tccp->stepsizes[bandno].mant);
|
&tccp->stepsizes[bandno].mant);
|
||||||
}
|
}
|
||||||
@@ -276,8 +319,10 @@ int main(int argc, char **argv)
|
|||||||
int ir = 0;
|
int ir = 0;
|
||||||
int res_spec = 0; /* For various precinct sizes specification */
|
int res_spec = 0; /* For various precinct sizes specification */
|
||||||
char sep;
|
char sep;
|
||||||
char *outbuf;
|
char *j2k_codestream;
|
||||||
|
char *jp2_codestream;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
int depth_0, sign, depth;
|
||||||
|
|
||||||
|
|
||||||
/* default value */
|
/* default value */
|
||||||
@@ -311,7 +356,7 @@ int main(int argc, char **argv)
|
|||||||
tcp_init = &cp_init.tcps[0];
|
tcp_init = &cp_init.tcps[0];
|
||||||
tcp_init->numlayers = 0;
|
tcp_init->numlayers = 0;
|
||||||
|
|
||||||
cp.intermed_file=1;
|
cp.intermed_file = 1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int c = getopt(argc, argv,
|
int c = getopt(argc, argv,
|
||||||
@@ -334,7 +379,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
|
if ((S1 == 'p' && S2 == 'g' && S3 == 'x')
|
||||||
|| (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
|
|| (S1 == 'P' && S2 == 'G' && S3 == 'X')) {
|
||||||
cp.image_type = 0;
|
cp.decod_format = PGX_DFMT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,13 +391,13 @@ int main(int argc, char **argv)
|
|||||||
|| (S1 == 'P' && S2 == 'P' && S3 == 'M') || (S1 == 'p'
|
|| (S1 == 'P' && S2 == 'P' && S3 == 'M') || (S1 == 'p'
|
||||||
&& S2 == 'p'
|
&& S2 == 'p'
|
||||||
&& S3 == 'm')) {
|
&& S3 == 'm')) {
|
||||||
cp.image_type = 1;
|
cp.decod_format = PXM_DFMT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
|
if ((S1 == 'b' && S2 == 'm' && S3 == 'p')
|
||||||
|| (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
|
|| (S1 == 'B' && S2 == 'M' && S3 == 'P')) {
|
||||||
cp.image_type = 2;
|
cp.decod_format = BMP_DFMT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -372,26 +417,29 @@ int main(int argc, char **argv)
|
|||||||
S2 = *outfile;
|
S2 = *outfile;
|
||||||
outfile--;
|
outfile--;
|
||||||
S1 = *outfile;
|
S1 = *outfile;
|
||||||
|
|
||||||
outfile = optarg;
|
outfile = optarg;
|
||||||
|
|
||||||
if ((S1 == 'j' && S2 == '2' && S3 == 'k') || (S1 == 'J' && S2 == '2' && S3 == 'K'))
|
if ((S1 == 'j' && S2 == '2' && S3 == 'k')
|
||||||
cp.JPEG2000_format=0;
|
|| (S1 == 'J' && S2 == '2' && S3 == 'K'))
|
||||||
else if ((S1 == 'j' && S2 == 'p' && S3 == '2') || (S1 == 'J' && S2 == 'P' && S3 == '2'))
|
cp.cod_format = J2K_CFMT;
|
||||||
cp.JPEG2000_format=1;
|
else if ((S1 == 'j' && S2 == 'p' && S3 == '2')
|
||||||
else {
|
|| (S1 == 'J' && S2 == 'P' && S3 == '2'))
|
||||||
fprintf(stderr,"Unknown output format image *.%c%c%c [only *.j2k, *.jp2]!! \n",S1,S2,S3);
|
cp.cod_format = JP2_CFMT;
|
||||||
|
else {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unknown output format image *.%c%c%c [only *.j2k, *.jp2]!! \n",
|
||||||
|
S1, S2, S3);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
case 'r': /* rates rates/distorsion */
|
case 'r': /* rates rates/distorsion */
|
||||||
s = optarg;
|
s = optarg;
|
||||||
while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers])
|
while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers]) == 1) {
|
||||||
== 1) {
|
|
||||||
tcp_init->numlayers++;
|
tcp_init->numlayers++;
|
||||||
while (*s && *s != ',') {
|
while (*s && *s != ',') {
|
||||||
s++;
|
s++;
|
||||||
@@ -406,8 +454,8 @@ int main(int argc, char **argv)
|
|||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
case 'q': /* add fixed_quality */
|
case 'q': /* add fixed_quality */
|
||||||
s = optarg;
|
s = optarg;
|
||||||
while (sscanf(s, "%f", &tcp_init->distoratio[tcp_init->numlayers]) ==
|
while (sscanf(s, "%f", &tcp_init->distoratio[tcp_init->numlayers])
|
||||||
1) {
|
== 1) {
|
||||||
tcp_init->numlayers++;
|
tcp_init->numlayers++;
|
||||||
while (*s && *s != ',') {
|
while (*s && *s != ',') {
|
||||||
s++;
|
s++;
|
||||||
@@ -476,7 +524,8 @@ int main(int argc, char **argv)
|
|||||||
CSty |= 0x01;
|
CSty |= 0x01;
|
||||||
res_spec++;
|
res_spec++;
|
||||||
s = strpbrk(s, "]") + 2;
|
s = strpbrk(s, "]") + 2;
|
||||||
} while (sep == ',');
|
}
|
||||||
|
while (sep == ',');
|
||||||
break;
|
break;
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
case 'b': /* code-block dimension */
|
case 'b': /* code-block dimension */
|
||||||
@@ -510,8 +559,7 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
/* ----------------------------------------------------- */
|
/* ----------------------------------------------------- */
|
||||||
case 's': /* subsampling factor */
|
case 's': /* subsampling factor */
|
||||||
if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy)
|
if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy) != 2) {
|
||||||
!= 2) {
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"'-s' sub-sampling argument error ! [-s dx,dy]\n");
|
"'-s' sub-sampling argument error ! [-s dx,dy]\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -609,15 +657,16 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cp.disto_alloc || cp.fixed_alloc || cp.fixed_quality)&&(!(cp.disto_alloc ^ cp.fixed_alloc ^ cp.fixed_quality))) {
|
if ((cp.disto_alloc || cp.fixed_alloc || cp.fixed_quality)
|
||||||
|
&& (!(cp.disto_alloc ^ cp.fixed_alloc ^ cp.fixed_quality))) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Error: options -r -q and -f can not be used together !!\n");
|
"Error: options -r -q and -f cannot be used together !!\n");
|
||||||
return 1;
|
return 1;
|
||||||
} // mod fixed_quality
|
} // mod fixed_quality
|
||||||
|
|
||||||
/* if no rate entered, lossless by default */
|
/* if no rate entered, lossless by default */
|
||||||
if (tcp_init->numlayers == 0) {
|
if (tcp_init->numlayers == 0) {
|
||||||
tcp_init->rates[tcp_init->numlayers] = 1;
|
tcp_init->rates[0] = 0; //MOD antonin : losslessbug
|
||||||
tcp_init->numlayers++;
|
tcp_init->numlayers++;
|
||||||
cp.disto_alloc = 1;
|
cp.disto_alloc = 1;
|
||||||
}
|
}
|
||||||
@@ -637,12 +686,12 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cp.image_type) {
|
switch (cp.decod_format) {
|
||||||
case 0:
|
case PGX_DFMT:
|
||||||
if (Tile_arg) {
|
if (Tile_arg) {
|
||||||
if (!pgxtoimage
|
if (!pgxtoimage
|
||||||
(infile, &img, cp.tdy, subsampling_dx, subsampling_dy, Dim,
|
(infile, &img, cp.tdy, subsampling_dx, subsampling_dy, Dim, cp))
|
||||||
cp)) {
|
{
|
||||||
fprintf(stderr, "not a pgx file\n");
|
fprintf(stderr, "not a pgx file\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -655,14 +704,14 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case PXM_DFMT:
|
||||||
if (!pnmtoimage(infile, &img, subsampling_dx, subsampling_dy, Dim)) {
|
if (!pnmtoimage(infile, &img, subsampling_dx, subsampling_dy, Dim)) {
|
||||||
fprintf(stderr, " not a pnm file\n");
|
fprintf(stderr, " not a pnm file\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case BMP_DFMT:
|
||||||
if (!bmptoimage(infile, &img, subsampling_dx, subsampling_dy, Dim)) {
|
if (!bmptoimage(infile, &img, subsampling_dx, subsampling_dy, Dim)) {
|
||||||
fprintf(stderr, " not a bmp file\n");
|
fprintf(stderr, " not a bmp file\n");
|
||||||
return 1;
|
return 1;
|
||||||
@@ -688,10 +737,11 @@ int main(int argc, char **argv)
|
|||||||
cp.tdx = img.x1 - cp.tx0;
|
cp.tdx = img.x1 - cp.tx0;
|
||||||
cp.tdy = img.y1 - cp.ty0;
|
cp.tdy = img.y1 - cp.ty0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialization for PPM marker */
|
/* Initialization for PPM marker */
|
||||||
cp.ppm = 0;
|
cp.ppm = 0;
|
||||||
cp.ppm_data = NULL;
|
cp.ppm_data = NULL;
|
||||||
|
cp.ppm_data_first = NULL;
|
||||||
cp.ppm_previous = 0;
|
cp.ppm_previous = 0;
|
||||||
cp.ppm_store = 0;
|
cp.ppm_store = 0;
|
||||||
|
|
||||||
@@ -703,7 +753,7 @@ int main(int argc, char **argv)
|
|||||||
tcp = &cp.tcps[tileno];
|
tcp = &cp.tcps[tileno];
|
||||||
tcp->numlayers = tcp_init->numlayers;
|
tcp->numlayers = tcp_init->numlayers;
|
||||||
for (j = 0; j < tcp->numlayers; j++) {
|
for (j = 0; j < tcp->numlayers; j++) {
|
||||||
if (cp.fixed_quality) // add fixed_quality
|
if (cp.fixed_quality) // add fixed_quality
|
||||||
tcp->distoratio[j] = tcp_init->distoratio[j];
|
tcp->distoratio[j] = tcp_init->distoratio[j];
|
||||||
else
|
else
|
||||||
tcp->rates[j] = tcp_init->rates[j];
|
tcp->rates[j] = tcp_init->rates[j];
|
||||||
@@ -713,6 +763,7 @@ int main(int argc, char **argv)
|
|||||||
tcp->mct = img.numcomps == 3 ? 1 : 0;
|
tcp->mct = img.numcomps == 3 ? 1 : 0;
|
||||||
tcp->ppt = 0;
|
tcp->ppt = 0;
|
||||||
tcp->ppt_data = NULL;
|
tcp->ppt_data = NULL;
|
||||||
|
tcp->ppt_data_first = NULL;
|
||||||
tcp->ppt_store = 0;
|
tcp->ppt_store = 0;
|
||||||
|
|
||||||
numpocs_tile = 0;
|
numpocs_tile = 0;
|
||||||
@@ -779,7 +830,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
/*printf("\nsize precinct pour level %d : %d,%d\n", j,
|
/*printf("\nsize precinct pour level %d : %d,%d\n", j,
|
||||||
tccp->prcw[j], tccp->prch[j]);*/
|
tccp->prcw[j], tccp->prch[j]); */
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (j = 0; j < tccp->numresolutions; j++) {
|
for (j = 0; j < tccp->numresolutions; j++) {
|
||||||
@@ -791,71 +842,123 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cp.JPEG2000_format==0) { /* J2K format output */
|
|
||||||
if (cp.intermed_file==1) { /* After the encoding of each tile, j2k_encode
|
|
||||||
stores the data in the file*/
|
if (cp.cod_format == J2K_CFMT) { /* J2K format output */
|
||||||
|
if (cp.intermed_file == 1) { /* After the encoding of each tile, j2k_encode
|
||||||
|
stores the data in the file */
|
||||||
len = j2k_encode(&img, &cp, outfile, cp.tdx * cp.tdy * 2, index);
|
len = j2k_encode(&img, &cp, outfile, cp.tdx * cp.tdy * 2, index);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
fprintf(stderr, "failed to encode image\n");
|
fprintf(stderr, "failed to encode image\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
j2k_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
outbuf = (char *) malloc( cp.tdx * cp.tdy * cp.tw * cp.th * 2); /* Allocate memory for all tiles */
|
/* Allocate memory for all tiles */
|
||||||
cio_init(outbuf, cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
cio_init(j2k_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
len = j2k_encode(&img, &cp, outbuf, cp.tdx * cp.tdy * cp.tw * cp.th * 2, index);
|
len =
|
||||||
|
j2k_encode(&img, &cp, j2k_codestream,
|
||||||
|
cp.tdx * cp.tdy * cp.tw * cp.th * 2, index);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
fprintf(stderr, "failed to encode image\n");
|
fprintf(stderr, "failed to encode image\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
f = fopen(outfile, "wb");
|
f = fopen(outfile, "wb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
fwrite(outbuf, 1, len, f);
|
fwrite(j2k_codestream, 1, len, f);
|
||||||
free(outbuf);
|
free(j2k_codestream);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
} else { /* JP2 format output */
|
||||||
else /* JP2 format output */
|
jp2_struct_t *jp2_struct;
|
||||||
{
|
|
||||||
jp2_struct_t * jp2_struct;
|
|
||||||
jp2_struct = (jp2_struct_t *) malloc(sizeof(jp2_struct_t));
|
|
||||||
jp2_struct->image = &img;
|
|
||||||
|
|
||||||
/* Initialising the standard JP2 box content*/
|
|
||||||
/* If you wish to modify those boxes, you have to modify the jp2_struct content*/
|
|
||||||
if (jp2_init_stdjp2(jp2_struct, &img))
|
|
||||||
{
|
|
||||||
fprintf(stderr,"Error with jp2 initialization");
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (cp.intermed_file==1) {
|
if (cp.intermed_file == 1) {
|
||||||
/*For the moment, JP2 format does not use intermediary files for each tile*/
|
/*For the moment, JP2 format does not use intermediary
|
||||||
cp.intermed_file=0;
|
files for each tile */
|
||||||
|
cp.intermed_file = 0;
|
||||||
}
|
}
|
||||||
outbuf = (char *) malloc( cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
j2k_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
cio_init(outbuf, cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
jp2_codestream = (char *) malloc(cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
len = jp2_encode(jp2_struct, &cp, outbuf, index);
|
|
||||||
|
cio_init(j2k_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
|
len = j2k_encode(&img, &cp, j2k_codestream,
|
||||||
|
cp.tdx * cp.tdy * cp.tw * cp.th * 2, index);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
fprintf(stderr, "failed to encode image\n");
|
fprintf(stderr, "failed to encode image\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
f = fopen(outfile, "wb");
|
|
||||||
if (!f) {
|
jp2_struct = (jp2_struct_t *) malloc(sizeof(jp2_struct_t));
|
||||||
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
jp2_struct->image = &img;
|
||||||
return 1;
|
jp2_struct->j2k_codestream_len = len;
|
||||||
|
|
||||||
|
/* Initialising the standard JP2 box content */
|
||||||
|
/* If you wish to modify those boxes, you have to modify
|
||||||
|
the jp2_struct content */
|
||||||
|
|
||||||
|
jp2_struct->numcomps = img.numcomps; // NC
|
||||||
|
|
||||||
|
if (jp2_init_stdjp2(jp2_struct)) {
|
||||||
|
fprintf(stderr, "Error with jp2 initialization");
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
jp2_struct->h = img.y1 - img.y0; // HEIGHT
|
||||||
|
jp2_struct->w = img.x1 - img.x0; // WIDTH
|
||||||
|
|
||||||
|
depth_0 = img.comps[0].prec - 1;
|
||||||
|
sign = img.comps[0].sgnd;
|
||||||
|
jp2_struct->bpc = depth_0 + (sign << 7);
|
||||||
|
|
||||||
|
for (i = 1; i < img.numcomps; i++) {
|
||||||
|
depth = img.comps[i].prec - 1;
|
||||||
|
sign = img.comps[i].sgnd;
|
||||||
|
if (depth_0 != depth)
|
||||||
|
jp2_struct->bpc = 255;
|
||||||
}
|
}
|
||||||
fwrite(outbuf, 1, len, f);
|
|
||||||
free(outbuf);
|
for (i = 0; i < img.numcomps; i++)
|
||||||
|
jp2_struct->comps[i].bpcc =
|
||||||
|
img.comps[i].prec - 1 + (img.comps[i].sgnd << 7);
|
||||||
|
|
||||||
|
if ((img.numcomps == 1 || img.numcomps == 3)
|
||||||
|
&& (jp2_struct->bpc != 255))
|
||||||
|
jp2_struct->meth = 1;
|
||||||
|
else
|
||||||
|
jp2_struct->meth = 2;
|
||||||
|
|
||||||
|
if (jp2_struct->meth == 1) {
|
||||||
|
if (img.color_space == 1)
|
||||||
|
jp2_struct->enumcs = 16;
|
||||||
|
else if (img.color_space == 2)
|
||||||
|
jp2_struct->enumcs = 17;
|
||||||
|
else if (img.color_space == 3)
|
||||||
|
jp2_struct->enumcs = 18; // YUV
|
||||||
|
} else
|
||||||
|
jp2_struct->enumcs = 0; // PROFILE (??)
|
||||||
|
|
||||||
|
cio_init(jp2_codestream, cp.tdx * cp.tdy * cp.tw * cp.th * 2);
|
||||||
|
len = jp2_wrap_j2k(jp2_struct, j2k_codestream, jp2_codestream);
|
||||||
|
f = fopen(outfile, "wb");
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fwrite(jp2_codestream, 1, len, f);
|
||||||
|
free(jp2_codestream);
|
||||||
|
free(j2k_codestream);
|
||||||
|
free(jp2_struct->comps);
|
||||||
|
free(jp2_struct->cl);
|
||||||
|
free(jp2_struct);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove the temporary files */
|
/* Remove the temporary files */
|
||||||
/* -------------------------- */
|
/* -------------------------- */
|
||||||
if (cp.image_type) { /* PNM PGM PPM */
|
if (cp.decod_format != PGX_DFMT) { /* PNM PGM PPM or BMP */
|
||||||
for (i = 0; i < img.numcomps; i++) {
|
for (i = 0; i < img.numcomps; i++) {
|
||||||
char tmp;
|
char tmp;
|
||||||
sprintf(&tmp, "Compo%d", i);
|
sprintf(&tmp, "Compo%d", i);
|
||||||
@@ -877,11 +980,25 @@ int main(int argc, char **argv)
|
|||||||
/* Free memory */
|
/* Free memory */
|
||||||
free(img.comps);
|
free(img.comps);
|
||||||
free(cp_init.tcps);
|
free(cp_init.tcps);
|
||||||
if (tcp_init->numlayers > 9) free(cp.matrice);
|
if (tcp_init->numlayers > 9)
|
||||||
|
free(cp.matrice);
|
||||||
for (tileno = 0; tileno < cp.tw * cp.th; tileno++)
|
for (tileno = 0; tileno < cp.tw * cp.th; tileno++)
|
||||||
free(cp.tcps[tileno].tccps);
|
free(cp.tcps[tileno].tccps);
|
||||||
free(cp.tcps);
|
free(cp.tcps);
|
||||||
|
|
||||||
system("pause");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//MEM
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +0,0 @@
|
|||||||
CC = gcc
|
|
||||||
|
|
||||||
LDFLAGS = -lm
|
|
||||||
CFLAGS = -Wall
|
|
||||||
|
|
||||||
all: index_create
|
|
||||||
|
|
||||||
|
|
||||||
bio.o : bio.c bio.h
|
|
||||||
cio.o : cio.c cio.h
|
|
||||||
int.o : int.c
|
|
||||||
pi.o : pi.c pi.h int.h
|
|
||||||
index_create.o : index_create.c j2k.h cio.h tcd.h int.h
|
|
||||||
t2.o : t2.c t2.h tcd.h bio.h j2k.h pi.h tgt.h int.h cio.h
|
|
||||||
tgt.o : tgt.c bio.h tgt.h
|
|
||||||
tcd.o : tcd.c tcd.h t2.h int.h
|
|
||||||
jpip.o : jpip.c j2k.h cio.h tcd.h int.h
|
|
||||||
jp2.o : jp2.c j2k.h cio.h tcd.h int.h
|
|
||||||
|
|
||||||
index_create : bio.o cio.o int.o pi.o t2.o tgt.o tcd.o index_create.o jpip.o jp2.o
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -rf *.o *.*~ *~ core.*
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bio.h"
|
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
static unsigned char *bio_start, *bio_end, *bio_bp;
|
|
||||||
static unsigned int bio_buf;
|
|
||||||
static int bio_ct;
|
|
||||||
|
|
||||||
extern jmp_buf j2k_error;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of bytes written.
|
|
||||||
/// </summary>
|
|
||||||
int bio_numbytes() {
|
|
||||||
return bio_bp-bio_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Init decoder.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="bp">Input buffer</param>
|
|
||||||
/// <param name="len">Input buffer length</param>
|
|
||||||
void bio_init_dec(unsigned char *bp, int len) {
|
|
||||||
bio_start=bp;
|
|
||||||
bio_end=bp+len;
|
|
||||||
bio_bp=bp;
|
|
||||||
bio_buf=0;
|
|
||||||
bio_ct=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bio_byteout()
|
|
||||||
{
|
|
||||||
bio_buf = (bio_buf << 8) & 0xffff;
|
|
||||||
bio_ct = bio_buf == 0xff00 ? 7 : 8;
|
|
||||||
if (bio_bp >= bio_end)
|
|
||||||
return 1;
|
|
||||||
*bio_bp++ = bio_buf >> 8;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read byte.
|
|
||||||
/// </summary>
|
|
||||||
int bio_bytein() {
|
|
||||||
bio_buf=(bio_buf<<8)&0xffff;
|
|
||||||
bio_ct=bio_buf==0xff00?7:8;
|
|
||||||
if (bio_bp>=bio_end) return 1; //longjmp(j2k_error, 1);
|
|
||||||
bio_buf|=*bio_bp++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read bit.
|
|
||||||
/// </summary>
|
|
||||||
int bio_getbit() {
|
|
||||||
if (bio_ct==0) {
|
|
||||||
bio_bytein();
|
|
||||||
}
|
|
||||||
bio_ct--;
|
|
||||||
return (bio_buf>>bio_ct)&1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read bits.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="n">Number of bits to read</param>
|
|
||||||
int bio_read(int n) {
|
|
||||||
int i, v;
|
|
||||||
v=0;
|
|
||||||
for (i=n-1; i>=0; i--) {
|
|
||||||
v+=bio_getbit()<<i;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Flush bits.
|
|
||||||
/// </summary>
|
|
||||||
int bio_flush() {
|
|
||||||
bio_ct=0;
|
|
||||||
bio_byteout();
|
|
||||||
if (bio_ct==7) {
|
|
||||||
bio_ct=0;
|
|
||||||
if ( bio_byteout()) return 1;;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// </summary>
|
|
||||||
int bio_inalign() {
|
|
||||||
bio_ct=0;
|
|
||||||
if ((bio_buf&0xff)==0xff) {
|
|
||||||
if( bio_bytein()) return 1;
|
|
||||||
bio_ct=0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __BIO_H
|
|
||||||
#define __BIO_H
|
|
||||||
|
|
||||||
int bio_numbytes();
|
|
||||||
void bio_init_dec(unsigned char *bp, int len);
|
|
||||||
int bio_read(int n);
|
|
||||||
int bio_flush();
|
|
||||||
int bio_inalign();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "cio.h"
|
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
static unsigned char *cio_start, *cio_end, *cio_bp;
|
|
||||||
|
|
||||||
extern jmp_buf j2k_error;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of bytes written.
|
|
||||||
/// </summary>
|
|
||||||
int cio_numbytes() {
|
|
||||||
return cio_bp-cio_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get position in byte stream.
|
|
||||||
/// </summary>
|
|
||||||
int cio_tell() {
|
|
||||||
return cio_bp-cio_start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set position in byte stream.
|
|
||||||
/// </summary>
|
|
||||||
void cio_seek(int pos) {
|
|
||||||
cio_bp=cio_start+pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Number of bytes left before the end of the stream.
|
|
||||||
/// </summary>
|
|
||||||
int cio_numbytesleft() {
|
|
||||||
return cio_end-cio_bp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get pointer to the current position in the stream.
|
|
||||||
/// </summary>
|
|
||||||
unsigned char *cio_getbp() {
|
|
||||||
return cio_bp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initialize byte IO.
|
|
||||||
/// </summary>
|
|
||||||
void cio_init(unsigned char *bp, int len) {
|
|
||||||
cio_start=bp;
|
|
||||||
cio_end=bp+len;
|
|
||||||
cio_bp=bp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Write a byte.
|
|
||||||
/// </summary>
|
|
||||||
void cio_byteout(unsigned char v) {
|
|
||||||
if (cio_bp>=cio_end) longjmp(j2k_error, 1);
|
|
||||||
*cio_bp++=v;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read a byte.
|
|
||||||
/// </summary>
|
|
||||||
unsigned char cio_bytein() {
|
|
||||||
if (cio_bp>=cio_end) longjmp(j2k_error, 1);
|
|
||||||
return *cio_bp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Write a byte.
|
|
||||||
/// </summary>
|
|
||||||
//void cio_write(unsigned int v, int n) {
|
|
||||||
void cio_write(long long v, int n) {
|
|
||||||
int i;
|
|
||||||
for (i=n-1; i>=0; i--)
|
|
||||||
{
|
|
||||||
cio_byteout((unsigned char)((v>>(i<<3))&0xff));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Read some bytes.
|
|
||||||
/// </summary>
|
|
||||||
/* unsigned int cio_read(int n) { */
|
|
||||||
long long cio_read(int n) {
|
|
||||||
int i;
|
|
||||||
/*unsigned int v;*/
|
|
||||||
long long v;
|
|
||||||
v=0;
|
|
||||||
for (i=n-1; i>=0; i--) {
|
|
||||||
v+=cio_bytein()<<(i<<3);
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Write some bytes.
|
|
||||||
/// </summary>
|
|
||||||
void cio_skip(int n) {
|
|
||||||
cio_bp+=n;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __CIO_H
|
|
||||||
#define __CIO_H
|
|
||||||
|
|
||||||
int cio_tell();
|
|
||||||
void cio_seek(int pos);
|
|
||||||
int cio_numbytes();
|
|
||||||
int cio_numbytesleft();
|
|
||||||
unsigned char *cio_getbp();
|
|
||||||
void cio_init(unsigned char *bp, int len);
|
|
||||||
/* void cio_write(unsigned int v, int n); */
|
|
||||||
void cio_write(long long v, int n);
|
|
||||||
/* unsigned int cio_read(int n); */
|
|
||||||
long long cio_read(int n);
|
|
||||||
void cio_skip(int n);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "fix.h"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define int64 __int64
|
|
||||||
#else
|
|
||||||
#define int64 long long
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Multiply two fixed-precision rational numbers.
|
|
||||||
/// </summary>
|
|
||||||
int fix_mul(int a, int b) {
|
|
||||||
return (int)((int64)a*(int64)b>>13);
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __FIX_H
|
|
||||||
#define __FIX_H
|
|
||||||
|
|
||||||
int fix_mul(int a, int b);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,89 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the minimum of two integers.
|
|
||||||
/// </summary>
|
|
||||||
int int_min(int a, int b) {
|
|
||||||
return a<b?a:b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get the maximum of two integers.
|
|
||||||
/// </summary>
|
|
||||||
int int_max(int a, int b) {
|
|
||||||
return a>b?a:b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clamp an integer inside an interval.
|
|
||||||
/// </summary>
|
|
||||||
int int_clamp(int a, int min, int max) {
|
|
||||||
if (a<min) return min;
|
|
||||||
if (a>max) return max;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get absolute value of integer.
|
|
||||||
/// </summary>
|
|
||||||
int int_abs(int a) {
|
|
||||||
return a<0?-a:a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide an integer and round upwards.
|
|
||||||
/// </summary>
|
|
||||||
int int_ceildiv(int a, int b) {
|
|
||||||
return (a+b-1)/b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide an integer by a power of 2 and round upwards.
|
|
||||||
/// </summary>
|
|
||||||
int int_ceildivpow2(int a, int b) {
|
|
||||||
return (a+(1<<b)-1)>>b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Divide an integer by a power of 2 and round downwards.
|
|
||||||
/// </summary>
|
|
||||||
int int_floordivpow2(int a, int b) {
|
|
||||||
return a>>b;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Get logarithm of an integer and round downwards.
|
|
||||||
/// </summary>
|
|
||||||
int int_floorlog2(int a) {
|
|
||||||
int l;
|
|
||||||
for (l=0; a>1; l++) {
|
|
||||||
a>>=1;
|
|
||||||
}
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __INT_H
|
|
||||||
#define __INT_H
|
|
||||||
|
|
||||||
int int_min(int a, int b);
|
|
||||||
int int_max(int a, int b);
|
|
||||||
int int_clamp(int a, int min, int max);
|
|
||||||
int int_abs(int a);
|
|
||||||
int int_ceildiv(int a, int b);
|
|
||||||
int int_ceildivpow2(int a, int b);
|
|
||||||
int int_floordivpow2(int a, int b);
|
|
||||||
int int_floorlog2(int a);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,288 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define VERSION "0.0.8"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#ifdef LIBJ2K_EXPORTS
|
|
||||||
#define LIBJ2K_API __declspec(dllexport)
|
|
||||||
#else
|
|
||||||
#define LIBJ2K_API __declspec(dllimport)
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define LIBJ2K_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef __J2K_H
|
|
||||||
#define __J2K_H
|
|
||||||
|
|
||||||
#define J2K_MAXRLVLS 33
|
|
||||||
#define J2K_MAXBANDS (3*J2K_MAXRLVLS+1)
|
|
||||||
|
|
||||||
#define J2K_CP_CSTY_PRT 0x01
|
|
||||||
#define J2K_CP_CSTY_SOP 0x02
|
|
||||||
#define J2K_CP_CSTY_EPH 0x04
|
|
||||||
#define J2K_CCP_CSTY_PRT 0x01
|
|
||||||
#define J2K_CCP_CBLKSTY_LAZY 0x01
|
|
||||||
#define J2K_CCP_CBLKSTY_RESET 0x02
|
|
||||||
#define J2K_CCP_CBLKSTY_TERMALL 0x04
|
|
||||||
#define J2K_CCP_CBLKSTY_VSC 0x08
|
|
||||||
#define J2K_CCP_CBLKSTY_PTERM 0x10
|
|
||||||
#define J2K_CCP_CBLKSTY_SEGSYM 0x20
|
|
||||||
#define J2K_CCP_QNTSTY_NOQNT 0
|
|
||||||
#define J2K_CCP_QNTSTY_SIQNT 1
|
|
||||||
#define J2K_CCP_QNTSTY_SEQNT 2
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
int dx, dy; /* XRsiz, YRsiz */
|
|
||||||
int prec; /* precision */
|
|
||||||
int bpp; /* deapth of image in bits */
|
|
||||||
int sgnd; /* signed */
|
|
||||||
int *data; /* image-component data */
|
|
||||||
} j2k_comp_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int version;
|
|
||||||
int x0, y0; /* XOsiz, YOsiz */
|
|
||||||
int x1, y1; /* Xsiz, Ysiz */
|
|
||||||
int numcomps; /* number of components */
|
|
||||||
int index_on; /* 0 = no index || 1 = index */
|
|
||||||
j2k_comp_t *comps; /* image-components */
|
|
||||||
} j2k_image_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int expn; /* exponent */
|
|
||||||
int mant; /* mantissa */
|
|
||||||
} j2k_stepsize_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int csty; /* coding style */
|
|
||||||
int numresolutions; /* number of resolutions */
|
|
||||||
int cblkw; /* width of code-blocks */
|
|
||||||
int cblkh; /* height of code-blocks */
|
|
||||||
int cblksty; /* code-block coding style */
|
|
||||||
int qmfbid; /* discrete wavelet transform identifier */
|
|
||||||
int qntsty; /* quantisation style */
|
|
||||||
j2k_stepsize_t stepsizes[J2K_MAXBANDS]; /* stepsizes used for quantisation */
|
|
||||||
int numgbits; /* number of guard bits */
|
|
||||||
int roishift; /* Region of Interest shift */
|
|
||||||
int prcw[J2K_MAXRLVLS]; /* Precinct width */
|
|
||||||
int prch[J2K_MAXRLVLS]; /* Precinct height */
|
|
||||||
} j2k_tccp_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int resno0, compno0;
|
|
||||||
int layno1, resno1, compno1;
|
|
||||||
int prg;
|
|
||||||
int tile;
|
|
||||||
char progorder[4];
|
|
||||||
} j2k_poc_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int csty; /* coding style */
|
|
||||||
int prg; /* progression order */
|
|
||||||
int numlayers; /* number of layers */
|
|
||||||
int mct; /* multi-component transform identifier */
|
|
||||||
int rates[100]; /* rates of layers */
|
|
||||||
int numpocs; /* number of progression order changes */
|
|
||||||
int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
|
|
||||||
j2k_poc_t pocs[32]; /* progression order changes */
|
|
||||||
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
|
||||||
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
|
||||||
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
|
||||||
j2k_tccp_t *tccps; /* tile-component coding parameters */
|
|
||||||
} j2k_tcp_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int tx0, ty0; /* XTOsiz, YTOsiz */
|
|
||||||
int tdx, tdy; /* XTsiz, YTsiz */
|
|
||||||
int tw, th;
|
|
||||||
unsigned char *ppm_data; /* packet header store there for futur use in t2_decode_packet */
|
|
||||||
int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
|
|
||||||
int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
|
|
||||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
|
||||||
j2k_tcp_t *tcps; /* tile coding parameters */
|
|
||||||
} j2k_cp_t;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Packet information : Layer level */
|
|
||||||
typedef struct {
|
|
||||||
int len; /* Length of the body of the packet */
|
|
||||||
int len_header; /* Length of the header of the packet */
|
|
||||||
int offset; /* Offset of the body of the packet */
|
|
||||||
int offset_header; /* Offset of the header of the packet */
|
|
||||||
} info_layer_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Access to packet information : precinct level */
|
|
||||||
typedef struct {
|
|
||||||
info_layer_t *layer;
|
|
||||||
} info_prec_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Access to packet information : resolution level */
|
|
||||||
typedef struct {
|
|
||||||
info_prec_t *prec;
|
|
||||||
} info_reso_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Access to packet information : component level */
|
|
||||||
typedef struct {
|
|
||||||
info_reso_t *reso;
|
|
||||||
} info_compo_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Information about the marker */
|
|
||||||
typedef struct {
|
|
||||||
int type; /* type of marker [SIZ, QCD, POC, PPM, CRG, COD] appearing only once */
|
|
||||||
int start_pos; /* Start position of the marker */
|
|
||||||
int len; /* Length of the marker */
|
|
||||||
} info_marker_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Multiple marker in tile header */
|
|
||||||
typedef struct{
|
|
||||||
info_marker_t *COC; /* COC markers */
|
|
||||||
int num_COC; /* Number of COC marker */
|
|
||||||
int CzCOC; /* Current size of the vector COC */
|
|
||||||
|
|
||||||
info_marker_t *RGN; /* RGN markers */
|
|
||||||
int num_RGN; /* Number of RGN marker */
|
|
||||||
int CzRGN; /* Current size of the vector RGN */
|
|
||||||
|
|
||||||
info_marker_t *QCC; /* QCC markers */
|
|
||||||
int num_QCC; /* Number of QCC marker */
|
|
||||||
int CzQCC; /* Current size of the vector QCC */
|
|
||||||
|
|
||||||
info_marker_t *PLT; /* PLT markers */
|
|
||||||
int num_PLT; /* Number of PLT marker */
|
|
||||||
int CzPLT; /* Current size of the vector PLT */
|
|
||||||
|
|
||||||
info_marker_t *PPT; /* PPT markers */
|
|
||||||
int num_PPT; /* Number of PPT marker */
|
|
||||||
int CzPPT; /* Current size of the vector PPT */
|
|
||||||
|
|
||||||
info_marker_t *COM; /* COM markers */
|
|
||||||
int num_COM; /* Number of COM marker */
|
|
||||||
int CzCOM; /* Current size of the vector COC */
|
|
||||||
} info_marker_mul_tile_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Information about each tile_part for a particulary tile */
|
|
||||||
typedef struct{
|
|
||||||
int start_pos; /* Start position of the tile_part */
|
|
||||||
int length; /* Length of the tile_part header + body */
|
|
||||||
int length_header; /* Length of the header */
|
|
||||||
int end_pos; /* End position of the tile part */
|
|
||||||
int end_header; /* End position of the tile part header */
|
|
||||||
|
|
||||||
int num_reso_AUX; /* Number of resolution level completed */
|
|
||||||
} info_tile_part_t;
|
|
||||||
|
|
||||||
|
|
||||||
/* Information about each tile */
|
|
||||||
typedef struct {
|
|
||||||
int num_tile; /* Number of Tile */
|
|
||||||
int pw, ph; /* number of precinct by tile */
|
|
||||||
int num_packet; /* number of packet in the tile */
|
|
||||||
info_compo_t *compo; /* component [packet] */
|
|
||||||
|
|
||||||
info_marker_t *marker; /* information concerning markers inside image [only one apparition] */
|
|
||||||
info_marker_mul_tile_t marker_mul; /* information concerning markers inside image [multiple apparition] */
|
|
||||||
int num_marker; /* number of marker */
|
|
||||||
|
|
||||||
int numparts; /* number of tile_part for this tile */
|
|
||||||
info_tile_part_t *tile_parts; /* Information about each tile_part */
|
|
||||||
int Cztile_parts; /* Current size of the tile_parts vector */
|
|
||||||
} info_tile_t; /* index struct */
|
|
||||||
|
|
||||||
|
|
||||||
/* Multiple marker in main header */
|
|
||||||
typedef struct{
|
|
||||||
info_marker_t *COC; /* COC markers */
|
|
||||||
int num_COC; /* Number of COC marker */
|
|
||||||
int CzCOC; /* Current size of the vector COC */
|
|
||||||
|
|
||||||
info_marker_t *RGN; /* RGN markers */
|
|
||||||
int num_RGN; /* Number of RGN marker */
|
|
||||||
int CzRGN; /* Current size of the vector RGN */
|
|
||||||
|
|
||||||
info_marker_t *QCC; /* QCC markers */
|
|
||||||
int num_QCC; /* Number of QCC marker */
|
|
||||||
int CzQCC; /* Current size of the vector QCC */
|
|
||||||
|
|
||||||
info_marker_t *TLM; /* TLM markers */
|
|
||||||
int num_TLM; /* Number of TLM marker */
|
|
||||||
int CzTLM; /* Current size of the vector TLM */
|
|
||||||
|
|
||||||
info_marker_t *PLM; /* PLM markers */
|
|
||||||
int num_PLM; /* Number of PLM marker */
|
|
||||||
int CzPLM; /* Current size of the vector PLM */
|
|
||||||
|
|
||||||
info_marker_t *PPM; /* PPM markers */
|
|
||||||
int num_PPM; /* Number of PPM marker */
|
|
||||||
int CzPPM; /* Current size of the vector PPM */
|
|
||||||
|
|
||||||
info_marker_t *COM; /* COM markers */
|
|
||||||
int num_COM; /* Number of COM marker */
|
|
||||||
int CzCOM; /* Current size of the vector COM */
|
|
||||||
} info_marker_mul_t; /* index struct */
|
|
||||||
|
|
||||||
|
|
||||||
/* Information about image */
|
|
||||||
typedef struct {
|
|
||||||
int Im_w, Im_h; /* Image width and Height */
|
|
||||||
int Tile_x, Tile_y; /* Number of Tile in X and Y */
|
|
||||||
int tw, th;
|
|
||||||
int pw, ph; /* nombre precinct in X and Y */
|
|
||||||
int pdx, pdy; /* size of precinct in X and Y */
|
|
||||||
|
|
||||||
int Prog; /* progression order */
|
|
||||||
int Comp; /* Component numbers */
|
|
||||||
int Layer; /* number of layer */
|
|
||||||
int Decomposition; /* number of decomposition */
|
|
||||||
|
|
||||||
int Main_head_end; /* Main header position */
|
|
||||||
int codestream_size; /* codestream's size */
|
|
||||||
|
|
||||||
info_marker_t *marker; /* information concerning markers inside image [only one apparition] */
|
|
||||||
info_marker_mul_t marker_mul; /* information concerning markers inside image [multiple apparition] */
|
|
||||||
int num_marker; /* number of marker */
|
|
||||||
|
|
||||||
int num_packet_max; /* Maximum number of packet */
|
|
||||||
|
|
||||||
int num_max_tile_parts; /* Maximum number of tile-part */
|
|
||||||
info_tile_t *tile; /* information concerning tiles inside image */
|
|
||||||
} info_image_t; /* index struct */
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,301 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
#include "cio.h"
|
|
||||||
#include "tcd.h"
|
|
||||||
#include "int.h"
|
|
||||||
|
|
||||||
#define JPIP_JPIP 0x6a706970
|
|
||||||
|
|
||||||
#define JP2_JP 0x6a502020
|
|
||||||
#define JP2_FTYP 0x66747970
|
|
||||||
#define JP2_JP2H 0x6a703268
|
|
||||||
#define JP2_IHDR 0x69686472
|
|
||||||
#define JP2_COLR 0x636f6c72
|
|
||||||
#define JP2_JP2C 0x6a703263
|
|
||||||
#define JP2_URL 0x75726c20
|
|
||||||
#define JP2_DBTL 0x6474626c
|
|
||||||
#define JP2_BPCC 0x62706363
|
|
||||||
#define JP2 0x6a703220
|
|
||||||
|
|
||||||
|
|
||||||
void jp2_write_url(char *Idx_file)
|
|
||||||
{
|
|
||||||
int len, lenp, i;
|
|
||||||
char str[256];
|
|
||||||
|
|
||||||
sprintf(str, "%s", Idx_file);
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_URL, 4); // DBTL
|
|
||||||
cio_write(0,1); // VERS
|
|
||||||
cio_write(0,3); // FLAG
|
|
||||||
|
|
||||||
for (i=0; i<strlen(str); i++) {
|
|
||||||
cio_write(str[i], 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void jp2_write_dbtl(char *Idx_file)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_DBTL, 4); // DBTL
|
|
||||||
cio_write(1,2); // NDR : Only 1
|
|
||||||
|
|
||||||
jp2_write_url(Idx_file); // URL Box
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
int jp2_write_ihdr(j2k_image_t *j2k_img)
|
|
||||||
{
|
|
||||||
int len, lenp,i;
|
|
||||||
int depth_0,depth, sign, BPC_ok=1;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_IHDR, 4); // IHDR
|
|
||||||
|
|
||||||
cio_write(j2k_img->y1-j2k_img->x0,4); // HEIGHT
|
|
||||||
cio_write(j2k_img->x1-j2k_img->x0,4); // WIDTH
|
|
||||||
cio_write(j2k_img->numcomps,2); // NC
|
|
||||||
|
|
||||||
depth_0=j2k_img->comps[0].prec-1;
|
|
||||||
sign=j2k_img->comps[0].sgnd;
|
|
||||||
|
|
||||||
for(i=1;i<j2k_img->numcomps;i++)
|
|
||||||
{
|
|
||||||
depth=j2k_img->comps[i].prec-1;
|
|
||||||
sign=j2k_img->comps[i].sgnd;
|
|
||||||
if(depth_0!=depth) BPC_ok=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BPC_ok)
|
|
||||||
cio_write(depth_0+(sign<<7),1);
|
|
||||||
else
|
|
||||||
cio_write(255,1);
|
|
||||||
|
|
||||||
cio_write(7,1); // C : Always 7
|
|
||||||
cio_write(1,1); // UnkC, colorspace unknow
|
|
||||||
cio_write(0,1); // IPR, no intellectual property
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
|
|
||||||
return BPC_ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jp2_write_bpcc(j2k_image_t *j2k_img)
|
|
||||||
{
|
|
||||||
int len, lenp, i;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_BPCC, 4); // BPCC
|
|
||||||
|
|
||||||
for(i=0;i<j2k_img->numcomps;i++)
|
|
||||||
cio_write(j2k_img->comps[i].prec-1+(j2k_img->comps[i].sgnd<<7),1);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void jp2_write_colr(int BPC_ok, j2k_image_t *j2k_img)
|
|
||||||
{
|
|
||||||
int len, lenp, meth;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_COLR, 4); // COLR
|
|
||||||
|
|
||||||
if ((j2k_img->numcomps==1 || j2k_img->numcomps==3) && (BPC_ok && j2k_img->comps[0].prec==8))
|
|
||||||
meth=1;
|
|
||||||
else
|
|
||||||
meth=2;
|
|
||||||
|
|
||||||
cio_write(meth,1); // METH
|
|
||||||
cio_write(0,1); // PREC
|
|
||||||
cio_write(0,1); // APPROX
|
|
||||||
|
|
||||||
if (meth==1)
|
|
||||||
cio_write(j2k_img->numcomps>1?16:17,4); // EnumCS
|
|
||||||
|
|
||||||
if (meth==2)
|
|
||||||
cio_write(0,1); // PROFILE (??)
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the JP2H box
|
|
||||||
*
|
|
||||||
* JP2 Header box
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jp2_write_jp2h(j2k_image_t *j2k_img)
|
|
||||||
{
|
|
||||||
int len, lenp, BPC_ok;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_JP2H, 4); /* JP2H */
|
|
||||||
|
|
||||||
BPC_ok=jp2_write_ihdr(j2k_img);
|
|
||||||
|
|
||||||
if (!BPC_ok)
|
|
||||||
jp2_write_bpcc(j2k_img);
|
|
||||||
jp2_write_colr(BPC_ok, j2k_img);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the FTYP box
|
|
||||||
*
|
|
||||||
* File type box
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jp2_write_ftyp()
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_FTYP, 4); /* FTYP */
|
|
||||||
|
|
||||||
cio_write(JP2,4); /* BR */
|
|
||||||
cio_write(0,4); /* MinV */
|
|
||||||
cio_write(JP2,4); /* CL0 : JP2 */
|
|
||||||
cio_write(JPIP_JPIP,4); /* CL1 : JPIP */
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the FTYP box
|
|
||||||
*
|
|
||||||
* File type box
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jp2_read_ftyp(int length)
|
|
||||||
{
|
|
||||||
int BR, MinV, type, i;
|
|
||||||
|
|
||||||
BR = cio_read(4); /* BR */
|
|
||||||
MinV = cio_read(4); /* MinV */
|
|
||||||
length-=8;
|
|
||||||
|
|
||||||
for (i=length/4;i>0;i--)
|
|
||||||
type = cio_read(4); /* CLi : JP2, JPIP */
|
|
||||||
}
|
|
||||||
|
|
||||||
int jp2_write_jp2c(char *J2K_file)
|
|
||||||
{
|
|
||||||
int len, lenp, totlen, i;
|
|
||||||
FILE *src;
|
|
||||||
char *j2kfile;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_JP2C, 4); // JP2C
|
|
||||||
|
|
||||||
src=fopen(J2K_file, "rb");
|
|
||||||
fseek(src, 0, SEEK_END);
|
|
||||||
totlen=ftell(src);
|
|
||||||
fseek(src, 0, SEEK_SET);
|
|
||||||
|
|
||||||
j2kfile=(char*)malloc(totlen);
|
|
||||||
fread(j2kfile, 1, totlen, src);
|
|
||||||
fclose(src);
|
|
||||||
|
|
||||||
for (i=0;i<totlen;i++)
|
|
||||||
cio_write(j2kfile[i],1);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
return lenp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void jp2_write_jp()
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4);
|
|
||||||
cio_write(JP2_JP, 4); // JP
|
|
||||||
cio_write(0x0d0a870a,4);
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len,4); // L
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the JP box
|
|
||||||
*
|
|
||||||
* JPEG 2000 signature
|
|
||||||
*
|
|
||||||
* return 1 if error else 0
|
|
||||||
*/
|
|
||||||
int jp2_read_jp()
|
|
||||||
{
|
|
||||||
if (0x0d0a870a!=cio_read(4))
|
|
||||||
return 1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __JP2_H
|
|
||||||
#define __JP2_H
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
|
|
||||||
void jp2_write_url(char *Idx_file);
|
|
||||||
|
|
||||||
void jp2_write_dbtl(char *Idx_file);
|
|
||||||
|
|
||||||
void jp2_write_jp2h(j2k_image_t *j2k_img);
|
|
||||||
|
|
||||||
void jp2_write_ftyp();
|
|
||||||
|
|
||||||
int jp2_write_jp2c(char *J2K_file);
|
|
||||||
|
|
||||||
void jp2_write_jp();
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,768 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
#include "cio.h"
|
|
||||||
#include "tcd.h"
|
|
||||||
#include "int.h"
|
|
||||||
|
|
||||||
#define JPIP_CIDX 0x63696478 /* Codestream index */
|
|
||||||
#define JPIP_CPTR 0x63707472 /* Codestream Finder Box */
|
|
||||||
#define JPIP_MANF 0x6d616e66 /* Manifest Box */
|
|
||||||
#define JPIP_FAIX 0x66616978 /* Fragment array Index box */
|
|
||||||
#define JPIP_MHIX 0x6d686978 /* Main Header Index Table */
|
|
||||||
#define JPIP_TPIX 0x74706978 /* Tile-part Index Table box */
|
|
||||||
#define JPIP_THIX 0x74686978 /* Tile header Index Table box */
|
|
||||||
#define JPIP_PPIX 0x70706978 /* Precinct Packet Index Table box */
|
|
||||||
#define JPIP_PHIX 0x70686978 /* Packet Header index Table */
|
|
||||||
#define JPIP_FIDX 0x66696478 /* File Index */
|
|
||||||
#define JPIP_FPTR 0x66707472 /* File Finder */
|
|
||||||
#define JPIP_PRXY 0x70727879 /* Proxy boxes */
|
|
||||||
#define JPIP_IPTR 0x69707472 /* Index finder box */
|
|
||||||
#define JPIP_PHLD 0x70686c64 /* Place holder */
|
|
||||||
|
|
||||||
#define JP2C 0x6a703263
|
|
||||||
|
|
||||||
//static info_marker_t marker_jpip[32], marker_local_jpip[32]; /* SIZE to precise ! */
|
|
||||||
//static int num_marker_jpip, num_marker_local_jpip;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the CPTR box
|
|
||||||
*
|
|
||||||
* Codestream finder box (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_write_cptr(int offset, info_image_t img)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_CPTR,4); /* T */
|
|
||||||
cio_write(0,2); /* DR A PRECISER !! */
|
|
||||||
cio_write(0,2); /* CONT */
|
|
||||||
cio_write(offset,8); /* COFF A PRECISER !! */
|
|
||||||
cio_write(img.codestream_size,8); /* CLEN */
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the CPTR box
|
|
||||||
*
|
|
||||||
* Codestream finder box (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_read_cptr()
|
|
||||||
{
|
|
||||||
int DR, CONT;
|
|
||||||
long long Coff, codestream_size;
|
|
||||||
|
|
||||||
DR = cio_read(2); /* DR */
|
|
||||||
CONT = cio_read(2); /* CONT */
|
|
||||||
Coff = cio_read(8); /* COFF */
|
|
||||||
codestream_size = cio_read(8); /* CLEN */
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the MANF box
|
|
||||||
*
|
|
||||||
* Manifest box (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_write_manf(int second, int v, info_marker_t *marker)
|
|
||||||
{
|
|
||||||
int len, lenp, i;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_MANF,4); /* T */
|
|
||||||
|
|
||||||
if (second) /* Write only during the second pass */
|
|
||||||
{
|
|
||||||
for(i=0;i<v;i++)
|
|
||||||
{
|
|
||||||
cio_write(marker[i].len,4); /* Marker length */
|
|
||||||
cio_write(marker[i].type,4); /* Marker type */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the MANF box
|
|
||||||
*
|
|
||||||
* Manifest box (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_read_manf(int len)
|
|
||||||
{
|
|
||||||
int i, v, marker_len, marker_type;
|
|
||||||
|
|
||||||
v = (len - 8)/ 8;
|
|
||||||
|
|
||||||
for(i=0;i<v;i++)
|
|
||||||
{
|
|
||||||
marker_len = cio_read(4); /* Marker length */
|
|
||||||
marker_type = cio_read(4); /* Marker type */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the MHIX box
|
|
||||||
*
|
|
||||||
* Main Header Index Table (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_mhix(info_image_t img, int status, int tileno)
|
|
||||||
{
|
|
||||||
int len, lenp, i;
|
|
||||||
info_tile_t *tile;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_MHIX, 4); /* MHIX */
|
|
||||||
|
|
||||||
if (status) /* MAIN HEADER */
|
|
||||||
{
|
|
||||||
cio_write(img.Main_head_end,8); /* TLEN */
|
|
||||||
|
|
||||||
for(i = 0; i < img.num_marker; i++) /* Marker restricted to 1 apparition */
|
|
||||||
{
|
|
||||||
cio_write(img.marker[i].type, 2);
|
|
||||||
cio_write(0, 2);
|
|
||||||
cio_write(img.marker[i].start_pos, 8);
|
|
||||||
cio_write(img.marker[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Marker NOT restricted to 1 apparition */
|
|
||||||
for(i = img.marker_mul.num_COC - 1; i >= 0; i--) /* COC */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.COC[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.COC[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.COC[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_RGN - 1; i >= 0; i--) /* RGN */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.RGN[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.RGN[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.RGN[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_QCC - 1; i >= 0; i--) /* QCC */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.QCC[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.QCC[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.QCC[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_TLM - 1; i >= 0; i--) /* TLM */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.TLM[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.TLM[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.TLM[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_PLM - 1; i >= 0; i--) /* PLM */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.PLM[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.PLM[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.PLM[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_PPM - 1; i >= 0; i--) /* PPM */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.PPM[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.PPM[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.PPM[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = img.marker_mul.num_COM - 1; i >= 0; i--) /* COM */
|
|
||||||
{
|
|
||||||
cio_write(img.marker_mul.COM[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(img.marker_mul.COM[i].start_pos, 8);
|
|
||||||
cio_write(img.marker_mul.COM[i].len, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else /* TILE HEADER */
|
|
||||||
{
|
|
||||||
tile = &img.tile[tileno];
|
|
||||||
cio_write(tile->tile_parts[0].length_header, 8); /* TLEN */
|
|
||||||
|
|
||||||
for(i = 0; i < tile->num_marker; i++) /* Marker restricted to 1 apparition */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker[i].type, 2);
|
|
||||||
cio_write(0, 2);
|
|
||||||
cio_write(tile->marker[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Marker NOT restricted to 1 apparition */
|
|
||||||
for(i = tile->marker_mul.num_COC - 1; i >= 0; i--) /* COC */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.COC[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(tile->marker_mul.COC[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker_mul.COC[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = tile->marker_mul.num_RGN - 1; i >= 0; i--) /* RGN */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.RGN[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(tile->marker_mul.RGN[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker_mul.RGN[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = tile->marker_mul.num_QCC - 1; i >= 0; i--) /* QCC */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.QCC[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(tile->marker_mul.QCC[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker_mul.QCC[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = tile->marker_mul.num_PLT - 1; i >= 0; i--) /* PLT */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.PLT[i].type,2);
|
|
||||||
cio_write(i,2);
|
|
||||||
cio_write(tile->marker_mul.PLT[i].start_pos,8);
|
|
||||||
cio_write(tile->marker_mul.PLT[i].len,2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = tile->marker_mul.num_PPT - 1; i >= 0; i--) /* PPT */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.PPT[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(tile->marker_mul.PPT[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker_mul.PPT[i].len, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = tile->marker_mul.num_COM - 1; i >= 0; i--) /* COM */
|
|
||||||
{
|
|
||||||
cio_write(tile->marker_mul.COM[i].type, 2);
|
|
||||||
cio_write(i, 2);
|
|
||||||
cio_write(tile->marker_mul.COM[i].start_pos, 8);
|
|
||||||
cio_write(tile->marker_mul.COM[i].len, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read the MHIX box
|
|
||||||
*
|
|
||||||
* Main Header Index Table (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_read_mhix(int len)
|
|
||||||
{
|
|
||||||
int i, v, marker_type, marker_start_pos, marker_len, marker_remains;
|
|
||||||
|
|
||||||
v = (len - 8) / 14;
|
|
||||||
|
|
||||||
for (i=0; i<v ; i++)
|
|
||||||
{
|
|
||||||
marker_type = cio_read(2); /* Type of the marker */
|
|
||||||
marker_remains = cio_read(2); /* Number of same markers following */
|
|
||||||
marker_start_pos = cio_read(2); /* Start position of the marker */
|
|
||||||
marker_len = cio_read(2); /* Length of the marker */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the FAIX box
|
|
||||||
*
|
|
||||||
* Fragment array Index box (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_faix(int v, int compno, info_image_t img, j2k_cp_t *j2k_cp, int version)
|
|
||||||
{
|
|
||||||
int len, lenp, i, j;
|
|
||||||
/*int version = 0;*/
|
|
||||||
int tileno, resno, precno, layno, num_packet=0;
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_FAIX, 4); /* FAIX */
|
|
||||||
cio_write(version,1); /* Version 0 = 4 bytes */
|
|
||||||
|
|
||||||
switch(v)
|
|
||||||
{
|
|
||||||
case 0: /* TPIX */
|
|
||||||
cio_write(img.num_max_tile_parts,(version & 0x01)?8:4); /* NMAX */
|
|
||||||
cio_write(img.tw*img.th,(version & 0x01)?8:4); /* M */
|
|
||||||
for (i = 0; i < img.tw*img.th; i++)
|
|
||||||
{
|
|
||||||
for (j = 0; j < img.tile[i].numparts ; j++)
|
|
||||||
{
|
|
||||||
cio_write(img.tile[i].tile_parts[j].start_pos,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write(img.tile[i].tile_parts[j].length,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
//cio_write(0,4);
|
|
||||||
}
|
|
||||||
/* PADDING */
|
|
||||||
while (j < img.num_max_tile_parts)
|
|
||||||
{
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(0,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* case 1: */ /* THIX */
|
|
||||||
/* cio_write(1,(version & 0x01)?8:4); */ /* NMAX */
|
|
||||||
/* cio_write(img.tw*img.th,(version & 0x01)?8:4); */ /* M */
|
|
||||||
/* for (i=0;i<img.tw*img.th;i++) */
|
|
||||||
/* { */
|
|
||||||
/* cio_write(img.tile[i].start_pos,(version & 0x01)?8:4); */ /* start position */
|
|
||||||
/* cio_write(img.tile[i].end_header-img.tile[i].start_pos,(version & 0x01)?8:4); */ /* length */
|
|
||||||
/* if (version & 0x02)*/
|
|
||||||
/* cio_write(0,4); */ /* Aux_i,j : Auxiliary value */
|
|
||||||
/* } */
|
|
||||||
/* break; */
|
|
||||||
|
|
||||||
case 2: /* PPIX NOT FINISHED !! */
|
|
||||||
cio_write(img.num_packet_max,(version & 0x01)?8:4); /* NMAX */
|
|
||||||
cio_write(img.tw*img.th,(version & 0x01)?8:4); /* M */
|
|
||||||
for(tileno=0;tileno<img.tw*img.th;tileno++)
|
|
||||||
{
|
|
||||||
info_tile_t *tile_Idx = &img.tile[tileno];
|
|
||||||
info_compo_t *compo_Idx = &tile_Idx->compo[compno];
|
|
||||||
int correction;
|
|
||||||
|
|
||||||
num_packet=0;
|
|
||||||
|
|
||||||
if(j2k_cp->tcps[tileno].csty&J2K_CP_CSTY_EPH)
|
|
||||||
correction=3;
|
|
||||||
else
|
|
||||||
correction=1;
|
|
||||||
for(resno=0;resno<img.Decomposition+1;resno++)
|
|
||||||
{
|
|
||||||
info_reso_t *reso_Idx = &compo_Idx->reso[resno];
|
|
||||||
for (precno=0;precno<img.tile[tileno].pw*img.tile[tileno].ph;precno++)
|
|
||||||
{
|
|
||||||
info_prec_t *prec_Idx = &reso_Idx->prec[precno];
|
|
||||||
for(layno=0;layno<img.Layer;layno++)
|
|
||||||
{
|
|
||||||
info_layer_t *layer_Idx = &prec_Idx->layer[layno];
|
|
||||||
cio_write(layer_Idx->offset,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write((layer_Idx->len_header-correction)?0:layer_Idx->len,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(0,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
num_packet++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* PADDING */
|
|
||||||
while (num_packet < img.num_packet_max)
|
|
||||||
{
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(0,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
num_packet++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3: /* PHIX NOT FINISHED !! */
|
|
||||||
cio_write(img.num_packet_max,(version & 0x01)?8:4); /* NMAX */
|
|
||||||
cio_write(img.tw*img.th,(version & 0x01)?8:4); /* M */
|
|
||||||
for(tileno=0;tileno<img.tw*img.th;tileno++)
|
|
||||||
{
|
|
||||||
info_tile_t *tile_Idx = &img.tile[tileno];
|
|
||||||
info_compo_t *compo_Idx = &tile_Idx->compo[compno];
|
|
||||||
int correction;
|
|
||||||
|
|
||||||
num_packet = 0;
|
|
||||||
if(j2k_cp->tcps[tileno].csty&J2K_CP_CSTY_EPH)
|
|
||||||
correction=3;
|
|
||||||
else
|
|
||||||
correction=1;
|
|
||||||
for(resno=0;resno<img.Decomposition+1;resno++)
|
|
||||||
{
|
|
||||||
info_reso_t *reso_Idx = &compo_Idx->reso[resno];
|
|
||||||
for (precno=0;precno<img.tile[tileno].pw*img.tile[tileno].ph;precno++)
|
|
||||||
{
|
|
||||||
info_prec_t *prec_Idx = &reso_Idx->prec[precno];
|
|
||||||
for(layno=0;layno<img.Layer;layno++)
|
|
||||||
{
|
|
||||||
info_layer_t *layer_Idx = &prec_Idx->layer[layno];
|
|
||||||
cio_write(layer_Idx->offset_header,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write((layer_Idx->len_header-correction)?0:layer_Idx->len_header,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(0,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
num_packet++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* PADDING */
|
|
||||||
while (num_packet<img.num_packet_max)
|
|
||||||
{
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* start position */
|
|
||||||
cio_write(0,(version & 0x01)?8:4); /* length */
|
|
||||||
if (version & 0x02)
|
|
||||||
cio_write(0,4); /* Aux_i,j : Auxiliary value */
|
|
||||||
num_packet++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the TPIX box
|
|
||||||
*
|
|
||||||
* Tile-part Index table box (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_tpix(info_image_t img, j2k_cp_t *j2k_cp, int version)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_TPIX, 4); /* TPIX */
|
|
||||||
|
|
||||||
jpip_write_faix(0,0,img, j2k_cp, version);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the THIX box
|
|
||||||
*
|
|
||||||
* Tile header Index table box (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
//int jpip_write_thix(info_image_t img, j2k_cp_t *j2k_cp)
|
|
||||||
// {
|
|
||||||
// int len, lenp;
|
|
||||||
// lenp=cio_tell();
|
|
||||||
// cio_skip(4); /* L [at the end] */
|
|
||||||
// cio_write(JPIP_THIX, 4); /* THIX */
|
|
||||||
|
|
||||||
// jpip_write_faix(1,0,img, j2k_cp);
|
|
||||||
|
|
||||||
// len=cio_tell()-lenp;
|
|
||||||
// cio_seek(lenp);
|
|
||||||
// cio_write(len, 4); /* L */
|
|
||||||
// cio_seek(lenp+len);
|
|
||||||
|
|
||||||
// return len;
|
|
||||||
//}
|
|
||||||
|
|
||||||
int jpip_write_thix(info_image_t img, j2k_cp_t *j2k_cp)
|
|
||||||
{
|
|
||||||
int len, lenp, i;
|
|
||||||
int tileno;
|
|
||||||
info_marker_t *marker;
|
|
||||||
int num_marker_local_jpip;
|
|
||||||
|
|
||||||
marker = (info_marker_t*)calloc(sizeof(info_marker_t), j2k_cp->tw*j2k_cp->th);
|
|
||||||
|
|
||||||
for ( i = 0; i < 2 ; i++ )
|
|
||||||
{
|
|
||||||
if (i) cio_seek(lenp);
|
|
||||||
|
|
||||||
lenp = cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_THIX, 4); /* THIX */
|
|
||||||
jpip_write_manf(i, j2k_cp->tw*j2k_cp->th, marker);
|
|
||||||
num_marker_local_jpip=img.Comp;
|
|
||||||
|
|
||||||
for (tileno = 0; tileno < j2k_cp->tw*j2k_cp->th; tileno++)
|
|
||||||
{
|
|
||||||
marker[tileno].len = jpip_write_mhix(img, 1, tileno);
|
|
||||||
marker[tileno].type = JPIP_MHIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(marker);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Write the PPIX box
|
|
||||||
*
|
|
||||||
* Precinct Packet Index table box (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_ppix(info_image_t img,j2k_cp_t *j2k_cp)
|
|
||||||
{
|
|
||||||
int len, lenp, compno, i;
|
|
||||||
info_marker_t *marker;
|
|
||||||
int num_marker_local_jpip;
|
|
||||||
marker = (info_marker_t*)calloc(sizeof(info_marker_t), img.Comp);
|
|
||||||
|
|
||||||
for (i=0;i<2;i++)
|
|
||||||
{
|
|
||||||
if (i) cio_seek(lenp);
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_PPIX, 4); /* PPIX */
|
|
||||||
jpip_write_manf(i,img.Comp,marker);
|
|
||||||
num_marker_local_jpip=img.Comp;
|
|
||||||
|
|
||||||
for (compno=0; compno<img.Comp; compno++)
|
|
||||||
{
|
|
||||||
marker[compno].len=jpip_write_faix(2,compno,img, j2k_cp, 0);
|
|
||||||
marker[compno].type=JPIP_FAIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(marker);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the PHIX box
|
|
||||||
*
|
|
||||||
* Packet Header Index table box (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_phix(info_image_t img, j2k_cp_t *j2k_cp)
|
|
||||||
{
|
|
||||||
int len, lenp=0, compno, i;
|
|
||||||
info_marker_t *marker;
|
|
||||||
|
|
||||||
marker = (info_marker_t*)calloc(sizeof(info_marker_t), img.Comp);
|
|
||||||
|
|
||||||
for (i=0;i<2;i++)
|
|
||||||
{
|
|
||||||
if (i) cio_seek(lenp);
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_PHIX, 4); /* PHIX */
|
|
||||||
|
|
||||||
jpip_write_manf(i,img.Comp,marker);
|
|
||||||
|
|
||||||
for (compno=0; compno<img.Comp; compno++)
|
|
||||||
{
|
|
||||||
marker[compno].len=jpip_write_faix(3,compno,img, j2k_cp, 0);
|
|
||||||
marker[compno].type=JPIP_FAIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(marker);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the CIDX box
|
|
||||||
*
|
|
||||||
* Codestream Index box (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_cidx(int offset, info_image_t img, j2k_cp_t *j2k_cp, int version)
|
|
||||||
{
|
|
||||||
int len, lenp = 0, i;
|
|
||||||
info_marker_t *marker_jpip;
|
|
||||||
int num_marker_jpip = 0;
|
|
||||||
|
|
||||||
marker_jpip = (info_marker_t*)calloc(sizeof(info_marker_t), 32);
|
|
||||||
|
|
||||||
for (i=0;i<2;i++)
|
|
||||||
{
|
|
||||||
if(i)
|
|
||||||
cio_seek(lenp);
|
|
||||||
|
|
||||||
lenp=cio_tell();
|
|
||||||
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_CIDX, 4); /* CIDX */
|
|
||||||
jpip_write_cptr(offset, img);
|
|
||||||
|
|
||||||
jpip_write_manf(i,num_marker_jpip, marker_jpip);
|
|
||||||
|
|
||||||
num_marker_jpip=0;
|
|
||||||
marker_jpip[num_marker_jpip].len=jpip_write_mhix(img, 0, 0);
|
|
||||||
marker_jpip[num_marker_jpip].type=JPIP_MHIX;
|
|
||||||
num_marker_jpip++;
|
|
||||||
|
|
||||||
marker_jpip[num_marker_jpip].len=jpip_write_tpix(img, j2k_cp, version);
|
|
||||||
marker_jpip[num_marker_jpip].type=JPIP_TPIX;
|
|
||||||
num_marker_jpip++;
|
|
||||||
|
|
||||||
marker_jpip[num_marker_jpip].len=jpip_write_thix(img, j2k_cp);
|
|
||||||
marker_jpip[num_marker_jpip].type=JPIP_THIX;
|
|
||||||
num_marker_jpip++;
|
|
||||||
|
|
||||||
marker_jpip[num_marker_jpip].len=jpip_write_ppix(img, j2k_cp);
|
|
||||||
marker_jpip[num_marker_jpip].type=JPIP_PPIX;
|
|
||||||
num_marker_jpip++;
|
|
||||||
|
|
||||||
marker_jpip[num_marker_jpip].len=jpip_write_phix(img, j2k_cp);
|
|
||||||
marker_jpip[num_marker_jpip].type=JPIP_PHIX;
|
|
||||||
num_marker_jpip++;
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(marker_jpip);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the IPTR box
|
|
||||||
*
|
|
||||||
* Index Finder box
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_write_iptr(int offset, int length)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_IPTR, 4); /* IPTR */
|
|
||||||
|
|
||||||
cio_write(offset,8);
|
|
||||||
cio_write(length,8);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the PRXY box
|
|
||||||
*
|
|
||||||
* proxy (box)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void jpip_write_prxy(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_PRXY, 4); /* IPTR */
|
|
||||||
|
|
||||||
cio_write(offset_jp2c,8); /* OOFF */
|
|
||||||
cio_write(length_jp2c,4); /* OBH part 1 */
|
|
||||||
cio_write(JP2C,4); /* OBH part 2 */
|
|
||||||
|
|
||||||
cio_write(1,1); /* NI */
|
|
||||||
|
|
||||||
cio_write(offset_idx,8); /* IOFF */
|
|
||||||
cio_write(length_idx,4); /* IBH part 1 */
|
|
||||||
cio_write(JPIP_CIDX,4); /* IBH part 2 */
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write the FIDX box
|
|
||||||
*
|
|
||||||
* File Index (superbox)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
int jpip_write_fidx(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx)
|
|
||||||
{
|
|
||||||
int len, lenp;
|
|
||||||
lenp=cio_tell();
|
|
||||||
cio_skip(4); /* L [at the end] */
|
|
||||||
cio_write(JPIP_FIDX, 4); /* IPTR */
|
|
||||||
|
|
||||||
jpip_write_prxy(offset_jp2c, length_jp2c, offset_idx, offset_jp2c);
|
|
||||||
|
|
||||||
len=cio_tell()-lenp;
|
|
||||||
cio_seek(lenp);
|
|
||||||
cio_write(len, 4); /* L */
|
|
||||||
cio_seek(lenp+len);
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __JPIP_H
|
|
||||||
#define __JPIP_H
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
|
|
||||||
// Codestream index box (superbox)
|
|
||||||
int jpip_write_cidx(int offset, info_image_t img, j2k_cp_t *j2k_cp, int version);
|
|
||||||
|
|
||||||
// Index Finder Box
|
|
||||||
void jpip_write_iptr(int offset, int length);
|
|
||||||
|
|
||||||
// File Index Box
|
|
||||||
int jpip_write_fidx(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,465 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003-2004, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "pi.h"
|
|
||||||
#include "int.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Create a packet iterator. */
|
|
||||||
/* </summary> */
|
|
||||||
pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
|
|
||||||
{
|
|
||||||
int p, q;
|
|
||||||
int compno, resno, pino;
|
|
||||||
int maxres = 0;
|
|
||||||
pi_iterator_t *pi;
|
|
||||||
j2k_tcp_t *tcp;
|
|
||||||
j2k_tccp_t *tccp;
|
|
||||||
|
|
||||||
tcp = &cp->tcps[tileno];
|
|
||||||
pi = (pi_iterator_t *) malloc((tcp->numpocs + 1) * sizeof(pi_iterator_t));
|
|
||||||
|
|
||||||
for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */
|
|
||||||
p = tileno % cp->tw;
|
|
||||||
q = tileno / cp->tw;
|
|
||||||
|
|
||||||
pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, img->x0);
|
|
||||||
pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, img->y0);
|
|
||||||
pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, img->x1);
|
|
||||||
pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, img->y1);
|
|
||||||
pi[pino].numcomps = img->numcomps;
|
|
||||||
pi[pino].comps = (pi_comp_t *) malloc(img->numcomps * sizeof(pi_comp_t));
|
|
||||||
|
|
||||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
|
||||||
int tcx0, tcy0, tcx1, tcy1;
|
|
||||||
pi_comp_t *comp = &pi[pino].comps[compno];
|
|
||||||
tccp = &tcp->tccps[compno];
|
|
||||||
comp->dx = img->comps[compno].dx;
|
|
||||||
comp->dy = img->comps[compno].dy;
|
|
||||||
comp->numresolutions = tccp->numresolutions;
|
|
||||||
comp->resolutions =
|
|
||||||
(pi_resolution_t *) malloc(comp->numresolutions *
|
|
||||||
sizeof(pi_resolution_t));
|
|
||||||
tcx0 = int_ceildiv(pi->tx0, comp->dx);
|
|
||||||
tcy0 = int_ceildiv(pi->ty0, comp->dy);
|
|
||||||
tcx1 = int_ceildiv(pi->tx1, comp->dx);
|
|
||||||
tcy1 = int_ceildiv(pi->ty1, comp->dy);
|
|
||||||
if (comp->numresolutions > maxres) {
|
|
||||||
maxres = comp->numresolutions;
|
|
||||||
}
|
|
||||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
|
||||||
int levelno;
|
|
||||||
int rx0, ry0, rx1, ry1;
|
|
||||||
int px0, py0, px1, py1;
|
|
||||||
pi_resolution_t *res = &comp->resolutions[resno];
|
|
||||||
if (tccp->csty & J2K_CCP_CSTY_PRT) {
|
|
||||||
res->pdx = tccp->prcw[resno];
|
|
||||||
res->pdy = tccp->prch[resno];
|
|
||||||
} else {
|
|
||||||
res->pdx = 15;
|
|
||||||
res->pdy = 15;
|
|
||||||
}
|
|
||||||
levelno = comp->numresolutions - 1 - resno;
|
|
||||||
rx0 = int_ceildivpow2(tcx0, levelno);
|
|
||||||
ry0 = int_ceildivpow2(tcy0, levelno);
|
|
||||||
rx1 = int_ceildivpow2(tcx1, levelno);
|
|
||||||
ry1 = int_ceildivpow2(tcy1, levelno);
|
|
||||||
px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
|
|
||||||
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
|
||||||
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
|
||||||
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
|
||||||
res->pw = (px1 - px0) >> res->pdx;
|
|
||||||
res->ph = (py1 - py0) >> res->pdy;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tccp = &tcp->tccps[0];
|
|
||||||
pi[pino].step_p=1;
|
|
||||||
pi[pino].step_c=100*pi[pino].step_p;
|
|
||||||
pi[pino].step_r=img->numcomps*pi[pino].step_c;
|
|
||||||
pi[pino].step_l=maxres*pi[pino].step_r;
|
|
||||||
|
|
||||||
if (pino==0)
|
|
||||||
pi[pino].include=(short int*)calloc(img->numcomps*maxres*tcp->numlayers*100,sizeof(short int));
|
|
||||||
else
|
|
||||||
pi[pino].include=pi[pino-1].include;
|
|
||||||
|
|
||||||
/*if (pino == tcp->numpocs) {*/
|
|
||||||
if (tcp->POC == 0) {
|
|
||||||
pi[pino].first = 1;
|
|
||||||
pi[pino].poc.resno0 = 0;
|
|
||||||
pi[pino].poc.compno0 = 0;
|
|
||||||
pi[pino].poc.layno1 = tcp->numlayers;
|
|
||||||
pi[pino].poc.resno1 = maxres;
|
|
||||||
pi[pino].poc.compno1 = img->numcomps;
|
|
||||||
pi[pino].poc.prg = tcp->prg;
|
|
||||||
} else {
|
|
||||||
pi[pino].first = 1;
|
|
||||||
pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
|
|
||||||
pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
|
|
||||||
pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
|
|
||||||
pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
|
|
||||||
pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
|
|
||||||
pi[pino].poc.prg = tcp->pocs[pino].prg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pi;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet in layer=resolution-component-precinct order. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next_lrcp(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
pi_comp_t *comp;
|
|
||||||
pi_resolution_t *res;
|
|
||||||
|
|
||||||
if (!pi->first) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
goto skip;
|
|
||||||
} else {
|
|
||||||
pi->first = 0;
|
|
||||||
}
|
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
|
||||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1;
|
|
||||||
pi->resno++) {
|
|
||||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
|
||||||
pi->compno++) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
if (pi->resno >= comp->numresolutions) {
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
|
|
||||||
if (!pi->include[pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p]){
|
|
||||||
pi->include[pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p] = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
skip:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet in resolution-layer-component-precinct order. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next_rlcp(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
pi_comp_t *comp;
|
|
||||||
pi_resolution_t *res;
|
|
||||||
if (!pi->first) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
goto skip;
|
|
||||||
} else {
|
|
||||||
pi->first = 0;
|
|
||||||
}
|
|
||||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
|
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
|
||||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
|
||||||
pi->compno++) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
if (pi->resno >= comp->numresolutions) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
for (pi->precno = 0; pi->precno < res->pw * res->ph; pi->precno++) {
|
|
||||||
if (!pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
|
|
||||||
pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
skip:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet in resolution-precinct-component-layer order. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next_rpcl(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
pi_comp_t *comp;
|
|
||||||
pi_resolution_t *res;
|
|
||||||
if (!pi->first) {
|
|
||||||
goto skip;
|
|
||||||
} else {
|
|
||||||
int compno, resno;
|
|
||||||
pi->first = 0;
|
|
||||||
pi->dx = 0;
|
|
||||||
pi->dy = 0;
|
|
||||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
|
||||||
comp = &pi->comps[compno];
|
|
||||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
|
||||||
int dx, dy;
|
|
||||||
res = &comp->resolutions[resno];
|
|
||||||
dx =
|
|
||||||
comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
|
|
||||||
dy =
|
|
||||||
comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
|
|
||||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
|
||||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
|
|
||||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
|
||||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
|
||||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
|
||||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
|
||||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
|
||||||
pi->compno++) {
|
|
||||||
int levelno;
|
|
||||||
int trx0, try0;
|
|
||||||
int rpx, rpy;
|
|
||||||
int prci, prcj;
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
if (pi->resno >= comp->numresolutions) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
|
||||||
rpx = res->pdx + levelno;
|
|
||||||
rpy = res->pdy + levelno;
|
|
||||||
if (!
|
|
||||||
(pi->x % (comp->dx << rpx) == 0
|
|
||||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!
|
|
||||||
(pi->y % (comp->dy << rpy) == 0
|
|
||||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
prci =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
|
|
||||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
|
||||||
prcj =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
|
|
||||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
|
||||||
pi->precno = prci + prcj * res->pw;
|
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
|
||||||
if (!pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
|
|
||||||
pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
skip:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet in precinct-component-resolution-layer order. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next_pcrl(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
pi_comp_t *comp;
|
|
||||||
pi_resolution_t *res;
|
|
||||||
if (!pi->first) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
goto skip;
|
|
||||||
} else {
|
|
||||||
int compno, resno;
|
|
||||||
pi->first = 0;
|
|
||||||
pi->dx = 0;
|
|
||||||
pi->dy = 0;
|
|
||||||
for (compno = 0; compno < pi->numcomps; compno++) {
|
|
||||||
comp = &pi->comps[compno];
|
|
||||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
|
||||||
int dx, dy;
|
|
||||||
res = &comp->resolutions[resno];
|
|
||||||
dx =
|
|
||||||
comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
|
|
||||||
dy =
|
|
||||||
comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
|
|
||||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
|
||||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
|
||||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
|
||||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
|
||||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
|
||||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
|
||||||
pi->compno++) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
for (pi->resno = pi->poc.resno0;
|
|
||||||
pi->resno < int_min(pi->poc.resno1, comp->numresolutions);
|
|
||||||
pi->resno++) {
|
|
||||||
int levelno;
|
|
||||||
int trx0, try0;
|
|
||||||
int rpx, rpy;
|
|
||||||
int prci, prcj;
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
|
||||||
rpx = res->pdx + levelno;
|
|
||||||
rpy = res->pdy + levelno;
|
|
||||||
if (!
|
|
||||||
(pi->x % (comp->dx << rpx) == 0
|
|
||||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!
|
|
||||||
(pi->y % (comp->dy << rpy) == 0
|
|
||||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
prci =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
|
|
||||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
|
||||||
prcj =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
|
|
||||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
|
||||||
pi->precno = prci + prcj * res->pw;
|
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
|
||||||
if (! pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
|
|
||||||
pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
skip:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet in component-precinct-resolution-layer order. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next_cprl(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
pi_comp_t *comp;
|
|
||||||
pi_resolution_t *res;
|
|
||||||
if (!pi->first) {
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
goto skip;
|
|
||||||
} else {
|
|
||||||
pi->first = 0;
|
|
||||||
}
|
|
||||||
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1;
|
|
||||||
pi->compno++) {
|
|
||||||
int resno;
|
|
||||||
comp = &pi->comps[pi->compno];
|
|
||||||
pi->dx = 0;
|
|
||||||
pi->dy = 0;
|
|
||||||
for (resno = 0; resno < comp->numresolutions; resno++) {
|
|
||||||
int dx, dy;
|
|
||||||
res = &comp->resolutions[resno];
|
|
||||||
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
|
|
||||||
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
|
|
||||||
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
|
|
||||||
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
|
|
||||||
}
|
|
||||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
|
||||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
|
||||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
|
||||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
|
||||||
for (pi->resno = pi->poc.resno0;
|
|
||||||
pi->resno < int_min(pi->poc.resno1, comp->numresolutions);
|
|
||||||
pi->resno++) {
|
|
||||||
int levelno;
|
|
||||||
int trx0, try0;
|
|
||||||
int rpx, rpy;
|
|
||||||
int prci, prcj;
|
|
||||||
res = &comp->resolutions[pi->resno];
|
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
|
||||||
rpx = res->pdx + levelno;
|
|
||||||
rpy = res->pdy + levelno;
|
|
||||||
if (!
|
|
||||||
(pi->x % (comp->dx << rpx) == 0
|
|
||||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!
|
|
||||||
(pi->y % (comp->dy << rpy) == 0
|
|
||||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
prci =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelno),
|
|
||||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
|
||||||
prcj =
|
|
||||||
int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelno),
|
|
||||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
|
||||||
pi->precno = prci + prcj * res->pw;
|
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
|
||||||
if (! pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p]){
|
|
||||||
pi->include[pi->layno*pi->step_l+pi->resno*pi->step_r+pi->compno*pi->step_c+pi->precno*pi->step_p] = 1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
skip:;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* <summary> */
|
|
||||||
/* Get next packet. */
|
|
||||||
/* </summary> */
|
|
||||||
int pi_next(pi_iterator_t * pi)
|
|
||||||
{
|
|
||||||
switch (pi->poc.prg) {
|
|
||||||
case 0:
|
|
||||||
return pi_next_lrcp(pi);
|
|
||||||
case 1:
|
|
||||||
return pi_next_rlcp(pi);
|
|
||||||
case 2:
|
|
||||||
return pi_next_rpcl(pi);
|
|
||||||
case 3:
|
|
||||||
return pi_next_pcrl(pi);
|
|
||||||
case 4:
|
|
||||||
return pi_next_cprl(pi);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* 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 __PI_H
|
|
||||||
#define __PI_H
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
#include "tcd.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int pdx, pdy;
|
|
||||||
int pw, ph;
|
|
||||||
} pi_resolution_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int dx, dy;
|
|
||||||
int numresolutions;
|
|
||||||
pi_resolution_t *resolutions;
|
|
||||||
} pi_comp_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
short int *include;
|
|
||||||
int step_l, step_r, step_c, step_p;
|
|
||||||
int compno, resno, precno, layno; /* component, resolution, precinct and layer that indentify the packet */
|
|
||||||
int first;
|
|
||||||
j2k_poc_t poc;
|
|
||||||
int numcomps;
|
|
||||||
pi_comp_t *comps;
|
|
||||||
int tx0, ty0, tx1, ty1;
|
|
||||||
int x, y, dx, dy;
|
|
||||||
} pi_iterator_t; /* packet iterator */
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a packet iterator
|
|
||||||
* img: raw image for which the packets will be listed
|
|
||||||
* cp: coding paremeters
|
|
||||||
* tileno: number that identifies the tile for which to list the packets
|
|
||||||
* return value: returns a packet iterator that points to the first packet of the tile
|
|
||||||
*/
|
|
||||||
pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Modify the packet iterator to point to the next packet
|
|
||||||
* pi: packet iterator to modify
|
|
||||||
* return value: returns 0 if pi pointed to the last packet or else returns 1
|
|
||||||
*/
|
|
||||||
int pi_next(pi_iterator_t * pi);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,389 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "t2.h"
|
|
||||||
#include "tcd.h"
|
|
||||||
#include "bio.h"
|
|
||||||
#include "j2k.h"
|
|
||||||
#include "pi.h"
|
|
||||||
#include "tgt.h"
|
|
||||||
#include "int.h"
|
|
||||||
#include "cio.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define RESTART 0x04
|
|
||||||
|
|
||||||
extern jmp_buf j2k_error;
|
|
||||||
|
|
||||||
int t2_getcommacode() {
|
|
||||||
int n;
|
|
||||||
for (n=0; bio_read(1); n++) {}
|
|
||||||
return n;
|
|
||||||
}
|
|
||||||
|
|
||||||
int t2_getnumpasses()
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
if (!bio_read(1)) return 1;
|
|
||||||
if (!bio_read(1)) return 2;
|
|
||||||
if ((n=bio_read(2))!=3) return 3+n;
|
|
||||||
if ((n=bio_read(5))!=31) return 6+n;
|
|
||||||
return 37+bio_read(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
void t2_init_seg(tcd_seg_t *seg, int cblksty) {
|
|
||||||
seg->numpasses=0;
|
|
||||||
seg->len=0;
|
|
||||||
seg->maxpasses=cblksty&J2K_CCP_CBLKSTY_TERMALL?1:100;
|
|
||||||
}
|
|
||||||
|
|
||||||
int t2_decode_packet(unsigned char *src, int len, tcd_tile_t *tile, j2k_cp_t * cp, j2k_tcp_t *tcp, int compno, int resno, int precno, int layno, info_layer_t *layer_Idx) {
|
|
||||||
int bandno, cblkno;
|
|
||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
|
||||||
tcd_resolution_t *res = &tilec->resolutions[resno];
|
|
||||||
unsigned char *c = src;
|
|
||||||
unsigned char *d = c;
|
|
||||||
int e;
|
|
||||||
int present;
|
|
||||||
|
|
||||||
if (layno == 0) {
|
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
|
||||||
tgt_reset(prc->incltree);
|
|
||||||
tgt_reset(prc->imsbtree);
|
|
||||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
|
||||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
|
||||||
cblk->numsegs = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* INDEX */
|
|
||||||
layer_Idx->len_header = 0;
|
|
||||||
|
|
||||||
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
|
|
||||||
This part deal with this caracteristic
|
|
||||||
step 1: Read packet header in the saved structure
|
|
||||||
step 2: (futher) return to codestream for decoding */
|
|
||||||
if (cp->ppm == 1) /* PPM */
|
|
||||||
{
|
|
||||||
c = cp->ppm_data;
|
|
||||||
d = c;
|
|
||||||
bio_init_dec(c, 1000);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (tcp->ppt == 1) /* PPT */
|
|
||||||
{
|
|
||||||
c = tcp->ppt_data;
|
|
||||||
d = c;
|
|
||||||
bio_init_dec(c, 1000);
|
|
||||||
} else /* Normal Case */
|
|
||||||
{
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_SOP)
|
|
||||||
{
|
|
||||||
if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [1]!!!\n");}
|
|
||||||
c += 6;
|
|
||||||
}
|
|
||||||
bio_init_dec(c, src + len - c);
|
|
||||||
layer_Idx->len_header = -6;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
present = bio_read(1);
|
|
||||||
|
|
||||||
if (!present)
|
|
||||||
{
|
|
||||||
bio_inalign();
|
|
||||||
/* Normal case */
|
|
||||||
c += bio_numbytes();
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_EPH)
|
|
||||||
{
|
|
||||||
if ((*c) != 255 || (*(c+1) != 146)) {printf("Error : expected EPH marker [1]!!!\n");}
|
|
||||||
c += 2;
|
|
||||||
}
|
|
||||||
/* INDEX */
|
|
||||||
layer_Idx->len_header += (c-d);
|
|
||||||
|
|
||||||
/* PPT and PPM dealing */
|
|
||||||
if (cp->ppm == 1) /* PPM */
|
|
||||||
{
|
|
||||||
cp->ppm_data = c;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (tcp->ppt == 1) /* PPT */
|
|
||||||
{
|
|
||||||
tcp->ppt_data = c;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return c - src;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (bandno=0; bandno<res->numbands; bandno++) {
|
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
|
||||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
|
||||||
int included, increment, n;
|
|
||||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
|
||||||
tcd_seg_t *seg;
|
|
||||||
if (!cblk->numsegs) {
|
|
||||||
included = tgt_decode(prc->incltree, cblkno, layno+1);
|
|
||||||
} else {
|
|
||||||
included = bio_read(1);
|
|
||||||
}
|
|
||||||
if (!included) {
|
|
||||||
cblk->numnewpasses = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!cblk->numsegs) {
|
|
||||||
int i, numimsbs;
|
|
||||||
for (i = 0; !tgt_decode(prc->imsbtree, cblkno, i); i++) {}
|
|
||||||
numimsbs = i-1;
|
|
||||||
cblk->numbps = band->numbps - numimsbs;
|
|
||||||
cblk->numlenbits = 3;
|
|
||||||
}
|
|
||||||
cblk->numnewpasses = t2_getnumpasses();
|
|
||||||
increment = t2_getcommacode();
|
|
||||||
cblk->numlenbits += increment;
|
|
||||||
if (!cblk->numsegs) {
|
|
||||||
seg = &cblk->segs[0];
|
|
||||||
t2_init_seg(seg, tcp->tccps[compno].cblksty);
|
|
||||||
} else {
|
|
||||||
seg = &cblk->segs[cblk->numsegs - 1];
|
|
||||||
if (seg->numpasses == seg->maxpasses) {
|
|
||||||
t2_init_seg(++seg, tcp->tccps[compno].cblksty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n = cblk->numnewpasses;
|
|
||||||
do {
|
|
||||||
seg->numnewpasses = int_min(seg->maxpasses-seg->numpasses, n);
|
|
||||||
seg->newlen = bio_read(cblk->numlenbits + int_floorlog2(seg->numnewpasses));
|
|
||||||
n -= seg->numnewpasses;
|
|
||||||
if (n > 0) {
|
|
||||||
t2_init_seg(++seg, tcp->tccps[compno].cblksty);
|
|
||||||
}
|
|
||||||
} while (n > 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(bio_inalign()) return -999;
|
|
||||||
c += bio_numbytes();
|
|
||||||
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_EPH) { /* EPH marker */
|
|
||||||
if ((*c) != 255 || (*(c+1) != 146)) {printf("Error : expected EPH marker [2]!!!\n"); }
|
|
||||||
c += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* INDEX */
|
|
||||||
layer_Idx->len_header += (c-d);
|
|
||||||
|
|
||||||
/* PPT Step 2 : see above for details */
|
|
||||||
if (cp->ppm == 1)
|
|
||||||
{
|
|
||||||
cp->ppm_data = c; /* Update pointer */
|
|
||||||
|
|
||||||
/* INDEX */
|
|
||||||
layer_Idx->len_header = c-d;
|
|
||||||
|
|
||||||
c = src;
|
|
||||||
d = c;
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_SOP)
|
|
||||||
{
|
|
||||||
if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [2] !!!\n"); }
|
|
||||||
c += 6;
|
|
||||||
}
|
|
||||||
bio_init_dec(c, src + len - c);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
if (tcp->ppt == 1)
|
|
||||||
{
|
|
||||||
tcp->ppt_data = c; /* Update pointer */
|
|
||||||
/* INDEX */
|
|
||||||
layer_Idx->len_header = c-d;
|
|
||||||
|
|
||||||
c = src;
|
|
||||||
d = c;
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_SOP) /* SOP marker */
|
|
||||||
{
|
|
||||||
if ((*c) != 255 || (*(c+1) != 145)) {printf("Error : expected SOP marker [2] !!!\n"); }
|
|
||||||
c += 6;
|
|
||||||
}
|
|
||||||
bio_init_dec(c, src + len - c);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
|
||||||
for (cblkno = 0; cblkno < prc->cw*prc->ch; cblkno++) {
|
|
||||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
|
||||||
tcd_seg_t *seg;
|
|
||||||
if (!cblk->numnewpasses) continue;
|
|
||||||
if (!cblk->numsegs) {
|
|
||||||
seg = &cblk->segs[cblk->numsegs++];
|
|
||||||
cblk->len = 0;
|
|
||||||
} else {
|
|
||||||
seg = &cblk->segs[cblk->numsegs-1];
|
|
||||||
if (seg->numpasses == seg->maxpasses) {
|
|
||||||
seg++;
|
|
||||||
cblk->numsegs++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
if (c + seg->newlen > src + len) return -999;
|
|
||||||
memcpy(cblk->data + cblk->len, c, seg->newlen);
|
|
||||||
if (seg->numpasses == 0) {
|
|
||||||
seg->data = cblk->data + cblk->len;
|
|
||||||
}
|
|
||||||
c += seg->newlen;
|
|
||||||
cblk->len += seg->newlen;
|
|
||||||
seg->len += seg->newlen;
|
|
||||||
seg->numpasses += seg->numnewpasses;
|
|
||||||
cblk->numnewpasses -= seg->numnewpasses;
|
|
||||||
if (cblk->numnewpasses > 0) {
|
|
||||||
seg++;
|
|
||||||
cblk->numsegs++;
|
|
||||||
}
|
|
||||||
} while (cblk->numnewpasses > 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* <INDEX> */
|
|
||||||
e = c-d;
|
|
||||||
layer_Idx->len = e;
|
|
||||||
/* </INDEX> */
|
|
||||||
|
|
||||||
return c-src;
|
|
||||||
}
|
|
||||||
|
|
||||||
void t2_init_info_packets(info_image_t *img, j2k_cp_t *cp)
|
|
||||||
{
|
|
||||||
int compno, tileno, resno, precno, layno;
|
|
||||||
|
|
||||||
for(compno = 0; compno < img->Comp; compno++)
|
|
||||||
{
|
|
||||||
for(tileno = 0; tileno < img->tw*img->th; tileno++)
|
|
||||||
{
|
|
||||||
info_tile_t *tile_Idx = &img->tile[tileno];
|
|
||||||
info_compo_t *compo_Idx = &tile_Idx->compo[compno];
|
|
||||||
for(resno = 0; resno < img->Decomposition + 1 ; resno++)
|
|
||||||
{
|
|
||||||
info_reso_t *reso_Idx = &compo_Idx->reso[resno];
|
|
||||||
for (precno = 0; precno < img->tile[tileno].pw * img->tile[tileno].ph; precno++)
|
|
||||||
{
|
|
||||||
info_prec_t *prec_Idx = &reso_Idx->prec[precno];
|
|
||||||
for(layno = 0; layno < img->Layer ; layno++)
|
|
||||||
{
|
|
||||||
info_layer_t *layer_Idx = &prec_Idx->layer[layno];
|
|
||||||
layer_Idx->offset = 0; /* start position */
|
|
||||||
layer_Idx->len_header = 0; /* length */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int t2_decode_packets(unsigned char *src, int len, j2k_image_t *img, j2k_cp_t *cp, int tileno, tcd_tile_t *tile, info_image_t *imgg) {
|
|
||||||
unsigned char *c = src;
|
|
||||||
pi_iterator_t *pi;
|
|
||||||
int pino, compno,e;
|
|
||||||
int partno;
|
|
||||||
info_tile_part_t *tile_part;
|
|
||||||
int position;
|
|
||||||
int length_read;
|
|
||||||
info_tile_t *tile_Idx;
|
|
||||||
info_compo_t *compo_Idx;
|
|
||||||
info_reso_t *reso_Idx;
|
|
||||||
info_prec_t *prec_Idx;
|
|
||||||
info_layer_t *layer_Idx;
|
|
||||||
|
|
||||||
t2_init_info_packets(imgg, cp); /* Initialize the packets information : LEN and OFFSET to 0 */
|
|
||||||
|
|
||||||
tile_Idx = &imgg->tile[tileno];
|
|
||||||
tile_Idx->num_packet = 0;
|
|
||||||
pi = pi_create(img, cp, tileno);
|
|
||||||
partno = 0;
|
|
||||||
tile_part = &tile_Idx->tile_parts[partno];
|
|
||||||
position = tile_part->end_header + 1;
|
|
||||||
length_read = 0;
|
|
||||||
|
|
||||||
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++)
|
|
||||||
{
|
|
||||||
while (pi_next(&pi[pino]))
|
|
||||||
{
|
|
||||||
compo_Idx = &tile_Idx->compo[pi[pino].compno];
|
|
||||||
reso_Idx = &compo_Idx->reso[pi[pino].resno];
|
|
||||||
prec_Idx = &reso_Idx->prec[pi[pino].precno];
|
|
||||||
layer_Idx = &prec_Idx->layer[pi[pino].layno];
|
|
||||||
|
|
||||||
layer_Idx->offset = position;
|
|
||||||
layer_Idx->offset_header = position;
|
|
||||||
|
|
||||||
e = t2_decode_packet(c, src+len-c, tile, cp, &cp->tcps[tileno], pi[pino].compno, pi[pino].resno, pi[pino].precno, pi[pino].layno,layer_Idx);
|
|
||||||
if (e == -999)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
} else
|
|
||||||
c += e;
|
|
||||||
position += e;
|
|
||||||
|
|
||||||
/* Update position in case of multiple tile-parts for a tile >> */
|
|
||||||
length_read += e;
|
|
||||||
if (length_read >= (tile_part->end_pos - tile_part->end_header))
|
|
||||||
{
|
|
||||||
partno++;
|
|
||||||
tile_part = &tile_Idx->tile_parts[partno];
|
|
||||||
position = tile_part->end_header + 1;
|
|
||||||
length_read = 0;
|
|
||||||
}
|
|
||||||
/* << end_update */
|
|
||||||
|
|
||||||
tile_Idx->num_packet++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FREE space memory taken by pi
|
|
||||||
for (compno = 0; compno < pi[pino].numcomps; compno++)
|
|
||||||
{
|
|
||||||
free(pi[pino].comps[compno].resolutions);
|
|
||||||
}
|
|
||||||
free(pi[pino].comps);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(pi[0].include);
|
|
||||||
free(pi);
|
|
||||||
|
|
||||||
if (e==-999)
|
|
||||||
return e;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
imgg->num_packet_max=int_max(imgg->num_packet_max,tile_Idx->num_packet);
|
|
||||||
return c-src;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __T2_H
|
|
||||||
#define __T2_H
|
|
||||||
|
|
||||||
#include "tcd.h"
|
|
||||||
#include "j2k.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decode the packets of a tile from a source buffer
|
|
||||||
* src: the source buffer
|
|
||||||
* len: length of the source buffer
|
|
||||||
* img: destination image
|
|
||||||
* cp: image coding parameters
|
|
||||||
* tileno: number that identifies the tile for which to decode the packets
|
|
||||||
* tile: tile for which to decode the packets
|
|
||||||
*/
|
|
||||||
int t2_decode_packets(unsigned char *src, int len, j2k_image_t *img, j2k_cp_t *cp, int tileno, tcd_tile_t *tile, info_image_t *imgg);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tcd.h"
|
|
||||||
#include "int.h"
|
|
||||||
#include "t2.h"
|
|
||||||
#include <setjmp.h>
|
|
||||||
#include <float.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
static tcd_image_t tcd_image;
|
|
||||||
|
|
||||||
static j2k_image_t *tcd_img;
|
|
||||||
static j2k_cp_t *tcd_cp;
|
|
||||||
|
|
||||||
extern jmp_buf j2k_error;
|
|
||||||
|
|
||||||
void tcd_init(j2k_image_t *img, j2k_cp_t *cp, info_image_t *imgg) {
|
|
||||||
int tileno, compno, resno, bandno, precno, cblkno;
|
|
||||||
tcd_img=img;
|
|
||||||
tcd_cp=cp;
|
|
||||||
tcd_image.tw=cp->tw;
|
|
||||||
tcd_image.th=cp->th;
|
|
||||||
tcd_image.tiles=(tcd_tile_t*)malloc(cp->tw*cp->th*sizeof(tcd_tile_t));
|
|
||||||
for (tileno=0; tileno<cp->tw*cp->th; tileno++) {
|
|
||||||
j2k_tcp_t *tcp=&cp->tcps[tileno];
|
|
||||||
tcd_tile_t *tile=&tcd_image.tiles[tileno];
|
|
||||||
// cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000)
|
|
||||||
int p=tileno%cp->tw; // si numerotation matricielle ..
|
|
||||||
int q=tileno/cp->tw; // .. coordonnees de la tile (q,p) q pour ligne et p pour colonne
|
|
||||||
info_tile_t *tile_Idx=&imgg->tile[tileno]; // INDEX
|
|
||||||
|
|
||||||
// 4 borders of the tile rescale on the image if necessary
|
|
||||||
tile->x0=int_max(cp->tx0+p*cp->tdx, img->x0);
|
|
||||||
tile->y0=int_max(cp->ty0+q*cp->tdy, img->y0);
|
|
||||||
tile->x1=int_min(cp->tx0+(p+1)*cp->tdx, img->x1);
|
|
||||||
tile->y1=int_min(cp->ty0+(q+1)*cp->tdy, img->y1);
|
|
||||||
|
|
||||||
tile->numcomps=img->numcomps;
|
|
||||||
tile->comps=(tcd_tilecomp_t*)malloc(img->numcomps*sizeof(tcd_tilecomp_t));
|
|
||||||
tile_Idx->compo=(info_compo_t*)malloc(img->numcomps*sizeof(info_compo_t)); // INDEX
|
|
||||||
for (compno=0; compno<tile->numcomps; compno++) {
|
|
||||||
j2k_tccp_t *tccp=&tcp->tccps[compno];
|
|
||||||
tcd_tilecomp_t *tilec=&tile->comps[compno];
|
|
||||||
info_compo_t *compo_Idx=&tile_Idx->compo[compno]; // INDEX
|
|
||||||
|
|
||||||
// border of each tile component (global)
|
|
||||||
tilec->x0=int_ceildiv(tile->x0, img->comps[compno].dx);
|
|
||||||
tilec->y0=int_ceildiv(tile->y0, img->comps[compno].dy);
|
|
||||||
tilec->x1=int_ceildiv(tile->x1, img->comps[compno].dx);
|
|
||||||
tilec->y1=int_ceildiv(tile->y1, img->comps[compno].dy);
|
|
||||||
|
|
||||||
tilec->data=(int*)malloc(sizeof(int)*(tilec->x1-tilec->x0)*(tilec->y1-tilec->y0));
|
|
||||||
tilec->numresolutions=tccp->numresolutions;
|
|
||||||
tilec->resolutions=(tcd_resolution_t*)malloc(tilec->numresolutions*sizeof(tcd_resolution_t));
|
|
||||||
compo_Idx->reso=(info_reso_t*)malloc(tilec->numresolutions*sizeof(info_reso_t)); // INDEX
|
|
||||||
for (resno=0; resno<tilec->numresolutions; resno++) {
|
|
||||||
int pdx, pdy;
|
|
||||||
int levelno=tilec->numresolutions-1-resno;
|
|
||||||
int tlprcxstart, tlprcystart, brprcxend, brprcyend;
|
|
||||||
int tlcbgxstart, tlcbgystart, brcbgxend, brcbgyend;
|
|
||||||
int cbgwidthexpn, cbgheightexpn;
|
|
||||||
int cblkwidthexpn, cblkheightexpn;
|
|
||||||
tcd_resolution_t *res=&tilec->resolutions[resno];
|
|
||||||
info_reso_t *res_Idx=&compo_Idx->reso[resno]; // INDEX
|
|
||||||
int precno_Idx; // INDEX
|
|
||||||
|
|
||||||
// border for each resolution level (global)
|
|
||||||
res->x0=int_ceildivpow2(tilec->x0, levelno);
|
|
||||||
res->y0=int_ceildivpow2(tilec->y0, levelno);
|
|
||||||
res->x1=int_ceildivpow2(tilec->x1, levelno);
|
|
||||||
res->y1=int_ceildivpow2(tilec->y1, levelno);
|
|
||||||
|
|
||||||
res->numbands=resno==0?1:3;
|
|
||||||
// p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000)
|
|
||||||
if (tccp->csty&J2K_CCP_CSTY_PRT) {
|
|
||||||
pdx=tccp->prcw[resno];
|
|
||||||
pdy=tccp->prch[resno];
|
|
||||||
} else {
|
|
||||||
pdx=15;
|
|
||||||
pdy=15;
|
|
||||||
}
|
|
||||||
// p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000)
|
|
||||||
tlprcxstart=int_floordivpow2(res->x0, pdx)<<pdx;
|
|
||||||
tlprcystart=int_floordivpow2(res->y0, pdy)<<pdy;
|
|
||||||
brprcxend=int_ceildivpow2(res->x1, pdx)<<pdx;
|
|
||||||
brprcyend=int_ceildivpow2(res->y1, pdy)<<pdy;
|
|
||||||
res->pw=(brprcxend-tlprcxstart)>>pdx;
|
|
||||||
res->ph=(brprcyend-tlprcystart)>>pdy;
|
|
||||||
|
|
||||||
// <INDEX>
|
|
||||||
imgg->tile[tileno].pw=res->pw;
|
|
||||||
imgg->tile[tileno].ph=res->ph;
|
|
||||||
|
|
||||||
res_Idx->prec=(info_prec_t*)malloc(res->pw*res->ph*sizeof(info_prec_t));
|
|
||||||
for (precno_Idx=0;precno_Idx<res->pw*res->ph;precno_Idx++)
|
|
||||||
{
|
|
||||||
info_prec_t *prec_Idx = &res_Idx->prec[precno_Idx];
|
|
||||||
prec_Idx->layer=(info_layer_t*)malloc(imgg->Layer*sizeof(info_layer_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
imgg->pw=res->pw; // old parser version
|
|
||||||
imgg->ph=res->ph; // old parser version
|
|
||||||
imgg->pdx=1<<pdx;
|
|
||||||
imgg->pdy=1<<pdy;
|
|
||||||
// </INDEX>
|
|
||||||
|
|
||||||
if (resno==0) {
|
|
||||||
tlcbgxstart=tlprcxstart;
|
|
||||||
tlcbgystart=tlprcystart;
|
|
||||||
brcbgxend=brprcxend;
|
|
||||||
brcbgyend=brprcyend;
|
|
||||||
cbgwidthexpn=pdx;
|
|
||||||
cbgheightexpn=pdy;
|
|
||||||
} else {
|
|
||||||
tlcbgxstart=int_ceildivpow2(tlprcxstart, 1);
|
|
||||||
tlcbgystart=int_ceildivpow2(tlprcystart, 1);
|
|
||||||
brcbgxend=int_ceildivpow2(brprcxend, 1);
|
|
||||||
brcbgyend=int_ceildivpow2(brprcyend, 1);
|
|
||||||
cbgwidthexpn=pdx-1;
|
|
||||||
cbgheightexpn=pdy-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
cblkwidthexpn=int_min(tccp->cblkw, cbgwidthexpn);
|
|
||||||
cblkheightexpn=int_min(tccp->cblkh, cbgheightexpn);
|
|
||||||
|
|
||||||
for (bandno=0; bandno<res->numbands; bandno++) {
|
|
||||||
int x0b, y0b;
|
|
||||||
tcd_band_t *band=&res->bands[bandno];
|
|
||||||
band->bandno=resno==0?0:bandno+1;
|
|
||||||
x0b=(band->bandno==1)||(band->bandno==3)?1:0;
|
|
||||||
y0b=(band->bandno==2)||(band->bandno==3)?1:0;
|
|
||||||
|
|
||||||
if (band->bandno==0) {
|
|
||||||
// band border (global)
|
|
||||||
band->x0=int_ceildivpow2(tilec->x0, levelno);
|
|
||||||
band->y0=int_ceildivpow2(tilec->y0, levelno);
|
|
||||||
band->x1=int_ceildivpow2(tilec->x1, levelno);
|
|
||||||
band->y1=int_ceildivpow2(tilec->y1, levelno);
|
|
||||||
} else {
|
|
||||||
// band border (global)
|
|
||||||
band->x0=int_ceildivpow2(tilec->x0-(1<<levelno)*x0b, levelno+1);
|
|
||||||
band->y0=int_ceildivpow2(tilec->y0-(1<<levelno)*y0b, levelno+1);
|
|
||||||
band->x1=int_ceildivpow2(tilec->x1-(1<<levelno)*x0b, levelno+1);
|
|
||||||
band->y1=int_ceildivpow2(tilec->y1-(1<<levelno)*y0b, levelno+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
band->precincts=(tcd_precinct_t*)malloc(res->pw*res->ph*sizeof(tcd_precinct_t));
|
|
||||||
|
|
||||||
for (precno=0; precno<res->pw*res->ph; precno++) {
|
|
||||||
int tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend;
|
|
||||||
int cbgxstart=tlcbgxstart+(precno%res->pw)*(1<<cbgwidthexpn);
|
|
||||||
int cbgystart=tlcbgystart+(precno/res->pw)*(1<<cbgheightexpn);
|
|
||||||
int cbgxend=cbgxstart+(1<<cbgwidthexpn);
|
|
||||||
int cbgyend=cbgystart+(1<<cbgheightexpn);
|
|
||||||
tcd_precinct_t *prc=&band->precincts[precno];
|
|
||||||
// precinct size (global)
|
|
||||||
prc->x0=int_max(cbgxstart, band->x0);
|
|
||||||
prc->y0=int_max(cbgystart, band->y0);
|
|
||||||
prc->x1=int_min(cbgxend, band->x1);
|
|
||||||
prc->y1=int_min(cbgyend, band->y1);
|
|
||||||
|
|
||||||
tlcblkxstart=int_floordivpow2(prc->x0, cblkwidthexpn)<<cblkwidthexpn;
|
|
||||||
tlcblkystart=int_floordivpow2(prc->y0, cblkheightexpn)<<cblkheightexpn;
|
|
||||||
brcblkxend=int_ceildivpow2(prc->x1, cblkwidthexpn)<<cblkwidthexpn;
|
|
||||||
brcblkyend=int_ceildivpow2(prc->y1, cblkheightexpn)<<cblkheightexpn;
|
|
||||||
prc->cw=(brcblkxend-tlcblkxstart)>>cblkwidthexpn;
|
|
||||||
prc->ch=(brcblkyend-tlcblkystart)>>cblkheightexpn;
|
|
||||||
|
|
||||||
prc->cblks=(tcd_cblk_t*)malloc(prc->cw*prc->ch*sizeof(tcd_cblk_t));
|
|
||||||
|
|
||||||
prc->incltree=tgt_create(prc->cw, prc->ch);
|
|
||||||
prc->imsbtree=tgt_create(prc->cw, prc->ch);
|
|
||||||
|
|
||||||
for (cblkno=0; cblkno<prc->cw*prc->ch; cblkno++) {
|
|
||||||
int cblkxstart=tlcblkxstart+(cblkno%prc->cw)*(1<<cblkwidthexpn);
|
|
||||||
int cblkystart=tlcblkystart+(cblkno/prc->cw)*(1<<cblkheightexpn);
|
|
||||||
int cblkxend=cblkxstart+(1<<cblkwidthexpn);
|
|
||||||
int cblkyend=cblkystart+(1<<cblkheightexpn);
|
|
||||||
tcd_cblk_t *cblk=&prc->cblks[cblkno];
|
|
||||||
// code-block size (global)
|
|
||||||
cblk->x0=int_max(cblkxstart, prc->x0);
|
|
||||||
cblk->y0=int_max(cblkystart, prc->y0);
|
|
||||||
cblk->x1=int_min(cblkxend, prc->x1);
|
|
||||||
cblk->y1=int_min(cblkyend, prc->y1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void tcd_free(j2k_image_t *img, j2k_cp_t *cp) {
|
|
||||||
int tileno, compno, resno, bandno, precno;
|
|
||||||
tcd_img=img;
|
|
||||||
tcd_cp=cp;
|
|
||||||
tcd_image.tw=cp->tw;
|
|
||||||
tcd_image.th=cp->th;
|
|
||||||
for (tileno=0; tileno<tcd_image.tw*tcd_image.th; tileno++)
|
|
||||||
{
|
|
||||||
// j2k_tcp_t *tcp=&cp->tcps[curtileno];
|
|
||||||
tcd_tile_t *tile=&tcd_image.tiles[tileno];
|
|
||||||
for (compno=0; compno<tile->numcomps; compno++)
|
|
||||||
{
|
|
||||||
tcd_tilecomp_t *tilec=&tile->comps[compno];
|
|
||||||
for (resno=0; resno<tilec->numresolutions; resno++)
|
|
||||||
{
|
|
||||||
tcd_resolution_t *res=&tilec->resolutions[resno];
|
|
||||||
for (bandno=0; bandno<res->numbands; bandno++)
|
|
||||||
{
|
|
||||||
tcd_band_t *band=&res->bands[bandno];
|
|
||||||
for (precno=0; precno<res->pw*res->ph; precno++)
|
|
||||||
{
|
|
||||||
tcd_precinct_t *prc=&band->precincts[precno];
|
|
||||||
|
|
||||||
if (prc->incltree!=NULL)
|
|
||||||
tgt_destroy(prc->incltree);
|
|
||||||
if (prc->imsbtree!=NULL)
|
|
||||||
tgt_destroy(prc->imsbtree);
|
|
||||||
free(prc->cblks);
|
|
||||||
} // for (precno
|
|
||||||
free(band->precincts);
|
|
||||||
} // for (bandno
|
|
||||||
} // for (resno
|
|
||||||
free(tilec->resolutions);
|
|
||||||
} // for (compno
|
|
||||||
free(tile->comps);
|
|
||||||
} // for (tileno
|
|
||||||
free(tcd_image.tiles);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int tcd_decode_tile(unsigned char *src, int len, int tileno, info_image_t *imgg) {
|
|
||||||
int l;
|
|
||||||
int eof=0;
|
|
||||||
tcd_tile_t *tile;
|
|
||||||
|
|
||||||
tile = &tcd_image.tiles[tileno];
|
|
||||||
|
|
||||||
l = t2_decode_packets(src, len, tcd_img, tcd_cp, tileno, tile, imgg);
|
|
||||||
|
|
||||||
if (l==-999)
|
|
||||||
{
|
|
||||||
eof=1;
|
|
||||||
fprintf(stderr, "tcd_decode: incomplete bistream\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eof) {
|
|
||||||
longjmp(j2k_error, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
l=1;
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __TCD_H
|
|
||||||
#define __TCD_H
|
|
||||||
|
|
||||||
#include "j2k.h"
|
|
||||||
#include "tgt.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int numpasses;
|
|
||||||
int len;
|
|
||||||
unsigned char *data;
|
|
||||||
int maxpasses;
|
|
||||||
int numnewpasses;
|
|
||||||
int newlen;
|
|
||||||
} tcd_seg_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int rate;
|
|
||||||
double distortiondec;
|
|
||||||
} tcd_pass_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int numpasses;
|
|
||||||
int len;
|
|
||||||
unsigned char *data;
|
|
||||||
} tcd_layer_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int numbps;
|
|
||||||
int numlenbits;
|
|
||||||
int len;
|
|
||||||
int numpasses;
|
|
||||||
int numnewpasses;
|
|
||||||
int numsegs;
|
|
||||||
tcd_seg_t segs[100];
|
|
||||||
unsigned char data[8192];
|
|
||||||
int numpassesinlayers;
|
|
||||||
tcd_layer_t layers[100];
|
|
||||||
int totalpasses;
|
|
||||||
tcd_pass_t passes[100];
|
|
||||||
} tcd_cblk_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int cw, ch;
|
|
||||||
tcd_cblk_t *cblks;
|
|
||||||
tgt_tree_t *incltree;
|
|
||||||
tgt_tree_t *imsbtree;
|
|
||||||
} tcd_precinct_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int bandno;
|
|
||||||
tcd_precinct_t *precincts;
|
|
||||||
int numbps;
|
|
||||||
int stepsize;
|
|
||||||
} tcd_band_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int previous_x0, previous_y0, previous_x1, previous_y1; // usefull for the DWT
|
|
||||||
int cas_col, cas_row; // usefull for the DWT
|
|
||||||
int pw, ph;
|
|
||||||
int numbands;
|
|
||||||
tcd_band_t bands[3];
|
|
||||||
} tcd_resolution_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int previous_row, previous_col; // usefull for the DWT
|
|
||||||
int numresolutions;
|
|
||||||
tcd_resolution_t *resolutions;
|
|
||||||
int *data;
|
|
||||||
} tcd_tilecomp_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int x0, y0, x1, y1;
|
|
||||||
int numcomps;
|
|
||||||
//int PPT;
|
|
||||||
//int len_ppt;
|
|
||||||
tcd_tilecomp_t *comps;
|
|
||||||
} tcd_tile_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int tw, th;
|
|
||||||
tcd_tile_t *tiles;
|
|
||||||
} tcd_image_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Initialize the tile coder/decoder
|
|
||||||
* img: raw image
|
|
||||||
* cp: coding parameters
|
|
||||||
* imgg: creation of index file
|
|
||||||
*/
|
|
||||||
|
|
||||||
void tcd_init(j2k_image_t *img, j2k_cp_t *cp, info_image_t *imgg);
|
|
||||||
|
|
||||||
void tcd_free(j2k_image_t *img, j2k_cp_t *cp);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decode a tile from a buffer into a raw image
|
|
||||||
* src: source buffer
|
|
||||||
* len: length of the source buffer
|
|
||||||
* tileno: number that identifies the tile that will be decoded
|
|
||||||
* imgg : Structure for index file
|
|
||||||
*/
|
|
||||||
int tcd_decode_tile(unsigned char *src, int len, int tileno, info_image_t *imgg);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "tgt.h"
|
|
||||||
#include "bio.h"
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reset tag-tree.
|
|
||||||
/// </summary>
|
|
||||||
void tgt_reset(tgt_tree_t *tree)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i=0; i<tree->numnodes; i++) {
|
|
||||||
tree->nodes[i].value=999;
|
|
||||||
tree->nodes[i].low=0;
|
|
||||||
tree->nodes[i].known=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create tag-tree.
|
|
||||||
/// </summary>
|
|
||||||
tgt_tree_t *tgt_create(int numleafsh, int numleafsv)
|
|
||||||
{
|
|
||||||
int nplh[32];
|
|
||||||
int nplv[32];
|
|
||||||
tgt_node_t *node;
|
|
||||||
tgt_node_t *parentnode;
|
|
||||||
tgt_node_t *parentnode0;
|
|
||||||
tgt_tree_t *tree;
|
|
||||||
int i, j, k;
|
|
||||||
int numlvls;
|
|
||||||
int n;
|
|
||||||
|
|
||||||
tree=(tgt_tree_t*)malloc(sizeof(tgt_tree_t));
|
|
||||||
tree->numleafsh=numleafsh;
|
|
||||||
tree->numleafsv=numleafsv;
|
|
||||||
|
|
||||||
numlvls=0;
|
|
||||||
nplh[0]=numleafsh;
|
|
||||||
nplv[0]=numleafsv;
|
|
||||||
tree->numnodes=0;
|
|
||||||
do {
|
|
||||||
n=nplh[numlvls]*nplv[numlvls];
|
|
||||||
nplh[numlvls+1]=(nplh[numlvls]+1)/2;
|
|
||||||
nplv[numlvls+1]=(nplv[numlvls]+1)/2;
|
|
||||||
tree->numnodes+=n;
|
|
||||||
++numlvls;
|
|
||||||
} while (n>1);
|
|
||||||
|
|
||||||
tree->nodes=(tgt_node_t*)malloc(tree->numnodes*sizeof(tgt_node_t));
|
|
||||||
|
|
||||||
node=tree->nodes;
|
|
||||||
parentnode=&tree->nodes[tree->numleafsh*tree->numleafsv];
|
|
||||||
parentnode0=parentnode;
|
|
||||||
|
|
||||||
for (i=0; i<numlvls-1; ++i) {
|
|
||||||
for (j=0; j<nplv[i]; ++j) {
|
|
||||||
k=nplh[i];
|
|
||||||
while (--k>=0) {
|
|
||||||
node->parent=parentnode;
|
|
||||||
++node;
|
|
||||||
if (--k >= 0) {
|
|
||||||
node->parent=parentnode;
|
|
||||||
++node;
|
|
||||||
}
|
|
||||||
++parentnode;
|
|
||||||
}
|
|
||||||
if ((j&1)||j==nplv[i]-1) {
|
|
||||||
parentnode0=parentnode;
|
|
||||||
} else {
|
|
||||||
parentnode=parentnode0;
|
|
||||||
parentnode0+=nplh[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node->parent=0;
|
|
||||||
|
|
||||||
tgt_reset(tree);
|
|
||||||
|
|
||||||
return tree;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Destroy tag-tree.
|
|
||||||
/// </summary>
|
|
||||||
void tgt_destroy(tgt_tree_t *t) {
|
|
||||||
free(t->nodes);
|
|
||||||
free(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set the value of a leaf of the tag-tree.
|
|
||||||
/// </summary>
|
|
||||||
void tgt_setvalue(tgt_tree_t *tree, int leafno, int value) {
|
|
||||||
tgt_node_t *node;
|
|
||||||
node=&tree->nodes[leafno];
|
|
||||||
while (node && node->value>value) {
|
|
||||||
node->value=value;
|
|
||||||
node=node->parent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Decode the value of a leaf of the tag-tree.
|
|
||||||
/// </summary>
|
|
||||||
int tgt_decode(tgt_tree_t *tree, int leafno, int threshold)
|
|
||||||
{
|
|
||||||
tgt_node_t *stk[31];
|
|
||||||
tgt_node_t **stkptr;
|
|
||||||
tgt_node_t *node;
|
|
||||||
int low;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
while (low<threshold && low<node->value) {
|
|
||||||
if (bio_read(1)) {
|
|
||||||
node->value=low;
|
|
||||||
} else {
|
|
||||||
++low;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
node->low=low;
|
|
||||||
if (stkptr==stk) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
node=*--stkptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (node->value<threshold)?1:0;
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2001-2002, David Janssens
|
|
||||||
* Copyright (c) 2003, Yannick Verschueren
|
|
||||||
* Copyright (c) 2003, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
|
||||||
* 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 __TGT_H
|
|
||||||
#define __TGT_H
|
|
||||||
|
|
||||||
typedef struct tgt_node {
|
|
||||||
struct tgt_node *parent;
|
|
||||||
int value;
|
|
||||||
int low;
|
|
||||||
int known;
|
|
||||||
} tgt_node_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
int numleafsh;
|
|
||||||
int numleafsv;
|
|
||||||
int numnodes;
|
|
||||||
tgt_node_t *nodes;
|
|
||||||
} tgt_tree_t;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Create a tag-tree
|
|
||||||
* numleafsh: width of the array of leafs of the tree
|
|
||||||
* numleafsv: height of the array of leafs of the tree
|
|
||||||
*/
|
|
||||||
tgt_tree_t *tgt_create(int numleafsh, int numleafsv);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reset a tag-tree (set all leafs to 0)
|
|
||||||
* tree: tag-tree to reset
|
|
||||||
*/
|
|
||||||
void tgt_reset(tgt_tree_t *tree);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Destroy a tag-tree, liberating memory
|
|
||||||
* tree: tag-tree to destroy
|
|
||||||
*/
|
|
||||||
void tgt_destroy(tgt_tree_t *tree);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the value of a leaf of a tag-tree
|
|
||||||
* tree: tag-tree to modify
|
|
||||||
* leafno: number that identifies the leaf to modify
|
|
||||||
* value: new value of the leaf
|
|
||||||
*/
|
|
||||||
void tgt_setvalue(tgt_tree_t *tree, int leafno, int value);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Decode the value of a leaf of the tag-tree up to a given threshold
|
|
||||||
* leafno: number that identifies the leaf to decode
|
|
||||||
* threshold: threshold to use when decoding value of the leaf
|
|
||||||
*/
|
|
||||||
int tgt_decode(tgt_tree_t *tree, int leafno, int threshold);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<project name="seb_j2kviewer" default="dist" basedir=".">
|
|
||||||
<description>Seb's J2K viewer</description>
|
|
||||||
<property name="src" location="src" />
|
|
||||||
<property name="build" location="build"/>
|
|
||||||
<property name="dist" location="dist" />
|
|
||||||
|
|
||||||
<target name="init">
|
|
||||||
<tstamp/>
|
|
||||||
<mkdir dir="${build}"/>
|
|
||||||
</target>
|
|
||||||
<target name="compile" depends="init">
|
|
||||||
<javac srcdir="${src}" destdir="${build}"/>
|
|
||||||
</target>
|
|
||||||
<target name="dist" depends="compile">
|
|
||||||
<mkdir dir="${dist}"/>
|
|
||||||
<jar jarfile="${dist}/seb_j2kviewer-${DSTAMP}.jar"
|
|
||||||
basedir="${build}" manifest="${dist}/manifest.txt"/>
|
|
||||||
<exec dir="${dist}" executable="ln">
|
|
||||||
<arg line="-sf seb_j2kviewer-${DSTAMP}.jar seb_j2kviewer.jar"/>
|
|
||||||
</exec>
|
|
||||||
</target>
|
|
||||||
<target name="clean">
|
|
||||||
<delete dir="${build}"/>
|
|
||||||
<delete dir="${dist}"/>
|
|
||||||
</target>
|
|
||||||
<target name="test" depends="dist">
|
|
||||||
<exec executable="appletviewer"><arg line="dist.html"/></exec>
|
|
||||||
</target>
|
|
||||||
<target name="build_test" depends="compile">
|
|
||||||
<exec executable="appletviewer"><arg line="compile.html"/></exec>
|
|
||||||
</target>
|
|
||||||
<target name="build_testj" depends="compile">
|
|
||||||
<exec executable="java"><arg line="-classpath build ImageViewer girl"/></exec>
|
|
||||||
</target>
|
|
||||||
</project>
|
|
||||||
@@ -1,212 +0,0 @@
|
|||||||
import java.io.*;
|
|
||||||
|
|
||||||
// This appears in Core Web Programming from
|
|
||||||
// Prentice Hall Publishers, and may be freely used
|
|
||||||
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.
|
|
||||||
|
|
||||||
/** A class that eases the pain of running external
|
|
||||||
* processes from applications.
|
|
||||||
* Lets you run a program three ways:
|
|
||||||
* <OL>
|
|
||||||
* <LI><B>exec</B>: Execute the command, returning
|
|
||||||
* immediately even if the command is still
|
|
||||||
* running. This would be appropriate
|
|
||||||
* for printing a file.
|
|
||||||
* <LI><B>execWait</B>: Execute the command, but
|
|
||||||
* don't return until the command finishes.
|
|
||||||
* This would be appropriate for
|
|
||||||
* sequential commands where the first depends
|
|
||||||
* on the second having finished (e.g.
|
|
||||||
* <CODE>javac</CODE> followed by
|
|
||||||
* <CODE>java</CODE>).
|
|
||||||
* <LI><B>execPrint</B>: Execute the command and
|
|
||||||
* print the output. This would be appropriate
|
|
||||||
* for the UNIX command <CODE>ls</CODE>.
|
|
||||||
* </OL>
|
|
||||||
* Note that the PATH is not taken into account,
|
|
||||||
* so you must specify the <B>full</B> pathname to
|
|
||||||
* the command, and shell builtin commands
|
|
||||||
* will not work. For instance, on Unix the above
|
|
||||||
* three examples might look like:
|
|
||||||
* <OL>
|
|
||||||
* <LI><PRE>Exec.exec("/usr/ucb/lpr Some-File");</PRE>
|
|
||||||
* <LI><PRE>
|
|
||||||
* Exec.execWait("/usr/local/bin/javac Foo.java");
|
|
||||||
* Exec.execWait("/usr/local/bin/java Foo");
|
|
||||||
* </PRE>
|
|
||||||
* <LI><PRE>Exec.execPrint("/usr/bin/ls -al");</PRE>
|
|
||||||
* </OL>
|
|
||||||
*
|
|
||||||
* @author Marty Hall
|
|
||||||
* (<A HREF="mailto:hall@apl.jhu.edu">
|
|
||||||
* hall@apl.jhu.edu</A>)
|
|
||||||
* @version 1.0 1997
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Exec {
|
|
||||||
//----------------------------------------------------
|
|
||||||
|
|
||||||
private static boolean verbose = true;
|
|
||||||
|
|
||||||
/** Determines if the Exec class should print which
|
|
||||||
* commands are being executed, and print error
|
|
||||||
* messages if a problem is found. Default is true.
|
|
||||||
*
|
|
||||||
* @param verboseFlag true: print messages.
|
|
||||||
* false: don't.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static void setVerbose(boolean verboseFlag) {
|
|
||||||
verbose = verboseFlag;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Will Exec print status messages? */
|
|
||||||
|
|
||||||
public static boolean getVerbose() {
|
|
||||||
return(verbose);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
/** Starts a process to execute the command. Returns
|
|
||||||
* immediately, even if the new process is still
|
|
||||||
* running.
|
|
||||||
*
|
|
||||||
* @param command The <B>full</B> pathname of the
|
|
||||||
* command to be executed. No shell builtins
|
|
||||||
* (e.g. "cd") or shell meta-chars (e.g. ">")
|
|
||||||
* allowed.
|
|
||||||
* @return false if a problem is known to occur, but
|
|
||||||
* since this returns immediately, problems
|
|
||||||
* aren't usually found in time.
|
|
||||||
* Returns true otherwise.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static boolean exec(String command) {
|
|
||||||
return(exec(command, false, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
/** Starts a process to execute the command. Waits
|
|
||||||
* for the process to finish before returning.
|
|
||||||
*
|
|
||||||
* @param command The <B>full</B> pathname of the
|
|
||||||
* command to be executed. No shell builtins
|
|
||||||
* or shell meta-chars allowed.
|
|
||||||
* @return false if a problem is known to occur,
|
|
||||||
* either due to an exception or from the
|
|
||||||
* subprocess returning a non-zero value.
|
|
||||||
* Returns true otherwise.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static boolean execWait(String command) {
|
|
||||||
return(exec(command, false, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
/** Starts a process to execute the command. Prints
|
|
||||||
* all output the command gives.
|
|
||||||
*
|
|
||||||
* @param command The <B>full</B> pathname of the
|
|
||||||
* command to be executed. No shell builtins
|
|
||||||
* or shell meta-chars allowed.
|
|
||||||
* @return false if a problem is known to occur,
|
|
||||||
* either due to an exception or from the
|
|
||||||
* subprocess returning a non-zero value.
|
|
||||||
* Returns true otherwise.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static boolean execPrint(String command) {
|
|
||||||
return(exec(command, true, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
// This creates a Process object via
|
|
||||||
// Runtime.getRuntime.exec(). Depending on the
|
|
||||||
// flags, it may call waitFor on the process
|
|
||||||
// to avoid continuing until the process terminates,
|
|
||||||
// or open an input stream from the process to read
|
|
||||||
// the results.
|
|
||||||
|
|
||||||
private static boolean exec(String command,
|
|
||||||
boolean printResults,
|
|
||||||
boolean wait) {
|
|
||||||
if (verbose) {
|
|
||||||
printSeparator();
|
|
||||||
System.out.println("Executing '" + command + "'.");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// Start running command, returning immediately.
|
|
||||||
Process p = Runtime.getRuntime().exec(command);
|
|
||||||
|
|
||||||
// Print the output. Since we read until
|
|
||||||
// there is no more input, this causes us
|
|
||||||
// to wait until the process is completed
|
|
||||||
if(printResults) {
|
|
||||||
BufferedInputStream buffer =
|
|
||||||
new BufferedInputStream(p.getInputStream());
|
|
||||||
DataInputStream commandResult =
|
|
||||||
new DataInputStream(buffer);
|
|
||||||
String s = null;
|
|
||||||
try {
|
|
||||||
while ((s = commandResult.readLine()) != null)
|
|
||||||
System.out.println("Output: " + s);
|
|
||||||
commandResult.close();
|
|
||||||
if (p.exitValue() != 0) {
|
|
||||||
if (verbose)
|
|
||||||
printError(command +
|
|
||||||
" -- p.exitValue() != 0");
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
// Ignore read errors; they mean process is done
|
|
||||||
} catch (Exception e) {}
|
|
||||||
|
|
||||||
// If you don't print the results, then you
|
|
||||||
// need to call waitFor to stop until the process
|
|
||||||
// is completed
|
|
||||||
} else if (wait) {
|
|
||||||
try {
|
|
||||||
System.out.println(" ");
|
|
||||||
int returnVal = p.waitFor();
|
|
||||||
if (returnVal != 0) {
|
|
||||||
if (verbose)
|
|
||||||
printError(command);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (verbose)
|
|
||||||
printError(command, e);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (verbose)
|
|
||||||
printError(command, e);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
|
|
||||||
private static void printError(String command,
|
|
||||||
Exception e) {
|
|
||||||
System.out.println("Error doing exec(" +
|
|
||||||
command + "): " + e.getMessage());
|
|
||||||
System.out.println("Did you specify the full " +
|
|
||||||
"pathname?");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printError(String command) {
|
|
||||||
System.out.println("Error executing '" +
|
|
||||||
command + "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
|
|
||||||
private static void printSeparator() {
|
|
||||||
System.out.println
|
|
||||||
("==============================================");
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------
|
|
||||||
}
|
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.awt.geom.*;
|
|
||||||
import java.net.URL;
|
|
||||||
import javax.swing.border.*;
|
|
||||||
import java.util.*;
|
|
||||||
import java.io.*;
|
|
||||||
|
|
||||||
public class ImageViewer extends JApplet
|
|
||||||
{
|
|
||||||
private class zoomLevel {
|
|
||||||
int x1, y1, x2, y2, zf;
|
|
||||||
|
|
||||||
zoomLevel() {}
|
|
||||||
zoomLevel(zoomLevel zl)
|
|
||||||
{
|
|
||||||
x1 = zl.x1;
|
|
||||||
y1 = zl.y1;
|
|
||||||
x2 = zl.x2;
|
|
||||||
y2 = zl.y2;
|
|
||||||
zf = zl.zf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BufferedImage bi;
|
|
||||||
private Graphics2D big;
|
|
||||||
private MML myMML;
|
|
||||||
private int iw, ih;
|
|
||||||
private int selected = 0, imgId;
|
|
||||||
private Image img;
|
|
||||||
private PgmImage pgm = new PgmImage();
|
|
||||||
private String cmdline = new String();
|
|
||||||
private static String hostname;
|
|
||||||
private static boolean isApplet = true;
|
|
||||||
private boolean fullRefresh = false;
|
|
||||||
private Point offset = new Point(0,0);
|
|
||||||
private zoomLevel zl = new zoomLevel();
|
|
||||||
private Rectangle rect = new Rectangle();
|
|
||||||
private Stack zoomStack = new Stack();
|
|
||||||
private static String j2kfilename;
|
|
||||||
|
|
||||||
public int getX() { return offset.x; }
|
|
||||||
public int getY() { return offset.y; }
|
|
||||||
public int getWidth() { return iw; }
|
|
||||||
public int getHeight() { return ih; }
|
|
||||||
|
|
||||||
public void destroy()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zoomIn()
|
|
||||||
{
|
|
||||||
Dimension asz = this.getSize();
|
|
||||||
int maxzf = 3;
|
|
||||||
int coef = 1;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
cmdline =
|
|
||||||
"/bin/sh get.sh " + j2kfilename + " " + iw
|
|
||||||
+ " " + ih + " " + rect.x + " " + rect.y + " "
|
|
||||||
+ rect.width + " " + rect.height;
|
|
||||||
Exec.execPrint(cmdline);
|
|
||||||
|
|
||||||
rect.x = rect.y = rect.width = rect.height = 0;
|
|
||||||
|
|
||||||
img = pgm.open("out.pgm");
|
|
||||||
|
|
||||||
iw = img.getWidth(this);
|
|
||||||
ih = img.getHeight(this);
|
|
||||||
bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
|
|
||||||
big = bi.createGraphics();
|
|
||||||
selected = 0;
|
|
||||||
fullRefresh = true;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zoomOut()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init()
|
|
||||||
{
|
|
||||||
String str;
|
|
||||||
int port;
|
|
||||||
|
|
||||||
imgId = 4;
|
|
||||||
if (isApplet && (((hostname = this.getParameter("hostname")) == null)
|
|
||||||
|| hostname.equals("")))
|
|
||||||
hostname = "localhost";
|
|
||||||
if (!isApplet || ((str = this.getParameter("cmdPort")) == null)) {
|
|
||||||
port = 3000;
|
|
||||||
} else {
|
|
||||||
port = new Integer(str).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setSize(512, 512);
|
|
||||||
Dimension asz = this.getSize();
|
|
||||||
zl.x2 = asz.width;
|
|
||||||
zl.y2 = asz.height;
|
|
||||||
|
|
||||||
cmdline =
|
|
||||||
"/bin/sh get.sh " + j2kfilename + " " + asz.width
|
|
||||||
+ " " + asz.height + " " + zl.x1 + " " + zl.y1 + " "
|
|
||||||
+ zl.x2 + " " + zl.y2;
|
|
||||||
Exec.execPrint(cmdline);
|
|
||||||
img = pgm.open("out.pgm");
|
|
||||||
|
|
||||||
iw = img.getWidth(this);
|
|
||||||
ih = img.getHeight(this);
|
|
||||||
|
|
||||||
setBackground(Color.black);
|
|
||||||
bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
|
|
||||||
big = bi.createGraphics();
|
|
||||||
myMML = new MML(this);
|
|
||||||
addMouseListener(myMML);
|
|
||||||
addMouseMotionListener(myMML);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSelected(int state)
|
|
||||||
{
|
|
||||||
if (state != selected) {
|
|
||||||
selected = state;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInsideRect(int x, int y)
|
|
||||||
{
|
|
||||||
return rect.contains(x - offset.x, y - offset.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRGeom(int x1, int y1, int x2, int y2)
|
|
||||||
{
|
|
||||||
rect.x = Math.min(x1,x2) - offset.x;
|
|
||||||
rect.y = Math.min(y1,y2) - offset.y;
|
|
||||||
rect.width = Math.abs(x2-x1);
|
|
||||||
rect.height = Math.abs(y2-y1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paint(Graphics g)
|
|
||||||
{
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
Dimension asz = this.getSize();
|
|
||||||
|
|
||||||
if (fullRefresh) {
|
|
||||||
g2.clearRect(0, 0, asz.width, asz.height);
|
|
||||||
fullRefresh = false;
|
|
||||||
}
|
|
||||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
|
||||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING,
|
|
||||||
RenderingHints.VALUE_RENDER_QUALITY);
|
|
||||||
big.setColor(Color.black);
|
|
||||||
offset.x = (int) (asz.width - iw) / 2;
|
|
||||||
offset.y = (int) (asz.height - ih) / 2;
|
|
||||||
big.drawImage(img, 0, 0, this);
|
|
||||||
big.setPaint(Color.red);
|
|
||||||
if ((rect.width > 0) && (rect.height > 0))
|
|
||||||
big.draw(rect);
|
|
||||||
if (selected == 1)
|
|
||||||
shadeExt(big, 0, 0, 0, 64);
|
|
||||||
else if (selected == 2) {
|
|
||||||
shadeExt(big, 0, 0, 0, 255);
|
|
||||||
selected = 1;
|
|
||||||
}
|
|
||||||
g2.drawImage(bi, offset.x, offset.y, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shadeRect(Graphics2D g2, int r, int g, int b, int a)
|
|
||||||
{
|
|
||||||
g2.setPaint(new Color(r, g, b, a));
|
|
||||||
g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void shadeExt(Graphics2D g2, int r, int g, int b, int a)
|
|
||||||
{
|
|
||||||
g2.setPaint(new Color(r, g, b, a));
|
|
||||||
g2.fillRect(0, 0, iw, rect.y); /* _N_ */
|
|
||||||
g2.fillRect(rect.x + rect.width + 1, rect.y,
|
|
||||||
iw - rect.x - rect.width - 1, rect.height + 1); /* E */
|
|
||||||
g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */
|
|
||||||
g2.fillRect(0, rect.y + rect.height + 1,
|
|
||||||
iw, ih - rect.y - rect.height - 1); /* _S_ */
|
|
||||||
}
|
|
||||||
|
|
||||||
protected URL getURL(String filename)
|
|
||||||
{
|
|
||||||
URL codeBase = this.getCodeBase();
|
|
||||||
URL url = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
url = new URL(codeBase, filename);
|
|
||||||
} catch (java.net.MalformedURLException e) {
|
|
||||||
System.out.println("Couldn't create image: badly specified URL");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String s[])
|
|
||||||
{
|
|
||||||
if (s.length > 0)
|
|
||||||
j2kfilename = s[0];
|
|
||||||
else
|
|
||||||
j2kfilename = "girl";
|
|
||||||
System.out.println(j2kfilename);
|
|
||||||
isApplet = false;
|
|
||||||
JFrame f = new JFrame("ImageViewer");
|
|
||||||
f.addWindowListener(new WindowAdapter() {
|
|
||||||
public void windowClosing(WindowEvent e) {System.exit(0);}
|
|
||||||
});
|
|
||||||
JApplet applet = new ImageViewer();
|
|
||||||
f.getContentPane().add("Center", applet);
|
|
||||||
applet.init();
|
|
||||||
f.pack();
|
|
||||||
f.setSize(new Dimension(550,550));
|
|
||||||
f.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
class MML implements MouseMotionListener, MouseListener
|
|
||||||
{
|
|
||||||
public void mouseExited(MouseEvent e) {}
|
|
||||||
public void mouseEntered(MouseEvent e) {}
|
|
||||||
public void mouseClicked(MouseEvent e) {}
|
|
||||||
|
|
||||||
private ImageViewer applet;
|
|
||||||
private int x1, y1, x2, y2, zf, btn;
|
|
||||||
private boolean zoomrq;
|
|
||||||
|
|
||||||
public MML(ImageViewer iv)
|
|
||||||
{
|
|
||||||
x1 = y1 = -1;
|
|
||||||
applet = iv;
|
|
||||||
zoomrq = false;
|
|
||||||
zf = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInside(int x, int y)
|
|
||||||
{
|
|
||||||
x -= applet.getX();
|
|
||||||
y -= applet.getY();
|
|
||||||
return (x >= 0) && (x < applet.getWidth())
|
|
||||||
&& (y >= 0) && (y < applet.getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mousePressed(MouseEvent e)
|
|
||||||
{
|
|
||||||
btn = e.getButton();
|
|
||||||
if (applet.isInsideRect(e.getX(), e.getY())) {
|
|
||||||
applet.setSelected(2);
|
|
||||||
applet.repaint();
|
|
||||||
zoomrq = true;
|
|
||||||
} else {
|
|
||||||
applet.setRGeom(0, 0, 0, 0);
|
|
||||||
applet.setSelected(0);
|
|
||||||
applet.repaint();
|
|
||||||
x1 = y1 = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseReleased(MouseEvent e)
|
|
||||||
{
|
|
||||||
if (zoomrq && (e.getButton() == 1)) {
|
|
||||||
applet.zoomIn();
|
|
||||||
zoomrq = false;
|
|
||||||
} else if (e.getButton() == 3) {
|
|
||||||
applet.zoomOut();
|
|
||||||
zoomrq = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseMoved(MouseEvent e)
|
|
||||||
{
|
|
||||||
applet.setSelected(applet.isInsideRect(e.getX(), e.getY()) ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseDragged(MouseEvent e)
|
|
||||||
{
|
|
||||||
String str;
|
|
||||||
|
|
||||||
if (btn == 1) {
|
|
||||||
x2 = e.getX();
|
|
||||||
y2 = e.getY();
|
|
||||||
|
|
||||||
applet.setSelected(0);
|
|
||||||
zoomrq = false;
|
|
||||||
|
|
||||||
if (isInside(x2, y2)) {
|
|
||||||
str = "[IN ]";
|
|
||||||
if (x1 == -1) {
|
|
||||||
x1 = x2;
|
|
||||||
y1 = y2;
|
|
||||||
} else {
|
|
||||||
applet.setRGeom(x1, y1, x2, y2);
|
|
||||||
applet.repaint();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
str = "[OUT]";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
import java.awt.*;
|
|
||||||
import java.awt.image.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.io.*;
|
|
||||||
import java.util.regex.*;
|
|
||||||
|
|
||||||
class PgmImage extends Component
|
|
||||||
{
|
|
||||||
private Socket s;
|
|
||||||
private BufferedReader in;
|
|
||||||
private int x, y;
|
|
||||||
|
|
||||||
PgmImage()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private String read()
|
|
||||||
{
|
|
||||||
try { return in.readLine(); }
|
|
||||||
catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image open(String filename)
|
|
||||||
{
|
|
||||||
String str;
|
|
||||||
Pattern pat;
|
|
||||||
Matcher mat;
|
|
||||||
int bytes, width, height, depth;
|
|
||||||
FileInputStream fis;
|
|
||||||
|
|
||||||
try {
|
|
||||||
in = new BufferedReader(
|
|
||||||
new InputStreamReader(
|
|
||||||
fis = new FileInputStream(
|
|
||||||
new File(filename))));
|
|
||||||
|
|
||||||
pat = Pattern.compile("^P5$");
|
|
||||||
mat = pat.matcher(str = read());
|
|
||||||
mat.matches();
|
|
||||||
pat = Pattern.compile("^(\\d+) (\\d+)$");
|
|
||||||
mat = pat.matcher(str = read());
|
|
||||||
mat.matches();
|
|
||||||
x = new Integer(mat.group(1)).intValue();
|
|
||||||
y = new Integer(mat.group(2)).intValue();
|
|
||||||
width = x;
|
|
||||||
height = y;
|
|
||||||
depth = 1;
|
|
||||||
pat = Pattern.compile("^255$");
|
|
||||||
mat = pat.matcher(str = read());
|
|
||||||
mat.matches();
|
|
||||||
bytes = x*y;
|
|
||||||
char[] buf = new char[bytes];
|
|
||||||
int r, offset = 0;
|
|
||||||
while (bytes > 0) {
|
|
||||||
try { r = in.read(buf, offset, bytes); offset += r; bytes -= r; }
|
|
||||||
catch (IOException e) { e.printStackTrace(); }
|
|
||||||
}
|
|
||||||
int[] buf2 = new int[buf.length];
|
|
||||||
if (depth == 3) {
|
|
||||||
for (int i = 0; i < buf.length/3; ++i)
|
|
||||||
buf2[i] = 0xFF << 24 | buf[3*i] << 16 | buf[3*i+1] << 8 | buf[3*i+2];
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < buf.length; ++i)
|
|
||||||
buf2[i] = 0xFF << 24 | buf[i] << 16 | buf[i] << 8 | buf[i];
|
|
||||||
}
|
|
||||||
fis.close();
|
|
||||||
return createImage(new MemoryImageSource(width, height, buf2, 0, width));
|
|
||||||
} catch (IOException e) { e.printStackTrace(); }
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean bye()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getXOffset()
|
|
||||||
{
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getYOffset()
|
|
||||||
{
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
***/
|
||||||
|
|
||||||
#include "bio.h"
|
#include "bio.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include "cio.h"
|
#include "cio.h"
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
static unsigned char *cio_start; /* pointer to the start of the stream */
|
static unsigned char *cio_start; /* pointer to the start of the stream */
|
||||||
static unsigned char *cio_end; /* pointer to the end of the stream */
|
static unsigned char *cio_end; /* pointer to the end of the stream */
|
||||||
@@ -150,3 +151,29 @@ void cio_skip(int n)
|
|||||||
{
|
{
|
||||||
cio_bp += n;
|
cio_bp += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read n bytes, copy to buffer
|
||||||
|
*
|
||||||
|
* n : number of bytes to transfer
|
||||||
|
*/
|
||||||
|
void cio_read_to_buf(unsigned char* src_buf, int n)/* Glenn adds */
|
||||||
|
{
|
||||||
|
if (cio_bp + n > cio_end)
|
||||||
|
longjmp(j2k_error, 1);
|
||||||
|
memcpy(cio_bp, src_buf, n);
|
||||||
|
cio_bp += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write n bytes, copy from buffer
|
||||||
|
*
|
||||||
|
* n : number of bytes to transfer
|
||||||
|
*/
|
||||||
|
void cio_write_from_buf(unsigned char* dest_buf, int n)/* Glenn adds */
|
||||||
|
{
|
||||||
|
if (cio_bp + n > cio_end)
|
||||||
|
longjmp(j2k_error, 1);
|
||||||
|
memcpy(dest_buf, cio_bp, n);
|
||||||
|
cio_bp += n;
|
||||||
|
}
|
||||||
@@ -94,4 +94,14 @@ unsigned int cio_read(int n);
|
|||||||
*/
|
*/
|
||||||
void cio_skip(int n);
|
void cio_skip(int n);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read n bytes, copy to buffer
|
||||||
|
*/
|
||||||
|
void cio_read_to_buf(unsigned char* src_buf, int n);/* Glenn Pearson adds */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write n bytes, copy from buffer
|
||||||
|
*/
|
||||||
|
void cio_write_from_buf(unsigned char* dest_buf, int n);/* Glenn Pearson adds */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
* Copyright (c) 2001-2002, David Janssens
|
* Copyright (c) 2001-2002, David Janssens
|
||||||
* Copyright (c) 2002-2004, Yannick Verschueren
|
* Copyright (c) 2002-2004, Yannick Verschueren
|
||||||
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
||||||
|
* Copyright (c) 2005, Reiner Wahler
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -26,16 +27,37 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE:
|
||||||
|
* This is a modified version of the openjpeg dwt.c file.
|
||||||
|
* Average speed improvement compared to the original file (measured on
|
||||||
|
* my own machine, a P4 running at 3.0 GHz):
|
||||||
|
* 5x3 wavelets about 2 times faster
|
||||||
|
* 9x7 wavelets about 3 times faster
|
||||||
|
* for both, encoding and decoding.
|
||||||
|
*
|
||||||
|
* The better performance is caused by doing the 1-dimensional DWT
|
||||||
|
* within a temporary buffer where the data can be accessed sequential
|
||||||
|
* for both directions, horizontal and vertical. The 2d vertical DWT was
|
||||||
|
* the major bottleneck in the former version.
|
||||||
|
*
|
||||||
|
* I have also removed the "Add Patrick" part because it is not longer
|
||||||
|
* needed.
|
||||||
|
*
|
||||||
|
* 6/6/2005
|
||||||
|
* -Ive (aka Reiner Wahler)
|
||||||
|
* mail: ive@lilysoft.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "dwt.h"
|
#include "dwt.h"
|
||||||
#include "int.h"
|
#include "int.h"
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
#include "tcd.h"
|
#include "tcd.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
|
||||||
//#include <math.h>
|
|
||||||
|
|
||||||
#define S(i) a[x*(i)*2]
|
#define S(i) a[(i)*2]
|
||||||
#define D(i) a[x*(1+(i)*2)]
|
#define D(i) a[(1+(i)*2)]
|
||||||
#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i)))
|
#define S_(i) ((i)<0?S(0):((i)>=sn?S(sn-1):S(i)))
|
||||||
#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i)))
|
#define D_(i) ((i)<0?D(0):((i)>=dn?D(dn-1):D(i)))
|
||||||
/* new */
|
/* new */
|
||||||
@@ -62,211 +84,230 @@ double dwt_norms_real[4][10] = {
|
|||||||
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Add Patrick */
|
|
||||||
static int *b = NULL;
|
|
||||||
static int lastSizeOfB = 0;
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Cleaning memory. */
|
/* Forward lazy transform (horizontal). */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
|
void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) {
|
||||||
void dwt_clean()
|
int i;
|
||||||
{
|
for (i=0; i<sn; i++) b[i]=a[2*i+cas];
|
||||||
if (b != NULL) {
|
for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)];
|
||||||
free(b);
|
|
||||||
}
|
|
||||||
b = NULL;
|
|
||||||
lastSizeOfB = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* \ Add Patrick */
|
/* <summary> */
|
||||||
|
/* Forward lazy transform (vertical). */
|
||||||
/* <summary> */
|
/* </summary> */
|
||||||
/* Forward lazy transform. */
|
void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
|
||||||
/* </summary> */
|
int i;
|
||||||
void dwt_deinterleave(int *a, int n, int x, int res, int cas)
|
for (i=0; i<sn; i++) b[i*x]=a[2*i+cas];
|
||||||
{
|
for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)];
|
||||||
int dn, sn, i;
|
|
||||||
sn = res;
|
|
||||||
dn = n - res;
|
|
||||||
if (lastSizeOfB != n) {
|
|
||||||
if (b != NULL)
|
|
||||||
free(b);
|
|
||||||
b = (int *) malloc(n * sizeof(int));
|
|
||||||
lastSizeOfB = n;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cas) {
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
b[i] = a[(2 * i + 1) * x];
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
b[sn + i] = a[2 * i * x];
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
b[i] = a[2 * i * x];
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
b[sn + i] = a[(2 * i + 1) * x];
|
|
||||||
}
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
a[i * x] = b[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Inverse lazy transform. */
|
/* Inverse lazy transform (horizontal). */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_interleave(int *a, int n, int x, int res, int cas)
|
void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas) {
|
||||||
{
|
int i;
|
||||||
int dn, sn, i;
|
/* for (i=0; i<sn; i++) b[2*i+cas]=a[i];*/
|
||||||
sn = res;
|
/* for (i=0; i<dn; i++) b[2*i+1-cas]=a[(sn+i)];*/
|
||||||
dn = n - res;
|
int* ai;
|
||||||
|
int* bi;
|
||||||
if (lastSizeOfB != n) {
|
ai=a;
|
||||||
if (b != NULL)
|
bi=b+cas;
|
||||||
free(b);
|
for (i=0; i<sn; i++) {
|
||||||
b = (int *) malloc(n * sizeof(int));
|
*bi = *ai; bi+=2; ai++;
|
||||||
lastSizeOfB = n;
|
}
|
||||||
}
|
ai=a+sn;
|
||||||
|
bi=b+1-cas;
|
||||||
if (cas) {
|
for (i=0; i<dn; i++) {
|
||||||
for (i = 0; i < sn; i++)
|
*bi = *ai; bi+=2; ai++;
|
||||||
b[2 * i + 1] = a[i * x];
|
}
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
b[2 * i] = a[(sn + i) * x];
|
|
||||||
} else {
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
b[2 * i] = a[i * x];
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
b[2 * i + 1] = a[(sn + i) * x];
|
|
||||||
}
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
a[i * x] = b[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* <summary> */
|
||||||
|
/* Inverse lazy transform (vertical). */
|
||||||
|
/* </summary> */
|
||||||
|
void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
|
||||||
|
int i;
|
||||||
|
/* for (i=0; i<sn; i++) b[2*i+cas]=a[i*x];*/
|
||||||
|
/* for (i=0; i<dn; i++) b[2*i+1-cas]=a[(sn+i)*x];*/
|
||||||
|
int* ai;
|
||||||
|
int* bi;
|
||||||
|
ai=a;
|
||||||
|
bi=b+cas;
|
||||||
|
for (i=0; i<sn; i++) {
|
||||||
|
*bi = *ai; bi+=2; ai+=x;
|
||||||
|
}
|
||||||
|
ai=a+(sn*x);
|
||||||
|
bi=b+1-cas;
|
||||||
|
for (i=0; i<dn; i++) {
|
||||||
|
*bi = *ai; bi+=2; ai+=x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Forward 5-3 wavelet tranform in 1-D. */
|
/* Forward 5-3 wavelet tranform in 1-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_encode_1(int *a, int n, int x, int res, int cas)
|
void dwt_encode_1(int *a, int dn, int sn, int cas)
|
||||||
{
|
{
|
||||||
int dn, sn, i = 0;
|
int i;
|
||||||
sn = res;
|
|
||||||
dn = n - res;
|
|
||||||
|
|
||||||
if (cas) {
|
if (!cas) {
|
||||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
S(i) *= 2;
|
for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1;
|
||||||
else {
|
for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||||
for (i = 0; i < dn; i++)
|
S(0) *= 2;
|
||||||
D(i) -= (S_(i) + S_(i + 1)) >> 1;
|
else {
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
|
||||||
S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
|
for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
dwt_deinterleave(a, n, x, res, cas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Inverse 5-3 wavelet tranform in 1-D. */
|
/* Inverse 5-3 wavelet tranform in 1-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_decode_1(int *a, int n, int x, int res, int cas)
|
void dwt_decode_1(int *a, int dn, int sn, int cas)
|
||||||
{
|
{
|
||||||
int dn, sn, i = 0;
|
int i;
|
||||||
sn = res;
|
|
||||||
dn = n - res;
|
|
||||||
|
|
||||||
dwt_interleave(a, n, x, res, cas);
|
if (!cas) {
|
||||||
if (cas) {
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
for (i = 0; i < sn; i++) S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
|
||||||
S(i) /= 2;
|
for (i = 0; i < dn; i++) D(i) += (S_(i) + S_(i + 1)) >> 1;
|
||||||
else {
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) += (DD_(i) + DD_(i - 1)) >> 1;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
if (!sn && dn == 1) /* NEW : CASE ONE ELEMENT */
|
||||||
for (i = 0; i < sn; i++)
|
S(0) /= 2;
|
||||||
S(i) -= (D_(i - 1) + D_(i) + 2) >> 2;
|
else {
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < sn; i++) D(i) -= (SS_(i) + SS_(i + 1) + 2) >> 2;
|
||||||
D(i) += (S_(i) + S_(i + 1)) >> 1;
|
for (i = 0; i < dn; i++) S(i) += (DD_(i) + DD_(i - 1)) >> 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Forward 5-3 wavelet tranform in 2-D. */
|
/* Forward 5-3 wavelet tranform in 2-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
void dwt_encode(tcd_tilecomp_t * tilec)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j, k;
|
||||||
int rw; /* width of the resolution level computed */
|
int* a;
|
||||||
int rh; /* heigth of the resolution level computed */
|
int* aj;
|
||||||
int rw1; /* width of the resolution level once lower than computed one */
|
int* bj;
|
||||||
int rh1; /* height of the resolution level once lower than computed one */
|
int w, l;
|
||||||
|
|
||||||
|
w = tilec->x1-tilec->x0;
|
||||||
|
l = tilec->numresolutions-1;
|
||||||
|
a = tilec->data;
|
||||||
|
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
int rw; /* width of the resolution level computed */
|
||||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
int rh; /* heigth of the resolution level computed */
|
||||||
|
int rw1; /* width of the resolution level once lower than computed one */
|
||||||
|
int rh1; /* height of the resolution level once lower than computed one */
|
||||||
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int dn, sn;
|
||||||
|
|
||||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||||
rw1 =
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||||
rh1 =
|
|
||||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
|
||||||
|
|
||||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||||
|
|
||||||
for (j = 0; j < rw; j++)
|
|
||||||
dwt_encode_1(a + j, rh, w, rh1, cas_col);
|
|
||||||
for (j = 0; j < rh; j++)
|
|
||||||
dwt_encode_1(a + j * w, rw, 1, rw1, cas_row);
|
|
||||||
}
|
|
||||||
|
|
||||||
dwt_clean();
|
sn = rh1;
|
||||||
|
dn = rh - rh1;
|
||||||
|
bj=(int*)malloc(rh*sizeof(int));
|
||||||
|
for (j=0; j<rw; j++) {
|
||||||
|
aj=a+j;
|
||||||
|
for (k=0; k<rh; k++) bj[k]=aj[k*w];
|
||||||
|
dwt_encode_1(bj, dn, sn, cas_col);
|
||||||
|
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
|
||||||
|
sn = rw1;
|
||||||
|
dn = rw - rw1;
|
||||||
|
bj=(int*)malloc(rw*sizeof(int));
|
||||||
|
for (j=0; j<rh; j++) {
|
||||||
|
aj=a+j*w;
|
||||||
|
for (k=0; k<rw; k++) bj[k]=aj[k];
|
||||||
|
dwt_encode_1(bj, dn, sn, cas_row);
|
||||||
|
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Inverse 5-3 wavelet tranform in 2-D. */
|
/* Inverse 5-3 wavelet tranform in 2-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
void dwt_decode(tcd_tilecomp_t * tilec, int stop)
|
||||||
int stop)
|
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j, k;
|
||||||
int rw; /* width of the resolution level computed */
|
int* a;
|
||||||
int rh; /* heigth of the resolution level computed */
|
int* aj;
|
||||||
int rw1; /* width of the resolution level once lower than computed one */
|
int* bj;
|
||||||
int rh1; /* height of the resolution level once lower than computed one */
|
int w, l;
|
||||||
|
|
||||||
|
w = tilec->x1-tilec->x0;
|
||||||
|
l = tilec->numresolutions-1;
|
||||||
|
a = tilec->data;
|
||||||
|
|
||||||
for (i = l - 1; i >= stop; i--) {
|
for (i = l - 1; i >= stop; i--) {
|
||||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
int rw; /* width of the resolution level computed */
|
||||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
int rh; /* heigth of the resolution level computed */
|
||||||
|
int rw1; /* width of the resolution level once lower than computed one */
|
||||||
|
int rh1; /* height of the resolution level once lower than computed one */
|
||||||
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int dn, sn;
|
||||||
|
|
||||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||||
rw1 =
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||||
rh1 =
|
|
||||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
|
||||||
|
|
||||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||||
|
|
||||||
for (j = 0; j < rh; j++)
|
sn = rw1;
|
||||||
dwt_decode_1(a + j * w, rw, 1, rw1, cas_row);
|
dn = rw - rw1;
|
||||||
for (j = 0; j < rw; j++)
|
bj=(int*)malloc(rw*sizeof(int));
|
||||||
dwt_decode_1(a + j, rh, w, rh1, cas_col);
|
for (j = 0; j < rh; j++) {
|
||||||
|
aj = a+j*w;
|
||||||
|
dwt_interleave_h(aj, bj, dn, sn, cas_row);
|
||||||
|
dwt_decode_1(bj, dn, sn, cas_row);
|
||||||
|
for (k = 0; k < rw; k++) aj[k] = bj[k];
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
|
||||||
|
sn = rh1;
|
||||||
|
dn = rh - rh1;
|
||||||
|
bj=(int*)malloc(rh*sizeof(int));
|
||||||
|
for (j = 0; j < rw; j++) {
|
||||||
|
aj = a+j;
|
||||||
|
dwt_interleave_v(aj, bj, dn, sn, w, cas_col);
|
||||||
|
dwt_decode_1(bj, dn, sn, cas_col);
|
||||||
|
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
|
||||||
}
|
}
|
||||||
dwt_clean();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Get gain of 5-3 wavelet transform. */
|
/* Get gain of 5-3 wavelet transform. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
@@ -290,84 +331,77 @@ double dwt_getnorm(int level, int orient)
|
|||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Forward 9-7 wavelet transform in 1-D. */
|
/* Forward 9-7 wavelet transform in 1-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_encode_1_real(int *a, int n, int x, int res, int cas)
|
void dwt_encode_1_real(int *a, int dn, int sn, int cas)
|
||||||
{
|
{
|
||||||
int dn, sn, i = 0;
|
int i;
|
||||||
dn = n - res;
|
if (!cas) {
|
||||||
sn = res;
|
|
||||||
|
|
||||||
if (cas) {
|
|
||||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) = fix_mul(S(i), 5038); /*5038 */
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) = fix_mul(D(i), 6659); /*6660 */
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
|
D(i) -= fix_mul(S_(i) + S_(i + 1), 12993);
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
|
S(i) -= fix_mul(D_(i - 1) + D_(i), 434);
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
|
D(i) += fix_mul(S_(i) + S_(i + 1), 7233);
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
|
S(i) += fix_mul(D_(i - 1) + D_(i), 3633);
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) = fix_mul(D(i), 5038); /*5038 */
|
D(i) = fix_mul(D(i), 5038); /*5038 */
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) = fix_mul(S(i), 6659); /*6660 */
|
S(i) = fix_mul(S(i), 6659); /*6660 */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 12993);
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) += fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) += fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) = fix_mul(S(i), 5038); /*5038 */
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) = fix_mul(D(i), 6659); /*6660 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dwt_deinterleave(a, n, x, res, cas);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Inverse 9-7 wavelet transform in 1-D. */
|
/* Inverse 9-7 wavelet transform in 1-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
|
void dwt_decode_1_real(int *a, int dn, int sn, int cas)
|
||||||
{
|
{
|
||||||
int dn, sn, i = 0;
|
int i;
|
||||||
dn = n - res;
|
if (!cas) {
|
||||||
sn = res;
|
|
||||||
dwt_interleave(a, n, x, res, cas);
|
|
||||||
if (cas) {
|
|
||||||
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) = fix_mul(D(i), 10078); /* 10076 */
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) = fix_mul(S(i), 13318); /* 13320 */
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
|
|
||||||
for (i = 0; i < sn; i++)
|
|
||||||
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
|
|
||||||
for (i = 0; i < dn; i++)
|
|
||||||
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12993);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) = fix_mul(S(i), 10078); /* 10076 */
|
S(i) = fix_mul(S(i), 10078); /* 10076 */
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) = fix_mul(D(i), 13318); /* 13320 */
|
D(i) = fix_mul(D(i), 13318); /* 13320 */
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
|
S(i) -= fix_mul(D_(i - 1) + D_(i), 3633);
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
|
D(i) -= fix_mul(S_(i) + S_(i + 1), 7233);
|
||||||
for (i = 0; i < sn; i++)
|
for (i = 0; i < sn; i++)
|
||||||
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
|
S(i) += fix_mul(D_(i - 1) + D_(i), 434);
|
||||||
for (i = 0; i < dn; i++)
|
for (i = 0; i < dn; i++)
|
||||||
D(i) += fix_mul(S_(i) + S_(i + 1), 12993);
|
D(i) += fix_mul(S_(i) + S_(i + 1), 12994); /* 12993 */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ((sn > 0) || (dn > 1)) { /* NEW : CASE ONE ELEMENT */
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) = fix_mul(D(i), 10078); /* 10076 */
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) = fix_mul(S(i), 13318); /* 13320 */
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) -= fix_mul(SS_(i) + SS_(i + 1), 3633);
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) -= fix_mul(DD_(i) + DD_(i - 1), 7233);
|
||||||
|
for (i = 0; i < sn; i++)
|
||||||
|
D(i) += fix_mul(SS_(i) + SS_(i + 1), 434);
|
||||||
|
for (i = 0; i < dn; i++)
|
||||||
|
S(i) += fix_mul(DD_(i) + DD_(i - 1), 12994); /* 12993 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,72 +410,124 @@ void dwt_decode_1_real(int *a, int n, int x, int res, int cas)
|
|||||||
/* Forward 9-7 wavelet transform in 2-D. */
|
/* Forward 9-7 wavelet transform in 2-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
|
|
||||||
void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l)
|
void dwt_encode_real(tcd_tilecomp_t * tilec)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j, k;
|
||||||
int rw; /* width of the resolution level computed */
|
int* a;
|
||||||
int rh; /* heigth of the resolution level computed */
|
int* aj;
|
||||||
int rw1; /* width of the resolution level once lower than computed one */
|
int* bj;
|
||||||
int rh1; /* height of the resolution level once lower than computed one */
|
int w, l;
|
||||||
|
|
||||||
|
w = tilec->x1-tilec->x0;
|
||||||
|
l = tilec->numresolutions-1;
|
||||||
|
a = tilec->data;
|
||||||
|
|
||||||
for (i = 0; i < l; i++) {
|
for (i = 0; i < l; i++) {
|
||||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
int rw; /* width of the resolution level computed */
|
||||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
int rh; /* heigth of the resolution level computed */
|
||||||
|
int rw1; /* width of the resolution level once lower than computed one */
|
||||||
|
int rh1; /* height of the resolution level once lower than computed one */
|
||||||
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int dn, sn;
|
||||||
|
|
||||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||||
rw1 =
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||||
rh1 =
|
|
||||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
|
||||||
|
|
||||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
cas_row = tilec->resolutions[l - i].x0 % 2;
|
||||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
cas_col = tilec->resolutions[l - i].y0 % 2;
|
||||||
|
|
||||||
for (j = 0; j < rw; j++)
|
sn = rh1;
|
||||||
dwt_encode_1_real(a + j, rh, w, rh1, cas_col);
|
dn = rh - rh1;
|
||||||
for (j = 0; j < rh; j++)
|
bj=(int*)malloc(rh*sizeof(int));
|
||||||
dwt_encode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
for (j = 0; j < rw; j++) {
|
||||||
|
aj = a + j;
|
||||||
|
for (k = 0; k < rh; k++) bj[k] = aj[k*w];
|
||||||
|
dwt_encode_1_real(bj, dn, sn, cas_col);
|
||||||
|
dwt_deinterleave_v(bj, aj, dn, sn, w, cas_col);
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
|
||||||
|
sn = rw1;
|
||||||
|
dn = rw - rw1;
|
||||||
|
bj=(int*)malloc(rw*sizeof(int));
|
||||||
|
for (j = 0; j < rh; j++) {
|
||||||
|
aj = a + j * w;
|
||||||
|
for (k = 0; k < rw; k++) bj[k] = aj[k];
|
||||||
|
dwt_encode_1_real(bj, dn, sn, cas_row);
|
||||||
|
dwt_deinterleave_h(bj, aj, dn, sn, cas_row);
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Inverse 9-7 wavelet transform in 2-D. */
|
/* Inverse 9-7 wavelet transform in 2-D. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
void dwt_decode_real(tcd_tilecomp_t * tilec, int stop)
|
||||||
int stop)
|
|
||||||
{
|
{
|
||||||
int i, j;
|
|
||||||
int rw; /* width of the resolution level computed */
|
|
||||||
int rh; /* heigth of the resolution level computed */
|
|
||||||
int rw1; /* width of the resolution level once lower than computed one */
|
|
||||||
int rh1; /* height of the resolution level once lower than computed one */
|
|
||||||
|
|
||||||
for (i = l - 1; i >= stop; i--) {
|
int i, j, k;
|
||||||
int cas_col = 0; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
int* a;
|
||||||
int cas_row = 0; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
int* aj;
|
||||||
|
int* bj;
|
||||||
|
int w, l;
|
||||||
|
|
||||||
|
w = tilec->x1-tilec->x0;
|
||||||
|
l = tilec->numresolutions-1;
|
||||||
|
a = tilec->data;
|
||||||
|
|
||||||
|
for (i = l-1; i >= stop; i--) {
|
||||||
|
int rw; /* width of the resolution level computed */
|
||||||
|
int rh; /* heigth of the resolution level computed */
|
||||||
|
int rw1; /* width of the resolution level once lower than computed one */
|
||||||
|
int rh1; /* height of the resolution level once lower than computed one */
|
||||||
|
int cas_col; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int cas_row; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
int dn, sn;
|
||||||
|
|
||||||
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
rw = tilec->resolutions[l - i].x1 - tilec->resolutions[l - i].x0;
|
||||||
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
rh = tilec->resolutions[l - i].y1 - tilec->resolutions[l - i].y0;
|
||||||
rw1 =
|
rw1= tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
||||||
tilec->resolutions[l - i - 1].x1 - tilec->resolutions[l - i - 1].x0;
|
rh1= tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
||||||
rh1 =
|
|
||||||
tilec->resolutions[l - i - 1].y1 - tilec->resolutions[l - i - 1].y0;
|
|
||||||
|
|
||||||
cas_row = tilec->resolutions[l - i].x0 % 2;
|
cas_col = tilec->resolutions[l - i].x0 % 2; /* 0 = non inversion on horizontal filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
cas_col = tilec->resolutions[l - i].y0 % 2;
|
cas_row = tilec->resolutions[l - i].y0 % 2; /* 0 = non inversion on vertical filtering 1 = inversion between low-pass and high-pass filtering */
|
||||||
|
|
||||||
for (j = 0; j < rh; j++)
|
sn = rw1;
|
||||||
dwt_decode_1_real(a + j * w, rw, 1, rw1, cas_row);
|
dn = rw-rw1;
|
||||||
for (j = 0; j < rw; j++)
|
bj = (int*)malloc(rw * sizeof(int));
|
||||||
dwt_decode_1_real(a + j, rh, w, rh1, cas_col);
|
for (j = 0; j < rh; j++) {
|
||||||
|
aj = a+j*w;
|
||||||
|
dwt_interleave_h(aj, bj, dn, sn, cas_col);
|
||||||
|
dwt_decode_1_real(bj, dn, sn, cas_col);
|
||||||
|
for (k = 0; k < rw; k++) aj[k] = bj[k];
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
|
|
||||||
|
sn = rh1;
|
||||||
|
dn = rh-rh1;
|
||||||
|
bj = (int*)malloc(rh * sizeof(int));
|
||||||
|
for (j=0; j<rw; j++) {
|
||||||
|
aj = a+j;
|
||||||
|
dwt_interleave_v(aj, bj, dn, sn, w, cas_row);
|
||||||
|
dwt_decode_1_real(bj, dn, sn, cas_row);
|
||||||
|
for (k = 0; k < rh; k++) aj[k * w] = bj[k];
|
||||||
|
}
|
||||||
|
free(bj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* <summary> */
|
/* <summary> */
|
||||||
/* Get gain of 9-7 wavelet transform. */
|
/* Get gain of 9-7 wavelet transform. */
|
||||||
/* </summary> */
|
/* </summary> */
|
||||||
int dwt_getgain_real(int orient)
|
int dwt_getgain_real(int orient)
|
||||||
{
|
{
|
||||||
|
(void)orient;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,26 +33,15 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply a reversible DWT transform to a component of an image
|
* Apply a reversible DWT transform to a component of an image
|
||||||
* a: samples of the component
|
|
||||||
* w: width of the component
|
|
||||||
* h: height of the component
|
|
||||||
* tilec : tile component information (present tile)
|
* tilec : tile component information (present tile)
|
||||||
* l: number of decomposition levels in the DWT
|
|
||||||
*/
|
*/
|
||||||
/* void dwt_encode(int* a, int w, int h, int l); */
|
/* void dwt_encode(int* a, int w, int h, int l); */
|
||||||
void dwt_encode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
|
void dwt_encode(tcd_tilecomp_t * tilec);
|
||||||
/*
|
/*
|
||||||
* Apply a reversible inverse DWT transform to a component of an image
|
* Apply a reversible inverse DWT transform to a component of an image
|
||||||
* a: samples of the component
|
|
||||||
* w: width of the component
|
|
||||||
* h: height of the component
|
|
||||||
* tilec : tile component information (present tile)
|
* tilec : tile component information (present tile)
|
||||||
* l: number of decomposition levels in the DWT
|
|
||||||
* row_tilec : tile component information (previous tile on the same row)
|
|
||||||
* col_tilec : tile component information (previous tile on the same column)
|
|
||||||
*/
|
*/
|
||||||
void dwt_decode(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
void dwt_decode(tcd_tilecomp_t * tilec, int stop);
|
||||||
int stop);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the gain of a subband for the reversible DWT
|
* Get the gain of a subband for the reversible DWT
|
||||||
@@ -69,22 +58,13 @@ double dwt_getnorm(int level, int orient);
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply an irreversible DWT transform to a component of an image
|
* Apply an irreversible DWT transform to a component of an image
|
||||||
* a: samples of the component
|
|
||||||
* w: width of the component
|
|
||||||
* h: height of the component
|
|
||||||
* l: number of decomposition levels in the DWT
|
|
||||||
*/
|
*/
|
||||||
void dwt_encode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l);
|
void dwt_encode_real(tcd_tilecomp_t * tilec);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Apply an irreversible inverse DWT transform to a component of an image
|
* Apply an irreversible inverse DWT transform to a component of an image
|
||||||
* a: samples of the component
|
|
||||||
* w: width of the component
|
|
||||||
* h: height of the component
|
|
||||||
* l: number of decomposition levels in the DWT
|
|
||||||
*/
|
*/
|
||||||
void dwt_decode_real(int *a, int w, int h, tcd_tilecomp_t * tilec, int l,
|
void dwt_decode_real(tcd_tilecomp_t * tilec, int stop);
|
||||||
int stop);
|
|
||||||
/*
|
/*
|
||||||
* Get the gain of a subband for the irreversible DWT
|
* Get the gain of a subband for the irreversible DWT
|
||||||
* orient: number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
|
* orient: number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
#include <math.h> //Add Antonin : multbug1
|
#include <math.h> /*Add Antonin : multbug1*/
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define int64 __int64
|
#define int64 __int64
|
||||||
@@ -37,12 +37,14 @@
|
|||||||
* Multiply two fixed-precision rational numbers.
|
* Multiply two fixed-precision rational numbers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//int fix_mul(int a, int b)
|
/*int fix_mul(int a, int b)
|
||||||
//{
|
{
|
||||||
// return (int) ((int64) a * (int64) b >> 13);
|
return (int) ((int64) a * (int64) b >> 13);
|
||||||
//}
|
}*/
|
||||||
|
|
||||||
//Mod Antonin : multbug1
|
|
||||||
|
/*Mod Antonin : multbug1*/
|
||||||
|
/*
|
||||||
int fix_mul(int a, int b)
|
int fix_mul(int a, int b)
|
||||||
{
|
{
|
||||||
double tmp= (double) ((int64) a * (int64) b);
|
double tmp= (double) ((int64) a * (int64) b);
|
||||||
@@ -50,5 +52,12 @@ int fix_mul(int a, int b)
|
|||||||
v = (tmp<0)?-v:v;
|
v = (tmp<0)?-v:v;
|
||||||
return (int) v;
|
return (int) v;
|
||||||
}
|
}
|
||||||
//doM
|
*/
|
||||||
|
/*doM*/
|
||||||
|
|
||||||
|
int fix_mul(int a, int b) /* Luke Lee optimized : 11/16/2004*/
|
||||||
|
{
|
||||||
|
int64 temp = (int64) a * (int64) b >> 12;
|
||||||
|
return (int) ((temp >> 1) + (temp & 1)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "int.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the minimum of two integers.
|
* Get the minimum of two integers.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "j2k.h"
|
||||||
|
|
||||||
#ifndef __INT_H
|
#ifndef __INT_H
|
||||||
#define __INT_H
|
#define __INT_H
|
||||||
|
|
||||||
@@ -67,14 +69,14 @@ int int_ceildiv(int a, int b);
|
|||||||
*
|
*
|
||||||
* a divided by 2^b
|
* a divided by 2^b
|
||||||
*/
|
*/
|
||||||
int int_ceildivpow2(int a, int b);
|
LIBJ2K_API int int_ceildivpow2(int a, int b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Divide an integer by a power of 2 and round downwards.
|
* Divide an integer by a power of 2 and round downwards.
|
||||||
*
|
*
|
||||||
* a divided by 2^b
|
* a divided by 2^b
|
||||||
*/
|
*/
|
||||||
int int_floordivpow2(int a, int b);
|
LIBJ2K_API int int_floordivpow2(int a, int b);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get logarithm of an integer and round downwards.
|
* Get logarithm of an integer and round downwards.
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -28,21 +28,34 @@
|
|||||||
|
|
||||||
#define VERSION "0.0.8"
|
#define VERSION "0.0.8"
|
||||||
|
|
||||||
#ifdef DAVID_WIN32
|
#if defined(_WIN32) && defined (OPENJPEGDLL)
|
||||||
#ifdef LIBJ2K_EXPORTS
|
#ifdef gdcmopenjpeg_EXPORTS /*LIBJ2K_EXPORTS*/
|
||||||
#define LIBJ2K_API __declspec(dllexport)
|
#define LIBJ2K_API __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define LIBJ2K_API __declspec(dllimport)
|
#define LIBJ2K_API __declspec(dllimport)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#ifdef OPENJPEGSTATIC
|
||||||
|
#define LIBJ2K_API extern
|
||||||
|
#else
|
||||||
#define LIBJ2K_API
|
#define LIBJ2K_API
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef __J2K_H
|
#ifndef __J2K_H
|
||||||
#define __J2K_H
|
#define __J2K_H
|
||||||
|
|
||||||
#define J2K_MAXRLVLS 33 /* Number of maximum resolution level authorized */
|
#define J2K_MAXRLVLS 33 /* Number of maximum resolution level authorized */
|
||||||
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /* Number of maximum sub-band linked to number of resolution level */
|
#define J2K_MAXBANDS (3*J2K_MAXRLVLS-2) /* Number of maximum sub-band linked to number of resolution level */
|
||||||
|
#define J2K_CFMT 0
|
||||||
|
#define JP2_CFMT 1
|
||||||
|
#define JPT_CFMT 2
|
||||||
|
#define MJ2_CFMT 3
|
||||||
|
#define PXM_DFMT 0
|
||||||
|
#define PGX_DFMT 1
|
||||||
|
#define BMP_DFMT 2
|
||||||
|
#define YUV_DFMT 3
|
||||||
|
|
||||||
#define J2K_CP_CSTY_PRT 0x01
|
#define J2K_CP_CSTY_PRT 0x01
|
||||||
#define J2K_CP_CSTY_SOP 0x02
|
#define J2K_CP_CSTY_SOP 0x02
|
||||||
@@ -117,6 +130,7 @@ typedef struct {
|
|||||||
int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
|
int POC; /* Precise if a POC marker has been used O:NO, 1:YES */
|
||||||
j2k_poc_t pocs[32]; /* progression order changes */
|
j2k_poc_t pocs[32]; /* progression order changes */
|
||||||
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
unsigned char *ppt_data; /* packet header store there for futur use in t2_decode_packet */
|
||||||
|
unsigned char *ppt_data_first; /* pointer remaining on the first byte of the first header if ppt is used */
|
||||||
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
int ppt; /* If ppt == 1 --> there was a PPT marker for the present tile */
|
||||||
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
int ppt_store; /* Use in case of multiple marker PPT (number of info already store) */
|
||||||
int ppt_len; /* ppmbug1 */
|
int ppt_len; /* ppmbug1 */
|
||||||
@@ -125,14 +139,14 @@ typedef struct {
|
|||||||
} j2k_tcp_t;
|
} j2k_tcp_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int JPEG2000_format; /* 0: J2K 1:JP2 */
|
|
||||||
int intermed_file; /* 1: Store each encoded tile one by one in the output file (for mega-Images)*/
|
int intermed_file; /* 1: Store each encoded tile one by one in the output file (for mega-Images)*/
|
||||||
int image_type; /* 0: PNM, PGM, PPM 1: PGX */
|
int decod_format; /* 0: PGX, 1: PxM, 2: BMP */
|
||||||
|
int cod_format; /* 0: J2K, 1: JP2, 2: JPT */
|
||||||
int disto_alloc; /* Allocation by rate/distortion */
|
int disto_alloc; /* Allocation by rate/distortion */
|
||||||
int fixed_alloc; /* Allocation by fixed layer */
|
int fixed_alloc; /* Allocation by fixed layer */
|
||||||
int fixed_quality; /* add fixed_quality */
|
int fixed_quality; /* add fixed_quality */
|
||||||
int reduce_on; /* option reduce is used if reduce = 1 */
|
int reduce; /* if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
|
||||||
int reduce_value; /* if option reduce is used -> original dimension divided by 2^value */
|
int layer; /* if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
|
||||||
int index_on; /* 0 = no index || 1 = index */
|
int index_on; /* 0 = no index || 1 = index */
|
||||||
int tx0, ty0; /* XTOsiz, YTOsiz */
|
int tx0, ty0; /* XTOsiz, YTOsiz */
|
||||||
int tdx, tdy; /* XTsiz, YTsiz */
|
int tdx, tdy; /* XTsiz, YTsiz */
|
||||||
@@ -141,6 +155,7 @@ typedef struct {
|
|||||||
int *tileno; /* ID number of the tiles present in the codestream */
|
int *tileno; /* ID number of the tiles present in the codestream */
|
||||||
int tileno_size; /* size of the vector tileno */
|
int tileno_size; /* size of the vector tileno */
|
||||||
unsigned char *ppm_data; /* packet header store there for futur use in t2_decode_packet */
|
unsigned char *ppm_data; /* packet header store there for futur use in t2_decode_packet */
|
||||||
|
unsigned char *ppm_data_first; /* pointer remaining on the first byte of the first header if ppm is used */
|
||||||
int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
|
int ppm; /* If ppm == 1 --> there was a PPM marker for the present tile */
|
||||||
int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
|
int ppm_store; /* Use in case of multiple marker PPM (number of info already store) */
|
||||||
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
int ppm_previous; /* Use in case of multiple marker PPM (case on non-finished previous info) */
|
||||||
@@ -176,6 +191,7 @@ typedef struct {
|
|||||||
int Im_w, Im_h; /* Image width and Height */
|
int Im_w, Im_h; /* Image width and Height */
|
||||||
int Prog; /* progression order */
|
int Prog; /* progression order */
|
||||||
int Tile_x, Tile_y; /* Tile size in x and y */
|
int Tile_x, Tile_y; /* Tile size in x and y */
|
||||||
|
int Tile_Ox, Tile_Oy;
|
||||||
int tw, th; /* Number of Tile in X and Y */
|
int tw, th; /* Number of Tile in X and Y */
|
||||||
int Comp; /* Component numbers */
|
int Comp; /* Component numbers */
|
||||||
int Layer; /* number of layer */
|
int Layer; /* number of layer */
|
||||||
@@ -220,4 +236,6 @@ LIBJ2K_API int j2k_decode(unsigned char *src, int len, j2k_image_t * img,
|
|||||||
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
int j2k_decode_jpt_stream(unsigned char *src, int len, j2k_image_t * img,
|
||||||
j2k_cp_t * cp);
|
j2k_cp_t * cp);
|
||||||
|
|
||||||
|
LIBJ2K_API void j2k_dec_release();/*antonin*/
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,8 +32,6 @@
|
|||||||
#include "j2k.h"
|
#include "j2k.h"
|
||||||
#include "jp2.h"
|
#include "jp2.h"
|
||||||
#include "cio.h"
|
#include "cio.h"
|
||||||
#include "tcd.h"
|
|
||||||
#include "int.h"
|
|
||||||
|
|
||||||
#define JPIP_JPIP 0x6a706970
|
#define JPIP_JPIP 0x6a706970
|
||||||
|
|
||||||
@@ -63,8 +61,12 @@ int jp2_read_boxhdr(jp2_box_t * box)
|
|||||||
if (cio_read(4) != 0) {
|
if (cio_read(4) != 0) {
|
||||||
fprintf(stderr, "Error: Cannot handle box sizes higher than 2^32\n");
|
fprintf(stderr, "Error: Cannot handle box sizes higher than 2^32\n");
|
||||||
return 1;
|
return 1;
|
||||||
};
|
}
|
||||||
box->length = cio_read(4);
|
box->length = cio_read(4);
|
||||||
|
if (box->length == 0)
|
||||||
|
box->length = cio_numbytesleft() + 12;
|
||||||
|
} else if (box->length == 0) {
|
||||||
|
box->length = cio_numbytesleft() + 8;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -74,61 +76,25 @@ int jp2_read_boxhdr(jp2_box_t * box)
|
|||||||
* Initialisation of a Standard JP2 structure
|
* Initialisation of a Standard JP2 structure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int jp2_init_stdjp2(jp2_struct_t * jp2_struct, j2k_image_t * img)
|
int jp2_init_stdjp2(jp2_struct_t * jp2_struct)
|
||||||
{
|
{
|
||||||
int depth_0, sign, depth, i;
|
|
||||||
|
|
||||||
|
jp2_struct->comps =
|
||||||
|
(jp2_comps_t *) malloc(jp2_struct->numcomps * sizeof(jp2_comps_t));
|
||||||
|
|
||||||
jp2_struct->h = img->y1 - img->y0; // HEIGHT
|
jp2_struct->precedence = 0; /* PRECEDENCE*/
|
||||||
jp2_struct->w = img->x1 - img->x0; // WIDTH
|
jp2_struct->approx = 0; /* APPROX*/
|
||||||
jp2_struct->numcomps = img->numcomps; // NC
|
|
||||||
jp2_struct->comps = (jp2_comps_t *) malloc(jp2_struct->numcomps * sizeof(jp2_comps_t));
|
|
||||||
|
|
||||||
depth_0 = img->comps[0].prec - 1;
|
|
||||||
sign = img->comps[0].sgnd;
|
|
||||||
jp2_struct->bpc = depth_0 + (sign << 7);
|
|
||||||
|
|
||||||
for (i = 1; i < img->numcomps; i++) {
|
|
||||||
depth = img->comps[i].prec - 1;
|
|
||||||
sign = img->comps[i].sgnd;
|
|
||||||
if (depth_0 != depth)
|
|
||||||
jp2_struct->bpc = 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jp2_struct->C = 7; // C : Always 7
|
|
||||||
jp2_struct->UnkC = 0; // UnkC, colorspace specified in colr box
|
|
||||||
jp2_struct->IPR = 0; // IPR, no intellectual property
|
|
||||||
|
|
||||||
for (i = 0; i < img->numcomps; i++)
|
|
||||||
jp2_struct->comps[i].bpcc =
|
|
||||||
img->comps[i].prec - 1 + (img->comps[i].sgnd << 7);
|
|
||||||
|
|
||||||
jp2_struct->precedence = 0; // PRECEDENCE
|
|
||||||
jp2_struct->approx = 0; // APPROX
|
|
||||||
|
|
||||||
if ((img->numcomps == 1 || img->numcomps == 3)
|
|
||||||
&& (jp2_struct->bpc != 255))
|
|
||||||
jp2_struct->meth = 1;
|
|
||||||
else
|
|
||||||
jp2_struct->meth = 2;
|
|
||||||
|
|
||||||
if (jp2_struct->meth == 1) {
|
|
||||||
if (img->color_space == 1)
|
|
||||||
jp2_struct->enumcs = 16;
|
|
||||||
else if (img->color_space == 2)
|
|
||||||
jp2_struct->enumcs = 17;
|
|
||||||
else if (img->color_space == 3)
|
|
||||||
jp2_struct->enumcs = 18; // YUV
|
|
||||||
} else
|
|
||||||
jp2_struct->enumcs = 0; // PROFILE (??)
|
|
||||||
|
|
||||||
jp2_struct->brand = JP2_JP2; /* BR */
|
jp2_struct->brand = JP2_JP2; /* BR */
|
||||||
jp2_struct->minversion = 0; /* MinV */
|
jp2_struct->minversion = 0; /* MinV */
|
||||||
jp2_struct->numcl = 1;
|
jp2_struct->numcl = 1;
|
||||||
jp2_struct->cl = (int *) malloc(jp2_struct->numcl * sizeof(int));
|
jp2_struct->cl = (unsigned int *) malloc(jp2_struct->numcl * sizeof(int));
|
||||||
jp2_struct->cl[0] = JP2_JP2; /* CL0 : JP2 */
|
jp2_struct->cl[0] = JP2_JP2; /* CL0 : JP2 */
|
||||||
|
|
||||||
|
jp2_struct->C = 7; /* C : Always 7*/
|
||||||
|
jp2_struct->UnkC = 0; /* UnkC, colorspace specified in colr box*/
|
||||||
|
jp2_struct->IPR = 0; /* IPR, no intellectual property*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,9 +110,9 @@ void jp2_write_url(char *Idx_file)
|
|||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_URL, 4); // DBTL
|
cio_write(JP2_URL, 4); /* DBTL*/
|
||||||
cio_write(0, 1); // VERS
|
cio_write(0, 1); /* VERS*/
|
||||||
cio_write(0, 3); // FLAG
|
cio_write(0, 3); /* FLAG*/
|
||||||
|
|
||||||
for (i = 0; i < strlen(str); i++) {
|
for (i = 0; i < strlen(str); i++) {
|
||||||
cio_write(str[i], 1);
|
cio_write(str[i], 1);
|
||||||
@@ -174,15 +140,15 @@ int jp2_read_ihdr(jp2_struct_t * jp2_struct)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
jp2_struct->h = cio_read(4); // HEIGHT
|
jp2_struct->h = cio_read(4); /* HEIGHT*/
|
||||||
jp2_struct->w = cio_read(4); // WIDTH
|
jp2_struct->w = cio_read(4); /* WIDTH*/
|
||||||
jp2_struct->numcomps = cio_read(2); // NC
|
jp2_struct->numcomps = cio_read(2); /* NC*/
|
||||||
|
|
||||||
jp2_struct->bpc = cio_read(1); // BPC
|
jp2_struct->bpc = cio_read(1); /* BPC*/
|
||||||
|
|
||||||
jp2_struct->C = cio_read(1); // C
|
jp2_struct->C = cio_read(1); /* C */
|
||||||
jp2_struct->UnkC = cio_read(1); // UnkC
|
jp2_struct->UnkC = cio_read(1); /* UnkC*/
|
||||||
jp2_struct->IPR = cio_read(1); // IPR
|
jp2_struct->IPR = cio_read(1); /* IPR*/
|
||||||
|
|
||||||
if (cio_tell() - box.init_pos != box.length) {
|
if (cio_tell() - box.init_pos != box.length) {
|
||||||
fprintf(stderr, "Error with IHDR Box\n");
|
fprintf(stderr, "Error with IHDR Box\n");
|
||||||
@@ -197,17 +163,17 @@ void jp2_write_ihdr(jp2_struct_t * jp2_struct)
|
|||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_IHDR, 4); // IHDR
|
cio_write(JP2_IHDR, 4); /* IHDR*/
|
||||||
|
|
||||||
cio_write(jp2_struct->h, 4); // HEIGHT
|
cio_write(jp2_struct->h, 4); /* HEIGHT*/
|
||||||
cio_write(jp2_struct->w, 4); // WIDTH
|
cio_write(jp2_struct->w, 4); /* WIDTH*/
|
||||||
cio_write(jp2_struct->numcomps, 2); // NC
|
cio_write(jp2_struct->numcomps, 2); /* NC*/
|
||||||
|
|
||||||
cio_write(jp2_struct->bpc, 1); // BPC
|
cio_write(jp2_struct->bpc, 1); /* BPC */
|
||||||
|
|
||||||
cio_write(jp2_struct->C, 1); // C : Always 7
|
cio_write(jp2_struct->C, 1); /* C : Always 7*/
|
||||||
cio_write(jp2_struct->UnkC, 1); // UnkC, colorspace unknow
|
cio_write(jp2_struct->UnkC, 1); /* UnkC, colorspace unknow*/
|
||||||
cio_write(jp2_struct->IPR, 1); // IPR, no intellectual property
|
cio_write(jp2_struct->IPR, 1); /* IPR, no intellectual property*/
|
||||||
|
|
||||||
box.length = cio_tell() - box.init_pos;
|
box.length = cio_tell() - box.init_pos;
|
||||||
cio_seek(box.init_pos);
|
cio_seek(box.init_pos);
|
||||||
@@ -223,7 +189,7 @@ void jp2_write_bpcc(jp2_struct_t * jp2_struct)
|
|||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_BPCC, 4); // BPCC
|
cio_write(JP2_BPCC, 4); /* BPCC*/
|
||||||
|
|
||||||
for (i = 0; i < jp2_struct->numcomps; i++)
|
for (i = 0; i < jp2_struct->numcomps; i++)
|
||||||
cio_write(jp2_struct->comps[i].bpcc, 1);
|
cio_write(jp2_struct->comps[i].bpcc, 1);
|
||||||
@@ -262,16 +228,16 @@ void jp2_write_colr(jp2_struct_t * jp2_struct)
|
|||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_COLR, 4); // COLR
|
cio_write(JP2_COLR, 4); /* COLR*/
|
||||||
|
|
||||||
cio_write(jp2_struct->meth, 1); // METH
|
cio_write(jp2_struct->meth, 1); /* METH*/
|
||||||
cio_write(jp2_struct->precedence, 1); // PRECEDENCE
|
cio_write(jp2_struct->precedence, 1); /* PRECEDENCE*/
|
||||||
cio_write(jp2_struct->approx, 1); // APPROX
|
cio_write(jp2_struct->approx, 1); /* APPROX*/
|
||||||
|
|
||||||
if (jp2_struct->meth == 1)
|
if (jp2_struct->meth == 1)
|
||||||
cio_write(jp2_struct->enumcs, 4); // EnumCS
|
cio_write(jp2_struct->enumcs, 4); /* EnumCS*/
|
||||||
else
|
else
|
||||||
cio_write(0, 1); // PROFILE (??)
|
cio_write(0, 1); /* PROFILE (??)*/
|
||||||
|
|
||||||
box.length = cio_tell() - box.init_pos;
|
box.length = cio_tell() - box.init_pos;
|
||||||
cio_seek(box.init_pos);
|
cio_seek(box.init_pos);
|
||||||
@@ -282,21 +248,31 @@ void jp2_write_colr(jp2_struct_t * jp2_struct)
|
|||||||
int jp2_read_colr(jp2_struct_t * jp2_struct)
|
int jp2_read_colr(jp2_struct_t * jp2_struct)
|
||||||
{
|
{
|
||||||
jp2_box_t box;
|
jp2_box_t box;
|
||||||
|
int skip_len;
|
||||||
|
|
||||||
jp2_read_boxhdr(&box);
|
jp2_read_boxhdr(&box);
|
||||||
if (JP2_COLR != box.type) {
|
do {
|
||||||
fprintf(stderr, "Error: Expected COLR Marker\n");
|
if (JP2_COLR != box.type) {
|
||||||
return 1;
|
cio_skip(box.length - 8);
|
||||||
}
|
jp2_read_boxhdr(&box);
|
||||||
|
}
|
||||||
|
} while (JP2_COLR != box.type);
|
||||||
|
|
||||||
jp2_struct->meth = cio_read(1); // METH
|
jp2_struct->meth = cio_read(1); /* METH*/
|
||||||
jp2_struct->precedence = cio_read(1); // PRECEDENCE
|
jp2_struct->precedence = cio_read(1); /* PRECEDENCE*/
|
||||||
jp2_struct->approx = cio_read(1); // APPROX
|
jp2_struct->approx = cio_read(1); /* APPROX*/
|
||||||
|
|
||||||
if (jp2_struct->meth == 1)
|
if (jp2_struct->meth == 1)
|
||||||
jp2_struct->enumcs = cio_read(4); // EnumCS
|
jp2_struct->enumcs = cio_read(4); /* EnumCS*/
|
||||||
else
|
else {
|
||||||
cio_read(1); // PROFILE
|
/* SKIP PROFILE */
|
||||||
|
skip_len = box.init_pos + box.length - cio_tell();
|
||||||
|
if (skip_len < 0) {
|
||||||
|
fprintf(stderr, "Error with JP2H box size\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cio_skip(box.init_pos + box.length - cio_tell());
|
||||||
|
}
|
||||||
|
|
||||||
if (cio_tell() - box.init_pos != box.length) {
|
if (cio_tell() - box.init_pos != box.length) {
|
||||||
fprintf(stderr, "Error with BPCC Box\n");
|
fprintf(stderr, "Error with BPCC Box\n");
|
||||||
@@ -341,26 +317,38 @@ void jp2_write_jp2h(jp2_struct_t * jp2_struct)
|
|||||||
int jp2_read_jp2h(jp2_struct_t * jp2_struct)
|
int jp2_read_jp2h(jp2_struct_t * jp2_struct)
|
||||||
{
|
{
|
||||||
jp2_box_t box;
|
jp2_box_t box;
|
||||||
|
int skip_len;
|
||||||
|
|
||||||
jp2_read_boxhdr(&box);
|
jp2_read_boxhdr(&box);
|
||||||
if (JP2_JP2H != box.type) {
|
do {
|
||||||
fprintf(stderr, "Error: Expected JP2H Marker\n");
|
if (JP2_JP2H != box.type) {
|
||||||
return 1;
|
if (box.type == JP2_JP2C) {
|
||||||
}
|
fprintf(stderr, "Error: Expected JP2H Marker\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
cio_skip(box.length - 8);
|
||||||
|
jp2_read_boxhdr(&box);
|
||||||
|
}
|
||||||
|
} while (JP2_JP2H != box.type);
|
||||||
|
|
||||||
if (jp2_read_ihdr(jp2_struct))
|
if (jp2_read_ihdr(jp2_struct))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (jp2_struct->bpc == 255)
|
if (jp2_struct->bpc == 255) {
|
||||||
if (jp2_read_bpcc(jp2_struct))
|
if (jp2_read_bpcc(jp2_struct))
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (jp2_read_colr(jp2_struct))
|
if (jp2_read_colr(jp2_struct))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (cio_tell() - box.init_pos != box.length) {
|
skip_len = box.init_pos + box.length - cio_tell();
|
||||||
fprintf(stderr, "Error with JP2H Box\n");
|
if (skip_len < 0) {
|
||||||
|
fprintf(stderr, "Error with JP2H box size\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
cio_skip(box.init_pos + box.length - cio_tell());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +403,7 @@ int jp2_read_ftyp(jp2_struct_t * jp2_struct)
|
|||||||
jp2_struct->cl =
|
jp2_struct->cl =
|
||||||
(unsigned int *) malloc(jp2_struct->numcl * sizeof(unsigned int));
|
(unsigned int *) malloc(jp2_struct->numcl * sizeof(unsigned int));
|
||||||
|
|
||||||
for (i = jp2_struct->numcl; i > 0; i--)
|
for (i = 0; i < (int) jp2_struct->numcl; i++)
|
||||||
jp2_struct->cl[i] = cio_read(4); /* CLi */
|
jp2_struct->cl[i] = cio_read(4); /* CLi */
|
||||||
|
|
||||||
if (cio_tell() - box.init_pos != box.length) {
|
if (cio_tell() - box.init_pos != box.length) {
|
||||||
@@ -425,43 +413,42 @@ int jp2_read_ftyp(jp2_struct_t * jp2_struct)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int jp2_write_jp2c(j2k_image_t * img, j2k_cp_t * cp, char *jp2_buffer,
|
int jp2_write_jp2c(int j2k_codestream_len, int *j2k_codestream_offset,
|
||||||
char *index)
|
char *j2k_codestream)
|
||||||
{
|
{
|
||||||
int len;
|
|
||||||
jp2_box_t box;
|
jp2_box_t box;
|
||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_JP2C, 4); // JP2C
|
cio_write(JP2_JP2C, 4); /* JP2C*/
|
||||||
|
|
||||||
len = j2k_encode(img, cp, jp2_buffer, cp->tdx * cp->tdy * cp->th * cp->tw * 2, index);
|
*j2k_codestream_offset = cio_tell();
|
||||||
|
memcpy(cio_getbp(), j2k_codestream, j2k_codestream_len);
|
||||||
|
|
||||||
box.length = cio_tell() - box.init_pos;
|
box.length = 8 + j2k_codestream_len;
|
||||||
cio_seek(box.init_pos);
|
cio_seek(box.init_pos);
|
||||||
cio_write(box.length, 4); /* L */
|
cio_write(box.length, 4); /* L */
|
||||||
cio_seek(box.init_pos + box.length);
|
cio_seek(box.init_pos + box.length);
|
||||||
|
|
||||||
return box.length;
|
return box.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int jp2_read_jp2c(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
int jp2_read_jp2c(unsigned int *j2k_codestream_len,
|
||||||
j2k_cp_t * cp)
|
unsigned int *j2k_codestream_offset)
|
||||||
{
|
{
|
||||||
jp2_box_t box;
|
jp2_box_t box;
|
||||||
|
|
||||||
jp2_read_boxhdr(&box);
|
jp2_read_boxhdr(&box);
|
||||||
if (JP2_JP2C != box.type) {
|
do {
|
||||||
fprintf(stderr, "Error: Expected JP2C Marker\n");
|
if (JP2_JP2C != box.type) {
|
||||||
return 1;
|
cio_skip(box.length - 8);
|
||||||
}
|
jp2_read_boxhdr(&box);
|
||||||
|
}
|
||||||
|
} while (JP2_JP2C != box.type);
|
||||||
|
|
||||||
src += cio_tell();
|
*j2k_codestream_offset = cio_tell();
|
||||||
|
*j2k_codestream_len = box.length - 8;
|
||||||
if (j2k_decode(src, len, jp2_struct->image, cp) == 0) {
|
|
||||||
fprintf(stderr, "JP2F box: failed to decode J2K bitstream image!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -472,7 +459,7 @@ void jp2_write_jp()
|
|||||||
|
|
||||||
box.init_pos = cio_tell();
|
box.init_pos = cio_tell();
|
||||||
cio_skip(4);
|
cio_skip(4);
|
||||||
cio_write(JP2_JP, 4); // JP
|
cio_write(JP2_JP, 4); /* JP*/
|
||||||
cio_write(0x0d0a870a, 4);
|
cio_write(0x0d0a870a, 4);
|
||||||
|
|
||||||
box.length = cio_tell() - box.init_pos;
|
box.length = cio_tell() - box.init_pos;
|
||||||
@@ -509,8 +496,8 @@ int jp2_read_jp()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
|
||||||
j2k_cp_t * cp)
|
int jp2_read_struct(unsigned char *src, jp2_struct_t * jp2_struct, int len)
|
||||||
{
|
{
|
||||||
cio_init(src, len);
|
cio_init(src, len);
|
||||||
|
|
||||||
@@ -520,20 +507,23 @@ int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
|||||||
return 1;
|
return 1;
|
||||||
if (jp2_read_jp2h(jp2_struct))
|
if (jp2_read_jp2h(jp2_struct))
|
||||||
return 1;
|
return 1;
|
||||||
if (jp2_read_jp2c(src, len, jp2_struct, cp))
|
if (jp2_read_jp2c
|
||||||
|
(&jp2_struct->j2k_codestream_len,
|
||||||
|
&jp2_struct->j2k_codestream_offset))
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int jp2_encode(jp2_struct_t * jp2_struct, j2k_cp_t * cp, char *output,
|
int jp2_wrap_j2k(jp2_struct_t * jp2_struct, char *j2k_codestream,
|
||||||
char *index)
|
char *output)
|
||||||
{
|
{
|
||||||
int len;
|
(void)output;
|
||||||
|
|
||||||
jp2_write_jp();
|
jp2_write_jp();
|
||||||
jp2_write_ftyp(jp2_struct);
|
jp2_write_ftyp(jp2_struct);
|
||||||
jp2_write_jp2h(jp2_struct);
|
jp2_write_jp2h(jp2_struct);
|
||||||
len = jp2_write_jp2c(jp2_struct->image, cp, output, index);
|
|
||||||
|
jp2_write_jp2c(jp2_struct->j2k_codestream_len,
|
||||||
|
&jp2_struct->j2k_codestream_offset, j2k_codestream);
|
||||||
|
|
||||||
return cio_tell();
|
return cio_tell();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ typedef struct {
|
|||||||
unsigned int *cl;
|
unsigned int *cl;
|
||||||
jp2_comps_t *comps;
|
jp2_comps_t *comps;
|
||||||
j2k_image_t *image;
|
j2k_image_t *image;
|
||||||
|
unsigned int j2k_codestream_offset;
|
||||||
|
unsigned int j2k_codestream_len;
|
||||||
} jp2_struct_t;
|
} jp2_struct_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -67,19 +69,16 @@ typedef struct {
|
|||||||
* jp2_struct: the structure you are creating
|
* jp2_struct: the structure you are creating
|
||||||
* img: a j2k_image_t wich will help you to create the jp2_structure
|
* img: a j2k_image_t wich will help you to create the jp2_structure
|
||||||
*/
|
*/
|
||||||
int jp2_init_stdjp2(jp2_struct_t * jp2_struct, j2k_image_t * img);
|
int jp2_init_stdjp2(jp2_struct_t * jp2_struct);
|
||||||
|
|
||||||
/* int jp2_write_jp2c(j2k_image_t * img, j2k_cp_t * cp, char *jp2_buffer,
|
/* int jp2_write_jp2c(int j2k_len, int *j2k_codestream_offset, char *j2k_codestream)
|
||||||
* char *index);
|
|
||||||
*
|
*
|
||||||
* Write the jp2c codestream box
|
* Write the jp2c codestream box
|
||||||
* img: the j2k_image that will be compressed
|
* j2k_len: the j2k codestream length
|
||||||
* jp2_buffer: the buffer that will recieve the compressed data
|
* j2k_codestream_offset: the function will return the j2k codestream offset
|
||||||
* index: the name of the index file
|
* j2k_codestream: the j2k codestream to include in jp2 file
|
||||||
*/
|
*/
|
||||||
int jp2_write_jp2c(j2k_image_t * img, j2k_cp_t * cp, char *jp2_buffer,
|
int jp2_write_jp2c(int j2k_len, int *j2k_codestream_offset, char *j2k_codestream);
|
||||||
char *index);
|
|
||||||
|
|
||||||
|
|
||||||
/* int jp2_write_jp2h(jp2_struct_t * jp2_struct);
|
/* int jp2_write_jp2h(jp2_struct_t * jp2_struct);
|
||||||
*
|
*
|
||||||
@@ -95,28 +94,25 @@ void jp2_write_jp2h(jp2_struct_t * jp2_struct);
|
|||||||
*/
|
*/
|
||||||
int jp2_read_jp2h(jp2_struct_t * jp2_struct);
|
int jp2_read_jp2h(jp2_struct_t * jp2_struct);
|
||||||
|
|
||||||
/* int jp2_encode(jp2_struct_t * jp2_struct, j2k_cp_t * cp, char *output,
|
/* int jp2_wrap_j2k(jp2_struct_t * jp2_struct, char *j2k_codestream,
|
||||||
* char *index);
|
int j2k_len, char *output)
|
||||||
*
|
*
|
||||||
* Encode a JP2 file
|
* Wrap a J2K codestream in a JP2 file
|
||||||
* jp2_buffer: the buffer containing the pointer to the image to encode
|
* jp2_struct: the jp2 structure used to create jp2 boxes
|
||||||
* cp: coding parameters of the image
|
* j2k_codestream: the j2k codestream to include in jp2 file
|
||||||
* outbuf: pointer to memory where compressed data will be written
|
* output: pointer to jp2 codestream that will be created
|
||||||
* index: the name of the index file
|
|
||||||
*/
|
*/
|
||||||
int jp2_encode(jp2_struct_t * jp2_struct, j2k_cp_t * cp, char *output,
|
int jp2_wrap_j2k(jp2_struct_t * jp2_struct, char *j2k_codestream,
|
||||||
char *index);
|
char *output);
|
||||||
|
|
||||||
/* int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
|
||||||
* j2k_cp_t * cp);
|
/* int jp2_read_struct(unsigned char *src, jp2_struct_t * jp2_struct);
|
||||||
*
|
*
|
||||||
* Decode a JP2 file
|
* Decode the structure of a JP2 file
|
||||||
* src: pointer to memory where compressed data is stored
|
* src: pointer to memory where compressed data is stored
|
||||||
* len: length of src buffer
|
|
||||||
* jp2_struct: the jp2 structure that will be created
|
* jp2_struct: the jp2 structure that will be created
|
||||||
* cp: coding parameters of the image
|
* len: length of jp2 codestream
|
||||||
*/
|
*/
|
||||||
int jp2_decode(unsigned char *src, int len, jp2_struct_t * jp2_struct,
|
int jp2_read_struct(unsigned char *src, jp2_struct_t * jp2_struct, int len);
|
||||||
j2k_cp_t * cp);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t * header)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
|
/* see information on bits 'c' [p 10 : A.2.1 general, ISO/IEC FCD 15444-9] */
|
||||||
if (((elmt >> 3) & 0x01) == 1)
|
if (((elmt >> 4) & 0x01) == 1)
|
||||||
header->last_byte = 1;
|
header->last_byte = 1;
|
||||||
|
|
||||||
/* In-class identifier */
|
/* In-class identifier */
|
||||||
@@ -156,7 +156,7 @@ void jpt_read_Msg_Header(jpt_msg_header_struct_t * header)
|
|||||||
/* ---------- */
|
/* ---------- */
|
||||||
/* VBAS : Aux */
|
/* VBAS : Aux */
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
if (header->CSn_Id == 1) {
|
if ((header->Class_Id & 0x01) == 1) {
|
||||||
header->Layer_nb = 0;
|
header->Layer_nb = 0;
|
||||||
header->Layer_nb = jpt_read_VBAS_info(header->Layer_nb);
|
header->Layer_nb = jpt_read_VBAS_info(header->Layer_nb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -536,7 +536,10 @@ void mqc_init_dec(unsigned char *bp, int len)
|
|||||||
mqc_start = bp;
|
mqc_start = bp;
|
||||||
mqc_end = bp + len;
|
mqc_end = bp + len;
|
||||||
mqc_bp = bp;
|
mqc_bp = bp;
|
||||||
mqc_c = *mqc_bp << 16;
|
/*add antonin initbug1*/
|
||||||
|
if (len==0) mqc_c = 0xff << 16;
|
||||||
|
else mqc_c = *mqc_bp << 16;
|
||||||
|
/*dda*/
|
||||||
mqc_bytein();
|
mqc_bytein();
|
||||||
mqc_c <<= 7;
|
mqc_c <<= 7;
|
||||||
mqc_ct -= 7;
|
mqc_ct -= 7;
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ pi_iterator_t *pi_create(j2k_image_t * img, j2k_cp_t * cp, int tileno)
|
|||||||
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
|
||||||
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
|
||||||
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
|
||||||
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); //Mod Antonin : sizebug1
|
res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx); /*Mod Antonin : sizebug1*/
|
||||||
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); //Mod Antonin : sizebug1
|
res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy); /*Mod Antonin : sizebug1*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +269,7 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;/* Add antonin pcrl*/
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
comp = &pi->comps[pi->compno];
|
comp = &pi->comps[pi->compno];
|
||||||
@@ -279,6 +280,8 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);/* Add antonin pcrl*/
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);/* Add antonin pcrl*/
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
@@ -292,9 +295,13 @@ int pi_next_rpcl(pi_iterator_t * pi)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
/*Add Antonin : sizebug1*/
|
||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
/*ddA*/
|
||||||
|
|
||||||
|
/*Add Antonin : pcrl*/
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
@@ -358,62 +365,69 @@ int pi_next_pcrl(pi_iterator_t * pi)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
for (pi->y = pi->ty0; pi->y < pi->ty1;
|
||||||
pi->y += pi->dy - (pi->y % pi->dy)) {
|
pi->y += pi->dy - (pi->y % pi->dy)) {
|
||||||
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
for (pi->x = pi->tx0; pi->x < pi->tx1;
|
||||||
pi->x += pi->dx - (pi->x % pi->dx)) {
|
pi->x += pi->dx - (pi->x % pi->dx)) {
|
||||||
for (pi->compno = pi->poc.compno0;
|
for (pi->compno = pi->poc.compno0;
|
||||||
pi->compno < pi->poc.compno1; pi->compno++) {
|
pi->compno < pi->poc.compno1; pi->compno++) {
|
||||||
comp = &pi->comps[pi->compno];
|
comp = &pi->comps[pi->compno];
|
||||||
for (pi->resno = pi->poc.resno0;
|
for (pi->resno = pi->poc.resno0;
|
||||||
pi->resno < int_min(pi->poc.resno1,
|
pi->resno < int_min(pi->poc.resno1,
|
||||||
comp->numresolutions); pi->resno++) {
|
comp->numresolutions); pi->resno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;/* Add antonin pcrl*/
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
res = &comp->resolutions[pi->resno];
|
res = &comp->resolutions[pi->resno];
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);/* Add antonin pcrl*/
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);/* Add antonin pcrl*/
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
(pi->x % (comp->dx << rpx) == 0
|
(pi->x % (comp->dx << rpx) == 0
|
||||||
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
|| (pi->x == pi->tx0 && (trx0 << levelno) % (1 << rpx)))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!
|
if (!
|
||||||
(pi->y % (comp->dy << rpy) == 0
|
(pi->y % (comp->dy << rpy) == 0
|
||||||
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
|| (pi->y == pi->ty0 && (try0 << levelno) % (1 << rpx)))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
/*Add Antonin : sizebug1*/
|
||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
/*ddA*/
|
||||||
|
|
||||||
|
/*Add Antonin : pcrl*/
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->x, comp->dx << levelno),
|
(pi->x, comp->dx << levelno),
|
||||||
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
res->pdx) - int_floordivpow2(trx0, res->pdx);
|
||||||
prcj =
|
prcj =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
(pi->y, comp->dy << levelno),
|
(pi->y, comp->dy << levelno),
|
||||||
res->pdy) - int_floordivpow2(try0, res->pdy);
|
res->pdy) - int_floordivpow2(try0, res->pdy);
|
||||||
pi->precno = prci + prcj * res->pw;
|
pi->precno = prci + prcj * res->pw;
|
||||||
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) {
|
||||||
if (!pi->
|
if (!pi->
|
||||||
include[pi->layno * pi->step_l +
|
include[pi->layno * pi->step_l +
|
||||||
pi->resno * pi->step_r +
|
pi->resno * pi->step_r +
|
||||||
pi->compno * pi->step_c +
|
pi->compno * pi->step_c +
|
||||||
pi->precno * pi->step_p]) {
|
pi->precno * pi->step_p]) {
|
||||||
pi->include[pi->layno * pi->step_l +
|
pi->include[pi->layno * pi->step_l +
|
||||||
pi->resno * pi->step_r +
|
pi->resno * pi->step_r +
|
||||||
pi->compno * pi->step_c +
|
pi->compno * pi->step_c +
|
||||||
pi->precno * pi->step_p] = 1;
|
pi->precno * pi->step_p] = 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
skip:;
|
skip:;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -460,12 +474,15 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||||||
comp->numresolutions); pi->resno++) {
|
comp->numresolutions); pi->resno++) {
|
||||||
int levelno;
|
int levelno;
|
||||||
int trx0, try0;
|
int trx0, try0;
|
||||||
|
int trx1, try1;/* Add antonin pcrl*/
|
||||||
int rpx, rpy;
|
int rpx, rpy;
|
||||||
int prci, prcj;
|
int prci, prcj;
|
||||||
res = &comp->resolutions[pi->resno];
|
res = &comp->resolutions[pi->resno];
|
||||||
levelno = comp->numresolutions - 1 - pi->resno;
|
levelno = comp->numresolutions - 1 - pi->resno;
|
||||||
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
trx0 = int_ceildiv(pi->tx0, comp->dx << levelno);
|
||||||
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
try0 = int_ceildiv(pi->ty0, comp->dy << levelno);
|
||||||
|
trx1 = int_ceildiv(pi->tx1, comp->dx << levelno);/* Add antonin pcrl*/
|
||||||
|
try1 = int_ceildiv(pi->ty1, comp->dy << levelno);/* Add antonin pcrl*/
|
||||||
rpx = res->pdx + levelno;
|
rpx = res->pdx + levelno;
|
||||||
rpy = res->pdy + levelno;
|
rpy = res->pdy + levelno;
|
||||||
if (!
|
if (!
|
||||||
@@ -479,9 +496,13 @@ int pi_next_cprl(pi_iterator_t * pi)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
/*Add Antonin : sizebug1*/
|
||||||
if ((res->pw==0)||(res->pw==0)) continue;
|
if ((res->pw==0)||(res->pw==0)) continue;
|
||||||
//ddA
|
/*ddA*/
|
||||||
|
|
||||||
|
/*Add Antonin : pcrl*/
|
||||||
|
if ((trx0==trx1)||(try0==try1)) continue;
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
prci =
|
prci =
|
||||||
int_floordivpow2(int_ceildiv
|
int_floordivpow2(int_ceildiv
|
||||||
|
|||||||
103
libopenjpeg/t1.c
103
libopenjpeg/t1.c
@@ -188,6 +188,7 @@ void t1_enc_sigpass_step(int *fp, int *dp, int orient, int bpno, int one,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf,
|
void t1_dec_sigpass_step(int *fp, int *dp, int orient, int oneplushalf,
|
||||||
char type, int vsc)
|
char type, int vsc)
|
||||||
{
|
{
|
||||||
@@ -249,7 +250,9 @@ void t1_dec_sigpass(int w, int h, int bpno, int orient, char type,
|
|||||||
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
||||||
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i],
|
t1_dec_sigpass_step(&t1_flags[1 + j][1 + i],
|
||||||
&t1_data[j][i],
|
&t1_data[j][i],
|
||||||
|
|
||||||
orient,
|
orient,
|
||||||
|
|
||||||
oneplushalf,
|
oneplushalf,
|
||||||
type, vsc);
|
type, vsc);
|
||||||
}
|
}
|
||||||
@@ -279,6 +282,7 @@ void t1_enc_refpass_step(int *fp, int *dp, int bpno, int one, int *nmsedec,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf,
|
void t1_dec_refpass_step(int *fp, int *dp, int poshalf, int neghalf,
|
||||||
char type, int vsc)
|
char type, int vsc)
|
||||||
{
|
{
|
||||||
@@ -331,8 +335,11 @@ void t1_dec_refpass(int w, int h, int bpno, char type, int cblksty)
|
|||||||
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
||||||
t1_dec_refpass_step(&t1_flags[1 + j][1 + i],
|
t1_dec_refpass_step(&t1_flags[1 + j][1 + i],
|
||||||
&t1_data[j][i],
|
&t1_data[j][i],
|
||||||
|
|
||||||
poshalf,
|
poshalf,
|
||||||
|
|
||||||
neghalf,
|
neghalf,
|
||||||
|
|
||||||
type, vsc);
|
type, vsc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,6 +373,8 @@ void t1_enc_clnpass_step(int *fp, int *dp, int orient, int bpno, int one,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf,
|
void t1_dec_clnpass_step(int *fp, int *dp, int orient, int oneplushalf,
|
||||||
int partial, int vsc)
|
int partial, int vsc)
|
||||||
{
|
{
|
||||||
@@ -504,7 +513,9 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
|
|||||||
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
&& (j == k + 3 || j == h - 1)) ? 1 : 0;
|
||||||
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i],
|
t1_dec_clnpass_step(&t1_flags[1 + j][1 + i],
|
||||||
&t1_data[j][i],
|
&t1_data[j][i],
|
||||||
|
|
||||||
orient,
|
orient,
|
||||||
|
|
||||||
oneplushalf,
|
oneplushalf,
|
||||||
agg && (j == k + runlen), vsc);
|
agg && (j == k + runlen), vsc);
|
||||||
}
|
}
|
||||||
@@ -524,7 +535,7 @@ void t1_dec_clnpass(int w, int h, int bpno, int orient, int cblksty)
|
|||||||
}
|
}
|
||||||
} /* VSC and BYPASS by Antonin */
|
} /* VSC and BYPASS by Antonin */
|
||||||
|
|
||||||
double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, double stepsize, int numcomps) //mod fixed_quality
|
double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, int qmfbid, float stepsize, int numcomps) /*mod fixed_quality*/
|
||||||
{
|
{
|
||||||
double w1, w2, wmsedec;
|
double w1, w2, wmsedec;
|
||||||
if (qmfbid == 1) {
|
if (qmfbid == 1) {
|
||||||
@@ -539,7 +550,7 @@ double t1_getwmsedec(int nmsedec, int compno, int level, int orient, int bpno, i
|
|||||||
return wmsedec;
|
return wmsedec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, double stepsize, int cblksty, int numcomps, tcd_tile_t * tile) //mod fixed_quality
|
void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qmfbid, float stepsize, int cblksty, int numcomps, tcd_tile_t * tile) /*mod fixed_quality*/
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
int w, h;
|
int w, h;
|
||||||
@@ -562,8 +573,12 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
|
|||||||
|
|
||||||
cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
|
cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
|
||||||
|
|
||||||
for (i = 0; i < sizeof(t1_flags) / sizeof(int); i++)
|
/* Changed by Dmitry Kolyadin */
|
||||||
((int *) t1_flags)[i] = 0;
|
for (i = 0; i <= w; i++)
|
||||||
|
for (j = 0; j <= h; j++){
|
||||||
|
t1_flags[j][i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
bpno = cblk->numbps - 1;
|
bpno = cblk->numbps - 1;
|
||||||
passtype = 2;
|
passtype = 2;
|
||||||
|
|
||||||
@@ -595,8 +610,8 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cumwmsedec += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); //mod fixed_quality
|
cumwmsedec += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); /*mod fixed_quality*/
|
||||||
tile->distotile += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); //add antonin quality
|
tile->distotile += t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps); /*add antonin quality*/
|
||||||
|
|
||||||
|
|
||||||
/* Code switch "RESTART" (i.e. TERMALL) */
|
/* Code switch "RESTART" (i.e. TERMALL) */
|
||||||
@@ -666,19 +681,28 @@ void t1_encode_cblk(tcd_cblk_t * cblk, int orient, int compno, int level, int qm
|
|||||||
void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
|
void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
|
||||||
int cblksty)
|
int cblksty)
|
||||||
{
|
{
|
||||||
int i;
|
int i, j, w, h;
|
||||||
int w, h;
|
|
||||||
int bpno, passtype;
|
int bpno, passtype;
|
||||||
int segno, passno;
|
int segno, passno;
|
||||||
char type = T1_TYPE_MQ; //BYPASS mode
|
char type = T1_TYPE_MQ; /*BYPASS mode*/
|
||||||
|
|
||||||
for (i = 0; i < sizeof(t1_data) / sizeof(int); i++)
|
|
||||||
((int *) t1_data)[i] = 0;
|
|
||||||
for (i = 0; i < sizeof(t1_flags) / sizeof(int); i++)
|
|
||||||
((int *) t1_flags)[i] = 0;
|
|
||||||
|
|
||||||
w = cblk->x1 - cblk->x0;
|
w = cblk->x1 - cblk->x0;
|
||||||
h = cblk->y1 - cblk->y0;
|
h = cblk->y1 - cblk->y0;
|
||||||
|
|
||||||
|
/* Changed by Dmitry Kolyadin */
|
||||||
|
for (j = 0; j <= h; j++){
|
||||||
|
for (i = 0; i <= w; i++) {
|
||||||
|
t1_flags[j][i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Changed by Dmitry Kolyadin */
|
||||||
|
for (i = 0; i < w; i++) {
|
||||||
|
for (j = 0; j < h; j++){
|
||||||
|
t1_data[j][i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bpno = roishift + cblk->numbps - 1;
|
bpno = roishift + cblk->numbps - 1;
|
||||||
passtype = 2;
|
passtype = 2;
|
||||||
|
|
||||||
@@ -690,7 +714,7 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
|
|||||||
for (segno = 0; segno < cblk->numsegs; segno++) {
|
for (segno = 0; segno < cblk->numsegs; segno++) {
|
||||||
tcd_seg_t *seg = &cblk->segs[segno];
|
tcd_seg_t *seg = &cblk->segs[segno];
|
||||||
|
|
||||||
// Add BYPASS mode
|
/* Add BYPASS mode */
|
||||||
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2)
|
type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2)
|
||||||
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
|
&& (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW :
|
||||||
T1_TYPE_MQ;
|
T1_TYPE_MQ;
|
||||||
@@ -698,28 +722,30 @@ void t1_decode_cblk(tcd_cblk_t * cblk, int orient, int roishift,
|
|||||||
raw_init_dec(seg->data, seg->len);
|
raw_init_dec(seg->data, seg->len);
|
||||||
else
|
else
|
||||||
mqc_init_dec(seg->data, seg->len);
|
mqc_init_dec(seg->data, seg->len);
|
||||||
// ddA
|
/* ddA */
|
||||||
|
|
||||||
if (bpno==0) cblk->lastbp=1; // Add Antonin : quantizbug1
|
|
||||||
|
|
||||||
for (passno = 0; passno < seg->numpasses; passno++) {
|
for (passno = 0; passno < seg->numpasses; passno++) {
|
||||||
switch (passtype) {
|
switch (passtype) {
|
||||||
case 0:
|
case 0:
|
||||||
t1_dec_sigpass(w, h, bpno, orient, type, cblksty);
|
t1_dec_sigpass(w, h, bpno+1, orient, type, cblksty);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
t1_dec_refpass(w, h, bpno, type, cblksty);
|
t1_dec_refpass(w, h, bpno+1, type, cblksty);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
t1_dec_clnpass(w, h, bpno, orient, cblksty);
|
t1_dec_clnpass(w, h, bpno+1, orient, cblksty);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
|
if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) {
|
||||||
mqc_resetstates();
|
mqc_resetstates();
|
||||||
|
|
||||||
mqc_setstate(T1_CTXNO_UNI, 0, 46);
|
mqc_setstate(T1_CTXNO_UNI, 0, 46);
|
||||||
|
|
||||||
mqc_setstate(T1_CTXNO_AGG, 0, 3);
|
mqc_setstate(T1_CTXNO_AGG, 0, 3);
|
||||||
|
|
||||||
mqc_setstate(T1_CTXNO_ZC, 0, 4);
|
mqc_setstate(T1_CTXNO_ZC, 0, 4);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++passtype == 3) {
|
if (++passtype == 3) {
|
||||||
@@ -740,7 +766,7 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
|
|||||||
tcd_precinct_t *prc;
|
tcd_precinct_t *prc;
|
||||||
tcd_cblk_t *cblk;
|
tcd_cblk_t *cblk;
|
||||||
|
|
||||||
tile->distotile = 0; //add fixed_quality
|
tile->distotile = 0; /*add fixed_quality*/
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
tilec = &tile->comps[compno];
|
tilec = &tile->comps[compno];
|
||||||
@@ -791,7 +817,7 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
|
|||||||
tilec->
|
tilec->
|
||||||
x0)],
|
x0)],
|
||||||
8192 * 8192 /
|
8192 * 8192 /
|
||||||
band->stepsize) >> (13 - T1_NMSEDEC_FRACBITS);
|
((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -801,7 +827,7 @@ void t1_encode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
|
|||||||
} else if (orient == 1) {
|
} else if (orient == 1) {
|
||||||
orient = 2;
|
orient = 2;
|
||||||
}
|
}
|
||||||
t1_encode_cblk(cblk, orient, compno, tilec->numresolutions - 1 - resno, tcp->tccps[compno].qmfbid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); //mod fixed_quality
|
t1_encode_cblk(cblk, orient, compno, tilec->numresolutions - 1 - resno, tcp->tccps[compno].qmfbid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); /*mod fixed_quality*/
|
||||||
} /* cblkno */
|
} /* cblkno */
|
||||||
} /* precno */
|
} /* precno */
|
||||||
} /* bandno */
|
} /* bandno */
|
||||||
@@ -868,29 +894,22 @@ void t1_decode_cblks(tcd_tile_t * tile, j2k_tcp_t * tcp)
|
|||||||
if (tcp->tccps[compno].qmfbid == 1) {
|
if (tcp->tccps[compno].qmfbid == 1) {
|
||||||
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
|
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
|
||||||
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
|
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
|
||||||
tilec->data[x + i +
|
int tmp=t1_data[j][i];
|
||||||
(y + j) * (tilec->x1 -
|
if (tmp>>1==0) tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0;
|
||||||
tilec->x0)] = t1_data[j][i];
|
else tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = tmp<0?(tmp>>1)+1:(tmp>>1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { /* if (tcp->tccps[compno].qmfbid == 0) */
|
} else { /* if (tcp->tccps[compno].qmfbid == 0) */
|
||||||
|
|
||||||
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
|
for (j = 0; j < cblk->y1 - cblk->y0; j++) {
|
||||||
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
|
for (i = 0; i < cblk->x1 - cblk->x0; i++) {
|
||||||
if (t1_data[j][i] == 0) {
|
double tmp=t1_data[j][i] * band->stepsize * 4096.0;
|
||||||
tilec->data[x + i +
|
int tmp2;
|
||||||
(y + j) * (tilec->x1 - tilec->x0)] = 0;
|
if (t1_data[j][i]>>1 == 0) {
|
||||||
|
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = 0;
|
||||||
} else {
|
} else {
|
||||||
// Add antonin : quantizbug1
|
tmp2=((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
|
||||||
t1_data[j][i]<<=1;
|
tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0)] = ((tmp<0)?-tmp2:tmp2);
|
||||||
//if (cblk->lastbp)
|
|
||||||
t1_data[j][i]+=t1_data[j][i]>0?1:-1;
|
|
||||||
// ddA
|
|
||||||
tilec->data[x + i +
|
|
||||||
(y + j) * (tilec->x1 -
|
|
||||||
tilec->
|
|
||||||
x0)] =
|
|
||||||
fix_mul(t1_data[j][i] << 12, band->stepsize); //Mod Antonin : quantizbug1 (before : << 13)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1061,7 +1080,7 @@ void t1_init_luts()
|
|||||||
t1_lut_spb[i] = t1_init_spb(i << 4);
|
t1_lut_spb[i] = t1_init_spb(i << 4);
|
||||||
}
|
}
|
||||||
/* FIXME FIXME FIXME */
|
/* FIXME FIXME FIXME */
|
||||||
/* printf("nmsedec luts:\n"); */
|
/* fprintf(stdout,"nmsedec luts:\n"); */
|
||||||
for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) {
|
for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) {
|
||||||
t = i / pow(2, T1_NMSEDEC_FRACBITS);
|
t = i / pow(2, T1_NMSEDEC_FRACBITS);
|
||||||
u = t;
|
u = t;
|
||||||
|
|||||||
111
libopenjpeg/t2.c
111
libopenjpeg/t2.c
@@ -303,6 +303,7 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
tcd_resolution_t *res = &tilec->resolutions[resno];
|
tcd_resolution_t *res = &tilec->resolutions[resno];
|
||||||
unsigned char *c = src;
|
unsigned char *c = src;
|
||||||
|
|
||||||
unsigned char *hd = NULL;
|
unsigned char *hd = NULL;
|
||||||
int present;
|
int present;
|
||||||
|
|
||||||
@@ -310,10 +311,15 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
tcd_band_t *band = &res->bands[bandno];
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
tcd_precinct_t *prc = &band->precincts[precno];
|
||||||
|
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
|
||||||
|
/*Add Antonin : sizebug1*/
|
||||||
|
|
||||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||||
//ddA
|
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
|
|
||||||
tgt_reset(prc->incltree);
|
tgt_reset(prc->incltree);
|
||||||
tgt_reset(prc->imsbtree);
|
tgt_reset(prc->imsbtree);
|
||||||
@@ -323,15 +329,25 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SOP markers
|
|
||||||
|
/* SOP markers*/
|
||||||
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_SOP) {
|
if (tcp->csty & J2K_CP_CSTY_SOP) {
|
||||||
|
|
||||||
if ((*c) != 0xff || (*(c + 1) != 0x91)) {
|
if ((*c) != 0xff || (*(c + 1) != 0x91)) {
|
||||||
printf("Warning : expected SOP marker\n");
|
|
||||||
|
fprintf(stderr,"Warning : expected SOP marker\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
c += 6;
|
c += 6;
|
||||||
|
|
||||||
}
|
}
|
||||||
//TODO : check the Nsop value
|
|
||||||
|
/*TODO : check the Nsop value*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
|
/* When the marker PPT/PPM is used the packet header are store in PPT/PPM marker
|
||||||
@@ -339,53 +355,76 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
step 1: Read packet header in the saved structure
|
step 1: Read packet header in the saved structure
|
||||||
step 2: Return to codestream for decoding */
|
step 2: Return to codestream for decoding */
|
||||||
|
|
||||||
|
|
||||||
if (cp->ppm == 1) { /* PPM */
|
if (cp->ppm == 1) { /* PPM */
|
||||||
hd = cp->ppm_data;
|
hd = cp->ppm_data;
|
||||||
bio_init_dec(hd, cp->ppm_len); //Mod Antonin : ppmbug1
|
bio_init_dec(hd, cp->ppm_len); /*Mod Antonin : ppmbug1*/
|
||||||
} else if (tcp->ppt == 1) { /* PPT */
|
} else if (tcp->ppt == 1) { /* PPT */
|
||||||
hd = tcp->ppt_data;
|
hd = tcp->ppt_data;
|
||||||
bio_init_dec(hd, tcp->ppt_len); //Mod Antonin : ppmbug1
|
bio_init_dec(hd, tcp->ppt_len); /*Mod Antonin : ppmbug1*/
|
||||||
} else { /* Normal Case */
|
} else { /* Normal Case */
|
||||||
|
|
||||||
hd = c;
|
hd = c;
|
||||||
|
|
||||||
bio_init_dec(hd, src+len-hd);
|
bio_init_dec(hd, src+len-hd);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
present = bio_read(1);
|
present = bio_read(1);
|
||||||
|
|
||||||
if (!present) {
|
if (!present) {
|
||||||
bio_inalign();
|
bio_inalign();
|
||||||
|
|
||||||
hd += bio_numbytes();
|
hd += bio_numbytes();
|
||||||
|
|
||||||
// EPH markers
|
|
||||||
|
|
||||||
|
/* EPH markers*/
|
||||||
|
|
||||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||||
|
|
||||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||||
|
|
||||||
printf("Error : expected EPH marker\n");
|
printf("Error : expected EPH marker\n");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
hd += 2;
|
hd += 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cp->ppm == 1) { /* PPM case */
|
if (cp->ppm == 1) { /* PPM case */
|
||||||
|
|
||||||
cp->ppm_len+=cp->ppm_data-hd;
|
cp->ppm_len+=cp->ppm_data-hd;
|
||||||
cp->ppm_data = hd;
|
cp->ppm_data = hd;
|
||||||
return c - src;
|
return c - src;
|
||||||
}
|
}
|
||||||
if (tcp->ppt == 1) { /* PPT case */
|
if (tcp->ppt == 1) { /* PPT case */
|
||||||
|
|
||||||
tcp->ppt_len+=tcp->ppt_data-hd;
|
tcp->ppt_len+=tcp->ppt_data-hd;
|
||||||
tcp->ppt_data = hd;
|
tcp->ppt_data = hd;
|
||||||
return c - src;
|
return c - src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return hd - src;
|
return hd - src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
tcd_band_t *band = &res->bands[bandno];
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
tcd_precinct_t *prc = &band->precincts[precno];
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
|
||||||
|
|
||||||
|
/*Add Antonin : sizebug1*/
|
||||||
|
|
||||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||||
//ddA
|
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
|
|
||||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||||
int included, increment, n;
|
int included, increment, n;
|
||||||
@@ -444,32 +483,49 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
|
|
||||||
hd += bio_numbytes();
|
hd += bio_numbytes();
|
||||||
|
|
||||||
// EPH markers
|
|
||||||
|
/* EPH markers*/
|
||||||
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
if (tcp->csty & J2K_CP_CSTY_EPH) {
|
||||||
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
|
||||||
printf("Error : expected EPH marker\n");
|
fprintf(stderr,"Error : expected EPH marker\n");
|
||||||
} else {
|
} else {
|
||||||
hd += 2;
|
hd += 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (cp->ppm==1) {
|
if (cp->ppm==1) {
|
||||||
|
|
||||||
cp->ppm_len+=cp->ppm_data-hd;
|
cp->ppm_len+=cp->ppm_data-hd;
|
||||||
|
|
||||||
cp->ppm_data = hd;
|
cp->ppm_data = hd;
|
||||||
|
|
||||||
} else if (tcp->ppt == 1) {
|
} else if (tcp->ppt == 1) {
|
||||||
|
|
||||||
tcp->ppt_len+=tcp->ppt_data-hd;
|
tcp->ppt_len+=tcp->ppt_data-hd;
|
||||||
|
|
||||||
tcp->ppt_data = hd;
|
tcp->ppt_data = hd;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
c=hd;
|
c=hd;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
tcd_band_t *band = &res->bands[bandno];
|
||||||
tcd_precinct_t *prc = &band->precincts[precno];
|
tcd_precinct_t *prc = &band->precincts[precno];
|
||||||
|
|
||||||
//Add Antonin : sizebug1
|
|
||||||
|
|
||||||
|
/*Add Antonin : sizebug1*/
|
||||||
|
|
||||||
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)) continue;
|
||||||
//ddA
|
|
||||||
|
/*ddA*/
|
||||||
|
|
||||||
|
|
||||||
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
for (cblkno = 0; cblkno < prc->cw * prc->ch; cblkno++) {
|
||||||
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
tcd_cblk_t *cblk = &prc->cblks[cblkno];
|
||||||
@@ -478,6 +534,7 @@ int t2_decode_packet(unsigned char *src, int len, tcd_tile_t * tile,
|
|||||||
continue;
|
continue;
|
||||||
if (!cblk->numsegs) {
|
if (!cblk->numsegs) {
|
||||||
seg = &cblk->segs[0];
|
seg = &cblk->segs[0];
|
||||||
|
|
||||||
cblk->numsegs++;
|
cblk->numsegs++;
|
||||||
cblk->len = 0;
|
cblk->len = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -609,23 +666,29 @@ int t2_decode_packets(unsigned char *src, int len, j2k_image_t * img,
|
|||||||
|
|
||||||
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
|
for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) {
|
||||||
while (pi_next(&pi[pino])) {
|
while (pi_next(&pi[pino])) {
|
||||||
e = t2_decode_packet(c, src + len - c, tile, cp,
|
|
||||||
&cp->tcps[tileno], pi[pino].compno,
|
if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) {
|
||||||
pi[pino].resno, pi[pino].precno,
|
e = t2_decode_packet(c, src + len - c, tile, cp,
|
||||||
pi[pino].layno);
|
&cp->tcps[tileno], pi[pino].compno,
|
||||||
|
pi[pino].resno, pi[pino].precno,
|
||||||
|
pi[pino].layno);
|
||||||
|
} else {
|
||||||
|
e = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* progression in resolution */
|
/* progression in resolution */
|
||||||
img->comps[pi[pino].compno].resno_decoded =
|
img->comps[pi[pino].compno].resno_decoded =
|
||||||
e > 0 ? int_max(pi[pino].resno,
|
e > 0 ? int_max(pi[pino].resno,
|
||||||
img->comps[pi[pino].compno].
|
img->comps[pi[pino].compno].
|
||||||
resno_decoded) : img->comps[pi[pino].
|
resno_decoded) : img->comps[pi[pino].
|
||||||
compno].resno_decoded;
|
compno].resno_decoded;
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
if (e == -999) { /* ADD */
|
if (e == -999) { /* ADD */
|
||||||
break;
|
break;
|
||||||
} else
|
} else {
|
||||||
c += e;
|
c += e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FREE space memory taken by pi */
|
/* FREE space memory taken by pi */
|
||||||
|
|||||||
@@ -61,46 +61,62 @@ extern jmp_buf j2k_error;
|
|||||||
void tcd_dump(tcd_image_t * img, int curtileno)
|
void tcd_dump(tcd_image_t * img, int curtileno)
|
||||||
{
|
{
|
||||||
int tileno, compno, resno, bandno, precno, cblkno;
|
int tileno, compno, resno, bandno, precno, cblkno;
|
||||||
fprintf(stderr, "image {\n");
|
(void)curtileno;
|
||||||
fprintf(stderr, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw, img->th,
|
fprintf(stdout, "image {\n");
|
||||||
tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
|
fprintf(stdout, " tw=%d, th=%d x0=%d x1=%d y0=%d y1=%d\n", img->tw,
|
||||||
for (tileno = 0; tileno < 1; tileno++) {
|
img->th, tcd_img->x0, tcd_img->x1, tcd_img->y0, tcd_img->y1);
|
||||||
tcd_tile_t *tile = &tcd_image.tiles[curtileno];
|
for (tileno = 0; tileno < img->th * img->tw; tileno++) {
|
||||||
fprintf(stderr, " tile {\n");
|
tcd_tile_t *tile = &tcd_image.tiles[tileno];
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n", tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
|
fprintf(stdout, " tile {\n");
|
||||||
|
fprintf(stdout, " x0=%d, y0=%d, x1=%d, y1=%d, numcomps=%d\n",
|
||||||
|
tile->x0, tile->y0, tile->x1, tile->y1, tile->numcomps);
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
fprintf(stderr, " tilec {\n");
|
fprintf(stdout, " tilec {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n", tilec->x0, tilec->y0, tilec->x1, tilec->y1, tilec->numresolutions);
|
fprintf(stdout,
|
||||||
|
" x0=%d, y0=%d, x1=%d, y1=%d, numresolutions=%d\n",
|
||||||
|
tilec->x0, tilec->y0, tilec->x1, tilec->y1,
|
||||||
|
tilec->numresolutions);
|
||||||
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
||||||
tcd_resolution_t *res = &tilec->resolutions[resno];
|
tcd_resolution_t *res = &tilec->resolutions[resno];
|
||||||
fprintf(stderr, "\n res {\n");
|
fprintf(stdout, "\n res {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n", res->x0, res->y0, res->x1, res->y1, res->pw, res->ph, res->numbands);
|
fprintf(stdout,
|
||||||
|
" x0=%d, y0=%d, x1=%d, y1=%d, pw=%d, ph=%d, numbands=%d\n",
|
||||||
|
res->x0, res->y0, res->x1, res->y1, res->pw, res->ph,
|
||||||
|
res->numbands);
|
||||||
for (bandno = 0; bandno < res->numbands; bandno++) {
|
for (bandno = 0; bandno < res->numbands; bandno++) {
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
tcd_band_t *band = &res->bands[bandno];
|
||||||
fprintf(stderr, " band {\n");
|
fprintf(stdout, " band {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%d, numbps=%d\n", band->x0, band->y0, band->x1, band->y1, band->stepsize, band->numbps);
|
fprintf(stdout,
|
||||||
|
" x0=%d, y0=%d, x1=%d, y1=%d, stepsize=%f, numbps=%d\n",
|
||||||
|
band->x0, band->y0, band->x1, band->y1,
|
||||||
|
band->stepsize, band->numbps);
|
||||||
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
||||||
tcd_precinct_t *prec = &band->precincts[precno];
|
tcd_precinct_t *prec = &band->precincts[precno];
|
||||||
fprintf(stderr, " prec {\n");
|
fprintf(stdout, " prec {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n", prec->x0, prec->y0, prec->x1, prec->y1, prec->cw, prec->ch);
|
fprintf(stdout,
|
||||||
|
" x0=%d, y0=%d, x1=%d, y1=%d, cw=%d, ch=%d\n",
|
||||||
|
prec->x0, prec->y0, prec->x1, prec->y1,
|
||||||
|
prec->cw, prec->ch);
|
||||||
for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) {
|
for (cblkno = 0; cblkno < prec->cw * prec->ch; cblkno++) {
|
||||||
tcd_cblk_t *cblk=&prec->cblks[cblkno];
|
tcd_cblk_t *cblk = &prec->cblks[cblkno];
|
||||||
fprintf(stderr, " cblk {\n");
|
fprintf(stdout, " cblk {\n");
|
||||||
fprintf(stderr, " x0=%d, y0=%d, x1=%d, y1=%d\n", cblk->x0, cblk->y0, cblk->x1, cblk->y1);
|
fprintf(stdout,
|
||||||
fprintf(stderr, " }\n");
|
" x0=%d, y0=%d, x1=%d, y1=%d\n",
|
||||||
|
cblk->x0, cblk->y0, cblk->x1, cblk->y1);
|
||||||
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " }\n");
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " }\n");
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " }\n");
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " }\n");
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, " }\n");
|
fprintf(stdout, " }\n");
|
||||||
}
|
}
|
||||||
fprintf(stderr, "}\n");
|
fprintf(stdout, "}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||||
@@ -129,17 +145,14 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
/* tile->PPT=img->PPT; */
|
/* tile->PPT=img->PPT; */
|
||||||
/* Modification of the RATE >> */
|
/* Modification of the RATE >> */
|
||||||
for (j = 0; j < tcp->numlayers; j++) {
|
for (j = 0; j < tcp->numlayers; j++) {
|
||||||
tcp->rates[j] =
|
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; /*Mod antonin losslessbug*/
|
||||||
int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) *
|
if (tcp->rates[j]) {
|
||||||
(tile->y1 -
|
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
||||||
tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 *
|
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
||||||
img->comps[0].dx *
|
} else {
|
||||||
img->comps[0].dy));
|
if (!j && tcp->rates[j] < 30)
|
||||||
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
tcp->rates[j] = 30;
|
||||||
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
}
|
||||||
} else {
|
|
||||||
if (!j && tcp->rates[j] < 30)
|
|
||||||
tcp->rates[j] = 30;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* << Modification of the RATE */
|
/* << Modification of the RATE */
|
||||||
@@ -226,10 +239,8 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
j2k_stepsize_t *ss;
|
j2k_stepsize_t *ss;
|
||||||
band = &res->bands[bandno];
|
band = &res->bands[bandno];
|
||||||
band->bandno = resno == 0 ? 0 : bandno + 1;
|
band->bandno = resno == 0 ? 0 : bandno + 1;
|
||||||
x0b = (band->bandno == 1)
|
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
|
||||||
y0b = (band->bandno == 2)
|
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
|
||||||
|
|
||||||
if (band->bandno == 0) {
|
if (band->bandno == 0) {
|
||||||
/* band border (global) */
|
/* band border (global) */
|
||||||
@@ -260,9 +271,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
tccp->qmfbid ==
|
tccp->qmfbid ==
|
||||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||||
numbps = img->comps[compno].prec + gain;
|
numbps = img->comps[compno].prec + gain;
|
||||||
band->stepsize =
|
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||||
(int) floor((1.0 + ss->mant / 2048.0) *
|
|
||||||
pow(2.0, numbps - ss->expn) * 8192.0);
|
|
||||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||||
|
|
||||||
band->precincts =
|
band->precincts =
|
||||||
@@ -333,6 +342,7 @@ void tcd_malloc_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
void tcd_free_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
void tcd_free_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
||||||
{
|
{
|
||||||
int tileno, compno, resno, bandno, precno;
|
int tileno, compno, resno, bandno, precno;
|
||||||
|
(void)curtileno;
|
||||||
tcd_img = img;
|
tcd_img = img;
|
||||||
tcd_cp = cp;
|
tcd_cp = cp;
|
||||||
tcd_image.tw = cp->tw;
|
tcd_image.tw = cp->tw;
|
||||||
@@ -372,7 +382,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
for (tileno = 0; tileno < 1; tileno++) {
|
for (tileno = 0; tileno < 1; tileno++) {
|
||||||
j2k_tcp_t *tcp = &cp->tcps[curtileno];
|
j2k_tcp_t *tcp = &cp->tcps[curtileno];
|
||||||
int j;
|
int j;
|
||||||
// int previous_x0, previous_x1, previous_y0, previous_y1;
|
/* int previous_x0, previous_x1, previous_y0, previous_y1;*/
|
||||||
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
||||||
int p = curtileno % cp->tw;
|
int p = curtileno % cp->tw;
|
||||||
int q = curtileno / cp->tw;
|
int q = curtileno / cp->tw;
|
||||||
@@ -388,17 +398,14 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
/* tile->PPT=img->PPT; */
|
/* tile->PPT=img->PPT; */
|
||||||
/* Modification of the RATE >> */
|
/* Modification of the RATE >> */
|
||||||
for (j = 0; j < tcp->numlayers; j++) {
|
for (j = 0; j < tcp->numlayers; j++) {
|
||||||
tcp->rates[j] =
|
tcp->rates[j] = tcp->rates[j] ? int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 * img->comps[0].dx * img->comps[0].dy)) : 0; /*Mod antonin losslessbug*/
|
||||||
int_ceildiv(tile->numcomps * (tile->x1 - tile->x0) *
|
if (tcp->rates[j]) {
|
||||||
(tile->y1 -
|
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
||||||
tile->y0) * img->comps[0].prec, (tcp->rates[j] * 8 *
|
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
||||||
img->comps[0].dx *
|
} else {
|
||||||
img->comps[0].dy));
|
if (!j && tcp->rates[j] < 30)
|
||||||
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
|
tcp->rates[j] = 30;
|
||||||
tcp->rates[j] = tcp->rates[j - 1] + 20;
|
}
|
||||||
} else {
|
|
||||||
if (!j && tcp->rates[j] < 30)
|
|
||||||
tcp->rates[j] = 30;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* << Modification of the RATE */
|
/* << Modification of the RATE */
|
||||||
@@ -477,10 +484,8 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
j2k_stepsize_t *ss;
|
j2k_stepsize_t *ss;
|
||||||
band = &res->bands[bandno];
|
band = &res->bands[bandno];
|
||||||
band->bandno = resno == 0 ? 0 : bandno + 1;
|
band->bandno = resno == 0 ? 0 : bandno + 1;
|
||||||
x0b = (band->bandno == 1)
|
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
|
||||||
y0b = (band->bandno == 2)
|
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
|
||||||
|
|
||||||
if (band->bandno == 0) {
|
if (band->bandno == 0) {
|
||||||
/* band border */
|
/* band border */
|
||||||
@@ -509,9 +514,7 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
tccp->qmfbid ==
|
tccp->qmfbid ==
|
||||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||||
numbps = img->comps[compno].prec + gain;
|
numbps = img->comps[compno].prec + gain;
|
||||||
band->stepsize =
|
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||||
(int) floor((1.0 + ss->mant / 2048.0) *
|
|
||||||
pow(2.0, numbps - ss->expn) * 8192.0);
|
|
||||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||||
|
|
||||||
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
for (precno = 0; precno < res->pw * res->ph; precno++) {
|
||||||
@@ -580,8 +583,8 @@ void tcd_init_encode(j2k_image_t * img, j2k_cp_t * cp, int curtileno)
|
|||||||
|
|
||||||
void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
||||||
{
|
{
|
||||||
int tileno, compno, resno, bandno, precno, cblkno, i, j;
|
int tileno, compno, resno, bandno, precno, cblkno, i, j, p, q;
|
||||||
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h, p, q;
|
unsigned int x0 = 0, y0 = 0, x1 = 0, y1 = 0, w, h;
|
||||||
tcd_img = img;
|
tcd_img = img;
|
||||||
tcd_cp = cp;
|
tcd_cp = cp;
|
||||||
tcd_image.tw = cp->tw;
|
tcd_image.tw = cp->tw;
|
||||||
@@ -599,7 +602,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
tileno = cp->tileno[i];
|
tileno = cp->tileno[i];
|
||||||
|
|
||||||
|
|
||||||
// int previous_x0, previous_x1, previous_y0, previous_y1;
|
/* int previous_x0, previous_x1, previous_y0, previous_y1;*/
|
||||||
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
/* cfr p59 ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */
|
||||||
p = tileno % cp->tw; /* si numerotation matricielle .. */
|
p = tileno % cp->tw; /* si numerotation matricielle .. */
|
||||||
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
|
q = tileno / cp->tw; /* .. coordonnees de la tile (q,p) q pour ligne et p pour colonne */
|
||||||
@@ -658,8 +661,8 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
|
tlprcystart = int_floordivpow2(res->y0, pdy) << pdy;
|
||||||
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
|
brprcxend = int_ceildivpow2(res->x1, pdx) << pdx;
|
||||||
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
|
brprcyend = int_ceildivpow2(res->y1, pdy) << pdy;
|
||||||
res->pw = (res->x0==res->x1)?0:((brprcxend - tlprcxstart) >> pdx); // Mod Antonin : sizebug1
|
res->pw = (res->x0 == res->x1) ? 0 : ((brprcxend - tlprcxstart) >> pdx); /* Mod Antonin : sizebug1*/
|
||||||
res->ph = (res->y0==res->y1)?0:((brprcyend - tlprcystart) >> pdy); // Mod Antonin : sizebug1
|
res->ph = (res->y0 == res->y1) ? 0 : ((brprcyend - tlprcystart) >> pdy); /* Mod Antonin : sizebug1*/
|
||||||
|
|
||||||
if (resno == 0) {
|
if (resno == 0) {
|
||||||
tlcbgxstart = tlprcxstart;
|
tlcbgxstart = tlprcxstart;
|
||||||
@@ -686,10 +689,8 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
j2k_stepsize_t *ss;
|
j2k_stepsize_t *ss;
|
||||||
tcd_band_t *band = &res->bands[bandno];
|
tcd_band_t *band = &res->bands[bandno];
|
||||||
band->bandno = resno == 0 ? 0 : bandno + 1;
|
band->bandno = resno == 0 ? 0 : bandno + 1;
|
||||||
x0b = (band->bandno == 1)
|
x0b = (band->bandno == 1) || (band->bandno == 3) ? 1 : 0;
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
y0b = (band->bandno == 2) || (band->bandno == 3) ? 1 : 0;
|
||||||
y0b = (band->bandno == 2)
|
|
||||||
|| (band->bandno == 3) ? 1 : 0;
|
|
||||||
|
|
||||||
if (band->bandno == 0) {
|
if (band->bandno == 0) {
|
||||||
/* band border (global) */
|
/* band border (global) */
|
||||||
@@ -715,13 +716,11 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
|
|
||||||
ss = &tccp->stepsizes[resno ==
|
ss = &tccp->stepsizes[resno ==
|
||||||
0 ? 0 : 3 * (resno - 1) + bandno + 1];
|
0 ? 0 : 3 * (resno - 1) + bandno + 1];
|
||||||
gain =
|
gain =
|
||||||
tccp->qmfbid ==
|
tccp->qmfbid ==
|
||||||
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
0 ? dwt_getgain_real(band->bandno) : dwt_getgain(band->bandno);
|
||||||
numbps = img->comps[compno].prec + gain;
|
numbps = img->comps[compno].prec + gain;
|
||||||
band->stepsize =
|
band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn));
|
||||||
(int) floor((1.0 + ss->mant / 2048.0) *
|
|
||||||
pow(2.0, numbps - ss->expn) * 8192.0);
|
|
||||||
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */
|
||||||
|
|
||||||
band->precincts =
|
band->precincts =
|
||||||
@@ -774,41 +773,54 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
cblk->y0 = int_max(cblkystart, prc->y0);
|
cblk->y0 = int_max(cblkystart, prc->y0);
|
||||||
cblk->x1 = int_min(cblkxend, prc->x1);
|
cblk->x1 = int_min(cblkxend, prc->x1);
|
||||||
cblk->y1 = int_min(cblkyend, prc->y1);
|
cblk->y1 = int_min(cblkyend, prc->y1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cblk->lastbp = 0; // Add Antonin : quantizbug1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//tcd_dump(&tcd_image,0);
|
/*tcd_dump(&tcd_image,0);*/
|
||||||
|
|
||||||
|
|
||||||
/* Allocate place to store the data decoded = final image */
|
/* Allocate place to store the data decoded = final image */
|
||||||
/* Place limited by the tile really present in the codestream */
|
/* Place limited by the tile really present in the codestream */
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < img->numcomps; i++) {
|
for (i = 0; i < img->numcomps; i++) {
|
||||||
for (j = 0; j < cp->tileno_size; j++) {
|
for (j = 0; j < cp->tileno_size; j++) {
|
||||||
tileno = cp->tileno[j];
|
tileno = cp->tileno[j];
|
||||||
x0 = j == 0 ? tcd_image.tiles[tileno].comps[i].x0 : int_min(x0,
|
x0 = j == 0 ? tcd_image.tiles[tileno].comps[i].x0 : int_min(x0,
|
||||||
tcd_image.
|
(unsigned int)
|
||||||
tiles[tileno].comps[i].x0);
|
tcd_image.
|
||||||
y0 = j == 0 ? tcd_image.tiles[tileno].comps[i].y0 : int_min(y0,
|
tiles
|
||||||
tcd_image.
|
[tileno].
|
||||||
tiles[tileno].comps[i].y0);
|
comps
|
||||||
x1 = j == 0 ? tcd_image.tiles[tileno].comps[i].x1 : int_max(x1,
|
[i].x0);
|
||||||
tcd_image.
|
y0 =
|
||||||
tiles[tileno].comps[i].x1);
|
j == 0 ? tcd_image.tiles[tileno].comps[i].y0 : int_min(y0,
|
||||||
y1 = j == 0 ? tcd_image.tiles[tileno].comps[i].y1 : int_max(y1,
|
(unsigned int)
|
||||||
tcd_image.
|
tcd_image.
|
||||||
tiles[tileno].comps[i].y1);
|
tiles
|
||||||
|
[tileno].
|
||||||
|
comps[i].
|
||||||
|
y0);
|
||||||
|
x1 =
|
||||||
|
j == 0 ? tcd_image.tiles[tileno].comps[i].x1 : int_max(x1,
|
||||||
|
(unsigned int)
|
||||||
|
tcd_image.
|
||||||
|
tiles
|
||||||
|
[tileno].
|
||||||
|
comps[i].
|
||||||
|
x1);
|
||||||
|
y1 =
|
||||||
|
j == 0 ? tcd_image.tiles[tileno].comps[i].y1 : int_max(y1,
|
||||||
|
(unsigned int)
|
||||||
|
tcd_image.
|
||||||
|
tiles
|
||||||
|
[tileno].
|
||||||
|
comps[i].
|
||||||
|
y1);
|
||||||
}
|
}
|
||||||
//w = int_ceildiv(x1 - x0, img->comps[i].dx);
|
|
||||||
//h = int_ceildiv(y1 - y0, img->comps[i].dy);
|
|
||||||
|
|
||||||
w = x1 - x0;
|
w = x1 - x0;
|
||||||
|
|
||||||
@@ -824,7 +836,7 @@ void tcd_init(j2k_image_t * img, j2k_cp_t * cp)
|
|||||||
void tcd_makelayer_fixed(int layno, int final)
|
void tcd_makelayer_fixed(int layno, int final)
|
||||||
{
|
{
|
||||||
int compno, resno, bandno, precno, cblkno;
|
int compno, resno, bandno, precno, cblkno;
|
||||||
int value; //, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3];
|
int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3];*/
|
||||||
int matrice[10][10][3];
|
int matrice[10][10][3];
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
|
|
||||||
@@ -841,7 +853,9 @@ void tcd_makelayer_fixed(int layno, int final)
|
|||||||
j * 3 +
|
j * 3 +
|
||||||
k] *
|
k] *
|
||||||
(float) (tcd_img->comps[compno].prec / 16.0));
|
(float) (tcd_img->comps[compno].prec / 16.0));
|
||||||
}}}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
for (resno = 0; resno < tilec->numresolutions; resno++) {
|
||||||
tcd_resolution_t *res = &tilec->resolutions[resno];
|
tcd_resolution_t *res = &tilec->resolutions[resno];
|
||||||
@@ -923,7 +937,7 @@ void tcd_makelayer(int layno, double thresh, int final)
|
|||||||
{
|
{
|
||||||
int compno, resno, bandno, precno, cblkno, passno;
|
int compno, resno, bandno, precno, cblkno, passno;
|
||||||
|
|
||||||
tcd_tile->distolayer[layno] = 0; //add fixed_quality
|
tcd_tile->distolayer[layno] = 0; /*add fixed_quality*/
|
||||||
|
|
||||||
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
||||||
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
||||||
@@ -955,12 +969,13 @@ void tcd_makelayer(int layno, double thresh, int final)
|
|||||||
dd = pass->distortiondec - cblk->passes[n -
|
dd = pass->distortiondec - cblk->passes[n -
|
||||||
1].distortiondec;
|
1].distortiondec;
|
||||||
}
|
}
|
||||||
if (dr == 0) {
|
if (!dr) {
|
||||||
if (dd != 0)
|
if (dd)
|
||||||
n = passno + 1;
|
n = passno + 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (dd / dr > thresh)
|
|
||||||
|
if (dd / dr >= thresh)
|
||||||
n = passno + 1;
|
n = passno + 1;
|
||||||
}
|
}
|
||||||
layer->numpasses = n - cblk->numpassesinlayers;
|
layer->numpasses = n - cblk->numpassesinlayers;
|
||||||
@@ -985,7 +1000,7 @@ void tcd_makelayer(int layno, double thresh, int final)
|
|||||||
cblk->passes[cblk->numpassesinlayers - 1].distortiondec;
|
cblk->passes[cblk->numpassesinlayers - 1].distortiondec;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcd_tile->distolayer[layno] += layer->disto; //add fixed_quality
|
tcd_tile->distolayer[layno] += layer->disto; /*add fixed_quality*/
|
||||||
|
|
||||||
if (final)
|
if (final)
|
||||||
cblk->numpassesinlayers = n;
|
cblk->numpassesinlayers = n;
|
||||||
@@ -1000,14 +1015,14 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
|||||||
{
|
{
|
||||||
int compno, resno, bandno, precno, cblkno, passno, layno;
|
int compno, resno, bandno, precno, cblkno, passno, layno;
|
||||||
double min, max;
|
double min, max;
|
||||||
double cumdisto[100]; //add fixed_quality
|
double cumdisto[100]; /*add fixed_quality*/
|
||||||
const double K = 1; // 1.1; //add fixed_quality
|
const double K = 1; /* 1.1; //add fixed_quality*/
|
||||||
|
|
||||||
double maxSE = 0;
|
double maxSE = 0;
|
||||||
min = DBL_MAX;
|
min = DBL_MAX;
|
||||||
max = 0;
|
max = 0;
|
||||||
|
|
||||||
tcd_tile->nbpix = 0; //add fixed_quality
|
tcd_tile->nbpix = 0; /*add fixed_quality*/
|
||||||
|
|
||||||
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
for (compno = 0; compno < tcd_tile->numcomps; compno++) {
|
||||||
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tcd_tile->comps[compno];
|
||||||
@@ -1036,7 +1051,9 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
|||||||
if (dr == 0) {
|
if (dr == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rdslope = dd / dr;
|
rdslope = dd / dr;
|
||||||
|
|
||||||
if (rdslope < min) {
|
if (rdslope < min) {
|
||||||
min = rdslope;
|
min = rdslope;
|
||||||
}
|
}
|
||||||
@@ -1045,16 +1062,15 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
|||||||
}
|
}
|
||||||
} /* passno */
|
} /* passno */
|
||||||
|
|
||||||
tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); //add fixed_quality
|
tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); /*add fixed_quality*/
|
||||||
|
|
||||||
tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); //add fixed_quality
|
tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0)); /*add fixed_quality*/
|
||||||
|
|
||||||
} /* cbklno */
|
} /* cbklno */
|
||||||
} /* precno */
|
} /* precno */
|
||||||
} /* bandno */
|
} /* bandno */
|
||||||
} /* resno */
|
} /* resno */
|
||||||
|
maxSE += (((double)(1 << tcd_img->comps[compno].prec) - 1.0) * ((double)(1 << tcd_img->comps[compno].prec) -1.0)) * ((double)(tilec->nbpix));
|
||||||
maxSE+=(double)(((1<<tcd_img->comps[compno].prec)-1)*((1<<tcd_img->comps[compno].prec)-1))*(tilec->nbpix);
|
|
||||||
} /* compno */
|
} /* compno */
|
||||||
|
|
||||||
/* add antonin index */
|
/* add antonin index */
|
||||||
@@ -1071,47 +1087,49 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
|||||||
volatile double lo = min;
|
volatile double lo = min;
|
||||||
volatile double hi = max;
|
volatile double hi = max;
|
||||||
volatile int success = 0;
|
volatile int success = 0;
|
||||||
volatile int maxlen = int_min(tcd_tcp->rates[layno], len);
|
volatile int maxlen = tcd_tcp->rates[layno] ? int_min(tcd_tcp->rates[layno], len) : len; /*Mod antonin losslessbug*/
|
||||||
volatile double goodthresh;
|
volatile double goodthresh;
|
||||||
volatile int goodlen;
|
|
||||||
volatile int i;
|
volatile int i;
|
||||||
double distotarget; //add fixed_quality
|
double distotarget; /*add fixed_quality*/
|
||||||
|
|
||||||
distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); // add fixed_quality
|
distotarget = tcd_tile->distotile - ((K * maxSE) / pow(10, tcd_tcp->distoratio[layno] / 10)); /* add fixed_quality*/
|
||||||
|
|
||||||
|
if ((tcd_tcp->rates[layno]) || (tcd_cp->disto_alloc==0)) {
|
||||||
|
for (i = 0; i < 32; i++) {
|
||||||
|
volatile double thresh = (lo + hi) / 2;
|
||||||
|
int l = 0;
|
||||||
|
double distoachieved = 0; /* add fixed_quality*/
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
tcd_makelayer(layno, thresh, 0);
|
||||||
volatile double thresh = (lo + hi) / 2;
|
|
||||||
int l=0;
|
|
||||||
double distoachieved = 0; // add fixed_quality
|
|
||||||
|
|
||||||
tcd_makelayer(layno, thresh, 0);
|
if (tcd_cp->fixed_quality) { /* add fixed_quality*/
|
||||||
|
distoachieved =
|
||||||
if (tcd_cp->fixed_quality) { // add fixed_quality
|
layno ==
|
||||||
distoachieved =
|
0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] +
|
||||||
layno ==
|
tcd_tile->distolayer[layno];
|
||||||
0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] +
|
if (distoachieved < distotarget) {
|
||||||
tcd_tile->distolayer[layno];
|
hi = thresh;
|
||||||
if (distoachieved < distotarget) {
|
continue;
|
||||||
hi = thresh;
|
}
|
||||||
continue;
|
|
||||||
}
|
|
||||||
lo = thresh;
|
|
||||||
} else {
|
|
||||||
l =
|
|
||||||
t2_encode_packets(tcd_img, tcd_cp, tcd_tileno, tcd_tile,
|
|
||||||
layno + 1, dest, maxlen, info_IM);
|
|
||||||
/* fprintf(stderr, "rate alloc: len=%d, max=%d\n", l, maxlen); */
|
|
||||||
if (l == -999) {
|
|
||||||
lo = thresh;
|
lo = thresh;
|
||||||
continue;
|
} else {
|
||||||
|
l =
|
||||||
|
t2_encode_packets(tcd_img, tcd_cp, tcd_tileno, tcd_tile,
|
||||||
|
layno + 1, dest, maxlen, info_IM);
|
||||||
|
/* fprintf(stderr, "rate alloc: len=%d, max=%d\n", l, maxlen); */
|
||||||
|
if (l == -999) {
|
||||||
|
lo = thresh;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hi = thresh;
|
||||||
}
|
}
|
||||||
hi = thresh;
|
|
||||||
|
success = 1;
|
||||||
|
goodthresh = thresh;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
success = 1;
|
success = 1;
|
||||||
goodthresh = thresh;
|
goodthresh = min;
|
||||||
goodlen = l;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@@ -1123,45 +1141,43 @@ void tcd_rateallocate(unsigned char *dest, int len, info_image * info_IM)
|
|||||||
}
|
}
|
||||||
tcd_makelayer(layno, goodthresh, 1);
|
tcd_makelayer(layno, goodthresh, 1);
|
||||||
|
|
||||||
cumdisto[layno] =
|
cumdisto[layno] = layno == 0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; /* add fixed_quality*/
|
||||||
|
|
||||||
layno ==
|
|
||||||
|
|
||||||
0 ? tcd_tile->distolayer[0] : cumdisto[layno - 1] +
|
|
||||||
|
|
||||||
tcd_tile->distolayer[layno]; // add fixed_quality
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
int
|
||||||
info_image * info_IM)
|
tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
||||||
|
info_image * info_IM)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int l,i;
|
int l, i, npck=0;
|
||||||
clock_t time7;
|
clock_t time7;
|
||||||
tcd_tile_t *tile;
|
tcd_tile_t *tile;
|
||||||
j2k_tcp_t *tcp = &tcd_cp->tcps[0];
|
j2k_tcp_t *tcp = &tcd_cp->tcps[0];
|
||||||
j2k_tccp_t *tccp = &tcp->tccps[0];
|
j2k_tccp_t *tccp = &tcp->tccps[0];
|
||||||
|
|
||||||
tcd_tileno = tileno;
|
tcd_tileno = tileno;
|
||||||
tcd_tile = tcd_image.tiles;
|
tcd_tile = tcd_image.tiles;
|
||||||
tcd_tcp = &tcd_cp->tcps[tileno];
|
tcd_tcp = &tcd_cp->tcps[tileno];
|
||||||
tile = tcd_tile;
|
tile = tcd_tile;
|
||||||
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
||||||
if (info_IM->index_on) {
|
if (info_IM->index_on) {
|
||||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; //Based on Component 0
|
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /*Based on Component 0*/
|
||||||
|
|
||||||
for (i=0;i<tilec_idx->numresolutions;i++) {
|
for (i = 0; i < tilec_idx->numresolutions; i++) {
|
||||||
|
|
||||||
tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
|
tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
|
||||||
|
|
||||||
info_IM->tile[tileno].pw[i] = res_idx->pw;
|
info_IM->tile[tileno].pw[i] = res_idx->pw;
|
||||||
info_IM->tile[tileno].ph[i] = res_idx->ph;
|
info_IM->tile[tileno].ph[i] = res_idx->ph;
|
||||||
|
|
||||||
|
npck+=res_idx->pw * res_idx->ph;
|
||||||
|
|
||||||
info_IM->tile[tileno].pdx[i] = tccp->prcw[i];
|
info_IM->tile[tileno].pdx[i] = tccp->prcw[i];
|
||||||
info_IM->tile[tileno].pdy[i] = tccp->prch[i];
|
info_IM->tile[tileno].pdy[i] = tccp->prch[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
info_IM->tile[tileno].packet = (info_packet *) calloc(info_IM->Comp * info_IM->Layer * npck, sizeof(info_packet));
|
||||||
}
|
}
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
|
|
||||||
@@ -1239,18 +1255,16 @@ int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
|||||||
}
|
}
|
||||||
/*----------------DWT---------------------*/
|
/*----------------DWT---------------------*/
|
||||||
|
|
||||||
/* time3=clock(); */
|
/* mod Ive*/
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||||
dwt_encode(tilec->data, tilec->x1 - tilec->x0,
|
dwt_encode(tilec);
|
||||||
tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1);
|
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
|
||||||
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
|
dwt_encode_real(tilec);
|
||||||
dwt_encode_real(tilec->data, tilec->x1 - tilec->x0,
|
|
||||||
tilec->y1 - tilec->y0, tilec,
|
|
||||||
tilec->numresolutions - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/* /mod Ive*/
|
||||||
/*------------------TIER1-----------------*/
|
/*------------------TIER1-----------------*/
|
||||||
|
|
||||||
t1_init_luts();
|
t1_init_luts();
|
||||||
@@ -1259,7 +1273,7 @@ int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
|||||||
/*-----------RATE-ALLOCATE------------------*/
|
/*-----------RATE-ALLOCATE------------------*/
|
||||||
info_IM->index_write = 0; /* INDEX */
|
info_IM->index_write = 0; /* INDEX */
|
||||||
|
|
||||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) // mod fixed_quality
|
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) /* mod fixed_quality*/
|
||||||
/* Normal Rate/distortion allocation */
|
/* Normal Rate/distortion allocation */
|
||||||
tcd_rateallocate(dest, len, info_IM);
|
tcd_rateallocate(dest, len, info_IM);
|
||||||
else
|
else
|
||||||
@@ -1273,8 +1287,8 @@ int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
|||||||
/*---------------CLEAN-------------------*/
|
/*---------------CLEAN-------------------*/
|
||||||
|
|
||||||
time7 = clock() - time7;
|
time7 = clock() - time7;
|
||||||
printf("total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC,
|
fprintf(stdout,"total: %ld.%.3ld s\n", time7 / CLOCKS_PER_SEC,
|
||||||
(time7 % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
(time7 % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||||
|
|
||||||
/* cleaning memory */
|
/* cleaning memory */
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
@@ -1285,46 +1299,40 @@ int tcd_encode_tile_pxm(int tileno, unsigned char *dest, int len,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
int
|
||||||
info_image * info_IM)
|
tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
||||||
|
info_image * info_IM)
|
||||||
{
|
{
|
||||||
int compno;
|
int compno;
|
||||||
int l,i;
|
int l, i, npck=0;
|
||||||
clock_t time;
|
clock_t time;
|
||||||
tcd_tile_t *tile;
|
tcd_tile_t *tile;
|
||||||
j2k_tcp_t *tcp = &tcd_cp->tcps[0];
|
j2k_tcp_t *tcp = &tcd_cp->tcps[0];
|
||||||
j2k_tccp_t *tccp = &tcp->tccps[0];
|
j2k_tccp_t *tccp = &tcp->tccps[0];
|
||||||
|
|
||||||
tcd_tileno = tileno;
|
tcd_tileno = tileno;
|
||||||
tcd_tile = tcd_image.tiles;
|
tcd_tile = tcd_image.tiles;
|
||||||
tcd_tcp = &tcd_cp->tcps[tileno];
|
tcd_tcp = &tcd_cp->tcps[tileno];
|
||||||
tile = tcd_tile;
|
tile = tcd_tile;
|
||||||
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
/* INDEX >> "Precinct_nb_X et Precinct_nb_Y" */
|
||||||
|
|
||||||
if (info_IM->index_on) {
|
if (info_IM->index_on) {
|
||||||
|
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /*Based on Component 0*/
|
||||||
tcd_tilecomp_t *tilec_idx = &tile->comps[0]; //Based on Component 0
|
|
||||||
|
for (i = 0; i < tilec_idx->numresolutions; i++) {
|
||||||
for (i=0;i<tilec_idx->numresolutions;i++) {
|
|
||||||
|
|
||||||
tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
|
tcd_resolution_t *res_idx = &tilec_idx->resolutions[i];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
info_IM->tile[tileno].pw[i] = res_idx->pw;
|
info_IM->tile[tileno].pw[i] = res_idx->pw;
|
||||||
|
|
||||||
info_IM->tile[tileno].ph[i] = res_idx->ph;
|
info_IM->tile[tileno].ph[i] = res_idx->ph;
|
||||||
|
|
||||||
|
npck+=res_idx->pw * res_idx->ph;
|
||||||
|
|
||||||
info_IM->tile[tileno].pdx[i] = tccp->prcw[i];
|
info_IM->tile[tileno].pdx[i] = tccp->prcw[i];
|
||||||
|
|
||||||
info_IM->tile[tileno].pdy[i] = tccp->prch[i];
|
info_IM->tile[tileno].pdy[i] = tccp->prch[i];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
info_IM->tile[tileno].packet = (info_packet *) calloc(info_IM->Comp * info_IM->Layer * npck, sizeof(info_packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* << INDEX */
|
/* << INDEX */
|
||||||
/*---------------TILE-------------------*/
|
/*---------------TILE-------------------*/
|
||||||
time = clock();
|
time = clock();
|
||||||
@@ -1399,17 +1407,16 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
|||||||
|
|
||||||
/*----------------DWT---------------------*/
|
/*----------------DWT---------------------*/
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
/* mod Ive*/
|
||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
dwt_encode(tilec->data, tilec->x1 - tilec->x0,
|
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||||
tilec->y1 - tilec->y0, tilec, tilec->numresolutions - 1);
|
dwt_encode(tilec);
|
||||||
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
|
} else if (tcd_tcp->tccps[compno].qmfbid == 0) {
|
||||||
dwt_encode_real(tilec->data, tilec->x1 - tilec->x0,
|
dwt_encode_real(tilec);
|
||||||
tilec->y1 - tilec->y0, tilec,
|
|
||||||
tilec->numresolutions - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/* /mod Ive*/
|
||||||
|
|
||||||
/*------------------TIER1-----------------*/
|
/*------------------TIER1-----------------*/
|
||||||
|
|
||||||
@@ -1420,14 +1427,13 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
|||||||
|
|
||||||
info_IM->index_write = 0; /* INDEX */
|
info_IM->index_write = 0; /* INDEX */
|
||||||
|
|
||||||
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) // mod fixed_quality
|
if (tcd_cp->disto_alloc || tcd_cp->fixed_quality) /* mod fixed_quality*/
|
||||||
|
|
||||||
/* Normal Rate/distortion allocation */
|
/* Normal Rate/distortion allocation */
|
||||||
|
|
||||||
tcd_rateallocate(dest, len, info_IM);
|
tcd_rateallocate(dest, len, info_IM);
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
/* Fixed layer allocation */
|
/* Fixed layer allocation */
|
||||||
|
|
||||||
tcd_rateallocate_fixed();
|
tcd_rateallocate_fixed();
|
||||||
@@ -1440,8 +1446,8 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
|||||||
|
|
||||||
/*---------------CLEAN-------------------*/
|
/*---------------CLEAN-------------------*/
|
||||||
time = clock() - time;
|
time = clock() - time;
|
||||||
printf("total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
fprintf(stdout,"total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
||||||
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
(time % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
tilec = &tile->comps[compno];
|
tilec = &tile->comps[compno];
|
||||||
@@ -1467,7 +1473,7 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||||||
|
|
||||||
time = clock();
|
time = clock();
|
||||||
|
|
||||||
fprintf(stderr, "tile decoding time %d/%d: ", tileno + 1,
|
fprintf(stdout, "Tile %d of %d decoded in ", tileno + 1,
|
||||||
tcd_cp->tw * tcd_cp->th);
|
tcd_cp->tw * tcd_cp->th);
|
||||||
|
|
||||||
/*--------------TIER2------------------*/
|
/*--------------TIER2------------------*/
|
||||||
@@ -1487,26 +1493,24 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
tcd_tilecomp_t *tilec = &tile->comps[compno];
|
||||||
if (tcd_cp->reduce_on == 1) {
|
if (tcd_cp->reduce != 0) {
|
||||||
tcd_img->comps[compno].resno_decoded =
|
tcd_img->comps[compno].resno_decoded =
|
||||||
tile->comps[compno].numresolutions - tcd_cp->reduce_value - 1;
|
tile->comps[compno].numresolutions - tcd_cp->reduce - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* mod Ive */
|
||||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||||
dwt_decode(tilec->data, tilec->x1 - tilec->x0,
|
dwt_decode(tilec,
|
||||||
tilec->y1 - tilec->y0, tilec,
|
tilec->numresolutions - 1 -
|
||||||
tilec->numresolutions - 1,
|
tcd_img->comps[compno].resno_decoded);
|
||||||
tilec->numresolutions - 1 -
|
|
||||||
tcd_img->comps[compno].resno_decoded);
|
|
||||||
} else {
|
} else {
|
||||||
dwt_decode_real(tilec->data, tilec->x1 - tilec->x0,
|
dwt_decode_real(tilec,
|
||||||
tilec->y1 - tilec->y0, tilec,
|
|
||||||
tilec->numresolutions - 1,
|
|
||||||
tilec->numresolutions - 1 -
|
tilec->numresolutions - 1 -
|
||||||
tcd_img->comps[compno].resno_decoded);
|
tcd_img->comps[compno].resno_decoded);
|
||||||
}
|
}
|
||||||
|
/* /mod Ive*/
|
||||||
|
|
||||||
if (tile->comps[compno].numresolutions > 0)
|
if (tile->comps[compno].numresolutions > 0)
|
||||||
tcd_img->comps[compno].factor =
|
tcd_img->comps[compno].factor =
|
||||||
tile->comps[compno].numresolutions -
|
tile->comps[compno].numresolutions -
|
||||||
@@ -1561,21 +1565,16 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||||||
for (i = res->x0; i < res->x1; i++) {
|
for (i = res->x0; i < res->x1; i++) {
|
||||||
|
|
||||||
int v;
|
int v;
|
||||||
|
double tmp = (tilec->data[i - res->x0 + (j - res->y0) * tw])/8192.0;
|
||||||
double tmp= (double) tilec->data[i - res->x0 + (j - res->y0) * tw];
|
int tmp2;
|
||||||
|
|
||||||
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
if (tcd_tcp->tccps[compno].qmfbid == 1) {
|
||||||
v = (int) tmp;
|
v = tilec->data[i - res->x0 + (j - res->y0) * tw];
|
||||||
} else {
|
} else {
|
||||||
|
tmp2=((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2);
|
||||||
//v = (int) tmp >> 13;
|
v = ((tmp<0)?-tmp2:tmp2);
|
||||||
|
}
|
||||||
//Mod antonin : multbug1
|
|
||||||
v = (int) ((fabs(tmp/8192.0)>=floor(fabs(tmp/8192.0))+0.5)?fabs(tmp/8192.0)+1.0:fabs(tmp/8192.0));
|
|
||||||
|
|
||||||
v = (tmp<0)?-v:v;
|
|
||||||
|
|
||||||
//doM
|
|
||||||
}
|
|
||||||
v += adjust;
|
v += adjust;
|
||||||
|
|
||||||
tcd_img->comps[compno].data[(i - offset_x) +
|
tcd_img->comps[compno].data[(i - offset_x) +
|
||||||
@@ -1586,12 +1585,14 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||||||
}
|
}
|
||||||
|
|
||||||
time = clock() - time;
|
time = clock() - time;
|
||||||
fprintf(stderr, "total: %ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
fprintf(stdout, "%ld.%.3ld s\n", time / CLOCKS_PER_SEC,
|
||||||
(time % CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
(time % (int)CLOCKS_PER_SEC) * 1000 / CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (compno = 0; compno < tile->numcomps; compno++) {
|
for (compno = 0; compno < tile->numcomps; compno++) {
|
||||||
free(tcd_image.tiles[tileno].comps[compno].data);
|
free(tcd_image.tiles[tileno].comps[compno].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eof) {
|
if (eof) {
|
||||||
longjmp(j2k_error, 1);
|
longjmp(j2k_error, 1);
|
||||||
@@ -1599,3 +1600,57 @@ int tcd_decode_tile(unsigned char *src, int len, int tileno)
|
|||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void tcd_dec_release()
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
int tileno,compno,resno,bandno,precno;
|
||||||
|
|
||||||
|
for (tileno=0;tileno<tcd_image.tw*tcd_image.th;tileno++) {
|
||||||
|
|
||||||
|
tcd_tile_t tile=tcd_image.tiles[tileno];
|
||||||
|
|
||||||
|
for (compno=0;compno<tile.numcomps;compno++) {
|
||||||
|
|
||||||
|
tcd_tilecomp_t tilec=tile.comps[compno];
|
||||||
|
|
||||||
|
for (resno=0;resno<tilec.numresolutions;resno++) {
|
||||||
|
|
||||||
|
tcd_resolution_t res=tilec.resolutions[resno];
|
||||||
|
|
||||||
|
for (bandno=0;bandno<res.numbands;bandno++) {
|
||||||
|
|
||||||
|
tcd_band_t band=res.bands[bandno];
|
||||||
|
|
||||||
|
for (precno=0;precno<res.ph*res.pw;precno++) {
|
||||||
|
|
||||||
|
tcd_precinct_t prec=band.precincts[precno];
|
||||||
|
|
||||||
|
if (prec.cblks!=NULL) free(prec.cblks);
|
||||||
|
|
||||||
|
if (prec.imsbtree!=NULL) free(prec.imsbtree);
|
||||||
|
|
||||||
|
if (prec.incltree!=NULL) free(prec.incltree);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (band.precincts!=NULL) free(band.precincts);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tilec.resolutions!=NULL) free(tilec.resolutions);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tile.comps!=NULL) free(tile.comps);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tcd_image.tiles!=NULL) free(tcd_image.tiles);
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
int x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */
|
||||||
int numbps;
|
int numbps;
|
||||||
int lastbp; /* Add antonin : quantizbug1 */
|
|
||||||
int numlenbits;
|
int numlenbits;
|
||||||
int len; /* length */
|
int len; /* length */
|
||||||
int numpasses; /* number of pass already done for the code-blocks */
|
int numpasses; /* number of pass already done for the code-blocks */
|
||||||
@@ -84,7 +83,7 @@ typedef struct {
|
|||||||
int bandno;
|
int bandno;
|
||||||
tcd_precinct_t *precincts; /* precinct information */
|
tcd_precinct_t *precincts; /* precinct information */
|
||||||
int numbps;
|
int numbps;
|
||||||
int stepsize;
|
float stepsize;
|
||||||
} tcd_band_t;
|
} tcd_band_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -179,4 +178,6 @@ int tcd_encode_tile_pgx(int tileno, unsigned char *dest, int len,
|
|||||||
*/
|
*/
|
||||||
int tcd_decode_tile(unsigned char *src, int len, int tileno);
|
int tcd_decode_tile(unsigned char *src, int len, int tileno);
|
||||||
|
|
||||||
|
void tcd_dec_release();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
128
mj2/MJ2_Extractor.dsp
Normal file
128
mj2/MJ2_Extractor.dsp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="MJ2_Extractor" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=MJ2_Extractor - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "MJ2_Extractor.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "MJ2_Extractor.mak" CFG="MJ2_Extractor - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "MJ2_Extractor - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "MJ2_Extractor - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "MJ2_Extractor - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "MJ2_Extractor - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "MJ2_Extractor___Win32_Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "MJ2_Extractor___Win32_Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "MJ2_Extractor___Win32_Debug"
|
||||||
|
# PROP Intermediate_Dir "MJ2_Extractor___Win32_Debug"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "MJ2_Extractor - Win32 Release"
|
||||||
|
# Name "MJ2_Extractor - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\extract_j2k_from_mj2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
136
mj2/MJ2_Wrapper.dsp
Normal file
136
mj2/MJ2_Wrapper.dsp
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="MJ2_Wrapper" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=MJ2_Wrapper - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "MJ2_Wrapper.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "MJ2_Wrapper.mak" CFG="MJ2_Wrapper - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "MJ2_Wrapper - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "MJ2_Wrapper - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "MJ2_Wrapper - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "MJ2_Wrapper - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "MJ2_Wrapper___Win32_Debug"
|
||||||
|
# PROP BASE Intermediate_Dir "MJ2_Wrapper___Win32_Debug"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "MJ2_Wrapper___Win32_Debug"
|
||||||
|
# PROP Intermediate_Dir "MJ2_Wrapper___Win32_Debug"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "MJ2_Wrapper - Win32 Release"
|
||||||
|
# Name "MJ2_Wrapper - Win32 Debug"
|
||||||
|
# Begin Group "Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\wrap_j2k_in_mj2.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "Resource Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
79
mj2/Makefile
Normal file
79
mj2/Makefile
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#
|
||||||
|
# Valentin Mesaros (Octalis | DICE/UCL Belgium)
|
||||||
|
# 19 April 2005
|
||||||
|
#
|
||||||
|
# Makefile for mj2 source files (frames_to_mj2, mj2_to_frames, extract_j2k_from_mj2, wrap_j2k_in_mj2)
|
||||||
|
#
|
||||||
|
|
||||||
|
INCLUDES = -Imj2 \
|
||||||
|
-I../libopenjpeg
|
||||||
|
|
||||||
|
C_OPT = -Wall
|
||||||
|
CFLAGS = $(INCLUDES) $(C_OPT)
|
||||||
|
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
|
OBJ_MJ2_DIR = obj
|
||||||
|
BIN_MJ2_DIR = bin
|
||||||
|
LIB_OPENJPEG_DIR = ../libopenjpeg/lib
|
||||||
|
LIB_OPENJPEG = $(LIB_OPENJPEG_DIR)/libopenjpeg.a
|
||||||
|
|
||||||
|
all: $(OBJ_MJ2_DIR) $(BIN_MJ2_DIR) \
|
||||||
|
$(BIN_MJ2_DIR)/frames_to_mj2 \
|
||||||
|
$(BIN_MJ2_DIR)/mj2_to_frames \
|
||||||
|
$(BIN_MJ2_DIR)/extract_j2k_from_mj2 \
|
||||||
|
$(BIN_MJ2_DIR)/wrap_j2k_in_mj2
|
||||||
|
|
||||||
|
|
||||||
|
$(OBJ_MJ2_DIR):
|
||||||
|
mkdir $(OBJ_MJ2_DIR)
|
||||||
|
|
||||||
|
$(BIN_MJ2_DIR):
|
||||||
|
mkdir $(BIN_MJ2_DIR)
|
||||||
|
|
||||||
|
$(OBJ_MJ2_DIR)/%.o:
|
||||||
|
$(CC) -c $(CFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
$(OBJ_MJ2_DIR)/frames_to_mj2.o: frames_to_mj2.c
|
||||||
|
$(OBJ_MJ2_DIR)/mj2_to_frames.o: mj2_to_frames.c
|
||||||
|
$(OBJ_MJ2_DIR)/mj2.o: mj2.c
|
||||||
|
$(OBJ_MJ2_DIR)/mj2_convert.o: mj2_convert.c
|
||||||
|
$(OBJ_MJ2_DIR)/extract_j2k_from_mj2.o: extract_j2k_from_mj2.c
|
||||||
|
$(OBJ_MJ2_DIR)/wrap_j2k_in_mj2.o: wrap_j2k_in_mj2.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MJ2_OBJS = $(addprefix $(OBJ_MJ2_DIR)/, mj2.o mj2_convert.o)
|
||||||
|
|
||||||
|
|
||||||
|
$(BIN_MJ2_DIR)/frames_to_mj2: $(OBJ_MJ2_DIR)/frames_to_mj2.o $(MJ2_OBJS) $(LIB_OPENJPEG)
|
||||||
|
$(CC) $(CFLAGS) \
|
||||||
|
-o $(BIN_MJ2_DIR)/frames_to_mj2 \
|
||||||
|
$(MJ2_OBJS) $(OBJ_MJ2_DIR)/frames_to_mj2.o \
|
||||||
|
$(LIB_OPENJPEG) \
|
||||||
|
-lm
|
||||||
|
|
||||||
|
|
||||||
|
$(BIN_MJ2_DIR)/mj2_to_frames: $(OBJ_MJ2_DIR)/mj2_to_frames.o $(MJ2_OBJS) $(LIB_OPENJPEG)
|
||||||
|
$(CC) $(CFLAGS) \
|
||||||
|
-o $(BIN_MJ2_DIR)/mj2_to_frames \
|
||||||
|
$(MJ2_OBJS) $(OBJ_MJ2_DIR)/mj2_to_frames.o \
|
||||||
|
$(LIB_OPENJPEG) \
|
||||||
|
-lm
|
||||||
|
|
||||||
|
|
||||||
|
$(BIN_MJ2_DIR)/extract_j2k_from_mj2: $(OBJ_MJ2_DIR)/extract_j2k_from_mj2.o $(MJ2_OBJS) $(LIB_OPENJPEG)
|
||||||
|
$(CC) $(CFLAGS) \
|
||||||
|
-o $(BIN_MJ2_DIR)/extract_j2k_from_mj2 \
|
||||||
|
$(MJ2_OBJS) $(OBJ_MJ2_DIR)/extract_j2k_from_mj2.o \
|
||||||
|
$(LIB_OPENJPEG) \
|
||||||
|
-lm
|
||||||
|
$(BIN_MJ2_DIR)/wrap_j2k_in_mj2: $(OBJ_MJ2_DIR)/wrap_j2k_in_mj2.o $(MJ2_OBJS) $(LIB_OPENJPEG)
|
||||||
|
$(CC) $(CFLAGS) \
|
||||||
|
-o $(BIN_MJ2_DIR)/wrap_j2k_in_mj2 \
|
||||||
|
$(MJ2_OBJS) $(OBJ_MJ2_DIR)/wrap_j2k_in_mj2.o \
|
||||||
|
$(LIB_OPENJPEG) \
|
||||||
|
-lm
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(BIN_MJ2_DIR)/* $(OBJ_MJ2_DIR)/*
|
||||||
81
mj2/extract_j2k_from_mj2.c
Normal file
81
mj2/extract_j2k_from_mj2.c
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include "mj2.h"
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
jmp_buf j2k_error;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
int tnum;
|
||||||
|
unsigned int snum;
|
||||||
|
mj2_movie_t movie;
|
||||||
|
mj2_tk_t *track;
|
||||||
|
mj2_sample_t *sample;
|
||||||
|
unsigned char* frame_codestream;
|
||||||
|
FILE *file, *outfile;
|
||||||
|
char outfilename[50];
|
||||||
|
|
||||||
|
if (argc != 3) {
|
||||||
|
printf("Bad syntax: Usage: MJ2_extractor mj2filename output_location\n");
|
||||||
|
printf("Example: MJ2_extractor foreman.mj2 output/foreman\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = fopen(argv[1], "rb");
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_%d.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);
|
||||||
|
mj2_memory_free(&movie);
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
997
mj2/frames_to_mj2.c
Normal file
997
mj2/frames_to_mj2.c
Normal file
@@ -0,0 +1,997 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2004, Fran<61>ois-Olivier Devaux
|
||||||
|
* Copyright (c) 2002-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <openjpeg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#ifndef DONT_HAVE_GETOPT
|
||||||
|
#include <getopt.h>
|
||||||
|
#else
|
||||||
|
#include "compat/getopt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "mj2_convert.h"
|
||||||
|
|
||||||
|
#define MJ2_MDAT 0x6d646174
|
||||||
|
#define JP2_JP2C 0x6a703263
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
jmp_buf j2k_error;
|
||||||
|
|
||||||
|
void help_display()
|
||||||
|
{
|
||||||
|
fprintf(stdout,"HELP\n----\n\n");
|
||||||
|
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
|
||||||
|
|
||||||
|
|
||||||
|
fprintf(stdout,"List of parameters for the MJ2 encoder:\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"REMARKS:\n");
|
||||||
|
fprintf(stdout,"---------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"The markers written to the main_header are : SOC SIZ COD QCD COM.\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"COD and QCD never appear in the tile_header.\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"By default:\n");
|
||||||
|
fprintf(stdout,"------------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout," * Lossless\n");
|
||||||
|
fprintf(stdout," * 1 tile\n");
|
||||||
|
fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n");
|
||||||
|
fprintf(stdout," * Size of code-block : 64 x 64\n");
|
||||||
|
fprintf(stdout," * Number of resolutions: 6\n");
|
||||||
|
fprintf(stdout," * No SOP marker in the codestream\n");
|
||||||
|
fprintf(stdout," * No EPH marker in the codestream\n");
|
||||||
|
fprintf(stdout," * No sub-sampling in x or y direction\n");
|
||||||
|
fprintf(stdout," * No mode switch activated\n");
|
||||||
|
fprintf(stdout," * Progression order: LRCP\n");
|
||||||
|
fprintf(stdout," * No index file\n");
|
||||||
|
fprintf(stdout," * No ROI upshifted\n");
|
||||||
|
fprintf(stdout," * No offset of the origin of the image\n");
|
||||||
|
fprintf(stdout," * No offset of the origin of the tiles\n");
|
||||||
|
fprintf(stdout," * Reversible DWT 5-3\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"Parameters:\n");
|
||||||
|
fprintf(stdout,"------------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"Required Parameters (except with -h):\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-i : source file (-i source.yuv) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-o : destination file (-o dest.mj2) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"Optional Parameters:\n");
|
||||||
|
fprintf(stdout,"-h : display the help information \n");
|
||||||
|
fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n ");
|
||||||
|
fprintf(stdout," - The rate specified for each quality level is the desired \n");
|
||||||
|
fprintf(stdout," compression factor.\n");
|
||||||
|
fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n");
|
||||||
|
fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n");
|
||||||
|
fprintf(stdout," (options -r and -q cannot be used together)\n ");
|
||||||
|
|
||||||
|
fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n ");
|
||||||
|
|
||||||
|
fprintf(stdout," (options -r and -q cannot be used together)\n ");
|
||||||
|
|
||||||
|
fprintf(stdout,"-n : number of resolutions (-n 3) \n");
|
||||||
|
fprintf(stdout,"-b : size of code block (-b 32,32) \n");
|
||||||
|
fprintf(stdout,"-c : size of precinct (-c 128,128) \n");
|
||||||
|
fprintf(stdout,"-t : size of tile (-t 512,512) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n");
|
||||||
|
fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-SOP : write SOP marker before each packet \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-EPH : write EPH marker after each header packet \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n");
|
||||||
|
fprintf
|
||||||
|
(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n");
|
||||||
|
fprintf
|
||||||
|
(stdout," Indicate multiple modes by adding their values. \n");
|
||||||
|
fprintf
|
||||||
|
(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
|
||||||
|
fprintf
|
||||||
|
(stdout," for component c=%%d [%%d = 0,1,2]\n");
|
||||||
|
fprintf
|
||||||
|
(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI:c=0,U=25) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-d : offset of the origin of the image (-d 150,300) \n");
|
||||||
|
fprintf
|
||||||
|
(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n");
|
||||||
|
fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n");
|
||||||
|
fprintf(stdout,"-W : image width, height and the dx and dy subsampling \n");
|
||||||
|
fprintf(stdout," of the Cb and Cr components for YUV files \n");
|
||||||
|
fprintf(stdout," (default is '352,288,2,2' for CIF format's 352x288 and 4:2:0)\n");
|
||||||
|
fprintf(stdout,"-F : video frame rate (set to 25 by default)\n");
|
||||||
|
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"IMPORTANT:\n");
|
||||||
|
fprintf(stdout,"-----------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"The index file has the structure below:\n");
|
||||||
|
fprintf(stdout,"---------------------------------------\n");
|
||||||
|
fprintf(stdout,"\n");
|
||||||
|
fprintf(stdout,"Image_height Image_width\n");
|
||||||
|
fprintf(stdout,"progression order\n");
|
||||||
|
fprintf(stdout,"Tiles_size_X Tiles_size_Y\n");
|
||||||
|
fprintf(stdout,"Components_nb\n");
|
||||||
|
fprintf(stdout,"Layers_nb\n");
|
||||||
|
fprintf(stdout,"decomposition_levels\n");
|
||||||
|
fprintf(stdout,"[Precincts_size_X_res_Nr Precincts_size_Y_res_Nr]...\n");
|
||||||
|
fprintf(stdout," [Precincts_size_X_res_0 Precincts_size_Y_res_0]\n");
|
||||||
|
fprintf(stdout,"Main_header_end_position\n");
|
||||||
|
fprintf(stdout,"Codestream_size\n");
|
||||||
|
fprintf(stdout,"Tile_0 start_pos end_Theader end_pos TotalDisto NumPix MaxMSE\n");
|
||||||
|
fprintf(stdout,"Tile_1 '' '' '' '' '' ''\n");
|
||||||
|
fprintf(stdout,"...\n");
|
||||||
|
fprintf(stdout,"Tile_Nt '' '' '' '' '' ''\n");
|
||||||
|
fprintf(stdout,"Tpacket_0 Tile layer res. comp. prec. start_pos end_pos disto\n");
|
||||||
|
fprintf(stdout,"...\n");
|
||||||
|
fprintf(stdout,"Tpacket_Np '' '' '' '' '' '' '' ''\n");
|
||||||
|
|
||||||
|
fprintf(stdout,"MaxDisto\n");
|
||||||
|
|
||||||
|
fprintf(stdout,"TotalDisto\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int give_progression(char progression[4])
|
||||||
|
{
|
||||||
|
if (progression[0] == 'L' && progression[1] == 'R'
|
||||||
|
&& progression[2] == 'C' && progression[3] == 'P') {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
if (progression[0] == 'R' && progression[1] == 'L'
|
||||||
|
&& progression[2] == 'C' && progression[3] == 'P') {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
if (progression[0] == 'R' && progression[1] == 'P'
|
||||||
|
&& progression[2] == 'C' && progression[3] == 'L') {
|
||||||
|
return 2;
|
||||||
|
} else {
|
||||||
|
if (progression[0] == 'P' && progression[1] == 'C'
|
||||||
|
&& progression[2] == 'R' && progression[3] == 'L') {
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
if (progression[0] == 'C' && progression[1] == 'P'
|
||||||
|
&& progression[2] == 'R' && progression[3] == 'L') {
|
||||||
|
return 4;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double dwt_norms_97[4][10] = {
|
||||||
|
{1.000, 1.965, 4.177, 8.403, 16.90, 33.84, 67.69, 135.3, 270.6, 540.9},
|
||||||
|
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||||
|
{2.022, 3.989, 8.355, 17.04, 34.27, 68.63, 137.3, 274.6, 549.0},
|
||||||
|
{2.080, 3.865, 8.307, 17.18, 34.71, 69.59, 139.3, 278.6, 557.2}
|
||||||
|
};
|
||||||
|
|
||||||
|
int floorlog2(int a)
|
||||||
|
{
|
||||||
|
int l;
|
||||||
|
for (l = 0; a > 1; l++) {
|
||||||
|
a >>= 1;
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
void encode_stepsize(int stepsize, int numbps, int *expn, int *mant)
|
||||||
|
{
|
||||||
|
int p, n;
|
||||||
|
p = floorlog2(stepsize) - 13;
|
||||||
|
n = 11 - floorlog2(stepsize);
|
||||||
|
*mant = (n < 0 ? stepsize >> -n : stepsize << n) & 0x7ff;
|
||||||
|
*expn = numbps - p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void calc_explicit_stepsizes(j2k_tccp_t * tccp, int prec)
|
||||||
|
{
|
||||||
|
int numbands, bandno;
|
||||||
|
numbands = 3 * tccp->numresolutions - 2;
|
||||||
|
for (bandno = 0; bandno < numbands; bandno++) {
|
||||||
|
double stepsize;
|
||||||
|
|
||||||
|
int resno, level, orient, gain;
|
||||||
|
resno = bandno == 0 ? 0 : (bandno - 1) / 3 + 1;
|
||||||
|
orient = bandno == 0 ? 0 : (bandno - 1) % 3 + 1;
|
||||||
|
level = tccp->numresolutions - 1 - resno;
|
||||||
|
gain =
|
||||||
|
tccp->qmfbid == 0 ? 0 : (orient ==
|
||||||
|
0 ? 0 : (orient == 1
|
||||||
|
|| orient == 2 ? 1 : 2));
|
||||||
|
if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
|
||||||
|
stepsize = 1.0;
|
||||||
|
} else {
|
||||||
|
double norm = dwt_norms_97[orient][level];
|
||||||
|
stepsize = (1 << (gain + 1)) / norm;
|
||||||
|
}
|
||||||
|
encode_stepsize((int) floor(stepsize * 8192.0), prec + gain,
|
||||||
|
&tccp->stepsizes[bandno].expn,
|
||||||
|
&tccp->stepsizes[bandno].mant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int NumResolution, numD_min; /* NumResolution : number of resolution */
|
||||||
|
int Tile_arg; /* Tile_arg = 0 (not in argument) ou = 1 (in argument) */
|
||||||
|
int CSty; /* CSty : coding style */
|
||||||
|
int Prog_order; /* progression order (default LRCP) */
|
||||||
|
char progression[4];
|
||||||
|
int numpocs, numpocs_tile; /* Number of progression order change (POC) default 0 */
|
||||||
|
int prcw_init[J2K_MAXRLVLS]; /* Initialisation Precinct width */
|
||||||
|
int prch_init[J2K_MAXRLVLS]; /* Initialisation Precinct height */
|
||||||
|
//int prcw_init, prch_init; /* Initialisation precincts' size */
|
||||||
|
int cblockw_init, cblockh_init; /* Initialisation codeblocks' size */
|
||||||
|
int mode, value; /* Mode switch (cblk_style) */
|
||||||
|
int subsampling_dx, subsampling_dy; /* subsampling value for dx and dy */
|
||||||
|
int ROI_compno, ROI_shift; /* region of interrest */
|
||||||
|
int Dim[2]; /* portion of the image coded */
|
||||||
|
int TX0, TY0; /* tile off-set */
|
||||||
|
mj2_movie_t movie;
|
||||||
|
j2k_cp_t cp, cp_init; /* cp_init is used to initialise in multiple tiles */
|
||||||
|
j2k_tcp_t *tcp, *tcp_init; /* tcp_init is used to initialise in multiple tile */
|
||||||
|
j2k_poc_t POC[32]; /* POC : used in case of Progression order change */
|
||||||
|
j2k_poc_t *tcp_poc;
|
||||||
|
j2k_tccp_t *tccp;
|
||||||
|
int i, tileno, l, j;
|
||||||
|
char *infile = 0;
|
||||||
|
char *outfile = 0;
|
||||||
|
char *index = 0;
|
||||||
|
char *s, S1, S2, S3;
|
||||||
|
char *buf;
|
||||||
|
int ir = 0;
|
||||||
|
int res_spec = 0; /* For various precinct sizes specification */
|
||||||
|
char sep;
|
||||||
|
int w; /* Width of YUV file */
|
||||||
|
int h; /* Height of YUV file */
|
||||||
|
int CbCr_subsampling_dx; /* Sample rate of YUV 4:4:4 4:2:2 or 4:2:0 */
|
||||||
|
int CbCr_subsampling_dy; /* Sample rate of YUV 4:4:4 4:2:2 or 4:2:0 */
|
||||||
|
int frame_rate; /* Video Frame Rate */
|
||||||
|
int numcomps; /* In YUV files, numcomps always considered as 3 */
|
||||||
|
int prec; /* In YUV files, precision always considered as 8 */
|
||||||
|
int x1, y1, len, jp2c_initpos, m, k, pos;
|
||||||
|
long mdat_initpos, offset;
|
||||||
|
FILE *mj2file, *yuvfile;
|
||||||
|
unsigned int sampleno;
|
||||||
|
j2k_image_t img;
|
||||||
|
|
||||||
|
/* default value */
|
||||||
|
/* ------------- */
|
||||||
|
NumResolution = 6;
|
||||||
|
CSty = 0;
|
||||||
|
cblockw_init = 64;
|
||||||
|
cblockh_init = 64;
|
||||||
|
cp.tw = 1;
|
||||||
|
cp.th = 1;
|
||||||
|
cp.index_on = 0;
|
||||||
|
Prog_order = 0;
|
||||||
|
numpocs = 0;
|
||||||
|
mode = 0;
|
||||||
|
subsampling_dx = 1;
|
||||||
|
subsampling_dy = 1;
|
||||||
|
ROI_compno = -1; /* no ROI */
|
||||||
|
ROI_shift = 0;
|
||||||
|
Dim[0] = 0;
|
||||||
|
Dim[1] = 0;
|
||||||
|
TX0 = 0;
|
||||||
|
TY0 = 0;
|
||||||
|
cp.comment = NULL;
|
||||||
|
cp.disto_alloc = 0;
|
||||||
|
cp.fixed_alloc = 0;
|
||||||
|
cp.fixed_quality = 0; //add fixed_quality
|
||||||
|
w = 352; // CIF default value
|
||||||
|
h = 288; // CIF default value
|
||||||
|
CbCr_subsampling_dx = 2; // CIF default value
|
||||||
|
CbCr_subsampling_dy = 2; // CIF default value
|
||||||
|
frame_rate = 25;
|
||||||
|
|
||||||
|
|
||||||
|
Tile_arg = 0;
|
||||||
|
cp_init.tcps = (j2k_tcp_t *) malloc(sizeof(j2k_tcp_t)); /* initialisation if only one tile */
|
||||||
|
tcp_init = &cp_init.tcps[0];
|
||||||
|
tcp_init->numlayers = 0;
|
||||||
|
|
||||||
|
cp.intermed_file = 0; // Don't store each tile in a file during processing
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
int c = getopt(argc, argv,
|
||||||
|
"i:o:r:q:f:t:n:c:b:x:p:s:d:h:P:S:E:M:R:T:C:I:W:F:");
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
switch (c) {
|
||||||
|
case 'i': /* IN fill */
|
||||||
|
infile = optarg;
|
||||||
|
s = optarg;
|
||||||
|
while (*s) {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
s--;
|
||||||
|
S3 = *s;
|
||||||
|
s--;
|
||||||
|
S2 = *s;
|
||||||
|
s--;
|
||||||
|
S1 = *s;
|
||||||
|
|
||||||
|
if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
|
||||||
|
|| (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
|
||||||
|
cp.decod_format = YUV_DFMT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fprintf(stderr,
|
||||||
|
"!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
|
||||||
|
S1, S2, S3);
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'o': /* OUT fill */
|
||||||
|
outfile = optarg;
|
||||||
|
while (*outfile) {
|
||||||
|
outfile++;
|
||||||
|
}
|
||||||
|
outfile--;
|
||||||
|
S3 = *outfile;
|
||||||
|
outfile--;
|
||||||
|
S2 = *outfile;
|
||||||
|
outfile--;
|
||||||
|
S1 = *outfile;
|
||||||
|
|
||||||
|
outfile = optarg;
|
||||||
|
|
||||||
|
if ((S1 == 'm' && S2 == 'j' && S3 == '2')
|
||||||
|
|| (S1 == 'M' && S2 == 'J' && S3 == '2'))
|
||||||
|
cp.cod_format = MJ2_CFMT;
|
||||||
|
else {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unknown output format image *.%c%c%c [only *.mj2]!! \n",
|
||||||
|
S1, S2, S3);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'r': /* rates rates/distorsion */
|
||||||
|
s = optarg;
|
||||||
|
while (sscanf(s, "%d", &tcp_init->rates[tcp_init->numlayers])
|
||||||
|
== 1) {
|
||||||
|
tcp_init->numlayers++;
|
||||||
|
while (*s && *s != ',') {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (!*s)
|
||||||
|
break;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
cp.disto_alloc = 1;
|
||||||
|
cp.matrice = NULL;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'q': /* add fixed_quality */
|
||||||
|
s = optarg;
|
||||||
|
while (sscanf
|
||||||
|
(s, "%f", &tcp_init->distoratio[tcp_init->numlayers]) == 1) {
|
||||||
|
tcp_init->numlayers++;
|
||||||
|
while (*s && *s != ',') {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (!*s)
|
||||||
|
break;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
cp.fixed_quality = 1;
|
||||||
|
cp.matrice = NULL;
|
||||||
|
break;
|
||||||
|
/* dda */
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'f': /* mod fixed_quality (before : -q) */
|
||||||
|
s = optarg;
|
||||||
|
sscanf(s, "%d", &tcp_init->numlayers);
|
||||||
|
s++;
|
||||||
|
if (tcp_init->numlayers > 9)
|
||||||
|
s++;
|
||||||
|
cp.matrice =
|
||||||
|
(int *) malloc(tcp_init->numlayers * NumResolution * 3 *
|
||||||
|
sizeof(int));
|
||||||
|
s = s + 2;
|
||||||
|
for (i = 0; i < tcp_init->numlayers; i++) {
|
||||||
|
tcp_init->rates[i] = 1;
|
||||||
|
sscanf(s, "%d,", &cp.matrice[i * NumResolution * 3]);
|
||||||
|
s += 2;
|
||||||
|
if (cp.matrice[i * NumResolution * 3] > 9)
|
||||||
|
s++;
|
||||||
|
cp.matrice[i * NumResolution * 3 + 1] = 0;
|
||||||
|
cp.matrice[i * NumResolution * 3 + 2] = 0;
|
||||||
|
for (j = 1; j < NumResolution; j++) {
|
||||||
|
sscanf(s, "%d,%d,%d",
|
||||||
|
&cp.matrice[i * NumResolution * 3 + j * 3 + 0],
|
||||||
|
&cp.matrice[i * NumResolution * 3 + j * 3 + 1],
|
||||||
|
&cp.matrice[i * NumResolution * 3 + j * 3 + 2]);
|
||||||
|
s += 6;
|
||||||
|
if (cp.matrice[i * NumResolution * 3 + j * 3] > 9)
|
||||||
|
s++;
|
||||||
|
if (cp.matrice[i * NumResolution * 3 + j * 3 + 1] > 9)
|
||||||
|
s++;
|
||||||
|
if (cp.matrice[i * NumResolution * 3 + j * 3 + 2] > 9)
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (i < tcp_init->numlayers - 1)
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
cp.fixed_alloc = 1;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 't': /* tiles */
|
||||||
|
sscanf(optarg, "%d,%d", &cp.tdx, &cp.tdy);
|
||||||
|
Tile_arg = 1;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'n': /* resolution */
|
||||||
|
sscanf(optarg, "%d", &NumResolution);
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'c': /* precinct dimension */
|
||||||
|
s = optarg;
|
||||||
|
do {
|
||||||
|
sep = 0;
|
||||||
|
sscanf(s, "[%d,%d]%c", &prcw_init[res_spec],
|
||||||
|
&prch_init[res_spec], &sep);
|
||||||
|
CSty |= 0x01;
|
||||||
|
res_spec++;
|
||||||
|
s = strpbrk(s, "]") + 2;
|
||||||
|
} while (sep == ',');
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'b': /* code-block dimension */
|
||||||
|
sscanf(optarg, "%d,%d", &cblockw_init, &cblockh_init);
|
||||||
|
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
|
||||||
|
|| cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"!! Size of code_block error (option -b) !!\n\nRestriction :\n * width*height<=4096\n * 4<=width,height<= 1024\n\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'x': /* creation of index file */
|
||||||
|
index = optarg;
|
||||||
|
cp.index_on = 1;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'p': /* progression order */
|
||||||
|
s = optarg;
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
progression[i] = *s;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
Prog_order = give_progression(progression);
|
||||||
|
|
||||||
|
if (Prog_order == -1) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unrecognized progression order [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 's': /* subsampling factor */
|
||||||
|
if (sscanf(optarg, "%d,%d", &subsampling_dx, &subsampling_dy)
|
||||||
|
!= 2) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"'-s' sub-sampling argument error ! [-s dx,dy]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'd': /* coordonnate of the reference grid */
|
||||||
|
if (sscanf(optarg, "%d,%d", &Dim[0], &Dim[1]) != 2) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"-d 'coordonnate of the reference grid' argument error !! [-d x0,y0]\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'h': /* Display an help description */
|
||||||
|
help_display();
|
||||||
|
return 0;
|
||||||
|
break;
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'P': /* POC */
|
||||||
|
fprintf(stderr, "/----------------------------------\\\n");
|
||||||
|
fprintf(stderr, "| POC option not fully tested !! |\n");
|
||||||
|
fprintf(stderr, "\\----------------------------------/\n");
|
||||||
|
|
||||||
|
s = optarg;
|
||||||
|
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%s", &POC[numpocs].tile,
|
||||||
|
&POC[numpocs].resno0, &POC[numpocs].compno0,
|
||||||
|
&POC[numpocs].layno1, &POC[numpocs].resno1,
|
||||||
|
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
|
||||||
|
POC[numpocs].prg = give_progression(POC[numpocs].progorder);
|
||||||
|
/* POC[numpocs].tile; */
|
||||||
|
numpocs++;
|
||||||
|
while (*s && *s != '/') {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
if (!*s)
|
||||||
|
break;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'S': /* SOP marker */
|
||||||
|
CSty |= 0x02;
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'E': /* EPH marker */
|
||||||
|
CSty |= 0x04;
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'M': /* Mode switch pas tous au point !! */
|
||||||
|
if (sscanf(optarg, "%d", &value) == 1) {
|
||||||
|
for (i = 0; i <= 5; i++) {
|
||||||
|
int cache = value & (1 << i);
|
||||||
|
if (cache)
|
||||||
|
mode |= (1 << i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'R': /* ROI */
|
||||||
|
if (sscanf(optarg, "OI:c=%d,U=%d", &ROI_compno, &ROI_shift) != 2) {
|
||||||
|
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'T': /* Tile offset */
|
||||||
|
if (sscanf(optarg, "%d,%d", &TX0, &TY0) != 2) {
|
||||||
|
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'C': /* Add a comment */
|
||||||
|
cp.comment = optarg;
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'I': /* reversible or not */
|
||||||
|
ir = 1;
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'W': /* Width and Height and Cb and Cr subsampling in case of YUV format files */
|
||||||
|
if (sscanf
|
||||||
|
(optarg, "%d,%d,%d,%d", &w, &h, &CbCr_subsampling_dx,
|
||||||
|
&CbCr_subsampling_dy) != 4) {
|
||||||
|
fprintf(stderr, "-W argument error");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
case 'F': /* Video frame rate */
|
||||||
|
if (sscanf(optarg, "%d", &frame_rate) != 1) {
|
||||||
|
fprintf(stderr, "-F argument error");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
/* ------------------------------------------------------ */
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cp.tx0 = TX0;
|
||||||
|
cp.ty0 = TY0;
|
||||||
|
|
||||||
|
/* Error messages */
|
||||||
|
/* -------------- */
|
||||||
|
if (!infile || !outfile) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Correct usage: mj2_encoder -i yuv-file -o mj2-file (+ options)\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((cp.disto_alloc || cp.fixed_alloc || cp.fixed_quality)
|
||||||
|
&& (!(cp.disto_alloc ^ cp.fixed_alloc ^ cp.fixed_quality))) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Error: options -r -q and -f can not be used together !!\n");
|
||||||
|
return 1;
|
||||||
|
} // mod fixed_quality
|
||||||
|
|
||||||
|
/* if no rate entered, lossless by default */
|
||||||
|
if (tcp_init->numlayers == 0) {
|
||||||
|
tcp_init->rates[tcp_init->numlayers] = 0; //MOD antonin : losslessbug
|
||||||
|
tcp_init->numlayers++;
|
||||||
|
cp.disto_alloc = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TX0 > Dim[0] || TY0 > Dim[1]) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n",
|
||||||
|
TX0, Dim[0], TY0, Dim[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < numpocs; i++) {
|
||||||
|
if (POC[i].prg == -1) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n",
|
||||||
|
i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* to respect profile - 0 */
|
||||||
|
/* ---------------------- */
|
||||||
|
numD_min = 0;
|
||||||
|
|
||||||
|
x1 = !Dim[0] ? (w - 1) * subsampling_dx + 1 : Dim[0] + (w -
|
||||||
|
1) *
|
||||||
|
subsampling_dx + 1;
|
||||||
|
y1 = !Dim[1] ? (h - 1) * subsampling_dy + 1 : Dim[1] + (h -
|
||||||
|
1) *
|
||||||
|
subsampling_dy + 1;
|
||||||
|
|
||||||
|
if (Tile_arg == 1) {
|
||||||
|
cp.tw = int_ceildiv(x1 - cp.tx0, cp.tdx);
|
||||||
|
cp.th = int_ceildiv(y1 - cp.ty0, cp.tdy);
|
||||||
|
} else {
|
||||||
|
cp.tdx = x1 - cp.tx0;
|
||||||
|
cp.tdy = y1 - cp.ty0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialization for PPM marker */
|
||||||
|
cp.ppm = 0;
|
||||||
|
cp.ppm_data = NULL;
|
||||||
|
cp.ppm_previous = 0;
|
||||||
|
cp.ppm_store = 0;
|
||||||
|
|
||||||
|
numcomps = 3; /* Because YUV files only have 3 components */
|
||||||
|
|
||||||
|
tcp_init->mct = 0; /* No component transform needed */
|
||||||
|
|
||||||
|
prec = 8; /* Because in YUV files, components have 8-bit depth */
|
||||||
|
|
||||||
|
/* Init the mutiple tiles */
|
||||||
|
/* ---------------------- */
|
||||||
|
cp.tcps = (j2k_tcp_t *) malloc(cp.tw * cp.th * sizeof(j2k_tcp_t));
|
||||||
|
|
||||||
|
for (tileno = 0; tileno < cp.tw * cp.th; tileno++) {
|
||||||
|
tcp = &cp.tcps[tileno];
|
||||||
|
tcp->numlayers = tcp_init->numlayers;
|
||||||
|
for (j = 0; j < tcp->numlayers; j++) {
|
||||||
|
if (cp.fixed_quality) // add fixed_quality
|
||||||
|
tcp->distoratio[j] = tcp_init->distoratio[j];
|
||||||
|
else
|
||||||
|
tcp->rates[j] = tcp_init->rates[j];
|
||||||
|
}
|
||||||
|
tcp->csty = CSty;
|
||||||
|
tcp->prg = Prog_order;
|
||||||
|
tcp->mct = tcp_init->mct;
|
||||||
|
tcp->ppt = 0;
|
||||||
|
tcp->ppt_data = NULL;
|
||||||
|
tcp->ppt_store = 0;
|
||||||
|
|
||||||
|
numpocs_tile = 0;
|
||||||
|
tcp->POC = 0;
|
||||||
|
if (numpocs) {
|
||||||
|
/* intialisation of POC */
|
||||||
|
tcp->POC = 1;
|
||||||
|
for (i = 0; i < numpocs; i++) {
|
||||||
|
if (tileno == POC[i].tile - 1 || POC[i].tile == -1) {
|
||||||
|
tcp_poc = &tcp->pocs[numpocs_tile];
|
||||||
|
tcp_poc->resno0 = POC[numpocs_tile].resno0;
|
||||||
|
tcp_poc->compno0 = POC[numpocs_tile].compno0;
|
||||||
|
tcp_poc->layno1 = POC[numpocs_tile].layno1;
|
||||||
|
tcp_poc->resno1 = POC[numpocs_tile].resno1;
|
||||||
|
tcp_poc->compno1 = POC[numpocs_tile].compno1;
|
||||||
|
tcp_poc->prg = POC[numpocs_tile].prg;
|
||||||
|
tcp_poc->tile = POC[numpocs_tile].tile;
|
||||||
|
numpocs_tile++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tcp->numpocs = numpocs_tile;
|
||||||
|
tcp->tccps = (j2k_tccp_t *) malloc(numcomps * sizeof(j2k_tccp_t));
|
||||||
|
|
||||||
|
for (i = 0; i < numcomps; i++) {
|
||||||
|
tccp = &tcp->tccps[i];
|
||||||
|
tccp->csty = CSty & 0x01; /* 0 => one precinct || 1 => custom precinct */
|
||||||
|
tccp->numresolutions = NumResolution;
|
||||||
|
tccp->cblkw = int_floorlog2(cblockw_init);
|
||||||
|
tccp->cblkh = int_floorlog2(cblockh_init);
|
||||||
|
tccp->cblksty = mode;
|
||||||
|
tccp->qmfbid = ir ? 0 : 1;
|
||||||
|
tccp->qntsty = ir ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT;
|
||||||
|
tccp->numgbits = 2;
|
||||||
|
if (i == ROI_compno)
|
||||||
|
tccp->roishift = ROI_shift;
|
||||||
|
else
|
||||||
|
tccp->roishift = 0;
|
||||||
|
if (CSty & J2K_CCP_CSTY_PRT) {
|
||||||
|
int p = 0;
|
||||||
|
for (j = tccp->numresolutions - 1; j >= 0; j--) {
|
||||||
|
if (p < res_spec) {
|
||||||
|
if (prcw_init[p] < 1)
|
||||||
|
tccp->prcw[j] = 1;
|
||||||
|
else
|
||||||
|
tccp->prcw[j] = int_floorlog2(prcw_init[p]);
|
||||||
|
|
||||||
|
if (prch_init[p] < 1)
|
||||||
|
tccp->prch[j] = 1;
|
||||||
|
else
|
||||||
|
tccp->prch[j] = int_floorlog2(prch_init[p]);
|
||||||
|
} else {
|
||||||
|
int size_prcw, size_prch;
|
||||||
|
size_prcw = prcw_init[res_spec - 1] >> (p - (res_spec - 1));
|
||||||
|
size_prch = prch_init[res_spec - 1] >> (p - (res_spec - 1));
|
||||||
|
if (size_prcw < 1)
|
||||||
|
tccp->prcw[j] = 1;
|
||||||
|
else
|
||||||
|
tccp->prcw[j] = int_floorlog2(size_prcw);
|
||||||
|
if (size_prch < 1)
|
||||||
|
tccp->prch[j] = 1;
|
||||||
|
else
|
||||||
|
tccp->prch[j] = int_floorlog2(size_prch);
|
||||||
|
}
|
||||||
|
p++;
|
||||||
|
/*printf("\nsize precinct pour level %d : %d,%d\n", j,
|
||||||
|
tccp->prcw[j], tccp->prch[j]); */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (j = 0; j < tccp->numresolutions; j++) {
|
||||||
|
tccp->prcw[j] = 15;
|
||||||
|
tccp->prch[j] = 15;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
calc_explicit_stepsizes(tccp, prec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mj2file = fopen(outfile, "wb");
|
||||||
|
|
||||||
|
if (!mj2file) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
movie.tk = (mj2_tk_t *) malloc(sizeof(mj2_tk_t));
|
||||||
|
movie.num_vtk = 1;
|
||||||
|
movie.num_stk = 0;
|
||||||
|
movie.num_htk = 0;
|
||||||
|
|
||||||
|
movie.tk[0].track_type = 0; // Video Track
|
||||||
|
movie.tk[0].track_ID = 1;
|
||||||
|
movie.tk[0].Dim[0] = Dim[0];
|
||||||
|
movie.tk[0].Dim[1] = Dim[1];
|
||||||
|
movie.tk[0].w = w;
|
||||||
|
movie.tk[0].h = h;
|
||||||
|
movie.tk[0].CbCr_subsampling_dx = CbCr_subsampling_dx;
|
||||||
|
movie.tk[0].CbCr_subsampling_dy = CbCr_subsampling_dy;
|
||||||
|
movie.tk[0].sample_rate = frame_rate;
|
||||||
|
movie.tk[0].jp2_struct.numcomps = 3; // NC
|
||||||
|
jp2_init_stdjp2(&movie.tk[0].jp2_struct);
|
||||||
|
|
||||||
|
movie.tk[0].jp2_struct.w = w;
|
||||||
|
movie.tk[0].jp2_struct.h = h;
|
||||||
|
movie.tk[0].jp2_struct.bpc = 7;
|
||||||
|
movie.tk[0].jp2_struct.meth = 1;
|
||||||
|
movie.tk[0].jp2_struct.enumcs = 18; // YUV
|
||||||
|
|
||||||
|
|
||||||
|
yuvfile = fopen(infile,"rb");
|
||||||
|
if (!yuvfile) {
|
||||||
|
fprintf(stderr, "failed to open %s for reading\n",infile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
movie.tk[0].num_samples = yuv_num_frames(&movie.tk[0],yuvfile);
|
||||||
|
if (!movie.tk[0].num_samples) {
|
||||||
|
fprintf(stderr,"Unable to count the number of frames in YUV input file\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// One sample per chunk
|
||||||
|
movie.tk[0].chunk = (mj2_chunk_t*) malloc(movie.tk[0].num_samples * sizeof(mj2_chunk_t));
|
||||||
|
movie.tk[0].sample = (mj2_sample_t*) malloc(movie.tk[0].num_samples * sizeof(mj2_sample_t));
|
||||||
|
|
||||||
|
if (mj2_init_stdmovie(&movie)) {
|
||||||
|
fprintf(stderr, "Error with movie initialization");
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Writing JP, FTYP and MDAT boxes
|
||||||
|
buf = (char*) malloc (300 * sizeof(char)); // Assuming that the JP and FTYP
|
||||||
|
// boxes won't be longer than 300 bytes
|
||||||
|
cio_init(buf , 300);
|
||||||
|
mj2_write_jp();
|
||||||
|
mj2_write_ftyp(&movie);
|
||||||
|
mdat_initpos = cio_tell();
|
||||||
|
cio_skip(4);
|
||||||
|
cio_write(MJ2_MDAT, 4);
|
||||||
|
fwrite(buf,cio_tell(),1,mj2file);
|
||||||
|
offset = cio_tell();
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
for (i = 0; i < movie.num_stk + movie.num_htk + movie.num_vtk; i++) {
|
||||||
|
if (movie.tk[i].track_type != 0) {
|
||||||
|
fprintf(stderr, "Unable to write sound or hint tracks\n");
|
||||||
|
} else {
|
||||||
|
//j2k_cp_t cp_init;
|
||||||
|
mj2_tk_t *tk;
|
||||||
|
|
||||||
|
tk = &movie.tk[i];
|
||||||
|
|
||||||
|
//tk->sample =
|
||||||
|
//(mj2_sample_t *) malloc(tk->num_samples * sizeof(mj2_sample_t));
|
||||||
|
tk->num_chunks = tk->num_samples;
|
||||||
|
//tk->chunk =
|
||||||
|
//(mj2_chunk_t *) malloc(tk->num_chunks * sizeof(mj2_chunk_t));
|
||||||
|
|
||||||
|
fprintf(stderr, "Video Track number %d\n", i + 1);
|
||||||
|
|
||||||
|
// Copy the first tile coding parameters (tcp) to cp_init
|
||||||
|
|
||||||
|
//cp_init.tcps =
|
||||||
|
//(j2k_tcp_t *) malloc(cp.tw * cp.th * sizeof(j2k_tcp_t));
|
||||||
|
for (tileno = 0; tileno < cp.tw * cp.th; tileno++) {
|
||||||
|
for (l = 0; l < cp.tcps[tileno].numlayers; l++) {
|
||||||
|
cp_init.tcps[tileno].rates[l] = cp.tcps[tileno].rates[l];
|
||||||
|
//tileno = cp.tcps[tileno].rates[l];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (sampleno = 0; sampleno < tk->num_samples; sampleno++) {
|
||||||
|
buf = (char *) malloc(cp.tdx * cp.tdy * cp.th * cp.tw * 2);
|
||||||
|
cio_init(buf, cp.tdx * cp.tdy * cp.th * cp.tw * 2);
|
||||||
|
|
||||||
|
fprintf(stderr, "Frame number %d/%d: ", sampleno + 1, tk->num_samples);
|
||||||
|
|
||||||
|
|
||||||
|
if (!yuvtoimage(yuvfile, tk, &img, sampleno, subsampling_dx, subsampling_dy)) {
|
||||||
|
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
jp2c_initpos = cio_tell();
|
||||||
|
cio_skip(4);
|
||||||
|
cio_write(JP2_JP2C, 4); // JP2C
|
||||||
|
|
||||||
|
len = j2k_encode(&img, &cp, buf, cp.tdx * cp.tdy * 2, index);
|
||||||
|
if (len ==0) {
|
||||||
|
fprintf(stderr,"Unable to encode image");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
cio_seek(jp2c_initpos);
|
||||||
|
cio_write(len+8,4);
|
||||||
|
|
||||||
|
for (m = 0; m < img.numcomps; m++) {
|
||||||
|
free(img.comps[m].data);
|
||||||
|
}
|
||||||
|
free(img.comps);
|
||||||
|
|
||||||
|
tk->sample[sampleno].sample_size = len+8;
|
||||||
|
|
||||||
|
tk->sample[sampleno].offset = offset;
|
||||||
|
tk->chunk[sampleno].offset = offset; // There is one sample per chunk
|
||||||
|
|
||||||
|
fwrite(buf, 1, len+8, mj2file);
|
||||||
|
|
||||||
|
offset += len+8;
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
// Copy the cp_init parameters to cp.tcps
|
||||||
|
|
||||||
|
for (tileno = 0; tileno < cp.tw * cp.th; tileno++) {
|
||||||
|
for (k = 0; k < cp.tcps[tileno].numlayers; k++) {
|
||||||
|
cp.tcps[tileno].rates[k] = cp_init.tcps[tileno].rates[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(mj2file, mdat_initpos, SEEK_SET);
|
||||||
|
|
||||||
|
buf = (char*) malloc(4*sizeof(char));
|
||||||
|
|
||||||
|
cio_init(buf, 4); // Init a cio to write box length variable in a little endian way
|
||||||
|
cio_write(offset - mdat_initpos, 4);
|
||||||
|
fwrite(buf, 4, 1, mj2file);
|
||||||
|
fseek(mj2file,0,SEEK_END);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
// Writing MOOV box
|
||||||
|
i=1;
|
||||||
|
buf = (char*) malloc (10000 * sizeof(char));
|
||||||
|
cio_init(buf , i*10000);
|
||||||
|
if (setjmp(j2k_error)) {
|
||||||
|
i++;
|
||||||
|
realloc(buf,i*10000* sizeof(char));
|
||||||
|
pos = cio_tell();
|
||||||
|
cio_init(buf , i*10000);
|
||||||
|
cio_seek(pos);
|
||||||
|
}
|
||||||
|
mj2_write_moov(&movie);
|
||||||
|
fwrite(buf,cio_tell(),1,mj2file);
|
||||||
|
|
||||||
|
// Ending program
|
||||||
|
mj2_memory_free(&movie);
|
||||||
|
free(cp_init.tcps);
|
||||||
|
if (tcp_init->numlayers > 9)
|
||||||
|
free(cp.matrice);
|
||||||
|
for (tileno = 0; tileno < cp.tw * cp.th; tileno++)
|
||||||
|
free(cp.tcps[tileno].tccps);
|
||||||
|
free(cp.tcps);
|
||||||
|
fclose(mj2file);
|
||||||
|
free(buf);
|
||||||
|
remove("Compo0");
|
||||||
|
remove("Compo1");
|
||||||
|
remove("Compo2");
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
269
mj2/frames_to_mj2.dsp
Normal file
269
mj2/frames_to_mj2.dsp
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="frames_to_mj2" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=frames_to_mj2 - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "frames_to_mj2.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "frames_to_mj2.mak" CFG="frames_to_mj2 - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "frames_to_mj2 - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "frames_to_mj2 - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "frames_to_mj2 - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "DONT_HAVE_GETOPT" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "frames_to_mj2 - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "frames_to_mj2___Win32_Debug0"
|
||||||
|
# PROP BASE Intermediate_Dir "frames_to_mj2___Win32_Debug0"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "frames_to_mj2___Win32_Debug0"
|
||||||
|
# PROP Intermediate_Dir "frames_to_mj2___Win32_Debug0"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DONT_HAVE_GETOPT" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "frames_to_mj2 - Win32 Release"
|
||||||
|
# Name "frames_to_mj2 - Win32 Debug"
|
||||||
|
# Begin Group "MJ2"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "MJ2 Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "MJ2 Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\frames_to_mj2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "OpenJPEG Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\openjpeg.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
2185
mj2/meta_out.c
Normal file
2185
mj2/meta_out.c
Normal file
File diff suppressed because it is too large
Load Diff
13
mj2/meta_out.h
Normal file
13
mj2/meta_out.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/* meta_out.h */
|
||||||
|
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
|
||||||
|
/* Callable from mj2_to_metadata */
|
||||||
|
/* Contributed to Open JPEG by Glenn Pearson, U.S. National Library of Medicine */
|
||||||
|
|
||||||
|
#define BOOL int
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
void xml_write_init(BOOL n, BOOL t, BOOL r, BOOL d);
|
||||||
|
|
||||||
|
int xml_write_struct(FILE *file, FILE *xmlout, mj2_movie_t * movie, unsigned int sampleframe, char* stringDTD);
|
||||||
|
|
||||||
201
mj2/mj2.h
Normal file
201
mj2/mj2.h
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2004, Fran<61>ois-Olivier Devaux
|
||||||
|
* Copyright (c) 2003-2004, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <j2k.h>
|
||||||
|
#include <jp2.h>
|
||||||
|
|
||||||
|
#ifndef __MJ2_H
|
||||||
|
#define __MJ2_H
|
||||||
|
|
||||||
|
typedef struct { /* Time To Sample */
|
||||||
|
int sample_count;
|
||||||
|
int sample_delta;
|
||||||
|
} mj2_tts_t;
|
||||||
|
|
||||||
|
typedef struct { /* Chunk */
|
||||||
|
int num_samples;
|
||||||
|
int sample_descr_idx;
|
||||||
|
int offset;
|
||||||
|
} mj2_chunk_t;
|
||||||
|
|
||||||
|
typedef struct { /* Sample to chunk */
|
||||||
|
int first_chunk;
|
||||||
|
int samples_per_chunk;
|
||||||
|
int sample_descr_idx;
|
||||||
|
} mj2_sampletochunk_t;
|
||||||
|
|
||||||
|
typedef struct { /* Sample */
|
||||||
|
unsigned int sample_size;
|
||||||
|
unsigned int offset;
|
||||||
|
unsigned int sample_delta;
|
||||||
|
} mj2_sample_t;
|
||||||
|
|
||||||
|
typedef struct { /* URL */
|
||||||
|
int location[4];
|
||||||
|
} mj2_url_t;
|
||||||
|
|
||||||
|
typedef struct { /* URN */
|
||||||
|
int name[2];
|
||||||
|
int location[4];
|
||||||
|
} mj2_urn_t;
|
||||||
|
|
||||||
|
typedef struct { /* Video Track Parameters */
|
||||||
|
int track_ID;
|
||||||
|
int track_type;
|
||||||
|
unsigned int creation_time;
|
||||||
|
unsigned int modification_time;
|
||||||
|
int duration;
|
||||||
|
int timescale;
|
||||||
|
int layer;
|
||||||
|
int volume;
|
||||||
|
int language;
|
||||||
|
int balance;
|
||||||
|
int maxPDUsize;
|
||||||
|
int avgPDUsize;
|
||||||
|
int maxbitrate;
|
||||||
|
int avgbitrate;
|
||||||
|
int slidingavgbitrate;
|
||||||
|
int graphicsmode;
|
||||||
|
int opcolor[3];
|
||||||
|
int num_url;
|
||||||
|
mj2_url_t *url;
|
||||||
|
int num_urn;
|
||||||
|
mj2_urn_t *urn;
|
||||||
|
int Dim[2];
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
int visual_w;
|
||||||
|
int visual_h;
|
||||||
|
int CbCr_subsampling_dx;
|
||||||
|
int CbCr_subsampling_dy;
|
||||||
|
// int subsampling_dx;
|
||||||
|
// int subsampling_dy;
|
||||||
|
int sample_rate;
|
||||||
|
int sample_description;
|
||||||
|
int horizresolution;
|
||||||
|
int vertresolution;
|
||||||
|
int compressorname[8];
|
||||||
|
int depth;
|
||||||
|
unsigned char fieldcount;
|
||||||
|
unsigned char fieldorder;
|
||||||
|
unsigned char or_fieldcount;
|
||||||
|
unsigned char or_fieldorder;
|
||||||
|
int num_br;
|
||||||
|
unsigned int *br;
|
||||||
|
unsigned char num_jp2x;
|
||||||
|
unsigned char *jp2xdata;
|
||||||
|
unsigned char hsub;
|
||||||
|
unsigned char vsub;
|
||||||
|
unsigned char hoff;
|
||||||
|
unsigned char voff;
|
||||||
|
int trans_matrix[9];
|
||||||
|
unsigned int num_samples; /* Number of samples */
|
||||||
|
int transorm;
|
||||||
|
int handler_type;
|
||||||
|
int name_size;
|
||||||
|
unsigned char same_sample_size;
|
||||||
|
int num_tts;
|
||||||
|
mj2_tts_t *tts; /* Time to sample */
|
||||||
|
unsigned int num_chunks;
|
||||||
|
mj2_chunk_t *chunk;
|
||||||
|
int num_samplestochunk;
|
||||||
|
mj2_sampletochunk_t *sampletochunk;
|
||||||
|
char *name;
|
||||||
|
jp2_struct_t jp2_struct;
|
||||||
|
mj2_sample_t *sample; /* Sample parameters */
|
||||||
|
} mj2_tk_t; /* Track Parameters */
|
||||||
|
|
||||||
|
typedef struct { /* Movie */
|
||||||
|
unsigned int brand;
|
||||||
|
unsigned int minversion;
|
||||||
|
int num_cl;
|
||||||
|
unsigned int *cl;
|
||||||
|
unsigned int creation_time;
|
||||||
|
unsigned int modification_time;
|
||||||
|
int timescale;
|
||||||
|
unsigned int duration;
|
||||||
|
int rate;
|
||||||
|
int num_vtk;
|
||||||
|
int num_stk;
|
||||||
|
int num_htk;
|
||||||
|
int volume;
|
||||||
|
int trans_matrix[9];
|
||||||
|
int next_tk_id;
|
||||||
|
mj2_tk_t *tk; /* Track Parameters */
|
||||||
|
} mj2_movie_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int length;
|
||||||
|
int type;
|
||||||
|
int init_pos;
|
||||||
|
} mj2_box_t;
|
||||||
|
|
||||||
|
void mj2_write_jp();
|
||||||
|
|
||||||
|
void mj2_write_ftyp(mj2_movie_t * movie);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use this function to initialize a standard movie with standard values
|
||||||
|
* It has one sample per chunk
|
||||||
|
*/
|
||||||
|
int mj2_init_stdmovie(mj2_movie_t * movie);
|
||||||
|
|
||||||
|
|
||||||
|
/* int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index);
|
||||||
|
*
|
||||||
|
* Encode a MJ2 movie from a yuv file
|
||||||
|
* movie: an existing mj2_movie structure (to create a standard one, use mj2_init_stdmovie
|
||||||
|
* cp: coding parameters of j2k images
|
||||||
|
* index: index file name
|
||||||
|
*/
|
||||||
|
int mj2_encode(mj2_movie_t * movie, j2k_cp_t * cp, char *index);
|
||||||
|
|
||||||
|
|
||||||
|
/* int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
|
||||||
|
* j2k_cp_t * cp, char *outfile);
|
||||||
|
*
|
||||||
|
* Decode a MJ2 movie to a yuv file
|
||||||
|
* src: pointer to memory where frames will be stored
|
||||||
|
* movie: a mj2_movie structure
|
||||||
|
* cp: coding parameters of j2k images
|
||||||
|
* outfile: yuv file name
|
||||||
|
*/
|
||||||
|
int mj2_decode(unsigned char *src, int len, mj2_movie_t * movie,
|
||||||
|
j2k_cp_t * cp, char *outfile);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free memory used to encode and decode mj2 files
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void mj2_memory_free(mj2_movie_t * movie);
|
||||||
|
|
||||||
|
int mj2_read_struct(FILE *file, mj2_movie_t * movie);
|
||||||
|
|
||||||
|
void mj2_write_moov(mj2_movie_t * movie);
|
||||||
|
|
||||||
|
#endif
|
||||||
318
mj2/mj2_convert.c
Normal file
318
mj2/mj2_convert.c
Normal file
@@ -0,0 +1,318 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
|
#include "mj2.h"
|
||||||
|
#include <j2k.h>
|
||||||
|
#include <int.h>
|
||||||
|
|
||||||
|
/* ----------------------- */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* Count the number of frames */
|
||||||
|
/* in a YUV file */
|
||||||
|
/* */
|
||||||
|
/* ----------------------- */
|
||||||
|
|
||||||
|
int yuv_num_frames(mj2_tk_t * tk, FILE *f)
|
||||||
|
{
|
||||||
|
int numimages, frame_size;
|
||||||
|
long end_of_f;
|
||||||
|
|
||||||
|
frame_size = (int) (tk->w * tk->h * (1.0 + (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy))); /* Calculate frame size */
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
end_of_f = ftell(f); /* Calculate file size */
|
||||||
|
|
||||||
|
if (end_of_f < frame_size) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"YUV does not contains any frame of %d x %d size\n", tk->w,
|
||||||
|
tk->h);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
numimages = end_of_f / frame_size; /* Calculate number of images */
|
||||||
|
|
||||||
|
return numimages;
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// YUV to IMAGE
|
||||||
|
//
|
||||||
|
// -----------------------
|
||||||
|
|
||||||
|
int yuvtoimage(FILE *yuvfile, mj2_tk_t * tk, j2k_image_t * img,
|
||||||
|
int frame_num, int subsampling_dx, int subsampling_dy)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
int offset;
|
||||||
|
long end_of_f, position;
|
||||||
|
FILE *Compo;
|
||||||
|
|
||||||
|
offset =
|
||||||
|
(int) ((double) (frame_num * tk->w * tk->h) *
|
||||||
|
(1.0 +
|
||||||
|
1.0 * (double) 2 / (double) (tk->CbCr_subsampling_dx *
|
||||||
|
tk->CbCr_subsampling_dy)));
|
||||||
|
fseek(yuvfile, 0, SEEK_END);
|
||||||
|
end_of_f = ftell(yuvfile);
|
||||||
|
fseek(yuvfile, sizeof(unsigned char) * offset, SEEK_SET);
|
||||||
|
position = ftell(yuvfile);
|
||||||
|
if (position >= end_of_f) {
|
||||||
|
fprintf(stderr, "Cannot reach frame number %d in yuv file !!\n",
|
||||||
|
frame_num);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
img->x0 = tk->Dim[0];
|
||||||
|
img->y0 = tk->Dim[1];
|
||||||
|
img->x1 = !tk->Dim[0] ? (tk->w - 1) * subsampling_dx + 1 : tk->Dim[0] +
|
||||||
|
(tk->w - 1) * subsampling_dx + 1;
|
||||||
|
img->y1 = !tk->Dim[1] ? (tk->h - 1) * subsampling_dy + 1 : tk->Dim[1] +
|
||||||
|
(tk->h - 1) * subsampling_dy + 1;
|
||||||
|
img->numcomps = 3;
|
||||||
|
img->color_space = 3;
|
||||||
|
img->comps = (j2k_comp_t *) malloc(img->numcomps * sizeof(j2k_comp_t));
|
||||||
|
|
||||||
|
for (i = 0; i < img->numcomps; i++) {
|
||||||
|
img->comps[i].data = (int *) malloc(sizeof(int) * tk->w * tk->h);
|
||||||
|
img->comps[i].prec = 8;
|
||||||
|
img->comps[i].bpp = 8;
|
||||||
|
img->comps[i].sgnd = 0;
|
||||||
|
if (i == 0) {
|
||||||
|
img->comps[i].dx = subsampling_dx;
|
||||||
|
img->comps[i].dy = subsampling_dy;
|
||||||
|
} else {
|
||||||
|
img->comps[i].dx = subsampling_dx * tk->CbCr_subsampling_dx;
|
||||||
|
img->comps[i].dy = subsampling_dy * tk->CbCr_subsampling_dy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Compo = fopen("Compo0", "wb");
|
||||||
|
if (!Compo) {
|
||||||
|
fprintf(stderr, "Failed to open Compo0 for writing !\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < (tk->w * tk->h / (img->comps[0].dx * img->comps[0].dy))
|
||||||
|
&& !feof(yuvfile); i++) {
|
||||||
|
unsigned char y;
|
||||||
|
j = fread(&y, 1, 1, yuvfile);
|
||||||
|
fwrite(&y, 1, 1, Compo);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(Compo);
|
||||||
|
|
||||||
|
Compo = fopen("Compo1", "wb");
|
||||||
|
if (!Compo) {
|
||||||
|
fprintf(stderr, "Failed to open Compo1 for writing !\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < (tk->w * tk->h / (img->comps[1].dx * img->comps[1].dy))
|
||||||
|
&& !feof(yuvfile); i++) {
|
||||||
|
unsigned char cb;
|
||||||
|
j = fread(&cb, sizeof(unsigned char), 1, yuvfile);
|
||||||
|
fwrite(&cb, 1, 1, Compo);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(Compo);
|
||||||
|
|
||||||
|
Compo = fopen("Compo2", "wb");
|
||||||
|
if (!Compo) {
|
||||||
|
fprintf(stderr, "Failed to open Compo2 for writing !\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < (tk->w * tk->h / (img->comps[2].dx * img->comps[2].dy))
|
||||||
|
&& !feof(yuvfile); i++) {
|
||||||
|
unsigned char cr;
|
||||||
|
j = fread(&cr, sizeof(unsigned char), 1, yuvfile);
|
||||||
|
fwrite(&cr, 1, 1, Compo);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(Compo);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// IMAGE to YUV
|
||||||
|
//
|
||||||
|
// -----------------------
|
||||||
|
|
||||||
|
|
||||||
|
int imagetoyuv(j2k_image_t * img, j2k_cp_t * cp, char *outfile)
|
||||||
|
{
|
||||||
|
FILE *f;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (img->numcomps == 3) {
|
||||||
|
if (img->comps[0].dx != img->comps[1].dx / 2
|
||||||
|
|| img->comps[1].dx != img->comps[2].dx) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Error with the input image components size: cannot create yuv file)\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if (!(img->numcomps == 1)) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Error with the number of image components(must be one or three)\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
f = fopen(outfile, "a+b");
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < (img->comps[0].w * img->comps[0].h); i++) {
|
||||||
|
unsigned char y;
|
||||||
|
y = img->comps[0].data[i];
|
||||||
|
fwrite(&y, 1, 1, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (img->numcomps == 3) {
|
||||||
|
for (i = 0; i < (img->comps[1].w * img->comps[1].h); i++) {
|
||||||
|
unsigned char cb;
|
||||||
|
cb = img->comps[1].data[i];
|
||||||
|
fwrite(&cb, 1, 1, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < (img->comps[2].w * img->comps[2].h); i++) {
|
||||||
|
unsigned char cr;
|
||||||
|
cr = img->comps[2].data[i];
|
||||||
|
fwrite(&cr, 1, 1, f);
|
||||||
|
}
|
||||||
|
} else if (img->numcomps == 1) {
|
||||||
|
for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) {
|
||||||
|
unsigned char cb = 125;
|
||||||
|
fwrite(&cb, 1, 1, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (i = 0; i < (img->comps[0].w * img->comps[0].h * 0.25); i++) {
|
||||||
|
unsigned char cr = 125;
|
||||||
|
fwrite(&cr, 1, 1, f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// IMAGE to BMP
|
||||||
|
//
|
||||||
|
// -----------------------
|
||||||
|
|
||||||
|
int imagetobmp(j2k_image_t * img, j2k_cp_t * cp, char *outfile) {
|
||||||
|
int w,wr,h,hr,i,pad;
|
||||||
|
FILE *f;
|
||||||
|
|
||||||
|
if (img->numcomps == 3 && img->comps[0].dx == img->comps[1].dx
|
||||||
|
&& img->comps[1].dx == img->comps[2].dx
|
||||||
|
&& img->comps[0].dy == img->comps[1].dy
|
||||||
|
&& img->comps[1].dy == img->comps[2].dy
|
||||||
|
&& img->comps[0].prec == img->comps[1].prec
|
||||||
|
&& img->comps[1].prec == img->comps[2].prec) {
|
||||||
|
/* -->> -->> -->> -->>
|
||||||
|
|
||||||
|
24 bits color
|
||||||
|
|
||||||
|
<<-- <<-- <<-- <<-- */
|
||||||
|
|
||||||
|
f = fopen(outfile, "wb");
|
||||||
|
if (!f) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing\n", outfile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
w = img->comps[0].w;
|
||||||
|
wr = int_ceildivpow2(img->comps[0].w, img->comps[0].factor);
|
||||||
|
|
||||||
|
h = img->comps[0].h;
|
||||||
|
hr = int_ceildivpow2(img->comps[0].h, img->comps[0].factor);
|
||||||
|
|
||||||
|
fprintf(f, "BM");
|
||||||
|
|
||||||
|
/* FILE HEADER */
|
||||||
|
/* ------------- */
|
||||||
|
fprintf(f, "%c%c%c%c",
|
||||||
|
(unsigned char) (hr * wr * 3 + 3 * hr * (wr % 2) +
|
||||||
|
54) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
|
||||||
|
>> 8) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
|
||||||
|
>> 16) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2) + 54)
|
||||||
|
>> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
|
||||||
|
((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff,
|
||||||
|
((54) >> 16) & 0xff, ((54) >> 24) & 0xff);
|
||||||
|
|
||||||
|
/* INFO HEADER */
|
||||||
|
/* ------------- */
|
||||||
|
fprintf(f, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff,
|
||||||
|
((40) >> 16) & 0xff, ((40) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (unsigned char) ((wr) & 0xff),
|
||||||
|
(unsigned char) ((wr) >> 8) & 0xff,
|
||||||
|
(unsigned char) ((wr) >> 16) & 0xff,
|
||||||
|
(unsigned char) ((wr) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (unsigned char) ((hr) & 0xff),
|
||||||
|
(unsigned char) ((hr) >> 8) & 0xff,
|
||||||
|
(unsigned char) ((hr) >> 16) & 0xff,
|
||||||
|
(unsigned char) ((hr) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff);
|
||||||
|
fprintf(f, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
|
||||||
|
((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c",
|
||||||
|
(unsigned char) (3 * hr * wr +
|
||||||
|
3 * hr * (wr % 2)) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
|
||||||
|
8) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
|
||||||
|
16) & 0xff,
|
||||||
|
(unsigned char) ((hr * wr * 3 + 3 * hr * (wr % 2)) >>
|
||||||
|
24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
|
||||||
|
((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff,
|
||||||
|
((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
|
||||||
|
((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||||
|
fprintf(f, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff,
|
||||||
|
((0) >> 16) & 0xff, ((0) >> 24) & 0xff);
|
||||||
|
|
||||||
|
for (i = 0; i < wr * hr; i++) {
|
||||||
|
unsigned char R, G, B;
|
||||||
|
/* a modifier */
|
||||||
|
// R = img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
|
R = img->comps[0].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
|
// G = img->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
|
G = img->comps[1].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
|
// B = img->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
|
||||||
|
B = img->comps[2].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
|
||||||
|
fprintf(f, "%c%c%c", B, G, R);
|
||||||
|
|
||||||
|
if ((i + 1) % wr == 0) {
|
||||||
|
for (pad = (3 * wr) % 4 ? 4 - (3 * wr) % 4 : 0; pad > 0; pad--) /* ADD */
|
||||||
|
fprintf(f, "%c", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
free(img->comps[1].data);
|
||||||
|
free(img->comps[2].data);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
16
mj2/mj2_convert.h
Normal file
16
mj2/mj2_convert.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "mj2.h"
|
||||||
|
|
||||||
|
#ifndef __MJ2_CONVERT_H
|
||||||
|
#define __MJ2_CONVERT_H
|
||||||
|
|
||||||
|
int imagetoyuv(j2k_image_t * img, j2k_cp_t * cp, char *outfile);
|
||||||
|
|
||||||
|
int imagetobmp(j2k_image_t * img, j2k_cp_t * cp, char *outfile);
|
||||||
|
|
||||||
|
int yuvtoimage(FILE *yuvfile, mj2_tk_t * tk, j2k_image_t * img,
|
||||||
|
int frame_num, int subsampling_dx, int subsampling_dy);
|
||||||
|
|
||||||
|
int yuv_num_frames(mj2_tk_t * tk, FILE *f);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
130
mj2/mj2_to_frames.c
Normal file
130
mj2/mj2_to_frames.c
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include "mj2.h"
|
||||||
|
#include "mj2_convert.h"
|
||||||
|
#include <openjpeg.h>
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
jmp_buf j2k_error;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
unsigned int tnum, snum;
|
||||||
|
mj2_movie_t movie;
|
||||||
|
mj2_tk_t *track;
|
||||||
|
mj2_sample_t *sample;
|
||||||
|
unsigned char* frame_codestream;
|
||||||
|
FILE *file, *outfile;
|
||||||
|
char outfilename[50];
|
||||||
|
j2k_image_t img;
|
||||||
|
j2k_cp_t cp;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cp.layer=0;
|
||||||
|
cp.reduce=0;
|
||||||
|
|
||||||
|
if (argc != 3) {
|
||||||
|
printf("Bad syntax: Usage: MJ2_decoder inputfile.mj2 outputfile.yuv\n");
|
||||||
|
printf("Example: MJ2_decoder foreman.mj2 foreman.yuv\n");
|
||||||
|
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);
|
||||||
|
|
||||||
|
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];
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
for (snum=0; snum < track->num_samples; snum++)
|
||||||
|
{
|
||||||
|
fprintf(stdout,"Frame %d: ",snum+1);
|
||||||
|
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
|
||||||
|
|
||||||
|
if (!j2k_decode(frame_codestream, sample->sample_size-8, &img, &cp)) // Decode J2K to image
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
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, &cp, 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, &cp, outfilename)) // Convert image to YUV
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
for (i=0; i<img.numcomps; i++)
|
||||||
|
free(img.comps[i].data);
|
||||||
|
j2k_dec_release();
|
||||||
|
free(frame_codestream);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
|
fprintf(stdout, "%d frame(s) correctly extracted\n", snum);
|
||||||
|
mj2_memory_free(&movie);
|
||||||
|
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
305
mj2/mj2_to_frames.dsp
Normal file
305
mj2/mj2_to_frames.dsp
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="mj2_to_frames" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=mj2_to_frames - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "mj2_to_frames.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "mj2_to_frames.mak" CFG="mj2_to_frames - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "mj2_to_frames - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "mj2_to_frames - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_frames - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Ignore_Export_Lib 0
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_frames - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "mj2_to_frames___Win32_Debug0"
|
||||||
|
# PROP BASE Intermediate_Dir "mj2_to_frames___Win32_Debug0"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "mj2_to_frames___Win32_Debug0"
|
||||||
|
# PROP Intermediate_Dir "mj2_to_frames___Win32_Debug0"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "mj2_to_frames - Win32 Release"
|
||||||
|
# Name "mj2_to_frames - Win32 Debug"
|
||||||
|
# Begin Group "MJ2"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "MJ2 Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "MJ2 Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.c
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_frames - Win32 Release"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_frames - Win32 Debug"
|
||||||
|
|
||||||
|
# ADD CPP /I "../libopenjpeg"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.c
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_frames - Win32 Release"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_frames - Win32 Debug"
|
||||||
|
|
||||||
|
# ADD CPP /I "../libopenjpeg"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.c
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_frames - Win32 Release"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_frames - Win32 Debug"
|
||||||
|
|
||||||
|
# ADD CPP /I "../libopenjpeg"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_to_frames.c
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_frames - Win32 Release"
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_frames - Win32 Debug"
|
||||||
|
|
||||||
|
# ADD CPP /I "../libopenjpeg"
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "OpenJPEG Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ".h"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\openjpeg.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ".c"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
281
mj2/mj2_to_metadata.c
Normal file
281
mj2/mj2_to_metadata.c
Normal file
@@ -0,0 +1,281 @@
|
|||||||
|
/* mj2_to_metadata.c */
|
||||||
|
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
|
||||||
|
/* 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.
|
||||||
|
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.
|
||||||
|
Except for copyright, inclusion of the code within Open JPEG for distribution and use
|
||||||
|
can be bound by the Open JPEG open-source license and disclaimer, expressed elsewhere.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
#include "mj2.h"
|
||||||
|
#include <openjpeg.h>
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
#include "mj2_to_metadata.h"
|
||||||
|
#include <string.h>
|
||||||
|
#ifndef DONT_HAVE_GETOPT
|
||||||
|
#include <getopt.h>
|
||||||
|
#else
|
||||||
|
#include "compat/getopt.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------- */
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
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., hexidecimal) 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[]) {
|
||||||
|
|
||||||
|
FILE *file, *xmlout;
|
||||||
|
/* char xmloutname[50]; */
|
||||||
|
mj2_movie_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;
|
||||||
|
|
||||||
|
#ifndef NO_PACKETS_DECODING
|
||||||
|
fprintf(stdout,"WARNING: For best performance, define NO_PACKETS_DECODING in preprocessing.\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'f': /* Choose sample frame. 0 = none */
|
||||||
|
sscanf(optarg, "%u", &sampleframe);
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'v': /* Verification by DTD. */
|
||||||
|
stringDTD = optarg;
|
||||||
|
/* We will not insist upon last 3 chars being "dtd", since non-file
|
||||||
|
access protocol may be used. */
|
||||||
|
if(strchr(stringDTD,'"') != NULL) {
|
||||||
|
fprintf(stderr, "-D's string must not contain any embedded double-quote characters.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(stringDTD,"PUBLIC ",7) == 0 || strncmp(stringDTD,"SYSTEM ",7) == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
fprintf(stderr, "-D's string must start with \"PUBLIC \" or \"SYSTEM \"\n");
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
case 'n': /* Suppress comments */
|
||||||
|
notes = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* ----------------------------------------------------- */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = strlen(outfile);
|
||||||
|
if(outfile[0] == ' ')
|
||||||
|
{
|
||||||
|
outfile++; /* There may be a leading blank if user put space after -o */
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (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);
|
||||||
|
fclose(xmlout);
|
||||||
|
|
||||||
|
mj2_memory_free(&movie);
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
276
mj2/mj2_to_metadata.dsp
Normal file
276
mj2/mj2_to_metadata.dsp
Normal file
@@ -0,0 +1,276 @@
|
|||||||
|
# Microsoft Developer Studio Project File - Name="mj2_to_metadata" - Package Owner=<4>
|
||||||
|
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||||
|
# ** DO NOT EDIT **
|
||||||
|
|
||||||
|
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||||
|
|
||||||
|
CFG=mj2_to_metadata - Win32 Debug
|
||||||
|
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||||
|
!MESSAGE use the Export Makefile command and run
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "mj2_to_metadata.mak".
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE You can specify a configuration when running NMAKE
|
||||||
|
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE NMAKE /f "mj2_to_metadata.mak" CFG="mj2_to_metadata - Win32 Debug"
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE Possible choices for configuration are:
|
||||||
|
!MESSAGE
|
||||||
|
!MESSAGE "mj2_to_metadata - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE "mj2_to_metadata - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||||
|
!MESSAGE
|
||||||
|
|
||||||
|
# Begin Project
|
||||||
|
# PROP AllowPerConfigDependencies 0
|
||||||
|
# PROP Scc_ProjName ""
|
||||||
|
# PROP Scc_LocalPath ""
|
||||||
|
CPP=cl.exe
|
||||||
|
RSC=rc.exe
|
||||||
|
|
||||||
|
!IF "$(CFG)" == "mj2_to_metadata - Win32 Release"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 0
|
||||||
|
# PROP BASE Output_Dir "Release"
|
||||||
|
# PROP BASE Intermediate_Dir "Release"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 0
|
||||||
|
# PROP Output_Dir "Release"
|
||||||
|
# PROP Intermediate_Dir "Release"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||||
|
# ADD CPP /nologo /W3 /GX /O2 /I "../libopenjpeg" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D "DONT_HAVE_GETOPT" /YX /FD /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "NDEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "NDEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||||
|
|
||||||
|
!ELSEIF "$(CFG)" == "mj2_to_metadata - Win32 Debug"
|
||||||
|
|
||||||
|
# PROP BASE Use_MFC 0
|
||||||
|
# PROP BASE Use_Debug_Libraries 1
|
||||||
|
# PROP BASE Output_Dir "mj2_to_metadata___Win32_Debug0"
|
||||||
|
# PROP BASE Intermediate_Dir "mj2_to_metadata___Win32_Debug0"
|
||||||
|
# PROP BASE Target_Dir ""
|
||||||
|
# PROP Use_MFC 0
|
||||||
|
# PROP Use_Debug_Libraries 1
|
||||||
|
# PROP Output_Dir "mj2_to_metadata___Win32_Debug0"
|
||||||
|
# PROP Intermediate_Dir "mj2_to_metadata___Win32_Debug0"
|
||||||
|
# PROP Target_Dir ""
|
||||||
|
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||||
|
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../libopenjpeg" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "DONT_HAVE_GETOPT" /FR /YX /FD /GZ /c
|
||||||
|
# ADD BASE RSC /l 0x809 /d "_DEBUG"
|
||||||
|
# ADD RSC /l 0x809 /d "_DEBUG"
|
||||||
|
BSC32=bscmake.exe
|
||||||
|
# ADD BASE BSC32 /nologo
|
||||||
|
# ADD BSC32 /nologo
|
||||||
|
LINK32=link.exe
|
||||||
|
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||||
|
|
||||||
|
!ENDIF
|
||||||
|
|
||||||
|
# Begin Target
|
||||||
|
|
||||||
|
# Name "mj2_to_metadata - Win32 Release"
|
||||||
|
# Name "mj2_to_metadata - Win32 Debug"
|
||||||
|
# Begin Group "MJ2"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "MJ2 Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\meta_out.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "MJ2 Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\compat\getopt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\meta_out.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_convert.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\mj2_to_metadata.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG"
|
||||||
|
|
||||||
|
# PROP Default_Filter ""
|
||||||
|
# Begin Group "OpenJPEG Header Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ".h"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\openjpeg.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.h
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.h
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# Begin Group "OpenJPEG Source Files"
|
||||||
|
|
||||||
|
# PROP Default_Filter ".c"
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\bio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\cio.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\dwt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\fix.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\int.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\j2k.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jp2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\jpt.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mct.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\mqc.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\pi.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\raw.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t1.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\t2.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tcd.c
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=..\libopenjpeg\tgt.c
|
||||||
|
# End Source File
|
||||||
|
# End Group
|
||||||
|
# End Group
|
||||||
|
# End Target
|
||||||
|
# End Project
|
||||||
425
mj2/mj2_to_metadata.dtd
Normal file
425
mj2/mj2_to_metadata.dtd
Normal file
@@ -0,0 +1,425 @@
|
|||||||
|
<!--
|
||||||
|
Preliminary DTD for Open JPEG "mj2_to_metadata" function.
|
||||||
|
Last revised: April 20, 2005
|
||||||
|
Author: Glenn Pearson, at U.S. National Library of Medicine.
|
||||||
|
See mj2_to_metadata.c regarding copyright, license, disclaimer status.
|
||||||
|
|
||||||
|
While the vocabulary of this DTD is based on the relevant portions of the
|
||||||
|
ISO/IEC JPEG 200 standard, the detailed representation is the author's own.
|
||||||
|
It is neither an ISO/IEC nor NLM official or consensus representation.
|
||||||
|
Furthermore, it deviates from a pure representation of the ISO/IEC standard
|
||||||
|
in these aspects:
|
||||||
|
|
||||||
|
- it is incomplete in a number of ways (which to some extent may be
|
||||||
|
addressed over time);
|
||||||
|
- it has extensions for "derived" data and "statistics";
|
||||||
|
- it is more flexible. That is, some elements are marked as optional
|
||||||
|
not because they are optional in an MJ2 file, but because reporting
|
||||||
|
of them is optional based on current or projected mj2_to_metadata
|
||||||
|
command-line flags.
|
||||||
|
-->
|
||||||
|
<!ELEMENT MJ2_File (JP2?, FileType?, MovieBox?)>
|
||||||
|
<!ELEMENT JP2 EMPTY>
|
||||||
|
<!ATTLIST JP2 BoxType CDATA #FIXED "jP[space][space]">
|
||||||
|
<!ATTLIST JP2 Signature CDATA #FIXED "0x0d0a870a">
|
||||||
|
<!ELEMENT FileType (Brand, MinorVersion, CompatibilityList)>
|
||||||
|
<!ATTLIST FileType BoxType CDATA #FIXED "ftyp">
|
||||||
|
<!ELEMENT Brand (#PCDATA)> <!-- 4 characters max -->
|
||||||
|
<!ELEMENT MinorVersion (#PCDATA)> <!-- 4 chararcters max -->
|
||||||
|
<!ELEMENT CompatibilityList (CompatibleBrand)*>
|
||||||
|
<!ATTLIST CompatibilityList Count CDATA #REQUIRED> <!-- Count >= 0 -->
|
||||||
|
<!ELEMENT CompatibleBrand (#PCDATA)> <!-- 4 characters max -->
|
||||||
|
<!ELEMENT MovieBox (MovieHeader, Statistics?, Track*)>
|
||||||
|
<!ATTLIST MovieBox BoxType CDATA #FIXED "moov">
|
||||||
|
<!ELEMENT MovieHeader (CreationTime, ModificationTime, Timescale, Rate, Duration, Volume, TransformationMatrix)>
|
||||||
|
<!ATTLIST MovieHeader BoxType CDATA #FIXED "mvhd">
|
||||||
|
<!ELEMENT CreationTime (InSeconds?,AsLocalTime?)>
|
||||||
|
<!ELEMENT InSeconds (#PCDATA)>
|
||||||
|
<!ELEMENT AsLocalTime (#PCDATA)>
|
||||||
|
<!ELEMENT ModificationTime (InSeconds?,AsLocalTime?)>
|
||||||
|
<!ELEMENT Timescale (#PCDATA)> <!-- Timescale defines time units in one second -->
|
||||||
|
<!ELEMENT Rate (AsHex | (AsHex, AsDecimal) | AsDecimal)> <!-- Decimal is Approximation; Optional on input. -->
|
||||||
|
<!ELEMENT AsHex (#PCDATA)>
|
||||||
|
<!ELEMENT AsDecimal (#PCDATA)>
|
||||||
|
<!ELEMENT Duration (InTimeUnits | (InTimeUnits, InSeconds) | InSeconds)> <!-- InSeconds Optional on input. -->
|
||||||
|
<!ELEMENT InTimeUnits (#PCDATA)>
|
||||||
|
<!ELEMENT Volume (AsHex | (AsHex, AsDecimal) | AsDecimal)> <!-- hex default = 0x0100 -->
|
||||||
|
<!-- Fixed 8.8 value of audio volume. Full, normal value is 1.0 (0x0100) -->
|
||||||
|
<!ELEMENT TransformationMatrix (TMa,TMb,TMu,TMc,TMd,TMv,TMx,TMy,TMw)> <!-- for video -->
|
||||||
|
<!-- 3 x 3 Video Transformation Matrix {a,b,u,c,d,v,x,y,w}. Required: u=0, v=0, w=1 -->
|
||||||
|
<!-- Maps decompressed point (p,q) to rendered point (ap + cq + x, bp + dq + y) -->
|
||||||
|
<!-- Stored as Fixed Point Hex: all are 16.16, except u,v,w are 2.30 -->
|
||||||
|
<!-- Unity = 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 -->
|
||||||
|
<!ELEMENT TMa (#PCDATA)>
|
||||||
|
<!ELEMENT TMb (#PCDATA)>
|
||||||
|
<!ELEMENT TMu (#PCDATA)> <!--Always "0x00000000" -->
|
||||||
|
<!ELEMENT TMc (#PCDATA)>
|
||||||
|
<!ELEMENT TMd (#PCDATA)>
|
||||||
|
<!ELEMENT TMv (#PCDATA)> <!--Always "0x00000000" -->
|
||||||
|
<!ELEMENT TMx (#PCDATA)>
|
||||||
|
<!ELEMENT TMy (#PCDATA)>
|
||||||
|
<!ELEMENT TMw (#PCDATA)> <!--Always "0x40000000" -->
|
||||||
|
|
||||||
|
<!ELEMENT Statistics (TracksFound)>
|
||||||
|
<!ELEMENT TracksFound (Video,Audio,Hint)>
|
||||||
|
<!ELEMENT Video (#PCDATA)>
|
||||||
|
<!ELEMENT Audio (#PCDATA)>
|
||||||
|
<!ELEMENT Hint (#PCDATA)>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- For now, output info on at most one video track -->
|
||||||
|
|
||||||
|
|
||||||
|
<!ELEMENT Track (TrackHeader, TrackReferenceContainer?, EditListContainer?, Media, JP2_Frame?)> <!-- JP2_Frame is mj2_to_metadata extension -->
|
||||||
|
<!ATTLIST Track BoxType CDATA #FIXED "trak">
|
||||||
|
<!ATTLIST Track Instance CDATA #REQUIRED>
|
||||||
|
<!ELEMENT TrackHeader (TrackID, TrackLayer?, Volume?, TransformationMatrix?, Width?, Height?)>
|
||||||
|
<!ATTLIST TrackHeader BoxType CDATA #FIXED "tkhd">
|
||||||
|
<!-- Not shown here: CreationTime, ModificationTime, Duration. -->
|
||||||
|
<!-- These 3 fields are reported under MediaHeader below. When reading these 3, -->
|
||||||
|
<!-- m2j_to_metadata currently doesn't distinguish between TrackHeader and MediaHeader source. -->
|
||||||
|
<!-- If both found, value read from MediaHeader is used. -->
|
||||||
|
<!ELEMENT TrackID (#PCDATA)>
|
||||||
|
<!ELEMENT TrackLayer (#PCDATA)> <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->
|
||||||
|
<!-- "Volume" element described above; here it is for particular audio track. Full, normal (default = 0x0100) -->
|
||||||
|
<!-- "TransformationMatrix" element described above; matrix here is applied before MovieHeader one. -->
|
||||||
|
<!ELEMENT Width (AsHex | (AsHex, AsDecimal) | AsDecimal)>
|
||||||
|
<!ELEMENT Height (AsHex | (AsHex, AsDecimal) | AsDecimal)>
|
||||||
|
<!-- AsHex, AsDecimal already defined above -->
|
||||||
|
<!-- Width and Height are for the presentation; frames will be scaled to this -->
|
||||||
|
<!-- /TrackHeader -->
|
||||||
|
<!ELEMENT TrackReferenceContainer ANY> <!-- TO DO: TrackReferenceContainer 'tref' just used in hint track -->
|
||||||
|
<!ELEMENT EditListContainer ANY> <!-- TO DO: EditListContainer 'edts', contains EditList 'elst' with media-time, segment-duration, media-rate -->
|
||||||
|
<!ELEMENT Media (MediaHeader, HandlerReference,MediaInfoContainer)>
|
||||||
|
<!ATTLIST Media BoxType CDATA #FIXED "mdia">
|
||||||
|
<!ELEMENT MediaHeader (CreationTime,ModificationTime,Timescale,Duration,Language)>
|
||||||
|
<!ATTLIST MediaHeader BoxType CDATA #FIXED "mdhd">
|
||||||
|
<!-- Elements already defined above: CreationTime, ModificationTime, Timescale, Duration -->
|
||||||
|
<!ELEMENT Language (#PCDATA)> <!-- 3 chars max. There's an enumeration available -->
|
||||||
|
<!ELEMENT HandlerReference (HandlerType)>
|
||||||
|
<!ATTLIST HandlerReference BoxType CDATA #FIXED "hdlr">
|
||||||
|
<!ELEMENT HandlerType (#PCDATA)>
|
||||||
|
<!ATTLIST HandlerType Code ( vide | soun | hint ) "vide">
|
||||||
|
|
||||||
|
<!-- make the media headers multiple? -->
|
||||||
|
<!ELEMENT MediaInfoContainer ((VideoMediaHeader | SoundMediaHeader | HintMediaHeader), DataInfo, SampleTable)>
|
||||||
|
<!ATTLIST MediaInfoContainer BoxType CDATA #FIXED "minf">
|
||||||
|
<!ELEMENT VideoMediaHeader (GraphicsMode, Opcolor)>
|
||||||
|
<!ATTLIST VideoMediaHeader BoxType CDATA #FIXED "vmhd">
|
||||||
|
<!ELEMENT GraphicsMode (#PCDATA)>
|
||||||
|
<!-- Enumerated values of graphics mode: -->
|
||||||
|
<!-- 0x00 = copy (over existing image); -->
|
||||||
|
<!-- 0x24 = transparent; 'blue-screen' this image using opcolor; -->
|
||||||
|
<!-- 0x100 = alpha; alpha-blend this image -->
|
||||||
|
<!-- 0x101 = whitealpha; alpha-blend this image, which has been blended with white; -->
|
||||||
|
<!-- 0x102 = blackalpha; alpha-blend this image, which has been blended with black. -->
|
||||||
|
<!ELEMENT Opcolor (Red,Green,Blue)>
|
||||||
|
<!ELEMENT Red (#PCDATA)>
|
||||||
|
<!ELEMENT Green (#PCDATA)>
|
||||||
|
<!ELEMENT Blue (#PCDATA)>
|
||||||
|
<!ELEMENT SoundMediaHeader (Balance)>
|
||||||
|
<!ATTLIST SoundMediaHeader BoxType CDATA #FIXED "smhd">
|
||||||
|
<!ELEMENT Balance (#PCDATA)>
|
||||||
|
<!-- Fixed Point 8.8, fixes mono track in stereo space. -->
|
||||||
|
<!-- 0.0 = center, -1.0 = full left, 1.0 = full right -->
|
||||||
|
<!ELEMENT HintMediaHeader (MaxPDU_Size, AvgPDU_Size, MaxBitRate, AvgBitRate, SlidingAvgBitRate)>
|
||||||
|
<!ATTLIST HintMediaHeader BoxType CDATA #FIXED "hmhd">
|
||||||
|
<!ELEMENT MaxPDU_Size (#PCDATA)>
|
||||||
|
<!-- Size in bytes of largest PDU in this hint stream. -->
|
||||||
|
<!ELEMENT AvgPDU_Size (#PCDATA)>
|
||||||
|
<!-- Average size in bytes of a PDU over the entire presentation. -->
|
||||||
|
<!ELEMENT MaxBitRate (#PCDATA)>
|
||||||
|
<!-- Maximum rate in bits per second over any window of 1 second. -->
|
||||||
|
<!ELEMENT AvgBitRate (#PCDATA)>
|
||||||
|
<!-- Averate rate in bits per second over the entire presentation. -->
|
||||||
|
<!ELEMENT SlidingAvgBit (#PCDATA)>
|
||||||
|
<!-- Maximum rate in bits per second over any window of one minute. -->
|
||||||
|
|
||||||
|
<!ELEMENT DataInfo (DataReference)>
|
||||||
|
<!ATTLIST DataInfo BoxType CDATA #FIXED "dinf">
|
||||||
|
<!ELEMENT DataReference (DataEntryUrlBox | DataEntryUrnBox )*>
|
||||||
|
<!ATTLIST DataReference BoxType CDATA #FIXED "dref">
|
||||||
|
<!ATTLIST DataReference URL_Count CDATA #REQUIRED>
|
||||||
|
<!ATTLIST DataReference URN_Count CDATA #REQUIRED> <!-- table w. flags, URLs, URNs -->
|
||||||
|
<!-- // Data structure does not distinguish between single URL, single URN, or DREF table or URLs & URNs.
|
||||||
|
// We could infer those, but for now just present everything as a DREF table.
|
||||||
|
-->
|
||||||
|
<!-- No entries here mean that file is self-contained, as required by Simple Profile. -->
|
||||||
|
|
||||||
|
<!ELEMENT DataEntryUrlBox (Location)>
|
||||||
|
<!ATTLIST DataEntryUrlBox BoxType CDATA #FIXED "url[space]"> <!-- table w. flags, URLs, URNs -->
|
||||||
|
<!-- Only the first 16 bytes of URL location are recorded in mj2_to_metadata data structure. -->
|
||||||
|
<!ELEMENT DataEntryUrnBox (Name, Location?)>
|
||||||
|
<!ATTLIST DataEntryUrnBox BoxType CDATA #FIXED "urn[space]\">
|
||||||
|
<!-- Only the first 16 bytes each of URN name and optional location are recorded in mj2_to_metadata data structure. -->
|
||||||
|
|
||||||
|
<!ELEMENT SampleTable (VisualSampleEntry,TimeToSample,SampleToChunk,SampleSize,ChunkOffset)> <!-- structure doesn't do non-visual sample entry yet -->
|
||||||
|
<!ATTLIST SampleTable BoxType CDATA #FIXED "stbl"> <!-- to add: entry count -->
|
||||||
|
<!-- Next are instances of generic SampleDescription BoxType=\"stsd\" -->
|
||||||
|
|
||||||
|
<!-- There could be multiple instances of this, but "entry_count" is just a local at read-time.
|
||||||
|
And it's used wrong, too, as count of just visual type, when it's really all 3 types.
|
||||||
|
This is referred to as "smj2" within mj2.c -->
|
||||||
|
<!ELEMENT VisualSampleEntry (WidthAsInteger, HeightAsInteger, HorizontalRes, VerticalRes, CompressorName, Depth, JP2Header?, FieldCoding?, MJP2_Profile?, MJP2_Prefix?, MJP2_SubSampling?, MJP2_OriginalFormat?)>
|
||||||
|
<!ATTLIST VisualSampleEntry BoxType CDATA #FIXED "mjp2">
|
||||||
|
<!-- If multiple instances of this, only first is shown here. -->
|
||||||
|
<!ELEMENT WidthAsInteger (#PCDATA)>
|
||||||
|
<!ELEMENT HeightAsInteger (#PCDATA)>
|
||||||
|
<!ELEMENT HorizontalRes (AsHex | (AsHex, AsDecimal) | AsDecimal)>
|
||||||
|
<!ELEMENT VerticalRes (AsHex | (AsHex, AsDecimal) | AsDecimal)>
|
||||||
|
<!-- Typical value for both resolution is 72 (0x00480000) -->
|
||||||
|
<!ELEMENT CompressorName (#PCDATA)>
|
||||||
|
<!-- Compressor name for debugging. Standard restricts max length to 31 bytes. -->
|
||||||
|
<!-- Usually blank or \"Motion JPEG2000\" -->
|
||||||
|
<!ELEMENT Depth (#PCDATA)>
|
||||||
|
<!-- Depth is: -->
|
||||||
|
<!-- 0x20: alpha channels present (color or grayscale) -->
|
||||||
|
<!-- 0x28: grayscale without alpha -->
|
||||||
|
<!-- 0x18: color without alpha -->
|
||||||
|
|
||||||
|
<!-- TODO somewhere: tk->jp2_struct.numcomps -->
|
||||||
|
<!ELEMENT JP2Header (ImageHeader, ColourSpecification)>
|
||||||
|
<!ATTLIST JP2Header BoxType CDATA #FIXED "jp2h">
|
||||||
|
<!ELEMENT ImageHeader (HEIGHT, WIDTH, NC, BPC, C, UnkC, IPR)>
|
||||||
|
<!ATTLIST ImageHeader BoxType CDATA #FIXED "ihdr">
|
||||||
|
<!ELEMENT HEIGHT (#PCDATA)> <!-- If 2 fields/frame, total deinterlaced height -->
|
||||||
|
<!ELEMENT WIDTH (#PCDATA)>
|
||||||
|
<!ELEMENT NC (#PCDATA)> <!-- number of components -->
|
||||||
|
<!ELEMENT BPC (AsHex | (AsHex,BitsPerPixel,Signed) | (BitsPerPixel,Signed))>
|
||||||
|
<!ELEMENT BitsPerPixel (#PCDATA)>
|
||||||
|
<!ELEMENT Signed (#PCDATA)>
|
||||||
|
<!ELEMENT C (#PCDATA)> <!-- Compression type. Only "7" defined -->
|
||||||
|
<!ELEMENT UnkC (#PCDATA)> <!-- Colourspace Unknown. 1 = unknown, 0 = known -->
|
||||||
|
<!ELEMENT IPR (#PCDATA)> <!-- 1 = frame has Intellectual Prop. box; otherwise 0 -->
|
||||||
|
<!ELEMENT ColourSpecification (METH, PREC, APPROX, EnumCS)>
|
||||||
|
<!ATTLIST ColourSpecification BoxType CDATA #FIXED "colr">
|
||||||
|
<!ELEMENT METH (#PCDATA)> <!-- 1 = EnumCS field; 2 = PROFILE field (not yet generated) -->
|
||||||
|
<!ELEMENT PREC (#PCDATA)> <!-- precedence must be 0 so far -->
|
||||||
|
<!ELEMENT APPROX (#PCDATA)> <!-- colourspace approximation must be 0 so far -->
|
||||||
|
<!ELEMENT EnumCS (#PCDATA)> <!-- Valid enumerated MJ2 colourspaces: 16 (sRGB), 17 (grey sRGB), 18 (YCC) -->
|
||||||
|
|
||||||
|
<!-- Following subboxes are optional -->
|
||||||
|
<!ELEMENT FieldCoding (FieldCount, FieldOrder)>
|
||||||
|
<!ATTLIST FieldCoding BoxType CDATA #FIXED "fiel">
|
||||||
|
<!ELEMENT FieldCount (#PCDATA)>
|
||||||
|
<!-- Must be either 1 or 2 -->
|
||||||
|
<!ELEMENT FieldOrder (#PCDATA)>
|
||||||
|
<!-- When FieldCount=2, FieldOrder means: -->
|
||||||
|
<!-- 0: Field coding unknown -->
|
||||||
|
<!-- 1: Field with topmost line is stored first in sample; fields are in temporal order -->
|
||||||
|
<!-- 6: Field with topmost line is stored second in sample; fields are in temporal order -->
|
||||||
|
<!-- Defaults: FieldCount=1, FieldOrder=0 if FieldCoding box not present -->
|
||||||
|
<!-- Current implementation doesn't retain whether box was actually present. -->
|
||||||
|
|
||||||
|
<!ELEMENT MJP2_Profile (CompatibleBrand*)>
|
||||||
|
<!ATTLIST MJP2_Profile BoxType CDATA #FIXED "jp2p">
|
||||||
|
<!ATTLIST MJP2_Profile Count CDATA #REQUIRED>
|
||||||
|
|
||||||
|
<!ELEMENT MJP2_Prefix (Data*)>
|
||||||
|
<!ATTLIST MJP2_Prefix BoxType CDATA #FIXED "jp2x">
|
||||||
|
<!ATTLIST MJP2_Prefix Count CDATA #REQUIRED>
|
||||||
|
<!-- We'll probably need better formatting than this -->
|
||||||
|
<!ELEMENT Data (#PCDATA)> <!-- Multiple. Each entry is single byte -->
|
||||||
|
|
||||||
|
<!ELEMENT MJP2_SubSampling (HorizontalSub, VerticalSub, HorizontalOffset, VerticalOffset)>
|
||||||
|
<!ATTLIST MJP2_SubSampling BoxType CDATA #FIXED "jsub">
|
||||||
|
<!-- These values are all 1 byte -->
|
||||||
|
<!-- Typical subsample value is 2 for 4:2:0 -->
|
||||||
|
<!ELEMENT HorizontalSub (#PCDATA)>
|
||||||
|
<!ELEMENT VerticalSub (#PCDATA)>
|
||||||
|
<!ELEMENT HorizontalOffset (#PCDATA)>
|
||||||
|
<!ELEMENT VerticalOffset (#PCDATA)>
|
||||||
|
|
||||||
|
<!ELEMENT MJP2_OriginalFormat (OriginalFieldCount, OriginalFieldOrder)>
|
||||||
|
<!ATTLIST MJP2_OriginalFormat BoxType CDATA #FIXED "orfo"> <!-- Part III Appx. 2 -->
|
||||||
|
<!ELEMENT OriginalFieldCount (#PCDATA)>
|
||||||
|
<!-- In original material before encoding. Must be either 1 or 2 -->
|
||||||
|
<!ELEMENT OriginalFieldOrder (#PCDATA)>
|
||||||
|
<!-- When FieldCount=2, FieldOrder means: -->
|
||||||
|
<!-- 0: Field coding unknown -->
|
||||||
|
<!-- 11: Topmost line came from the earlier field; -->
|
||||||
|
<!-- 16: Topmost line came form the later field. -->
|
||||||
|
<!-- Defaults: FieldCount=1, FieldOrder=0 if FieldCoding box not present -->
|
||||||
|
<!-- Current implementation doesn't retain whether box was actually present. -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- mj2_to_metadata's data structure doesn't record Audio and Hint sample data currently. -->
|
||||||
|
|
||||||
|
<!-- Within SampleTable: -->
|
||||||
|
<!ELEMENT TimeToSample (SampleStatistics, SampleEntries)>
|
||||||
|
<!ATTLIST TimeToSample BoxType CDATA #FIXED "stts">
|
||||||
|
<!ELEMENT SampleStatistics (TotalSamples)> <!-- Not part of standard -->
|
||||||
|
<!ELEMENT TotalSamples (#PCDATA)>
|
||||||
|
<!-- For video, gives the total frames in the track, by summing all entries in the Sample Table -->
|
||||||
|
|
||||||
|
<!ELEMENT SampleEntries (Table*)>
|
||||||
|
<!ATTLIST SampleEntries EntryCount CDATA #REQUIRED>
|
||||||
|
<!ELEMENT Table EMPTY> <!-- Multiple. Attributes have values -->
|
||||||
|
<!ATTLIST Table Entry CDATA #REQUIRED>
|
||||||
|
<!ATTLIST Table SampleCount CDATA #REQUIRED>
|
||||||
|
<!ATTLIST Table SampleDelta CDATA #REQUIRED>
|
||||||
|
|
||||||
|
<!-- Within SampleTable: -->
|
||||||
|
<!ELEMENT SampleToChunk (FirstChunk,SamplesPerChunk,SampleDescrIndex)>
|
||||||
|
<!ATTLIST SampleToChunk BoxType CDATA #FIXED "stsc">
|
||||||
|
<!ATTLIST SampleToChunk Count CDATA #REQUIRED>
|
||||||
|
<!ELEMENT FirstChunk (#PCDATA)>
|
||||||
|
<!ELEMENT SamplesPerChunk (#PCDATA)>
|
||||||
|
<!ELEMENT SampleDescrIndex (#PCDATA)>
|
||||||
|
<!ELEMENT SampleSize (Sample_Size,Sample_Count,EntrySize*)>
|
||||||
|
<!ATTLIST SampleSize BoxType CDATA #FIXED "stsz">
|
||||||
|
<!ELEMENT Sample_Size (#PCDATA)>
|
||||||
|
<!ELEMENT Sample_Count (#PCDATA)>
|
||||||
|
<!ELEMENT EntrySize (#PCDATA)> <!-- appears multiply, but only with mj2_to_metadata option -t -->
|
||||||
|
<!ATTLIST EntrySize Num CDATA #REQUIRED>
|
||||||
|
<!ELEMENT ChunkOffset (EntryCount, Chunk_Offset*)>
|
||||||
|
<!ATTLIST ChunkOffset BoxType CDATA #FIXED "stco">
|
||||||
|
<!ELEMENT EntryCount (#PCDATA)>
|
||||||
|
<!ELEMENT Chunk_Offset (#PCDATA)> <!-- appears multiply, but only with mj2_to_metadata option -t -->
|
||||||
|
<!ATTLIST Chunk_Offset Num CDATA #REQUIRED>
|
||||||
|
<!-- </SampleTable> </MediaInfoContainer> </Media> -->
|
||||||
|
|
||||||
|
<!-- TO DO: optional UserData 'udat', can contain multiple Copyright 'cprt' -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Optional, and only for Visual Track: given individual frame -->
|
||||||
|
<!ELEMENT JP2_Frame (MainHeader, TilePartHeaders)>
|
||||||
|
<!ATTLIST JP2_Frame Num CDATA #REQUIRED>
|
||||||
|
<!ELEMENT MainHeader (StartOfCodestream,ImageAndFileSize,CodingStyleDefault,QuantizationDefault,QuantizationComponent*,RegionOfInterest?,ProgressionOrderChange*)>
|
||||||
|
<!ELEMENT StartOfCodestream EMPTY>
|
||||||
|
<!ATTLIST StartOfCodestream Marker CDATA #FIXED "SOC">
|
||||||
|
<!ELEMENT ImageAndFileSize (Xsiz,Ysiz,XOsiz,YOsiz,XTsiz,YTsiz,XTOsiz,YTOsiz,Csiz,Component+)>
|
||||||
|
<!ATTLIST ImageAndFileSize Marker CDATA #FIXED "SIZ">
|
||||||
|
<!ELEMENT Xsiz (#PCDATA)>
|
||||||
|
<!ELEMENT Ysiz (#PCDATA)> <!-- Xsiz, Ysiz is the size of the reference grid. -->
|
||||||
|
<!ELEMENT XOsiz (#PCDATA)>
|
||||||
|
<!ELEMENT YOsiz (#PCDATA)> <!-- XOsiz, YOsiz are offsets from grid origin to image origin. -->
|
||||||
|
<!ELEMENT XTsiz (#PCDATA)>
|
||||||
|
<!ELEMENT YTsiz (#PCDATA)> <!-- XTsiz, YTsiz is the size of one tile with respect to the grid. -->
|
||||||
|
<!ELEMENT XTOsiz (#PCDATA)>
|
||||||
|
<!ELEMENT YTOsiz (#PCDATA)> <!-- XTOsiz, YTOsiz are offsets from grid origin to first tile origin. -->
|
||||||
|
<!ELEMENT Csiz (#PCDATA)> <!-- Csiz is the number of components in the image. -->
|
||||||
|
<!-- For image components next -->
|
||||||
|
<!ELEMENT Component (Ssiz,XRsiz,YRsiz,WidthOfData,HeightOfData)>
|
||||||
|
<!ATTLIST Component Num CDATA #REQUIRED>
|
||||||
|
<!ELEMENT Ssiz (AsHex | (AsHex,Signed,PrecisionInBits) | (Signed,PrecisionInBits))>
|
||||||
|
<!-- Signed already defined -->
|
||||||
|
<!ELEMENT PrecisionInBits (#PCDATA)> <!-- Bits per pixel (bpp) or pixel depth. -->
|
||||||
|
<!ELEMENT XRsiz (#PCDATA)>
|
||||||
|
<!ELEMENT YRsiz (#PCDATA)> <!-- XRsiz, YRsiz denote pixel-sample-spacing on the grid, per Part I Annex B. -->
|
||||||
|
<!ELEMENT WidthOfData (#PCDATA)>
|
||||||
|
<!ELEMENT HeightOfData (#PCDATA)> <!-- WidthOfData and HeightOfData are calculated values, e.g.: w = roundup((Xsiz - XOsiz)/ XRsiz) -->
|
||||||
|
<!-- -->
|
||||||
|
<!ELEMENT CodingStyleDefault (Scod,SGcod,SPcod)>
|
||||||
|
<!ATTLIST CodingStyleDefault Marker CDATA #FIXED "COD">
|
||||||
|
<!ELEMENT Scod (#PCDATA)>
|
||||||
|
<!-- For Scod, specific bits mean (where bit 0 is lowest or rightmost): -->
|
||||||
|
<!-- bit 0: Defines entropy coder precincts -->
|
||||||
|
<!-- 0 = (PPx=15, PPy=15); 1 = precincts defined below. -->
|
||||||
|
<!-- bit 1: 1 = SOP marker may be used; 0 = not. -->
|
||||||
|
<!-- bit 2: 1 = EPH marker may be used; 0 = not. -->
|
||||||
|
<!ELEMENT SGcod (ProgressionOrder,NumberOfLayers,MultipleComponentTransformation)>
|
||||||
|
<!ELEMENT ProgressionOrder (#PCDATA)>
|
||||||
|
<!-- Defined Progression Order Values are: -->
|
||||||
|
<!-- 0 = LRCP; 1 = RLCP; 2 = RPCL; 3 = PCRL; 4 = CPRL -->
|
||||||
|
<!-- where L = "layer", R = "resolution level", C = "component", P = "position". -->
|
||||||
|
<!ELEMENT NumberOfLayers (#PCDATA)>
|
||||||
|
<!ELEMENT MultipleComponentTransformation (#PCDATA)>
|
||||||
|
<!-- For MCT, 0 = none, 1 = transform first 3 components for efficiency, per Part I Annex G -->
|
||||||
|
<!ELEMENT SPcod (NumberOfDecompositionLevels,CodeblockWidth,CodeblockHeight,CodeblockStyle,Transformation)>
|
||||||
|
<!ELEMENT NumberOfDecompositionLevels (#PCDATA)>
|
||||||
|
<!ELEMENT CodeblockWidth (#PCDATA)> <!-- CBW and CBH are non-negative, and summed cannot exceed 8 -->
|
||||||
|
<!ELEMENT CodeblockHeight (#PCDATA)> <!-- Codeblock dimension is 2^(value + 2) -->
|
||||||
|
<!ELEMENT CodeblockStyle (#PCDATA)>
|
||||||
|
<!-- For CodeblockStyle, bits mean (with value 1=feature on, 0=off): -->
|
||||||
|
<!-- bit 0: Selective arithmetic coding bypass. -->
|
||||||
|
<!-- bit 1: Reset context probabilities on coding pass boundaries. -->
|
||||||
|
<!-- bit 2: Termination on each coding pass. -->
|
||||||
|
<!-- bit 3: Vertically causal context. -->
|
||||||
|
<!-- bit 4: Predictable termination. -->
|
||||||
|
<!-- bit 5: Segmentation symbols are used. -->
|
||||||
|
<!ELEMENT Transformation (#PCDATA)> <!-- For Transformation, 0="9-7 irreversible filter", 1="5-3 reversible filter" -->
|
||||||
|
<!-- mj2_to_metadata implementation always reports component[0] as using default COD, -->
|
||||||
|
<!-- and any other component, with main-header style values different from [0], as COC. -->
|
||||||
|
<!ELEMENT QuantizationDefault (Sqcd,SPqcd)>
|
||||||
|
<!ATTLIST QuantizationDefault Marker CDATA #FIXED "QCD">
|
||||||
|
<!ELEMENT Sqcd (AsHex | (AsHex,QuantizationStyle,NumberOfGuardBits) | (QuantizationStyle,NumberOfGuardBits))>
|
||||||
|
<!ELEMENT QuantizationStyle (#PCDATA)> <!-- Default quantization style for all components. -->
|
||||||
|
<!-- Quantization style (in Sqcd's low 5 bits) may be: -->
|
||||||
|
<!-- 0 = No quantization. SPqcd size = 8 bits-->
|
||||||
|
<!-- 1 = Scalar derived (values signaled for N(L)LL subband only). Use Eq. E.5. SPqcd size = 16. -->
|
||||||
|
<!-- 2 = Scalar expounded (values signaled for each subband). SPqcd size = 16. -->
|
||||||
|
<!ELEMENT NumberOfGuardBits (#PCDATA)> <!-- 0-7 guard bits allowed (stored in Sqcd's high 3 bits) -->
|
||||||
|
<!ELEMENT SPqcd (ReversibleStepSizeValue | QuantizationStepSizeValues )> <!-- TO DO: Irreversible choices -->
|
||||||
|
<!ELEMENT ReversibleStepSizeValue (DynamicRangeExponent+)>
|
||||||
|
<!-- Current mj2_to_metadata implementation dumps entire internal table, -->
|
||||||
|
<!-- until an exponent with zero value is reached. -->
|
||||||
|
<!-- Exponent epsilon(b) of reversible dynamic range. -->
|
||||||
|
<!-- Hex value is as stored, in high-order 5 bits. -->
|
||||||
|
<!ELEMENT DynamicRangeExponent (AsHex | (AsHex, AsDecimal) | AsDecimal)>
|
||||||
|
<!ATTLIST DynamicRangeExponent Subband CDATA #REQUIRED>
|
||||||
|
<!ELEMENT QuantizationStepSizeValues (QuantizationValues+, CalculatedExponent*)> <!-- Calculated exponents iff only subband 0 reported -->
|
||||||
|
<!ELEMENT QuantizationValues (AsHex | (AsHex,Exponent,Mantissa) | (Exponent,Mantissa))>
|
||||||
|
<!ATTLIST QuantizationValues Subband CDATA #REQUIRED>
|
||||||
|
<!ELEMENT Exponent (#PCDATA)>
|
||||||
|
<!ELEMENT Mantissa (#PCDATA)>
|
||||||
|
<!ELEMENT CalculatedExponent (#PCDATA)>
|
||||||
|
<!ATTLIST CalculatedExponent Subband CDATA #REQUIRED>
|
||||||
|
<!-- /QuantizationDefault -->
|
||||||
|
<!-- mj2_to_metadata implementation always reports component[0] as using default QCD, -->
|
||||||
|
<!-- and any other component, with main-header quantization values different from [0], as QCC. -->
|
||||||
|
<!ELEMENT QuantizationComponent (Sqcc,SPqcc)>
|
||||||
|
<!ATTLIST QuantizationComponent Marker CDATA #FIXED "QCC">
|
||||||
|
<!ATTLIST QuantizationComponent Component CDATA #REQUIRED>
|
||||||
|
<!ELEMENT Sqcc (AsHex | (AsHex,QuantizationStyle,NumberOfGuardBits) | (QuantizationStyle,NumberOfGuardBits))>
|
||||||
|
<!ELEMENT SPqcc (ReversibleStepSizeValue | QuantizationStepSizeValues )> <!-- TO DO: Irreversible choices -->
|
||||||
|
<!-- /QuantizationComponent -->
|
||||||
|
<!-- Don't know if MJ2 files can have regions of interest. Assume yes -->
|
||||||
|
<!ELEMENT RegionOfInterest (Srgn,Crgn,Sprgn)> <!-- Optional in main header, at most 1 per component -->
|
||||||
|
<!ATTLIST RegionOfInterest Marker CDATA #FIXED "RGN">
|
||||||
|
<!ELEMENT Srgn (#PCDATA)> <!-- ROI style. Only style=0 defined: Implicit ROI (max. shift) -->
|
||||||
|
<!ELEMENT Crgn (#PCDATA)> <!-- Zero-based component number. -->
|
||||||
|
<!ELEMENT SPrgn (#PCDATA)> <!-- Implicit ROI shift, i.e., binary shifting of ROI coefficients above background. -->
|
||||||
|
<!-- </RegionOfInterest> -->
|
||||||
|
<!ELEMENT ProgressionOrderChange (Progression+)> <!-- Optional in main header, at most 1 per component (but impl allows more?) -->
|
||||||
|
<!ATTLIST ProgressionOrderChange Marker CDATA #REQUIRED>
|
||||||
|
<!ELEMENT Progression (RSpoc,CSpoc,LYEpoc,REpoc,CEpoc,Ppoc)>
|
||||||
|
<!ATTLIST Progression Num CDATA #REQUIRED>
|
||||||
|
<!ELEMENT RSpoc (#PCDATA)> <!-- Resolution level index (inclusive) for progression start. Range: 0 to 33 -->
|
||||||
|
<!ELEMENT CSpoc (#PCDATA)> <!-- Component index (inclusive) for progression start. -->
|
||||||
|
<!ELEMENT LYEpoc (#PCDATA)> <!-- Layer index (exclusive) for progression end. -->
|
||||||
|
<!ELEMENT REpoc (#PCDATA)> <!-- Resolution level index (exclusive) for progression end. Range: RSpoc to 33 -->
|
||||||
|
<!ELEMENT CEpoc (#PCDATA)> <!-- Component index (exclusive) for progression end. Minimum: CSpoc -->
|
||||||
|
<!ELEMENT Ppoc (#PCDATA)> <!-- Defined Progression Order Values are: -->
|
||||||
|
<!-- 0 = LRCP; 1 = RLCP; 2 = RPCL; 3 = PCRL; 4 = CPRL -->
|
||||||
|
<!-- where L = "layer", R = "resolution level", C = "component", P = "position". -->
|
||||||
|
<!-- </Progression>, </ProgressionOrderChange -->
|
||||||
|
<!-- /MainHeader -->
|
||||||
|
<!ELEMENT TilePartHeaders (TilePartHeader+)>
|
||||||
|
<!ATTLIST TilePartHeaders Count CDATA #REQUIRED>
|
||||||
|
<!ELEMENT TilePartHeader (StartOfTilePart,CodingStyleDefault,QuantizationDefault,QuantizationComponent*,RegionOfInterest?,ProgressionOrderChange*,StartOfData)>
|
||||||
|
<!ATTLIST TilePartHeader Num CDATA #REQUIRED>
|
||||||
|
<!ATTLIST TilePartHeader ID CDATA #REQUIRED>
|
||||||
|
<!ELEMENT StartOfTilePart EMPTY>
|
||||||
|
<!ATTLIST StartOfTilePart Marker CDATA #FIXED "SOT">
|
||||||
|
<!-- CodingStyleDefault, QuantizationDefault, QuantizationComponent already defined -->
|
||||||
|
<!-- mj2_to_metadata implementation always reports component[0] as using default QCD, -->
|
||||||
|
<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->
|
||||||
|
<!ELEMENT StartOfData EMPTY> <!-- always empty for now -->
|
||||||
|
<!ATTLIST StartOfData Marker CDATA #FIXED "SOD">
|
||||||
|
<!-- Tile-part bitstream, not shown, follows tile-part header and SOD marker. -->
|
||||||
|
<!-- /TilePartHeader, /TilePartHeaders, /JP2_Frame -->
|
||||||
|
<!-- </Track> -->
|
||||||
|
|
||||||
|
<!-- to come:
|
||||||
|
<MovieExtends mvek> // possibly not in Simple Profile
|
||||||
|
<UserDataBox udat> contains <CopyrightBox cprt>
|
||||||
|
-->
|
||||||
|
<!-- /MovieBox -->
|
||||||
|
<!-- To come:
|
||||||
|
<mdat>
|
||||||
|
<moof> // probably not in Simple Profile
|
||||||
|
<free>
|
||||||
|
<skip>
|
||||||
|
-->
|
||||||
|
<!-- </MJ2_File> -->
|
||||||
9
mj2/mj2_to_metadata.h
Normal file
9
mj2/mj2_to_metadata.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/* mj2_to_metadata.h */
|
||||||
|
/* Dump MJ2, JP2 metadata (partial so far) to xml file */
|
||||||
|
/* Contributed to Open JPEG by Glenn Pearson, U.S. National Library of Medicine */
|
||||||
|
|
||||||
|
#define BOOL int
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE 1
|
||||||
|
|
||||||
|
#include "meta_out.h"
|
||||||
324
mj2/mj2_to_metadata.vcproj
Normal file
324
mj2/mj2_to_metadata.vcproj
Normal file
@@ -0,0 +1,324 @@
|
|||||||
|
<?xml version="1.0" encoding="Windows-1252"?>
|
||||||
|
<VisualStudioProject
|
||||||
|
ProjectType="Visual C++"
|
||||||
|
Version="7.10"
|
||||||
|
Name="mj2_to_metadata"
|
||||||
|
ProjectGUID="{338C1241-ACB9-469F-98DF-3B9D79ADD1A0}"
|
||||||
|
SccProjectName=""
|
||||||
|
SccLocalPath="">
|
||||||
|
<Platforms>
|
||||||
|
<Platform
|
||||||
|
Name="Win32"/>
|
||||||
|
</Platforms>
|
||||||
|
<Configurations>
|
||||||
|
<Configuration
|
||||||
|
Name="Release|Win32"
|
||||||
|
OutputDirectory=".\Release"
|
||||||
|
IntermediateDirectory=".\Release"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
InlineFunctionExpansion="1"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg"
|
||||||
|
PreprocessorDefinitions="WIN32,NDEBUG,_CONSOLE,DONT_HAVE_GETOPT,NO_PACKETS_DECODING"
|
||||||
|
StringPooling="TRUE"
|
||||||
|
RuntimeLibrary="4"
|
||||||
|
EnableFunctionLevelLinking="TRUE"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\Release/mj2_to_metadata.pch"
|
||||||
|
AssemblerListingLocation=".\Release/"
|
||||||
|
ObjectFile=".\Release/"
|
||||||
|
ProgramDataBaseFileName=".\Release/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
AdditionalOptions="/MACHINE:I386"
|
||||||
|
AdditionalDependencies="odbc32.lib odbccp32.lib"
|
||||||
|
OutputFile=".\Release/mj2_to_metadata.exe"
|
||||||
|
LinkIncremental="1"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
ProgramDatabaseFile=".\Release/mj2_to_metadata.pdb"
|
||||||
|
SubSystem="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\Release/mj2_to_metadata.tlb"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="NDEBUG"
|
||||||
|
Culture="2057"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
<Configuration
|
||||||
|
Name="Debug|Win32"
|
||||||
|
OutputDirectory=".\mj2_to_metadata___Win32_Debug0"
|
||||||
|
IntermediateDirectory=".\mj2_to_metadata___Win32_Debug0"
|
||||||
|
ConfigurationType="1"
|
||||||
|
UseOfMFC="0"
|
||||||
|
ATLMinimizesCRunTimeLibraryUsage="FALSE"
|
||||||
|
CharacterSet="2">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
Optimization="0"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg"
|
||||||
|
PreprocessorDefinitions="WIN32,_DEBUG,_CONSOLE,DONT_HAVE_GETOPT,NO_PACKETS_DECODING"
|
||||||
|
BasicRuntimeChecks="3"
|
||||||
|
RuntimeLibrary="5"
|
||||||
|
UsePrecompiledHeader="2"
|
||||||
|
PrecompiledHeaderFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.pch"
|
||||||
|
AssemblerListingLocation=".\mj2_to_metadata___Win32_Debug0/"
|
||||||
|
ObjectFile=".\mj2_to_metadata___Win32_Debug0/"
|
||||||
|
ProgramDataBaseFileName=".\mj2_to_metadata___Win32_Debug0/"
|
||||||
|
WarningLevel="3"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
DebugInformationFormat="4"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCCustomBuildTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCLinkerTool"
|
||||||
|
AdditionalOptions="/MACHINE:I386"
|
||||||
|
AdditionalDependencies="odbc32.lib odbccp32.lib"
|
||||||
|
OutputFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.exe"
|
||||||
|
LinkIncremental="2"
|
||||||
|
SuppressStartupBanner="TRUE"
|
||||||
|
GenerateDebugInformation="TRUE"
|
||||||
|
ProgramDatabaseFile=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.pdb"
|
||||||
|
SubSystem="1"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCMIDLTool"
|
||||||
|
TypeLibraryName=".\mj2_to_metadata___Win32_Debug0/mj2_to_metadata.tlb"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPostBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreBuildEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCPreLinkEventTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCResourceCompilerTool"
|
||||||
|
PreprocessorDefinitions="_DEBUG"
|
||||||
|
Culture="2057"
|
||||||
|
AdditionalIncludeDirectories=""
|
||||||
|
ResourceOutputFileName=""/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebServiceProxyGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCXMLDataGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCWebDeploymentTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCManagedWrapperGeneratorTool"/>
|
||||||
|
<Tool
|
||||||
|
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||||
|
</Configuration>
|
||||||
|
</Configurations>
|
||||||
|
<References>
|
||||||
|
</References>
|
||||||
|
<Files>
|
||||||
|
<Filter
|
||||||
|
Name="MJ2"
|
||||||
|
Filter="">
|
||||||
|
<Filter
|
||||||
|
Name="MJ2 Header Files"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\compat\getopt.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="meta_out.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\mj2.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\mj2_convert.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="mj2_to_metadata.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="MJ2 Source Files"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\compat\getopt.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg;$(NoInherit)"
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="meta_out.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\mj2.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg;$(NoInherit)"
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\mj2_convert.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg;$(NoInherit)"
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\mj2_to_metadata.c">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
AdditionalIncludeDirectories="../libopenjpeg;$(NoInherit)"
|
||||||
|
CompileAs="0"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="OpenJPEG"
|
||||||
|
Filter="">
|
||||||
|
<Filter
|
||||||
|
Name="OpenJPEG Header Files"
|
||||||
|
Filter=".h">
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\bio.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\cio.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\dwt.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\fix.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\int.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\j2k.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\jp2.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\jpt.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\mct.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\mqc.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\openjpeg.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\pi.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\raw.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\t1.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\t2.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\tcd.h">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\tgt.h">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="OpenJPEG Source Files"
|
||||||
|
Filter=".c">
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\bio.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\cio.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\dwt.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\fix.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\int.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\j2k.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\jp2.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\jpt.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\mct.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\mqc.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\pi.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\raw.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\t1.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\t2.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\tcd.c">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath="..\libopenjpeg\tgt.c">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
</Filter>
|
||||||
|
<File
|
||||||
|
RelativePath="resource.h">
|
||||||
|
</File>
|
||||||
|
</Files>
|
||||||
|
<Globals>
|
||||||
|
</Globals>
|
||||||
|
</VisualStudioProject>
|
||||||
BIN
mj2/mj2_to_metadata_Notes.doc
Normal file
BIN
mj2/mj2_to_metadata_Notes.doc
Normal file
Binary file not shown.
287
mj2/wrap_j2k_in_mj2.c
Normal file
287
mj2/wrap_j2k_in_mj2.c
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mj2.h"
|
||||||
|
#include <cio.h>
|
||||||
|
#include <j2k.h>
|
||||||
|
#include <int.h>
|
||||||
|
|
||||||
|
#define MJ2_MJ2 0x6d6a7032
|
||||||
|
#define MJ2_MJ2S 0x6d6a3273
|
||||||
|
#define JP2_JP2C 0x6a703263
|
||||||
|
#define MJ2_MDAT 0x6d646174
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h> // Must be included first
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
jmp_buf j2k_error;
|
||||||
|
|
||||||
|
void j2k_read_siz_marker(FILE *file, j2k_image_t *j2k_img)
|
||||||
|
{
|
||||||
|
int len,i;
|
||||||
|
char buf, buf2[2];
|
||||||
|
char *siz_buffer;
|
||||||
|
|
||||||
|
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 = (char*) malloc(len * sizeof(char));
|
||||||
|
fread(siz_buffer,len, 1, file);
|
||||||
|
cio_init(siz_buffer,len);
|
||||||
|
|
||||||
|
cio_read(2); /* Rsiz (capabilities) */
|
||||||
|
j2k_img->x1 = cio_read(4); /* Xsiz */
|
||||||
|
j2k_img->y1 = cio_read(4); /* Ysiz */
|
||||||
|
j2k_img->x0 = cio_read(4); /* X0siz */
|
||||||
|
j2k_img->y0 = cio_read(4); /* Y0siz */
|
||||||
|
cio_skip(16); /* XTsiz, YTsiz, XT0siz, YT0siz */
|
||||||
|
|
||||||
|
j2k_img->numcomps = cio_read(2); /* Csiz */
|
||||||
|
j2k_img->comps =
|
||||||
|
(j2k_comp_t *) malloc(j2k_img->numcomps * sizeof(j2k_comp_t));
|
||||||
|
for (i = 0; i < j2k_img->numcomps; i++) {
|
||||||
|
int tmp;
|
||||||
|
tmp = cio_read(1); /* Ssiz_i */
|
||||||
|
j2k_img->comps[i].prec = (tmp & 0x7f) + 1;
|
||||||
|
j2k_img->comps[i].sgnd = tmp >> 7;
|
||||||
|
j2k_img->comps[i].dx = cio_read(1); /* XRsiz_i */
|
||||||
|
j2k_img->comps[i].dy = cio_read(1); /* YRsiz_i */
|
||||||
|
j2k_img->comps[i].resno_decoded = 0; /* number of resolution decoded */
|
||||||
|
j2k_img->comps[i].factor = 0; /* reducing factor by component */
|
||||||
|
}
|
||||||
|
free(siz_buffer);
|
||||||
|
fseek(file, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setparams(mj2_movie_t *movie, j2k_image_t *img) {
|
||||||
|
int i, depth_0, depth, sign;
|
||||||
|
|
||||||
|
movie->tk[0].sample_rate = 25;
|
||||||
|
movie->tk[0].w = int_ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||||
|
movie->tk[0].h = int_ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||||
|
mj2_init_stdmovie(movie);
|
||||||
|
|
||||||
|
movie->tk[0].depth = img->comps[0].prec;
|
||||||
|
|
||||||
|
if (img->numcomps==3) {
|
||||||
|
if ((img->comps[0].dx == 1) && (img->comps[1].dx == 1) && (img->comps[1].dx == 1))
|
||||||
|
movie->tk[0].CbCr_subsampling_dx = 1;
|
||||||
|
else if ((img->comps[0].dx == 1) && (img->comps[1].dx == 2) && (img->comps[1].dx == 2))
|
||||||
|
movie->tk[0].CbCr_subsampling_dx = 2;
|
||||||
|
else
|
||||||
|
fprintf(stderr,"Image component sizes are incoherent\n");
|
||||||
|
|
||||||
|
if ((img->comps[0].dy == 1) && (img->comps[1].dy == 1) && (img->comps[1].dy == 1))
|
||||||
|
movie->tk[0].CbCr_subsampling_dy = 1;
|
||||||
|
else if ((img->comps[0].dy == 1) && (img->comps[1].dy == 2) && (img->comps[1].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 = img->numcomps; // NC
|
||||||
|
jp2_init_stdjp2(&movie->tk[0].jp2_struct);
|
||||||
|
|
||||||
|
movie->tk[0].jp2_struct.w = int_ceildiv(img->x1 - img->x0, img->comps[0].dx);
|
||||||
|
movie->tk[0].jp2_struct.h = int_ceildiv(img->y1 - img->y0, img->comps[0].dy);
|
||||||
|
|
||||||
|
depth_0 = img->comps[0].prec - 1;
|
||||||
|
sign = img->comps[0].sgnd;
|
||||||
|
movie->tk[0].jp2_struct.bpc = depth_0 + (sign << 7);
|
||||||
|
|
||||||
|
for (i = 1; i < img->numcomps; i++) {
|
||||||
|
depth = img->comps[i].prec - 1;
|
||||||
|
sign = img->comps[i].sgnd;
|
||||||
|
if (depth_0 != depth)
|
||||||
|
movie->tk[0].jp2_struct.bpc = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < img->numcomps; i++)
|
||||||
|
movie->tk[0].jp2_struct.comps[i].bpcc =
|
||||||
|
img->comps[i].prec - 1 + (img->comps[i].sgnd << 7);
|
||||||
|
|
||||||
|
if ((img->numcomps == 1 || img->numcomps == 3)
|
||||||
|
&& (movie->tk[0].jp2_struct.bpc != 255))
|
||||||
|
movie->tk[0].jp2_struct.meth = 1;
|
||||||
|
else
|
||||||
|
movie->tk[0].jp2_struct.meth = 2;
|
||||||
|
|
||||||
|
if (img->numcomps == 1)
|
||||||
|
movie->tk[0].jp2_struct.enumcs = 17; // Grayscale
|
||||||
|
|
||||||
|
else if ((img->comps[0].dx == 1) && (img->comps[1].dx == 1) && (img->comps[1].dx == 1) &&
|
||||||
|
(img->comps[0].dy == 1) && (img->comps[1].dy == 1) && (img->comps[1].dy == 1))
|
||||||
|
movie->tk[0].jp2_struct.enumcs = 16; // RGB
|
||||||
|
|
||||||
|
else if ((img->comps[0].dx == 1) && (img->comps[1].dx == 2) && (img->comps[1].dx == 2) &&
|
||||||
|
(img->comps[0].dy == 1) && (img->comps[1].dy == 2) && (img->comps[1].dy == 2))
|
||||||
|
movie->tk[0].jp2_struct.enumcs = 18; // YUV
|
||||||
|
|
||||||
|
else
|
||||||
|
movie->tk[0].jp2_struct.enumcs = 0; // Unkown profile */
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
unsigned int snum;
|
||||||
|
mj2_movie_t movie;
|
||||||
|
mj2_sample_t *sample;
|
||||||
|
unsigned char* frame_codestream;
|
||||||
|
FILE *mj2file, *j2kfile;
|
||||||
|
char j2kfilename[50];
|
||||||
|
char *buf;
|
||||||
|
int offset, mdat_initpos;
|
||||||
|
j2k_image_t img;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (argc != 3) {
|
||||||
|
printf("Bad syntax: Usage: MJ2_Wrapper source_location mj2_filename\n");
|
||||||
|
printf("Example: MJ2_Wrapper input/input output.mj2\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
mj2file = fopen(argv[2], "wb");
|
||||||
|
|
||||||
|
if (!mj2file) {
|
||||||
|
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialing the movie (parameters used in the JP and FTYP boxes
|
||||||
|
movie.num_htk = 0; // No hint tracks
|
||||||
|
movie.num_stk = 0; // No sound tracks
|
||||||
|
movie.num_vtk = 1; // One video track
|
||||||
|
movie.tk = (mj2_tk_t*) malloc (sizeof(mj2_tk_t)); //Memory allocation for the video track
|
||||||
|
movie.tk[0].sample = (mj2_sample_t*) malloc (sizeof(mj2_sample_t));
|
||||||
|
movie.tk[0].chunk = (mj2_chunk_t *) malloc(sizeof(mj2_chunk_t));
|
||||||
|
movie.tk[0].track_type = 0; // Video track
|
||||||
|
movie.tk[0].track_ID = 1; // Track ID = 1
|
||||||
|
movie.brand = MJ2_MJ2; // One brand: MJ2
|
||||||
|
movie.num_cl = 2; // Two compatible brands: MJ2 and MJ2S
|
||||||
|
movie.cl = (unsigned int *) malloc(movie.num_cl * sizeof(unsigned int));
|
||||||
|
movie.cl[0] = MJ2_MJ2;
|
||||||
|
movie.cl[1] = MJ2_MJ2S;
|
||||||
|
movie.minversion = 0; // Minimum version: 0
|
||||||
|
|
||||||
|
// Writing JP, FTYP and MDAT boxes
|
||||||
|
buf = (char*) malloc (300 * sizeof(char)); // Assuming that the JP and FTYP
|
||||||
|
// boxes won't be longer than 300 bytes
|
||||||
|
cio_init(buf , 300);
|
||||||
|
mj2_write_jp();
|
||||||
|
mj2_write_ftyp(&movie);
|
||||||
|
mdat_initpos = cio_tell();
|
||||||
|
cio_skip(4);
|
||||||
|
cio_write(MJ2_MDAT, 4);
|
||||||
|
fwrite(buf,cio_tell(),1,mj2file);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
// Insert each j2k codestream in a JP2C box
|
||||||
|
snum=0;
|
||||||
|
offset = 0;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
sample = &movie.tk[0].sample[snum];
|
||||||
|
sprintf(j2kfilename,"%s_%d.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 created\n",snum);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Calculating offset for samples and chunks
|
||||||
|
offset += cio_tell();
|
||||||
|
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)
|
||||||
|
j2k_read_siz_marker(j2kfile, &img);
|
||||||
|
|
||||||
|
// Writing JP2C box header
|
||||||
|
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
|
||||||
|
cio_init(frame_codestream, sample->sample_size);
|
||||||
|
cio_write(sample->sample_size, 4); // Sample size
|
||||||
|
cio_write(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(sample->sample_size-8);
|
||||||
|
|
||||||
|
// Ending loop
|
||||||
|
fclose(j2kfile);
|
||||||
|
snum++;
|
||||||
|
movie.tk[0].sample = realloc(movie.tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
|
||||||
|
movie.tk[0].chunk = realloc(movie.tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
|
||||||
|
free(frame_codestream);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Writing the MDAT box length in header
|
||||||
|
offset += cio_tell();
|
||||||
|
buf = (char*) malloc (4 * sizeof(char));
|
||||||
|
cio_init(buf,4);
|
||||||
|
cio_write(offset-mdat_initpos,4); // Write MDAT length in MDAT box header
|
||||||
|
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
|
||||||
|
i=1;
|
||||||
|
buf = (char*) malloc (10000 * sizeof(char));
|
||||||
|
cio_init(buf , i*10000);
|
||||||
|
if (setjmp(j2k_error)) {
|
||||||
|
i++;
|
||||||
|
buf = realloc(buf,i*10000* sizeof(char));
|
||||||
|
cio_init(buf , i*10000);
|
||||||
|
}
|
||||||
|
mj2_write_moov(&movie);
|
||||||
|
fwrite(buf,cio_tell(),1,mj2file);
|
||||||
|
|
||||||
|
// Ending program
|
||||||
|
fclose(mj2file);
|
||||||
|
free(img.comps);
|
||||||
|
free(buf);
|
||||||
|
mj2_memory_free(&movie);
|
||||||
|
|
||||||
|
|
||||||
|
//MEMORY LEAK
|
||||||
|
#ifdef _DEBUG
|
||||||
|
_CrtDumpMemoryLeaks();
|
||||||
|
#endif
|
||||||
|
//MEM
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user