vendor: OpenCV 5.0.0 snapshot at 40738fb16ceddb5fb3fea747585f7ce6abb0605b
This commit is contained in:
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
# ----------------------------------------------------------------------------
|
||||
# CMake file for libjasper. See root CMakeLists.txt
|
||||
#
|
||||
# ----------------------------------------------------------------------------
|
||||
project(${JASPER_LIBRARY})
|
||||
|
||||
|
||||
add_definitions(-DEXCLUDE_MIF_SUPPORT -DEXCLUDE_PNM_SUPPORT -DEXCLUDE_BMP_SUPPORT -DEXCLUDE_RAS_SUPPORT -DEXCLUDE_JPG_SUPPORT -DEXCLUDE_PGX_SUPPORT)
|
||||
|
||||
ocv_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
file(GLOB lib_srcs *.c)
|
||||
file(GLOB lib_hdrs *.h)
|
||||
file(GLOB lib_ext_hdrs jasper/*.h)
|
||||
|
||||
# ----------------------------------------------------------------------------------
|
||||
# Define the library target:
|
||||
# ----------------------------------------------------------------------------------
|
||||
|
||||
add_library(${JASPER_LIBRARY} STATIC ${OPENCV_3RDPARTY_EXCLUDE_FROM_ALL} ${lib_srcs} ${lib_hdrs} ${lib_ext_hdrs})
|
||||
|
||||
if(WIN32 AND NOT MINGW)
|
||||
add_definitions(-DJAS_WIN_MSVC_BUILD)
|
||||
endif(WIN32 AND NOT MINGW)
|
||||
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wno-implicit-function-declaration -Wno-uninitialized -Wmissing-prototypes
|
||||
-Wno-unused-but-set-parameter -Wmissing-declarations -Wunused -Wshadow
|
||||
-Wsign-compare -Wstrict-overflow -Wpointer-compare
|
||||
-Wabsolute-value # clang on Linux
|
||||
-Wimplicit-fallthrough
|
||||
)
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter -Wstrict-prototypes) # clang
|
||||
ocv_warnings_disable(CMAKE_C_FLAGS /wd4013 /wd4018 /wd4101 /wd4244 /wd4267 /wd4715) # vs2005
|
||||
|
||||
set_target_properties(${JASPER_LIBRARY}
|
||||
PROPERTIES
|
||||
OUTPUT_NAME ${JASPER_LIBRARY}
|
||||
DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
|
||||
COMPILE_PDB_NAME ${JASPER_LIBRARY}
|
||||
COMPILE_PDB_NAME_DEBUG "${JASPER_LIBRARY}${OPENCV_DEBUG_POSTFIX}"
|
||||
ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH}
|
||||
)
|
||||
|
||||
if(ENABLE_SOLUTION_FOLDERS)
|
||||
set_target_properties(${JASPER_LIBRARY} PROPERTIES FOLDER "3rdparty")
|
||||
endif()
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
ocv_install_target(${JASPER_LIBRARY} EXPORT OpenCVModules ARCHIVE DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev OPTIONAL)
|
||||
endif()
|
||||
|
||||
ocv_install_3rdparty_licenses(jasper LICENSE README copyright)
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
JasPer License Version 2.0
|
||||
|
||||
Copyright (c) 2001-2006 Michael David Adams
|
||||
Copyright (c) 1999-2000 Image Power, Inc.
|
||||
Copyright (c) 1999-2000 The University of British Columbia
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person (the
|
||||
"User") obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
1. The above copyright notices and this permission notice (which
|
||||
includes the disclaimer below) shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
2. The name of a copyright holder shall not be used to endorse or
|
||||
promote products derived from the Software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
JasPer Readme
|
||||
*************
|
||||
|
||||
This is the source code distribution for JasPer. JasPer is a collection
|
||||
of software (i.e., a library and application programs) for the coding
|
||||
and manipulation of images. This software can handle image data in a
|
||||
variety of formats. One such format supported by JasPer is the JPEG-2000
|
||||
format defined in ISO/IEC 15444-1.
|
||||
|
||||
The complete licensing terms for the JasPer software can be found in
|
||||
the file named "LICENSE" in the top level directory of this software
|
||||
distribution. Any use of this software contrary to the terms of the
|
||||
license is strictly prohibited. The changes made to the software
|
||||
since the last release are described in the file "NEWS". Detailed
|
||||
documentation on the JasPer software can be found in the JasPer Software
|
||||
Reference Manual. This manual is located in the "doc" directory, and
|
||||
includes useful information such as: 1) how to build, install, and use
|
||||
the software, 2) how to submit report bugs, and 3) where to find
|
||||
additional information about the software.
|
||||
|
||||
Enjoy! :)
|
||||
|
||||
Vendored
+162
@@ -0,0 +1,162 @@
|
||||
jasper (1.900.1-13) unstable; urgency=high
|
||||
|
||||
* Fix CVE-2011-4516 and CVE-2011-4517: Two buffer overflow issues possibly
|
||||
exploitable via specially crafted input files (Closes: #652649)
|
||||
Thanks to Red Hat and Michael Gilbert
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Wed, 04 Jan 2012 19:14:40 +0100
|
||||
|
||||
jasper (1.900.1-12) unstable; urgency=low
|
||||
|
||||
* Added patch to fix filename buffer overflow, thanks to Jonas Smedegard
|
||||
and Alex Cherepanov from ghostscript (Closes: #649833)
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sun, 27 Nov 2011 19:56:01 +0100
|
||||
|
||||
jasper (1.900.1-11) unstable; urgency=low
|
||||
|
||||
* Added Multiarch support, thanks to Colin Watson (Closes: #645118)
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Wed, 02 Nov 2011 17:16:10 +0100
|
||||
|
||||
jasper (1.900.1-10) unstable; urgency=low
|
||||
|
||||
* Added debian/watch
|
||||
* debian/patches/01-misc-fixes.patch:
|
||||
- Separated out config.{guess,sub}
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Mon, 15 Aug 2011 19:09:29 +0200
|
||||
|
||||
jasper (1.900.1-9) unstable; urgency=low
|
||||
|
||||
* Switch to dpkg-source 3.0 (quilt) format
|
||||
* Using new dh 7 build system
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Tue, 12 Jul 2011 20:21:21 +0200
|
||||
|
||||
jasper (1.900.1-8) unstable; urgency=low
|
||||
|
||||
* Removed unneeded .la file (Closes: #633162)
|
||||
* debian/control:
|
||||
- Standards-Version: 3.9.2
|
||||
- use libjpeg8-dev instead of libjpeg62-dev
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Mon, 11 Jul 2011 21:27:24 +0200
|
||||
|
||||
jasper (1.900.1-7) unstable; urgency=low
|
||||
|
||||
* Acknowledge NMU
|
||||
* Added patch to fix Debian patch for CVE-2008-3521 (Closes: #506739)
|
||||
* debian/control: Standards-Version: 3.8.4
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sun, 21 Feb 2010 16:09:45 +0100
|
||||
|
||||
jasper (1.900.1-6.1) unstable; urgency=low
|
||||
|
||||
* Non-maintainer upload.
|
||||
* This is a fix for the GeoJP2 patch introduced in 1.900.1-5 which caused
|
||||
GDAL faulting. Thanks Even Rouault. (Closes: #553429)
|
||||
|
||||
-- Francesco Paolo Lovergine <frankie@debian.org> Wed, 28 Oct 2009 09:39:28 +0100
|
||||
|
||||
jasper (1.900.1-6) unstable; urgency=low
|
||||
|
||||
* Reverted to jasper 1.900.1-6 because 1.900.1-5.1 messed up (see #528543)
|
||||
but 1.900.1-5 wasn't available anymore. (Closes: #514296, #528543)
|
||||
* Re-applied patch from #275619 as in 1.900.1-5
|
||||
* debian/control: Standards-Version: 3.8.2
|
||||
* Applied patch by Nico Golde (Closes: #501021)
|
||||
- CVE-2008-3522[0]: Buffer overflow.
|
||||
- CVE-2008-3521[1]: unsecure temporary files handling.
|
||||
- CVE-2008-3520[2]: Multiple integer overflows.
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sat, 20 Jun 2009 15:21:16 +0200
|
||||
|
||||
jasper (1.900.1-5.1) unstable; urgency=low
|
||||
|
||||
* Non-maintainer upload.
|
||||
* add patches/02_security.dpatch to fix various CVEs (Closes: #501021):
|
||||
+ CVE-2008-3522[0]: Buffer overflow.
|
||||
+ CVE-2008-3521[1]: unsecure temporary files handling.
|
||||
+ CVE-2008-3520[2]: Multiple integer overflows.
|
||||
|
||||
-- Pierre Habouzit <madcoder@debian.org> Sun, 12 Oct 2008 21:40:59 +0200
|
||||
|
||||
jasper (1.900.1-5) unstable; urgency=low
|
||||
|
||||
* Added GeoJP2 patch by Sven Geggus <sven.geggus@iitb.fraunhofer.de>
|
||||
(Closes: #275619)
|
||||
* debian/control: Standards-Version: 3.8.0
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sun, 08 Jun 2008 13:14:24 +0200
|
||||
|
||||
jasper (1.900.1-4) unstable; urgency=low
|
||||
|
||||
* src/libjasper/jpc/jpc_dec.c: Extended assert() to accept 4 color
|
||||
components (Closes: #469786)
|
||||
* debian/rules: improve "make distclean", thanks to lintian
|
||||
* debian/control:
|
||||
- Standards-Version: 3.7.3
|
||||
- ${Source-Version} -> ${binary:Version}
|
||||
- Removed self-dependencies of libjasper-dev
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sun, 09 Mar 2008 11:53:44 +0100
|
||||
|
||||
jasper (1.900.1-3) unstable; urgency=low
|
||||
|
||||
* Fixed segfaults on broken images (Closes: #413041)
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Tue, 10 Apr 2007 10:05:10 +0200
|
||||
|
||||
jasper (1.900.1-2) experimental; urgency=low
|
||||
|
||||
* Added jas_tmr.h to -dev package (Closes: #414705)
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Tue, 13 Mar 2007 14:23:58 +0100
|
||||
|
||||
jasper (1.900.1-1) experimental; urgency=low
|
||||
|
||||
* New upstream release
|
||||
* debian/control:
|
||||
- Standards-Version: 3.7.2
|
||||
- Build-Depends: freeglut3-dev instead of libglut3-dev (Closes: #394496)
|
||||
* Renamed packages to libjasper1, libjasper-dev, libjasper-runtime according
|
||||
to upstream shared library naming change
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Fri, 26 Jan 2007 14:22:18 +0100
|
||||
|
||||
jasper (1.701.0-2) unstable; urgency=low
|
||||
|
||||
* Prevent compression of pdf documents in binary packages
|
||||
* Added man pages for the executables (Closes: #250077)
|
||||
* Again renamed binary packages to reflect Policy:
|
||||
- libjasper-1.701-1
|
||||
- libjasper-1.701-dev (Provides, Replaces and Conflicts: libjasper-dev)
|
||||
- libjasper-runtime
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sun, 20 Jun 2004 13:54:10 +0200
|
||||
|
||||
jasper (1.701.0-1) unstable; urgency=low
|
||||
|
||||
* New maintainer (Closes: #217099)
|
||||
* New upstream release (Closes: #217570)
|
||||
- new DFSG-compliant license (Closes: #218999, #245075)
|
||||
- includes newer libtool related files (Closes: #210383)
|
||||
* debian/control:
|
||||
- Standards-Version: 3.6.1
|
||||
- Changed binary package names, fixed interdependencies (Closes: #211592)
|
||||
libjasper-1.700-2 => libjasper1
|
||||
libjasper-1.700-2-dev => libjasper-dev
|
||||
libjasper-progs => libjasper-runtime
|
||||
(new packages conflicting and replacing the old ones)
|
||||
- Added libxi-dev, libxmu-dev, libxt-dev to Build-Depends
|
||||
(Closes: #250481)
|
||||
|
||||
-- Roland Stigge <stigge@antcom.de> Sat, 19 Jun 2004 23:19:32 +0200
|
||||
|
||||
jasper (1.700.2-1) unstable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
-- Christopher L Cheney <ccheney@debian.org> Fri, 22 Aug 2003 01:30:00 -0500
|
||||
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
This package was debianized by Christopher L Cheney <ccheney@debian.org> on
|
||||
Fri, 22 Aug 2003 01:33:34 -0500.
|
||||
|
||||
The current maintainer is Roland Stigge <stigge@antcom.de>
|
||||
|
||||
It was downloaded from http://www.ece.uvic.ca/~mdadams/jasper/
|
||||
|
||||
Upstream Author: Michael Adams <mdadams@ece.uvic.ca>
|
||||
|
||||
License:
|
||||
|
||||
JasPer License Version 2.0
|
||||
|
||||
Copyright (c) 1999-2000 Image Power, Inc.
|
||||
Copyright (c) 1999-2000 The University of British Columbia
|
||||
Copyright (c) 2001-2003 Michael David Adams
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person (the
|
||||
"User") obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, and/or sell copies of the Software, and to permit
|
||||
persons to whom the Software is furnished to do so, subject to the
|
||||
following conditions:
|
||||
|
||||
1. The above copyright notices and this permission notice (which
|
||||
includes the disclaimer below) shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
2. The name of a copyright holder shall not be used to endorse or
|
||||
promote products derived from the Software without specific prior
|
||||
written permission.
|
||||
|
||||
THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
"AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
|
||||
Vendored
+1280
File diff suppressed because it is too large
Load Diff
Vendored
+137
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Local data.
|
||||
\******************************************************************************/
|
||||
|
||||
static int jas_dbglevel = 0;
|
||||
/* The debug level. */
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for getting/setting the debug level.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Set the library debug level. */
|
||||
int jas_setdbglevel(int dbglevel)
|
||||
{
|
||||
int olddbglevel;
|
||||
|
||||
/* Save the old debug level. */
|
||||
olddbglevel = jas_dbglevel;
|
||||
|
||||
/* Change the debug level. */
|
||||
jas_dbglevel = dbglevel;
|
||||
|
||||
/* Return the old debug level. */
|
||||
return olddbglevel;
|
||||
}
|
||||
|
||||
/* Get the library debug level. */
|
||||
int jas_getdbglevel()
|
||||
{
|
||||
return jas_dbglevel;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Perform formatted output to standard error. */
|
||||
int jas_eprintf(const char *fmt, ...)
|
||||
{
|
||||
int ret;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = vfprintf(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Dump memory to a stream. */
|
||||
int jas_memdump(FILE *out, void *data, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
uchar *dp;
|
||||
dp = data;
|
||||
for (i = 0; i < len; i += 16) {
|
||||
fprintf(out, "%04x:", (int)i);
|
||||
for (j = 0; j < 16; ++j) {
|
||||
if (i + j < len) {
|
||||
fprintf(out, " %02x", dp[i + j]);
|
||||
}
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Vendored
+168
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000, Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Command Line Option Parsing Library
|
||||
*
|
||||
* $Id: jas_getopt.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "jasper/jas_getopt.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Global data.
|
||||
\******************************************************************************/
|
||||
|
||||
int jas_optind = 0;
|
||||
int jas_opterr = 1;
|
||||
char *jas_optarg = 0;
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
static jas_opt_t *jas_optlookup(jas_opt_t *opts, char *name)
|
||||
{
|
||||
jas_opt_t *opt;
|
||||
|
||||
for (opt = opts; opt->id >= 0 && opt->name; ++opt) {
|
||||
if (!strcmp(opt->name, name)) {
|
||||
return opt;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jas_getopt(int argc, char **argv, jas_opt_t *opts)
|
||||
{
|
||||
char *cp;
|
||||
int id;
|
||||
int hasarg;
|
||||
jas_opt_t *opt;
|
||||
char *s;
|
||||
|
||||
if (!jas_optind) {
|
||||
jas_optind = JAS_MIN(1, argc);
|
||||
}
|
||||
while (jas_optind < argc) {
|
||||
s = cp = argv[jas_optind];
|
||||
if (*cp == '-') {
|
||||
/* We are processing an option. */
|
||||
++jas_optind;
|
||||
if (*++cp == '-') {
|
||||
/* We are processing a long option. */
|
||||
++cp;
|
||||
if (*cp == '\0') {
|
||||
/* This is the end of the options. */
|
||||
return JAS_GETOPT_EOF;
|
||||
}
|
||||
if (!(opt = jas_optlookup(opts, cp))) {
|
||||
if (jas_opterr) {
|
||||
jas_eprintf("unknown long option %s\n", s);
|
||||
}
|
||||
return JAS_GETOPT_ERR;
|
||||
}
|
||||
hasarg = (opt->flags & JAS_OPT_HASARG) != 0;
|
||||
id = opt->id;
|
||||
} else {
|
||||
/* We are processing a short option. */
|
||||
if (strlen(cp) != 1 ||
|
||||
!(opt = jas_optlookup(opts, cp))) {
|
||||
if (jas_opterr) {
|
||||
jas_eprintf("unknown short option %s\n", s);
|
||||
}
|
||||
return JAS_GETOPT_ERR;
|
||||
}
|
||||
hasarg = (opt->flags & JAS_OPT_HASARG) != 0;
|
||||
id = opt->id;
|
||||
}
|
||||
if (hasarg) {
|
||||
/* The option has an argument. */
|
||||
if (jas_optind >= argc) {
|
||||
if (jas_opterr) {
|
||||
jas_eprintf("missing argument for option %s\n", s);
|
||||
}
|
||||
return JAS_GETOPT_ERR;
|
||||
}
|
||||
jas_optarg = argv[jas_optind];
|
||||
++jas_optind;
|
||||
} else {
|
||||
/* The option does not have an argument. */
|
||||
jas_optarg = 0;
|
||||
}
|
||||
return id;
|
||||
} else {
|
||||
/* We are not processing an option. */
|
||||
return JAS_GETOPT_EOF;
|
||||
}
|
||||
}
|
||||
return JAS_GETOPT_EOF;
|
||||
}
|
||||
Vendored
+1721
File diff suppressed because it is too large
Load Diff
Vendored
+517
@@ -0,0 +1,517 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_types.h>
|
||||
|
||||
uchar jas_iccprofdata_srgb[] =
|
||||
{
|
||||
0x00, 0x00, 0x0c, 0x48, 0x4c, 0x69, 0x6e, 0x6f,
|
||||
0x02, 0x10, 0x00, 0x00, 0x6d, 0x6e, 0x74, 0x72,
|
||||
0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20,
|
||||
0x07, 0xce, 0x00, 0x02, 0x00, 0x09, 0x00, 0x06,
|
||||
0x00, 0x31, 0x00, 0x00, 0x61, 0x63, 0x73, 0x70,
|
||||
0x4d, 0x53, 0x46, 0x54, 0x00, 0x00, 0x00, 0x00,
|
||||
0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47, 0x42,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d,
|
||||
0x48, 0x50, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x11, 0x63, 0x70, 0x72, 0x74,
|
||||
0x00, 0x00, 0x01, 0x50, 0x00, 0x00, 0x00, 0x33,
|
||||
0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x01, 0x84,
|
||||
0x00, 0x00, 0x00, 0x6c, 0x77, 0x74, 0x70, 0x74,
|
||||
0x00, 0x00, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x14,
|
||||
0x62, 0x6b, 0x70, 0x74, 0x00, 0x00, 0x02, 0x04,
|
||||
0x00, 0x00, 0x00, 0x14, 0x72, 0x58, 0x59, 0x5a,
|
||||
0x00, 0x00, 0x02, 0x18, 0x00, 0x00, 0x00, 0x14,
|
||||
0x67, 0x58, 0x59, 0x5a, 0x00, 0x00, 0x02, 0x2c,
|
||||
0x00, 0x00, 0x00, 0x14, 0x62, 0x58, 0x59, 0x5a,
|
||||
0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x14,
|
||||
0x64, 0x6d, 0x6e, 0x64, 0x00, 0x00, 0x02, 0x54,
|
||||
0x00, 0x00, 0x00, 0x70, 0x64, 0x6d, 0x64, 0x64,
|
||||
0x00, 0x00, 0x02, 0xc4, 0x00, 0x00, 0x00, 0x88,
|
||||
0x76, 0x75, 0x65, 0x64, 0x00, 0x00, 0x03, 0x4c,
|
||||
0x00, 0x00, 0x00, 0x86, 0x76, 0x69, 0x65, 0x77,
|
||||
0x00, 0x00, 0x03, 0xd4, 0x00, 0x00, 0x00, 0x24,
|
||||
0x6c, 0x75, 0x6d, 0x69, 0x00, 0x00, 0x03, 0xf8,
|
||||
0x00, 0x00, 0x00, 0x14, 0x6d, 0x65, 0x61, 0x73,
|
||||
0x00, 0x00, 0x04, 0x0c, 0x00, 0x00, 0x00, 0x24,
|
||||
0x74, 0x65, 0x63, 0x68, 0x00, 0x00, 0x04, 0x30,
|
||||
0x00, 0x00, 0x00, 0x0c, 0x72, 0x54, 0x52, 0x43,
|
||||
0x00, 0x00, 0x04, 0x3c, 0x00, 0x00, 0x08, 0x0c,
|
||||
0x67, 0x54, 0x52, 0x43, 0x00, 0x00, 0x04, 0x3c,
|
||||
0x00, 0x00, 0x08, 0x0c, 0x62, 0x54, 0x52, 0x43,
|
||||
0x00, 0x00, 0x04, 0x3c, 0x00, 0x00, 0x08, 0x0c,
|
||||
0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00,
|
||||
0x43, 0x6f, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
|
||||
0x74, 0x20, 0x28, 0x63, 0x29, 0x20, 0x31, 0x39,
|
||||
0x39, 0x38, 0x20, 0x48, 0x65, 0x77, 0x6c, 0x65,
|
||||
0x74, 0x74, 0x2d, 0x50, 0x61, 0x63, 0x6b, 0x61,
|
||||
0x72, 0x64, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x61,
|
||||
0x6e, 0x79, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12,
|
||||
0x73, 0x52, 0x47, 0x42, 0x20, 0x49, 0x45, 0x43,
|
||||
0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e,
|
||||
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x12, 0x73, 0x52, 0x47,
|
||||
0x42, 0x20, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39,
|
||||
0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xf3, 0x51, 0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x01, 0x16, 0xcc, 0x58, 0x59, 0x5a, 0x20,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x6f, 0xa2, 0x00, 0x00, 0x38, 0xf5,
|
||||
0x00, 0x00, 0x03, 0x90, 0x58, 0x59, 0x5a, 0x20,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x99,
|
||||
0x00, 0x00, 0xb7, 0x85, 0x00, 0x00, 0x18, 0xda,
|
||||
0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x24, 0xa0, 0x00, 0x00, 0x0f, 0x84,
|
||||
0x00, 0x00, 0xb6, 0xcf, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16,
|
||||
0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74, 0x70,
|
||||
0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69,
|
||||
0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x16, 0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74,
|
||||
0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e,
|
||||
0x69, 0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e,
|
||||
0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39, 0x36,
|
||||
0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44, 0x65,
|
||||
0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52, 0x47,
|
||||
0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72,
|
||||
0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x2d,
|
||||
0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x2e, 0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39,
|
||||
0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44,
|
||||
0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52,
|
||||
0x47, 0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75,
|
||||
0x72, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20,
|
||||
0x2d, 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
|
||||
0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
|
||||
0x65, 0x20, 0x56, 0x69, 0x65, 0x77, 0x69, 0x6e,
|
||||
0x67, 0x20, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74,
|
||||
0x69, 0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x49,
|
||||
0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d,
|
||||
0x32, 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x52,
|
||||
0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
|
||||
0x20, 0x56, 0x69, 0x65, 0x77, 0x69, 0x6e, 0x67,
|
||||
0x20, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69,
|
||||
0x6f, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x49, 0x45,
|
||||
0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32,
|
||||
0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x65, 0x77,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xa4, 0xfe,
|
||||
0x00, 0x14, 0x5f, 0x2e, 0x00, 0x10, 0xcf, 0x14,
|
||||
0x00, 0x03, 0xed, 0xcc, 0x00, 0x04, 0x13, 0x0b,
|
||||
0x00, 0x03, 0x5c, 0x9e, 0x00, 0x00, 0x00, 0x01,
|
||||
0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x4c, 0x09, 0x56, 0x00, 0x50, 0x00, 0x00,
|
||||
0x00, 0x57, 0x1f, 0xe7, 0x6d, 0x65, 0x61, 0x73,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x02, 0x8f, 0x00, 0x00, 0x00, 0x02,
|
||||
0x73, 0x69, 0x67, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x43, 0x52, 0x54, 0x20, 0x63, 0x75, 0x72, 0x76,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
|
||||
0x00, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x0f,
|
||||
0x00, 0x14, 0x00, 0x19, 0x00, 0x1e, 0x00, 0x23,
|
||||
0x00, 0x28, 0x00, 0x2d, 0x00, 0x32, 0x00, 0x37,
|
||||
0x00, 0x3b, 0x00, 0x40, 0x00, 0x45, 0x00, 0x4a,
|
||||
0x00, 0x4f, 0x00, 0x54, 0x00, 0x59, 0x00, 0x5e,
|
||||
0x00, 0x63, 0x00, 0x68, 0x00, 0x6d, 0x00, 0x72,
|
||||
0x00, 0x77, 0x00, 0x7c, 0x00, 0x81, 0x00, 0x86,
|
||||
0x00, 0x8b, 0x00, 0x90, 0x00, 0x95, 0x00, 0x9a,
|
||||
0x00, 0x9f, 0x00, 0xa4, 0x00, 0xa9, 0x00, 0xae,
|
||||
0x00, 0xb2, 0x00, 0xb7, 0x00, 0xbc, 0x00, 0xc1,
|
||||
0x00, 0xc6, 0x00, 0xcb, 0x00, 0xd0, 0x00, 0xd5,
|
||||
0x00, 0xdb, 0x00, 0xe0, 0x00, 0xe5, 0x00, 0xeb,
|
||||
0x00, 0xf0, 0x00, 0xf6, 0x00, 0xfb, 0x01, 0x01,
|
||||
0x01, 0x07, 0x01, 0x0d, 0x01, 0x13, 0x01, 0x19,
|
||||
0x01, 0x1f, 0x01, 0x25, 0x01, 0x2b, 0x01, 0x32,
|
||||
0x01, 0x38, 0x01, 0x3e, 0x01, 0x45, 0x01, 0x4c,
|
||||
0x01, 0x52, 0x01, 0x59, 0x01, 0x60, 0x01, 0x67,
|
||||
0x01, 0x6e, 0x01, 0x75, 0x01, 0x7c, 0x01, 0x83,
|
||||
0x01, 0x8b, 0x01, 0x92, 0x01, 0x9a, 0x01, 0xa1,
|
||||
0x01, 0xa9, 0x01, 0xb1, 0x01, 0xb9, 0x01, 0xc1,
|
||||
0x01, 0xc9, 0x01, 0xd1, 0x01, 0xd9, 0x01, 0xe1,
|
||||
0x01, 0xe9, 0x01, 0xf2, 0x01, 0xfa, 0x02, 0x03,
|
||||
0x02, 0x0c, 0x02, 0x14, 0x02, 0x1d, 0x02, 0x26,
|
||||
0x02, 0x2f, 0x02, 0x38, 0x02, 0x41, 0x02, 0x4b,
|
||||
0x02, 0x54, 0x02, 0x5d, 0x02, 0x67, 0x02, 0x71,
|
||||
0x02, 0x7a, 0x02, 0x84, 0x02, 0x8e, 0x02, 0x98,
|
||||
0x02, 0xa2, 0x02, 0xac, 0x02, 0xb6, 0x02, 0xc1,
|
||||
0x02, 0xcb, 0x02, 0xd5, 0x02, 0xe0, 0x02, 0xeb,
|
||||
0x02, 0xf5, 0x03, 0x00, 0x03, 0x0b, 0x03, 0x16,
|
||||
0x03, 0x21, 0x03, 0x2d, 0x03, 0x38, 0x03, 0x43,
|
||||
0x03, 0x4f, 0x03, 0x5a, 0x03, 0x66, 0x03, 0x72,
|
||||
0x03, 0x7e, 0x03, 0x8a, 0x03, 0x96, 0x03, 0xa2,
|
||||
0x03, 0xae, 0x03, 0xba, 0x03, 0xc7, 0x03, 0xd3,
|
||||
0x03, 0xe0, 0x03, 0xec, 0x03, 0xf9, 0x04, 0x06,
|
||||
0x04, 0x13, 0x04, 0x20, 0x04, 0x2d, 0x04, 0x3b,
|
||||
0x04, 0x48, 0x04, 0x55, 0x04, 0x63, 0x04, 0x71,
|
||||
0x04, 0x7e, 0x04, 0x8c, 0x04, 0x9a, 0x04, 0xa8,
|
||||
0x04, 0xb6, 0x04, 0xc4, 0x04, 0xd3, 0x04, 0xe1,
|
||||
0x04, 0xf0, 0x04, 0xfe, 0x05, 0x0d, 0x05, 0x1c,
|
||||
0x05, 0x2b, 0x05, 0x3a, 0x05, 0x49, 0x05, 0x58,
|
||||
0x05, 0x67, 0x05, 0x77, 0x05, 0x86, 0x05, 0x96,
|
||||
0x05, 0xa6, 0x05, 0xb5, 0x05, 0xc5, 0x05, 0xd5,
|
||||
0x05, 0xe5, 0x05, 0xf6, 0x06, 0x06, 0x06, 0x16,
|
||||
0x06, 0x27, 0x06, 0x37, 0x06, 0x48, 0x06, 0x59,
|
||||
0x06, 0x6a, 0x06, 0x7b, 0x06, 0x8c, 0x06, 0x9d,
|
||||
0x06, 0xaf, 0x06, 0xc0, 0x06, 0xd1, 0x06, 0xe3,
|
||||
0x06, 0xf5, 0x07, 0x07, 0x07, 0x19, 0x07, 0x2b,
|
||||
0x07, 0x3d, 0x07, 0x4f, 0x07, 0x61, 0x07, 0x74,
|
||||
0x07, 0x86, 0x07, 0x99, 0x07, 0xac, 0x07, 0xbf,
|
||||
0x07, 0xd2, 0x07, 0xe5, 0x07, 0xf8, 0x08, 0x0b,
|
||||
0x08, 0x1f, 0x08, 0x32, 0x08, 0x46, 0x08, 0x5a,
|
||||
0x08, 0x6e, 0x08, 0x82, 0x08, 0x96, 0x08, 0xaa,
|
||||
0x08, 0xbe, 0x08, 0xd2, 0x08, 0xe7, 0x08, 0xfb,
|
||||
0x09, 0x10, 0x09, 0x25, 0x09, 0x3a, 0x09, 0x4f,
|
||||
0x09, 0x64, 0x09, 0x79, 0x09, 0x8f, 0x09, 0xa4,
|
||||
0x09, 0xba, 0x09, 0xcf, 0x09, 0xe5, 0x09, 0xfb,
|
||||
0x0a, 0x11, 0x0a, 0x27, 0x0a, 0x3d, 0x0a, 0x54,
|
||||
0x0a, 0x6a, 0x0a, 0x81, 0x0a, 0x98, 0x0a, 0xae,
|
||||
0x0a, 0xc5, 0x0a, 0xdc, 0x0a, 0xf3, 0x0b, 0x0b,
|
||||
0x0b, 0x22, 0x0b, 0x39, 0x0b, 0x51, 0x0b, 0x69,
|
||||
0x0b, 0x80, 0x0b, 0x98, 0x0b, 0xb0, 0x0b, 0xc8,
|
||||
0x0b, 0xe1, 0x0b, 0xf9, 0x0c, 0x12, 0x0c, 0x2a,
|
||||
0x0c, 0x43, 0x0c, 0x5c, 0x0c, 0x75, 0x0c, 0x8e,
|
||||
0x0c, 0xa7, 0x0c, 0xc0, 0x0c, 0xd9, 0x0c, 0xf3,
|
||||
0x0d, 0x0d, 0x0d, 0x26, 0x0d, 0x40, 0x0d, 0x5a,
|
||||
0x0d, 0x74, 0x0d, 0x8e, 0x0d, 0xa9, 0x0d, 0xc3,
|
||||
0x0d, 0xde, 0x0d, 0xf8, 0x0e, 0x13, 0x0e, 0x2e,
|
||||
0x0e, 0x49, 0x0e, 0x64, 0x0e, 0x7f, 0x0e, 0x9b,
|
||||
0x0e, 0xb6, 0x0e, 0xd2, 0x0e, 0xee, 0x0f, 0x09,
|
||||
0x0f, 0x25, 0x0f, 0x41, 0x0f, 0x5e, 0x0f, 0x7a,
|
||||
0x0f, 0x96, 0x0f, 0xb3, 0x0f, 0xcf, 0x0f, 0xec,
|
||||
0x10, 0x09, 0x10, 0x26, 0x10, 0x43, 0x10, 0x61,
|
||||
0x10, 0x7e, 0x10, 0x9b, 0x10, 0xb9, 0x10, 0xd7,
|
||||
0x10, 0xf5, 0x11, 0x13, 0x11, 0x31, 0x11, 0x4f,
|
||||
0x11, 0x6d, 0x11, 0x8c, 0x11, 0xaa, 0x11, 0xc9,
|
||||
0x11, 0xe8, 0x12, 0x07, 0x12, 0x26, 0x12, 0x45,
|
||||
0x12, 0x64, 0x12, 0x84, 0x12, 0xa3, 0x12, 0xc3,
|
||||
0x12, 0xe3, 0x13, 0x03, 0x13, 0x23, 0x13, 0x43,
|
||||
0x13, 0x63, 0x13, 0x83, 0x13, 0xa4, 0x13, 0xc5,
|
||||
0x13, 0xe5, 0x14, 0x06, 0x14, 0x27, 0x14, 0x49,
|
||||
0x14, 0x6a, 0x14, 0x8b, 0x14, 0xad, 0x14, 0xce,
|
||||
0x14, 0xf0, 0x15, 0x12, 0x15, 0x34, 0x15, 0x56,
|
||||
0x15, 0x78, 0x15, 0x9b, 0x15, 0xbd, 0x15, 0xe0,
|
||||
0x16, 0x03, 0x16, 0x26, 0x16, 0x49, 0x16, 0x6c,
|
||||
0x16, 0x8f, 0x16, 0xb2, 0x16, 0xd6, 0x16, 0xfa,
|
||||
0x17, 0x1d, 0x17, 0x41, 0x17, 0x65, 0x17, 0x89,
|
||||
0x17, 0xae, 0x17, 0xd2, 0x17, 0xf7, 0x18, 0x1b,
|
||||
0x18, 0x40, 0x18, 0x65, 0x18, 0x8a, 0x18, 0xaf,
|
||||
0x18, 0xd5, 0x18, 0xfa, 0x19, 0x20, 0x19, 0x45,
|
||||
0x19, 0x6b, 0x19, 0x91, 0x19, 0xb7, 0x19, 0xdd,
|
||||
0x1a, 0x04, 0x1a, 0x2a, 0x1a, 0x51, 0x1a, 0x77,
|
||||
0x1a, 0x9e, 0x1a, 0xc5, 0x1a, 0xec, 0x1b, 0x14,
|
||||
0x1b, 0x3b, 0x1b, 0x63, 0x1b, 0x8a, 0x1b, 0xb2,
|
||||
0x1b, 0xda, 0x1c, 0x02, 0x1c, 0x2a, 0x1c, 0x52,
|
||||
0x1c, 0x7b, 0x1c, 0xa3, 0x1c, 0xcc, 0x1c, 0xf5,
|
||||
0x1d, 0x1e, 0x1d, 0x47, 0x1d, 0x70, 0x1d, 0x99,
|
||||
0x1d, 0xc3, 0x1d, 0xec, 0x1e, 0x16, 0x1e, 0x40,
|
||||
0x1e, 0x6a, 0x1e, 0x94, 0x1e, 0xbe, 0x1e, 0xe9,
|
||||
0x1f, 0x13, 0x1f, 0x3e, 0x1f, 0x69, 0x1f, 0x94,
|
||||
0x1f, 0xbf, 0x1f, 0xea, 0x20, 0x15, 0x20, 0x41,
|
||||
0x20, 0x6c, 0x20, 0x98, 0x20, 0xc4, 0x20, 0xf0,
|
||||
0x21, 0x1c, 0x21, 0x48, 0x21, 0x75, 0x21, 0xa1,
|
||||
0x21, 0xce, 0x21, 0xfb, 0x22, 0x27, 0x22, 0x55,
|
||||
0x22, 0x82, 0x22, 0xaf, 0x22, 0xdd, 0x23, 0x0a,
|
||||
0x23, 0x38, 0x23, 0x66, 0x23, 0x94, 0x23, 0xc2,
|
||||
0x23, 0xf0, 0x24, 0x1f, 0x24, 0x4d, 0x24, 0x7c,
|
||||
0x24, 0xab, 0x24, 0xda, 0x25, 0x09, 0x25, 0x38,
|
||||
0x25, 0x68, 0x25, 0x97, 0x25, 0xc7, 0x25, 0xf7,
|
||||
0x26, 0x27, 0x26, 0x57, 0x26, 0x87, 0x26, 0xb7,
|
||||
0x26, 0xe8, 0x27, 0x18, 0x27, 0x49, 0x27, 0x7a,
|
||||
0x27, 0xab, 0x27, 0xdc, 0x28, 0x0d, 0x28, 0x3f,
|
||||
0x28, 0x71, 0x28, 0xa2, 0x28, 0xd4, 0x29, 0x06,
|
||||
0x29, 0x38, 0x29, 0x6b, 0x29, 0x9d, 0x29, 0xd0,
|
||||
0x2a, 0x02, 0x2a, 0x35, 0x2a, 0x68, 0x2a, 0x9b,
|
||||
0x2a, 0xcf, 0x2b, 0x02, 0x2b, 0x36, 0x2b, 0x69,
|
||||
0x2b, 0x9d, 0x2b, 0xd1, 0x2c, 0x05, 0x2c, 0x39,
|
||||
0x2c, 0x6e, 0x2c, 0xa2, 0x2c, 0xd7, 0x2d, 0x0c,
|
||||
0x2d, 0x41, 0x2d, 0x76, 0x2d, 0xab, 0x2d, 0xe1,
|
||||
0x2e, 0x16, 0x2e, 0x4c, 0x2e, 0x82, 0x2e, 0xb7,
|
||||
0x2e, 0xee, 0x2f, 0x24, 0x2f, 0x5a, 0x2f, 0x91,
|
||||
0x2f, 0xc7, 0x2f, 0xfe, 0x30, 0x35, 0x30, 0x6c,
|
||||
0x30, 0xa4, 0x30, 0xdb, 0x31, 0x12, 0x31, 0x4a,
|
||||
0x31, 0x82, 0x31, 0xba, 0x31, 0xf2, 0x32, 0x2a,
|
||||
0x32, 0x63, 0x32, 0x9b, 0x32, 0xd4, 0x33, 0x0d,
|
||||
0x33, 0x46, 0x33, 0x7f, 0x33, 0xb8, 0x33, 0xf1,
|
||||
0x34, 0x2b, 0x34, 0x65, 0x34, 0x9e, 0x34, 0xd8,
|
||||
0x35, 0x13, 0x35, 0x4d, 0x35, 0x87, 0x35, 0xc2,
|
||||
0x35, 0xfd, 0x36, 0x37, 0x36, 0x72, 0x36, 0xae,
|
||||
0x36, 0xe9, 0x37, 0x24, 0x37, 0x60, 0x37, 0x9c,
|
||||
0x37, 0xd7, 0x38, 0x14, 0x38, 0x50, 0x38, 0x8c,
|
||||
0x38, 0xc8, 0x39, 0x05, 0x39, 0x42, 0x39, 0x7f,
|
||||
0x39, 0xbc, 0x39, 0xf9, 0x3a, 0x36, 0x3a, 0x74,
|
||||
0x3a, 0xb2, 0x3a, 0xef, 0x3b, 0x2d, 0x3b, 0x6b,
|
||||
0x3b, 0xaa, 0x3b, 0xe8, 0x3c, 0x27, 0x3c, 0x65,
|
||||
0x3c, 0xa4, 0x3c, 0xe3, 0x3d, 0x22, 0x3d, 0x61,
|
||||
0x3d, 0xa1, 0x3d, 0xe0, 0x3e, 0x20, 0x3e, 0x60,
|
||||
0x3e, 0xa0, 0x3e, 0xe0, 0x3f, 0x21, 0x3f, 0x61,
|
||||
0x3f, 0xa2, 0x3f, 0xe2, 0x40, 0x23, 0x40, 0x64,
|
||||
0x40, 0xa6, 0x40, 0xe7, 0x41, 0x29, 0x41, 0x6a,
|
||||
0x41, 0xac, 0x41, 0xee, 0x42, 0x30, 0x42, 0x72,
|
||||
0x42, 0xb5, 0x42, 0xf7, 0x43, 0x3a, 0x43, 0x7d,
|
||||
0x43, 0xc0, 0x44, 0x03, 0x44, 0x47, 0x44, 0x8a,
|
||||
0x44, 0xce, 0x45, 0x12, 0x45, 0x55, 0x45, 0x9a,
|
||||
0x45, 0xde, 0x46, 0x22, 0x46, 0x67, 0x46, 0xab,
|
||||
0x46, 0xf0, 0x47, 0x35, 0x47, 0x7b, 0x47, 0xc0,
|
||||
0x48, 0x05, 0x48, 0x4b, 0x48, 0x91, 0x48, 0xd7,
|
||||
0x49, 0x1d, 0x49, 0x63, 0x49, 0xa9, 0x49, 0xf0,
|
||||
0x4a, 0x37, 0x4a, 0x7d, 0x4a, 0xc4, 0x4b, 0x0c,
|
||||
0x4b, 0x53, 0x4b, 0x9a, 0x4b, 0xe2, 0x4c, 0x2a,
|
||||
0x4c, 0x72, 0x4c, 0xba, 0x4d, 0x02, 0x4d, 0x4a,
|
||||
0x4d, 0x93, 0x4d, 0xdc, 0x4e, 0x25, 0x4e, 0x6e,
|
||||
0x4e, 0xb7, 0x4f, 0x00, 0x4f, 0x49, 0x4f, 0x93,
|
||||
0x4f, 0xdd, 0x50, 0x27, 0x50, 0x71, 0x50, 0xbb,
|
||||
0x51, 0x06, 0x51, 0x50, 0x51, 0x9b, 0x51, 0xe6,
|
||||
0x52, 0x31, 0x52, 0x7c, 0x52, 0xc7, 0x53, 0x13,
|
||||
0x53, 0x5f, 0x53, 0xaa, 0x53, 0xf6, 0x54, 0x42,
|
||||
0x54, 0x8f, 0x54, 0xdb, 0x55, 0x28, 0x55, 0x75,
|
||||
0x55, 0xc2, 0x56, 0x0f, 0x56, 0x5c, 0x56, 0xa9,
|
||||
0x56, 0xf7, 0x57, 0x44, 0x57, 0x92, 0x57, 0xe0,
|
||||
0x58, 0x2f, 0x58, 0x7d, 0x58, 0xcb, 0x59, 0x1a,
|
||||
0x59, 0x69, 0x59, 0xb8, 0x5a, 0x07, 0x5a, 0x56,
|
||||
0x5a, 0xa6, 0x5a, 0xf5, 0x5b, 0x45, 0x5b, 0x95,
|
||||
0x5b, 0xe5, 0x5c, 0x35, 0x5c, 0x86, 0x5c, 0xd6,
|
||||
0x5d, 0x27, 0x5d, 0x78, 0x5d, 0xc9, 0x5e, 0x1a,
|
||||
0x5e, 0x6c, 0x5e, 0xbd, 0x5f, 0x0f, 0x5f, 0x61,
|
||||
0x5f, 0xb3, 0x60, 0x05, 0x60, 0x57, 0x60, 0xaa,
|
||||
0x60, 0xfc, 0x61, 0x4f, 0x61, 0xa2, 0x61, 0xf5,
|
||||
0x62, 0x49, 0x62, 0x9c, 0x62, 0xf0, 0x63, 0x43,
|
||||
0x63, 0x97, 0x63, 0xeb, 0x64, 0x40, 0x64, 0x94,
|
||||
0x64, 0xe9, 0x65, 0x3d, 0x65, 0x92, 0x65, 0xe7,
|
||||
0x66, 0x3d, 0x66, 0x92, 0x66, 0xe8, 0x67, 0x3d,
|
||||
0x67, 0x93, 0x67, 0xe9, 0x68, 0x3f, 0x68, 0x96,
|
||||
0x68, 0xec, 0x69, 0x43, 0x69, 0x9a, 0x69, 0xf1,
|
||||
0x6a, 0x48, 0x6a, 0x9f, 0x6a, 0xf7, 0x6b, 0x4f,
|
||||
0x6b, 0xa7, 0x6b, 0xff, 0x6c, 0x57, 0x6c, 0xaf,
|
||||
0x6d, 0x08, 0x6d, 0x60, 0x6d, 0xb9, 0x6e, 0x12,
|
||||
0x6e, 0x6b, 0x6e, 0xc4, 0x6f, 0x1e, 0x6f, 0x78,
|
||||
0x6f, 0xd1, 0x70, 0x2b, 0x70, 0x86, 0x70, 0xe0,
|
||||
0x71, 0x3a, 0x71, 0x95, 0x71, 0xf0, 0x72, 0x4b,
|
||||
0x72, 0xa6, 0x73, 0x01, 0x73, 0x5d, 0x73, 0xb8,
|
||||
0x74, 0x14, 0x74, 0x70, 0x74, 0xcc, 0x75, 0x28,
|
||||
0x75, 0x85, 0x75, 0xe1, 0x76, 0x3e, 0x76, 0x9b,
|
||||
0x76, 0xf8, 0x77, 0x56, 0x77, 0xb3, 0x78, 0x11,
|
||||
0x78, 0x6e, 0x78, 0xcc, 0x79, 0x2a, 0x79, 0x89,
|
||||
0x79, 0xe7, 0x7a, 0x46, 0x7a, 0xa5, 0x7b, 0x04,
|
||||
0x7b, 0x63, 0x7b, 0xc2, 0x7c, 0x21, 0x7c, 0x81,
|
||||
0x7c, 0xe1, 0x7d, 0x41, 0x7d, 0xa1, 0x7e, 0x01,
|
||||
0x7e, 0x62, 0x7e, 0xc2, 0x7f, 0x23, 0x7f, 0x84,
|
||||
0x7f, 0xe5, 0x80, 0x47, 0x80, 0xa8, 0x81, 0x0a,
|
||||
0x81, 0x6b, 0x81, 0xcd, 0x82, 0x30, 0x82, 0x92,
|
||||
0x82, 0xf4, 0x83, 0x57, 0x83, 0xba, 0x84, 0x1d,
|
||||
0x84, 0x80, 0x84, 0xe3, 0x85, 0x47, 0x85, 0xab,
|
||||
0x86, 0x0e, 0x86, 0x72, 0x86, 0xd7, 0x87, 0x3b,
|
||||
0x87, 0x9f, 0x88, 0x04, 0x88, 0x69, 0x88, 0xce,
|
||||
0x89, 0x33, 0x89, 0x99, 0x89, 0xfe, 0x8a, 0x64,
|
||||
0x8a, 0xca, 0x8b, 0x30, 0x8b, 0x96, 0x8b, 0xfc,
|
||||
0x8c, 0x63, 0x8c, 0xca, 0x8d, 0x31, 0x8d, 0x98,
|
||||
0x8d, 0xff, 0x8e, 0x66, 0x8e, 0xce, 0x8f, 0x36,
|
||||
0x8f, 0x9e, 0x90, 0x06, 0x90, 0x6e, 0x90, 0xd6,
|
||||
0x91, 0x3f, 0x91, 0xa8, 0x92, 0x11, 0x92, 0x7a,
|
||||
0x92, 0xe3, 0x93, 0x4d, 0x93, 0xb6, 0x94, 0x20,
|
||||
0x94, 0x8a, 0x94, 0xf4, 0x95, 0x5f, 0x95, 0xc9,
|
||||
0x96, 0x34, 0x96, 0x9f, 0x97, 0x0a, 0x97, 0x75,
|
||||
0x97, 0xe0, 0x98, 0x4c, 0x98, 0xb8, 0x99, 0x24,
|
||||
0x99, 0x90, 0x99, 0xfc, 0x9a, 0x68, 0x9a, 0xd5,
|
||||
0x9b, 0x42, 0x9b, 0xaf, 0x9c, 0x1c, 0x9c, 0x89,
|
||||
0x9c, 0xf7, 0x9d, 0x64, 0x9d, 0xd2, 0x9e, 0x40,
|
||||
0x9e, 0xae, 0x9f, 0x1d, 0x9f, 0x8b, 0x9f, 0xfa,
|
||||
0xa0, 0x69, 0xa0, 0xd8, 0xa1, 0x47, 0xa1, 0xb6,
|
||||
0xa2, 0x26, 0xa2, 0x96, 0xa3, 0x06, 0xa3, 0x76,
|
||||
0xa3, 0xe6, 0xa4, 0x56, 0xa4, 0xc7, 0xa5, 0x38,
|
||||
0xa5, 0xa9, 0xa6, 0x1a, 0xa6, 0x8b, 0xa6, 0xfd,
|
||||
0xa7, 0x6e, 0xa7, 0xe0, 0xa8, 0x52, 0xa8, 0xc4,
|
||||
0xa9, 0x37, 0xa9, 0xa9, 0xaa, 0x1c, 0xaa, 0x8f,
|
||||
0xab, 0x02, 0xab, 0x75, 0xab, 0xe9, 0xac, 0x5c,
|
||||
0xac, 0xd0, 0xad, 0x44, 0xad, 0xb8, 0xae, 0x2d,
|
||||
0xae, 0xa1, 0xaf, 0x16, 0xaf, 0x8b, 0xb0, 0x00,
|
||||
0xb0, 0x75, 0xb0, 0xea, 0xb1, 0x60, 0xb1, 0xd6,
|
||||
0xb2, 0x4b, 0xb2, 0xc2, 0xb3, 0x38, 0xb3, 0xae,
|
||||
0xb4, 0x25, 0xb4, 0x9c, 0xb5, 0x13, 0xb5, 0x8a,
|
||||
0xb6, 0x01, 0xb6, 0x79, 0xb6, 0xf0, 0xb7, 0x68,
|
||||
0xb7, 0xe0, 0xb8, 0x59, 0xb8, 0xd1, 0xb9, 0x4a,
|
||||
0xb9, 0xc2, 0xba, 0x3b, 0xba, 0xb5, 0xbb, 0x2e,
|
||||
0xbb, 0xa7, 0xbc, 0x21, 0xbc, 0x9b, 0xbd, 0x15,
|
||||
0xbd, 0x8f, 0xbe, 0x0a, 0xbe, 0x84, 0xbe, 0xff,
|
||||
0xbf, 0x7a, 0xbf, 0xf5, 0xc0, 0x70, 0xc0, 0xec,
|
||||
0xc1, 0x67, 0xc1, 0xe3, 0xc2, 0x5f, 0xc2, 0xdb,
|
||||
0xc3, 0x58, 0xc3, 0xd4, 0xc4, 0x51, 0xc4, 0xce,
|
||||
0xc5, 0x4b, 0xc5, 0xc8, 0xc6, 0x46, 0xc6, 0xc3,
|
||||
0xc7, 0x41, 0xc7, 0xbf, 0xc8, 0x3d, 0xc8, 0xbc,
|
||||
0xc9, 0x3a, 0xc9, 0xb9, 0xca, 0x38, 0xca, 0xb7,
|
||||
0xcb, 0x36, 0xcb, 0xb6, 0xcc, 0x35, 0xcc, 0xb5,
|
||||
0xcd, 0x35, 0xcd, 0xb5, 0xce, 0x36, 0xce, 0xb6,
|
||||
0xcf, 0x37, 0xcf, 0xb8, 0xd0, 0x39, 0xd0, 0xba,
|
||||
0xd1, 0x3c, 0xd1, 0xbe, 0xd2, 0x3f, 0xd2, 0xc1,
|
||||
0xd3, 0x44, 0xd3, 0xc6, 0xd4, 0x49, 0xd4, 0xcb,
|
||||
0xd5, 0x4e, 0xd5, 0xd1, 0xd6, 0x55, 0xd6, 0xd8,
|
||||
0xd7, 0x5c, 0xd7, 0xe0, 0xd8, 0x64, 0xd8, 0xe8,
|
||||
0xd9, 0x6c, 0xd9, 0xf1, 0xda, 0x76, 0xda, 0xfb,
|
||||
0xdb, 0x80, 0xdc, 0x05, 0xdc, 0x8a, 0xdd, 0x10,
|
||||
0xdd, 0x96, 0xde, 0x1c, 0xde, 0xa2, 0xdf, 0x29,
|
||||
0xdf, 0xaf, 0xe0, 0x36, 0xe0, 0xbd, 0xe1, 0x44,
|
||||
0xe1, 0xcc, 0xe2, 0x53, 0xe2, 0xdb, 0xe3, 0x63,
|
||||
0xe3, 0xeb, 0xe4, 0x73, 0xe4, 0xfc, 0xe5, 0x84,
|
||||
0xe6, 0x0d, 0xe6, 0x96, 0xe7, 0x1f, 0xe7, 0xa9,
|
||||
0xe8, 0x32, 0xe8, 0xbc, 0xe9, 0x46, 0xe9, 0xd0,
|
||||
0xea, 0x5b, 0xea, 0xe5, 0xeb, 0x70, 0xeb, 0xfb,
|
||||
0xec, 0x86, 0xed, 0x11, 0xed, 0x9c, 0xee, 0x28,
|
||||
0xee, 0xb4, 0xef, 0x40, 0xef, 0xcc, 0xf0, 0x58,
|
||||
0xf0, 0xe5, 0xf1, 0x72, 0xf1, 0xff, 0xf2, 0x8c,
|
||||
0xf3, 0x19, 0xf3, 0xa7, 0xf4, 0x34, 0xf4, 0xc2,
|
||||
0xf5, 0x50, 0xf5, 0xde, 0xf6, 0x6d, 0xf6, 0xfb,
|
||||
0xf7, 0x8a, 0xf8, 0x19, 0xf8, 0xa8, 0xf9, 0x38,
|
||||
0xf9, 0xc7, 0xfa, 0x57, 0xfa, 0xe7, 0xfb, 0x77,
|
||||
0xfc, 0x07, 0xfc, 0x98, 0xfd, 0x29, 0xfd, 0xba,
|
||||
0xfe, 0x4b, 0xfe, 0xdc, 0xff, 0x6d, 0xff, 0xff
|
||||
};
|
||||
|
||||
int jas_iccprofdata_srgblen = sizeof(jas_iccprofdata_srgb);
|
||||
|
||||
uchar jas_iccprofdata_sgray[] = {
|
||||
0x00, 0x00, 0x01, 0x8a, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x20, 0x00, 0x00, 0x73, 0x63, 0x6e, 0x72,
|
||||
0x47, 0x52, 0x41, 0x59, 0x58, 0x59, 0x5a, 0x20,
|
||||
0x07, 0xd3, 0x00, 0x01, 0x00, 0x1f, 0x00, 0x0d,
|
||||
0x00, 0x35, 0x00, 0x21, 0x61, 0x63, 0x73, 0x70,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x4b, 0x4f, 0x44, 0x41, 0x73, 0x47, 0x72, 0x79,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6,
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d,
|
||||
0x4a, 0x50, 0x45, 0x47, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x04, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00, 0x86,
|
||||
0x63, 0x70, 0x72, 0x74, 0x00, 0x00, 0x01, 0x3c,
|
||||
0x00, 0x00, 0x00, 0x2b, 0x77, 0x74, 0x70, 0x74,
|
||||
0x00, 0x00, 0x01, 0x68, 0x00, 0x00, 0x00, 0x14,
|
||||
0x6b, 0x54, 0x52, 0x43, 0x00, 0x00, 0x01, 0x7c,
|
||||
0x00, 0x00, 0x00, 0x0e, 0x64, 0x65, 0x73, 0x63,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c,
|
||||
0x52, 0x65, 0x73, 0x74, 0x72, 0x69, 0x63, 0x74,
|
||||
0x65, 0x64, 0x20, 0x49, 0x43, 0x43, 0x20, 0x70,
|
||||
0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x64,
|
||||
0x65, 0x73, 0x63, 0x72, 0x69, 0x62, 0x69, 0x6e,
|
||||
0x67, 0x20, 0x73, 0x52, 0x47, 0x42, 0x2d, 0x67,
|
||||
0x72, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74,
|
||||
0x00, 0x00, 0x00, 0x00, 0x43, 0x6f, 0x70, 0x79,
|
||||
0x72, 0x69, 0x67, 0x68, 0x74, 0x20, 0x32, 0x30,
|
||||
0x30, 0x33, 0x20, 0x73, 0x52, 0x47, 0x42, 0x2d,
|
||||
0x67, 0x72, 0x65, 0x79, 0x20, 0x52, 0x65, 0x66,
|
||||
0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x00, 0x00,
|
||||
0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xf3, 0x54, 0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x01, 0x16, 0xcf, 0x63, 0x75, 0x72, 0x76,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x01, 0xcd
|
||||
};
|
||||
|
||||
int jas_iccprofdata_sgraylen = sizeof(jas_iccprofdata_sgray);
|
||||
Vendored
+1444
File diff suppressed because it is too large
Load Diff
Vendored
+162
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_image.h"
|
||||
#include "jasper/jas_init.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Initialize the image format table. */
|
||||
int jas_init()
|
||||
{
|
||||
jas_image_fmtops_t fmtops;
|
||||
int fmtid;
|
||||
|
||||
fmtid = 0;
|
||||
|
||||
#if !defined(EXCLUDE_MIF_SUPPORT)
|
||||
fmtops.decode = mif_decode;
|
||||
fmtops.encode = mif_encode;
|
||||
fmtops.validate = mif_validate;
|
||||
jas_image_addfmt(fmtid, "mif", "mif", "My Image Format (MIF)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_PNM_SUPPORT)
|
||||
fmtops.decode = pnm_decode;
|
||||
fmtops.encode = pnm_encode;
|
||||
fmtops.validate = pnm_validate;
|
||||
jas_image_addfmt(fmtid, "pnm", "pnm", "Portable Graymap/Pixmap (PNM)",
|
||||
&fmtops);
|
||||
jas_image_addfmt(fmtid, "pnm", "pgm", "Portable Graymap/Pixmap (PNM)",
|
||||
&fmtops);
|
||||
jas_image_addfmt(fmtid, "pnm", "ppm", "Portable Graymap/Pixmap (PNM)",
|
||||
&fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_BMP_SUPPORT)
|
||||
fmtops.decode = bmp_decode;
|
||||
fmtops.encode = bmp_encode;
|
||||
fmtops.validate = bmp_validate;
|
||||
jas_image_addfmt(fmtid, "bmp", "bmp", "Microsoft Bitmap (BMP)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_RAS_SUPPORT)
|
||||
fmtops.decode = ras_decode;
|
||||
fmtops.encode = ras_encode;
|
||||
fmtops.validate = ras_validate;
|
||||
jas_image_addfmt(fmtid, "ras", "ras", "Sun Rasterfile (RAS)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_JP2_SUPPORT)
|
||||
fmtops.decode = jp2_decode;
|
||||
fmtops.encode = jp2_encode;
|
||||
fmtops.validate = jp2_validate;
|
||||
jas_image_addfmt(fmtid, "jp2", "jp2",
|
||||
"JPEG-2000 JP2 File Format Syntax (ISO/IEC 15444-1)", &fmtops);
|
||||
++fmtid;
|
||||
fmtops.decode = jpc_decode;
|
||||
fmtops.encode = jpc_encode;
|
||||
fmtops.validate = jpc_validate;
|
||||
jas_image_addfmt(fmtid, "jpc", "jpc",
|
||||
"JPEG-2000 Code Stream Syntax (ISO/IEC 15444-1)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_JPG_SUPPORT)
|
||||
fmtops.decode = jpg_decode;
|
||||
fmtops.encode = jpg_encode;
|
||||
fmtops.validate = jpg_validate;
|
||||
jas_image_addfmt(fmtid, "jpg", "jpg", "JPEG (ISO/IEC 10918-1)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_PGX_SUPPORT)
|
||||
fmtops.decode = pgx_decode;
|
||||
fmtops.encode = pgx_encode;
|
||||
fmtops.validate = pgx_validate;
|
||||
jas_image_addfmt(fmtid, "pgx", "pgx", "JPEG-2000 VM Format (PGX)", &fmtops);
|
||||
++fmtid;
|
||||
#endif
|
||||
|
||||
/* We must not register the JasPer library exit handler until after
|
||||
at least one memory allocation is performed. This is desirable
|
||||
as it ensures that the JasPer exit handler is called before the
|
||||
debug memory allocator exit handler. */
|
||||
atexit(jas_cleanup);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jas_cleanup()
|
||||
{
|
||||
jas_image_clearfmts();
|
||||
}
|
||||
Vendored
+168
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Memory Allocator
|
||||
*
|
||||
* $Id: jas_malloc.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* We need the prototype for memset. */
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#if !defined _WIN32 || defined __MINGW__ || defined __MINGW32__
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
#if defined(DEBUG_MEMALLOC)
|
||||
#include "../../../local/src/memalloc.c"
|
||||
#endif
|
||||
|
||||
#if !defined(DEBUG_MEMALLOC)
|
||||
|
||||
#define MEMALLOC_ALIGNMENT 32
|
||||
#define MEMALLOC_ALIGN2
|
||||
#undef MEMALLOC_ALIGN2
|
||||
|
||||
void *jas_malloc(size_t size)
|
||||
{
|
||||
#if defined(MEMALLOC_ALIGN2)
|
||||
void *ptr;
|
||||
abort();
|
||||
if (posix_memalign(&ptr, MEMALLOC_ALIGNMENT, size)) {
|
||||
return 0;
|
||||
}
|
||||
return ptr;
|
||||
#endif
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void jas_free(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void *jas_realloc(void *ptr, size_t size)
|
||||
{
|
||||
return ptr ? realloc(ptr, size) : malloc(size);
|
||||
}
|
||||
|
||||
void *jas_realloc2(void *ptr, size_t nmemb, size_t size)
|
||||
{
|
||||
if (!ptr)
|
||||
return jas_alloc2(nmemb, size);
|
||||
if (nmemb && SIZE_MAX / nmemb < size) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
return jas_realloc(ptr, nmemb * size);
|
||||
|
||||
}
|
||||
|
||||
void *jas_alloc2(size_t nmemb, size_t size)
|
||||
{
|
||||
if (nmemb && SIZE_MAX / nmemb < size) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return jas_malloc(nmemb * size);
|
||||
}
|
||||
|
||||
void *jas_alloc3(size_t a, size_t b, size_t c)
|
||||
{
|
||||
size_t n;
|
||||
|
||||
if (a && SIZE_MAX / a < b) {
|
||||
errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return jas_alloc2(a*b, c);
|
||||
}
|
||||
|
||||
void *jas_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
ptr = jas_alloc2(nmemb, size);
|
||||
if (ptr)
|
||||
memset(ptr, 0, nmemb*size);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
Vendored
+454
@@ -0,0 +1,454 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sequence/Matrix Library
|
||||
*
|
||||
* $Id: jas_seq.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constructors and destructors.
|
||||
\******************************************************************************/
|
||||
|
||||
jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend)
|
||||
{
|
||||
jas_matrix_t *matrix;
|
||||
assert(xstart <= xend && ystart <= yend);
|
||||
if (!(matrix = jas_matrix_create(yend - ystart, xend - xstart))) {
|
||||
return 0;
|
||||
}
|
||||
matrix->xstart_ = xstart;
|
||||
matrix->ystart_ = ystart;
|
||||
matrix->xend_ = xend;
|
||||
matrix->yend_ = yend;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
jas_matrix_t *jas_matrix_create(int numrows, int numcols)
|
||||
{
|
||||
jas_matrix_t *matrix;
|
||||
int i;
|
||||
|
||||
if (!(matrix = jas_malloc(sizeof(jas_matrix_t)))) {
|
||||
return 0;
|
||||
}
|
||||
matrix->flags_ = 0;
|
||||
matrix->numrows_ = numrows;
|
||||
matrix->numcols_ = numcols;
|
||||
matrix->rows_ = 0;
|
||||
matrix->maxrows_ = numrows;
|
||||
matrix->data_ = 0;
|
||||
matrix->datasize_ = numrows * numcols;
|
||||
|
||||
if (matrix->maxrows_ > 0) {
|
||||
if (!(matrix->rows_ = jas_alloc2(matrix->maxrows_,
|
||||
sizeof(jas_seqent_t *)))) {
|
||||
jas_matrix_destroy(matrix);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (matrix->datasize_ > 0) {
|
||||
if (!(matrix->data_ = jas_alloc2(matrix->datasize_,
|
||||
sizeof(jas_seqent_t)))) {
|
||||
jas_matrix_destroy(matrix);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < numrows; ++i) {
|
||||
matrix->rows_[i] = &matrix->data_[i * matrix->numcols_];
|
||||
}
|
||||
|
||||
for (i = 0; i < matrix->datasize_; ++i) {
|
||||
matrix->data_[i] = 0;
|
||||
}
|
||||
|
||||
matrix->xstart_ = 0;
|
||||
matrix->ystart_ = 0;
|
||||
matrix->xend_ = matrix->numcols_;
|
||||
matrix->yend_ = matrix->numrows_;
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void jas_matrix_destroy(jas_matrix_t *matrix)
|
||||
{
|
||||
if (matrix->data_) {
|
||||
assert(!(matrix->flags_ & JAS_MATRIX_REF));
|
||||
jas_free(matrix->data_);
|
||||
matrix->data_ = 0;
|
||||
}
|
||||
if (matrix->rows_) {
|
||||
jas_free(matrix->rows_);
|
||||
matrix->rows_ = 0;
|
||||
}
|
||||
jas_free(matrix);
|
||||
}
|
||||
|
||||
jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x)
|
||||
{
|
||||
jas_matrix_t *y;
|
||||
int i;
|
||||
int j;
|
||||
y = jas_seq2d_create(jas_seq2d_xstart(x), jas_seq2d_ystart(x), jas_seq2d_xend(x),
|
||||
jas_seq2d_yend(x));
|
||||
assert(y);
|
||||
for (i = 0; i < x->numrows_; ++i) {
|
||||
for (j = 0; j < x->numcols_; ++j) {
|
||||
*jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j);
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
jas_matrix_t *jas_matrix_copy(jas_matrix_t *x)
|
||||
{
|
||||
jas_matrix_t *y;
|
||||
int i;
|
||||
int j;
|
||||
y = jas_matrix_create(x->numrows_, x->numcols_);
|
||||
for (i = 0; i < x->numrows_; ++i) {
|
||||
for (j = 0; j < x->numcols_; ++j) {
|
||||
*jas_matrix_getref(y, i, j) = jas_matrix_get(x, i, j);
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Bind operations.
|
||||
\******************************************************************************/
|
||||
|
||||
void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart, int ystart,
|
||||
int xend, int yend)
|
||||
{
|
||||
jas_matrix_bindsub(s, s1, ystart - s1->ystart_, xstart - s1->xstart_,
|
||||
yend - s1->ystart_ - 1, xend - s1->xstart_ - 1);
|
||||
}
|
||||
|
||||
void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0,
|
||||
int r1, int c1)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (mat0->data_) {
|
||||
if (!(mat0->flags_ & JAS_MATRIX_REF)) {
|
||||
jas_free(mat0->data_);
|
||||
}
|
||||
mat0->data_ = 0;
|
||||
mat0->datasize_ = 0;
|
||||
}
|
||||
if (mat0->rows_) {
|
||||
jas_free(mat0->rows_);
|
||||
mat0->rows_ = 0;
|
||||
}
|
||||
mat0->flags_ |= JAS_MATRIX_REF;
|
||||
mat0->numrows_ = r1 - r0 + 1;
|
||||
mat0->numcols_ = c1 - c0 + 1;
|
||||
mat0->maxrows_ = mat0->numrows_;
|
||||
mat0->rows_ = jas_alloc2(mat0->maxrows_, sizeof(jas_seqent_t *));
|
||||
for (i = 0; i < mat0->numrows_; ++i) {
|
||||
mat0->rows_[i] = mat1->rows_[r0 + i] + c0;
|
||||
}
|
||||
|
||||
mat0->xstart_ = mat1->xstart_ + c0;
|
||||
mat0->ystart_ = mat1->ystart_ + r0;
|
||||
mat0->xend_ = mat0->xstart_ + mat0->numcols_;
|
||||
mat0->yend_ = mat0->ystart_ + mat0->numrows_;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Arithmetic operations.
|
||||
\******************************************************************************/
|
||||
|
||||
int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
if (mat0->numrows_ != mat1->numrows_ || mat0->numcols_ !=
|
||||
mat1->numcols_) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < mat0->numrows_; i++) {
|
||||
for (j = 0; j < mat0->numcols_; j++) {
|
||||
if (jas_matrix_get(mat0, i, j) != jas_matrix_get(mat1, i, j)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jas_matrix_divpow2(jas_matrix_t *matrix, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t *rowstart;
|
||||
int rowstep;
|
||||
jas_seqent_t *data;
|
||||
|
||||
rowstep = jas_matrix_rowstep(matrix);
|
||||
for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
|
||||
rowstart += rowstep) {
|
||||
for (j = matrix->numcols_, data = rowstart; j > 0; --j,
|
||||
++data) {
|
||||
*data = (*data >= 0) ? ((*data) >> n) :
|
||||
(-((-(*data)) >> n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval, jas_seqent_t maxval)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t v;
|
||||
jas_seqent_t *rowstart;
|
||||
jas_seqent_t *data;
|
||||
int rowstep;
|
||||
|
||||
rowstep = jas_matrix_rowstep(matrix);
|
||||
for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
|
||||
rowstart += rowstep) {
|
||||
data = rowstart;
|
||||
for (j = matrix->numcols_, data = rowstart; j > 0; --j,
|
||||
++data) {
|
||||
v = *data;
|
||||
if (v < minval) {
|
||||
*data = minval;
|
||||
} else if (v > maxval) {
|
||||
*data = maxval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jas_matrix_asr(jas_matrix_t *matrix, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t *rowstart;
|
||||
int rowstep;
|
||||
jas_seqent_t *data;
|
||||
|
||||
assert(n >= 0);
|
||||
rowstep = jas_matrix_rowstep(matrix);
|
||||
for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
|
||||
rowstart += rowstep) {
|
||||
for (j = matrix->numcols_, data = rowstart; j > 0; --j,
|
||||
++data) {
|
||||
*data >>= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jas_matrix_asl(jas_matrix_t *matrix, int n)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t *rowstart;
|
||||
int rowstep;
|
||||
jas_seqent_t *data;
|
||||
|
||||
rowstep = jas_matrix_rowstep(matrix);
|
||||
for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
|
||||
rowstart += rowstep) {
|
||||
for (j = matrix->numcols_, data = rowstart; j > 0; --j,
|
||||
++data) {
|
||||
*data <<= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols)
|
||||
{
|
||||
int size;
|
||||
int i;
|
||||
|
||||
size = numrows * numcols;
|
||||
if (size > matrix->datasize_ || numrows > matrix->maxrows_) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
matrix->numrows_ = numrows;
|
||||
matrix->numcols_ = numcols;
|
||||
|
||||
for (i = 0; i < numrows; ++i) {
|
||||
matrix->rows_[i] = &matrix->data_[numcols * i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t *rowstart;
|
||||
int rowstep;
|
||||
jas_seqent_t *data;
|
||||
|
||||
rowstep = jas_matrix_rowstep(matrix);
|
||||
for (i = matrix->numrows_, rowstart = matrix->rows_[0]; i > 0; --i,
|
||||
rowstart += rowstep) {
|
||||
for (j = matrix->numcols_, data = rowstart; j > 0; --j,
|
||||
++data) {
|
||||
*data = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jas_matrix_t *jas_seq2d_input(FILE *in)
|
||||
{
|
||||
jas_matrix_t *matrix;
|
||||
int i;
|
||||
int j;
|
||||
long x;
|
||||
int numrows;
|
||||
int numcols;
|
||||
int xoff;
|
||||
int yoff;
|
||||
|
||||
if (fscanf(in, "%d %d", &xoff, &yoff) != 2)
|
||||
return 0;
|
||||
if (fscanf(in, "%d %d", &numcols, &numrows) != 2)
|
||||
return 0;
|
||||
if (!(matrix = jas_seq2d_create(xoff, yoff, xoff + numcols, yoff + numrows)))
|
||||
return 0;
|
||||
|
||||
if (jas_matrix_numrows(matrix) != numrows || jas_matrix_numcols(matrix) != numcols) {
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Get matrix data. */
|
||||
for (i = 0; i < jas_matrix_numrows(matrix); i++) {
|
||||
for (j = 0; j < jas_matrix_numcols(matrix); j++) {
|
||||
if (fscanf(in, "%ld", &x) != 1) {
|
||||
jas_matrix_destroy(matrix);
|
||||
return 0;
|
||||
}
|
||||
jas_matrix_set(matrix, i, j, JAS_CAST(jas_seqent_t, x));
|
||||
}
|
||||
}
|
||||
|
||||
return matrix;
|
||||
}
|
||||
|
||||
int jas_seq2d_output(jas_matrix_t *matrix, FILE *out)
|
||||
{
|
||||
#define MAXLINELEN 80
|
||||
int i;
|
||||
int j;
|
||||
jas_seqent_t x;
|
||||
char buf[MAXLINELEN + 1];
|
||||
char sbuf[MAXLINELEN + 1];
|
||||
int n;
|
||||
|
||||
fprintf(out, "%d %d\n", (int)jas_seq2d_xstart(matrix),
|
||||
(int)jas_seq2d_ystart(matrix));
|
||||
fprintf(out, "%d %d\n", (int)jas_matrix_numcols(matrix),
|
||||
(int)jas_matrix_numrows(matrix));
|
||||
|
||||
buf[0] = '\0';
|
||||
for (i = 0; i < jas_matrix_numrows(matrix); ++i) {
|
||||
for (j = 0; j < jas_matrix_numcols(matrix); ++j) {
|
||||
x = jas_matrix_get(matrix, i, j);
|
||||
sprintf(sbuf, "%s%4ld", (strlen(buf) > 0) ? " " : "",
|
||||
JAS_CAST(long, x));
|
||||
n = strlen(buf);
|
||||
if (n + strlen(sbuf) > MAXLINELEN) {
|
||||
fputs(buf, out);
|
||||
fputs("\n", out);
|
||||
buf[0] = '\0';
|
||||
}
|
||||
strcat(buf, sbuf);
|
||||
if (j == jas_matrix_numcols(matrix) - 1) {
|
||||
fputs(buf, out);
|
||||
fputs("\n", out);
|
||||
buf[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
fputs(buf, out);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+1159
File diff suppressed because it is too large
Load Diff
Vendored
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* String Library
|
||||
*
|
||||
* $Id: jas_string.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_string.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous Functions
|
||||
\******************************************************************************/
|
||||
|
||||
/* This function is equivalent to the popular but non-standard (and
|
||||
not-always-available) strdup function. */
|
||||
|
||||
char *jas_strdup(const char *s)
|
||||
{
|
||||
int n;
|
||||
char *p;
|
||||
n = strlen(s) + 1;
|
||||
if (!(p = jas_malloc(n * sizeof(char)))) {
|
||||
return 0;
|
||||
}
|
||||
strcpy(p, s);
|
||||
return p;
|
||||
}
|
||||
Vendored
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Timing Routines
|
||||
*
|
||||
* $Id: jas_tmr.c,v 1.1 2008-05-26 09:40:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "jasper/jas_tmr.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
#if defined(HAVE_GETTIMEOFDAY)
|
||||
|
||||
void jas_tmr_start(jas_tmr_t *tmr)
|
||||
{
|
||||
if (gettimeofday(&tmr->start, 0)) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void jas_tmr_stop(jas_tmr_t *tmr)
|
||||
{
|
||||
if (gettimeofday(&tmr->stop, 0)) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
double jas_tmr_get(jas_tmr_t *tmr)
|
||||
{
|
||||
double t0;
|
||||
double t1;
|
||||
t0 = ((double) tmr->start.tv_sec) + ((double) tmr->start.tv_usec) / 1e6;
|
||||
t1 = ((double) tmr->stop.tv_sec) + ((double) tmr->stop.tv_usec) / 1e6;
|
||||
return t1 - t0;
|
||||
}
|
||||
|
||||
#elif defined(HAVE_GETRUSAGE)
|
||||
|
||||
void jas_tmr_start(jas_tmr_t *tmr)
|
||||
{
|
||||
if (getrusage(RUSAGE_SELF, &tmr->start) < 0) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void jas_tmr_stop(jas_tmr_t *tmr)
|
||||
{
|
||||
if (getrusage(RUSAGE_SELF, &tmr->stop) < 0) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
double jas_tmr_get(jas_tmr_t *tmr)
|
||||
{
|
||||
double t;
|
||||
t = ((tmr->stop.ru_utime.tv_sec * 1e6 + tmr->stop.ru_utime.tv_usec) -
|
||||
(tmr->start.ru_utime.tv_sec * 1e6 + tmr->start.ru_utime.tv_usec)) / 1e6;
|
||||
t += ((tmr->stop.ru_stime.tv_sec * 1e6 + tmr->stop.ru_stime.tv_usec) -
|
||||
(tmr->start.ru_stime.tv_sec * 1e6 + tmr->start.ru_stime.tv_usec)) / 1e6;
|
||||
return t;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void jas_tmr_start(jas_tmr_t *tmr)
|
||||
{
|
||||
}
|
||||
|
||||
void jas_tmr_stop(jas_tmr_t *tmr)
|
||||
{
|
||||
}
|
||||
|
||||
double jas_tmr_get(jas_tmr_t *tmr)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Vendored
+237
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tag-Value Parser Library
|
||||
*
|
||||
* $Id: jas_tvp.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_string.h"
|
||||
#include "jasper/jas_tvp.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Is the specified character valid for a tag name? */
|
||||
#define JAS_TVP_ISTAG(x) \
|
||||
(isalpha(x) || (x) == '_' || isdigit(x))
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for creating and destroying a tag-value parser.
|
||||
\******************************************************************************/
|
||||
|
||||
jas_tvparser_t *jas_tvparser_create(const char *s)
|
||||
{
|
||||
jas_tvparser_t *tvp;
|
||||
if (!(tvp = jas_malloc(sizeof(jas_tvparser_t)))) {
|
||||
return 0;
|
||||
}
|
||||
if (!(tvp->buf = jas_strdup(s))) {
|
||||
jas_tvparser_destroy(tvp);
|
||||
return 0;
|
||||
}
|
||||
tvp->pos = tvp->buf;
|
||||
tvp->tag = 0;
|
||||
tvp->val = 0;
|
||||
return tvp;
|
||||
}
|
||||
|
||||
void jas_tvparser_destroy(jas_tvparser_t *tvp)
|
||||
{
|
||||
if (tvp->buf) {
|
||||
jas_free(tvp->buf);
|
||||
}
|
||||
jas_free(tvp);
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Main parsing code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the next tag-value pair. */
|
||||
int jas_tvparser_next(jas_tvparser_t *tvp)
|
||||
{
|
||||
char *p;
|
||||
char *tag;
|
||||
char *val;
|
||||
|
||||
/* Skip any leading whitespace. */
|
||||
p = tvp->pos;
|
||||
while (*p != '\0' && isspace(*p)) {
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Has the end of the input data been reached? */
|
||||
if (*p == '\0') {
|
||||
/* No more tags are present. */
|
||||
tvp->pos = p;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Does the tag name begin with a valid character? */
|
||||
if (!JAS_TVP_ISTAG(*p)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Remember where the tag name begins. */
|
||||
tag = p;
|
||||
|
||||
/* Find the end of the tag name. */
|
||||
while (*p != '\0' && JAS_TVP_ISTAG(*p)) {
|
||||
++p;
|
||||
}
|
||||
|
||||
/* Has the end of the input data been reached? */
|
||||
if (*p == '\0') {
|
||||
/* The value field is empty. */
|
||||
tvp->tag = tag;
|
||||
tvp->val = "";
|
||||
tvp->pos = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Is a value field not present? */
|
||||
if (*p != '=') {
|
||||
if (*p != '\0' && !isspace(*p)) {
|
||||
return -1;
|
||||
}
|
||||
*p++ = '\0';
|
||||
tvp->tag = tag;
|
||||
tvp->val = "";
|
||||
tvp->pos = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*p++ = '\0';
|
||||
|
||||
val = p;
|
||||
while (*p != '\0' && !isspace(*p)) {
|
||||
++p;
|
||||
}
|
||||
|
||||
if (*p != '\0') {
|
||||
*p++ = '\0';
|
||||
}
|
||||
|
||||
tvp->pos = p;
|
||||
tvp->tag = tag;
|
||||
tvp->val = val;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for querying the current tag/value.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the current tag. */
|
||||
char *jas_tvparser_gettag(jas_tvparser_t *tvp)
|
||||
{
|
||||
return tvp->tag;
|
||||
}
|
||||
|
||||
/* Get the current value. */
|
||||
char *jas_tvparser_getval(jas_tvparser_t *tvp)
|
||||
{
|
||||
return tvp->val;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Lookup a tag by name. */
|
||||
jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name)
|
||||
{
|
||||
jas_taginfo_t *taginfo;
|
||||
taginfo = taginfos;
|
||||
while (taginfo->id >= 0) {
|
||||
if (!strcmp(taginfo->name, name)) {
|
||||
return taginfo;
|
||||
}
|
||||
++taginfo;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This function is simply for convenience. */
|
||||
/* One can avoid testing for the special case of a null pointer, by
|
||||
using this function. This function never returns a null pointer. */
|
||||
jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo)
|
||||
{
|
||||
static jas_taginfo_t invalidtaginfo = {
|
||||
-1, 0
|
||||
};
|
||||
|
||||
return taginfo ? taginfo : &invalidtaginfo;
|
||||
}
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#include "jasper/jas_version.h"
|
||||
|
||||
const char *jas_getversion()
|
||||
{
|
||||
return JAS_VERSION;
|
||||
}
|
||||
Vendored
+266
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Color Management
|
||||
*
|
||||
* $Id: jas_cm.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_CM_H
|
||||
#define JAS_CM_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_icc.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int jas_clrspc_t;
|
||||
|
||||
/* transform operations */
|
||||
#define JAS_CMXFORM_OP_FWD 0
|
||||
#define JAS_CMXFORM_OP_REV 1
|
||||
#define JAS_CMXFORM_OP_PROOF 2
|
||||
#define JAS_CMXFORM_OP_GAMUT 3
|
||||
|
||||
/* rendering intents */
|
||||
#define JAS_CMXFORM_INTENT_PER 0
|
||||
#define JAS_CMXFORM_INTENT_RELCLR 1
|
||||
#define JAS_CMXFORM_INTENT_ABSCLR 2
|
||||
#define JAS_CMXFORM_INTENT_SAT 3
|
||||
#define JAS_CMXFORM_NUMINTENTS 4
|
||||
|
||||
#define JAS_CMXFORM_OPTM_SPEED 0
|
||||
#define JAS_CMXFORM_OPTM_SIZE 1
|
||||
#define JAS_CMXFORM_OPTM_ACC 2
|
||||
|
||||
|
||||
#define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
|
||||
#define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
|
||||
#define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
|
||||
#define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
|
||||
#define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
|
||||
|
||||
#define JAS_CLRSPC_UNKNOWNMASK 0x4000
|
||||
|
||||
/* color space families */
|
||||
#define JAS_CLRSPC_FAM_UNKNOWN 0
|
||||
#define JAS_CLRSPC_FAM_XYZ 1
|
||||
#define JAS_CLRSPC_FAM_LAB 2
|
||||
#define JAS_CLRSPC_FAM_GRAY 3
|
||||
#define JAS_CLRSPC_FAM_RGB 4
|
||||
#define JAS_CLRSPC_FAM_YCBCR 5
|
||||
|
||||
/* specific color spaces */
|
||||
#define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
|
||||
#define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
|
||||
#define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
|
||||
#define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
|
||||
#define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
|
||||
#define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
|
||||
|
||||
/* generic color spaces */
|
||||
#define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
|
||||
#define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
|
||||
#define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
|
||||
|
||||
#define JAS_CLRSPC_CHANIND_YCBCR_Y 0
|
||||
#define JAS_CLRSPC_CHANIND_YCBCR_CB 1
|
||||
#define JAS_CLRSPC_CHANIND_YCBCR_CR 2
|
||||
|
||||
#define JAS_CLRSPC_CHANIND_RGB_R 0
|
||||
#define JAS_CLRSPC_CHANIND_RGB_G 1
|
||||
#define JAS_CLRSPC_CHANIND_RGB_B 2
|
||||
|
||||
#define JAS_CLRSPC_CHANIND_GRAY_Y 0
|
||||
|
||||
typedef double jas_cmreal_t;
|
||||
|
||||
struct jas_cmpxform_s;
|
||||
|
||||
typedef struct {
|
||||
long *buf;
|
||||
int prec;
|
||||
int sgnd;
|
||||
int width;
|
||||
int height;
|
||||
} jas_cmcmptfmt_t;
|
||||
|
||||
typedef struct {
|
||||
int numcmpts;
|
||||
jas_cmcmptfmt_t *cmptfmts;
|
||||
} jas_cmpixmap_t;
|
||||
|
||||
typedef struct {
|
||||
void (*destroy)(struct jas_cmpxform_s *pxform);
|
||||
int (*apply)(struct jas_cmpxform_s *pxform, jas_cmreal_t *in, jas_cmreal_t *out, int cnt);
|
||||
void (*dump)(struct jas_cmpxform_s *pxform);
|
||||
} jas_cmpxformops_t;
|
||||
|
||||
typedef struct {
|
||||
jas_cmreal_t *data;
|
||||
int size;
|
||||
} jas_cmshapmatlut_t;
|
||||
|
||||
typedef struct {
|
||||
int mono;
|
||||
int order;
|
||||
int useluts;
|
||||
int usemat;
|
||||
jas_cmshapmatlut_t luts[3];
|
||||
jas_cmreal_t mat[3][4];
|
||||
} jas_cmshapmat_t;
|
||||
|
||||
typedef struct {
|
||||
int order;
|
||||
} jas_cmshaplut_t;
|
||||
|
||||
typedef struct {
|
||||
int inclrspc;
|
||||
int outclrspc;
|
||||
} jas_cmclrspcconv_t;
|
||||
|
||||
#define jas_align_t double
|
||||
|
||||
typedef struct jas_cmpxform_s {
|
||||
int refcnt;
|
||||
jas_cmpxformops_t *ops;
|
||||
int numinchans;
|
||||
int numoutchans;
|
||||
union {
|
||||
jas_align_t dummy;
|
||||
jas_cmshapmat_t shapmat;
|
||||
jas_cmshaplut_t shaplut;
|
||||
jas_cmclrspcconv_t clrspcconv;
|
||||
} data;
|
||||
} jas_cmpxform_t;
|
||||
|
||||
typedef struct {
|
||||
int numpxforms;
|
||||
int maxpxforms;
|
||||
jas_cmpxform_t **pxforms;
|
||||
} jas_cmpxformseq_t;
|
||||
|
||||
typedef struct {
|
||||
int numinchans;
|
||||
int numoutchans;
|
||||
jas_cmpxformseq_t *pxformseq;
|
||||
} jas_cmxform_t;
|
||||
|
||||
#define JAS_CMPROF_TYPE_DEV 1
|
||||
#define JAS_CMPROF_TYPE_CLRSPC 2
|
||||
|
||||
#define JAS_CMPROF_NUMPXFORMSEQS 13
|
||||
|
||||
typedef struct {
|
||||
int clrspc;
|
||||
int numchans;
|
||||
int refclrspc;
|
||||
int numrefchans;
|
||||
jas_iccprof_t *iccprof;
|
||||
jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
|
||||
} jas_cmprof_t;
|
||||
|
||||
/* Create a profile. */
|
||||
|
||||
/* Destroy a profile. */
|
||||
void jas_cmprof_destroy(jas_cmprof_t *prof);
|
||||
|
||||
#if 0
|
||||
typedef int_fast32_t jas_cmattrname_t;
|
||||
typedef int_fast32_t jas_cmattrval_t;
|
||||
typedef int_fast32_t jas_cmattrtype_t;
|
||||
/* Load a profile. */
|
||||
int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, int fmt);
|
||||
/* Save a profile. */
|
||||
int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, int fmt);
|
||||
/* Set an attribute of a profile. */
|
||||
int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
|
||||
/* Get an attribute of a profile. */
|
||||
void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
|
||||
#endif
|
||||
|
||||
jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,
|
||||
jas_cmprof_t *proofprof, int op, int intent, int optimize);
|
||||
|
||||
void jas_cmxform_destroy(jas_cmxform_t *xform);
|
||||
|
||||
/* Apply a transform to data. */
|
||||
int jas_cmxform_apply(jas_cmxform_t *xform, jas_cmpixmap_t *in,
|
||||
jas_cmpixmap_t *out);
|
||||
|
||||
int jas_cxform_optimize(jas_cmxform_t *xform, int optimize);
|
||||
|
||||
int jas_clrspc_numchans(int clrspc);
|
||||
jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof);
|
||||
jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc);
|
||||
jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof);
|
||||
|
||||
#define jas_cmprof_clrspc(prof) ((prof)->clrspc)
|
||||
jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
/* src/libjasper/include/jasper/jas_config.h. Generated by configure. */
|
||||
/* src/libjasper/include/jasper/jas_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
|
||||
/* Avoid problems due to multiple inclusion. */
|
||||
#ifndef JAS_CONFIG_H
|
||||
#define JAS_CONFIG_H
|
||||
|
||||
/* This preprocessor symbol identifies the version of JasPer. */
|
||||
#define JAS_VERSION "1.900.1"
|
||||
/* If configure is being used, this symbol will be defined automatically
|
||||
at this point in the configuration header file. */
|
||||
|
||||
/* The preprocessor symbol JAS_WIN_MSVC_BUILD should not be defined
|
||||
unless the JasPer software is being built under Microsoft Windows
|
||||
using Microsoft Visual C. */
|
||||
#if !defined(JAS_WIN_MSVC_BUILD)
|
||||
/* A configure-based build is being used. */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// uClibc-ng workaround: https://github.com/opencv/opencv/pull/15279
|
||||
#ifndef L_tmpnam
|
||||
#define L_tmpnam 20
|
||||
#endif
|
||||
|
||||
|
||||
/* Extra debugging support */
|
||||
/* #undef DEBUG */
|
||||
|
||||
/* Debugging memory allocator */
|
||||
/* #undef DEBUG_MEMALLOC */
|
||||
|
||||
/* Debugging overflow detection */
|
||||
/* #undef DEBUG_OVERFLOW */
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `getrusage' function. */
|
||||
#define HAVE_GETRUSAGE 1
|
||||
|
||||
/* Define to 1 if you have the `gettimeofday' function. */
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
/* #undef HAVE_IO_H */
|
||||
|
||||
/* Define to 1 if you have the `m' library (-lm). */
|
||||
#define HAVE_LIBM 1
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#define HAVE_STDBOOL_H 1
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Have variable length arrays */
|
||||
#define HAVE_VLA 1
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
/* #undef HAVE_WINDOWS_H */
|
||||
|
||||
/* JasPer configure */
|
||||
#define JAS_CONFIGURE 1
|
||||
|
||||
/* JasPer version */
|
||||
#define JAS_VERSION "1.900.1"
|
||||
|
||||
/* Name of package */
|
||||
#define PACKAGE "jasper"
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME "jasper"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "jasper 1.900.1"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "jasper"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.900.1"
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.900.1"
|
||||
|
||||
/* Define to 1 if the X Window System is missing or not being used. */
|
||||
/* #undef X_DISPLAY_MISSING */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
/* #undef inline */
|
||||
#endif
|
||||
|
||||
/* Define to `long long' if <sys/types.h> does not define. */
|
||||
#define longlong long long
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef ssize_t */
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#define uchar unsigned char
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
/* #undef uint */
|
||||
|
||||
/* Define to `unsigned long' if <sys/types.h> does not define. */
|
||||
/* #undef ulong */
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#define ulonglong unsigned long long
|
||||
|
||||
/* Define to `unsigned short' if <sys/types.h> does not define. */
|
||||
/* #undef ushort */
|
||||
|
||||
|
||||
#else
|
||||
/* A configure-based build is not being used. */
|
||||
#include <jasper/jas_config2.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+172
@@ -0,0 +1,172 @@
|
||||
/* src/libjasper/include/jasper/jas_config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
|
||||
/* Avoid problems due to multiple inclusion. */
|
||||
#ifndef JAS_CONFIG_H
|
||||
#define JAS_CONFIG_H
|
||||
|
||||
/* This preprocessor symbol identifies the version of JasPer. */
|
||||
#undef JAS_VERSION
|
||||
/* If configure is being used, this symbol will be defined automatically
|
||||
at this point in the configuration header file. */
|
||||
|
||||
/* The preprocessor symbol JAS_WIN_MSVC_BUILD should not be defined
|
||||
unless the JasPer software is being built under Microsoft Windows
|
||||
using Microsoft Visual C. */
|
||||
#if !defined(JAS_WIN_MSVC_BUILD)
|
||||
/* A configure-based build is being used. */
|
||||
|
||||
|
||||
|
||||
/* Extra debugging support */
|
||||
#undef DEBUG
|
||||
|
||||
/* Debugging memory allocator */
|
||||
#undef DEBUG_MEMALLOC
|
||||
|
||||
/* Debugging overflow detection */
|
||||
#undef DEBUG_OVERFLOW
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
#undef HAVE_DOPRNT
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#undef HAVE_FCNTL_H
|
||||
|
||||
/* Define to 1 if you have the `getrusage' function. */
|
||||
#undef HAVE_GETRUSAGE
|
||||
|
||||
/* Define to 1 if you have the `gettimeofday' function. */
|
||||
#undef HAVE_GETTIMEOFDAY
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the <io.h> header file. */
|
||||
#undef HAVE_IO_H
|
||||
|
||||
/* Define to 1 if you have the `m' library (-lm). */
|
||||
#undef HAVE_LIBM
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#undef HAVE_LIMITS_H
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#undef HAVE_MEMORY_H
|
||||
|
||||
/* Define to 1 if you have the <stdbool.h> header file. */
|
||||
#undef HAVE_STDBOOL_H
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#undef HAVE_STDDEF_H
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#undef HAVE_STDINT_H
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#undef HAVE_STDLIB_H
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#undef HAVE_STRING_H
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#undef HAVE_SYS_STAT_H
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#undef HAVE_SYS_TIME_H
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#undef HAVE_SYS_TYPES_H
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Have variable length arrays */
|
||||
#undef HAVE_VLA
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#undef HAVE_VPRINTF
|
||||
|
||||
/* Define to 1 if you have the <windows.h> header file. */
|
||||
#undef HAVE_WINDOWS_H
|
||||
|
||||
/* JasPer configure */
|
||||
#undef JAS_CONFIGURE
|
||||
|
||||
/* JasPer version */
|
||||
#undef JAS_VERSION
|
||||
|
||||
/* Name of package */
|
||||
#undef PACKAGE
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#undef PACKAGE_BUGREPORT
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#undef PACKAGE_NAME
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#undef PACKAGE_STRING
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#undef STDC_HEADERS
|
||||
|
||||
/* Version number of package */
|
||||
#undef VERSION
|
||||
|
||||
/* Define to 1 if the X Window System is missing or not being used. */
|
||||
#undef X_DISPLAY_MISSING
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
#undef inline
|
||||
#endif
|
||||
|
||||
/* Define to `long long' if <sys/types.h> does not define. */
|
||||
#undef longlong
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
#undef size_t
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
#undef ssize_t
|
||||
|
||||
/* Define to `unsigned char' if <sys/types.h> does not define. */
|
||||
#undef uchar
|
||||
|
||||
/* Define to `unsigned int' if <sys/types.h> does not define. */
|
||||
#undef uint
|
||||
|
||||
/* Define to `unsigned long' if <sys/types.h> does not define. */
|
||||
#undef ulong
|
||||
|
||||
/* Define to `unsigned long long' if <sys/types.h> does not define. */
|
||||
#undef ulonglong
|
||||
|
||||
/* Define to `unsigned short' if <sys/types.h> does not define. */
|
||||
#undef ushort
|
||||
|
||||
|
||||
#else
|
||||
/* A configure-based build is not being used. */
|
||||
#include <jasper/jas_config2.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JAS_CONFIG2_H
|
||||
#define JAS_CONFIG2_H
|
||||
|
||||
/*
|
||||
* Configuration for Microsoft Windows and Microsoft Visual C.
|
||||
*
|
||||
* We are not using a configure-based build.
|
||||
* Try to compensate for this here, by specifying the preprocessor symbols
|
||||
* normally defined by configure.
|
||||
*/
|
||||
|
||||
#define uchar unsigned char
|
||||
#define ushort unsigned short
|
||||
#define uint unsigned int
|
||||
#define ulong unsigned long
|
||||
#define longlong long long
|
||||
#define ulonglong unsigned long long
|
||||
/*#define ssize_t int*/
|
||||
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_IO_H 1
|
||||
#define HAVE_WINDOWS_H 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
#define EXCLUDE_JPG_SUPPORT 1
|
||||
#define EXCLUDE_MIF_SUPPORT 1
|
||||
#define EXCLUDE_PNM_SUPPORT 1
|
||||
#define EXCLUDE_PNM_SUPPORT 1
|
||||
#define EXCLUDE_RAS_SUPPORT 1
|
||||
#define EXCLUDE_BMP_SUPPORT 1
|
||||
#define EXCLUDE_PGX_SUPPORT 1
|
||||
|
||||
#endif
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Debugging-Related Code
|
||||
*
|
||||
* $Id: jas_debug.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_DEBUG_H
|
||||
#define JAS_DEBUG_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros and functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Output debugging information to standard error provided that the debug
|
||||
level is set sufficiently high. */
|
||||
#if defined(DEBUG)
|
||||
#define JAS_DBGLOG(n, x) \
|
||||
((jas_getdbglevel() >= (n)) ? (jas_eprintf x) : 0)
|
||||
#else
|
||||
#define JAS_DBGLOG(n, x)
|
||||
#endif
|
||||
|
||||
/* Get the library debug level. */
|
||||
int jas_getdbglevel(void);
|
||||
|
||||
/* Set the library debug level. */
|
||||
int jas_setdbglevel(int dbglevel);
|
||||
|
||||
/* Perform formatted output to standard error. */
|
||||
int jas_eprintf(const char *fmt, ...);
|
||||
|
||||
/* Dump memory to a stream. */
|
||||
int jas_memdump(FILE *out, void *data, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+358
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Fixed-Point Number Class
|
||||
*
|
||||
* $Id: jas_fix.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_FIX_H
|
||||
#define JAS_FIX_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The representation of the value zero. */
|
||||
#define JAS_FIX_ZERO(fix_t, fracbits) \
|
||||
JAS_CAST(fix_t, 0)
|
||||
|
||||
/* The representation of the value one. */
|
||||
#define JAS_FIX_ONE(fix_t, fracbits) \
|
||||
(JAS_CAST(fix_t, 1) << (fracbits))
|
||||
|
||||
/* The representation of the value one half. */
|
||||
#define JAS_FIX_HALF(fix_t, fracbits) \
|
||||
(JAS_CAST(fix_t, 1) << ((fracbits) - 1))
|
||||
|
||||
/******************************************************************************\
|
||||
* Conversion operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Convert an int to a fixed-point number. */
|
||||
#define JAS_INTTOFIX(fix_t, fracbits, x) \
|
||||
JAS_CAST(fix_t, (x) << (fracbits))
|
||||
|
||||
/* Convert a fixed-point number to an int. */
|
||||
#define JAS_FIXTOINT(fix_t, fracbits, x) \
|
||||
JAS_CAST(int, (x) >> (fracbits))
|
||||
|
||||
/* Convert a fixed-point number to a double. */
|
||||
#define JAS_FIXTODBL(fix_t, fracbits, x) \
|
||||
(JAS_CAST(double, x) / (JAS_CAST(fix_t, 1) << (fracbits)))
|
||||
|
||||
/* Convert a double to a fixed-point number. */
|
||||
#define JAS_DBLTOFIX(fix_t, fracbits, x) \
|
||||
JAS_CAST(fix_t, ((x) * JAS_CAST(double, JAS_CAST(fix_t, 1) << (fracbits))))
|
||||
|
||||
/******************************************************************************\
|
||||
* Basic arithmetic operations.
|
||||
* All other arithmetic operations are synthesized from these basic operations.
|
||||
* There are three macros for each type of arithmetic operation.
|
||||
* One macro always performs overflow/underflow checking, one never performs
|
||||
* overflow/underflow checking, and one is generic with its behavior
|
||||
* depending on compile-time flags.
|
||||
* Only the generic macros should be invoked directly by application code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the sum of two fixed-point numbers. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_ADD JAS_FIX_ADD_FAST
|
||||
#else
|
||||
#define JAS_FIX_ADD JAS_FIX_ADD_OFLOW
|
||||
#endif
|
||||
|
||||
/* Calculate the sum of two fixed-point numbers without overflow checking. */
|
||||
#define JAS_FIX_ADD_FAST(fix_t, fracbits, x, y) ((x) + (y))
|
||||
|
||||
/* Calculate the sum of two fixed-point numbers with overflow checking. */
|
||||
#define JAS_FIX_ADD_OFLOW(fix_t, fracbits, x, y) \
|
||||
((x) >= 0) ? \
|
||||
(((y) >= 0) ? ((x) + (y) >= 0 || JAS_FIX_OFLOW(), (x) + (y)) : \
|
||||
((x) + (y))) : \
|
||||
(((y) >= 0) ? ((x) + (y)) : ((x) + (y) < 0 || JAS_FIX_OFLOW(), \
|
||||
(x) + (y)))
|
||||
|
||||
/* Calculate the product of two fixed-point numbers. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_MUL JAS_FIX_MUL_FAST
|
||||
#else
|
||||
#define JAS_FIX_MUL JAS_FIX_MUL_OFLOW
|
||||
#endif
|
||||
|
||||
/* Calculate the product of two fixed-point numbers without overflow
|
||||
checking. */
|
||||
#define JAS_FIX_MUL_FAST(fix_t, fracbits, bigfix_t, x, y) \
|
||||
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y)) >> \
|
||||
(fracbits))
|
||||
|
||||
/* Calculate the product of two fixed-point numbers with overflow
|
||||
checking. */
|
||||
#define JAS_FIX_MUL_OFLOW(fix_t, fracbits, bigfix_t, x, y) \
|
||||
((JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> (fracbits)) == \
|
||||
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
|
||||
(fracbits))) ? \
|
||||
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) * JAS_CAST(bigfix_t, y) >> \
|
||||
(fracbits))) : JAS_FIX_OFLOW())
|
||||
|
||||
/* Calculate the product of a fixed-point number and an int. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_FAST
|
||||
#else
|
||||
#define JAS_FIX_MULBYINT JAS_FIX_MULBYINT_OFLOW
|
||||
#endif
|
||||
|
||||
/* Calculate the product of a fixed-point number and an int without overflow
|
||||
checking. */
|
||||
#define JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y) \
|
||||
JAS_CAST(fix_t, ((x) * (y)))
|
||||
|
||||
/* Calculate the product of a fixed-point number and an int with overflow
|
||||
checking. */
|
||||
#define JAS_FIX_MULBYINT_OFLOW(fix_t, fracbits, x, y) \
|
||||
JAS_FIX_MULBYINT_FAST(fix_t, fracbits, x, y)
|
||||
|
||||
/* Calculate the quotient of two fixed-point numbers. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_DIV JAS_FIX_DIV_FAST
|
||||
#else
|
||||
#define JAS_FIX_DIV JAS_FIX_DIV_UFLOW
|
||||
#endif
|
||||
|
||||
/* Calculate the quotient of two fixed-point numbers without underflow
|
||||
checking. */
|
||||
#define JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y) \
|
||||
JAS_CAST(fix_t, (JAS_CAST(bigfix_t, x) << (fracbits)) / (y))
|
||||
|
||||
/* Calculate the quotient of two fixed-point numbers with underflow
|
||||
checking. */
|
||||
#define JAS_FIX_DIV_UFLOW(fix_t, fracbits, bigfix_t, x, y) \
|
||||
JAS_FIX_DIV_FAST(fix_t, fracbits, bigfix_t, x, y)
|
||||
|
||||
/* Negate a fixed-point number. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_NEG JAS_FIX_NEG_FAST
|
||||
#else
|
||||
#define JAS_FIX_NEG JAS_FIX_NEG_OFLOW
|
||||
#endif
|
||||
|
||||
/* Negate a fixed-point number without overflow checking. */
|
||||
#define JAS_FIX_NEG_FAST(fix_t, fracbits, x) \
|
||||
(-(x))
|
||||
|
||||
/* Negate a fixed-point number with overflow checking. */
|
||||
/* Yes, overflow is actually possible for two's complement representations,
|
||||
although highly unlikely to occur. */
|
||||
#define JAS_FIX_NEG_OFLOW(fix_t, fracbits, x) \
|
||||
(((x) < 0) ? (-(x) > 0 || JAS_FIX_OFLOW(), -(x)) : (-(x)))
|
||||
|
||||
/* Perform an arithmetic shift left of a fixed-point number. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_ASL JAS_FIX_ASL_FAST
|
||||
#else
|
||||
#define JAS_FIX_ASL JAS_FIX_ASL_OFLOW
|
||||
#endif
|
||||
|
||||
/* Perform an arithmetic shift left of a fixed-point number without overflow
|
||||
checking. */
|
||||
#define JAS_FIX_ASL_FAST(fix_t, fracbits, x, n) \
|
||||
((x) << (n))
|
||||
|
||||
/* Perform an arithmetic shift left of a fixed-point number with overflow
|
||||
checking. */
|
||||
#define JAS_FIX_ASL_OFLOW(fix_t, fracbits, x, n) \
|
||||
((((x) << (n)) >> (n)) == (x) || JAS_FIX_OFLOW(), (x) << (n))
|
||||
|
||||
/* Perform an arithmetic shift right of a fixed-point number. */
|
||||
#if !defined(DEBUG_OVERFLOW)
|
||||
#define JAS_FIX_ASR JAS_FIX_ASR_FAST
|
||||
#else
|
||||
#define JAS_FIX_ASR JAS_FIX_ASR_UFLOW
|
||||
#endif
|
||||
|
||||
/* Perform an arithmetic shift right of a fixed-point number without underflow
|
||||
checking. */
|
||||
#define JAS_FIX_ASR_FAST(fix_t, fracbits, x, n) \
|
||||
((x) >> (n))
|
||||
|
||||
/* Perform an arithmetic shift right of a fixed-point number with underflow
|
||||
checking. */
|
||||
#define JAS_FIX_ASR_UFLOW(fix_t, fracbits, x, n) \
|
||||
JAS_FIX_ASR_FAST(fix_t, fracbits, x, n)
|
||||
|
||||
/******************************************************************************\
|
||||
* Other basic arithmetic operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the difference between two fixed-point numbers. */
|
||||
#define JAS_FIX_SUB(fix_t, fracbits, x, y) \
|
||||
JAS_FIX_ADD(fix_t, fracbits, x, JAS_FIX_NEG(fix_t, fracbits, y))
|
||||
|
||||
/* Add one fixed-point number to another. */
|
||||
#define JAS_FIX_PLUSEQ(fix_t, fracbits, x, y) \
|
||||
((x) = JAS_FIX_ADD(fix_t, fracbits, x, y))
|
||||
|
||||
/* Subtract one fixed-point number from another. */
|
||||
#define JAS_FIX_MINUSEQ(fix_t, fracbits, x, y) \
|
||||
((x) = JAS_FIX_SUB(fix_t, fracbits, x, y))
|
||||
|
||||
/* Multiply one fixed-point number by another. */
|
||||
#define JAS_FIX_MULEQ(fix_t, fracbits, bigfix_t, x, y) \
|
||||
((x) = JAS_FIX_MUL(fix_t, fracbits, bigfix_t, x, y))
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the absolute value of a fixed-point number. */
|
||||
#define JAS_FIX_ABS(fix_t, fracbits, x) \
|
||||
(((x) >= 0) ? (x) : (JAS_FIX_NEG(fix_t, fracbits, x)))
|
||||
|
||||
/* Is a fixed-point number an integer? */
|
||||
#define JAS_FIX_ISINT(fix_t, fracbits, x) \
|
||||
(JAS_FIX_FLOOR(fix_t, fracbits, x) == (x))
|
||||
|
||||
/* Get the sign of a fixed-point number. */
|
||||
#define JAS_FIX_SGN(fix_t, fracbits, x) \
|
||||
((x) >= 0 ? 1 : (-1))
|
||||
|
||||
/******************************************************************************\
|
||||
* Relational operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Compare two fixed-point numbers. */
|
||||
#define JAS_FIX_CMP(fix_t, fracbits, x, y) \
|
||||
((x) > (y) ? 1 : (((x) == (y)) ? 0 : (-1)))
|
||||
|
||||
/* Less than. */
|
||||
#define JAS_FIX_LT(fix_t, fracbits, x, y) \
|
||||
((x) < (y))
|
||||
|
||||
/* Less than or equal. */
|
||||
#define JAS_FIX_LTE(fix_t, fracbits, x, y) \
|
||||
((x) <= (y))
|
||||
|
||||
/* Greater than. */
|
||||
#define JAS_FIX_GT(fix_t, fracbits, x, y) \
|
||||
((x) > (y))
|
||||
|
||||
/* Greater than or equal. */
|
||||
#define JAS_FIX_GTE(fix_t, fracbits, x, y) \
|
||||
((x) >= (y))
|
||||
|
||||
/******************************************************************************\
|
||||
* Rounding functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Round a fixed-point number to the nearest integer. */
|
||||
#define JAS_FIX_ROUND(fix_t, fracbits, x) \
|
||||
(((x) < 0) ? JAS_FIX_FLOOR(fix_t, fracbits, JAS_FIX_ADD(fix_t, fracbits, \
|
||||
(x), JAS_FIX_HALF(fix_t, fracbits))) : \
|
||||
JAS_FIX_NEG(fix_t, fracbits, JAS_FIX_FLOOR(fix_t, fracbits, \
|
||||
JAS_FIX_ADD(fix_t, fracbits, (-(x)), JAS_FIX_HALF(fix_t, fracbits)))))
|
||||
|
||||
/* Round a fixed-point number to the nearest integer in the direction of
|
||||
negative infinity (i.e., the floor function). */
|
||||
#define JAS_FIX_FLOOR(fix_t, fracbits, x) \
|
||||
((x) & (~((JAS_CAST(fix_t, 1) << (fracbits)) - 1)))
|
||||
|
||||
/* Round a fixed-point number to the nearest integer in the direction
|
||||
of zero. */
|
||||
#define JAS_FIX_TRUNC(fix_t, fracbits, x) \
|
||||
(((x) >= 0) ? JAS_FIX_FLOOR(fix_t, fracbits, x) : \
|
||||
JAS_FIX_CEIL(fix_t, fracbits, x))
|
||||
|
||||
/******************************************************************************\
|
||||
* The below macros are for internal library use only. Do not invoke them
|
||||
* directly in application code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Handle overflow. */
|
||||
#define JAS_FIX_OFLOW() \
|
||||
jas_eprintf("overflow error: file %s, line %d\n", __FILE__, __LINE__)
|
||||
|
||||
/* Handle underflow. */
|
||||
#define JAS_FIX_UFLOW() \
|
||||
jas_eprintf("underflow error: file %s, line %d\n", __FILE__, __LINE__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Command Line Option Parsing Code
|
||||
*
|
||||
* $Id: jas_getopt.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_GETOPT_H
|
||||
#define JAS_GETOPT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JAS_GETOPT_EOF (-1)
|
||||
#define JAS_GETOPT_ERR '?'
|
||||
|
||||
/* option flags. */
|
||||
#define JAS_OPT_HASARG 0x01 /* option has argument */
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Command line option type. */
|
||||
typedef struct {
|
||||
|
||||
int id;
|
||||
/* The unique identifier for this option. */
|
||||
|
||||
char *name;
|
||||
/* The name of this option. */
|
||||
|
||||
int flags;
|
||||
/* option flags. */
|
||||
|
||||
} jas_opt_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* External data.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The current option index. */
|
||||
extern int jas_optind;
|
||||
|
||||
/* The current option argument. */
|
||||
extern char *jas_optarg;
|
||||
|
||||
/* The debug level. */
|
||||
extern int jas_opterr;
|
||||
|
||||
/******************************************************************************\
|
||||
* Prototypes.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the next option. */
|
||||
int jas_getopt(int argc, char **argv, jas_opt_t *opts);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+407
@@ -0,0 +1,407 @@
|
||||
/*
|
||||
* Copyright (c) 2002-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JAS_ICC_H
|
||||
#define JAS_ICC_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_types.h>
|
||||
#include <jasper/jas_stream.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Profile file signature. */
|
||||
#define JAS_ICC_MAGIC 0x61637370
|
||||
|
||||
#define JAS_ICC_HDRLEN 128
|
||||
|
||||
/* Profile/device class signatures. */
|
||||
#define JAS_ICC_CLAS_IN 0x73636e72 /* input device */
|
||||
#define JAS_ICC_CLAS_DPY 0x6d6e7472 /* display device */
|
||||
#define JAS_ICC_CLAS_OUT 0x70727472 /* output device */
|
||||
#define JAS_ICC_CLAS_LNK 0x6c696e6b /* device link */
|
||||
#define JAS_ICC_CLAS_CNV 0x73706163 /* color space conversion */
|
||||
#define JAS_ICC_CLAS_ABS 0x61627374 /* abstract */
|
||||
#define JAS_ICC_CLAS_NAM 0x6e6d636c /* named color */
|
||||
|
||||
/* Color space signatures. */
|
||||
#define JAS_ICC_COLORSPC_XYZ 0x58595a20 /* XYZ */
|
||||
#define JAS_ICC_COLORSPC_LAB 0x4c616220 /* LAB */
|
||||
#define JAS_ICC_COLORSPC_LUV 0x4c757620 /* LUV */
|
||||
#define JAS_ICC_COLORSPC_YCBCR 0x59436272 /* YCbCr */
|
||||
#define JAS_ICC_COLORSPC_YXY 0x59787920 /* Yxy */
|
||||
#define JAS_ICC_COLORSPC_RGB 0x52474220 /* RGB */
|
||||
#define JAS_ICC_COLORSPC_GRAY 0x47524159 /* Gray */
|
||||
#define JAS_ICC_COLORSPC_HSV 0x48535620 /* HSV */
|
||||
#define JAS_ICC_COLORSPC_HLS 0x484c5320 /* HLS */
|
||||
#define JAS_ICC_COLORSPC_CMYK 0x434d594b /* CMYK */
|
||||
#define JAS_ICC_COLORSPC_CMY 0x434d5920 /* CMY */
|
||||
#define JAS_ICC_COLORSPC_2 0x32434c52 /* 2 channel color */
|
||||
#define JAS_ICC_COLORSPC_3 0x33434c52 /* 3 channel color */
|
||||
#define JAS_ICC_COLORSPC_4 0x34434c52 /* 4 channel color */
|
||||
#define JAS_ICC_COLORSPC_5 0x35434c52 /* 5 channel color */
|
||||
#define JAS_ICC_COLORSPC_6 0x36434c52 /* 6 channel color */
|
||||
#define JAS_ICC_COLORSPC_7 0x37434c52 /* 7 channel color */
|
||||
#define JAS_ICC_COLORSPC_8 0x38434c52 /* 8 channel color */
|
||||
#define JAS_ICC_COLORSPC_9 0x39434c52 /* 9 channel color */
|
||||
#define JAS_ICC_COLORSPC_10 0x41434c52 /* 10 channel color */
|
||||
#define JAS_ICC_COLORSPC_11 0x42434c52 /* 11 channel color */
|
||||
#define JAS_ICC_COLORSPC_12 0x43434c52 /* 12 channel color */
|
||||
#define JAS_ICC_COLORSPC_13 0x44434c52 /* 13 channel color */
|
||||
#define JAS_ICC_COLORSPC_14 0x45434c52 /* 14 channel color */
|
||||
#define JAS_ICC_COLORSPC_15 0x46434c52 /* 15 channel color */
|
||||
|
||||
/* Profile connection color space (PCS) signatures. */
|
||||
#define JAS_ICC_REFCOLORSPC_XYZ 0x58595a20 /* CIE XYZ */
|
||||
#define JAS_ICC_REFCOLORSPC_LAB 0x4c616220 /* CIE Lab */
|
||||
|
||||
/* Primary platform signatures. */
|
||||
#define JAS_ICC_PLATFORM_APPL 0x4150504c /* Apple Computer */
|
||||
#define JAS_ICC_PLATFORM_MSFT 0x4d534654 /* Microsoft */
|
||||
#define JAS_ICC_PLATFORM_SGI 0x53474920 /* Silicon Graphics */
|
||||
#define JAS_ICC_PLATFORM_SUNW 0x53554e57 /* Sun Microsystems */
|
||||
#define JAS_ICC_PLATFORM_TGNT 0x54474e54 /* Taligent */
|
||||
|
||||
/* Profile flags. */
|
||||
#define JAS_ICC_FLAGS_EMBED 0x01 /* embedded */
|
||||
#define JAS_ICC_FLAGS_NOSEP 0x02 /* no separate use */
|
||||
|
||||
/* Attributes. */
|
||||
#define JAS_ICC_ATTR_TRANS 0x01 /* transparent */
|
||||
#define JAS_ICC_ATTR_MATTE 0x02 /* matte */
|
||||
|
||||
/* Rendering intents. */
|
||||
#define JAS_ICC_INTENT_PER 0 /* perceptual */
|
||||
#define JAS_ICC_INTENT_REL 1 /* relative colorimetric */
|
||||
#define JAS_ICC_INTENT_SAT 2 /* saturation */
|
||||
#define JAS_ICC_INTENT_ABS 3 /* absolute colorimetric */
|
||||
|
||||
/* Tag signatures. */
|
||||
#define JAS_ICC_TAG_ATOB0 0x41324230 /* */
|
||||
#define JAS_ICC_TAG_ATOB1 0x41324231 /* */
|
||||
#define JAS_ICC_TAG_ATOB2 0x41324232 /* */
|
||||
#define JAS_ICC_TAG_BLUMATCOL 0x6258595a /* */
|
||||
#define JAS_ICC_TAG_BLUTRC 0x62545243 /* */
|
||||
#define JAS_ICC_TAG_BTOA0 0x42324130 /* */
|
||||
#define JAS_ICC_TAG_BTOA1 0x42324131 /* */
|
||||
#define JAS_ICC_TAG_BTOA2 0x42324132 /* */
|
||||
#define JAS_ICC_TAG_CALTIME 0x63616c74 /* */
|
||||
#define JAS_ICC_TAG_CHARTARGET 0x74617267 /* */
|
||||
#define JAS_ICC_TAG_CPYRT 0x63707274 /* */
|
||||
#define JAS_ICC_TAG_CRDINFO 0x63726469 /* */
|
||||
#define JAS_ICC_TAG_DEVMAKERDESC 0x646d6e64 /* */
|
||||
#define JAS_ICC_TAG_DEVMODELDESC 0x646d6464 /* */
|
||||
#define JAS_ICC_TAG_DEVSET 0x64657673 /* */
|
||||
#define JAS_ICC_TAG_GAMUT 0x67616d74 /* */
|
||||
#define JAS_ICC_TAG_GRYTRC 0x6b545243 /* */
|
||||
#define JAS_ICC_TAG_GRNMATCOL 0x6758595a /* */
|
||||
#define JAS_ICC_TAG_GRNTRC 0x67545243 /* */
|
||||
#define JAS_ICC_TAG_LUM 0x6c756d69 /* */
|
||||
#define JAS_ICC_TAG_MEASURE 0x6d656173 /* */
|
||||
#define JAS_ICC_TAG_MEDIABLKPT 0x626b7074 /* */
|
||||
#define JAS_ICC_TAG_MEDIAWHIPT 0x77747074 /* */
|
||||
#define JAS_ICC_TAG_NAMCOLR 0x6e636f6c /* */
|
||||
#define JAS_ICC_TAG_NAMCOLR2 0x6e636c32 /* */
|
||||
#define JAS_ICC_TAG_OUTRESP 0x72657370 /* */
|
||||
#define JAS_ICC_TAG_PREVIEW0 0x70726530 /* */
|
||||
#define JAS_ICC_TAG_PREVIEW1 0x70726531 /* */
|
||||
#define JAS_ICC_TAG_PREVIEW2 0x70726532 /* */
|
||||
#define JAS_ICC_TAG_PROFDESC 0x64657363 /* */
|
||||
#define JAS_ICC_TAG_PROFSEQDESC 0x70736571 /* */
|
||||
#define JAS_ICC_TAG_PSDCRD0 0x70736430 /* */
|
||||
#define JAS_ICC_TAG_PSCRDD1 0x70736431 /* */
|
||||
#define JAS_ICC_TAG_PSCRDD2 0x70736432 /* */
|
||||
#define JAS_ICC_TAG_PSCRDD3 0x70736433 /* */
|
||||
#define JAS_ICC_TAG_PS2CSA 0x70733273 /* */
|
||||
#define JAS_ICC_TAG_PS2RENINTENT 0x70733269 /* */
|
||||
#define JAS_ICC_TAG_REDMATCOL 0x7258595a /* */
|
||||
#define JAS_ICC_TAG_REDTRC 0x72545243 /* */
|
||||
#define JAS_ICC_TAG_SCRNGDES 0x73637264 /* */
|
||||
#define JAS_ICC_TAG_SCRNG 0x7363726e /* */
|
||||
#define JAS_ICC_TAG_TECH 0x74656368 /* */
|
||||
#define JAS_ICC_TAG_UCRBG 0x62666420 /* */
|
||||
#define JAS_ICC_TAG_VIEWCONDDESC 0x76756564 /* */
|
||||
#define JAS_ICC_TAG_VIEWCOND 0x76696577 /* */
|
||||
|
||||
/* Type signatures. */
|
||||
#define JAS_ICC_TYPE_CRDINFO 0x63726469 /* CRD information */
|
||||
#define JAS_ICC_TYPE_CURV 0x63757276 /* curve */
|
||||
#define JAS_ICC_TYPE_DATA 0x64617461 /* data */
|
||||
#define JAS_ICC_TYPE_TIME 0x6474696d /* date/time */
|
||||
#define JAS_ICC_TYPE_DEVSET 0x64657673 /* device settings */
|
||||
#define JAS_ICC_TYPE_LUT16 0x6d667432 /* */
|
||||
#define JAS_ICC_TYPE_LUT8 0x6d667431 /* */
|
||||
#define JAS_ICC_TYPE_MEASURE 0x6d656173 /* */
|
||||
#define JAS_ICC_TYPE_NAMCOLR 0x6e636f6c /* */
|
||||
#define JAS_ICC_TYPE_NAMCOLR2 0x6e636c32 /* */
|
||||
#define JAS_ICC_TYPE_PROFSEQDESC 0x70736571 /* profile sequence description */
|
||||
#define JAS_ICC_TYPE_RESPCURVSET16 0x72637332 /* response curve set 16 */
|
||||
#define JAS_ICC_TYPE_SF32 0x73663332 /* signed 32-bit fixed-point */
|
||||
#define JAS_ICC_TYPE_SCRNG 0x7363726e /* screening */
|
||||
#define JAS_ICC_TYPE_SIG 0x73696720 /* signature */
|
||||
#define JAS_ICC_TYPE_TXTDESC 0x64657363 /* text description */
|
||||
#define JAS_ICC_TYPE_TXT 0x74657874 /* text */
|
||||
#define JAS_ICC_TYPE_UF32 0x75663332 /* unsigned 32-bit fixed-point */
|
||||
#define JAS_ICC_TYPE_UCRBG 0x62666420 /* */
|
||||
#define JAS_ICC_TYPE_UI16 0x75693136 /* */
|
||||
#define JAS_ICC_TYPE_UI32 0x75693332 /* */
|
||||
#define JAS_ICC_TYPE_UI8 0x75693038 /* */
|
||||
#define JAS_ICC_TYPE_UI64 0x75693634 /* */
|
||||
#define JAS_ICC_TYPE_VIEWCOND 0x76696577 /* */
|
||||
#define JAS_ICC_TYPE_XYZ 0x58595a20 /* XYZ */
|
||||
|
||||
typedef uint_fast8_t jas_iccuint8_t;
|
||||
typedef uint_fast16_t jas_iccuint16_t;
|
||||
typedef uint_fast32_t jas_iccuint32_t;
|
||||
typedef int_fast32_t jas_iccsint32_t;
|
||||
typedef int_fast32_t jas_iccs15fixed16_t;
|
||||
typedef uint_fast32_t jas_iccu16fixed16_t;
|
||||
typedef uint_fast64_t jas_iccuint64_t;
|
||||
typedef uint_fast32_t jas_iccsig_t;
|
||||
|
||||
typedef jas_iccsig_t jas_icctagsig_t;
|
||||
typedef jas_iccsig_t jas_icctagtype_t;
|
||||
typedef jas_iccsig_t jas_iccattrname_t;
|
||||
|
||||
/* Date/time type. */
|
||||
typedef struct {
|
||||
jas_iccuint16_t year;
|
||||
jas_iccuint16_t month;
|
||||
jas_iccuint16_t day;
|
||||
jas_iccuint16_t hour;
|
||||
jas_iccuint16_t min;
|
||||
jas_iccuint16_t sec;
|
||||
} jas_icctime_t;
|
||||
|
||||
/* XYZ type. */
|
||||
typedef struct {
|
||||
jas_iccs15fixed16_t x;
|
||||
jas_iccs15fixed16_t y;
|
||||
jas_iccs15fixed16_t z;
|
||||
} jas_iccxyz_t;
|
||||
|
||||
/* Curve type. */
|
||||
typedef struct {
|
||||
jas_iccuint32_t numents;
|
||||
jas_iccuint16_t *ents;
|
||||
} jas_icccurv_t;
|
||||
|
||||
/* Text description type. */
|
||||
typedef struct {
|
||||
jas_iccuint32_t asclen;
|
||||
char *ascdata; /* ASCII invariant description */
|
||||
jas_iccuint32_t uclangcode; /* Unicode language code */
|
||||
jas_iccuint32_t uclen; /* Unicode localizable description count */
|
||||
uchar *ucdata; /* Unicode localizable description */
|
||||
jas_iccuint16_t sccode; /* ScriptCode code */
|
||||
jas_iccuint8_t maclen; /* Localizable Macintosh description count */
|
||||
uchar macdata[69]; /* Localizable Macintosh description */
|
||||
} jas_icctxtdesc_t;
|
||||
|
||||
/* Text type. */
|
||||
typedef struct {
|
||||
char *string; /* ASCII character string */
|
||||
} jas_icctxt_t;
|
||||
|
||||
typedef struct {
|
||||
jas_iccuint8_t numinchans;
|
||||
jas_iccuint8_t numoutchans;
|
||||
jas_iccsint32_t e[3][3];
|
||||
jas_iccuint8_t clutlen;
|
||||
jas_iccuint8_t *clut;
|
||||
jas_iccuint16_t numintabents;
|
||||
jas_iccuint8_t **intabs;
|
||||
jas_iccuint8_t *intabsbuf;
|
||||
jas_iccuint16_t numouttabents;
|
||||
jas_iccuint8_t **outtabs;
|
||||
jas_iccuint8_t *outtabsbuf;
|
||||
} jas_icclut8_t;
|
||||
|
||||
typedef struct {
|
||||
jas_iccuint8_t numinchans;
|
||||
jas_iccuint8_t numoutchans;
|
||||
jas_iccsint32_t e[3][3];
|
||||
jas_iccuint8_t clutlen;
|
||||
jas_iccuint16_t *clut;
|
||||
jas_iccuint16_t numintabents;
|
||||
jas_iccuint16_t **intabs;
|
||||
jas_iccuint16_t *intabsbuf;
|
||||
jas_iccuint16_t numouttabents;
|
||||
jas_iccuint16_t **outtabs;
|
||||
jas_iccuint16_t *outtabsbuf;
|
||||
} jas_icclut16_t;
|
||||
|
||||
struct jas_iccattrval_s;
|
||||
|
||||
typedef struct {
|
||||
void (*destroy)(struct jas_iccattrval_s *);
|
||||
int (*copy)(struct jas_iccattrval_s *, struct jas_iccattrval_s *);
|
||||
int (*input)(struct jas_iccattrval_s *, jas_stream_t *, int);
|
||||
int (*output)(struct jas_iccattrval_s *, jas_stream_t *);
|
||||
int (*getsize)(struct jas_iccattrval_s *);
|
||||
void (*dump)(struct jas_iccattrval_s *, FILE *);
|
||||
} jas_iccattrvalops_t;
|
||||
|
||||
/* Attribute value type (type and value information). */
|
||||
typedef struct jas_iccattrval_s {
|
||||
int refcnt; /* reference count */
|
||||
jas_iccsig_t type; /* type */
|
||||
jas_iccattrvalops_t *ops; /* type-dependent operations */
|
||||
union {
|
||||
jas_iccxyz_t xyz;
|
||||
jas_icccurv_t curv;
|
||||
jas_icctxtdesc_t txtdesc;
|
||||
jas_icctxt_t txt;
|
||||
jas_icclut8_t lut8;
|
||||
jas_icclut16_t lut16;
|
||||
} data; /* value */
|
||||
} jas_iccattrval_t;
|
||||
|
||||
/* Header type. */
|
||||
typedef struct {
|
||||
jas_iccuint32_t size; /* profile size */
|
||||
jas_iccsig_t cmmtype; /* CMM type signature */
|
||||
jas_iccuint32_t version; /* profile version */
|
||||
jas_iccsig_t clas; /* profile/device class signature */
|
||||
jas_iccsig_t colorspc; /* color space of data */
|
||||
jas_iccsig_t refcolorspc; /* profile connection space */
|
||||
jas_icctime_t ctime; /* creation time */
|
||||
jas_iccsig_t magic; /* profile file signature */
|
||||
jas_iccsig_t platform; /* primary platform */
|
||||
jas_iccuint32_t flags; /* profile flags */
|
||||
jas_iccsig_t maker; /* device manufacturer signature */
|
||||
jas_iccsig_t model; /* device model signature */
|
||||
jas_iccuint64_t attr; /* device setup attributes */
|
||||
jas_iccsig_t intent; /* rendering intent */
|
||||
jas_iccxyz_t illum; /* illuminant */
|
||||
jas_iccsig_t creator; /* profile creator signature */
|
||||
} jas_icchdr_t;
|
||||
|
||||
typedef struct {
|
||||
jas_iccsig_t name;
|
||||
jas_iccattrval_t *val;
|
||||
} jas_iccattr_t;
|
||||
|
||||
typedef struct {
|
||||
int numattrs;
|
||||
int maxattrs;
|
||||
jas_iccattr_t *attrs;
|
||||
} jas_iccattrtab_t;
|
||||
|
||||
typedef struct jas_icctagtabent_s {
|
||||
jas_iccuint32_t tag;
|
||||
jas_iccuint32_t off;
|
||||
jas_iccuint32_t len;
|
||||
void *data;
|
||||
struct jas_icctagtabent_s *first;
|
||||
} jas_icctagtabent_t;
|
||||
|
||||
typedef struct {
|
||||
jas_iccuint32_t numents;
|
||||
jas_icctagtabent_t *ents;
|
||||
} jas_icctagtab_t;
|
||||
|
||||
/* ICC profile type. */
|
||||
typedef struct {
|
||||
jas_icchdr_t hdr;
|
||||
jas_icctagtab_t tagtab;
|
||||
jas_iccattrtab_t *attrtab;
|
||||
} jas_iccprof_t;
|
||||
|
||||
typedef struct {
|
||||
jas_iccuint32_t type;
|
||||
jas_iccattrvalops_t ops;
|
||||
} jas_iccattrvalinfo_t;
|
||||
|
||||
jas_iccprof_t *jas_iccprof_load(jas_stream_t *in);
|
||||
int jas_iccprof_save(jas_iccprof_t *prof, jas_stream_t *out);
|
||||
void jas_iccprof_destroy(jas_iccprof_t *prof);
|
||||
jas_iccattrval_t *jas_iccprof_getattr(jas_iccprof_t *prof,
|
||||
jas_iccattrname_t name);
|
||||
int jas_iccprof_setattr(jas_iccprof_t *prof, jas_iccattrname_t name,
|
||||
jas_iccattrval_t *val);
|
||||
void jas_iccprof_dump(jas_iccprof_t *prof, FILE *out);
|
||||
jas_iccprof_t *jas_iccprof_copy(jas_iccprof_t *prof);
|
||||
int jas_iccprof_gethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
|
||||
int jas_iccprof_sethdr(jas_iccprof_t *prof, jas_icchdr_t *hdr);
|
||||
|
||||
void jas_iccattrval_destroy(jas_iccattrval_t *attrval);
|
||||
void jas_iccattrval_dump(jas_iccattrval_t *attrval, FILE *out);
|
||||
int jas_iccattrval_allowmodify(jas_iccattrval_t **attrval);
|
||||
jas_iccattrval_t *jas_iccattrval_clone(jas_iccattrval_t *attrval);
|
||||
jas_iccattrval_t *jas_iccattrval_create(jas_iccuint32_t type);
|
||||
|
||||
void jas_iccattrtab_dump(jas_iccattrtab_t *attrtab, FILE *out);
|
||||
|
||||
extern uchar jas_iccprofdata_srgb[];
|
||||
extern int jas_iccprofdata_srgblen;
|
||||
extern uchar jas_iccprofdata_sgray[];
|
||||
extern int jas_iccprofdata_sgraylen;
|
||||
jas_iccprof_t *jas_iccprof_createfrombuf(uchar *buf, int len);
|
||||
jas_iccprof_t *jas_iccprof_createfromclrspc(int clrspc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+564
@@ -0,0 +1,564 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Image Class
|
||||
*
|
||||
* $Id: jas_image.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_IMAGE_H
|
||||
#define JAS_IMAGE_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_stream.h>
|
||||
#include <jasper/jas_seq.h>
|
||||
#include <jasper/jas_cm.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Miscellaneous constants.
|
||||
*/
|
||||
|
||||
/* The threshold at which image data is no longer stored in memory. */
|
||||
#define JAS_IMAGE_INMEMTHRESH (16 * 1024 * 1024)
|
||||
|
||||
/*
|
||||
* Component types
|
||||
*/
|
||||
|
||||
#define JAS_IMAGE_CT_UNKNOWN 0x10000
|
||||
#define JAS_IMAGE_CT_COLOR(n) ((n) & 0x7fff)
|
||||
#define JAS_IMAGE_CT_OPACITY 0x08000
|
||||
|
||||
#define JAS_IMAGE_CT_RGB_R 0
|
||||
#define JAS_IMAGE_CT_RGB_G 1
|
||||
#define JAS_IMAGE_CT_RGB_B 2
|
||||
|
||||
#define JAS_IMAGE_CT_YCBCR_Y 0
|
||||
#define JAS_IMAGE_CT_YCBCR_CB 1
|
||||
#define JAS_IMAGE_CT_YCBCR_CR 2
|
||||
|
||||
#define JAS_IMAGE_CT_GRAY_Y 0
|
||||
|
||||
/******************************************************************************\
|
||||
* Simple types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Image coordinate. */
|
||||
typedef int_fast32_t jas_image_coord_t;
|
||||
|
||||
/* Color space (e.g., RGB, YCbCr). */
|
||||
typedef int_fast16_t jas_image_colorspc_t;
|
||||
|
||||
/* Component type (e.g., color, opacity). */
|
||||
typedef int_fast32_t jas_image_cmpttype_t;
|
||||
|
||||
/* Component sample data format (e.g., real/integer, signedness, precision). */
|
||||
typedef int_fast16_t jas_image_smpltype_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Image class and supporting classes.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Image component class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
jas_image_coord_t tlx_;
|
||||
/* The x-coordinate of the top-left corner of the component. */
|
||||
|
||||
jas_image_coord_t tly_;
|
||||
/* The y-coordinate of the top-left corner of the component. */
|
||||
|
||||
jas_image_coord_t hstep_;
|
||||
/* The horizontal sampling period in units of the reference grid. */
|
||||
|
||||
jas_image_coord_t vstep_;
|
||||
/* The vertical sampling period in units of the reference grid. */
|
||||
|
||||
jas_image_coord_t width_;
|
||||
/* The component width in samples. */
|
||||
|
||||
jas_image_coord_t height_;
|
||||
/* The component height in samples. */
|
||||
|
||||
#ifdef FIX_ME
|
||||
int smpltype_;
|
||||
#else
|
||||
int prec_;
|
||||
/* The precision of the sample data (i.e., the number of bits per
|
||||
sample). If the samples are signed values, this quantity
|
||||
includes the sign bit. */
|
||||
|
||||
int sgnd_;
|
||||
/* The signedness of the sample data. */
|
||||
#endif
|
||||
|
||||
jas_stream_t *stream_;
|
||||
/* The stream containing the component data. */
|
||||
|
||||
int cps_;
|
||||
/* The number of characters per sample in the stream. */
|
||||
|
||||
jas_image_cmpttype_t type_;
|
||||
/* The type of component (e.g., opacity, red, green, blue, luma). */
|
||||
|
||||
} jas_image_cmpt_t;
|
||||
|
||||
/* Image class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
jas_image_coord_t tlx_;
|
||||
/* The x-coordinate of the top-left corner of the image bounding box. */
|
||||
|
||||
jas_image_coord_t tly_;
|
||||
/* The y-coordinate of the top-left corner of the image bounding box. */
|
||||
|
||||
jas_image_coord_t brx_;
|
||||
/* The x-coordinate of the bottom-right corner of the image bounding
|
||||
box (plus one). */
|
||||
|
||||
jas_image_coord_t bry_;
|
||||
/* The y-coordinate of the bottom-right corner of the image bounding
|
||||
box (plus one). */
|
||||
|
||||
int numcmpts_;
|
||||
/* The number of components. */
|
||||
|
||||
int maxcmpts_;
|
||||
/* The maximum number of components that this image can have (i.e., the
|
||||
allocated size of the components array). */
|
||||
|
||||
jas_image_cmpt_t **cmpts_;
|
||||
/* Per-component information. */
|
||||
|
||||
jas_clrspc_t clrspc_;
|
||||
|
||||
jas_cmprof_t *cmprof_;
|
||||
|
||||
bool inmem_;
|
||||
|
||||
} jas_image_t;
|
||||
|
||||
/* Component parameters class. */
|
||||
/* This data type exists solely/mainly for the purposes of the
|
||||
jas_image_create function. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
jas_image_coord_t tlx;
|
||||
/* The x-coordinate of the top-left corner of the component. */
|
||||
|
||||
jas_image_coord_t tly;
|
||||
/* The y-coordinate of the top-left corner of the component. */
|
||||
|
||||
jas_image_coord_t hstep;
|
||||
/* The horizontal sampling period in units of the reference grid. */
|
||||
|
||||
jas_image_coord_t vstep;
|
||||
/* The vertical sampling period in units of the reference grid. */
|
||||
|
||||
jas_image_coord_t width;
|
||||
/* The width of the component in samples. */
|
||||
|
||||
jas_image_coord_t height;
|
||||
/* The height of the component in samples. */
|
||||
|
||||
#ifdef FIX_ME
|
||||
int smpltype;
|
||||
#else
|
||||
int prec;
|
||||
/* The precision of the component sample data. */
|
||||
|
||||
int sgnd;
|
||||
/* The signedness of the component sample data. */
|
||||
#endif
|
||||
|
||||
} jas_image_cmptparm_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* File format related classes.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JAS_IMAGE_MAXFMTS 32
|
||||
/* The maximum number of image data formats supported. */
|
||||
|
||||
/* Image format-dependent operations. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
jas_image_t *(*decode)(jas_stream_t *in, char *opts);
|
||||
/* Decode image data from a stream. */
|
||||
|
||||
int (*encode)(jas_image_t *image, jas_stream_t *out, char *opts);
|
||||
/* Encode image data to a stream. */
|
||||
|
||||
int (*validate)(jas_stream_t *in);
|
||||
/* Determine if stream data is in a particular format. */
|
||||
|
||||
} jas_image_fmtops_t;
|
||||
|
||||
/* Image format information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
int id;
|
||||
/* The ID for this format. */
|
||||
|
||||
char *name;
|
||||
/* The name by which this format is identified. */
|
||||
|
||||
char *ext;
|
||||
/* The file name extension associated with this format. */
|
||||
|
||||
char *desc;
|
||||
/* A brief description of the format. */
|
||||
|
||||
jas_image_fmtops_t ops;
|
||||
/* The operations for this format. */
|
||||
|
||||
} jas_image_fmtinfo_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Image operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create an image. */
|
||||
jas_image_t *jas_image_create(int numcmpts,
|
||||
jas_image_cmptparm_t *cmptparms, jas_clrspc_t clrspc);
|
||||
|
||||
/* Create an "empty" image. */
|
||||
jas_image_t *jas_image_create0(void);
|
||||
|
||||
/* Clone an image. */
|
||||
jas_image_t *jas_image_copy(jas_image_t *image);
|
||||
|
||||
/* Deallocate any resources associated with an image. */
|
||||
void jas_image_destroy(jas_image_t *image);
|
||||
|
||||
/* Get the width of the image in units of the image reference grid. */
|
||||
#define jas_image_width(image) \
|
||||
((image)->brx_ - (image)->tlx_)
|
||||
|
||||
/* Get the height of the image in units of the image reference grid. */
|
||||
#define jas_image_height(image) \
|
||||
((image)->bry_ - (image)->tly_)
|
||||
|
||||
/* Get the x-coordinate of the top-left corner of the image bounding box
|
||||
on the reference grid. */
|
||||
#define jas_image_tlx(image) \
|
||||
((image)->tlx_)
|
||||
|
||||
/* Get the y-coordinate of the top-left corner of the image bounding box
|
||||
on the reference grid. */
|
||||
#define jas_image_tly(image) \
|
||||
((image)->tly_)
|
||||
|
||||
/* Get the x-coordinate of the bottom-right corner of the image bounding box
|
||||
on the reference grid (plus one). */
|
||||
#define jas_image_brx(image) \
|
||||
((image)->brx_)
|
||||
|
||||
/* Get the y-coordinate of the bottom-right corner of the image bounding box
|
||||
on the reference grid (plus one). */
|
||||
#define jas_image_bry(image) \
|
||||
((image)->bry_)
|
||||
|
||||
/* Get the number of image components. */
|
||||
#define jas_image_numcmpts(image) \
|
||||
((image)->numcmpts_)
|
||||
|
||||
/* Get the color model used by the image. */
|
||||
#define jas_image_clrspc(image) \
|
||||
((image)->clrspc_)
|
||||
|
||||
/* Set the color model for an image. */
|
||||
#define jas_image_setclrspc(image, clrspc) \
|
||||
((image)->clrspc_ = (clrspc))
|
||||
|
||||
#define jas_image_cmpttype(image, cmptno) \
|
||||
((image)->cmpts_[(cmptno)]->type_)
|
||||
#define jas_image_setcmpttype(image, cmptno, type) \
|
||||
((image)->cmpts_[(cmptno)]->type_ = (type))
|
||||
|
||||
/* Get the width of a component. */
|
||||
#define jas_image_cmptwidth(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->width_)
|
||||
|
||||
/* Get the height of a component. */
|
||||
#define jas_image_cmptheight(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->height_)
|
||||
|
||||
/* Get the signedness of the sample data for a component. */
|
||||
#define jas_image_cmptsgnd(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->sgnd_)
|
||||
|
||||
/* Get the precision of the sample data for a component. */
|
||||
#define jas_image_cmptprec(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->prec_)
|
||||
|
||||
/* Get the horizontal subsampling factor for a component. */
|
||||
#define jas_image_cmpthstep(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->hstep_)
|
||||
|
||||
/* Get the vertical subsampling factor for a component. */
|
||||
#define jas_image_cmptvstep(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->vstep_)
|
||||
|
||||
/* Get the x-coordinate of the top-left corner of a component. */
|
||||
#define jas_image_cmpttlx(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->tlx_)
|
||||
|
||||
/* Get the y-coordinate of the top-left corner of a component. */
|
||||
#define jas_image_cmpttly(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->tly_)
|
||||
|
||||
/* Get the x-coordinate of the bottom-right corner of a component
|
||||
(plus "one"). */
|
||||
#define jas_image_cmptbrx(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->tlx_ + (image)->cmpts_[cmptno]->width_ * \
|
||||
(image)->cmpts_[cmptno]->hstep_)
|
||||
|
||||
/* Get the y-coordinate of the bottom-right corner of a component
|
||||
(plus "one"). */
|
||||
#define jas_image_cmptbry(image, cmptno) \
|
||||
((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \
|
||||
(image)->cmpts_[cmptno]->vstep_)
|
||||
|
||||
/* Get the raw size of an image (i.e., the nominal size of the image without
|
||||
any compression. */
|
||||
uint_fast32_t jas_image_rawsize(jas_image_t *image);
|
||||
|
||||
/* Create an image from a stream in some specified format. */
|
||||
jas_image_t *jas_image_decode(jas_stream_t *in, int fmt, char *optstr);
|
||||
|
||||
/* Write an image to a stream in a specified format. */
|
||||
int jas_image_encode(jas_image_t *image, jas_stream_t *out, int fmt,
|
||||
char *optstr);
|
||||
|
||||
/* Read a rectangular region of an image component. */
|
||||
/* The position and size of the rectangular region to be read is specified
|
||||
relative to the component's coordinate system. */
|
||||
int jas_image_readcmpt(jas_image_t *image, int cmptno,
|
||||
jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
|
||||
jas_matrix_t *data);
|
||||
|
||||
/* Write a rectangular region of an image component. */
|
||||
int jas_image_writecmpt(jas_image_t *image, int cmptno,
|
||||
jas_image_coord_t x, jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
|
||||
jas_matrix_t *data);
|
||||
|
||||
/* Delete a component from an image. */
|
||||
void jas_image_delcmpt(jas_image_t *image, int cmptno);
|
||||
|
||||
/* Add a component to an image. */
|
||||
int jas_image_addcmpt(jas_image_t *image, int cmptno,
|
||||
jas_image_cmptparm_t *cmptparm);
|
||||
|
||||
/* Copy a component from one image to another. */
|
||||
int jas_image_copycmpt(jas_image_t *dstimage, int dstcmptno,
|
||||
jas_image_t *srcimage, int srccmptno);
|
||||
|
||||
#define JAS_IMAGE_CDT_GETSGND(dtype) (((dtype) >> 7) & 1)
|
||||
#define JAS_IMAGE_CDT_SETSGND(dtype) (((dtype) & 1) << 7)
|
||||
#define JAS_IMAGE_CDT_GETPREC(dtype) ((dtype) & 0x7f)
|
||||
#define JAS_IMAGE_CDT_SETPREC(dtype) ((dtype) & 0x7f)
|
||||
|
||||
#define jas_image_cmptdtype(image, cmptno) \
|
||||
(JAS_IMAGE_CDT_SETSGND((image)->cmpts_[cmptno]->sgnd_) | JAS_IMAGE_CDT_SETPREC((image)->cmpts_[cmptno]->prec_))
|
||||
|
||||
int jas_image_depalettize(jas_image_t *image, int cmptno, int numlutents,
|
||||
int_fast32_t *lutents, int dtype, int newcmptno);
|
||||
|
||||
int jas_image_readcmptsample(jas_image_t *image, int cmptno, int x, int y);
|
||||
void jas_image_writecmptsample(jas_image_t *image, int cmptno, int x, int y,
|
||||
int_fast32_t v);
|
||||
|
||||
int jas_image_getcmptbytype(jas_image_t *image, int ctype);
|
||||
|
||||
/******************************************************************************\
|
||||
* Image format-related operations.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Clear the table of image formats. */
|
||||
void jas_image_clearfmts(void);
|
||||
|
||||
/* Add entry to table of image formats. */
|
||||
int jas_image_addfmt(int id, char *name, char *ext, char *desc,
|
||||
jas_image_fmtops_t *ops);
|
||||
|
||||
/* Get the ID for the image format with the specified name. */
|
||||
int jas_image_strtofmt(char *s);
|
||||
|
||||
/* Get the name of the image format with the specified ID. */
|
||||
char *jas_image_fmttostr(int fmt);
|
||||
|
||||
/* Lookup image format information by the format ID. */
|
||||
jas_image_fmtinfo_t *jas_image_lookupfmtbyid(int id);
|
||||
|
||||
/* Lookup image format information by the format name. */
|
||||
jas_image_fmtinfo_t *jas_image_lookupfmtbyname(const char *name);
|
||||
|
||||
/* Guess the format of an image file based on its name. */
|
||||
int jas_image_fmtfromname(char *filename);
|
||||
|
||||
/* Get the format of image data in a stream. */
|
||||
int jas_image_getfmt(jas_stream_t *in);
|
||||
|
||||
|
||||
#define jas_image_cmprof(image) ((image)->cmprof_)
|
||||
int jas_image_ishomosamp(jas_image_t *image);
|
||||
int jas_image_sampcmpt(jas_image_t *image, int cmptno, int newcmptno,
|
||||
jas_image_coord_t ho, jas_image_coord_t vo, jas_image_coord_t hs,
|
||||
jas_image_coord_t vs, int sgnd, int prec);
|
||||
int jas_image_writecmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
|
||||
jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
|
||||
long *buf);
|
||||
int jas_image_readcmpt2(jas_image_t *image, int cmptno, jas_image_coord_t x,
|
||||
jas_image_coord_t y, jas_image_coord_t width, jas_image_coord_t height,
|
||||
long *buf);
|
||||
|
||||
#define jas_image_setcmprof(image, cmprof) ((image)->cmprof_ = cmprof)
|
||||
jas_image_t *jas_image_chclrspc(jas_image_t *image, jas_cmprof_t *outprof,
|
||||
int intent);
|
||||
void jas_image_dump(jas_image_t *image, FILE *out);
|
||||
|
||||
/******************************************************************************\
|
||||
* Image format-dependent operations.
|
||||
\******************************************************************************/
|
||||
|
||||
#if !defined(EXCLUDE_JPG_SUPPORT)
|
||||
/* Format-dependent operations for JPG support. */
|
||||
jas_image_t *jpg_decode(jas_stream_t *in, char *optstr);
|
||||
int jpg_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int jpg_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_MIF_SUPPORT)
|
||||
/* Format-dependent operations for MIF support. */
|
||||
jas_image_t *mif_decode(jas_stream_t *in, char *optstr);
|
||||
int mif_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int mif_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_PNM_SUPPORT)
|
||||
/* Format-dependent operations for PNM support. */
|
||||
jas_image_t *pnm_decode(jas_stream_t *in, char *optstr);
|
||||
int pnm_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int pnm_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_RAS_SUPPORT)
|
||||
/* Format-dependent operations for Sun Rasterfile support. */
|
||||
jas_image_t *ras_decode(jas_stream_t *in, char *optstr);
|
||||
int ras_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int ras_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_BMP_SUPPORT)
|
||||
/* Format-dependent operations for BMP support. */
|
||||
jas_image_t *bmp_decode(jas_stream_t *in, char *optstr);
|
||||
int bmp_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int bmp_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_JP2_SUPPORT)
|
||||
/* Format-dependent operations for JP2 support. */
|
||||
jas_image_t *jp2_decode(jas_stream_t *in, char *optstr);
|
||||
int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int jp2_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_JPC_SUPPORT)
|
||||
/* Format-dependent operations for JPEG-2000 code stream support. */
|
||||
jas_image_t *jpc_decode(jas_stream_t *in, char *optstr);
|
||||
int jpc_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int jpc_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#if !defined(EXCLUDE_PGX_SUPPORT)
|
||||
/* Format-dependent operations for PGX support. */
|
||||
jas_image_t *pgx_decode(jas_stream_t *in, char *optstr);
|
||||
int pgx_encode(jas_image_t *image, jas_stream_t *out, char *optstr);
|
||||
int pgx_validate(jas_stream_t *in);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JAS_INIT_H
|
||||
#define JAS_INIT_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
int jas_init(void);
|
||||
|
||||
void jas_cleanup(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Memory Allocator
|
||||
*
|
||||
* $Id: jas_malloc.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_MALLOC_H
|
||||
#define JAS_MALLOC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Hack follows...
|
||||
\******************************************************************************/
|
||||
|
||||
#if defined(DEBUG_MEMALLOC)
|
||||
/* This is somewhat of a hack, but it's a useful hack. :-) */
|
||||
/* Use my own custom memory allocator for debugging. */
|
||||
#include "../../../../local/src/memalloc.h"
|
||||
#define jas_malloc MEMALLOC
|
||||
#define jas_free MEMFREE
|
||||
#define jas_realloc MEMREALLOC
|
||||
#define jas_calloc MEMCALLOC
|
||||
#define jas_alloc2(a, b) MEMALLOC((a)*(b))
|
||||
#define jas_alloc3(a, b, c) MEMALLOC((a)*(b)*(c))
|
||||
#define jas_realloc2(p, a, b) MEMREALLOC((p), (a)*(b))
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
#if !defined(DEBUG_MEMALLOC)
|
||||
|
||||
/* Allocate memory. */
|
||||
void *jas_malloc(size_t size);
|
||||
|
||||
/* Free memory. */
|
||||
void jas_free(void *ptr);
|
||||
|
||||
/* Resize a block of allocated memory. */
|
||||
void *jas_realloc(void *ptr, size_t size);
|
||||
|
||||
/* Allocate a block of memory and initialize the contents to zero. */
|
||||
void *jas_calloc(size_t nmemb, size_t size);
|
||||
|
||||
/* size-checked double allocation .*/
|
||||
void *jas_alloc2(size_t, size_t);
|
||||
|
||||
void *jas_alloc3(size_t, size_t, size_t);
|
||||
|
||||
void *jas_realloc2(void *, size_t, size_t);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+117
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Math-Related Code
|
||||
*
|
||||
* $Id: jas_math.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_MATH_H
|
||||
#define JAS_MATH_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros
|
||||
\******************************************************************************/
|
||||
|
||||
/* Compute the absolute value. */
|
||||
#define JAS_ABS(x) \
|
||||
(((x) >= 0) ? (x) : (-(x)))
|
||||
|
||||
/* Compute the minimum of two values. */
|
||||
#define JAS_MIN(x, y) \
|
||||
(((x) < (y)) ? (x) : (y))
|
||||
|
||||
/* Compute the maximum of two values. */
|
||||
#define JAS_MAX(x, y) \
|
||||
(((x) > (y)) ? (x) : (y))
|
||||
|
||||
/* Compute the remainder from division (where division is defined such
|
||||
that the remainder is always nonnegative). */
|
||||
#define JAS_MOD(x, y) \
|
||||
(((x) < 0) ? (((-x) % (y)) ? ((y) - ((-(x)) % (y))) : (0)) : ((x) % (y)))
|
||||
|
||||
/* Compute the integer with the specified number of least significant bits
|
||||
set to one. */
|
||||
#define JAS_ONES(n) \
|
||||
((1 << (n)) - 1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+301
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sequence/Matrix Library
|
||||
*
|
||||
* $Id: jas_seq.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_SEQ_H
|
||||
#define JAS_SEQ_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#include <jasper/jas_stream.h>
|
||||
#include <jasper/jas_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* This matrix is a reference to another matrix. */
|
||||
#define JAS_MATRIX_REF 0x0001
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* An element in a sequence. */
|
||||
typedef int_fast32_t jas_seqent_t;
|
||||
|
||||
/* An element in a matrix. */
|
||||
typedef int_fast32_t jas_matent_t;
|
||||
|
||||
/* Matrix. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* Additional state information. */
|
||||
int flags_;
|
||||
|
||||
/* The starting horizontal index. */
|
||||
int_fast32_t xstart_;
|
||||
|
||||
/* The starting vertical index. */
|
||||
int_fast32_t ystart_;
|
||||
|
||||
/* The ending horizontal index. */
|
||||
int_fast32_t xend_;
|
||||
|
||||
/* The ending vertical index. */
|
||||
int_fast32_t yend_;
|
||||
|
||||
/* The number of rows in the matrix. */
|
||||
int_fast32_t numrows_;
|
||||
|
||||
/* The number of columns in the matrix. */
|
||||
int_fast32_t numcols_;
|
||||
|
||||
/* Pointers to the start of each row. */
|
||||
jas_seqent_t **rows_;
|
||||
|
||||
/* The allocated size of the rows array. */
|
||||
int_fast32_t maxrows_;
|
||||
|
||||
/* The matrix data buffer. */
|
||||
jas_seqent_t *data_;
|
||||
|
||||
/* The allocated size of the data array. */
|
||||
int_fast32_t datasize_;
|
||||
|
||||
} jas_matrix_t;
|
||||
|
||||
typedef jas_matrix_t jas_seq2d_t;
|
||||
typedef jas_matrix_t jas_seq_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for matrix class.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the number of rows. */
|
||||
#define jas_matrix_numrows(matrix) \
|
||||
((matrix)->numrows_)
|
||||
|
||||
/* Get the number of columns. */
|
||||
#define jas_matrix_numcols(matrix) \
|
||||
((matrix)->numcols_)
|
||||
|
||||
/* Get a matrix element. */
|
||||
#define jas_matrix_get(matrix, i, j) \
|
||||
((matrix)->rows_[i][j])
|
||||
|
||||
/* Set a matrix element. */
|
||||
#define jas_matrix_set(matrix, i, j, v) \
|
||||
((matrix)->rows_[i][j] = (v))
|
||||
|
||||
/* Get an element from a matrix that is known to be a row or column vector. */
|
||||
#define jas_matrix_getv(matrix, i) \
|
||||
(((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i]) : \
|
||||
((matrix)->rows_[i][0]))
|
||||
|
||||
/* Set an element in a matrix that is known to be a row or column vector. */
|
||||
#define jas_matrix_setv(matrix, i, v) \
|
||||
(((matrix)->numrows_ == 1) ? ((matrix)->rows_[0][i] = (v)) : \
|
||||
((matrix)->rows_[i][0] = (v)))
|
||||
|
||||
/* Get the address of an element in a matrix. */
|
||||
#define jas_matrix_getref(matrix, i, j) \
|
||||
(&(matrix)->rows_[i][j])
|
||||
|
||||
#define jas_matrix_getvref(matrix, i) \
|
||||
(((matrix)->numrows_ > 1) ? jas_matrix_getref(matrix, i, 0) : jas_matrix_getref(matrix, 0, i))
|
||||
|
||||
#define jas_matrix_length(matrix) \
|
||||
(max((matrix)->numrows_, (matrix)->numcols_))
|
||||
|
||||
/* Create a matrix with the specified dimensions. */
|
||||
jas_matrix_t *jas_matrix_create(int numrows, int numcols);
|
||||
|
||||
/* Destroy a matrix. */
|
||||
void jas_matrix_destroy(jas_matrix_t *matrix);
|
||||
|
||||
/* Resize a matrix. The previous contents of the matrix are lost. */
|
||||
int jas_matrix_resize(jas_matrix_t *matrix, int numrows, int numcols);
|
||||
|
||||
int jas_matrix_output(jas_matrix_t *matrix, FILE *out);
|
||||
|
||||
/* Create a matrix that references part of another matrix. */
|
||||
void jas_matrix_bindsub(jas_matrix_t *mat0, jas_matrix_t *mat1, int r0, int c0,
|
||||
int r1, int c1);
|
||||
|
||||
/* Create a matrix that is a reference to a row of another matrix. */
|
||||
#define jas_matrix_bindrow(mat0, mat1, r) \
|
||||
(jas_matrix_bindsub((mat0), (mat1), (r), 0, (r), (mat1)->numcols_ - 1))
|
||||
|
||||
/* Create a matrix that is a reference to a column of another matrix. */
|
||||
#define jas_matrix_bindcol(mat0, mat1, c) \
|
||||
(jas_matrix_bindsub((mat0), (mat1), 0, (c), (mat1)->numrows_ - 1, (c)))
|
||||
|
||||
/* Clip the values of matrix elements to the specified range. */
|
||||
void jas_matrix_clip(jas_matrix_t *matrix, jas_seqent_t minval,
|
||||
jas_seqent_t maxval);
|
||||
|
||||
/* Arithmetic shift left of all elements in a matrix. */
|
||||
void jas_matrix_asl(jas_matrix_t *matrix, int n);
|
||||
|
||||
/* Arithmetic shift right of all elements in a matrix. */
|
||||
void jas_matrix_asr(jas_matrix_t *matrix, int n);
|
||||
|
||||
/* Almost-but-not-quite arithmetic shift right of all elements in a matrix. */
|
||||
void jas_matrix_divpow2(jas_matrix_t *matrix, int n);
|
||||
|
||||
/* Set all elements of a matrix to the specified value. */
|
||||
void jas_matrix_setall(jas_matrix_t *matrix, jas_seqent_t val);
|
||||
|
||||
/* The spacing between rows of a matrix. */
|
||||
#define jas_matrix_rowstep(matrix) \
|
||||
(((matrix)->numrows_ > 1) ? ((matrix)->rows_[1] - (matrix)->rows_[0]) : (0))
|
||||
|
||||
/* The spacing between columns of a matrix. */
|
||||
#define jas_matrix_step(matrix) \
|
||||
(((matrix)->numrows_ > 1) ? (jas_matrix_rowstep(matrix)) : (1))
|
||||
|
||||
/* Compare two matrices for equality. */
|
||||
int jas_matrix_cmp(jas_matrix_t *mat0, jas_matrix_t *mat1);
|
||||
|
||||
jas_matrix_t *jas_matrix_copy(jas_matrix_t *x);
|
||||
|
||||
jas_matrix_t *jas_matrix_input(FILE *);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for 2-D sequence class.
|
||||
\******************************************************************************/
|
||||
|
||||
jas_seq2d_t *jas_seq2d_copy(jas_seq2d_t *x);
|
||||
|
||||
jas_matrix_t *jas_seq2d_create(int xstart, int ystart, int xend, int yend);
|
||||
|
||||
#define jas_seq2d_destroy(s) \
|
||||
jas_matrix_destroy(s)
|
||||
|
||||
#define jas_seq2d_xstart(s) \
|
||||
((s)->xstart_)
|
||||
#define jas_seq2d_ystart(s) \
|
||||
((s)->ystart_)
|
||||
#define jas_seq2d_xend(s) \
|
||||
((s)->xend_)
|
||||
#define jas_seq2d_yend(s) \
|
||||
((s)->yend_)
|
||||
#define jas_seq2d_getref(s, x, y) \
|
||||
(jas_matrix_getref(s, (y) - (s)->ystart_, (x) - (s)->xstart_))
|
||||
#define jas_seq2d_get(s, x, y) \
|
||||
(jas_matrix_get(s, (y) - (s)->ystart_, (x) - (s)->xstart_))
|
||||
#define jas_seq2d_rowstep(s) \
|
||||
jas_matrix_rowstep(s)
|
||||
#define jas_seq2d_width(s) \
|
||||
((s)->xend_ - (s)->xstart_)
|
||||
#define jas_seq2d_height(s) \
|
||||
((s)->yend_ - (s)->ystart_)
|
||||
#define jas_seq2d_setshift(s, x, y) \
|
||||
((s)->xstart_ = (x), (s)->ystart_ = (y), \
|
||||
(s)->xend_ = (s)->xstart_ + (s)->numcols_, \
|
||||
(s)->yend_ = (s)->ystart_ + (s)->numrows_)
|
||||
|
||||
void jas_seq2d_bindsub(jas_matrix_t *s, jas_matrix_t *s1, int xstart,
|
||||
int ystart, int xend, int yend);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for 1-D sequence class.
|
||||
\******************************************************************************/
|
||||
|
||||
#define jas_seq_create(start, end) \
|
||||
(jas_seq2d_create(start, 0, end, 1))
|
||||
|
||||
#define jas_seq_destroy(seq) \
|
||||
(jas_seq2d_destroy(seq))
|
||||
|
||||
#define jas_seq_set(seq, i, v) \
|
||||
((seq)->rows_[0][(i) - (seq)->xstart_] = (v))
|
||||
#define jas_seq_getref(seq, i) \
|
||||
(&(seq)->rows_[0][(i) - (seq)->xstart_])
|
||||
#define jas_seq_get(seq, i) \
|
||||
((seq)->rows_[0][(i) - (seq)->xstart_])
|
||||
#define jas_seq_start(seq) \
|
||||
((seq)->xstart_)
|
||||
#define jas_seq_end(seq) \
|
||||
((seq)->xend_)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+469
@@ -0,0 +1,469 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* I/O Stream Class
|
||||
*
|
||||
* $Id: jas_stream.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_STREAM_H
|
||||
#define JAS_STREAM_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#if defined(HAVE_FCNTL_H)
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#if defined(HAVE_UNISTD_H)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <jasper/jas_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* On most UNIX systems, we probably need to define O_BINARY ourselves. */
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Stream open flags.
|
||||
*/
|
||||
|
||||
/* The stream was opened for reading. */
|
||||
#define JAS_STREAM_READ 0x0001
|
||||
/* The stream was opened for writing. */
|
||||
#define JAS_STREAM_WRITE 0x0002
|
||||
/* The stream was opened for appending. */
|
||||
#define JAS_STREAM_APPEND 0x0004
|
||||
/* The stream was opened in binary mode. */
|
||||
#define JAS_STREAM_BINARY 0x0008
|
||||
/* The stream should be created/truncated. */
|
||||
#define JAS_STREAM_CREATE 0x0010
|
||||
|
||||
|
||||
/*
|
||||
* Stream buffering flags.
|
||||
*/
|
||||
|
||||
/* The stream is unbuffered. */
|
||||
#define JAS_STREAM_UNBUF 0x0000
|
||||
/* The stream is line buffered. */
|
||||
#define JAS_STREAM_LINEBUF 0x0001
|
||||
/* The stream is fully buffered. */
|
||||
#define JAS_STREAM_FULLBUF 0x0002
|
||||
/* The buffering mode mask. */
|
||||
#define JAS_STREAM_BUFMODEMASK 0x000f
|
||||
|
||||
/* The memory associated with the buffer needs to be deallocated when the
|
||||
stream is destroyed. */
|
||||
#define JAS_STREAM_FREEBUF 0x0008
|
||||
/* The buffer is currently being used for reading. */
|
||||
#define JAS_STREAM_RDBUF 0x0010
|
||||
/* The buffer is currently being used for writing. */
|
||||
#define JAS_STREAM_WRBUF 0x0020
|
||||
|
||||
/*
|
||||
* Stream error flags.
|
||||
*/
|
||||
|
||||
/* The end-of-file has been encountered (on reading). */
|
||||
#define JAS_STREAM_EOF 0x0001
|
||||
/* An I/O error has been encountered on the stream. */
|
||||
#define JAS_STREAM_ERR 0x0002
|
||||
/* The read/write limit has been exceeded. */
|
||||
#define JAS_STREAM_RWLIMIT 0x0004
|
||||
/* The error mask. */
|
||||
#define JAS_STREAM_ERRMASK \
|
||||
(JAS_STREAM_EOF | JAS_STREAM_ERR | JAS_STREAM_RWLIMIT)
|
||||
|
||||
/*
|
||||
* Other miscellaneous constants.
|
||||
*/
|
||||
|
||||
/* The default buffer size (for fully-buffered operation). */
|
||||
#define JAS_STREAM_BUFSIZE 8192
|
||||
/* The default permission mask for file creation. */
|
||||
#define JAS_STREAM_PERMS 0666
|
||||
|
||||
/* The maximum number of characters that can always be put back on a stream. */
|
||||
#define JAS_STREAM_MAXPUTBACK 16
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Generic file object.
|
||||
*/
|
||||
|
||||
typedef void jas_stream_obj_t;
|
||||
|
||||
/*
|
||||
* Generic file object operations.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* Read characters from a file object. */
|
||||
int (*read_)(jas_stream_obj_t *obj, char *buf, int cnt);
|
||||
|
||||
/* Write characters to a file object. */
|
||||
int (*write_)(jas_stream_obj_t *obj, char *buf, int cnt);
|
||||
|
||||
/* Set the position for a file object. */
|
||||
long (*seek_)(jas_stream_obj_t *obj, long offset, int origin);
|
||||
|
||||
/* Close a file object. */
|
||||
int (*close_)(jas_stream_obj_t *obj);
|
||||
|
||||
} jas_stream_ops_t;
|
||||
|
||||
/*
|
||||
* Stream object.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The mode in which the stream was opened. */
|
||||
int openmode_;
|
||||
|
||||
/* The buffering mode. */
|
||||
int bufmode_;
|
||||
|
||||
/* The stream status. */
|
||||
int flags_;
|
||||
|
||||
/* The start of the buffer area to use for reading/writing. */
|
||||
uchar *bufbase_;
|
||||
|
||||
/* The start of the buffer area excluding the extra initial space for
|
||||
character putback. */
|
||||
uchar *bufstart_;
|
||||
|
||||
/* The buffer size. */
|
||||
int bufsize_;
|
||||
|
||||
/* The current position in the buffer. */
|
||||
uchar *ptr_;
|
||||
|
||||
/* The number of characters that must be read/written before
|
||||
the buffer needs to be filled/flushed. */
|
||||
int cnt_;
|
||||
|
||||
/* A trivial buffer to be used for unbuffered operation. */
|
||||
uchar tinybuf_[JAS_STREAM_MAXPUTBACK + 1];
|
||||
|
||||
/* The operations for the underlying stream file object. */
|
||||
jas_stream_ops_t *ops_;
|
||||
|
||||
/* The underlying stream file object. */
|
||||
jas_stream_obj_t *obj_;
|
||||
|
||||
/* The number of characters read/written. */
|
||||
long rwcnt_;
|
||||
|
||||
/* The maximum number of characters that may be read/written. */
|
||||
long rwlimit_;
|
||||
|
||||
} jas_stream_t;
|
||||
|
||||
/*
|
||||
* Regular file object.
|
||||
*/
|
||||
|
||||
/*
|
||||
* File descriptor file object.
|
||||
*/
|
||||
typedef struct {
|
||||
int fd;
|
||||
int flags;
|
||||
#if defined _WIN32 && !defined __MINGW__ && !defined __MINGW32__
|
||||
char pathname[MAX_PATH + 1];
|
||||
#else
|
||||
char pathname[PATH_MAX + 1];
|
||||
#endif
|
||||
} jas_stream_fileobj_t;
|
||||
|
||||
#define JAS_STREAM_FILEOBJ_DELONCLOSE 0x01
|
||||
#define JAS_STREAM_FILEOBJ_NOCLOSE 0x02
|
||||
|
||||
/*
|
||||
* Memory file object.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The data associated with this file. */
|
||||
uchar *buf_;
|
||||
|
||||
/* The allocated size of the buffer for holding file data. */
|
||||
int bufsize_;
|
||||
|
||||
/* The length of the file. */
|
||||
int_fast32_t len_;
|
||||
|
||||
/* The seek position. */
|
||||
int_fast32_t pos_;
|
||||
|
||||
/* Is the buffer growable? */
|
||||
int growable_;
|
||||
|
||||
/* Was the buffer allocated internally? */
|
||||
int myalloc_;
|
||||
|
||||
} jas_stream_memobj_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/functions for opening and closing streams.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Open a file as a stream. */
|
||||
jas_stream_t *jas_stream_fopen(const char *filename, const char *mode);
|
||||
|
||||
/* Open a memory buffer as a stream. */
|
||||
jas_stream_t *jas_stream_memopen(char *buf, int bufsize);
|
||||
|
||||
/* Open a file descriptor as a stream. */
|
||||
jas_stream_t *jas_stream_fdopen(int fd, const char *mode);
|
||||
|
||||
/* Open a stdio stream as a stream. */
|
||||
jas_stream_t *jas_stream_freopen(const char *path, const char *mode, FILE *fp);
|
||||
|
||||
/* Open a temporary file as a stream. */
|
||||
jas_stream_t *jas_stream_tmpfile(void);
|
||||
|
||||
/* Close a stream. */
|
||||
int jas_stream_close(jas_stream_t *stream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/functions for getting/setting the stream state.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the EOF indicator for a stream. */
|
||||
#define jas_stream_eof(stream) \
|
||||
(((stream)->flags_ & JAS_STREAM_EOF) != 0)
|
||||
|
||||
/* Get the error indicator for a stream. */
|
||||
#define jas_stream_error(stream) \
|
||||
(((stream)->flags_ & JAS_STREAM_ERR) != 0)
|
||||
|
||||
/* Clear the error indicator for a stream. */
|
||||
#define jas_stream_clearerr(stream) \
|
||||
((stream)->flags_ &= ~(JAS_STREAM_ERR | JAS_STREAM_EOF))
|
||||
|
||||
/* Get the read/write limit for a stream. */
|
||||
#define jas_stream_getrwlimit(stream) \
|
||||
(((const jas_stream_t *)(stream))->rwlimit_)
|
||||
|
||||
/* Set the read/write limit for a stream. */
|
||||
int jas_stream_setrwlimit(jas_stream_t *stream, long rwlimit);
|
||||
|
||||
/* Get the read/write count for a stream. */
|
||||
#define jas_stream_getrwcount(stream) \
|
||||
(((const jas_stream_t *)(stream))->rwcnt_)
|
||||
|
||||
/* Set the read/write count for a stream. */
|
||||
long jas_stream_setrwcount(jas_stream_t *stream, long rwcnt);
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/functions for I/O.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Read a character from a stream. */
|
||||
#if defined(DEBUG)
|
||||
#define jas_stream_getc(stream) jas_stream_getc_func(stream)
|
||||
#else
|
||||
#define jas_stream_getc(stream) jas_stream_getc_macro(stream)
|
||||
#endif
|
||||
|
||||
/* Write a character to a stream. */
|
||||
#if defined(DEBUG)
|
||||
#define jas_stream_putc(stream, c) jas_stream_putc_func(stream, c)
|
||||
#else
|
||||
#define jas_stream_putc(stream, c) jas_stream_putc_macro(stream, c)
|
||||
#endif
|
||||
|
||||
/* Read characters from a stream into a buffer. */
|
||||
int jas_stream_read(jas_stream_t *stream, void *buf, int cnt);
|
||||
|
||||
/* Write characters from a buffer to a stream. */
|
||||
int jas_stream_write(jas_stream_t *stream, const void *buf, int cnt);
|
||||
|
||||
/* Write formatted output to a stream. */
|
||||
int jas_stream_printf(jas_stream_t *stream, const char *fmt, ...);
|
||||
|
||||
/* Write a string to a stream. */
|
||||
int jas_stream_puts(jas_stream_t *stream, const char *s);
|
||||
|
||||
/* Read a line of input from a stream. */
|
||||
char *jas_stream_gets(jas_stream_t *stream, char *buf, int bufsize);
|
||||
|
||||
/* Look at the next character to be read from a stream without actually
|
||||
removing it from the stream. */
|
||||
#define jas_stream_peekc(stream) \
|
||||
(((stream)->cnt_ <= 0) ? jas_stream_fillbuf(stream, 0) : \
|
||||
((int)(*(stream)->ptr_)))
|
||||
|
||||
/* Put a character back on a stream. */
|
||||
int jas_stream_ungetc(jas_stream_t *stream, int c);
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/functions for getting/setting the stream position.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Is it possible to seek on this stream? */
|
||||
int jas_stream_isseekable(jas_stream_t *stream);
|
||||
|
||||
/* Set the current position within the stream. */
|
||||
long jas_stream_seek(jas_stream_t *stream, long offset, int origin);
|
||||
|
||||
/* Get the current position within the stream. */
|
||||
long jas_stream_tell(jas_stream_t *stream);
|
||||
|
||||
/* Seek to the beginning of a stream. */
|
||||
int jas_stream_rewind(jas_stream_t *stream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/functions for flushing.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Flush any pending output to a stream. */
|
||||
int jas_stream_flush(jas_stream_t *stream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous macros/functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Copy data from one stream to another. */
|
||||
int jas_stream_copy(jas_stream_t *dst, jas_stream_t *src, int n);
|
||||
|
||||
/* Display stream contents (for debugging purposes). */
|
||||
int jas_stream_display(jas_stream_t *stream, FILE *fp, int n);
|
||||
|
||||
/* Consume (i.e., discard) characters from stream. */
|
||||
int jas_stream_gobble(jas_stream_t *stream, int n);
|
||||
|
||||
/* Write a character multiple times to a stream. */
|
||||
int jas_stream_pad(jas_stream_t *stream, int n, int c);
|
||||
|
||||
/* Get the size of the file associated with the specified stream.
|
||||
The specified stream must be seekable. */
|
||||
long jas_stream_length(jas_stream_t *stream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Internal functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The following functions are for internal use only! If you call them
|
||||
directly, you will die a horrible, miserable, and painful death! */
|
||||
|
||||
/* Read a character from a stream. */
|
||||
#define jas_stream_getc_macro(stream) \
|
||||
((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \
|
||||
JAS_STREAM_RWLIMIT))) ? \
|
||||
(((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \
|
||||
(stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \
|
||||
jas_stream_getc2(stream)) : EOF)
|
||||
#define jas_stream_getc2(stream) \
|
||||
((--(stream)->cnt_ < 0) ? jas_stream_fillbuf(stream, 1) : \
|
||||
(++(stream)->rwcnt_, (int)(*(stream)->ptr_++)))
|
||||
|
||||
/* Write a character to a stream. */
|
||||
#define jas_stream_putc_macro(stream, c) \
|
||||
((!((stream)->flags_ & (JAS_STREAM_ERR | JAS_STREAM_EOF | \
|
||||
JAS_STREAM_RWLIMIT))) ? \
|
||||
(((stream)->rwlimit_ >= 0 && (stream)->rwcnt_ >= (stream)->rwlimit_) ? \
|
||||
(stream->flags_ |= JAS_STREAM_RWLIMIT, EOF) : \
|
||||
jas_stream_putc2(stream, c)) : EOF)
|
||||
#define jas_stream_putc2(stream, c) \
|
||||
(((stream)->bufmode_ |= JAS_STREAM_WRBUF, --(stream)->cnt_ < 0) ? \
|
||||
jas_stream_flushbuf((stream), (uchar)(c)) : \
|
||||
(++(stream)->rwcnt_, (int)(*(stream)->ptr_++ = (c))))
|
||||
|
||||
/* These prototypes need to be here for the sake of the stream_getc and
|
||||
stream_putc macros. */
|
||||
int jas_stream_fillbuf(jas_stream_t *stream, int getflag);
|
||||
int jas_stream_flushbuf(jas_stream_t *stream, int c);
|
||||
int jas_stream_getc_func(jas_stream_t *stream);
|
||||
int jas_stream_putc_func(jas_stream_t *stream, int c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* String Library
|
||||
*
|
||||
* $Id: jas_string.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_STRING_H
|
||||
#define JAS_STRING_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Copy a string (a la strdup). */
|
||||
char *jas_strdup(const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+103
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2004 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JAS_TMR_H
|
||||
#define JAS_TMR_H
|
||||
|
||||
#include<time.h>
|
||||
#include <jasper/jas_config.h>
|
||||
#if defined(HAVE_SYS_TIME_H)
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_GETTIMEOFDAY)
|
||||
|
||||
typedef struct {
|
||||
struct timeval start;
|
||||
struct timeval stop;
|
||||
} jas_tmr_t;
|
||||
|
||||
#elif defined(HAVE_GETRUSAGE)
|
||||
|
||||
typedef struct {
|
||||
struct rusage start;
|
||||
struct rusage stop;
|
||||
} jas_tmr_t;
|
||||
|
||||
#else
|
||||
|
||||
typedef int jas_tmr_t;
|
||||
|
||||
#endif
|
||||
|
||||
void jas_tmr_start(jas_tmr_t *tmr);
|
||||
void jas_tmr_stop(jas_tmr_t *tmr);
|
||||
double jas_tmr_get(jas_tmr_t *tmr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tag/Value Parser
|
||||
*
|
||||
* $Id: jas_tvp.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_TVP_H
|
||||
#define JAS_TVP_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Tag information type. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
int id;
|
||||
/* The ID for the tag. */
|
||||
|
||||
char *name;
|
||||
/* The name of the tag. */
|
||||
|
||||
} jas_taginfo_t;
|
||||
|
||||
/* Tag-value parser type. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
char *buf;
|
||||
/* The parsing buffer. */
|
||||
|
||||
char *tag;
|
||||
/* The current tag name. */
|
||||
|
||||
char *val;
|
||||
/* The current value. */
|
||||
|
||||
char *pos;
|
||||
/* The current position in the parsing buffer. */
|
||||
|
||||
} jas_tvparser_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Tag information functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Lookup a tag by name. */
|
||||
jas_taginfo_t *jas_taginfos_lookup(jas_taginfo_t *taginfos, const char *name);
|
||||
|
||||
/* This function returns a pointer to the specified taginfo object if it
|
||||
exists (i.e., the pointer is nonnull); otherwise, a pointer to a dummy
|
||||
object is returned. This is useful in some situations to avoid checking
|
||||
for a null pointer. */
|
||||
jas_taginfo_t *jas_taginfo_nonull(jas_taginfo_t *taginfo);
|
||||
|
||||
/******************************************************************************\
|
||||
* Tag-value parser functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a tag-value parser for the specified string. */
|
||||
jas_tvparser_t *jas_tvparser_create(const char *s);
|
||||
|
||||
/* Destroy a tag-value parser. */
|
||||
void jas_tvparser_destroy(jas_tvparser_t *tvparser);
|
||||
|
||||
/* Get the next tag-value pair. */
|
||||
int jas_tvparser_next(jas_tvparser_t *tvparser);
|
||||
|
||||
/* Get the tag name for the current tag-value pair. */
|
||||
char *jas_tvparser_gettag(jas_tvparser_t *tvparser);
|
||||
|
||||
/* Get the value for the current tag-value pair. */
|
||||
char *jas_tvparser_getval(jas_tvparser_t *tvparser);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Primitive Types
|
||||
*
|
||||
* $Id: jas_types.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_TYPES_H
|
||||
#define JAS_TYPES_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#if !defined(JAS_CONFIGURE)
|
||||
|
||||
#if defined(WIN32) || defined(HAVE_WINDOWS_H)
|
||||
/*
|
||||
We are dealing with Microsoft Windows and most likely Microsoft
|
||||
Visual C (MSVC). (Heaven help us.) Sadly, MSVC does not correctly
|
||||
define some of the standard types specified in ISO/IEC 9899:1999.
|
||||
In particular, it does not define the "long long" and "unsigned long
|
||||
long" types. So, we work around this problem by using the "INT64"
|
||||
and "UINT64" types that are defined in the header file "windows.h".
|
||||
*/
|
||||
#include <windows.h>
|
||||
#undef longlong
|
||||
#define longlong INT64
|
||||
#undef ulonglong
|
||||
#define ulonglong UINT64
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STDLIB_H)
|
||||
#undef false
|
||||
#undef true
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#if defined(HAVE_STDDEF_H)
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef __cplusplus
|
||||
#if defined(HAVE_STDBOOL_H)
|
||||
/*
|
||||
* The C language implementation does correctly provide the standard header
|
||||
* file "stdbool.h".
|
||||
*/
|
||||
#include <stdbool.h>
|
||||
#else
|
||||
|
||||
/*
|
||||
* The C language implementation does not provide the standard header file
|
||||
* "stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this
|
||||
* braindamage below.
|
||||
*/
|
||||
#if !defined(bool)
|
||||
#define bool int
|
||||
#endif
|
||||
#if !defined(true)
|
||||
#define true 1
|
||||
#endif
|
||||
#if !defined(false)
|
||||
#define false 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STDINT_H)
|
||||
/*
|
||||
* The C language implementation does correctly provide the standard header
|
||||
* file "stdint.h".
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#else
|
||||
/*
|
||||
* The C language implementation does not provide the standard header file
|
||||
* "stdint.h" as required by ISO/IEC 9899:1999. Try to compensate for this
|
||||
* braindamage below.
|
||||
*/
|
||||
#include <limits.h>
|
||||
/**********/
|
||||
#if !defined(INT_FAST8_MIN)
|
||||
typedef signed char int_fast8_t;
|
||||
#define INT_FAST8_MIN (-127)
|
||||
#define INT_FAST8_MAX 128
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(UINT_FAST8_MAX)
|
||||
typedef unsigned char uint_fast8_t;
|
||||
#define UINT_FAST8_MAX 255
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(INT_FAST16_MIN)
|
||||
typedef short int_fast16_t;
|
||||
#define INT_FAST16_MIN SHRT_MIN
|
||||
#define INT_FAST16_MAX SHRT_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(UINT_FAST16_MAX)
|
||||
typedef unsigned short uint_fast16_t;
|
||||
#define UINT_FAST16_MAX USHRT_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(INT_FAST32_MIN)
|
||||
typedef int int_fast32_t;
|
||||
#define INT_FAST32_MIN INT_MIN
|
||||
#define INT_FAST32_MAX INT_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(UINT_FAST32_MAX)
|
||||
typedef unsigned int uint_fast32_t;
|
||||
#define UINT_FAST32_MAX UINT_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(INT_FAST64_MIN)
|
||||
typedef longlong int_fast64_t;
|
||||
#define INT_FAST64_MIN LLONG_MIN
|
||||
#define INT_FAST64_MAX LLONG_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#if !defined(UINT_FAST64_MAX)
|
||||
typedef ulonglong uint_fast64_t;
|
||||
#define UINT_FAST64_MAX ULLONG_MAX
|
||||
#endif
|
||||
/**********/
|
||||
#endif
|
||||
|
||||
/* Hopefully, these macro definitions will fix more problems than they cause. */
|
||||
#if !defined(uchar)
|
||||
#define uchar unsigned char
|
||||
#endif
|
||||
#if !defined(ushort)
|
||||
#define ushort unsigned short
|
||||
#endif
|
||||
#if !defined(uint)
|
||||
#define uint unsigned int
|
||||
#endif
|
||||
#if !defined(ulong)
|
||||
#define ulong unsigned long
|
||||
#endif
|
||||
#if !defined(longlong)
|
||||
#define longlong long long
|
||||
#endif
|
||||
#if !defined(ulonglong)
|
||||
#define ulonglong unsigned long long
|
||||
#endif
|
||||
|
||||
/* The below macro is intended to be used for type casts. By using this
|
||||
macro, type casts can be easily located in the source code with
|
||||
tools like "grep". */
|
||||
#define JAS_CAST(t, e) \
|
||||
((t) (e))
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jas_version.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JAS_VERSION_H
|
||||
#define JAS_VERSION_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants and types.
|
||||
\******************************************************************************/
|
||||
|
||||
#if !defined(JAS_VERSION)
|
||||
/* The version information below should match that specified in
|
||||
the "configure.in" file! */
|
||||
#define JAS_VERSION "unknown"
|
||||
#endif
|
||||
|
||||
#define JAS_COPYRIGHT \
|
||||
"Copyright (c) 2001-2006 Michael David Adams.\n" \
|
||||
"Copyright (c) 1999-2000 Image Power, Inc. and the University of\n" \
|
||||
" British Columbia.\n" \
|
||||
"All rights reserved.\n"
|
||||
|
||||
#define JAS_NOTES \
|
||||
"For more information about this software, please visit the following\n" \
|
||||
"web sites/pages:\n" \
|
||||
" http://www.ece.uvic.ca/~mdadams/jasper\n" \
|
||||
" http://www.jpeg.org/software\n" \
|
||||
"To be added to the (moderated) JasPer software announcements\n" \
|
||||
"mailing list, send an email to:\n" \
|
||||
" jasper-announce-subscribe@yahoogroups.com\n" \
|
||||
"To be added to the (unmoderated) JasPer software discussion\n" \
|
||||
"mailing list, send an email to:\n" \
|
||||
" jasper-discussion-subscribe@yahoogroups.com\n" \
|
||||
"Please send any bug reports to:\n" \
|
||||
" mdadams@ieee.org\n"
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
const char *jas_getversion(void);
|
||||
/* Get the version information for the JasPer library. */
|
||||
/* Note: Since libjasper can be built as a shared library, the version
|
||||
returned by this function may not necessarily correspond to JAS_VERSION. */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JAS_JASPER_H
|
||||
#define JAS_JASPER_H
|
||||
|
||||
#include <jasper/jas_config.h>
|
||||
#include <jasper/jas_types.h>
|
||||
#include <jasper/jas_version.h>
|
||||
|
||||
#include <jasper/jas_init.h>
|
||||
#include <jasper/jas_cm.h>
|
||||
#include <jasper/jas_icc.h>
|
||||
#include <jasper/jas_fix.h>
|
||||
#include <jasper/jas_debug.h>
|
||||
#include <jasper/jas_getopt.h>
|
||||
#include <jasper/jas_image.h>
|
||||
#include <jasper/jas_icc.h>
|
||||
#include <jasper/jas_math.h>
|
||||
#include <jasper/jas_malloc.h>
|
||||
#include <jasper/jas_seq.h>
|
||||
#include <jasper/jas_stream.h>
|
||||
#include <jasper/jas_string.h>
|
||||
#include <jasper/jas_tmr.h>
|
||||
#include <jasper/jas_tvp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
+979
@@ -0,0 +1,979 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by Andrey Kiselev <dron@remotesensing.org> to handle UUID
|
||||
* box properly.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JP2 Library
|
||||
*
|
||||
* $Id: jp2_cod.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jp2_cod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Function prototypes.
|
||||
\******************************************************************************/
|
||||
|
||||
#define ONES(n) ((1 << (n)) - 1)
|
||||
|
||||
jp2_boxinfo_t *jp2_boxinfolookup(int type);
|
||||
|
||||
static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val);
|
||||
static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val);
|
||||
static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val);
|
||||
static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val);
|
||||
static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val);
|
||||
static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val);
|
||||
static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val);
|
||||
static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val);
|
||||
|
||||
static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val);
|
||||
|
||||
jp2_box_t *jp2_box_get(jas_stream_t *in);
|
||||
void jp2_box_dump(jp2_box_t *box, FILE *out);
|
||||
|
||||
static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static void jp2_bpcc_destroy(jp2_box_t *box);
|
||||
static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out);
|
||||
static void jp2_colr_destroy(jp2_box_t *box);
|
||||
static void jp2_cdef_destroy(jp2_box_t *box);
|
||||
static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out);
|
||||
static void jp2_cmap_destroy(jp2_box_t *box);
|
||||
static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out);
|
||||
static void jp2_pclr_destroy(jp2_box_t *box);
|
||||
static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out);
|
||||
static void jp2_uuid_destroy(jp2_box_t *box);
|
||||
static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in);
|
||||
static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out);
|
||||
|
||||
/******************************************************************************\
|
||||
* Local data.
|
||||
\******************************************************************************/
|
||||
|
||||
jp2_boxinfo_t jp2_boxinfos[] = {
|
||||
{JP2_BOX_JP, "JP", 0,
|
||||
{0, 0, jp2_jp_getdata, jp2_jp_putdata, 0}},
|
||||
{JP2_BOX_FTYP, "FTYP", 0,
|
||||
{0, 0, jp2_ftyp_getdata, jp2_ftyp_putdata, 0}},
|
||||
{JP2_BOX_JP2H, "JP2H", JP2_BOX_SUPER,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_IHDR, "IHDR", 0,
|
||||
{0, 0, jp2_ihdr_getdata, jp2_ihdr_putdata, 0}},
|
||||
{JP2_BOX_BPCC, "BPCC", 0,
|
||||
{0, jp2_bpcc_destroy, jp2_bpcc_getdata, jp2_bpcc_putdata, 0}},
|
||||
{JP2_BOX_COLR, "COLR", 0,
|
||||
{0, jp2_colr_destroy, jp2_colr_getdata, jp2_colr_putdata, jp2_colr_dumpdata}},
|
||||
{JP2_BOX_PCLR, "PCLR", 0,
|
||||
{0, jp2_pclr_destroy, jp2_pclr_getdata, jp2_pclr_putdata, jp2_pclr_dumpdata}},
|
||||
{JP2_BOX_CMAP, "CMAP", 0,
|
||||
{0, jp2_cmap_destroy, jp2_cmap_getdata, jp2_cmap_putdata, jp2_cmap_dumpdata}},
|
||||
{JP2_BOX_CDEF, "CDEF", 0,
|
||||
{0, jp2_cdef_destroy, jp2_cdef_getdata, jp2_cdef_putdata, jp2_cdef_dumpdata}},
|
||||
{JP2_BOX_RES, "RES", JP2_BOX_SUPER,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_RESC, "RESC", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_RESD, "RESD", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_JP2C, "JP2C", JP2_BOX_NODATA,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_JP2I, "JP2I", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_XML, "XML", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_UUID, "UUID", 0,
|
||||
{0, jp2_uuid_destroy, jp2_uuid_getdata, jp2_uuid_putdata, 0}},
|
||||
{JP2_BOX_UINF, "UINF", JP2_BOX_SUPER,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_ULST, "ULST", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{JP2_BOX_URL, "URL", 0,
|
||||
{0, 0, 0, 0, 0}},
|
||||
{0, 0, 0, {0, 0, 0, 0, 0}},
|
||||
};
|
||||
|
||||
jp2_boxinfo_t jp2_boxinfo_unk = {
|
||||
0, "Unknown", 0, {0, 0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/******************************************************************************\
|
||||
* Box constructor.
|
||||
\******************************************************************************/
|
||||
|
||||
jp2_box_t *jp2_box_create(int type)
|
||||
{
|
||||
jp2_box_t *box;
|
||||
jp2_boxinfo_t *boxinfo;
|
||||
|
||||
if (!(box = jas_malloc(sizeof(jp2_box_t)))) {
|
||||
return 0;
|
||||
}
|
||||
memset(box, 0, sizeof(jp2_box_t));
|
||||
box->type = type;
|
||||
box->len = 0;
|
||||
if (!(boxinfo = jp2_boxinfolookup(type))) {
|
||||
return 0;
|
||||
}
|
||||
box->info = boxinfo;
|
||||
box->ops = &boxinfo->ops;
|
||||
return box;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Box destructor.
|
||||
\******************************************************************************/
|
||||
|
||||
void jp2_box_destroy(jp2_box_t *box)
|
||||
{
|
||||
if (box->ops->destroy) {
|
||||
(*box->ops->destroy)(box);
|
||||
}
|
||||
jas_free(box);
|
||||
}
|
||||
|
||||
static void jp2_bpcc_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_bpcc_t *bpcc = &box->data.bpcc;
|
||||
if (bpcc->bpcs) {
|
||||
jas_free(bpcc->bpcs);
|
||||
bpcc->bpcs = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void jp2_cdef_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_cdef_t *cdef = &box->data.cdef;
|
||||
if (cdef->ents) {
|
||||
jas_free(cdef->ents);
|
||||
cdef->ents = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Box input.
|
||||
\******************************************************************************/
|
||||
|
||||
jp2_box_t *jp2_box_get(jas_stream_t *in)
|
||||
{
|
||||
jp2_box_t *box;
|
||||
jp2_boxinfo_t *boxinfo;
|
||||
jas_stream_t *tmpstream;
|
||||
uint_fast32_t len;
|
||||
uint_fast64_t extlen;
|
||||
bool dataflag;
|
||||
|
||||
box = 0;
|
||||
tmpstream = 0;
|
||||
|
||||
if (!(box = jas_malloc(sizeof(jp2_box_t)))) {
|
||||
goto error;
|
||||
}
|
||||
box->ops = &jp2_boxinfo_unk.ops;
|
||||
if (jp2_getuint32(in, &len) || jp2_getuint32(in, &box->type)) {
|
||||
goto error;
|
||||
}
|
||||
boxinfo = jp2_boxinfolookup(box->type);
|
||||
box->info = boxinfo;
|
||||
box->ops = &boxinfo->ops;
|
||||
box->len = len;
|
||||
if (box->len == 1) {
|
||||
if (jp2_getuint64(in, &extlen)) {
|
||||
goto error;
|
||||
}
|
||||
if (extlen > 0xffffffffUL) {
|
||||
jas_eprintf("warning: cannot handle large 64-bit box length\n");
|
||||
extlen = 0xffffffffUL;
|
||||
}
|
||||
box->len = extlen;
|
||||
box->datalen = extlen - JP2_BOX_HDRLEN(true);
|
||||
} else {
|
||||
box->datalen = box->len - JP2_BOX_HDRLEN(false);
|
||||
}
|
||||
if (box->len != 0 && box->len < 8) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA));
|
||||
|
||||
if (dataflag) {
|
||||
if (!(tmpstream = jas_stream_memopen(0, 0))) {
|
||||
goto error;
|
||||
}
|
||||
if (jas_stream_copy(tmpstream, in, box->datalen)) {
|
||||
jas_eprintf("cannot copy box data\n");
|
||||
goto error;
|
||||
}
|
||||
jas_stream_rewind(tmpstream);
|
||||
|
||||
if (box->ops->getdata) {
|
||||
if ((*box->ops->getdata)(box, tmpstream)) {
|
||||
jas_eprintf("cannot parse box data\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
jas_stream_close(tmpstream);
|
||||
}
|
||||
|
||||
if (jas_getdbglevel() >= 1) {
|
||||
jp2_box_dump(box, stderr);
|
||||
}
|
||||
|
||||
return box;
|
||||
abort();
|
||||
|
||||
error:
|
||||
if (box) {
|
||||
jp2_box_destroy(box);
|
||||
}
|
||||
if (tmpstream) {
|
||||
jas_stream_close(tmpstream);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jp2_box_dump(jp2_box_t *box, FILE *out)
|
||||
{
|
||||
jp2_boxinfo_t *boxinfo;
|
||||
boxinfo = jp2_boxinfolookup(box->type);
|
||||
assert(boxinfo);
|
||||
|
||||
fprintf(out, "JP2 box: ");
|
||||
fprintf(out, "type=%c%s%c (0x%08x); length=%d\n", '"', boxinfo->name,
|
||||
'"', (unsigned)box->type, (int)box->len);
|
||||
if (box->ops->dumpdata) {
|
||||
(*box->ops->dumpdata)(box, out);
|
||||
}
|
||||
}
|
||||
|
||||
static int jp2_jp_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_jp_t *jp = &box->data.jp;
|
||||
if (jp2_getuint32(in, &jp->magic)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_ftyp_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_ftyp_t *ftyp = &box->data.ftyp;
|
||||
unsigned int i;
|
||||
if (jp2_getuint32(in, &ftyp->majver) || jp2_getuint32(in, &ftyp->minver)) {
|
||||
return -1;
|
||||
}
|
||||
ftyp->numcompatcodes = (box->datalen - 8) / 4;
|
||||
if (ftyp->numcompatcodes > JP2_FTYP_MAXCOMPATCODES) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < ftyp->numcompatcodes; ++i) {
|
||||
if (jp2_getuint32(in, &ftyp->compatcodes[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_ihdr_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_ihdr_t *ihdr = &box->data.ihdr;
|
||||
if (jp2_getuint32(in, &ihdr->height) || jp2_getuint32(in, &ihdr->width) ||
|
||||
jp2_getuint16(in, &ihdr->numcmpts) || jp2_getuint8(in, &ihdr->bpc) ||
|
||||
jp2_getuint8(in, &ihdr->comptype) || jp2_getuint8(in, &ihdr->csunk) ||
|
||||
jp2_getuint8(in, &ihdr->ipr)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_bpcc_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_bpcc_t *bpcc = &box->data.bpcc;
|
||||
unsigned int i;
|
||||
bpcc->numcmpts = box->datalen;
|
||||
if (!(bpcc->bpcs = jas_alloc2(bpcc->numcmpts, sizeof(uint_fast8_t)))) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < bpcc->numcmpts; ++i) {
|
||||
if (jp2_getuint8(in, &bpcc->bpcs[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void jp2_colr_dumpdata(jp2_box_t *box, FILE *out)
|
||||
{
|
||||
jp2_colr_t *colr = &box->data.colr;
|
||||
fprintf(out, "method=%d; pri=%d; approx=%d\n", (int)colr->method, (int)colr->pri, (int)colr->approx);
|
||||
switch (colr->method) {
|
||||
case JP2_COLR_ENUM:
|
||||
fprintf(out, "csid=%d\n", (int)colr->csid);
|
||||
break;
|
||||
case JP2_COLR_ICC:
|
||||
jas_memdump(out, colr->iccp, colr->iccplen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int jp2_colr_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_colr_t *colr = &box->data.colr;
|
||||
colr->csid = 0;
|
||||
colr->iccp = 0;
|
||||
colr->iccplen = 0;
|
||||
|
||||
if (jp2_getuint8(in, &colr->method) || jp2_getuint8(in, &colr->pri) ||
|
||||
jp2_getuint8(in, &colr->approx)) {
|
||||
return -1;
|
||||
}
|
||||
switch (colr->method) {
|
||||
case JP2_COLR_ENUM:
|
||||
if (jp2_getuint32(in, &colr->csid)) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case JP2_COLR_ICC:
|
||||
colr->iccplen = box->datalen - 3;
|
||||
if (!(colr->iccp = jas_alloc2(colr->iccplen, sizeof(uint_fast8_t)))) {
|
||||
return -1;
|
||||
}
|
||||
if (jas_stream_read(in, colr->iccp, colr->iccplen) != colr->iccplen) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void jp2_cdef_dumpdata(jp2_box_t *box, FILE *out)
|
||||
{
|
||||
jp2_cdef_t *cdef = &box->data.cdef;
|
||||
unsigned int i;
|
||||
for (i = 0; i < cdef->numchans; ++i) {
|
||||
fprintf(out, "channo=%d; type=%d; assoc=%d\n",
|
||||
(int)cdef->ents[i].channo, (int)cdef->ents[i].type, (int)cdef->ents[i].assoc);
|
||||
}
|
||||
}
|
||||
|
||||
static void jp2_colr_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_colr_t *colr = &box->data.colr;
|
||||
if (colr->iccp) {
|
||||
jas_free(colr->iccp);
|
||||
}
|
||||
}
|
||||
|
||||
static int jp2_cdef_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_cdef_t *cdef = &box->data.cdef;
|
||||
jp2_cdefchan_t *chan;
|
||||
unsigned int channo;
|
||||
if (jp2_getuint16(in, &cdef->numchans)) {
|
||||
return -1;
|
||||
}
|
||||
if (!(cdef->ents = jas_alloc2(cdef->numchans, sizeof(jp2_cdefchan_t)))) {
|
||||
return -1;
|
||||
}
|
||||
for (channo = 0; channo < cdef->numchans; ++channo) {
|
||||
chan = &cdef->ents[channo];
|
||||
if (jp2_getuint16(in, &chan->channo) || jp2_getuint16(in, &chan->type) ||
|
||||
jp2_getuint16(in, &chan->assoc)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Box output.
|
||||
\******************************************************************************/
|
||||
|
||||
int jp2_box_put(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jas_stream_t *tmpstream;
|
||||
bool extlen;
|
||||
bool dataflag;
|
||||
|
||||
tmpstream = 0;
|
||||
|
||||
dataflag = !(box->info->flags & (JP2_BOX_SUPER | JP2_BOX_NODATA));
|
||||
|
||||
if (dataflag) {
|
||||
tmpstream = jas_stream_memopen(0, 0);
|
||||
if (box->ops->putdata) {
|
||||
if ((*box->ops->putdata)(box, tmpstream)) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
box->len = jas_stream_tell(tmpstream) + JP2_BOX_HDRLEN(false);
|
||||
jas_stream_rewind(tmpstream);
|
||||
}
|
||||
//extlen = (box->len >= (((uint_fast64_t)1) << 32)) != 0;
|
||||
if (jp2_putuint32(out, /*extlen ? 1 :*/ box->len)) {
|
||||
goto error;
|
||||
}
|
||||
if (jp2_putuint32(out, box->type)) {
|
||||
goto error;
|
||||
}
|
||||
/*if (extlen) {
|
||||
if (jp2_putuint64(out, box->len)) {
|
||||
goto error;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (dataflag) {
|
||||
if (jas_stream_copy(out, tmpstream, box->len - JP2_BOX_HDRLEN(false))) {
|
||||
goto error;
|
||||
}
|
||||
jas_stream_close(tmpstream);
|
||||
}
|
||||
|
||||
return 0;
|
||||
abort();
|
||||
|
||||
error:
|
||||
|
||||
if (tmpstream) {
|
||||
jas_stream_close(tmpstream);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int jp2_jp_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_jp_t *jp = &box->data.jp;
|
||||
if (jp2_putuint32(out, jp->magic)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_ftyp_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_ftyp_t *ftyp = &box->data.ftyp;
|
||||
unsigned int i;
|
||||
if (jp2_putuint32(out, ftyp->majver) || jp2_putuint32(out, ftyp->minver)) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < ftyp->numcompatcodes; ++i) {
|
||||
if (jp2_putuint32(out, ftyp->compatcodes[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_ihdr_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_ihdr_t *ihdr = &box->data.ihdr;
|
||||
if (jp2_putuint32(out, ihdr->height) || jp2_putuint32(out, ihdr->width) ||
|
||||
jp2_putuint16(out, ihdr->numcmpts) || jp2_putuint8(out, ihdr->bpc) ||
|
||||
jp2_putuint8(out, ihdr->comptype) || jp2_putuint8(out, ihdr->csunk) ||
|
||||
jp2_putuint8(out, ihdr->ipr)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_bpcc_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_bpcc_t *bpcc = &box->data.bpcc;
|
||||
unsigned int i;
|
||||
for (i = 0; i < bpcc->numcmpts; ++i) {
|
||||
if (jp2_putuint8(out, bpcc->bpcs[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_colr_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_colr_t *colr = &box->data.colr;
|
||||
if (jp2_putuint8(out, colr->method) || jp2_putuint8(out, colr->pri) ||
|
||||
jp2_putuint8(out, colr->approx)) {
|
||||
return -1;
|
||||
}
|
||||
switch (colr->method) {
|
||||
case JP2_COLR_ENUM:
|
||||
if (jp2_putuint32(out, colr->csid)) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case JP2_COLR_ICC:
|
||||
if (jas_stream_write(out, colr->iccp,
|
||||
JAS_CAST(int, colr->iccplen)) != JAS_CAST(int, colr->iccplen))
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_cdef_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_cdef_t *cdef = &box->data.cdef;
|
||||
unsigned int i;
|
||||
jp2_cdefchan_t *ent;
|
||||
|
||||
if (jp2_putuint16(out, cdef->numchans)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < cdef->numchans; ++i) {
|
||||
ent = &cdef->ents[i];
|
||||
if (jp2_putuint16(out, ent->channo) ||
|
||||
jp2_putuint16(out, ent->type) ||
|
||||
jp2_putuint16(out, ent->assoc)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Input operations for primitive types.
|
||||
\******************************************************************************/
|
||||
|
||||
static int jp2_getuint8(jas_stream_t *in, uint_fast8_t *val)
|
||||
{
|
||||
int c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
if (val) {
|
||||
*val = c;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_getuint16(jas_stream_t *in, uint_fast16_t *val)
|
||||
{
|
||||
uint_fast16_t v;
|
||||
int c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 8) | c;
|
||||
if (val) {
|
||||
*val = v;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_getuint32(jas_stream_t *in, uint_fast32_t *val)
|
||||
{
|
||||
uint_fast32_t v;
|
||||
int c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 8) | c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 8) | c;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 8) | c;
|
||||
if (val) {
|
||||
*val = v;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_getuint64(jas_stream_t *in, uint_fast64_t *val)
|
||||
{
|
||||
uint_fast64_t tmpval;
|
||||
int i;
|
||||
int c;
|
||||
|
||||
tmpval = 0;
|
||||
for (i = 0; i < 8; ++i) {
|
||||
tmpval <<= 8;
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
tmpval |= (c & 0xff);
|
||||
}
|
||||
*val = tmpval;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Output operations for primitive types.
|
||||
\******************************************************************************/
|
||||
|
||||
static int jp2_putuint8(jas_stream_t *out, uint_fast8_t val)
|
||||
{
|
||||
if (jas_stream_putc(out, val & 0xff) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_putuint16(jas_stream_t *out, uint_fast16_t val)
|
||||
{
|
||||
if (jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
|
||||
jas_stream_putc(out, val & 0xff) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_putuint32(jas_stream_t *out, uint_fast32_t val)
|
||||
{
|
||||
if (jas_stream_putc(out, (val >> 24) & 0xff) == EOF ||
|
||||
jas_stream_putc(out, (val >> 16) & 0xff) == EOF ||
|
||||
jas_stream_putc(out, (val >> 8) & 0xff) == EOF ||
|
||||
jas_stream_putc(out, val & 0xff) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_putuint64(jas_stream_t *out, uint_fast64_t val)
|
||||
{
|
||||
if (jp2_putuint32(out, (val >> 32) & 0xffffffffUL) ||
|
||||
jp2_putuint32(out, val & 0xffffffffUL)) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous code.
|
||||
\******************************************************************************/
|
||||
|
||||
jp2_boxinfo_t *jp2_boxinfolookup(int type)
|
||||
{
|
||||
jp2_boxinfo_t *boxinfo;
|
||||
for (boxinfo = jp2_boxinfos; boxinfo->name; ++boxinfo) {
|
||||
if (boxinfo->type == type) {
|
||||
return boxinfo;
|
||||
}
|
||||
}
|
||||
return &jp2_boxinfo_unk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void jp2_cmap_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_cmap_t *cmap = &box->data.cmap;
|
||||
if (cmap->ents) {
|
||||
jas_free(cmap->ents);
|
||||
}
|
||||
}
|
||||
|
||||
static int jp2_cmap_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_cmap_t *cmap = &box->data.cmap;
|
||||
jp2_cmapent_t *ent;
|
||||
unsigned int i;
|
||||
|
||||
cmap->numchans = (box->datalen) / 4;
|
||||
if (!(cmap->ents = jas_alloc2(cmap->numchans, sizeof(jp2_cmapent_t)))) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < cmap->numchans; ++i) {
|
||||
ent = &cmap->ents[i];
|
||||
if (jp2_getuint16(in, &ent->cmptno) ||
|
||||
jp2_getuint8(in, &ent->map) ||
|
||||
jp2_getuint8(in, &ent->pcol)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_cmap_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
/* Eliminate compiler warning about unused variables. */
|
||||
box = 0;
|
||||
out = 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void jp2_cmap_dumpdata(jp2_box_t *box, FILE *out)
|
||||
{
|
||||
jp2_cmap_t *cmap = &box->data.cmap;
|
||||
unsigned int i;
|
||||
jp2_cmapent_t *ent;
|
||||
fprintf(out, "numchans = %d\n", (int) cmap->numchans);
|
||||
for (i = 0; i < cmap->numchans; ++i) {
|
||||
ent = &cmap->ents[i];
|
||||
fprintf(out, "cmptno=%d; map=%d; pcol=%d\n",
|
||||
(int) ent->cmptno, (int) ent->map, (int) ent->pcol);
|
||||
}
|
||||
}
|
||||
|
||||
static void jp2_pclr_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_pclr_t *pclr = &box->data.pclr;
|
||||
if (pclr->lutdata) {
|
||||
jas_free(pclr->lutdata);
|
||||
}
|
||||
if (pclr->bpc)
|
||||
jas_free(pclr->bpc);
|
||||
}
|
||||
|
||||
static int jp2_pclr_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_pclr_t *pclr = &box->data.pclr;
|
||||
int lutsize;
|
||||
unsigned int i;
|
||||
unsigned int j;
|
||||
int_fast32_t x;
|
||||
|
||||
pclr->lutdata = 0;
|
||||
|
||||
if (jp2_getuint16(in, &pclr->numlutents) ||
|
||||
jp2_getuint8(in, &pclr->numchans)) {
|
||||
return -1;
|
||||
}
|
||||
lutsize = pclr->numlutents * pclr->numchans;
|
||||
if (!(pclr->lutdata = jas_alloc2(lutsize, sizeof(int_fast32_t)))) {
|
||||
return -1;
|
||||
}
|
||||
if (!(pclr->bpc = jas_alloc2(pclr->numchans, sizeof(uint_fast8_t)))) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < pclr->numchans; ++i) {
|
||||
if (jp2_getuint8(in, &pclr->bpc[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < pclr->numlutents; ++i) {
|
||||
for (j = 0; j < pclr->numchans; ++j) {
|
||||
if (jp2_getint(in, (pclr->bpc[j] & 0x80) != 0,
|
||||
(pclr->bpc[j] & 0x7f) + 1, &x)) {
|
||||
return -1;
|
||||
}
|
||||
pclr->lutdata[i * pclr->numchans + j] = x;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_pclr_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
#if 0
|
||||
jp2_pclr_t *pclr = &box->data.pclr;
|
||||
#endif
|
||||
/* Eliminate warning about unused variable. */
|
||||
box = 0;
|
||||
out = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void jp2_pclr_dumpdata(jp2_box_t *box, FILE *out)
|
||||
{
|
||||
jp2_pclr_t *pclr = &box->data.pclr;
|
||||
unsigned int i;
|
||||
int j;
|
||||
fprintf(out, "numents=%d; numchans=%d\n", (int) pclr->numlutents,
|
||||
(int) pclr->numchans);
|
||||
for (i = 0; i < pclr->numlutents; ++i) {
|
||||
for (j = 0; j < pclr->numchans; ++j) {
|
||||
fprintf(out, "LUT[%d][%d]=%d\n", i, j, (int)pclr->lutdata[i * pclr->numchans + j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void jp2_uuid_destroy(jp2_box_t *box)
|
||||
{
|
||||
jp2_uuid_t *uuid = &box->data.uuid;
|
||||
if (uuid->data)
|
||||
{
|
||||
jas_free(uuid->data);
|
||||
uuid->data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int jp2_uuid_getdata(jp2_box_t *box, jas_stream_t *in)
|
||||
{
|
||||
jp2_uuid_t *uuid = &box->data.uuid;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (jp2_getuint8(in, &uuid->uuid[i]))
|
||||
return -1;
|
||||
}
|
||||
|
||||
uuid->datalen = box->datalen - 16;
|
||||
uuid->data = jas_malloc(uuid->datalen * sizeof(uint_fast8_t));
|
||||
for (i = 0; i < uuid->datalen; i++)
|
||||
{
|
||||
if (jp2_getuint8(in, &uuid->data[i]))
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_uuid_putdata(jp2_box_t *box, jas_stream_t *out)
|
||||
{
|
||||
jp2_uuid_t *uuid = &box->data.uuid;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
if (jp2_putuint8(out, uuid->uuid[i]))
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < uuid->datalen; i++)
|
||||
{
|
||||
if (jp2_putuint8(out, uuid->data[i]))
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jp2_getint(jas_stream_t *in, int s, int n, int_fast32_t *val)
|
||||
{
|
||||
int c;
|
||||
int i;
|
||||
uint_fast32_t v;
|
||||
int m;
|
||||
|
||||
m = (n + 7) / 8;
|
||||
|
||||
v = 0;
|
||||
for (i = 0; i < m; ++i) {
|
||||
if ((c = jas_stream_getc(in)) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 8) | c;
|
||||
}
|
||||
v &= ONES(n);
|
||||
if (s) {
|
||||
int sb;
|
||||
sb = v & (1 << (8 * m - 1));
|
||||
*val = ((~v) + 1) & ONES(8 * m);
|
||||
if (sb) {
|
||||
*val = -*val;
|
||||
}
|
||||
} else {
|
||||
*val = v;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo)
|
||||
{
|
||||
unsigned int i;
|
||||
jp2_cdefchan_t *cdefent;
|
||||
for (i = 0; i < cdef->numchans; ++i) {
|
||||
cdefent = &cdef->ents[i];
|
||||
if (cdefent->channo == JAS_CAST(unsigned int, channo)) {
|
||||
return cdefent;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Vendored
+316
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by Andrey Kiselev <dron@remotesensing.org> to handle UUID
|
||||
* box properly.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JP2 Library
|
||||
*
|
||||
* $Id: jp2_cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JP2_COD_H
|
||||
#define JP2_COD_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JP2_SPTOBPC(s, p) \
|
||||
((((p) - 1) & 0x7f) | (((s) & 1) << 7))
|
||||
|
||||
/******************************************************************************\
|
||||
* Box class.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JP2_BOX_HDRLEN(ext) ((ext) ? 16 : 8)
|
||||
|
||||
/* Box types. */
|
||||
#define JP2_BOX_JP 0x6a502020 /* Signature */
|
||||
#define JP2_BOX_FTYP 0x66747970 /* File Type */
|
||||
#define JP2_BOX_JP2H 0x6a703268 /* JP2 Header */
|
||||
#define JP2_BOX_IHDR 0x69686472 /* Image Header */
|
||||
#define JP2_BOX_BPCC 0x62706363 /* Bits Per Component */
|
||||
#define JP2_BOX_COLR 0x636f6c72 /* Color Specification */
|
||||
#define JP2_BOX_PCLR 0x70636c72 /* Palette */
|
||||
#define JP2_BOX_CMAP 0x636d6170 /* Component Mapping */
|
||||
#define JP2_BOX_CDEF 0x63646566 /* Channel Definition */
|
||||
#define JP2_BOX_RES 0x72657320 /* Resolution */
|
||||
#define JP2_BOX_RESC 0x72657363 /* Capture Resolution */
|
||||
#define JP2_BOX_RESD 0x72657364 /* Default Display Resolution */
|
||||
#define JP2_BOX_JP2C 0x6a703263 /* Contiguous Code Stream */
|
||||
#define JP2_BOX_JP2I 0x6a703269 /* Intellectual Property */
|
||||
#define JP2_BOX_XML 0x786d6c20 /* XML */
|
||||
#define JP2_BOX_UUID 0x75756964 /* UUID */
|
||||
#define JP2_BOX_UINF 0x75696e66 /* UUID Info */
|
||||
#define JP2_BOX_ULST 0x75637374 /* UUID List */
|
||||
#define JP2_BOX_URL 0x75726c20 /* URL */
|
||||
|
||||
#define JP2_BOX_SUPER 0x01
|
||||
#define JP2_BOX_NODATA 0x02
|
||||
|
||||
/* JP box data. */
|
||||
|
||||
#define JP2_JP_MAGIC 0x0d0a870a
|
||||
#define JP2_JP_LEN 12
|
||||
|
||||
typedef struct {
|
||||
uint_fast32_t magic;
|
||||
} jp2_jp_t;
|
||||
|
||||
/* FTYP box data. */
|
||||
|
||||
#define JP2_FTYP_MAXCOMPATCODES 32
|
||||
#define JP2_FTYP_MAJVER 0x6a703220
|
||||
#define JP2_FTYP_MINVER 0
|
||||
#define JP2_FTYP_COMPATCODE JP2_FTYP_MAJVER
|
||||
|
||||
typedef struct {
|
||||
uint_fast32_t majver;
|
||||
uint_fast32_t minver;
|
||||
uint_fast32_t numcompatcodes;
|
||||
uint_fast32_t compatcodes[JP2_FTYP_MAXCOMPATCODES];
|
||||
} jp2_ftyp_t;
|
||||
|
||||
/* IHDR box data. */
|
||||
|
||||
#define JP2_IHDR_COMPTYPE 7
|
||||
#define JP2_IHDR_BPCNULL 255
|
||||
|
||||
typedef struct {
|
||||
uint_fast32_t width;
|
||||
uint_fast32_t height;
|
||||
uint_fast16_t numcmpts;
|
||||
uint_fast8_t bpc;
|
||||
uint_fast8_t comptype;
|
||||
uint_fast8_t csunk;
|
||||
uint_fast8_t ipr;
|
||||
} jp2_ihdr_t;
|
||||
|
||||
/* BPCC box data. */
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t numcmpts;
|
||||
uint_fast8_t *bpcs;
|
||||
} jp2_bpcc_t;
|
||||
|
||||
/* COLR box data. */
|
||||
|
||||
#define JP2_COLR_ENUM 1
|
||||
#define JP2_COLR_ICC 2
|
||||
#define JP2_COLR_PRI 0
|
||||
|
||||
#define JP2_COLR_SRGB 16
|
||||
#define JP2_COLR_SGRAY 17
|
||||
#define JP2_COLR_SYCC 18
|
||||
|
||||
typedef struct {
|
||||
uint_fast8_t method;
|
||||
uint_fast8_t pri;
|
||||
uint_fast8_t approx;
|
||||
uint_fast32_t csid;
|
||||
uint_fast8_t *iccp;
|
||||
int iccplen;
|
||||
/* XXX - Someday we ought to add ICC profile data here. */
|
||||
} jp2_colr_t;
|
||||
|
||||
/* PCLR box data. */
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t numlutents;
|
||||
uint_fast8_t numchans;
|
||||
int_fast32_t *lutdata;
|
||||
uint_fast8_t *bpc;
|
||||
} jp2_pclr_t;
|
||||
|
||||
/* CDEF box per-channel data. */
|
||||
|
||||
#define JP2_CDEF_RGB_R 1
|
||||
#define JP2_CDEF_RGB_G 2
|
||||
#define JP2_CDEF_RGB_B 3
|
||||
|
||||
#define JP2_CDEF_YCBCR_Y 1
|
||||
#define JP2_CDEF_YCBCR_CB 2
|
||||
#define JP2_CDEF_YCBCR_CR 3
|
||||
|
||||
#define JP2_CDEF_GRAY_Y 1
|
||||
|
||||
#define JP2_CDEF_TYPE_COLOR 0
|
||||
#define JP2_CDEF_TYPE_OPACITY 1
|
||||
#define JP2_CDEF_TYPE_UNSPEC 65535
|
||||
#define JP2_CDEF_ASOC_ALL 0
|
||||
#define JP2_CDEF_ASOC_NONE 65535
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t channo;
|
||||
uint_fast16_t type;
|
||||
uint_fast16_t assoc;
|
||||
} jp2_cdefchan_t;
|
||||
|
||||
/* CDEF box data. */
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t numchans;
|
||||
jp2_cdefchan_t *ents;
|
||||
} jp2_cdef_t;
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t cmptno;
|
||||
uint_fast8_t map;
|
||||
uint_fast8_t pcol;
|
||||
} jp2_cmapent_t;
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t numchans;
|
||||
jp2_cmapent_t *ents;
|
||||
} jp2_cmap_t;
|
||||
|
||||
typedef struct {
|
||||
uint_fast32_t datalen;
|
||||
uint_fast8_t uuid[16];
|
||||
uint_fast8_t *data;
|
||||
} jp2_uuid_t;
|
||||
|
||||
#define JP2_CMAP_DIRECT 0
|
||||
#define JP2_CMAP_PALETTE 1
|
||||
|
||||
/* Generic box. */
|
||||
|
||||
struct jp2_boxops_s;
|
||||
typedef struct {
|
||||
|
||||
struct jp2_boxops_s *ops;
|
||||
struct jp2_boxinfo_s *info;
|
||||
|
||||
uint_fast32_t type;
|
||||
|
||||
/* The length of the box including the (variable-length) header. */
|
||||
uint_fast32_t len;
|
||||
|
||||
/* The length of the box data. */
|
||||
uint_fast32_t datalen;
|
||||
|
||||
union {
|
||||
jp2_jp_t jp;
|
||||
jp2_ftyp_t ftyp;
|
||||
jp2_ihdr_t ihdr;
|
||||
jp2_bpcc_t bpcc;
|
||||
jp2_colr_t colr;
|
||||
jp2_pclr_t pclr;
|
||||
jp2_cdef_t cdef;
|
||||
jp2_cmap_t cmap;
|
||||
jp2_uuid_t uuid;
|
||||
} data;
|
||||
|
||||
} jp2_box_t;
|
||||
|
||||
typedef struct jp2_boxops_s {
|
||||
void (*init)(jp2_box_t *box);
|
||||
void (*destroy)(jp2_box_t *box);
|
||||
int (*getdata)(jp2_box_t *box, jas_stream_t *in);
|
||||
int (*putdata)(jp2_box_t *box, jas_stream_t *out);
|
||||
void (*dumpdata)(jp2_box_t *box, FILE *out);
|
||||
} jp2_boxops_t;
|
||||
|
||||
/******************************************************************************\
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
typedef struct jp2_boxinfo_s {
|
||||
int type;
|
||||
char *name;
|
||||
int flags;
|
||||
jp2_boxops_t ops;
|
||||
} jp2_boxinfo_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Box class.
|
||||
\******************************************************************************/
|
||||
|
||||
jp2_box_t *jp2_box_create(int type);
|
||||
void jp2_box_destroy(jp2_box_t *box);
|
||||
jp2_box_t *jp2_box_get(jas_stream_t *in);
|
||||
int jp2_box_put(jp2_box_t *box, jas_stream_t *out);
|
||||
|
||||
#define JP2_DTYPETOBPC(dtype) \
|
||||
((JAS_IMAGE_CDT_GETSGND(dtype) << 7) | (JAS_IMAGE_CDT_GETPREC(dtype) - 1))
|
||||
#define JP2_BPCTODTYPE(bpc) \
|
||||
(JAS_IMAGE_CDT_SETSGND(bpc >> 7) | JAS_IMAGE_CDT_SETPREC((bpc & 0x7f) + 1))
|
||||
|
||||
#define ICC_CS_RGB 0x52474220
|
||||
#define ICC_CS_YCBCR 0x59436272
|
||||
#define ICC_CS_GRAY 0x47524159
|
||||
|
||||
jp2_cdefchan_t *jp2_cdef_lookup(jp2_cdef_t *cdef, int channo);
|
||||
|
||||
|
||||
#endif
|
||||
Vendored
+603
@@ -0,0 +1,603 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JP2 Library
|
||||
*
|
||||
* $Id: jp2_dec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_image.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_version.h"
|
||||
|
||||
#include "jp2_cod.h"
|
||||
#include "jp2_dec.h"
|
||||
|
||||
#define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK))
|
||||
|
||||
static jp2_dec_t *jp2_dec_create(void);
|
||||
static void jp2_dec_destroy(jp2_dec_t *dec);
|
||||
static int jp2_getcs(jp2_colr_t *colr);
|
||||
static int fromiccpcs(int cs);
|
||||
static int jp2_getct(int colorspace, int type, int assoc);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
jas_image_t *jp2_decode(jas_stream_t *in, char *optstr)
|
||||
{
|
||||
jp2_box_t *box;
|
||||
int found;
|
||||
jas_image_t *image;
|
||||
jp2_dec_t *dec;
|
||||
bool samedtype;
|
||||
int dtype;
|
||||
unsigned int i;
|
||||
jp2_cmap_t *cmapd;
|
||||
jp2_pclr_t *pclrd;
|
||||
jp2_cdef_t *cdefd;
|
||||
unsigned int channo;
|
||||
int newcmptno;
|
||||
int_fast32_t *lutents;
|
||||
#if 0
|
||||
jp2_cdefchan_t *cdefent;
|
||||
int cmptno;
|
||||
#endif
|
||||
jp2_cmapent_t *cmapent;
|
||||
jas_icchdr_t icchdr;
|
||||
jas_iccprof_t *iccprof;
|
||||
|
||||
dec = 0;
|
||||
box = 0;
|
||||
image = 0;
|
||||
|
||||
if (!(dec = jp2_dec_create())) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Get the first box. This should be a JP box. */
|
||||
if (!(box = jp2_box_get(in))) {
|
||||
jas_eprintf("error: cannot get box\n");
|
||||
goto error;
|
||||
}
|
||||
if (box->type != JP2_BOX_JP) {
|
||||
jas_eprintf("error: expecting signature box\n");
|
||||
goto error;
|
||||
}
|
||||
if (box->data.jp.magic != JP2_JP_MAGIC) {
|
||||
jas_eprintf("incorrect magic number\n");
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/* Get the second box. This should be a FTYP box. */
|
||||
if (!(box = jp2_box_get(in))) {
|
||||
goto error;
|
||||
}
|
||||
if (box->type != JP2_BOX_FTYP) {
|
||||
jas_eprintf("expecting file type box\n");
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/* Get more boxes... */
|
||||
found = 0;
|
||||
while ((box = jp2_box_get(in))) {
|
||||
if (jas_getdbglevel() >= 1) {
|
||||
jas_eprintf("box type %s\n", box->info->name);
|
||||
}
|
||||
switch (box->type) {
|
||||
case JP2_BOX_JP2C:
|
||||
found = 1;
|
||||
break;
|
||||
case JP2_BOX_IHDR:
|
||||
if (!dec->ihdr) {
|
||||
dec->ihdr = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
case JP2_BOX_BPCC:
|
||||
if (!dec->bpcc) {
|
||||
dec->bpcc = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
case JP2_BOX_CDEF:
|
||||
if (!dec->cdef) {
|
||||
dec->cdef = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
case JP2_BOX_PCLR:
|
||||
if (!dec->pclr) {
|
||||
dec->pclr = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
case JP2_BOX_CMAP:
|
||||
if (!dec->cmap) {
|
||||
dec->cmap = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
case JP2_BOX_COLR:
|
||||
if (!dec->colr) {
|
||||
dec->colr = box;
|
||||
box = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (box) {
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
jas_eprintf("error: no code stream found\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(dec->image = jpc_decode(in, optstr))) {
|
||||
jas_eprintf("error: cannot decode code stream\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* An IHDR box must be present. */
|
||||
if (!dec->ihdr) {
|
||||
jas_eprintf("error: missing IHDR box\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Does the number of components indicated in the IHDR box match
|
||||
the value specified in the code stream? */
|
||||
if (dec->ihdr->data.ihdr.numcmpts != JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
|
||||
jas_eprintf("warning: number of components mismatch\n");
|
||||
}
|
||||
|
||||
/* At least one component must be present. */
|
||||
if (!jas_image_numcmpts(dec->image)) {
|
||||
jas_eprintf("error: no components\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Determine if all components have the same data type. */
|
||||
samedtype = true;
|
||||
dtype = jas_image_cmptdtype(dec->image, 0);
|
||||
for (i = 1; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
|
||||
if (jas_image_cmptdtype(dec->image, i) != dtype) {
|
||||
samedtype = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Is the component data type indicated in the IHDR box consistent
|
||||
with the data in the code stream? */
|
||||
if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) ||
|
||||
(!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) {
|
||||
jas_eprintf("warning: component data type mismatch\n");
|
||||
}
|
||||
|
||||
/* Is the compression type supported? */
|
||||
if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) {
|
||||
jas_eprintf("error: unsupported compression type\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (dec->bpcc) {
|
||||
/* Is the number of components indicated in the BPCC box
|
||||
consistent with the code stream data? */
|
||||
if (dec->bpcc->data.bpcc.numcmpts != JAS_CAST(uint, jas_image_numcmpts(
|
||||
dec->image))) {
|
||||
jas_eprintf("warning: number of components mismatch\n");
|
||||
}
|
||||
/* Is the component data type information indicated in the BPCC
|
||||
box consistent with the code stream data? */
|
||||
if (!samedtype) {
|
||||
for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
|
||||
if (jas_image_cmptdtype(dec->image, i) != JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) {
|
||||
jas_eprintf("warning: component data type mismatch\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
jas_eprintf("warning: superfluous BPCC box\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* A COLR box must be present. */
|
||||
if (!dec->colr) {
|
||||
jas_eprintf("error: no COLR box\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (dec->colr->data.colr.method) {
|
||||
case JP2_COLR_ENUM:
|
||||
jas_image_setclrspc(dec->image, jp2_getcs(&dec->colr->data.colr));
|
||||
break;
|
||||
case JP2_COLR_ICC:
|
||||
iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp,
|
||||
dec->colr->data.colr.iccplen);
|
||||
assert(iccprof);
|
||||
jas_iccprof_gethdr(iccprof, &icchdr);
|
||||
jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc);
|
||||
jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc));
|
||||
dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof);
|
||||
assert(dec->image->cmprof_);
|
||||
jas_iccprof_destroy(iccprof);
|
||||
break;
|
||||
}
|
||||
|
||||
/* If a CMAP box is present, a PCLR box must also be present. */
|
||||
if (dec->cmap && !dec->pclr) {
|
||||
jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n");
|
||||
jp2_box_destroy(dec->cmap);
|
||||
dec->cmap = 0;
|
||||
}
|
||||
|
||||
/* If a CMAP box is not present, a PCLR box must not be present. */
|
||||
if (!dec->cmap && dec->pclr) {
|
||||
jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n");
|
||||
jp2_box_destroy(dec->pclr);
|
||||
dec->pclr = 0;
|
||||
}
|
||||
|
||||
/* Determine the number of channels (which is essentially the number
|
||||
of components after any palette mappings have been applied). */
|
||||
dec->numchans = dec->cmap ? dec->cmap->data.cmap.numchans : JAS_CAST(uint, jas_image_numcmpts(dec->image));
|
||||
|
||||
/* Perform a basic sanity check on the CMAP box if present. */
|
||||
if (dec->cmap) {
|
||||
for (i = 0; i < dec->numchans; ++i) {
|
||||
/* Is the component number reasonable? */
|
||||
if (dec->cmap->data.cmap.ents[i].cmptno >= JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
|
||||
jas_eprintf("error: invalid component number in CMAP box\n");
|
||||
goto error;
|
||||
}
|
||||
/* Is the LUT index reasonable? */
|
||||
if (dec->cmap->data.cmap.ents[i].pcol >= dec->pclr->data.pclr.numchans) {
|
||||
jas_eprintf("error: invalid CMAP LUT index\n");
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Allocate space for the channel-number to component-number LUT. */
|
||||
if (!(dec->chantocmptlut = jas_alloc2(dec->numchans, sizeof(uint_fast16_t)))) {
|
||||
jas_eprintf("error: no memory\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!dec->cmap) {
|
||||
for (i = 0; i < dec->numchans; ++i) {
|
||||
dec->chantocmptlut[i] = i;
|
||||
}
|
||||
} else {
|
||||
cmapd = &dec->cmap->data.cmap;
|
||||
pclrd = &dec->pclr->data.pclr;
|
||||
cdefd = &dec->cdef->data.cdef;
|
||||
for (channo = 0; channo < cmapd->numchans; ++channo) {
|
||||
cmapent = &cmapd->ents[channo];
|
||||
if (cmapent->map == JP2_CMAP_DIRECT) {
|
||||
dec->chantocmptlut[channo] = channo;
|
||||
} else if (cmapent->map == JP2_CMAP_PALETTE) {
|
||||
lutents = jas_alloc2(pclrd->numlutents, sizeof(int_fast32_t));
|
||||
for (i = 0; i < pclrd->numlutents; ++i) {
|
||||
lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans];
|
||||
}
|
||||
newcmptno = jas_image_numcmpts(dec->image);
|
||||
jas_image_depalettize(dec->image, cmapent->cmptno, pclrd->numlutents, lutents, JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno);
|
||||
dec->chantocmptlut[channo] = newcmptno;
|
||||
jas_free(lutents);
|
||||
#if 0
|
||||
if (dec->cdef) {
|
||||
cdefent = jp2_cdef_lookup(cdefd, channo);
|
||||
if (!cdefent) {
|
||||
abort();
|
||||
}
|
||||
jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), cdefent->type, cdefent->assoc));
|
||||
} else {
|
||||
jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), 0, channo + 1));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Mark all components as being of unknown type. */
|
||||
|
||||
for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
|
||||
jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN);
|
||||
}
|
||||
|
||||
/* Determine the type of each component. */
|
||||
if (dec->cdef) {
|
||||
for (i = 0; i < dec->numchans; ++i) {
|
||||
jas_image_setcmpttype(dec->image,
|
||||
dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo],
|
||||
jp2_getct(jas_image_clrspc(dec->image),
|
||||
dec->cdef->data.cdef.ents[i].type, dec->cdef->data.cdef.ents[i].assoc));
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < dec->numchans; ++i) {
|
||||
jas_image_setcmpttype(dec->image, dec->chantocmptlut[i],
|
||||
jp2_getct(jas_image_clrspc(dec->image), 0, i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete any components that are not of interest. */
|
||||
for (i = jas_image_numcmpts(dec->image); i > 0; --i) {
|
||||
if (jas_image_cmpttype(dec->image, i - 1) == JAS_IMAGE_CT_UNKNOWN) {
|
||||
jas_image_delcmpt(dec->image, i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure that some components survived. */
|
||||
if (!jas_image_numcmpts(dec->image)) {
|
||||
jas_eprintf("error: no components\n");
|
||||
goto error;
|
||||
}
|
||||
#if 0
|
||||
jas_eprintf("no of components is %d\n", jas_image_numcmpts(dec->image));
|
||||
#endif
|
||||
|
||||
/* Prevent the image from being destroyed later. */
|
||||
image = dec->image;
|
||||
dec->image = 0;
|
||||
|
||||
jp2_dec_destroy(dec);
|
||||
|
||||
return image;
|
||||
|
||||
error:
|
||||
if (box) {
|
||||
jp2_box_destroy(box);
|
||||
}
|
||||
if (dec) {
|
||||
jp2_dec_destroy(dec);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jp2_validate(jas_stream_t *in)
|
||||
{
|
||||
char buf[JP2_VALIDATELEN];
|
||||
int i;
|
||||
int n;
|
||||
#if 0
|
||||
jas_stream_t *tmpstream;
|
||||
jp2_box_t *box;
|
||||
#endif
|
||||
|
||||
assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN);
|
||||
|
||||
/* Read the validation data (i.e., the data used for detecting
|
||||
the format). */
|
||||
if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Put the validation data back onto the stream, so that the
|
||||
stream position will not be changed. */
|
||||
for (i = n - 1; i >= 0; --i) {
|
||||
if (jas_stream_ungetc(in, buf[i]) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Did we read enough data? */
|
||||
if (n < JP2_VALIDATELEN) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Is the box type correct? */
|
||||
if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) !=
|
||||
JP2_BOX_JP)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static jp2_dec_t *jp2_dec_create(void)
|
||||
{
|
||||
jp2_dec_t *dec;
|
||||
|
||||
if (!(dec = jas_malloc(sizeof(jp2_dec_t)))) {
|
||||
return 0;
|
||||
}
|
||||
dec->ihdr = 0;
|
||||
dec->bpcc = 0;
|
||||
dec->cdef = 0;
|
||||
dec->pclr = 0;
|
||||
dec->image = 0;
|
||||
dec->chantocmptlut = 0;
|
||||
dec->cmap = 0;
|
||||
dec->colr = 0;
|
||||
return dec;
|
||||
}
|
||||
|
||||
static void jp2_dec_destroy(jp2_dec_t *dec)
|
||||
{
|
||||
if (dec->ihdr) {
|
||||
jp2_box_destroy(dec->ihdr);
|
||||
}
|
||||
if (dec->bpcc) {
|
||||
jp2_box_destroy(dec->bpcc);
|
||||
}
|
||||
if (dec->cdef) {
|
||||
jp2_box_destroy(dec->cdef);
|
||||
}
|
||||
if (dec->pclr) {
|
||||
jp2_box_destroy(dec->pclr);
|
||||
}
|
||||
if (dec->image) {
|
||||
jas_image_destroy(dec->image);
|
||||
}
|
||||
if (dec->cmap) {
|
||||
jp2_box_destroy(dec->cmap);
|
||||
}
|
||||
if (dec->colr) {
|
||||
jp2_box_destroy(dec->colr);
|
||||
}
|
||||
if (dec->chantocmptlut) {
|
||||
jas_free(dec->chantocmptlut);
|
||||
}
|
||||
jas_free(dec);
|
||||
}
|
||||
|
||||
static int jp2_getct(int colorspace, int type, int assoc)
|
||||
{
|
||||
if (type == 1 && assoc == 0) {
|
||||
return JAS_IMAGE_CT_OPACITY;
|
||||
}
|
||||
if (type == 0 && assoc >= 1 && assoc <= 65534) {
|
||||
switch (colorspace) {
|
||||
case JAS_CLRSPC_FAM_RGB:
|
||||
switch (assoc) {
|
||||
case JP2_CDEF_RGB_R:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R);
|
||||
break;
|
||||
case JP2_CDEF_RGB_G:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G);
|
||||
break;
|
||||
case JP2_CDEF_RGB_B:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_YCBCR:
|
||||
switch (assoc) {
|
||||
case JP2_CDEF_YCBCR_Y:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y);
|
||||
break;
|
||||
case JP2_CDEF_YCBCR_CB:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB);
|
||||
break;
|
||||
case JP2_CDEF_YCBCR_CR:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_GRAY:
|
||||
switch (assoc) {
|
||||
case JP2_CDEF_GRAY_Y:
|
||||
return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return JAS_IMAGE_CT_COLOR(assoc - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return JAS_IMAGE_CT_UNKNOWN;
|
||||
}
|
||||
|
||||
static int jp2_getcs(jp2_colr_t *colr)
|
||||
{
|
||||
if (colr->method == JP2_COLR_ENUM) {
|
||||
switch (colr->csid) {
|
||||
case JP2_COLR_SRGB:
|
||||
return JAS_CLRSPC_SRGB;
|
||||
break;
|
||||
case JP2_COLR_SYCC:
|
||||
return JAS_CLRSPC_SYCBCR;
|
||||
break;
|
||||
case JP2_COLR_SGRAY:
|
||||
return JAS_CLRSPC_SGRAY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return JAS_CLRSPC_UNKNOWN;
|
||||
}
|
||||
|
||||
static int fromiccpcs(int cs)
|
||||
{
|
||||
switch (cs) {
|
||||
case ICC_CS_RGB:
|
||||
return JAS_CLRSPC_GENRGB;
|
||||
break;
|
||||
case ICC_CS_YCBCR:
|
||||
return JAS_CLRSPC_GENYCBCR;
|
||||
break;
|
||||
case ICC_CS_GRAY:
|
||||
return JAS_CLRSPC_GENGRAY;
|
||||
break;
|
||||
}
|
||||
return JAS_CLRSPC_UNKNOWN;
|
||||
}
|
||||
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JP2_DEC_H
|
||||
#define JP2_DEC_H
|
||||
|
||||
#include "jasper/jas_image.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jp2_cod.h"
|
||||
|
||||
typedef struct {
|
||||
|
||||
jp2_box_t *pclr;
|
||||
jp2_box_t *cdef;
|
||||
jp2_box_t *ihdr;
|
||||
jp2_box_t *bpcc;
|
||||
jp2_box_t *cmap;
|
||||
jp2_box_t *colr;
|
||||
jas_image_t *image;
|
||||
uint_fast16_t numchans;
|
||||
uint_fast16_t *chantocmptlut;
|
||||
|
||||
} jp2_dec_t;
|
||||
|
||||
#endif
|
||||
Vendored
+481
@@ -0,0 +1,481 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by Andrey Kiselev <dron@remotesensing.org> to handle UUID
|
||||
* box properly.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JP2 Library
|
||||
*
|
||||
* $Id: jp2_enc.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_image.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_cm.h"
|
||||
#include "jasper/jas_icc.h"
|
||||
#include "jp2_cod.h"
|
||||
|
||||
static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype);
|
||||
static int clrspctojp2(jas_clrspc_t clrspc);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
int jp2_write_header(jas_image_t *image, jas_stream_t *out)
|
||||
{
|
||||
jp2_box_t *box;
|
||||
jp2_ftyp_t *ftyp;
|
||||
jp2_ihdr_t *ihdr;
|
||||
jas_stream_t *tmpstream;
|
||||
int allcmptssame;
|
||||
jp2_bpcc_t *bpcc;
|
||||
long len;
|
||||
uint_fast16_t cmptno;
|
||||
jp2_colr_t *colr;
|
||||
jp2_cdefchan_t *cdefchanent;
|
||||
jp2_cdef_t *cdef;
|
||||
int i;
|
||||
uint_fast32_t typeasoc;
|
||||
jas_iccprof_t *iccprof;
|
||||
jas_stream_t *iccstream;
|
||||
int pos;
|
||||
int needcdef;
|
||||
int prec;
|
||||
int sgnd;
|
||||
|
||||
box = 0;
|
||||
tmpstream = 0;
|
||||
|
||||
allcmptssame = 1;
|
||||
sgnd = jas_image_cmptsgnd(image, 0);
|
||||
prec = jas_image_cmptprec(image, 0);
|
||||
for (i = 1; i < jas_image_numcmpts(image); ++i) {
|
||||
if (jas_image_cmptsgnd(image, i) != sgnd ||
|
||||
jas_image_cmptprec(image, i) != prec) {
|
||||
allcmptssame = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the signature box. */
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_JP))) {
|
||||
goto error;
|
||||
}
|
||||
box->data.jp.magic = JP2_JP_MAGIC;
|
||||
if (jp2_box_put(box, out)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/* Output the file type box. */
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_FTYP))) {
|
||||
goto error;
|
||||
}
|
||||
ftyp = &box->data.ftyp;
|
||||
ftyp->majver = JP2_FTYP_MAJVER;
|
||||
ftyp->minver = JP2_FTYP_MINVER;
|
||||
ftyp->numcompatcodes = 1;
|
||||
ftyp->compatcodes[0] = JP2_FTYP_COMPATCODE;
|
||||
if (jp2_box_put(box, out)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/*
|
||||
* Generate the data portion of the JP2 header box.
|
||||
* We cannot simply output the header for this box
|
||||
* since we do not yet know the correct value for the length
|
||||
* field.
|
||||
*/
|
||||
|
||||
if (!(tmpstream = jas_stream_memopen(0, 0))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Generate image header box. */
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_IHDR))) {
|
||||
goto error;
|
||||
}
|
||||
ihdr = &box->data.ihdr;
|
||||
ihdr->width = jas_image_width(image);
|
||||
ihdr->height = jas_image_height(image);
|
||||
ihdr->numcmpts = jas_image_numcmpts(image);
|
||||
ihdr->bpc = allcmptssame ? JP2_SPTOBPC(jas_image_cmptsgnd(image, 0),
|
||||
jas_image_cmptprec(image, 0)) : JP2_IHDR_BPCNULL;
|
||||
ihdr->comptype = JP2_IHDR_COMPTYPE;
|
||||
ihdr->csunk = 0;
|
||||
ihdr->ipr = 0;
|
||||
if (jp2_box_put(box, tmpstream)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/* Generate bits per component box. */
|
||||
|
||||
if (!allcmptssame) {
|
||||
if (!(box = jp2_box_create(JP2_BOX_BPCC))) {
|
||||
goto error;
|
||||
}
|
||||
bpcc = &box->data.bpcc;
|
||||
bpcc->numcmpts = jas_image_numcmpts(image);
|
||||
if (!(bpcc->bpcs = jas_alloc2(bpcc->numcmpts,
|
||||
sizeof(uint_fast8_t)))) {
|
||||
goto error;
|
||||
}
|
||||
for (cmptno = 0; cmptno < bpcc->numcmpts; ++cmptno) {
|
||||
bpcc->bpcs[cmptno] = JP2_SPTOBPC(jas_image_cmptsgnd(image,
|
||||
cmptno), jas_image_cmptprec(image, cmptno));
|
||||
}
|
||||
if (jp2_box_put(box, tmpstream)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
}
|
||||
|
||||
/* Generate color specification box. */
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_COLR))) {
|
||||
goto error;
|
||||
}
|
||||
colr = &box->data.colr;
|
||||
switch (jas_image_clrspc(image)) {
|
||||
case JAS_CLRSPC_SRGB:
|
||||
case JAS_CLRSPC_SYCBCR:
|
||||
case JAS_CLRSPC_SGRAY:
|
||||
colr->method = JP2_COLR_ENUM;
|
||||
colr->csid = clrspctojp2(jas_image_clrspc(image));
|
||||
colr->pri = JP2_COLR_PRI;
|
||||
colr->approx = 0;
|
||||
break;
|
||||
default:
|
||||
colr->method = JP2_COLR_ICC;
|
||||
colr->pri = JP2_COLR_PRI;
|
||||
colr->approx = 0;
|
||||
iccprof = jas_iccprof_createfromcmprof(jas_image_cmprof(image));
|
||||
assert(iccprof);
|
||||
iccstream = jas_stream_memopen(0, 0);
|
||||
assert(iccstream);
|
||||
if (jas_iccprof_save(iccprof, iccstream))
|
||||
abort();
|
||||
if ((pos = jas_stream_tell(iccstream)) < 0)
|
||||
abort();
|
||||
colr->iccplen = pos;
|
||||
colr->iccp = jas_malloc(pos);
|
||||
assert(colr->iccp);
|
||||
jas_stream_rewind(iccstream);
|
||||
if (jas_stream_read(iccstream, colr->iccp, colr->iccplen) != colr->iccplen)
|
||||
abort();
|
||||
jas_stream_close(iccstream);
|
||||
jas_iccprof_destroy(iccprof);
|
||||
break;
|
||||
}
|
||||
if (jp2_box_put(box, tmpstream)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
needcdef = 1;
|
||||
switch (jas_clrspc_fam(jas_image_clrspc(image))) {
|
||||
case JAS_CLRSPC_FAM_RGB:
|
||||
if (jas_image_cmpttype(image, 0) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R) &&
|
||||
jas_image_cmpttype(image, 1) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G) &&
|
||||
jas_image_cmpttype(image, 2) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B))
|
||||
needcdef = 0;
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_YCBCR:
|
||||
if (jas_image_cmpttype(image, 0) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y) &&
|
||||
jas_image_cmpttype(image, 1) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB) &&
|
||||
jas_image_cmpttype(image, 2) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR))
|
||||
needcdef = 0;
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_GRAY:
|
||||
if (jas_image_cmpttype(image, 0) ==
|
||||
JAS_IMAGE_CT_COLOR(JAS_IMAGE_CT_GRAY_Y))
|
||||
needcdef = 0;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
if (needcdef) {
|
||||
if (!(box = jp2_box_create(JP2_BOX_CDEF))) {
|
||||
goto error;
|
||||
}
|
||||
cdef = &box->data.cdef;
|
||||
cdef->numchans = jas_image_numcmpts(image);
|
||||
cdef->ents = jas_alloc2(cdef->numchans, sizeof(jp2_cdefchan_t));
|
||||
for (i = 0; i < jas_image_numcmpts(image); ++i) {
|
||||
cdefchanent = &cdef->ents[i];
|
||||
cdefchanent->channo = i;
|
||||
typeasoc = jp2_gettypeasoc(jas_image_clrspc(image), jas_image_cmpttype(image, i));
|
||||
cdefchanent->type = typeasoc >> 16;
|
||||
cdefchanent->assoc = typeasoc & 0x7fff;
|
||||
}
|
||||
if (jp2_box_put(box, tmpstream)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
}
|
||||
|
||||
/* Determine the total length of the JP2 header box. */
|
||||
|
||||
len = jas_stream_tell(tmpstream);
|
||||
jas_stream_rewind(tmpstream);
|
||||
|
||||
/*
|
||||
* Output the JP2 header box and all of the boxes which it contains.
|
||||
*/
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_JP2H))) {
|
||||
goto error;
|
||||
}
|
||||
box->len = len + JP2_BOX_HDRLEN(false);
|
||||
if (jp2_box_put(box, out)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
if (jas_stream_copy(out, tmpstream, len)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
jas_stream_close(tmpstream);
|
||||
tmpstream = 0;
|
||||
|
||||
return 0;
|
||||
abort();
|
||||
|
||||
error:
|
||||
|
||||
if (box) {
|
||||
jp2_box_destroy(box);
|
||||
}
|
||||
if (tmpstream) {
|
||||
jas_stream_close(tmpstream);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int jp2_write_codestream(jas_image_t *image, jas_stream_t *out, char *optstr)
|
||||
{
|
||||
jp2_box_t *box;
|
||||
char buf[4096];
|
||||
uint_fast32_t overhead;
|
||||
|
||||
/*
|
||||
* Output the contiguous code stream box.
|
||||
*/
|
||||
|
||||
if (!(box = jp2_box_create(JP2_BOX_JP2C))) {
|
||||
goto error;
|
||||
}
|
||||
box->len = 0;
|
||||
if (jp2_box_put(box, out)) {
|
||||
goto error;
|
||||
}
|
||||
jp2_box_destroy(box);
|
||||
box = 0;
|
||||
|
||||
/* Output the JPEG-2000 code stream. */
|
||||
|
||||
overhead = jas_stream_getrwcount(out);
|
||||
sprintf(buf, "%s\n_jp2overhead=%lu\n", (optstr ? optstr : ""),
|
||||
(unsigned long) overhead);
|
||||
|
||||
if (jpc_encode(image, out, buf)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return 0;
|
||||
abort();
|
||||
|
||||
error:
|
||||
|
||||
if (box) {
|
||||
jp2_box_destroy(box);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int jp2_encode(jas_image_t *image, jas_stream_t *out, char *optstr)
|
||||
{
|
||||
if (jp2_write_header(image, out) < 0)
|
||||
return -1;
|
||||
if (jp2_write_codestream(image, out, optstr) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jp2_encode_uuid(jas_image_t *image, jas_stream_t *out,
|
||||
char *optstr, jp2_box_t *uuid)
|
||||
{
|
||||
if (jp2_write_header(image, out) < 0)
|
||||
return -1;
|
||||
if (uuid) {
|
||||
if (jp2_box_put(uuid, out))
|
||||
return -1;
|
||||
}
|
||||
if (jp2_write_codestream(image, out, optstr) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint_fast32_t jp2_gettypeasoc(int colorspace, int ctype)
|
||||
{
|
||||
int type;
|
||||
int asoc;
|
||||
|
||||
if (ctype & JAS_IMAGE_CT_OPACITY) {
|
||||
type = JP2_CDEF_TYPE_OPACITY;
|
||||
asoc = JP2_CDEF_ASOC_ALL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
type = JP2_CDEF_TYPE_UNSPEC;
|
||||
asoc = JP2_CDEF_ASOC_NONE;
|
||||
switch (jas_clrspc_fam(colorspace)) {
|
||||
case JAS_CLRSPC_FAM_RGB:
|
||||
switch (JAS_IMAGE_CT_COLOR(ctype)) {
|
||||
case JAS_IMAGE_CT_RGB_R:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_RGB_R;
|
||||
break;
|
||||
case JAS_IMAGE_CT_RGB_G:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_RGB_G;
|
||||
break;
|
||||
case JAS_IMAGE_CT_RGB_B:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_RGB_B;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_YCBCR:
|
||||
switch (JAS_IMAGE_CT_COLOR(ctype)) {
|
||||
case JAS_IMAGE_CT_YCBCR_Y:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_YCBCR_Y;
|
||||
break;
|
||||
case JAS_IMAGE_CT_YCBCR_CB:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_YCBCR_CB;
|
||||
break;
|
||||
case JAS_IMAGE_CT_YCBCR_CR:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_YCBCR_CR;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JAS_CLRSPC_FAM_GRAY:
|
||||
type = JP2_CDEF_TYPE_COLOR;
|
||||
asoc = JP2_CDEF_GRAY_Y;
|
||||
break;
|
||||
}
|
||||
|
||||
done:
|
||||
return (type << 16) | asoc;
|
||||
}
|
||||
|
||||
static int clrspctojp2(jas_clrspc_t clrspc)
|
||||
{
|
||||
switch (clrspc) {
|
||||
case JAS_CLRSPC_SRGB:
|
||||
return JP2_COLR_SRGB;
|
||||
case JAS_CLRSPC_SYCBCR:
|
||||
return JP2_COLR_SYCC;
|
||||
case JAS_CLRSPC_SGRAY:
|
||||
return JP2_COLR_SGRAY;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Vendored
+440
@@ -0,0 +1,440 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000, Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bit Stream Class
|
||||
*
|
||||
* $Id: jpc_bs.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jpc_bs.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Local function prototypes.
|
||||
\******************************************************************************/
|
||||
|
||||
static jpc_bitstream_t *jpc_bitstream_alloc(void);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for opening and closing bit streams.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Open a bit stream from a stream. */
|
||||
jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, char *mode)
|
||||
{
|
||||
jpc_bitstream_t *bitstream;
|
||||
|
||||
/* Ensure that the open mode is valid. */
|
||||
#if 1
|
||||
/* This causes a string literal too long error (with c99 pedantic mode). */
|
||||
assert(!strcmp(mode, "r") || !strcmp(mode, "w") || !strcmp(mode, "r+")
|
||||
|| !strcmp(mode, "w+"));
|
||||
#endif
|
||||
|
||||
if (!(bitstream = jpc_bitstream_alloc())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* By default, do not close the underlying (character) stream, upon
|
||||
the close of the bit stream. */
|
||||
bitstream->flags_ = JPC_BITSTREAM_NOCLOSE;
|
||||
|
||||
bitstream->stream_ = stream;
|
||||
bitstream->openmode_ = (mode[0] == 'w') ? JPC_BITSTREAM_WRITE :
|
||||
JPC_BITSTREAM_READ;
|
||||
|
||||
/* Mark the data buffer as empty. */
|
||||
bitstream->cnt_ = (bitstream->openmode_ == JPC_BITSTREAM_READ) ? 0 : 8;
|
||||
bitstream->buf_ = 0;
|
||||
|
||||
return bitstream;
|
||||
}
|
||||
|
||||
/* Close a bit stream. */
|
||||
int jpc_bitstream_close(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/* Align to the next byte boundary while considering the effects of
|
||||
bit stuffing. */
|
||||
if (jpc_bitstream_align(bitstream)) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
/* If necessary, close the underlying (character) stream. */
|
||||
if (!(bitstream->flags_ & JPC_BITSTREAM_NOCLOSE) && bitstream->stream_) {
|
||||
if (jas_stream_close(bitstream->stream_)) {
|
||||
ret = -1;
|
||||
}
|
||||
bitstream->stream_ = 0;
|
||||
}
|
||||
|
||||
jas_free(bitstream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allocate a new bit stream. */
|
||||
static jpc_bitstream_t *jpc_bitstream_alloc()
|
||||
{
|
||||
jpc_bitstream_t *bitstream;
|
||||
|
||||
/* Allocate memory for the new bit stream object. */
|
||||
if (!(bitstream = jas_malloc(sizeof(jpc_bitstream_t)))) {
|
||||
return 0;
|
||||
}
|
||||
/* Initialize all of the data members. */
|
||||
bitstream->stream_ = 0;
|
||||
bitstream->cnt_ = 0;
|
||||
bitstream->flags_ = 0;
|
||||
bitstream->openmode_ = 0;
|
||||
|
||||
return bitstream;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for reading/writing from/to bit streams.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get a bit from a bit stream. */
|
||||
int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
int ret;
|
||||
JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func(%p)\n", bitstream));
|
||||
ret = jpc_bitstream_getbit_macro(bitstream);
|
||||
JAS_DBGLOG(1000, ("jpc_bitstream_getbit_func -> %d\n", ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Put a bit to a bit stream. */
|
||||
int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int b)
|
||||
{
|
||||
int ret;
|
||||
JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func(%p, %d)\n", bitstream, b));
|
||||
ret = jpc_bitstream_putbit_macro(bitstream, b);
|
||||
JAS_DBGLOG(1000, ("jpc_bitstream_putbit_func() -> %d\n", ret));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get one or more bits from a bit stream. */
|
||||
long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n)
|
||||
{
|
||||
long v;
|
||||
int u;
|
||||
|
||||
/* We can reliably get at most 31 bits since ISO/IEC 9899 only
|
||||
guarantees that a long can represent values up to 2^31-1. */
|
||||
assert(n >= 0 && n < 32);
|
||||
|
||||
/* Get the number of bits requested from the specified bit stream. */
|
||||
v = 0;
|
||||
while (--n >= 0) {
|
||||
if ((u = jpc_bitstream_getbit(bitstream)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 1) | u;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Put one or more bits to a bit stream. */
|
||||
int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v)
|
||||
{
|
||||
int m;
|
||||
|
||||
/* We can reliably put at most 31 bits since ISO/IEC 9899 only
|
||||
guarantees that a long can represent values up to 2^31-1. */
|
||||
assert(n >= 0 && n < 32);
|
||||
/* Ensure that only the bits to be output are nonzero. */
|
||||
assert(!(v & (~JAS_ONES(n))));
|
||||
|
||||
/* Put the desired number of bits to the specified bit stream. */
|
||||
m = n - 1;
|
||||
while (--n >= 0) {
|
||||
if (jpc_bitstream_putbit(bitstream, (v >> m) & 1) == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
v <<= 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for buffer filling and flushing.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Fill the buffer for a bit stream. */
|
||||
int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
int c;
|
||||
/* Note: The count has already been decremented by the caller. */
|
||||
assert(bitstream->openmode_ & JPC_BITSTREAM_READ);
|
||||
assert(bitstream->cnt_ <= 0);
|
||||
|
||||
if (bitstream->flags_ & JPC_BITSTREAM_ERR) {
|
||||
bitstream->cnt_ = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (bitstream->flags_ & JPC_BITSTREAM_EOF) {
|
||||
bitstream->buf_ = 0x7f;
|
||||
bitstream->cnt_ = 7;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;
|
||||
if ((c = jas_stream_getc((bitstream)->stream_)) == EOF) {
|
||||
bitstream->flags_ |= JPC_BITSTREAM_EOF;
|
||||
return 1;
|
||||
}
|
||||
bitstream->cnt_ = (bitstream->buf_ == 0xff00) ? 6 : 7;
|
||||
bitstream->buf_ |= c & ((1 << (bitstream->cnt_ + 1)) - 1);
|
||||
return (bitstream->buf_ >> bitstream->cnt_) & 1;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* Code related to flushing.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Does the bit stream need to be aligned to a byte boundary (considering
|
||||
the effects of bit stuffing)? */
|
||||
int jpc_bitstream_needalign(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
|
||||
/* The bit stream is open for reading. */
|
||||
/* If there are any bits buffered for reading, or the
|
||||
previous byte forced a stuffed bit, alignment is
|
||||
required. */
|
||||
if ((bitstream->cnt_ < 8 && bitstream->cnt_ > 0) ||
|
||||
((bitstream->buf_ >> 8) & 0xff) == 0xff) {
|
||||
return 1;
|
||||
}
|
||||
} else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
|
||||
/* The bit stream is open for writing. */
|
||||
/* If there are any bits buffered for writing, or the
|
||||
previous byte forced a stuffed bit, alignment is
|
||||
required. */
|
||||
if ((bitstream->cnt_ < 8 && bitstream->cnt_ >= 0) ||
|
||||
((bitstream->buf_ >> 8) & 0xff) == 0xff) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
/* This should not happen. Famous last words, eh? :-) */
|
||||
assert(0);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* How many additional bytes would be output if we align the bit stream? */
|
||||
int jpc_bitstream_pending(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
|
||||
/* The bit stream is being used for writing. */
|
||||
#if 1
|
||||
/* XXX - Is this really correct? Check someday... */
|
||||
if (bitstream->cnt_ < 8) {
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
if (bitstream->cnt_ < 8) {
|
||||
if (((bitstream->buf_ >> 8) & 0xff) == 0xff) {
|
||||
return 2;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
} else {
|
||||
/* This operation should not be invoked on a bit stream that
|
||||
is being used for reading. */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Align the bit stream to a byte boundary. */
|
||||
int jpc_bitstream_align(jpc_bitstream_t *bitstream)
|
||||
{
|
||||
int ret;
|
||||
if (bitstream->openmode_ & JPC_BITSTREAM_READ) {
|
||||
ret = jpc_bitstream_inalign(bitstream, 0, 0);
|
||||
} else if (bitstream->openmode_ & JPC_BITSTREAM_WRITE) {
|
||||
ret = jpc_bitstream_outalign(bitstream, 0);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Align a bit stream in the input case. */
|
||||
int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask,
|
||||
int filldata)
|
||||
{
|
||||
int n;
|
||||
int v;
|
||||
int u;
|
||||
int numfill;
|
||||
int m;
|
||||
|
||||
numfill = 7;
|
||||
m = 0;
|
||||
v = 0;
|
||||
if (bitstream->cnt_ > 0) {
|
||||
n = bitstream->cnt_;
|
||||
} else if (!bitstream->cnt_) {
|
||||
n = ((bitstream->buf_ & 0xff) == 0xff) ? 7 : 0;
|
||||
} else {
|
||||
n = 0;
|
||||
}
|
||||
if (n > 0) {
|
||||
if ((u = jpc_bitstream_getbits(bitstream, n)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
m += n;
|
||||
v = (v << n) | u;
|
||||
}
|
||||
if ((bitstream->buf_ & 0xff) == 0xff) {
|
||||
if ((u = jpc_bitstream_getbits(bitstream, 7)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
v = (v << 7) | u;
|
||||
m += 7;
|
||||
}
|
||||
if (m > numfill) {
|
||||
v >>= m - numfill;
|
||||
} else {
|
||||
filldata >>= numfill - m;
|
||||
fillmask >>= numfill - m;
|
||||
}
|
||||
if (((~(v ^ filldata)) & fillmask) != fillmask) {
|
||||
/* The actual fill pattern does not match the expected one. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Align a bit stream in the output case. */
|
||||
int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata)
|
||||
{
|
||||
int n;
|
||||
int v;
|
||||
|
||||
/* Ensure that this bit stream is open for writing. */
|
||||
assert(bitstream->openmode_ & JPC_BITSTREAM_WRITE);
|
||||
|
||||
/* Ensure that the first bit of fill data is zero. */
|
||||
/* Note: The first bit of fill data must be zero. If this were not
|
||||
the case, the fill data itself could cause further bit stuffing to
|
||||
be required (which would cause numerous complications). */
|
||||
assert(!(filldata & (~0x3f)));
|
||||
|
||||
if (!bitstream->cnt_) {
|
||||
if ((bitstream->buf_ & 0xff) == 0xff) {
|
||||
n = 7;
|
||||
v = filldata;
|
||||
} else {
|
||||
n = 0;
|
||||
v = 0;
|
||||
}
|
||||
} else if (bitstream->cnt_ > 0 && bitstream->cnt_ < 8) {
|
||||
n = bitstream->cnt_;
|
||||
v = filldata >> (7 - n);
|
||||
} else {
|
||||
n = 0;
|
||||
v = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Write the appropriate fill data to the bit stream. */
|
||||
if (n > 0) {
|
||||
if (jpc_bitstream_putbits(bitstream, n, v)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (bitstream->cnt_ < 8) {
|
||||
assert(bitstream->cnt_ >= 0 && bitstream->cnt_ < 8);
|
||||
assert((bitstream->buf_ & 0xff) != 0xff);
|
||||
/* Force the pending byte of output to be written to the
|
||||
underlying (character) stream. */
|
||||
if (jas_stream_putc(bitstream->stream_, bitstream->buf_ & 0xff) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
bitstream->cnt_ = 8;
|
||||
bitstream->buf_ = (bitstream->buf_ << 8) & 0xffff;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+231
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Bit Stream Class
|
||||
*
|
||||
* $Id: jpc_bs.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_BS_H
|
||||
#define JPC_BS_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Bit stream open mode flags.
|
||||
*/
|
||||
|
||||
/* Bit stream open for reading. */
|
||||
#define JPC_BITSTREAM_READ 0x01
|
||||
/* Bit stream open for writing. */
|
||||
#define JPC_BITSTREAM_WRITE 0x02
|
||||
|
||||
/*
|
||||
* Bit stream flags.
|
||||
*/
|
||||
|
||||
/* Do not close underlying character stream. */
|
||||
#define JPC_BITSTREAM_NOCLOSE 0x01
|
||||
/* End of file has been reached while reading. */
|
||||
#define JPC_BITSTREAM_EOF 0x02
|
||||
/* An I/O error has occurerd. */
|
||||
#define JPC_BITSTREAM_ERR 0x04
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Bit stream class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* Some miscellaneous flags. */
|
||||
int flags_;
|
||||
|
||||
/* The input/output buffer. */
|
||||
uint_fast16_t buf_;
|
||||
|
||||
/* The number of bits remaining in the byte being read/written. */
|
||||
int cnt_;
|
||||
|
||||
/* The underlying stream associated with this bit stream. */
|
||||
jas_stream_t *stream_;
|
||||
|
||||
/* The mode in which this bit stream was opened. */
|
||||
int openmode_;
|
||||
|
||||
} jpc_bitstream_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for opening and closing bit streams..
|
||||
\******************************************************************************/
|
||||
|
||||
/* Open a stream as a bit stream. */
|
||||
jpc_bitstream_t *jpc_bitstream_sopen(jas_stream_t *stream, char *mode);
|
||||
|
||||
/* Close a bit stream. */
|
||||
int jpc_bitstream_close(jpc_bitstream_t *bitstream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for reading from and writing to bit streams..
|
||||
\******************************************************************************/
|
||||
|
||||
/* Read a bit from a bit stream. */
|
||||
#if defined(DEBUG)
|
||||
#define jpc_bitstream_getbit(bitstream) \
|
||||
jpc_bitstream_getbit_func(bitstream)
|
||||
#else
|
||||
#define jpc_bitstream_getbit(bitstream) \
|
||||
jpc_bitstream_getbit_macro(bitstream)
|
||||
#endif
|
||||
|
||||
/* Write a bit to a bit stream. */
|
||||
#if defined(DEBUG)
|
||||
#define jpc_bitstream_putbit(bitstream, v) \
|
||||
jpc_bitstream_putbit_func(bitstream, v)
|
||||
#else
|
||||
#define jpc_bitstream_putbit(bitstream, v) \
|
||||
jpc_bitstream_putbit_macro(bitstream, v)
|
||||
#endif
|
||||
|
||||
/* Read one or more bits from a bit stream. */
|
||||
long jpc_bitstream_getbits(jpc_bitstream_t *bitstream, int n);
|
||||
|
||||
/* Write one or more bits to a bit stream. */
|
||||
int jpc_bitstream_putbits(jpc_bitstream_t *bitstream, int n, long v);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for flushing and aligning bit streams.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Align the current position within the bit stream to the next byte
|
||||
boundary. */
|
||||
int jpc_bitstream_align(jpc_bitstream_t *bitstream);
|
||||
|
||||
/* Align the current position in the bit stream with the next byte boundary,
|
||||
ensuring that certain bits consumed in the process match a particular
|
||||
pattern. */
|
||||
int jpc_bitstream_inalign(jpc_bitstream_t *bitstream, int fillmask,
|
||||
int filldata);
|
||||
|
||||
/* Align the current position in the bit stream with the next byte boundary,
|
||||
writing bits from the specified pattern (if necessary) in the process. */
|
||||
int jpc_bitstream_outalign(jpc_bitstream_t *bitstream, int filldata);
|
||||
|
||||
/* Check if a bit stream needs alignment. */
|
||||
int jpc_bitstream_needalign(jpc_bitstream_t *bitstream);
|
||||
|
||||
/* How many additional bytes would be output if the bit stream was aligned? */
|
||||
int jpc_bitstream_pending(jpc_bitstream_t *bitstream);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for querying state information for bit streams.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Has EOF been encountered on a bit stream? */
|
||||
#define jpc_bitstream_eof(bitstream) \
|
||||
((bitstream)->flags_ & JPC_BITSTREAM_EOF)
|
||||
|
||||
/******************************************************************************\
|
||||
* Internals.
|
||||
\******************************************************************************/
|
||||
|
||||
/* DO NOT DIRECTLY INVOKE ANY OF THE MACROS OR FUNCTIONS BELOW. THEY ARE
|
||||
FOR INTERNAL USE ONLY. */
|
||||
|
||||
int jpc_bitstream_getbit_func(jpc_bitstream_t *bitstream);
|
||||
|
||||
int jpc_bitstream_putbit_func(jpc_bitstream_t *bitstream, int v);
|
||||
|
||||
int jpc_bitstream_fillbuf(jpc_bitstream_t *bitstream);
|
||||
|
||||
#define jpc_bitstream_getbit_macro(bitstream) \
|
||||
(assert((bitstream)->openmode_ & JPC_BITSTREAM_READ), \
|
||||
(--(bitstream)->cnt_ >= 0) ? \
|
||||
((int)(((bitstream)->buf_ >> (bitstream)->cnt_) & 1)) : \
|
||||
jpc_bitstream_fillbuf(bitstream))
|
||||
|
||||
#define jpc_bitstream_putbit_macro(bitstream, bit) \
|
||||
(assert((bitstream)->openmode_ & JPC_BITSTREAM_WRITE), \
|
||||
(--(bitstream)->cnt_ < 0) ? \
|
||||
((bitstream)->buf_ = ((bitstream)->buf_ << 8) & 0xffff, \
|
||||
(bitstream)->cnt_ = ((bitstream)->buf_ == 0xff00) ? 6 : 7, \
|
||||
(bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
|
||||
(jas_stream_putc((bitstream)->stream_, (bitstream)->buf_ >> 8) == EOF) \
|
||||
? (EOF) : ((bit) & 1)) : \
|
||||
((bitstream)->buf_ |= ((bit) & 1) << (bitstream)->cnt_, \
|
||||
(bit) & 1))
|
||||
|
||||
#endif
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jpc_cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_COD_H
|
||||
#define JPC_COD_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The nominal word size used by this implementation. */
|
||||
#define JPC_PREC 32
|
||||
|
||||
#endif
|
||||
Vendored
+1650
File diff suppressed because it is too large
Load Diff
Vendored
+763
@@ -0,0 +1,763 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JPEG-2000 Code Stream Library
|
||||
*
|
||||
* $Id: jpc_cs.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_CS_H
|
||||
#define JPC_CS_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_image.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
#include "jpc_cod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants and Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The maximum number of resolution levels. */
|
||||
#define JPC_MAXRLVLS 33
|
||||
|
||||
/* The maximum number of bands. */
|
||||
#define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1)
|
||||
|
||||
/* The maximum number of layers. */
|
||||
#define JPC_MAXLYRS 16384
|
||||
|
||||
/**************************************\
|
||||
* Code stream.
|
||||
\**************************************/
|
||||
|
||||
/*
|
||||
* Code stream states.
|
||||
*/
|
||||
|
||||
/* Initial. */
|
||||
#define JPC_CS_INIT 0
|
||||
/* Main header. */
|
||||
#define JPC_CS_MHDR 1
|
||||
/* Tile-part header. */
|
||||
#define JPC_CS_THDR 2
|
||||
/* Main trailer. */
|
||||
#define JPC_CS_MTLR 3
|
||||
/* Tile-part data. */
|
||||
#define JPC_CS_TDATA 4
|
||||
|
||||
/*
|
||||
* Unfortunately, the code stream syntax was not designed in such a way that
|
||||
* any given marker segment can be correctly decoded without additional state
|
||||
* derived from previously decoded marker segments.
|
||||
* For example, a RGN/COC/QCC marker segment cannot be decoded unless the
|
||||
* number of components is known.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Code stream state information.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of components. */
|
||||
uint_fast16_t numcomps;
|
||||
|
||||
} jpc_cstate_t;
|
||||
|
||||
/**************************************\
|
||||
* SOT marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The tile number. */
|
||||
uint_fast16_t tileno;
|
||||
|
||||
/* The combined length of the marker segment and its auxilary data
|
||||
(i.e., packet data). */
|
||||
uint_fast32_t len;
|
||||
|
||||
/* The tile-part instance. */
|
||||
uint_fast8_t partno;
|
||||
|
||||
/* The number of tile-parts. */
|
||||
uint_fast8_t numparts;
|
||||
|
||||
} jpc_sot_t;
|
||||
|
||||
/**************************************\
|
||||
* SIZ marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/* Per component information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The precision of the samples. */
|
||||
uint_fast8_t prec;
|
||||
|
||||
/* The signedness of the samples. */
|
||||
uint_fast8_t sgnd;
|
||||
|
||||
/* The horizontal separation of samples with respect to the reference
|
||||
grid. */
|
||||
uint_fast8_t hsamp;
|
||||
|
||||
/* The vertical separation of samples with respect to the reference
|
||||
grid. */
|
||||
uint_fast8_t vsamp;
|
||||
|
||||
} jpc_sizcomp_t;
|
||||
|
||||
/* SIZ marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The code stream capabilities. */
|
||||
uint_fast16_t caps;
|
||||
|
||||
/* The width of the image in units of the reference grid. */
|
||||
uint_fast32_t width;
|
||||
|
||||
/* The height of the image in units of the reference grid. */
|
||||
uint_fast32_t height;
|
||||
|
||||
/* The horizontal offset from the origin of the reference grid to the
|
||||
left side of the image area. */
|
||||
uint_fast32_t xoff;
|
||||
|
||||
/* The vertical offset from the origin of the reference grid to the
|
||||
top side of the image area. */
|
||||
uint_fast32_t yoff;
|
||||
|
||||
/* The nominal width of a tile in units of the reference grid. */
|
||||
uint_fast32_t tilewidth;
|
||||
|
||||
/* The nominal height of a tile in units of the reference grid. */
|
||||
uint_fast32_t tileheight;
|
||||
|
||||
/* The horizontal offset from the origin of the reference grid to the
|
||||
left side of the first tile. */
|
||||
uint_fast32_t tilexoff;
|
||||
|
||||
/* The vertical offset from the origin of the reference grid to the
|
||||
top side of the first tile. */
|
||||
uint_fast32_t tileyoff;
|
||||
|
||||
/* The number of components. */
|
||||
uint_fast16_t numcomps;
|
||||
|
||||
/* The per-component information. */
|
||||
jpc_sizcomp_t *comps;
|
||||
|
||||
} jpc_siz_t;
|
||||
|
||||
/**************************************\
|
||||
* COD marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/*
|
||||
* Coding style constants.
|
||||
*/
|
||||
|
||||
/* Precincts may be used. */
|
||||
#define JPC_COX_PRT 0x01
|
||||
/* SOP marker segments may be used. */
|
||||
#define JPC_COD_SOP 0x02
|
||||
/* EPH marker segments may be used. */
|
||||
#define JPC_COD_EPH 0x04
|
||||
|
||||
/*
|
||||
* Progression order constants.
|
||||
*/
|
||||
|
||||
/* Layer-resolution-component-precinct progressive
|
||||
(i.e., progressive by fidelity). */
|
||||
#define JPC_COD_LRCPPRG 0
|
||||
/* Resolution-layer-component-precinct progressive
|
||||
(i.e., progressive by resolution). */
|
||||
#define JPC_COD_RLCPPRG 1
|
||||
/* Resolution-precinct-component-layer progressive. */
|
||||
#define JPC_COD_RPCLPRG 2
|
||||
/* Precinct-component-resolution-layer progressive. */
|
||||
#define JPC_COD_PCRLPRG 3
|
||||
/* Component-position-resolution-layer progressive. */
|
||||
#define JPC_COD_CPRLPRG 4
|
||||
|
||||
/*
|
||||
* Code block style constants.
|
||||
*/
|
||||
|
||||
#define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */
|
||||
#define JPC_COX_RESET 0x02 /* Reset context probabilities. */
|
||||
#define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */
|
||||
#define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */
|
||||
#define JPC_COX_PTERM 0x10 /* Predictable termination. */
|
||||
#define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */
|
||||
|
||||
/* Transform constants. */
|
||||
#define JPC_COX_INS 0x00 /* Irreversible 9/7. */
|
||||
#define JPC_COX_RFT 0x01 /* Reversible 5/3. */
|
||||
|
||||
/* Multicomponent transform constants. */
|
||||
#define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */
|
||||
#define JPC_COD_MCT 0x01 /* Multicomponent transform. */
|
||||
|
||||
/* Get the code block size value from the code block size exponent. */
|
||||
#define JPC_COX_CBLKSIZEEXPN(x) ((x) - 2)
|
||||
/* Get the code block size exponent from the code block size value. */
|
||||
#define JPC_COX_GETCBLKSIZEEXPN(x) ((x) + 2)
|
||||
|
||||
/* Per resolution-level information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The packet partition width. */
|
||||
uint_fast8_t parwidthval;
|
||||
|
||||
/* The packet partition height. */
|
||||
uint_fast8_t parheightval;
|
||||
|
||||
} jpc_coxrlvl_t;
|
||||
|
||||
/* Per component information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The coding style. */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The number of decomposition levels. */
|
||||
uint_fast8_t numdlvls;
|
||||
|
||||
/* The nominal code block width specifier. */
|
||||
uint_fast8_t cblkwidthval;
|
||||
|
||||
/* The nominal code block height specifier. */
|
||||
uint_fast8_t cblkheightval;
|
||||
|
||||
/* The style of coding passes. */
|
||||
uint_fast8_t cblksty;
|
||||
|
||||
/* The QMFB employed. */
|
||||
uint_fast8_t qmfbid;
|
||||
|
||||
/* The number of resolution levels. */
|
||||
int numrlvls;
|
||||
|
||||
/* The per-resolution-level information. */
|
||||
jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
|
||||
|
||||
} jpc_coxcp_t;
|
||||
|
||||
/* COD marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The general coding style. */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The progression order. */
|
||||
uint_fast8_t prg;
|
||||
|
||||
/* The number of layers. */
|
||||
uint_fast16_t numlyrs;
|
||||
|
||||
/* The multicomponent transform. */
|
||||
uint_fast8_t mctrans;
|
||||
|
||||
/* Component-related parameters. */
|
||||
jpc_coxcp_t compparms;
|
||||
|
||||
} jpc_cod_t;
|
||||
|
||||
/* COC marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The component number. */
|
||||
uint_fast16_t compno;
|
||||
|
||||
/* Component-related parameters. */
|
||||
jpc_coxcp_t compparms;
|
||||
|
||||
} jpc_coc_t;
|
||||
|
||||
/**************************************\
|
||||
* RGN marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/* The maxshift ROI style. */
|
||||
#define JPC_RGN_MAXSHIFT 0x00
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The component to which the marker applies. */
|
||||
uint_fast16_t compno;
|
||||
|
||||
/* The ROI style. */
|
||||
uint_fast8_t roisty;
|
||||
|
||||
/* The ROI shift value. */
|
||||
uint_fast8_t roishift;
|
||||
|
||||
} jpc_rgn_t;
|
||||
|
||||
/**************************************\
|
||||
* QCD/QCC marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/*
|
||||
* Quantization style constants.
|
||||
*/
|
||||
|
||||
#define JPC_QCX_NOQNT 0 /* No quantization. */
|
||||
#define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */
|
||||
#define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */
|
||||
|
||||
/*
|
||||
* Stepsize manipulation macros.
|
||||
*/
|
||||
|
||||
#define JPC_QCX_GETEXPN(x) ((x) >> 11)
|
||||
#define JPC_QCX_GETMANT(x) ((x) & 0x07ff)
|
||||
#define JPC_QCX_EXPN(x) (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11))
|
||||
#define JPC_QCX_MANT(x) (assert(!((x) & (~0x7ff))), ((x) & 0x7ff))
|
||||
|
||||
/* Per component information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The quantization style. */
|
||||
uint_fast8_t qntsty;
|
||||
|
||||
/* The number of step sizes. */
|
||||
int numstepsizes;
|
||||
|
||||
/* The step sizes. */
|
||||
uint_fast16_t *stepsizes;
|
||||
|
||||
/* The number of guard bits. */
|
||||
uint_fast8_t numguard;
|
||||
|
||||
} jpc_qcxcp_t;
|
||||
|
||||
/* QCC marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The component associated with this marker segment. */
|
||||
uint_fast16_t compno;
|
||||
|
||||
/* The parameters. */
|
||||
jpc_qcxcp_t compparms;
|
||||
|
||||
} jpc_qcc_t;
|
||||
|
||||
/* QCD marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The parameters. */
|
||||
jpc_qcxcp_t compparms;
|
||||
|
||||
} jpc_qcd_t;
|
||||
|
||||
/**************************************\
|
||||
* POD marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The progression order. */
|
||||
uint_fast8_t prgord;
|
||||
|
||||
/* The lower bound (inclusive) on the resolution level for the
|
||||
progression order volume. */
|
||||
uint_fast8_t rlvlnostart;
|
||||
|
||||
/* The upper bound (exclusive) on the resolution level for the
|
||||
progression order volume. */
|
||||
uint_fast8_t rlvlnoend;
|
||||
|
||||
/* The lower bound (inclusive) on the component for the progression
|
||||
order volume. */
|
||||
uint_fast16_t compnostart;
|
||||
|
||||
/* The upper bound (exclusive) on the component for the progression
|
||||
order volume. */
|
||||
uint_fast16_t compnoend;
|
||||
|
||||
/* The upper bound (exclusive) on the layer for the progression
|
||||
order volume. */
|
||||
uint_fast16_t lyrnoend;
|
||||
|
||||
} jpc_pocpchg_t;
|
||||
|
||||
/* An alias for the above type. */
|
||||
typedef jpc_pocpchg_t jpc_pchg_t;
|
||||
|
||||
/* POC marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of progression order changes. */
|
||||
int numpchgs;
|
||||
|
||||
/* The per-progression-order-change information. */
|
||||
jpc_pocpchg_t *pchgs;
|
||||
|
||||
} jpc_poc_t;
|
||||
|
||||
/**************************************\
|
||||
* PPM/PPT marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/* PPM marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The index. */
|
||||
uint_fast8_t ind;
|
||||
|
||||
/* The length. */
|
||||
uint_fast16_t len;
|
||||
|
||||
/* The data. */
|
||||
uchar *data;
|
||||
|
||||
} jpc_ppm_t;
|
||||
|
||||
/* PPT marker segment parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The index. */
|
||||
uint_fast8_t ind;
|
||||
|
||||
/* The length. */
|
||||
uint_fast32_t len;
|
||||
|
||||
/* The data. */
|
||||
unsigned char *data;
|
||||
|
||||
} jpc_ppt_t;
|
||||
|
||||
/**************************************\
|
||||
* COM marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/*
|
||||
* Registration IDs.
|
||||
*/
|
||||
|
||||
#define JPC_COM_BIN 0x00
|
||||
#define JPC_COM_LATIN 0x01
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The registration ID. */
|
||||
uint_fast16_t regid;
|
||||
|
||||
/* The length of the data in bytes. */
|
||||
uint_fast16_t len;
|
||||
|
||||
/* The data. */
|
||||
uchar *data;
|
||||
|
||||
} jpc_com_t;
|
||||
|
||||
/**************************************\
|
||||
* SOP marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The sequence number. */
|
||||
uint_fast16_t seqno;
|
||||
|
||||
} jpc_sop_t;
|
||||
|
||||
/**************************************\
|
||||
* CRG marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
/* Per component information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The horizontal offset. */
|
||||
uint_fast16_t hoff;
|
||||
|
||||
/* The vertical offset. */
|
||||
uint_fast16_t voff;
|
||||
|
||||
} jpc_crgcomp_t;
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of components. */
|
||||
int numcomps;
|
||||
|
||||
/* Per component information. */
|
||||
jpc_crgcomp_t *comps;
|
||||
|
||||
} jpc_crg_t;
|
||||
|
||||
/**************************************\
|
||||
* Marker segment parameters for unknown marker type.
|
||||
\**************************************/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The data. */
|
||||
uchar *data;
|
||||
|
||||
/* The length. */
|
||||
uint_fast16_t len;
|
||||
|
||||
} jpc_unk_t;
|
||||
|
||||
/**************************************\
|
||||
* Generic marker segment parameters.
|
||||
\**************************************/
|
||||
|
||||
typedef union {
|
||||
int soc; /* unused */
|
||||
jpc_sot_t sot;
|
||||
int sod; /* unused */
|
||||
int eoc; /* unused */
|
||||
jpc_siz_t siz;
|
||||
jpc_cod_t cod;
|
||||
jpc_coc_t coc;
|
||||
jpc_rgn_t rgn;
|
||||
jpc_qcd_t qcd;
|
||||
jpc_qcc_t qcc;
|
||||
jpc_poc_t poc;
|
||||
/* jpc_plm_t plm; */
|
||||
/* jpc_plt_t plt; */
|
||||
jpc_ppm_t ppm;
|
||||
jpc_ppt_t ppt;
|
||||
jpc_sop_t sop;
|
||||
int eph; /* unused */
|
||||
jpc_com_t com;
|
||||
jpc_crg_t crg;
|
||||
jpc_unk_t unk;
|
||||
} jpc_msparms_t;
|
||||
|
||||
/**************************************\
|
||||
* Marker segment.
|
||||
\**************************************/
|
||||
|
||||
/* Marker segment IDs. */
|
||||
|
||||
/* The smallest valid marker value. */
|
||||
#define JPC_MS_MIN 0xff00
|
||||
|
||||
/* The largest valid marker value. */
|
||||
#define JPC_MS_MAX 0xffff
|
||||
|
||||
/* The minimum marker value that cannot occur within packet data. */
|
||||
#define JPC_MS_INMIN 0xff80
|
||||
/* The maximum marker value that cannot occur within packet data. */
|
||||
#define JPC_MS_INMAX 0xffff
|
||||
|
||||
/* Delimiting marker segments. */
|
||||
#define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */
|
||||
#define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */
|
||||
#define JPC_MS_SOD 0xff93 /* Start of data (SOD). */
|
||||
#define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */
|
||||
|
||||
/* Fixed information marker segments. */
|
||||
#define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */
|
||||
|
||||
/* Functional marker segments. */
|
||||
#define JPC_MS_COD 0xff52 /* Coding style default (COD). */
|
||||
#define JPC_MS_COC 0xff53 /* Coding style component (COC). */
|
||||
#define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */
|
||||
#define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */
|
||||
#define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */
|
||||
#define JPC_MS_POC 0xff5f /* Progression order default (POC). */
|
||||
|
||||
/* Pointer marker segments. */
|
||||
#define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */
|
||||
#define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */
|
||||
#define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */
|
||||
#define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */
|
||||
#define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */
|
||||
|
||||
/* In bit stream marker segments. */
|
||||
#define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */
|
||||
#define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */
|
||||
|
||||
/* Informational marker segments. */
|
||||
#define JPC_MS_CRG 0xff63 /* Component registration (CRG). */
|
||||
#define JPC_MS_COM 0xff64 /* Comment (COM). */
|
||||
|
||||
/* Forward declaration. */
|
||||
struct jpc_msops_s;
|
||||
|
||||
/* Generic marker segment class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The type of marker segment. */
|
||||
uint_fast16_t id;
|
||||
|
||||
/* The length of the marker segment. */
|
||||
uint_fast16_t len;
|
||||
|
||||
/* The starting offset within the stream. */
|
||||
uint_fast32_t off;
|
||||
|
||||
/* The parameters of the marker segment. */
|
||||
jpc_msparms_t parms;
|
||||
|
||||
/* The marker segment operations. */
|
||||
struct jpc_msops_s *ops;
|
||||
|
||||
} jpc_ms_t;
|
||||
|
||||
/* Marker segment operations (which depend on the marker segment type). */
|
||||
|
||||
typedef struct jpc_msops_s {
|
||||
|
||||
/* Destroy the marker segment parameters. */
|
||||
void (*destroyparms)(jpc_ms_t *ms);
|
||||
|
||||
/* Get the marker segment parameters from a stream. */
|
||||
int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
|
||||
|
||||
/* Put the marker segment parameters to a stream. */
|
||||
int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
|
||||
|
||||
/* Dump the marker segment parameters (for debugging). */
|
||||
int (*dumpparms)(jpc_ms_t *ms, FILE *out);
|
||||
|
||||
} jpc_msops_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros/Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a code-stream state object. */
|
||||
jpc_cstate_t *jpc_cstate_create(void);
|
||||
|
||||
/* Destroy a code-stream state object. */
|
||||
void jpc_cstate_destroy(jpc_cstate_t *cstate);
|
||||
|
||||
/* Create a marker segment. */
|
||||
jpc_ms_t *jpc_ms_create(int type);
|
||||
|
||||
/* Destroy a marker segment. */
|
||||
void jpc_ms_destroy(jpc_ms_t *ms);
|
||||
|
||||
/* Does a marker segment have parameters? */
|
||||
#define JPC_MS_HASPARMS(x) \
|
||||
(!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \
|
||||
(x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f)))
|
||||
|
||||
/* Get the marker segment type. */
|
||||
#define jpc_ms_gettype(ms) \
|
||||
((ms)->id)
|
||||
|
||||
/* Read a marker segment from a stream. */
|
||||
jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
|
||||
|
||||
/* Write a marker segment to a stream. */
|
||||
int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
|
||||
|
||||
/* Copy code stream data from one stream to another. */
|
||||
int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
|
||||
|
||||
/* Copy code stream data from one stream to another. */
|
||||
int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
|
||||
|
||||
/* Dump a marker segment (for debugging). */
|
||||
void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
|
||||
|
||||
/* Read a 8-bit unsigned integer from a stream. */
|
||||
int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
|
||||
|
||||
/* Read a 16-bit unsigned integer from a stream. */
|
||||
int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
|
||||
|
||||
/* Read a 32-bit unsigned integer from a stream. */
|
||||
int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
|
||||
|
||||
/* Write a 8-bit unsigned integer to a stream. */
|
||||
int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
|
||||
|
||||
/* Write a 16-bit unsigned integer to a stream. */
|
||||
int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
|
||||
|
||||
/* Write a 32-bit unsigned integer to a stream. */
|
||||
int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
|
||||
|
||||
#endif
|
||||
Vendored
+2304
File diff suppressed because it is too large
Load Diff
Vendored
+696
@@ -0,0 +1,696 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* JPEG-2000 Decoder
|
||||
*
|
||||
* $Id: jpc_dec.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_DEC_H
|
||||
#define JPC_DEC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
#include "jpc_tsfb.h"
|
||||
#include "jpc_bs.h"
|
||||
#include "jpc_tagtree.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_cod.h"
|
||||
#include "jpc_mqdec.h"
|
||||
#include "jpc_t2cod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Below are some ugly warts necessary to support packed packet headers.
|
||||
\******************************************************************************/
|
||||
|
||||
/* PPM/PPT marker segment table entry. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The index for this entry. */
|
||||
uint_fast16_t ind;
|
||||
|
||||
/* The data length. */
|
||||
uint_fast32_t len;
|
||||
|
||||
/* The data. */
|
||||
uchar *data;
|
||||
|
||||
} jpc_ppxstabent_t;
|
||||
|
||||
/* PPM/PPT marker segment table. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of entries. */
|
||||
int numents;
|
||||
|
||||
/* The maximum number of entries (i.e., the allocated size of the array
|
||||
below). */
|
||||
int maxents;
|
||||
|
||||
/* The table entries. */
|
||||
jpc_ppxstabent_t **ents;
|
||||
|
||||
} jpc_ppxstab_t;
|
||||
|
||||
/* Stream list class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of streams in this list. */
|
||||
int numstreams;
|
||||
|
||||
/* The maximum number of streams that can be accomodated without
|
||||
growing the streams array. */
|
||||
int maxstreams;
|
||||
|
||||
/* The streams. */
|
||||
jas_stream_t **streams;
|
||||
|
||||
} jpc_streamlist_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Coding parameters class.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Per-component coding parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* How were various coding parameters set? */
|
||||
int flags;
|
||||
|
||||
/* Per-component coding style parameters (e.g., explicit precinct sizes) */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The number of resolution levels. */
|
||||
uint_fast8_t numrlvls;
|
||||
|
||||
/* The code block width exponent. */
|
||||
uint_fast8_t cblkwidthexpn;
|
||||
|
||||
/* The code block height exponent. */
|
||||
uint_fast8_t cblkheightexpn;
|
||||
|
||||
/* The QMFB ID. */
|
||||
uint_fast8_t qmfbid;
|
||||
|
||||
/* The quantization style. */
|
||||
uint_fast8_t qsty;
|
||||
|
||||
/* The number of quantizer step sizes. */
|
||||
uint_fast16_t numstepsizes;
|
||||
|
||||
/* The step sizes. */
|
||||
uint_fast16_t stepsizes[3 * JPC_MAXRLVLS + 1];
|
||||
|
||||
/* The number of guard bits. */
|
||||
uint_fast8_t numguardbits;
|
||||
|
||||
/* The ROI shift value. */
|
||||
uint_fast8_t roishift;
|
||||
|
||||
/* The code block parameters. */
|
||||
uint_fast8_t cblkctx;
|
||||
|
||||
/* The precinct width exponents. */
|
||||
uint_fast8_t prcwidthexpns[JPC_MAXRLVLS];
|
||||
|
||||
/* The precinct height exponents. */
|
||||
uint_fast8_t prcheightexpns[JPC_MAXRLVLS];
|
||||
|
||||
} jpc_dec_ccp_t;
|
||||
|
||||
/* Coding paramters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* How were these coding parameters set? */
|
||||
int flags;
|
||||
|
||||
/* Progression change list. */
|
||||
jpc_pchglist_t *pchglist;
|
||||
|
||||
/* Progression order. */
|
||||
uint_fast8_t prgord;
|
||||
|
||||
/* The number of layers. */
|
||||
uint_fast16_t numlyrs;
|
||||
|
||||
/* The MCT ID. */
|
||||
uint_fast8_t mctid;
|
||||
|
||||
/* The coding style parameters (e.g., SOP, EPH). */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The number of components. */
|
||||
int numcomps;
|
||||
|
||||
/* The per-component coding parameters. */
|
||||
jpc_dec_ccp_t *ccps;
|
||||
|
||||
} jpc_dec_cp_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Decoder class.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Decoder per-segment state information. */
|
||||
|
||||
typedef struct jpc_dec_seg_s {
|
||||
|
||||
/* The next segment in the list. */
|
||||
struct jpc_dec_seg_s *next;
|
||||
|
||||
/* The previous segment in the list. */
|
||||
struct jpc_dec_seg_s *prev;
|
||||
|
||||
/* The starting pass number for this segment. */
|
||||
int passno;
|
||||
|
||||
/* The number of passes in this segment. */
|
||||
int numpasses;
|
||||
|
||||
/* The maximum number of passes in this segment. */
|
||||
int maxpasses;
|
||||
|
||||
/* The type of data in this segment (i.e., MQ or raw). */
|
||||
int type;
|
||||
|
||||
/* A stream containing the data for this segment. */
|
||||
jas_stream_t *stream;
|
||||
|
||||
/* The number of bytes destined for this segment from the packet
|
||||
currently being decoded. */
|
||||
int cnt;
|
||||
|
||||
/* A flag indicating if this segment has been terminated. */
|
||||
int complete;
|
||||
|
||||
/* The layer number to which this segment belongs. */
|
||||
/* If the segment spans multiple layers, then the largest layer number
|
||||
spanned by the segment is used. */
|
||||
int lyrno;
|
||||
|
||||
} jpc_dec_seg_t;
|
||||
|
||||
/* Decoder segment list. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The first entry in the list. */
|
||||
jpc_dec_seg_t *head;
|
||||
|
||||
/* The last entry in the list. */
|
||||
jpc_dec_seg_t *tail;
|
||||
|
||||
} jpc_dec_seglist_t;
|
||||
|
||||
/* Decoder per-code-block state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of passes. */
|
||||
int numpasses;
|
||||
|
||||
/* A list of segments that still need to be decoded. */
|
||||
jpc_dec_seglist_t segs;
|
||||
|
||||
/* The first incomplete/partial segment. */
|
||||
jpc_dec_seg_t *curseg;
|
||||
|
||||
/* The number of leading insignificant bit planes for this code block. */
|
||||
int numimsbs;
|
||||
|
||||
/* The number of bits used to encode pass data lengths. */
|
||||
int numlenbits;
|
||||
|
||||
/* The first pass number containing data for this code block. */
|
||||
int firstpassno;
|
||||
|
||||
/* The MQ decoder. */
|
||||
jpc_mqdec_t *mqdec;
|
||||
|
||||
/* The raw bit stream decoder. */
|
||||
jpc_bitstream_t *nulldec;
|
||||
|
||||
/* The per-sample state information for this code block. */
|
||||
jas_matrix_t *flags;
|
||||
|
||||
/* The sample data associated with this code block. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
} jpc_dec_cblk_t;
|
||||
|
||||
/* Decoder per-code-block-group state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The x-coordinate of the top-left corner of the precinct. */
|
||||
uint_fast32_t xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the precinct. */
|
||||
uint_fast32_t ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the precinct
|
||||
(plus one). */
|
||||
uint_fast32_t xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the precinct
|
||||
(plus one). */
|
||||
uint_fast32_t yend;
|
||||
|
||||
/* The number of code blocks spanning this precinct in the horizontal
|
||||
direction. */
|
||||
int numhcblks;
|
||||
|
||||
/* The number of code blocks spanning this precinct in the vertical
|
||||
direction. */
|
||||
int numvcblks;
|
||||
|
||||
/* The total number of code blocks in this precinct. */
|
||||
int numcblks;
|
||||
|
||||
/* The per code block information. */
|
||||
jpc_dec_cblk_t *cblks;
|
||||
|
||||
/* The inclusion tag tree. */
|
||||
jpc_tagtree_t *incltagtree;
|
||||
|
||||
/* The insignificant MSBs tag tree. */
|
||||
jpc_tagtree_t *numimsbstagtree;
|
||||
|
||||
} jpc_dec_prc_t;
|
||||
|
||||
/* Decoder per-band state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The per-code-block-group state information. */
|
||||
jpc_dec_prc_t *prcs;
|
||||
|
||||
/* The sample data associated with this band. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
/* The orientation of this band (i.e., LL, LH, HL, or HH). */
|
||||
int orient;
|
||||
|
||||
/* The encoded quantizer step size. */
|
||||
int stepsize;
|
||||
|
||||
/* The absolute quantizer step size. */
|
||||
jpc_fix_t absstepsize;
|
||||
|
||||
/* The number of bit planes for this band. */
|
||||
int numbps;
|
||||
|
||||
/* The analysis gain associated with this band. */
|
||||
int analgain;
|
||||
|
||||
/* The ROI shift value for this band. */
|
||||
int roishift;
|
||||
|
||||
} jpc_dec_band_t;
|
||||
|
||||
/* Decoder per-resolution-level state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of bands associated with this resolution level. */
|
||||
int numbands;
|
||||
|
||||
/* The per-band information. */
|
||||
jpc_dec_band_t *bands;
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile-component
|
||||
at this resolution. */
|
||||
uint_fast32_t xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile-component
|
||||
at this resolution. */
|
||||
uint_fast32_t ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile-component
|
||||
at this resolution (plus one). */
|
||||
uint_fast32_t xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile-component
|
||||
at this resolution (plus one). */
|
||||
uint_fast32_t yend;
|
||||
|
||||
/* The exponent value for the nominal precinct width measured
|
||||
relative to the associated LL band. */
|
||||
int prcwidthexpn;
|
||||
|
||||
/* The exponent value for the nominal precinct height measured
|
||||
relative to the associated LL band. */
|
||||
int prcheightexpn;
|
||||
|
||||
/* The number of precincts in the horizontal direction. */
|
||||
int numhprcs;
|
||||
|
||||
/* The number of precincts in the vertical direction. */
|
||||
int numvprcs;
|
||||
|
||||
/* The total number of precincts. */
|
||||
int numprcs;
|
||||
|
||||
/* The exponent value for the nominal code block group width.
|
||||
This quantity is associated with the next lower resolution level
|
||||
(assuming that there is one). */
|
||||
int cbgwidthexpn;
|
||||
|
||||
/* The exponent value for the nominal code block group height
|
||||
This quantity is associated with the next lower resolution level
|
||||
(assuming that there is one). */
|
||||
int cbgheightexpn;
|
||||
|
||||
/* The exponent value for the code block width. */
|
||||
uint_fast16_t cblkwidthexpn;
|
||||
|
||||
/* The exponent value for the code block height. */
|
||||
uint_fast16_t cblkheightexpn;
|
||||
|
||||
} jpc_dec_rlvl_t;
|
||||
|
||||
/* Decoder per-tile-component state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile-component
|
||||
in the coordinate system of the tile-component. */
|
||||
uint_fast32_t xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile-component
|
||||
in the coordinate system of the tile-component. */
|
||||
uint_fast32_t ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile-component
|
||||
in the coordinate system of the tile-component (plus one). */
|
||||
uint_fast32_t xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile-component
|
||||
in the coordinate system of the tile-component (plus one). */
|
||||
uint_fast32_t yend;
|
||||
|
||||
/* The component data for the current tile. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
/* The number of resolution levels. */
|
||||
int numrlvls;
|
||||
|
||||
/* The per resolution level information. */
|
||||
jpc_dec_rlvl_t *rlvls;
|
||||
|
||||
/* The TSFB. */
|
||||
jpc_tsfb_t *tsfb;
|
||||
|
||||
} jpc_dec_tcomp_t;
|
||||
|
||||
/*
|
||||
* Tile states.
|
||||
*/
|
||||
|
||||
#define JPC_TILE_INIT 0
|
||||
#define JPC_TILE_ACTIVE 1
|
||||
#define JPC_TILE_ACTIVELAST 2
|
||||
#define JPC_TILE_DONE 3
|
||||
|
||||
/* Decoder per-tile state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The processing state for this tile. */
|
||||
int state;
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile on the reference
|
||||
grid. */
|
||||
uint_fast32_t xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile on the reference
|
||||
grid. */
|
||||
uint_fast32_t ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile on the
|
||||
reference grid (plus one). */
|
||||
uint_fast32_t xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile on the
|
||||
reference grid (plus one). */
|
||||
uint_fast32_t yend;
|
||||
|
||||
/* The packed packet header data for this tile. */
|
||||
jpc_ppxstab_t *pptstab;
|
||||
|
||||
/* A stream containing the packed packet header data for this tile. */
|
||||
jas_stream_t *pkthdrstream;
|
||||
|
||||
/* The current position within the packed packet header stream. */
|
||||
long pkthdrstreampos;
|
||||
|
||||
/* The coding parameters for this tile. */
|
||||
jpc_dec_cp_t *cp;
|
||||
|
||||
/* The per tile-component information. */
|
||||
jpc_dec_tcomp_t *tcomps;
|
||||
|
||||
/* The next expected tile-part number. */
|
||||
int partno;
|
||||
|
||||
/* The number of tile-parts. */
|
||||
int numparts;
|
||||
|
||||
/* The coding mode. */
|
||||
int realmode;
|
||||
|
||||
/* The packet iterator for this tile. */
|
||||
jpc_pi_t *pi;
|
||||
|
||||
} jpc_dec_tile_t;
|
||||
|
||||
/* Decoder per-component state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The horizontal sampling period. */
|
||||
uint_fast32_t hstep;
|
||||
|
||||
/* The vertical sampling period. */
|
||||
uint_fast32_t vstep;
|
||||
|
||||
/* The number of samples in the horizontal direction. */
|
||||
uint_fast32_t width;
|
||||
|
||||
/* The number of samples in the vertical direction. */
|
||||
uint_fast32_t height;
|
||||
|
||||
/* The precision of the sample data. */
|
||||
uint_fast16_t prec;
|
||||
|
||||
/* The signedness of the sample data. */
|
||||
bool sgnd;
|
||||
|
||||
/* The sample alignment horizontal offset. */
|
||||
uint_fast32_t hsubstep;
|
||||
|
||||
/* The sample alignment vertical offset. */
|
||||
uint_fast32_t vsubstep;
|
||||
|
||||
} jpc_dec_cmpt_t;
|
||||
|
||||
/* Decoder state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The decoded image. */
|
||||
jas_image_t *image;
|
||||
|
||||
/* The x-coordinate of the top-left corner of the image area on
|
||||
the reference grid. */
|
||||
uint_fast32_t xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the image area on
|
||||
the reference grid. */
|
||||
uint_fast32_t ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the image area on
|
||||
the reference grid (plus one). */
|
||||
uint_fast32_t xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the image area on
|
||||
the reference grid (plus one). */
|
||||
uint_fast32_t yend;
|
||||
|
||||
/* The nominal tile width in units of the image reference grid. */
|
||||
uint_fast32_t tilewidth;
|
||||
|
||||
/* The nominal tile height in units of the image reference grid. */
|
||||
uint_fast32_t tileheight;
|
||||
|
||||
/* The horizontal offset from the origin of the reference grid to the
|
||||
left side of the first tile. */
|
||||
uint_fast32_t tilexoff;
|
||||
|
||||
/* The vertical offset from the origin of the reference grid to the
|
||||
top side of the first tile. */
|
||||
uint_fast32_t tileyoff;
|
||||
|
||||
/* The number of tiles spanning the image area in the vertical
|
||||
direction. */
|
||||
int numhtiles;
|
||||
|
||||
/* The number of tiles spanning the image area in the horizontal
|
||||
direction. */
|
||||
int numvtiles;
|
||||
|
||||
/* The total number of tiles. */
|
||||
int numtiles;
|
||||
|
||||
/* The per-tile information. */
|
||||
jpc_dec_tile_t *tiles;
|
||||
|
||||
/* The tile currently being processed. */
|
||||
jpc_dec_tile_t *curtile;
|
||||
|
||||
/* The number of components. */
|
||||
int numcomps;
|
||||
|
||||
/* The stream containing the input JPEG-2000 code stream data. */
|
||||
jas_stream_t *in;
|
||||
|
||||
/* The default coding parameters for all tiles. */
|
||||
jpc_dec_cp_t *cp;
|
||||
|
||||
/* The maximum number of layers that may be decoded. */
|
||||
int maxlyrs;
|
||||
|
||||
/* The maximum number of packets that may be decoded. */
|
||||
int maxpkts;
|
||||
|
||||
/* The number of packets decoded so far in the processing of the entire
|
||||
code stream. */
|
||||
int numpkts;
|
||||
|
||||
/* The next expected PPM marker segment sequence number. */
|
||||
int ppmseqno;
|
||||
|
||||
/* The current state for code stream processing. */
|
||||
int state;
|
||||
|
||||
/* The per-component information. */
|
||||
jpc_dec_cmpt_t *cmpts;
|
||||
|
||||
/* The information from PPM marker segments. */
|
||||
jpc_ppxstab_t *ppmstab;
|
||||
|
||||
/* A list of streams containing packet header data from PPM marker
|
||||
segments. */
|
||||
jpc_streamlist_t *pkthdrstreams;
|
||||
|
||||
/* The expected ending offset for a tile-part. */
|
||||
long curtileendoff;
|
||||
|
||||
/* This is required by the tier-2 decoder. */
|
||||
jpc_cstate_t *cstate;
|
||||
|
||||
} jpc_dec_t;
|
||||
|
||||
/* Decoder options. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The debug level for the decoder. */
|
||||
int debug;
|
||||
|
||||
/* The maximum number of layers to decode. */
|
||||
int maxlyrs;
|
||||
|
||||
/* The maximum number of packets to decode. */
|
||||
int maxpkts;
|
||||
|
||||
} jpc_dec_importopts_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a decoder segment object. */
|
||||
jpc_dec_seg_t *jpc_seg_alloc(void);
|
||||
|
||||
/* Destroy a decoder segment object. */
|
||||
void jpc_seg_destroy(jpc_dec_seg_t *seg);
|
||||
|
||||
/* Remove a segment from a segment list. */
|
||||
void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *node);
|
||||
|
||||
/* Insert a segment into a segment list. */
|
||||
void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins,
|
||||
jpc_dec_seg_t *node);
|
||||
|
||||
#endif
|
||||
Vendored
+2620
File diff suppressed because it is too large
Load Diff
Vendored
+646
@@ -0,0 +1,646 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jpc_enc.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_ENC_H
|
||||
#define JPC_ENC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
#include "jpc_t2cod.h"
|
||||
#include "jpc_mqenc.h"
|
||||
#include "jpc_cod.h"
|
||||
#include "jpc_tagtree.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_flt.h"
|
||||
#include "jpc_tsfb.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The number of bits used in various lookup tables. */
|
||||
#define JPC_NUMEXTRABITS JPC_NMSEDEC_FRACBITS
|
||||
|
||||
/* An invalid R-D slope value. */
|
||||
#define JPC_BADRDSLOPE (-1)
|
||||
|
||||
/******************************************************************************\
|
||||
* Coding parameters types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Per-component coding paramters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The horizontal sampling period. */
|
||||
uint_fast8_t sampgrdstepx;
|
||||
|
||||
/* The vertical sampling period. */
|
||||
uint_fast8_t sampgrdstepy;
|
||||
|
||||
/* The sample alignment horizontal offset. */
|
||||
uint_fast8_t sampgrdsubstepx;
|
||||
|
||||
/* The sample alignment vertical offset. */
|
||||
uint_fast8_t sampgrdsubstepy;
|
||||
|
||||
/* The precision of the samples. */
|
||||
uint_fast8_t prec;
|
||||
|
||||
/* The signedness of the samples. */
|
||||
bool sgnd;
|
||||
|
||||
/* The number of step sizes. */
|
||||
uint_fast16_t numstepsizes;
|
||||
|
||||
/* The quantizer step sizes. */
|
||||
uint_fast16_t stepsizes[JPC_MAXBANDS];
|
||||
|
||||
} jpc_enc_ccp_t;
|
||||
|
||||
/* Per-tile coding parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The coding mode. */
|
||||
bool intmode;
|
||||
|
||||
/* The coding style (i.e., SOP, EPH). */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The progression order. */
|
||||
uint_fast8_t prg;
|
||||
|
||||
/* The multicomponent transform. */
|
||||
uint_fast8_t mctid;
|
||||
|
||||
/* The number of layers. */
|
||||
uint_fast16_t numlyrs;
|
||||
|
||||
/* The normalized bit rates associated with the various
|
||||
intermediate layers. */
|
||||
jpc_fix_t *ilyrrates;
|
||||
|
||||
} jpc_enc_tcp_t;
|
||||
|
||||
/* Per tile-component coding parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The coding style (i.e., explicit precinct sizes). */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The maximum number of resolution levels allowed. */
|
||||
uint_fast8_t maxrlvls;
|
||||
|
||||
/* The exponent for the nominal code block width. */
|
||||
uint_fast16_t cblkwidthexpn;
|
||||
|
||||
/* The exponent for the nominal code block height. */
|
||||
uint_fast16_t cblkheightexpn;
|
||||
|
||||
/* The code block style parameters (e.g., lazy, terminate all,
|
||||
segmentation symbols, causal, reset probability models). */
|
||||
uint_fast8_t cblksty;
|
||||
|
||||
/* The QMFB. */
|
||||
uint_fast8_t qmfbid;
|
||||
|
||||
/* The precinct width values. */
|
||||
uint_fast16_t prcwidthexpns[JPC_MAXRLVLS];
|
||||
|
||||
/* The precinct height values. */
|
||||
uint_fast16_t prcheightexpns[JPC_MAXRLVLS];
|
||||
|
||||
/* The number of guard bits. */
|
||||
uint_fast8_t numgbits;
|
||||
|
||||
} jpc_enc_tccp_t;
|
||||
|
||||
/* Coding parameters. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The debug level. */
|
||||
int debug;
|
||||
|
||||
/* The horizontal offset from the origin of the reference grid to the
|
||||
left edge of the image area. */
|
||||
uint_fast32_t imgareatlx;
|
||||
|
||||
/* The vertical offset from the origin of the reference grid to the
|
||||
top edge of the image area. */
|
||||
uint_fast32_t imgareatly;
|
||||
|
||||
/* The horizontal offset from the origin of the reference grid to the
|
||||
right edge of the image area (plus one). */
|
||||
uint_fast32_t refgrdwidth;
|
||||
|
||||
/* The vertical offset from the origin of the reference grid to the
|
||||
bottom edge of the image area (plus one). */
|
||||
uint_fast32_t refgrdheight;
|
||||
|
||||
/* The horizontal offset from the origin of the tile grid to the
|
||||
origin of the reference grid. */
|
||||
uint_fast32_t tilegrdoffx;
|
||||
|
||||
/* The vertical offset from the origin of the tile grid to the
|
||||
origin of the reference grid. */
|
||||
uint_fast32_t tilegrdoffy;
|
||||
|
||||
/* The nominal tile width in units of the image reference grid. */
|
||||
uint_fast32_t tilewidth;
|
||||
|
||||
/* The nominal tile height in units of the image reference grid. */
|
||||
uint_fast32_t tileheight;
|
||||
|
||||
/* The number of tiles spanning the image area in the horizontal
|
||||
direction. */
|
||||
uint_fast32_t numhtiles;
|
||||
|
||||
/* The number of tiles spanning the image area in the vertical
|
||||
direction. */
|
||||
uint_fast32_t numvtiles;
|
||||
|
||||
/* The number of tiles. */
|
||||
uint_fast32_t numtiles;
|
||||
|
||||
/* The number of components. */
|
||||
uint_fast16_t numcmpts;
|
||||
|
||||
/* The per-component coding parameters. */
|
||||
jpc_enc_ccp_t *ccps;
|
||||
|
||||
/* The per-tile coding parameters. */
|
||||
jpc_enc_tcp_t tcp;
|
||||
|
||||
/* The per-tile-component coding parameters. */
|
||||
jpc_enc_tccp_t tccp;
|
||||
|
||||
/* The target code stream length in bytes. */
|
||||
uint_fast32_t totalsize;
|
||||
|
||||
/* The raw (i.e., uncompressed) size of the image in bytes. */
|
||||
uint_fast32_t rawsize;
|
||||
|
||||
} jpc_enc_cp_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Encoder class.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encoder per-coding-pass state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The starting offset for this pass. */
|
||||
int start;
|
||||
|
||||
/* The ending offset for this pass. */
|
||||
int end;
|
||||
|
||||
/* The type of data in this pass (i.e., MQ or raw). */
|
||||
int type;
|
||||
|
||||
/* Flag indicating that this pass is terminated. */
|
||||
int term;
|
||||
|
||||
/* The entropy coder state after coding this pass. */
|
||||
jpc_mqencstate_t mqencstate;
|
||||
|
||||
/* The layer to which this pass has been assigned. */
|
||||
int lyrno;
|
||||
|
||||
/* The R-D slope for this pass. */
|
||||
jpc_flt_t rdslope;
|
||||
|
||||
/* The weighted MSE reduction associated with this pass. */
|
||||
jpc_flt_t wmsedec;
|
||||
|
||||
/* The cumulative weighted MSE reduction. */
|
||||
jpc_flt_t cumwmsedec;
|
||||
|
||||
/* The normalized MSE reduction. */
|
||||
long nmsedec;
|
||||
|
||||
} jpc_enc_pass_t;
|
||||
|
||||
/* Encoder per-code-block state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of passes. */
|
||||
int numpasses;
|
||||
|
||||
/* The per-pass information. */
|
||||
jpc_enc_pass_t *passes;
|
||||
|
||||
/* The number of passes encoded so far. */
|
||||
int numencpasses;
|
||||
|
||||
/* The number of insignificant MSBs. */
|
||||
int numimsbs;
|
||||
|
||||
/* The number of bits used to encode pass data lengths. */
|
||||
int numlenbits;
|
||||
|
||||
/* The byte stream for this code block. */
|
||||
jas_stream_t *stream;
|
||||
|
||||
/* The entropy encoder. */
|
||||
jpc_mqenc_t *mqenc;
|
||||
|
||||
/* The data for this code block. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
/* The state for this code block. */
|
||||
jas_matrix_t *flags;
|
||||
|
||||
/* The number of bit planes required for this code block. */
|
||||
int numbps;
|
||||
|
||||
/* The next pass to be encoded. */
|
||||
jpc_enc_pass_t *curpass;
|
||||
|
||||
/* The per-code-block-group state information. */
|
||||
struct jpc_enc_prc_s *prc;
|
||||
|
||||
/* The saved current pass. */
|
||||
/* This is used by the rate control code. */
|
||||
jpc_enc_pass_t *savedcurpass;
|
||||
|
||||
/* The saved length indicator size. */
|
||||
/* This is used by the rate control code. */
|
||||
int savednumlenbits;
|
||||
|
||||
/* The saved number of encoded passes. */
|
||||
/* This is used by the rate control code. */
|
||||
int savednumencpasses;
|
||||
|
||||
} jpc_enc_cblk_t;
|
||||
|
||||
/* Encoder per-code-block-group state information. */
|
||||
|
||||
typedef struct jpc_enc_prc_s {
|
||||
|
||||
/* The x-coordinate of the top-left corner of the precinct. */
|
||||
uint_fast32_t tlx;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the precinct. */
|
||||
uint_fast32_t tly;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the precinct
|
||||
(plus one). */
|
||||
uint_fast32_t brx;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the precinct
|
||||
(plus one). */
|
||||
uint_fast32_t bry;
|
||||
|
||||
/* The number of code blocks spanning the precinct in the horizontal
|
||||
direction. */
|
||||
int numhcblks;
|
||||
|
||||
/* The number of code blocks spanning the precinct in the vertical
|
||||
direction. */
|
||||
int numvcblks;
|
||||
|
||||
/* The total number of code blocks. */
|
||||
int numcblks;
|
||||
|
||||
/* The per-code-block information. */
|
||||
jpc_enc_cblk_t *cblks;
|
||||
|
||||
/* The inclusion tag tree. */
|
||||
jpc_tagtree_t *incltree;
|
||||
|
||||
/* The insignifcant MSBs tag tree. */
|
||||
jpc_tagtree_t *nlibtree;
|
||||
|
||||
/* The per-band information. */
|
||||
struct jpc_enc_band_s *band;
|
||||
|
||||
/* The saved inclusion tag tree. */
|
||||
/* This is used by rate control. */
|
||||
jpc_tagtree_t *savincltree;
|
||||
|
||||
/* The saved leading-insignificant-bit-planes tag tree. */
|
||||
/* This is used by rate control. */
|
||||
jpc_tagtree_t *savnlibtree;
|
||||
|
||||
} jpc_enc_prc_t;
|
||||
|
||||
/* Encoder per-band state information. */
|
||||
|
||||
typedef struct jpc_enc_band_s {
|
||||
|
||||
/* The per precinct information. */
|
||||
jpc_enc_prc_t *prcs;
|
||||
|
||||
/* The coefficient data for this band. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
/* The orientation of this band (i.e., LL, LH, HL, or HH). */
|
||||
int orient;
|
||||
|
||||
/* The number of bit planes associated with this band. */
|
||||
int numbps;
|
||||
|
||||
/* The quantizer step size. */
|
||||
jpc_fix_t absstepsize;
|
||||
|
||||
/* The encoded quantizer step size. */
|
||||
int stepsize;
|
||||
|
||||
/* The L2 norm of the synthesis basis functions associated with
|
||||
this band. (The MCT is not considered in this value.) */
|
||||
jpc_fix_t synweight;
|
||||
|
||||
/* The analysis gain for this band. */
|
||||
int analgain;
|
||||
|
||||
/* The per-resolution-level information. */
|
||||
struct jpc_enc_rlvl_s *rlvl;
|
||||
|
||||
} jpc_enc_band_t;
|
||||
|
||||
/* Encoder per-resolution-level state information. */
|
||||
|
||||
typedef struct jpc_enc_rlvl_s {
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile-component
|
||||
at this resolution. */
|
||||
uint_fast32_t tlx;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile-component
|
||||
at this resolution. */
|
||||
uint_fast32_t tly;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile-component
|
||||
at this resolution (plus one). */
|
||||
uint_fast32_t brx;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile-component
|
||||
at this resolution (plus one). */
|
||||
uint_fast32_t bry;
|
||||
|
||||
/* The exponent value for the nominal precinct width measured
|
||||
relative to the associated LL band. */
|
||||
int prcwidthexpn;
|
||||
|
||||
/* The exponent value for the nominal precinct height measured
|
||||
relative to the associated LL band. */
|
||||
int prcheightexpn;
|
||||
|
||||
/* The number of precincts spanning the resolution level in the
|
||||
horizontal direction. */
|
||||
int numhprcs;
|
||||
|
||||
/* The number of precincts spanning the resolution level in the
|
||||
vertical direction. */
|
||||
int numvprcs;
|
||||
|
||||
/* The total number of precincts. */
|
||||
int numprcs;
|
||||
|
||||
/* The exponent value for the nominal code block group width.
|
||||
This quantity is associated with the next lower resolution level
|
||||
(assuming that there is one). */
|
||||
int cbgwidthexpn;
|
||||
|
||||
/* The exponent value for the nominal code block group height.
|
||||
This quantity is associated with the next lower resolution level
|
||||
(assuming that there is one). */
|
||||
int cbgheightexpn;
|
||||
|
||||
/* The exponent value for the code block width. */
|
||||
uint_fast16_t cblkwidthexpn;
|
||||
|
||||
/* The exponent value for the code block height. */
|
||||
uint_fast16_t cblkheightexpn;
|
||||
|
||||
/* The number of bands associated with this resolution level. */
|
||||
int numbands;
|
||||
|
||||
/* The per-band information. */
|
||||
jpc_enc_band_t *bands;
|
||||
|
||||
/* The parent tile-component. */
|
||||
struct jpc_enc_tcmpt_s *tcmpt;
|
||||
|
||||
} jpc_enc_rlvl_t;
|
||||
|
||||
/* Encoder per-tile-component state information. */
|
||||
|
||||
typedef struct jpc_enc_tcmpt_s {
|
||||
|
||||
/* The number of resolution levels. */
|
||||
int numrlvls;
|
||||
|
||||
/* The per-resolution-level information. */
|
||||
jpc_enc_rlvl_t *rlvls;
|
||||
|
||||
/* The tile-component data. */
|
||||
jas_matrix_t *data;
|
||||
|
||||
/* The QMFB. */
|
||||
int qmfbid;
|
||||
|
||||
/* The number of bands. */
|
||||
int numbands;
|
||||
|
||||
/* The TSFB. */
|
||||
jpc_tsfb_t *tsfb;
|
||||
|
||||
/* The synthesis energy weight (for the MCT). */
|
||||
jpc_fix_t synweight;
|
||||
|
||||
/* The precinct width exponents. */
|
||||
int prcwidthexpns[JPC_MAXRLVLS];
|
||||
|
||||
/* The precinct height exponents. */
|
||||
int prcheightexpns[JPC_MAXRLVLS];
|
||||
|
||||
/* The code block width exponent. */
|
||||
int cblkwidthexpn;
|
||||
|
||||
/* The code block height exponent. */
|
||||
int cblkheightexpn;
|
||||
|
||||
/* Coding style (i.e., explicit precinct sizes). */
|
||||
int csty;
|
||||
|
||||
/* Code block style. */
|
||||
int cblksty;
|
||||
|
||||
/* The number of quantizer step sizes. */
|
||||
int numstepsizes;
|
||||
|
||||
/* The encoded quantizer step sizes. */
|
||||
uint_fast16_t stepsizes[JPC_MAXBANDS];
|
||||
|
||||
/* The parent tile. */
|
||||
struct jpc_enc_tile_s *tile;
|
||||
|
||||
} jpc_enc_tcmpt_t;
|
||||
|
||||
/* Encoder per-tile state information. */
|
||||
|
||||
typedef struct jpc_enc_tile_s {
|
||||
|
||||
/* The tile number. */
|
||||
uint_fast32_t tileno;
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile measured with
|
||||
respect to the reference grid. */
|
||||
uint_fast32_t tlx;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile measured with
|
||||
respect to the reference grid. */
|
||||
uint_fast32_t tly;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile measured
|
||||
with respect to the reference grid (plus one). */
|
||||
uint_fast32_t brx;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile measured
|
||||
with respect to the reference grid (plus one). */
|
||||
uint_fast32_t bry;
|
||||
|
||||
/* The coding style. */
|
||||
uint_fast8_t csty;
|
||||
|
||||
/* The progression order. */
|
||||
uint_fast8_t prg;
|
||||
|
||||
/* The number of layers. */
|
||||
int numlyrs;
|
||||
|
||||
/* The MCT to employ (if any). */
|
||||
uint_fast8_t mctid;
|
||||
|
||||
/* The packet iterator (used to determine the order of packet
|
||||
generation). */
|
||||
jpc_pi_t *pi;
|
||||
|
||||
/* The coding mode (i.e., integer or real). */
|
||||
bool intmode;
|
||||
|
||||
/* The number of bytes to allocate to the various layers. */
|
||||
uint_fast32_t *lyrsizes;
|
||||
|
||||
/* The number of tile-components. */
|
||||
int numtcmpts;
|
||||
|
||||
/* The per tile-component information. */
|
||||
jpc_enc_tcmpt_t *tcmpts;
|
||||
|
||||
/* The raw (i.e., uncompressed) size of this tile. */
|
||||
uint_fast32_t rawsize;
|
||||
|
||||
} jpc_enc_tile_t;
|
||||
|
||||
/* Encoder class. */
|
||||
|
||||
typedef struct jpc_enc_s {
|
||||
|
||||
/* The image being encoded. */
|
||||
jas_image_t *image;
|
||||
|
||||
/* The output stream. */
|
||||
jas_stream_t *out;
|
||||
|
||||
/* The coding parameters. */
|
||||
jpc_enc_cp_t *cp;
|
||||
|
||||
/* The tile currently being processed. */
|
||||
jpc_enc_tile_t *curtile;
|
||||
|
||||
/* The code stream state. */
|
||||
jpc_cstate_t *cstate;
|
||||
|
||||
/* The number of bytes output so far. */
|
||||
uint_fast32_t len;
|
||||
|
||||
/* The number of bytes available for the main body of the code stream. */
|
||||
/* This is used for rate allocation purposes. */
|
||||
uint_fast32_t mainbodysize;
|
||||
|
||||
/* The marker segment currently being processed. */
|
||||
/* This member is a convenience for making cleanup easier. */
|
||||
jpc_ms_t *mrk;
|
||||
|
||||
/* The stream used to temporarily hold tile-part data. */
|
||||
jas_stream_t *tmpstream;
|
||||
|
||||
} jpc_enc_t;
|
||||
|
||||
#endif
|
||||
Vendored
+144
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Fixed-Point Number Class
|
||||
*
|
||||
* $Id: jpc_fix.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_FIX_H
|
||||
#define JPC_FIX_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_fix.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Basic parameters of the fixed-point type.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The integral type used to represent a fixed-point number. This
|
||||
type must be capable of representing values from -(2^31) to 2^31-1
|
||||
(inclusive). */
|
||||
typedef int_fast32_t jpc_fix_t;
|
||||
|
||||
/* The integral type used to respresent higher-precision intermediate results.
|
||||
This type should be capable of representing values from -(2^63) to 2^63-1
|
||||
(inclusive). */
|
||||
typedef int_fast64_t jpc_fix_big_t;
|
||||
|
||||
/* The number of bits used for the fractional part of a fixed-point number. */
|
||||
#define JPC_FIX_FRACBITS 13
|
||||
|
||||
/******************************************************************************\
|
||||
* Instantiations of the generic fixed-point number macros for the
|
||||
* parameters given above. (Too bad C does not support templates, eh?)
|
||||
* The purpose of these macros is self-evident if one examines the
|
||||
* corresponding macros in the jasper/jas_fix.h header file.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JPC_FIX_ZERO JAS_FIX_ZERO(jpc_fix_t, JPC_FIX_FRACBITS)
|
||||
#define JPC_FIX_ONE JAS_FIX_ONE(jpc_fix_t, JPC_FIX_FRACBITS)
|
||||
#define JPC_FIX_HALF JAS_FIX_HALF(jpc_fix_t, JPC_FIX_FRACBITS)
|
||||
|
||||
#define jpc_inttofix(x) JAS_INTTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fixtoint(x) JAS_FIXTOINT(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fixtodbl(x) JAS_FIXTODBL(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_dbltofix(x) JAS_DBLTOFIX(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
|
||||
#define jpc_fix_add(x, y) JAS_FIX_ADD(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
|
||||
#define jpc_fix_sub(x, y) JAS_FIX_SUB(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
|
||||
#define jpc_fix_mul(x, y) \
|
||||
JAS_FIX_MUL(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
|
||||
#define jpc_fix_mulbyint(x, y) \
|
||||
JAS_FIX_MULBYINT(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
|
||||
#define jpc_fix_div(x, y) \
|
||||
JAS_FIX_DIV(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
|
||||
#define jpc_fix_neg(x) JAS_FIX_NEG(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_asl(x, n) JAS_FIX_ASL(jpc_fix_t, JPC_FIX_FRACBITS, x, n)
|
||||
#define jpc_fix_asr(x, n) JAS_FIX_ASR(jpc_fix_t, JPC_FIX_FRACBITS, x, n)
|
||||
|
||||
#define jpc_fix_pluseq(x, y) JAS_FIX_PLUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
|
||||
#define jpc_fix_minuseq(x, y) JAS_FIX_MINUSEQ(jpc_fix_t, JPC_FIX_FRACBITS, x, y)
|
||||
#define jpc_fix_muleq(x, y) \
|
||||
JAS_FIX_MULEQ(jpc_fix_t, JPC_FIX_FRACBITS, jpc_fix_big_t, x, y)
|
||||
|
||||
#define jpc_fix_abs(x) JAS_FIX_ABS(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_isint(x) JAS_FIX_ISINT(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_sgn(x) JAS_FIX_SGN(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_round(x) JAS_FIX_ROUND(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_floor(x) JAS_FIX_FLOOR(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
#define jpc_fix_trunc(x) JAS_FIX_TRUNC(jpc_fix_t, JPC_FIX_FRACBITS, x)
|
||||
|
||||
/******************************************************************************\
|
||||
* Extra macros for convenience.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Compute the sum of three fixed-point numbers. */
|
||||
#define jpc_fix_add3(x, y, z) jpc_fix_add(jpc_fix_add(x, y), z)
|
||||
|
||||
#endif
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Floating-Point Class
|
||||
*
|
||||
* $Id: jpc_flt.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_FLT_H
|
||||
#define JPC_FLT_H
|
||||
|
||||
#include <float.h>
|
||||
|
||||
/* The code ought to be modified so this type is not used at all. */
|
||||
/* Very few places in the code rely on floating-point arithmetic, aside
|
||||
from conversions in printf's. */
|
||||
typedef double jpc_flt_t;
|
||||
|
||||
#endif
|
||||
Vendored
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Math Library
|
||||
*
|
||||
* $Id: jpc_math.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jpc_math.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous Functions
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the integer quantity floor(log2(x)), where x is a positive
|
||||
integer. */
|
||||
int jpc_floorlog2(int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* The argument must be positive. */
|
||||
assert(x > 0);
|
||||
|
||||
y = 0;
|
||||
while (x > 1) {
|
||||
x >>= 1;
|
||||
++y;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
/* Calculate the bit position of the first leading one in a nonnegative
|
||||
integer. */
|
||||
/* This function is the basically the same as ceillog2(x), except that the
|
||||
allowable range for x is slightly different. */
|
||||
int jpc_firstone(int x)
|
||||
{
|
||||
int n;
|
||||
|
||||
/* The argument must be nonnegative. */
|
||||
assert(x >= 0);
|
||||
|
||||
n = -1;
|
||||
while (x > 0) {
|
||||
x >>= 1;
|
||||
++n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
Vendored
+99
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JPC_MATH_H
|
||||
#define JPC_MATH_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros
|
||||
\******************************************************************************/
|
||||
|
||||
/* Compute the floor of the quotient of two integers. */
|
||||
#define JPC_FLOORDIV(x, y) ((x) / (y))
|
||||
|
||||
/* Compute the ceiling of the quotient of two integers. */
|
||||
#define JPC_CEILDIV(x, y) (((x) + (y) - 1) / (y))
|
||||
|
||||
/* Compute the floor of (x / 2^y). */
|
||||
#define JPC_FLOORDIVPOW2(x, y) ((x) >> (y))
|
||||
|
||||
/* Compute the ceiling of (x / 2^y). */
|
||||
#define JPC_CEILDIVPOW2(x, y) (((x) + (1 << (y)) - 1) >> (y))
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the bit position of the first leading one in a nonnegative
|
||||
integer. */
|
||||
int jpc_firstone(int x);
|
||||
|
||||
/* Calculate the integer quantity floor(log2(x)), where x is a positive
|
||||
integer. */
|
||||
int jpc_floorlog2(int x);
|
||||
|
||||
#endif
|
||||
Vendored
+291
@@ -0,0 +1,291 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Multicomponent Transform Code
|
||||
*
|
||||
* $Id: jpc_mct.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
#include "jpc_fix.h"
|
||||
#include "jpc_mct.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Compute the forward RCT. */
|
||||
|
||||
void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
|
||||
{
|
||||
int numrows;
|
||||
int numcols;
|
||||
int i;
|
||||
int j;
|
||||
jpc_fix_t *c0p;
|
||||
jpc_fix_t *c1p;
|
||||
jpc_fix_t *c2p;
|
||||
|
||||
numrows = jas_matrix_numrows(c0);
|
||||
numcols = jas_matrix_numcols(c0);
|
||||
|
||||
/* All three matrices must have the same dimensions. */
|
||||
assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
|
||||
&& jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
|
||||
|
||||
for (i = 0; i < numrows; i++) {
|
||||
c0p = jas_matrix_getref(c0, i, 0);
|
||||
c1p = jas_matrix_getref(c1, i, 0);
|
||||
c2p = jas_matrix_getref(c2, i, 0);
|
||||
for (j = numcols; j > 0; --j) {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int y;
|
||||
int u;
|
||||
int v;
|
||||
r = *c0p;
|
||||
g = *c1p;
|
||||
b = *c2p;
|
||||
y = (r + (g << 1) + b) >> 2;
|
||||
u = b - g;
|
||||
v = r - g;
|
||||
*c0p++ = y;
|
||||
*c1p++ = u;
|
||||
*c2p++ = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute the inverse RCT. */
|
||||
|
||||
void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
|
||||
{
|
||||
int numrows;
|
||||
int numcols;
|
||||
int i;
|
||||
int j;
|
||||
jpc_fix_t *c0p;
|
||||
jpc_fix_t *c1p;
|
||||
jpc_fix_t *c2p;
|
||||
|
||||
numrows = jas_matrix_numrows(c0);
|
||||
numcols = jas_matrix_numcols(c0);
|
||||
|
||||
/* All three matrices must have the same dimensions. */
|
||||
assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numcols(c1) == numcols
|
||||
&& jas_matrix_numrows(c2) == numrows && jas_matrix_numcols(c2) == numcols);
|
||||
|
||||
for (i = 0; i < numrows; i++) {
|
||||
c0p = jas_matrix_getref(c0, i, 0);
|
||||
c1p = jas_matrix_getref(c1, i, 0);
|
||||
c2p = jas_matrix_getref(c2, i, 0);
|
||||
for (j = numcols; j > 0; --j) {
|
||||
int r;
|
||||
int g;
|
||||
int b;
|
||||
int y;
|
||||
int u;
|
||||
int v;
|
||||
y = *c0p;
|
||||
u = *c1p;
|
||||
v = *c2p;
|
||||
g = y - ((u + v) >> 2);
|
||||
r = v + g;
|
||||
b = u + g;
|
||||
*c0p++ = r;
|
||||
*c1p++ = g;
|
||||
*c2p++ = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
|
||||
{
|
||||
int numrows;
|
||||
int numcols;
|
||||
int i;
|
||||
int j;
|
||||
jpc_fix_t r;
|
||||
jpc_fix_t g;
|
||||
jpc_fix_t b;
|
||||
jpc_fix_t y;
|
||||
jpc_fix_t u;
|
||||
jpc_fix_t v;
|
||||
jpc_fix_t *c0p;
|
||||
jpc_fix_t *c1p;
|
||||
jpc_fix_t *c2p;
|
||||
|
||||
numrows = jas_matrix_numrows(c0);
|
||||
assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
|
||||
numcols = jas_matrix_numcols(c0);
|
||||
assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
|
||||
for (i = 0; i < numrows; ++i) {
|
||||
c0p = jas_matrix_getref(c0, i, 0);
|
||||
c1p = jas_matrix_getref(c1, i, 0);
|
||||
c2p = jas_matrix_getref(c2, i, 0);
|
||||
for (j = numcols; j > 0; --j) {
|
||||
r = *c0p;
|
||||
g = *c1p;
|
||||
b = *c2p;
|
||||
y = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.299), r), jpc_fix_mul(jpc_dbltofix(0.587), g),
|
||||
jpc_fix_mul(jpc_dbltofix(0.114), b));
|
||||
u = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(-0.16875), r), jpc_fix_mul(jpc_dbltofix(-0.33126), g),
|
||||
jpc_fix_mul(jpc_dbltofix(0.5), b));
|
||||
v = jpc_fix_add3(jpc_fix_mul(jpc_dbltofix(0.5), r), jpc_fix_mul(jpc_dbltofix(-0.41869), g),
|
||||
jpc_fix_mul(jpc_dbltofix(-0.08131), b));
|
||||
*c0p++ = y;
|
||||
*c1p++ = u;
|
||||
*c2p++ = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2)
|
||||
{
|
||||
int numrows;
|
||||
int numcols;
|
||||
int i;
|
||||
int j;
|
||||
jpc_fix_t r;
|
||||
jpc_fix_t g;
|
||||
jpc_fix_t b;
|
||||
jpc_fix_t y;
|
||||
jpc_fix_t u;
|
||||
jpc_fix_t v;
|
||||
jpc_fix_t *c0p;
|
||||
jpc_fix_t *c1p;
|
||||
jpc_fix_t *c2p;
|
||||
|
||||
numrows = jas_matrix_numrows(c0);
|
||||
assert(jas_matrix_numrows(c1) == numrows && jas_matrix_numrows(c2) == numrows);
|
||||
numcols = jas_matrix_numcols(c0);
|
||||
assert(jas_matrix_numcols(c1) == numcols && jas_matrix_numcols(c2) == numcols);
|
||||
for (i = 0; i < numrows; ++i) {
|
||||
c0p = jas_matrix_getref(c0, i, 0);
|
||||
c1p = jas_matrix_getref(c1, i, 0);
|
||||
c2p = jas_matrix_getref(c2, i, 0);
|
||||
for (j = numcols; j > 0; --j) {
|
||||
y = *c0p;
|
||||
u = *c1p;
|
||||
v = *c2p;
|
||||
r = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.402), v));
|
||||
g = jpc_fix_add3(y, jpc_fix_mul(jpc_dbltofix(-0.34413), u),
|
||||
jpc_fix_mul(jpc_dbltofix(-0.71414), v));
|
||||
b = jpc_fix_add(y, jpc_fix_mul(jpc_dbltofix(1.772), u));
|
||||
*c0p++ = r;
|
||||
*c1p++ = g;
|
||||
*c2p++ = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno)
|
||||
{
|
||||
jpc_fix_t synweight;
|
||||
|
||||
synweight = JPC_FIX_ONE;
|
||||
switch (mctid) {
|
||||
case JPC_MCT_RCT:
|
||||
switch (cmptno) {
|
||||
case 0:
|
||||
synweight = jpc_dbltofix(sqrt(3.0));
|
||||
break;
|
||||
case 1:
|
||||
synweight = jpc_dbltofix(sqrt(0.6875));
|
||||
break;
|
||||
case 2:
|
||||
synweight = jpc_dbltofix(sqrt(0.6875));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case JPC_MCT_ICT:
|
||||
switch (cmptno) {
|
||||
case 0:
|
||||
synweight = jpc_dbltofix(sqrt(3.0000));
|
||||
break;
|
||||
case 1:
|
||||
synweight = jpc_dbltofix(sqrt(3.2584));
|
||||
break;
|
||||
case 2:
|
||||
synweight = jpc_dbltofix(sqrt(2.4755));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#if 0
|
||||
default:
|
||||
synweight = JPC_FIX_ONE;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return synweight;
|
||||
}
|
||||
Vendored
+111
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Multicomponent Transform Code
|
||||
*
|
||||
* $Id: jpc_mct.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_MCT_H
|
||||
#define JPC_MCT_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
#include "jasper/jas_fix.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Multicomponent transform IDs.
|
||||
*/
|
||||
|
||||
#define JPC_MCT_NONE 0
|
||||
#define JPC_MCT_ICT 1
|
||||
#define JPC_MCT_RCT 2
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Calculate the forward RCT. */
|
||||
void jpc_rct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
|
||||
|
||||
/* Calculate the inverse RCT. */
|
||||
void jpc_irct(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
|
||||
|
||||
/* Calculate the forward ICT. */
|
||||
void jpc_ict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
|
||||
|
||||
/* Calculate the inverse ICT. */
|
||||
void jpc_iict(jas_matrix_t *c0, jas_matrix_t *c1, jas_matrix_t *c2);
|
||||
|
||||
/* Get the synthesis weight associated with a particular component. */
|
||||
jpc_fix_t jpc_mct_getsynweight(int mctid, int cmptno);
|
||||
|
||||
#endif
|
||||
Vendored
+179
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Coder
|
||||
*
|
||||
* $Id: jpc_mqcod.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
|
||||
#include "jpc_mqcod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Data.
|
||||
\******************************************************************************/
|
||||
|
||||
/* MQ coder per-state information. */
|
||||
|
||||
jpc_mqstate_t jpc_mqstates[47 * 2] = {
|
||||
{0x5601, 0, &jpc_mqstates[ 2], &jpc_mqstates[ 3]},
|
||||
{0x5601, 1, &jpc_mqstates[ 3], &jpc_mqstates[ 2]},
|
||||
{0x3401, 0, &jpc_mqstates[ 4], &jpc_mqstates[12]},
|
||||
{0x3401, 1, &jpc_mqstates[ 5], &jpc_mqstates[13]},
|
||||
{0x1801, 0, &jpc_mqstates[ 6], &jpc_mqstates[18]},
|
||||
{0x1801, 1, &jpc_mqstates[ 7], &jpc_mqstates[19]},
|
||||
{0x0ac1, 0, &jpc_mqstates[ 8], &jpc_mqstates[24]},
|
||||
{0x0ac1, 1, &jpc_mqstates[ 9], &jpc_mqstates[25]},
|
||||
{0x0521, 0, &jpc_mqstates[10], &jpc_mqstates[58]},
|
||||
{0x0521, 1, &jpc_mqstates[11], &jpc_mqstates[59]},
|
||||
{0x0221, 0, &jpc_mqstates[76], &jpc_mqstates[66]},
|
||||
{0x0221, 1, &jpc_mqstates[77], &jpc_mqstates[67]},
|
||||
{0x5601, 0, &jpc_mqstates[14], &jpc_mqstates[13]},
|
||||
{0x5601, 1, &jpc_mqstates[15], &jpc_mqstates[12]},
|
||||
{0x5401, 0, &jpc_mqstates[16], &jpc_mqstates[28]},
|
||||
{0x5401, 1, &jpc_mqstates[17], &jpc_mqstates[29]},
|
||||
{0x4801, 0, &jpc_mqstates[18], &jpc_mqstates[28]},
|
||||
{0x4801, 1, &jpc_mqstates[19], &jpc_mqstates[29]},
|
||||
{0x3801, 0, &jpc_mqstates[20], &jpc_mqstates[28]},
|
||||
{0x3801, 1, &jpc_mqstates[21], &jpc_mqstates[29]},
|
||||
{0x3001, 0, &jpc_mqstates[22], &jpc_mqstates[34]},
|
||||
{0x3001, 1, &jpc_mqstates[23], &jpc_mqstates[35]},
|
||||
{0x2401, 0, &jpc_mqstates[24], &jpc_mqstates[36]},
|
||||
{0x2401, 1, &jpc_mqstates[25], &jpc_mqstates[37]},
|
||||
{0x1c01, 0, &jpc_mqstates[26], &jpc_mqstates[40]},
|
||||
{0x1c01, 1, &jpc_mqstates[27], &jpc_mqstates[41]},
|
||||
{0x1601, 0, &jpc_mqstates[58], &jpc_mqstates[42]},
|
||||
{0x1601, 1, &jpc_mqstates[59], &jpc_mqstates[43]},
|
||||
{0x5601, 0, &jpc_mqstates[30], &jpc_mqstates[29]},
|
||||
{0x5601, 1, &jpc_mqstates[31], &jpc_mqstates[28]},
|
||||
{0x5401, 0, &jpc_mqstates[32], &jpc_mqstates[28]},
|
||||
{0x5401, 1, &jpc_mqstates[33], &jpc_mqstates[29]},
|
||||
{0x5101, 0, &jpc_mqstates[34], &jpc_mqstates[30]},
|
||||
{0x5101, 1, &jpc_mqstates[35], &jpc_mqstates[31]},
|
||||
{0x4801, 0, &jpc_mqstates[36], &jpc_mqstates[32]},
|
||||
{0x4801, 1, &jpc_mqstates[37], &jpc_mqstates[33]},
|
||||
{0x3801, 0, &jpc_mqstates[38], &jpc_mqstates[34]},
|
||||
{0x3801, 1, &jpc_mqstates[39], &jpc_mqstates[35]},
|
||||
{0x3401, 0, &jpc_mqstates[40], &jpc_mqstates[36]},
|
||||
{0x3401, 1, &jpc_mqstates[41], &jpc_mqstates[37]},
|
||||
{0x3001, 0, &jpc_mqstates[42], &jpc_mqstates[38]},
|
||||
{0x3001, 1, &jpc_mqstates[43], &jpc_mqstates[39]},
|
||||
{0x2801, 0, &jpc_mqstates[44], &jpc_mqstates[38]},
|
||||
{0x2801, 1, &jpc_mqstates[45], &jpc_mqstates[39]},
|
||||
{0x2401, 0, &jpc_mqstates[46], &jpc_mqstates[40]},
|
||||
{0x2401, 1, &jpc_mqstates[47], &jpc_mqstates[41]},
|
||||
{0x2201, 0, &jpc_mqstates[48], &jpc_mqstates[42]},
|
||||
{0x2201, 1, &jpc_mqstates[49], &jpc_mqstates[43]},
|
||||
{0x1c01, 0, &jpc_mqstates[50], &jpc_mqstates[44]},
|
||||
{0x1c01, 1, &jpc_mqstates[51], &jpc_mqstates[45]},
|
||||
{0x1801, 0, &jpc_mqstates[52], &jpc_mqstates[46]},
|
||||
{0x1801, 1, &jpc_mqstates[53], &jpc_mqstates[47]},
|
||||
{0x1601, 0, &jpc_mqstates[54], &jpc_mqstates[48]},
|
||||
{0x1601, 1, &jpc_mqstates[55], &jpc_mqstates[49]},
|
||||
{0x1401, 0, &jpc_mqstates[56], &jpc_mqstates[50]},
|
||||
{0x1401, 1, &jpc_mqstates[57], &jpc_mqstates[51]},
|
||||
{0x1201, 0, &jpc_mqstates[58], &jpc_mqstates[52]},
|
||||
{0x1201, 1, &jpc_mqstates[59], &jpc_mqstates[53]},
|
||||
{0x1101, 0, &jpc_mqstates[60], &jpc_mqstates[54]},
|
||||
{0x1101, 1, &jpc_mqstates[61], &jpc_mqstates[55]},
|
||||
{0x0ac1, 0, &jpc_mqstates[62], &jpc_mqstates[56]},
|
||||
{0x0ac1, 1, &jpc_mqstates[63], &jpc_mqstates[57]},
|
||||
{0x09c1, 0, &jpc_mqstates[64], &jpc_mqstates[58]},
|
||||
{0x09c1, 1, &jpc_mqstates[65], &jpc_mqstates[59]},
|
||||
{0x08a1, 0, &jpc_mqstates[66], &jpc_mqstates[60]},
|
||||
{0x08a1, 1, &jpc_mqstates[67], &jpc_mqstates[61]},
|
||||
{0x0521, 0, &jpc_mqstates[68], &jpc_mqstates[62]},
|
||||
{0x0521, 1, &jpc_mqstates[69], &jpc_mqstates[63]},
|
||||
{0x0441, 0, &jpc_mqstates[70], &jpc_mqstates[64]},
|
||||
{0x0441, 1, &jpc_mqstates[71], &jpc_mqstates[65]},
|
||||
{0x02a1, 0, &jpc_mqstates[72], &jpc_mqstates[66]},
|
||||
{0x02a1, 1, &jpc_mqstates[73], &jpc_mqstates[67]},
|
||||
{0x0221, 0, &jpc_mqstates[74], &jpc_mqstates[68]},
|
||||
{0x0221, 1, &jpc_mqstates[75], &jpc_mqstates[69]},
|
||||
{0x0141, 0, &jpc_mqstates[76], &jpc_mqstates[70]},
|
||||
{0x0141, 1, &jpc_mqstates[77], &jpc_mqstates[71]},
|
||||
{0x0111, 0, &jpc_mqstates[78], &jpc_mqstates[72]},
|
||||
{0x0111, 1, &jpc_mqstates[79], &jpc_mqstates[73]},
|
||||
{0x0085, 0, &jpc_mqstates[80], &jpc_mqstates[74]},
|
||||
{0x0085, 1, &jpc_mqstates[81], &jpc_mqstates[75]},
|
||||
{0x0049, 0, &jpc_mqstates[82], &jpc_mqstates[76]},
|
||||
{0x0049, 1, &jpc_mqstates[83], &jpc_mqstates[77]},
|
||||
{0x0025, 0, &jpc_mqstates[84], &jpc_mqstates[78]},
|
||||
{0x0025, 1, &jpc_mqstates[85], &jpc_mqstates[79]},
|
||||
{0x0015, 0, &jpc_mqstates[86], &jpc_mqstates[80]},
|
||||
{0x0015, 1, &jpc_mqstates[87], &jpc_mqstates[81]},
|
||||
{0x0009, 0, &jpc_mqstates[88], &jpc_mqstates[82]},
|
||||
{0x0009, 1, &jpc_mqstates[89], &jpc_mqstates[83]},
|
||||
{0x0005, 0, &jpc_mqstates[90], &jpc_mqstates[84]},
|
||||
{0x0005, 1, &jpc_mqstates[91], &jpc_mqstates[85]},
|
||||
{0x0001, 0, &jpc_mqstates[90], &jpc_mqstates[86]},
|
||||
{0x0001, 1, &jpc_mqstates[91], &jpc_mqstates[87]},
|
||||
{0x5601, 0, &jpc_mqstates[92], &jpc_mqstates[92]},
|
||||
{0x5601, 1, &jpc_mqstates[93], &jpc_mqstates[93]},
|
||||
};
|
||||
Vendored
+124
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Coder
|
||||
*
|
||||
* $Id: jpc_mqcod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_MQCOD_H
|
||||
#define JPC_MQCOD_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* MQ coder context information.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The most probable symbol (MPS). */
|
||||
int mps;
|
||||
|
||||
/* The state index. */
|
||||
int_fast16_t ind;
|
||||
|
||||
} jpc_mqctx_t;
|
||||
|
||||
/*
|
||||
* MQ coder state table entry.
|
||||
*/
|
||||
|
||||
typedef struct jpc_mqstate_s {
|
||||
|
||||
/* The Qe value. */
|
||||
uint_fast16_t qeval;
|
||||
|
||||
/* The MPS. */
|
||||
int mps;
|
||||
|
||||
/* The NMPS state. */
|
||||
struct jpc_mqstate_s *nmps;
|
||||
|
||||
/* The NLPS state. */
|
||||
struct jpc_mqstate_s *nlps;
|
||||
|
||||
} jpc_mqstate_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Data.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The state table for the MQ coder. */
|
||||
extern jpc_mqstate_t jpc_mqstates[];
|
||||
|
||||
#endif
|
||||
Vendored
+306
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Decoder
|
||||
*
|
||||
* $Id: jpc_mqdec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jpc_mqdec.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Local macros.
|
||||
\******************************************************************************/
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define MQDEC_CALL(n, x) \
|
||||
((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0))
|
||||
#else
|
||||
#define MQDEC_CALL(n, x)
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Local function prototypes.
|
||||
\******************************************************************************/
|
||||
|
||||
static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for creation and destruction of a MQ decoder.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a MQ decoder. */
|
||||
jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in)
|
||||
{
|
||||
jpc_mqdec_t *mqdec;
|
||||
|
||||
/* There must be at least one context. */
|
||||
assert(maxctxs > 0);
|
||||
|
||||
/* Allocate memory for the MQ decoder. */
|
||||
if (!(mqdec = jas_malloc(sizeof(jpc_mqdec_t)))) {
|
||||
goto error;
|
||||
}
|
||||
mqdec->in = in;
|
||||
mqdec->maxctxs = maxctxs;
|
||||
/* Allocate memory for the per-context state information. */
|
||||
if (!(mqdec->ctxs = jas_alloc2(mqdec->maxctxs, sizeof(jpc_mqstate_t *)))) {
|
||||
goto error;
|
||||
}
|
||||
/* Set the current context to the first context. */
|
||||
mqdec->curctx = mqdec->ctxs;
|
||||
|
||||
/* If an input stream has been associated with the MQ decoder,
|
||||
initialize the decoder state from the stream. */
|
||||
if (mqdec->in) {
|
||||
jpc_mqdec_init(mqdec);
|
||||
}
|
||||
/* Initialize the per-context state information. */
|
||||
jpc_mqdec_setctxs(mqdec, 0, 0);
|
||||
|
||||
return mqdec;
|
||||
|
||||
error:
|
||||
/* Oops... Something has gone wrong. */
|
||||
if (mqdec) {
|
||||
jpc_mqdec_destroy(mqdec);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Destroy a MQ decoder. */
|
||||
void jpc_mqdec_destroy(jpc_mqdec_t *mqdec)
|
||||
{
|
||||
if (mqdec->ctxs) {
|
||||
jas_free(mqdec->ctxs);
|
||||
}
|
||||
jas_free(mqdec);
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for initialization of a MQ decoder.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Initialize the state of a MQ decoder. */
|
||||
|
||||
void jpc_mqdec_init(jpc_mqdec_t *mqdec)
|
||||
{
|
||||
int c;
|
||||
|
||||
mqdec->eof = 0;
|
||||
mqdec->creg = 0;
|
||||
/* Get the next byte from the input stream. */
|
||||
if ((c = jas_stream_getc(mqdec->in)) == EOF) {
|
||||
/* We have encountered an I/O error or EOF. */
|
||||
c = 0xff;
|
||||
mqdec->eof = 1;
|
||||
}
|
||||
mqdec->inbuffer = c;
|
||||
mqdec->creg += mqdec->inbuffer << 16;
|
||||
jpc_mqdec_bytein(mqdec);
|
||||
mqdec->creg <<= 7;
|
||||
mqdec->ctreg -= 7;
|
||||
mqdec->areg = 0x8000;
|
||||
}
|
||||
|
||||
/* Set the input stream for a MQ decoder. */
|
||||
|
||||
void jpc_mqdec_setinput(jpc_mqdec_t *mqdec, jas_stream_t *in)
|
||||
{
|
||||
mqdec->in = in;
|
||||
}
|
||||
|
||||
/* Initialize one or more contexts. */
|
||||
|
||||
void jpc_mqdec_setctxs(jpc_mqdec_t *mqdec, int numctxs, jpc_mqctx_t *ctxs)
|
||||
{
|
||||
jpc_mqstate_t **ctx;
|
||||
int n;
|
||||
|
||||
ctx = mqdec->ctxs;
|
||||
n = JAS_MIN(mqdec->maxctxs, numctxs);
|
||||
while (--n >= 0) {
|
||||
*ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps];
|
||||
++ctx;
|
||||
++ctxs;
|
||||
}
|
||||
n = mqdec->maxctxs - numctxs;
|
||||
while (--n >= 0) {
|
||||
*ctx = &jpc_mqstates[0];
|
||||
++ctx;
|
||||
}
|
||||
}
|
||||
|
||||
/* Initialize a context. */
|
||||
|
||||
void jpc_mqdec_setctx(jpc_mqdec_t *mqdec, int ctxno, jpc_mqctx_t *ctx)
|
||||
{
|
||||
jpc_mqstate_t **ctxi;
|
||||
ctxi = &mqdec->ctxs[ctxno];
|
||||
*ctxi = &jpc_mqstates[2 * ctx->ind + ctx->mps];
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for decoding a bit.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Decode a bit. */
|
||||
|
||||
int jpc_mqdec_getbit_func(register jpc_mqdec_t *mqdec)
|
||||
{
|
||||
int bit;
|
||||
JAS_DBGLOG(100, ("jpc_mqdec_getbit_func(%p)\n", mqdec));
|
||||
MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
|
||||
bit = jpc_mqdec_getbit_macro(mqdec);
|
||||
MQDEC_CALL(100, jpc_mqdec_dump(mqdec, stderr));
|
||||
JAS_DBGLOG(100, ("ctx = %d, decoded %d\n", mqdec->curctx -
|
||||
mqdec->ctxs, bit));
|
||||
return bit;
|
||||
}
|
||||
|
||||
/* Apply MPS_EXCHANGE algorithm (with RENORMD). */
|
||||
int jpc_mqdec_mpsexchrenormd(register jpc_mqdec_t *mqdec)
|
||||
{
|
||||
int ret;
|
||||
register jpc_mqstate_t *state = *mqdec->curctx;
|
||||
jpc_mqdec_mpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret);
|
||||
jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in,
|
||||
mqdec->eof, mqdec->inbuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Apply LPS_EXCHANGE algorithm (with RENORMD). */
|
||||
int jpc_mqdec_lpsexchrenormd(register jpc_mqdec_t *mqdec)
|
||||
{
|
||||
int ret;
|
||||
register jpc_mqstate_t *state = *mqdec->curctx;
|
||||
jpc_mqdec_lpsexchange(mqdec->areg, state->qeval, mqdec->curctx, ret);
|
||||
jpc_mqdec_renormd(mqdec->areg, mqdec->creg, mqdec->ctreg, mqdec->in,
|
||||
mqdec->eof, mqdec->inbuffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Support code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Apply the BYTEIN algorithm. */
|
||||
static void jpc_mqdec_bytein(jpc_mqdec_t *mqdec)
|
||||
{
|
||||
int c;
|
||||
unsigned char prevbuf;
|
||||
|
||||
if (!mqdec->eof) {
|
||||
if ((c = jas_stream_getc(mqdec->in)) == EOF) {
|
||||
mqdec->eof = 1;
|
||||
c = 0xff;
|
||||
}
|
||||
prevbuf = mqdec->inbuffer;
|
||||
mqdec->inbuffer = c;
|
||||
if (prevbuf == 0xff) {
|
||||
if (c > 0x8f) {
|
||||
mqdec->creg += 0xff00;
|
||||
mqdec->ctreg = 8;
|
||||
} else {
|
||||
mqdec->creg += c << 9;
|
||||
mqdec->ctreg = 7;
|
||||
}
|
||||
} else {
|
||||
mqdec->creg += c << 8;
|
||||
mqdec->ctreg = 8;
|
||||
}
|
||||
} else {
|
||||
mqdec->creg += 0xff00;
|
||||
mqdec->ctreg = 8;
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for debugging.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Dump a MQ decoder to a stream for debugging. */
|
||||
|
||||
void jpc_mqdec_dump(jpc_mqdec_t *mqdec, FILE *out)
|
||||
{
|
||||
fprintf(out, "MQDEC A = %08lx, C = %08lx, CT=%08lx, ",
|
||||
(unsigned long) mqdec->areg, (unsigned long) mqdec->creg,
|
||||
(unsigned long) mqdec->ctreg);
|
||||
fprintf(out, "CTX = %d, ", (int)(mqdec->curctx - mqdec->ctxs));
|
||||
fprintf(out, "IND %d, MPS %d, QEVAL %x\n", (int)(*mqdec->curctx -
|
||||
jpc_mqstates), (int)(*mqdec->curctx)->mps, (int)(*mqdec->curctx)->qeval);
|
||||
}
|
||||
Vendored
+271
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Decoder
|
||||
*
|
||||
* $Id: jpc_mqdec.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_MQDEC_H
|
||||
#define JPC_MQDEC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
#include "jpc_mqcod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* MQ arithmetic decoder. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The C register. */
|
||||
uint_fast32_t creg;
|
||||
|
||||
/* The A register. */
|
||||
uint_fast32_t areg;
|
||||
|
||||
/* The CT register. */
|
||||
uint_fast32_t ctreg;
|
||||
|
||||
/* The current context. */
|
||||
jpc_mqstate_t **curctx;
|
||||
|
||||
/* The per-context information. */
|
||||
jpc_mqstate_t **ctxs;
|
||||
|
||||
/* The maximum number of contexts. */
|
||||
int maxctxs;
|
||||
|
||||
/* The stream from which to read data. */
|
||||
jas_stream_t *in;
|
||||
|
||||
/* The last character read. */
|
||||
uchar inbuffer;
|
||||
|
||||
/* The EOF indicator. */
|
||||
int eof;
|
||||
|
||||
} jpc_mqdec_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for construction and destruction.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a MQ decoder. */
|
||||
jpc_mqdec_t *jpc_mqdec_create(int maxctxs, jas_stream_t *in);
|
||||
|
||||
/* Destroy a MQ decoder. */
|
||||
void jpc_mqdec_destroy(jpc_mqdec_t *dec);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for initialization.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Set the input stream associated with a MQ decoder. */
|
||||
void jpc_mqdec_setinput(jpc_mqdec_t *dec, jas_stream_t *in);
|
||||
|
||||
/* Initialize a MQ decoder. */
|
||||
void jpc_mqdec_init(jpc_mqdec_t *dec);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for manipulating contexts.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Set the current context for a MQ decoder. */
|
||||
#define jpc_mqdec_setcurctx(dec, ctxno) \
|
||||
((mqdec)->curctx = &(mqdec)->ctxs[ctxno]);
|
||||
|
||||
/* Set the state information for a particular context of a MQ decoder. */
|
||||
void jpc_mqdec_setctx(jpc_mqdec_t *dec, int ctxno, jpc_mqctx_t *ctx);
|
||||
|
||||
/* Set the state information for all contexts of a MQ decoder. */
|
||||
void jpc_mqdec_setctxs(jpc_mqdec_t *dec, int numctxs, jpc_mqctx_t *ctxs);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for decoding bits.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Decode a symbol. */
|
||||
#if !defined(DEBUG)
|
||||
#define jpc_mqdec_getbit(dec) \
|
||||
jpc_mqdec_getbit_macro(dec)
|
||||
#else
|
||||
#define jpc_mqdec_getbit(dec) \
|
||||
jpc_mqdec_getbit_func(dec)
|
||||
#endif
|
||||
|
||||
/* Decode a symbol (assuming an unskewed probability distribution). */
|
||||
#if !defined(DEBUG)
|
||||
#define jpc_mqdec_getbitnoskew(dec) \
|
||||
jpc_mqdec_getbit_macro(dec)
|
||||
#else
|
||||
#define jpc_mqdec_getbitnoskew(dec) \
|
||||
jpc_mqdec_getbit_func(dec)
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for debugging.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Dump the MQ decoder state for debugging. */
|
||||
void jpc_mqdec_dump(jpc_mqdec_t *dec, FILE *out);
|
||||
|
||||
/******************************************************************************\
|
||||
* EVERYTHING BELOW THIS POINT IS IMPLEMENTATION SPECIFIC AND NOT PART OF THE
|
||||
* APPLICATION INTERFACE. DO NOT RELY ON ANY OF THE INTERNAL FUNCTIONS/MACROS
|
||||
* GIVEN BELOW.
|
||||
\******************************************************************************/
|
||||
|
||||
#define jpc_mqdec_getbit_macro(dec) \
|
||||
((((dec)->areg -= (*(dec)->curctx)->qeval), \
|
||||
(dec)->creg >> 16 >= (*(dec)->curctx)->qeval) ? \
|
||||
((((dec)->creg -= (*(dec)->curctx)->qeval << 16), \
|
||||
(dec)->areg & 0x8000) ? (*(dec)->curctx)->mps : \
|
||||
jpc_mqdec_mpsexchrenormd(dec)) : \
|
||||
jpc_mqdec_lpsexchrenormd(dec))
|
||||
|
||||
#define jpc_mqdec_mpsexchange(areg, delta, curctx, bit) \
|
||||
{ \
|
||||
if ((areg) < (delta)) { \
|
||||
register jpc_mqstate_t *state = *(curctx); \
|
||||
/* LPS decoded. */ \
|
||||
(bit) = state->mps ^ 1; \
|
||||
*(curctx) = state->nlps; \
|
||||
} else { \
|
||||
register jpc_mqstate_t *state = *(curctx); \
|
||||
/* MPS decoded. */ \
|
||||
(bit) = state->mps; \
|
||||
*(curctx) = state->nmps; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define jpc_mqdec_lpsexchange(areg, delta, curctx, bit) \
|
||||
{ \
|
||||
if ((areg) >= (delta)) { \
|
||||
register jpc_mqstate_t *state = *(curctx); \
|
||||
(areg) = (delta); \
|
||||
(bit) = state->mps ^ 1; \
|
||||
*(curctx) = state->nlps; \
|
||||
} else { \
|
||||
register jpc_mqstate_t *state = *(curctx); \
|
||||
(areg) = (delta); \
|
||||
(bit) = state->mps; \
|
||||
*(curctx) = state->nmps; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define jpc_mqdec_renormd(areg, creg, ctreg, in, eof, inbuf) \
|
||||
{ \
|
||||
do { \
|
||||
if (!(ctreg)) { \
|
||||
jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf); \
|
||||
} \
|
||||
(areg) <<= 1; \
|
||||
(creg) <<= 1; \
|
||||
--(ctreg); \
|
||||
} while (!((areg) & 0x8000)); \
|
||||
}
|
||||
|
||||
#define jpc_mqdec_bytein2(creg, ctreg, in, eof, inbuf) \
|
||||
{ \
|
||||
int c; \
|
||||
unsigned char prevbuf; \
|
||||
if (!(eof)) { \
|
||||
if ((c = jas_stream_getc(in)) == EOF) { \
|
||||
(eof) = 1; \
|
||||
c = 0xff; \
|
||||
} \
|
||||
prevbuf = (inbuf); \
|
||||
(inbuf) = c; \
|
||||
if (prevbuf == 0xff) { \
|
||||
if (c > 0x8f) { \
|
||||
(creg) += 0xff00; \
|
||||
(ctreg) = 8; \
|
||||
} else { \
|
||||
(creg) += c << 9; \
|
||||
(ctreg) = 7; \
|
||||
} \
|
||||
} else { \
|
||||
(creg) += c << 8; \
|
||||
(ctreg) = 8; \
|
||||
} \
|
||||
} else { \
|
||||
(creg) += 0xff00; \
|
||||
(ctreg) = 8; \
|
||||
} \
|
||||
}
|
||||
|
||||
int jpc_mqdec_getbit_func(jpc_mqdec_t *dec);
|
||||
int jpc_mqdec_mpsexchrenormd(jpc_mqdec_t *dec);
|
||||
int jpc_mqdec_lpsexchrenormd(jpc_mqdec_t *dec);
|
||||
|
||||
#endif
|
||||
Vendored
+392
@@ -0,0 +1,392 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Encoder
|
||||
*
|
||||
* $Id: jpc_mqenc.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jpc_mqenc.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Macros
|
||||
\******************************************************************************/
|
||||
|
||||
#if defined(DEBUG)
|
||||
#define JPC_MQENC_CALL(n, x) \
|
||||
((jas_getdbglevel() >= (n)) ? ((void)(x)) : ((void)0))
|
||||
#else
|
||||
#define JPC_MQENC_CALL(n, x)
|
||||
#endif
|
||||
|
||||
#define jpc_mqenc_codemps9(areg, creg, ctreg, curctx, enc) \
|
||||
{ \
|
||||
jpc_mqstate_t *state = *(curctx); \
|
||||
(areg) -= state->qeval; \
|
||||
if (!((areg) & 0x8000)) { \
|
||||
if ((areg) < state->qeval) { \
|
||||
(areg) = state->qeval; \
|
||||
} else { \
|
||||
(creg) += state->qeval; \
|
||||
} \
|
||||
*(curctx) = state->nmps; \
|
||||
jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \
|
||||
} else { \
|
||||
(creg) += state->qeval; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define jpc_mqenc_codelps2(areg, creg, ctreg, curctx, enc) \
|
||||
{ \
|
||||
jpc_mqstate_t *state = *(curctx); \
|
||||
(areg) -= state->qeval; \
|
||||
if ((areg) < state->qeval) { \
|
||||
(creg) += state->qeval; \
|
||||
} else { \
|
||||
(areg) = state->qeval; \
|
||||
} \
|
||||
*(curctx) = state->nlps; \
|
||||
jpc_mqenc_renorme((areg), (creg), (ctreg), (enc)); \
|
||||
}
|
||||
|
||||
#define jpc_mqenc_renorme(areg, creg, ctreg, enc) \
|
||||
{ \
|
||||
do { \
|
||||
(areg) <<= 1; \
|
||||
(creg) <<= 1; \
|
||||
if (!--(ctreg)) { \
|
||||
jpc_mqenc_byteout((areg), (creg), (ctreg), (enc)); \
|
||||
} \
|
||||
} while (!((areg) & 0x8000)); \
|
||||
}
|
||||
|
||||
#define jpc_mqenc_byteout(areg, creg, ctreg, enc) \
|
||||
{ \
|
||||
if ((enc)->outbuf != 0xff) { \
|
||||
if ((creg) & 0x8000000) { \
|
||||
if (++((enc)->outbuf) == 0xff) { \
|
||||
(creg) &= 0x7ffffff; \
|
||||
jpc_mqenc_byteout2(enc); \
|
||||
enc->outbuf = ((creg) >> 20) & 0xff; \
|
||||
(creg) &= 0xfffff; \
|
||||
(ctreg) = 7; \
|
||||
} else { \
|
||||
jpc_mqenc_byteout2(enc); \
|
||||
enc->outbuf = ((creg) >> 19) & 0xff; \
|
||||
(creg) &= 0x7ffff; \
|
||||
(ctreg) = 8; \
|
||||
} \
|
||||
} else { \
|
||||
jpc_mqenc_byteout2(enc); \
|
||||
(enc)->outbuf = ((creg) >> 19) & 0xff; \
|
||||
(creg) &= 0x7ffff; \
|
||||
(ctreg) = 8; \
|
||||
} \
|
||||
} else { \
|
||||
jpc_mqenc_byteout2(enc); \
|
||||
(enc)->outbuf = ((creg) >> 20) & 0xff; \
|
||||
(creg) &= 0xfffff; \
|
||||
(ctreg) = 7; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define jpc_mqenc_byteout2(enc) \
|
||||
{ \
|
||||
if (enc->outbuf >= 0) { \
|
||||
if (jas_stream_putc(enc->out, (unsigned char)enc->outbuf) == EOF) { \
|
||||
enc->err |= 1; \
|
||||
} \
|
||||
} \
|
||||
enc->lastbyte = enc->outbuf; \
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Local function protoypes.
|
||||
\******************************************************************************/
|
||||
|
||||
static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for creation and destruction of encoder.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a MQ encoder. */
|
||||
|
||||
jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out)
|
||||
{
|
||||
jpc_mqenc_t *mqenc;
|
||||
|
||||
/* Allocate memory for the MQ encoder. */
|
||||
if (!(mqenc = jas_malloc(sizeof(jpc_mqenc_t)))) {
|
||||
goto error;
|
||||
}
|
||||
mqenc->out = out;
|
||||
mqenc->maxctxs = maxctxs;
|
||||
|
||||
/* Allocate memory for the per-context state information. */
|
||||
if (!(mqenc->ctxs = jas_alloc2(mqenc->maxctxs, sizeof(jpc_mqstate_t *)))) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set the current context to the first one. */
|
||||
mqenc->curctx = mqenc->ctxs;
|
||||
|
||||
jpc_mqenc_init(mqenc);
|
||||
|
||||
/* Initialize the per-context state information to something sane. */
|
||||
jpc_mqenc_setctxs(mqenc, 0, 0);
|
||||
|
||||
return mqenc;
|
||||
|
||||
error:
|
||||
if (mqenc) {
|
||||
jpc_mqenc_destroy(mqenc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Destroy a MQ encoder. */
|
||||
|
||||
void jpc_mqenc_destroy(jpc_mqenc_t *mqenc)
|
||||
{
|
||||
if (mqenc->ctxs) {
|
||||
jas_free(mqenc->ctxs);
|
||||
}
|
||||
jas_free(mqenc);
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* State initialization code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Initialize the coding state of a MQ encoder. */
|
||||
|
||||
void jpc_mqenc_init(jpc_mqenc_t *mqenc)
|
||||
{
|
||||
mqenc->areg = 0x8000;
|
||||
mqenc->outbuf = -1;
|
||||
mqenc->creg = 0;
|
||||
mqenc->ctreg = 12;
|
||||
mqenc->lastbyte = -1;
|
||||
mqenc->err = 0;
|
||||
}
|
||||
|
||||
/* Initialize one or more contexts. */
|
||||
|
||||
void jpc_mqenc_setctxs(jpc_mqenc_t *mqenc, int numctxs, jpc_mqctx_t *ctxs)
|
||||
{
|
||||
jpc_mqstate_t **ctx;
|
||||
int n;
|
||||
|
||||
ctx = mqenc->ctxs;
|
||||
n = JAS_MIN(mqenc->maxctxs, numctxs);
|
||||
while (--n >= 0) {
|
||||
*ctx = &jpc_mqstates[2 * ctxs->ind + ctxs->mps];
|
||||
++ctx;
|
||||
++ctxs;
|
||||
}
|
||||
n = mqenc->maxctxs - numctxs;
|
||||
while (--n >= 0) {
|
||||
*ctx = &jpc_mqstates[0];
|
||||
++ctx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Get the coding state for a MQ encoder. */
|
||||
|
||||
void jpc_mqenc_getstate(jpc_mqenc_t *mqenc, jpc_mqencstate_t *state)
|
||||
{
|
||||
state->areg = mqenc->areg;
|
||||
state->creg = mqenc->creg;
|
||||
state->ctreg = mqenc->ctreg;
|
||||
state->lastbyte = mqenc->lastbyte;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for coding symbols.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encode a bit. */
|
||||
|
||||
int jpc_mqenc_putbit_func(jpc_mqenc_t *mqenc, int bit)
|
||||
{
|
||||
const jpc_mqstate_t *state;
|
||||
JAS_DBGLOG(100, ("jpc_mqenc_putbit(%p, %d)\n", mqenc, bit));
|
||||
JPC_MQENC_CALL(100, jpc_mqenc_dump(mqenc, stderr));
|
||||
|
||||
state = *(mqenc->curctx);
|
||||
|
||||
if (state->mps == bit) {
|
||||
/* Apply the CODEMPS algorithm as defined in the standard. */
|
||||
mqenc->areg -= state->qeval;
|
||||
if (!(mqenc->areg & 0x8000)) {
|
||||
jpc_mqenc_codemps2(mqenc);
|
||||
} else {
|
||||
mqenc->creg += state->qeval;
|
||||
}
|
||||
} else {
|
||||
/* Apply the CODELPS algorithm as defined in the standard. */
|
||||
jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc);
|
||||
}
|
||||
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
|
||||
int jpc_mqenc_codemps2(jpc_mqenc_t *mqenc)
|
||||
{
|
||||
/* Note: This function only performs part of the work associated with
|
||||
the CODEMPS algorithm from the standard. Some of the work is also
|
||||
performed by the caller. */
|
||||
|
||||
jpc_mqstate_t *state = *(mqenc->curctx);
|
||||
if (mqenc->areg < state->qeval) {
|
||||
mqenc->areg = state->qeval;
|
||||
} else {
|
||||
mqenc->creg += state->qeval;
|
||||
}
|
||||
*mqenc->curctx = state->nmps;
|
||||
jpc_mqenc_renorme(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
|
||||
int jpc_mqenc_codelps(jpc_mqenc_t *mqenc)
|
||||
{
|
||||
jpc_mqenc_codelps2(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc->curctx, mqenc);
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Terminate the code word. */
|
||||
|
||||
int jpc_mqenc_flush(jpc_mqenc_t *mqenc, int termmode)
|
||||
{
|
||||
int_fast16_t k;
|
||||
|
||||
switch (termmode) {
|
||||
case JPC_MQENC_PTERM:
|
||||
k = 11 - mqenc->ctreg + 1;
|
||||
while (k > 0) {
|
||||
mqenc->creg <<= mqenc->ctreg;
|
||||
mqenc->ctreg = 0;
|
||||
jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg,
|
||||
mqenc);
|
||||
k -= mqenc->ctreg;
|
||||
}
|
||||
if (mqenc->outbuf != 0xff) {
|
||||
jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
|
||||
}
|
||||
break;
|
||||
case JPC_MQENC_DEFTERM:
|
||||
jpc_mqenc_setbits(mqenc);
|
||||
mqenc->creg <<= mqenc->ctreg;
|
||||
jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
|
||||
mqenc->creg <<= mqenc->ctreg;
|
||||
jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
|
||||
if (mqenc->outbuf != 0xff) {
|
||||
jpc_mqenc_byteout(mqenc->areg, mqenc->creg, mqenc->ctreg, mqenc);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void jpc_mqenc_setbits(jpc_mqenc_t *mqenc)
|
||||
{
|
||||
uint_fast32_t tmp = mqenc->creg + mqenc->areg;
|
||||
mqenc->creg |= 0xffff;
|
||||
if (mqenc->creg >= tmp) {
|
||||
mqenc->creg -= 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump a MQ encoder to a stream for debugging. */
|
||||
|
||||
int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out)
|
||||
{
|
||||
fprintf(out, "AREG = %08x, CREG = %08x, CTREG = %d\n",
|
||||
(unsigned)mqenc->areg, (unsigned)mqenc->creg, (int)mqenc->ctreg);
|
||||
fprintf(out, "IND = %02d, MPS = %d, QEVAL = %04x\n",
|
||||
(int)(*mqenc->curctx - jpc_mqstates), (int)(*mqenc->curctx)->mps,
|
||||
(int)(*mqenc->curctx)->qeval);
|
||||
return 0;
|
||||
}
|
||||
Vendored
+236
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* MQ Arithmetic Encoder
|
||||
*
|
||||
* $Id: jpc_mqenc.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_MQENC_H
|
||||
#define JPC_MQENC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
#include "jpc_mqcod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Termination modes.
|
||||
*/
|
||||
|
||||
#define JPC_MQENC_DEFTERM 0 /* default termination */
|
||||
#define JPC_MQENC_PTERM 1 /* predictable termination */
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* MQ arithmetic encoder class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The C register. */
|
||||
uint_fast32_t creg;
|
||||
|
||||
/* The A register. */
|
||||
uint_fast32_t areg;
|
||||
|
||||
/* The CT register. */
|
||||
uint_fast32_t ctreg;
|
||||
|
||||
/* The maximum number of contexts. */
|
||||
int maxctxs;
|
||||
|
||||
/* The per-context information. */
|
||||
jpc_mqstate_t **ctxs;
|
||||
|
||||
/* The current context. */
|
||||
jpc_mqstate_t **curctx;
|
||||
|
||||
/* The stream for encoder output. */
|
||||
jas_stream_t *out;
|
||||
|
||||
/* The byte buffer (i.e., the B variable in the standard). */
|
||||
int_fast16_t outbuf;
|
||||
|
||||
/* The last byte output. */
|
||||
int_fast16_t lastbyte;
|
||||
|
||||
/* The error indicator. */
|
||||
int err;
|
||||
|
||||
} jpc_mqenc_t;
|
||||
|
||||
/* MQ arithmetic encoder state information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The A register. */
|
||||
unsigned areg;
|
||||
|
||||
/* The C register. */
|
||||
unsigned creg;
|
||||
|
||||
/* The CT register. */
|
||||
unsigned ctreg;
|
||||
|
||||
/* The last byte output by the encoder. */
|
||||
int lastbyte;
|
||||
|
||||
} jpc_mqencstate_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for construction and destruction.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a MQ encoder. */
|
||||
jpc_mqenc_t *jpc_mqenc_create(int maxctxs, jas_stream_t *out);
|
||||
|
||||
/* Destroy a MQ encoder. */
|
||||
void jpc_mqenc_destroy(jpc_mqenc_t *enc);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for initialization.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Initialize a MQ encoder. */
|
||||
void jpc_mqenc_init(jpc_mqenc_t *enc);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for context manipulation.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Set the current context. */
|
||||
#define jpc_mqenc_setcurctx(enc, ctxno) \
|
||||
((enc)->curctx = &(enc)->ctxs[ctxno]);
|
||||
|
||||
/* Set the state information for a particular context. */
|
||||
void jpc_mqenc_setctx(jpc_mqenc_t *enc, int ctxno, jpc_mqctx_t *ctx);
|
||||
|
||||
/* Set the state information for multiple contexts. */
|
||||
void jpc_mqenc_setctxs(jpc_mqenc_t *enc, int numctxs, jpc_mqctx_t *ctxs);
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous functions/macros.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Get the error state of a MQ encoder. */
|
||||
#define jpc_mqenc_error(enc) \
|
||||
((enc)->err)
|
||||
|
||||
/* Get the current encoder state. */
|
||||
void jpc_mqenc_getstate(jpc_mqenc_t *enc, jpc_mqencstate_t *state);
|
||||
|
||||
/* Terminate the code. */
|
||||
int jpc_mqenc_flush(jpc_mqenc_t *enc, int termmode);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for encoding bits.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encode a bit. */
|
||||
#if !defined(DEBUG)
|
||||
#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_macro(enc, bit)
|
||||
#else
|
||||
#define jpc_mqenc_putbit(enc, bit) jpc_mqenc_putbit_func(enc, bit)
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for debugging.
|
||||
\******************************************************************************/
|
||||
|
||||
int jpc_mqenc_dump(jpc_mqenc_t *mqenc, FILE *out);
|
||||
|
||||
/******************************************************************************\
|
||||
* Implementation-specific details.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Note: This macro is included only to satisfy the needs of
|
||||
the mqenc_putbit macro. */
|
||||
#define jpc_mqenc_putbit_macro(enc, bit) \
|
||||
(((*((enc)->curctx))->mps == (bit)) ? \
|
||||
(((enc)->areg -= (*(enc)->curctx)->qeval), \
|
||||
((!((enc)->areg & 0x8000)) ? (jpc_mqenc_codemps2(enc)) : \
|
||||
((enc)->creg += (*(enc)->curctx)->qeval))) : \
|
||||
jpc_mqenc_codelps(enc))
|
||||
|
||||
/* Note: These function prototypes are included only to satisfy the
|
||||
needs of the mqenc_putbit_macro macro. Do not call any of these
|
||||
functions directly. */
|
||||
int jpc_mqenc_codemps2(jpc_mqenc_t *enc);
|
||||
int jpc_mqenc_codelps(jpc_mqenc_t *enc);
|
||||
|
||||
/* Note: This function prototype is included only to satisfy the needs of
|
||||
the mqenc_putbit macro. */
|
||||
int jpc_mqenc_putbit_func(jpc_mqenc_t *enc, int bit);
|
||||
|
||||
#endif
|
||||
Vendored
+3144
File diff suppressed because it is too large
Load Diff
Vendored
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2004 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Quadrature Mirror-Image Filter Bank (QMFB) Routines
|
||||
*
|
||||
* $Id: jpc_qmfb.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_QMFB_H
|
||||
#define JPC_QMFB_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* QMFB IDs. */
|
||||
#define JPC_QMFB1D_FT 1 /* 5/3 */
|
||||
#define JPC_QMFB1D_NS 2 /* 9/7 */
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
#if !defined(JPC_QMFB_COLGRPSIZE)
|
||||
/* The number of columns to group together during the vertical processing
|
||||
stage of the wavelet transform. */
|
||||
/* The default value for this parameter is probably not optimal for
|
||||
any particular platform. Hopefully, it is not too unreasonable, however. */
|
||||
#define JPC_QMFB_COLGRPSIZE 16
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int (*analyze)(int *, int, int, int, int, int);
|
||||
int (*synthesize)(int *, int, int, int, int, int);
|
||||
double *lpenergywts;
|
||||
double *hpenergywts;
|
||||
} jpc_qmfb2d_t;
|
||||
|
||||
extern jpc_qmfb2d_t jpc_ft_qmfb2d;
|
||||
extern jpc_qmfb2d_t jpc_ns_qmfb2d;
|
||||
|
||||
#endif
|
||||
Vendored
+497
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jpc_t1cod.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
#include "jpc_bs.h"
|
||||
#include "jpc_dec.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_mqcod.h"
|
||||
#include "jpc_t1cod.h"
|
||||
#include "jpc_tsfb.h"
|
||||
|
||||
double jpc_pow2i(int n);
|
||||
|
||||
/******************************************************************************\
|
||||
* Global data.
|
||||
\******************************************************************************/
|
||||
|
||||
int jpc_zcctxnolut[4 * 256];
|
||||
int jpc_spblut[256];
|
||||
int jpc_scctxnolut[256];
|
||||
int jpc_magctxnolut[4096];
|
||||
|
||||
jpc_fix_t jpc_signmsedec[1 << JPC_NMSEDEC_BITS];
|
||||
jpc_fix_t jpc_refnmsedec[1 << JPC_NMSEDEC_BITS];
|
||||
jpc_fix_t jpc_signmsedec0[1 << JPC_NMSEDEC_BITS];
|
||||
jpc_fix_t jpc_refnmsedec0[1 << JPC_NMSEDEC_BITS];
|
||||
|
||||
jpc_mqctx_t jpc_mqctxs[JPC_NUMCTXS];
|
||||
|
||||
/******************************************************************************\
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
void jpc_initmqctxs(void);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
int JPC_PASSTYPE(int passno)
|
||||
{
|
||||
int passtype;
|
||||
switch (passno % 3) {
|
||||
case 0:
|
||||
passtype = JPC_CLNPASS;
|
||||
break;
|
||||
case 1:
|
||||
passtype = JPC_SIGPASS;
|
||||
break;
|
||||
case 2:
|
||||
passtype = JPC_REFPASS;
|
||||
break;
|
||||
default:
|
||||
passtype = -1;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
return passtype;
|
||||
}
|
||||
|
||||
int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient)
|
||||
{
|
||||
/* Avoid compiler warnings about unused parameters. */
|
||||
numlvls = 0;
|
||||
|
||||
if (qmfbid == JPC_COX_INS) {
|
||||
return 0;
|
||||
}
|
||||
assert(qmfbid == JPC_COX_RFT);
|
||||
if (lvlno == 0) {
|
||||
assert(orient == JPC_TSFB_LL);
|
||||
return 0;
|
||||
} else {
|
||||
switch (orient) {
|
||||
case JPC_TSFB_LH:
|
||||
case JPC_TSFB_HL:
|
||||
return 1;
|
||||
break;
|
||||
case JPC_TSFB_HH:
|
||||
return 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Coding pass related functions.
|
||||
\******************************************************************************/
|
||||
|
||||
int JPC_SEGTYPE(int passno, int firstpassno, int bypass)
|
||||
{
|
||||
int passtype;
|
||||
if (bypass) {
|
||||
passtype = JPC_PASSTYPE(passno);
|
||||
if (passtype == JPC_CLNPASS) {
|
||||
return JPC_SEG_MQ;
|
||||
}
|
||||
return ((passno < firstpassno + 10) ? JPC_SEG_MQ : JPC_SEG_RAW);
|
||||
} else {
|
||||
return JPC_SEG_MQ;
|
||||
}
|
||||
}
|
||||
|
||||
int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass, int termall)
|
||||
{
|
||||
int ret;
|
||||
int passtype;
|
||||
|
||||
if (termall) {
|
||||
ret = 1;
|
||||
} else if (bypass) {
|
||||
if (passno < firstpassno + 10) {
|
||||
ret = 10 - (passno - firstpassno);
|
||||
} else {
|
||||
passtype = JPC_PASSTYPE(passno);
|
||||
switch (passtype) {
|
||||
case JPC_SIGPASS:
|
||||
ret = 2;
|
||||
break;
|
||||
case JPC_REFPASS:
|
||||
ret = 1;
|
||||
break;
|
||||
case JPC_CLNPASS:
|
||||
ret = 1;
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ret = JPC_PREC * 3 - 2;
|
||||
}
|
||||
ret = JAS_MIN(ret, numpasses - passno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,
|
||||
int lazy)
|
||||
{
|
||||
int ret;
|
||||
int n;
|
||||
if (passno - firstpassno == numpasses - 1) {
|
||||
ret = 1;
|
||||
} else {
|
||||
n = JPC_SEGPASSCNT(passno, firstpassno, numpasses, lazy, termall);
|
||||
ret = (n <= 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Lookup table code.
|
||||
\******************************************************************************/
|
||||
|
||||
void jpc_initluts()
|
||||
{
|
||||
int i;
|
||||
int orient;
|
||||
int refine;
|
||||
float u;
|
||||
float v;
|
||||
float t;
|
||||
|
||||
/* XXX - hack */
|
||||
jpc_initmqctxs();
|
||||
|
||||
for (orient = 0; orient < 4; ++orient) {
|
||||
for (i = 0; i < 256; ++i) {
|
||||
jpc_zcctxnolut[(orient << 8) | i] = jpc_getzcctxno(i, orient);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; ++i) {
|
||||
jpc_spblut[i] = jpc_getspb(i << 4);
|
||||
}
|
||||
|
||||
for (i = 0; i < 256; ++i) {
|
||||
jpc_scctxnolut[i] = jpc_getscctxno(i << 4);
|
||||
}
|
||||
|
||||
for (refine = 0; refine < 2; ++refine) {
|
||||
for (i = 0; i < 2048; ++i) {
|
||||
jpc_magctxnolut[(refine << 11) + i] = jpc_getmagctxno((refine ? JPC_REFINE : 0) | i);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < (1 << JPC_NMSEDEC_BITS); ++i) {
|
||||
t = i * jpc_pow2i(-JPC_NMSEDEC_FRACBITS);
|
||||
u = t;
|
||||
v = t - 1.5;
|
||||
jpc_signmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
|
||||
/* XXX - this calc is not correct */
|
||||
jpc_signmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
|
||||
u = t - 1.0;
|
||||
if (i & (1 << (JPC_NMSEDEC_BITS - 1))) {
|
||||
v = t - 1.5;
|
||||
} else {
|
||||
v = t - 0.5;
|
||||
}
|
||||
jpc_refnmsedec[i] = jpc_dbltofix(floor((u * u - v * v) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
|
||||
/* XXX - this calc is not correct */
|
||||
jpc_refnmsedec0[i] = jpc_dbltofix(floor((u * u) * jpc_pow2i(JPC_NMSEDEC_FRACBITS) + 0.5) / jpc_pow2i(JPC_NMSEDEC_FRACBITS));
|
||||
}
|
||||
}
|
||||
|
||||
jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos)
|
||||
{
|
||||
jpc_fix_t y;
|
||||
assert(!(x & (~JAS_ONES(bitpos + 1))));
|
||||
y = jpc_getsignmsedec_macro(x, bitpos);
|
||||
return y;
|
||||
}
|
||||
|
||||
int jpc_getzcctxno(int f, int orient)
|
||||
{
|
||||
int h;
|
||||
int v;
|
||||
int d;
|
||||
int n;
|
||||
int t;
|
||||
int hv;
|
||||
|
||||
/* Avoid compiler warning. */
|
||||
n = 0;
|
||||
|
||||
h = ((f & JPC_WSIG) != 0) + ((f & JPC_ESIG) != 0);
|
||||
v = ((f & JPC_NSIG) != 0) + ((f & JPC_SSIG) != 0);
|
||||
d = ((f & JPC_NWSIG) != 0) + ((f & JPC_NESIG) != 0) + ((f & JPC_SESIG) != 0) + ((f & JPC_SWSIG) != 0);
|
||||
switch (orient) {
|
||||
case JPC_TSFB_HL:
|
||||
t = h;
|
||||
h = v;
|
||||
v = t;
|
||||
case JPC_TSFB_LL:
|
||||
case JPC_TSFB_LH:
|
||||
if (!h) {
|
||||
if (!v) {
|
||||
if (!d) {
|
||||
n = 0;
|
||||
} else if (d == 1) {
|
||||
n = 1;
|
||||
} else {
|
||||
n = 2;
|
||||
}
|
||||
} else if (v == 1) {
|
||||
n = 3;
|
||||
} else {
|
||||
n = 4;
|
||||
}
|
||||
} else if (h == 1) {
|
||||
if (!v) {
|
||||
if (!d) {
|
||||
n = 5;
|
||||
} else {
|
||||
n = 6;
|
||||
}
|
||||
} else {
|
||||
n = 7;
|
||||
}
|
||||
} else {
|
||||
n = 8;
|
||||
}
|
||||
break;
|
||||
case JPC_TSFB_HH:
|
||||
hv = h + v;
|
||||
if (!d) {
|
||||
if (!hv) {
|
||||
n = 0;
|
||||
} else if (hv == 1) {
|
||||
n = 1;
|
||||
} else {
|
||||
n = 2;
|
||||
}
|
||||
} else if (d == 1) {
|
||||
if (!hv) {
|
||||
n = 3;
|
||||
} else if (hv == 1) {
|
||||
n = 4;
|
||||
} else {
|
||||
n = 5;
|
||||
}
|
||||
} else if (d == 2) {
|
||||
if (!hv) {
|
||||
n = 6;
|
||||
} else {
|
||||
n = 7;
|
||||
}
|
||||
} else {
|
||||
n = 8;
|
||||
}
|
||||
break;
|
||||
}
|
||||
assert(n < JPC_NUMZCCTXS);
|
||||
return JPC_ZCCTXNO + n;
|
||||
}
|
||||
|
||||
int jpc_getspb(int f)
|
||||
{
|
||||
int hc;
|
||||
int vc;
|
||||
int n;
|
||||
|
||||
hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG), 1) -
|
||||
JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) + ((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1);
|
||||
vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG), 1) -
|
||||
JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) + ((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1);
|
||||
if (!hc && !vc) {
|
||||
n = 0;
|
||||
} else {
|
||||
n = (!(hc > 0 || (!hc && vc > 0)));
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int jpc_getscctxno(int f)
|
||||
{
|
||||
int hc;
|
||||
int vc;
|
||||
int n;
|
||||
|
||||
/* Avoid compiler warning. */
|
||||
n = 0;
|
||||
|
||||
hc = JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == JPC_ESIG) + ((f & (JPC_WSIG | JPC_WSGN)) == JPC_WSIG),
|
||||
1) - JAS_MIN(((f & (JPC_ESIG | JPC_ESGN)) == (JPC_ESIG | JPC_ESGN)) +
|
||||
((f & (JPC_WSIG | JPC_WSGN)) == (JPC_WSIG | JPC_WSGN)), 1);
|
||||
vc = JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == JPC_NSIG) + ((f & (JPC_SSIG | JPC_SSGN)) == JPC_SSIG),
|
||||
1) - JAS_MIN(((f & (JPC_NSIG | JPC_NSGN)) == (JPC_NSIG | JPC_NSGN)) +
|
||||
((f & (JPC_SSIG | JPC_SSGN)) == (JPC_SSIG | JPC_SSGN)), 1);
|
||||
assert(hc >= -1 && hc <= 1 && vc >= -1 && vc <= 1);
|
||||
if (hc < 0) {
|
||||
hc = -hc;
|
||||
vc = -vc;
|
||||
}
|
||||
if (!hc) {
|
||||
if (vc == -1) {
|
||||
n = 1;
|
||||
} else if (!vc) {
|
||||
n = 0;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
} else if (hc == 1) {
|
||||
if (vc == -1) {
|
||||
n = 2;
|
||||
} else if (!vc) {
|
||||
n = 3;
|
||||
} else {
|
||||
n = 4;
|
||||
}
|
||||
}
|
||||
assert(n < JPC_NUMSCCTXS);
|
||||
return JPC_SCCTXNO + n;
|
||||
}
|
||||
|
||||
int jpc_getmagctxno(int f)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (!(f & JPC_REFINE)) {
|
||||
n = (f & (JPC_OTHSIGMSK)) ? 1 : 0;
|
||||
} else {
|
||||
n = 2;
|
||||
}
|
||||
|
||||
assert(n < JPC_NUMMAGCTXS);
|
||||
return JPC_MAGCTXNO + n;
|
||||
}
|
||||
|
||||
void jpc_initctxs(jpc_mqctx_t *ctxs)
|
||||
{
|
||||
jpc_mqctx_t *ctx;
|
||||
int i;
|
||||
|
||||
ctx = ctxs;
|
||||
for (i = 0; i < JPC_NUMCTXS; ++i) {
|
||||
ctx->mps = 0;
|
||||
switch (i) {
|
||||
case JPC_UCTXNO:
|
||||
ctx->ind = 46;
|
||||
break;
|
||||
case JPC_ZCCTXNO:
|
||||
ctx->ind = 4;
|
||||
break;
|
||||
case JPC_AGGCTXNO:
|
||||
ctx->ind = 3;
|
||||
break;
|
||||
default:
|
||||
ctx->ind = 0;
|
||||
break;
|
||||
}
|
||||
++ctx;
|
||||
}
|
||||
}
|
||||
|
||||
void jpc_initmqctxs()
|
||||
{
|
||||
jpc_initctxs(jpc_mqctxs);
|
||||
}
|
||||
|
||||
/* Calculate the real quantity exp2(n), where x is an integer. */
|
||||
double jpc_pow2i(int n)
|
||||
{
|
||||
double x;
|
||||
double a;
|
||||
|
||||
x = 1.0;
|
||||
if (n < 0) {
|
||||
a = 0.5;
|
||||
n = -n;
|
||||
} else {
|
||||
a = 2.0;
|
||||
}
|
||||
while (--n >= 0) {
|
||||
x *= a;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
Vendored
+295
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jpc_t1cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T1COD_H
|
||||
#define JPC_T1COD_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
#include "jpc_mqcod.h"
|
||||
#include "jpc_tsfb.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
/* The number of bits used to index into various lookup tables. */
|
||||
#define JPC_NMSEDEC_BITS 7
|
||||
#define JPC_NMSEDEC_FRACBITS (JPC_NMSEDEC_BITS - 1)
|
||||
|
||||
/*
|
||||
* Segment types.
|
||||
*/
|
||||
|
||||
/* Invalid. */
|
||||
#define JPC_SEG_INVALID 0
|
||||
/* MQ. */
|
||||
#define JPC_SEG_MQ 1
|
||||
/* Raw. */
|
||||
#define JPC_SEG_RAW 2
|
||||
|
||||
/* The nominal word size. */
|
||||
#define JPC_PREC 32
|
||||
|
||||
/* Tier-1 coding pass types. */
|
||||
#define JPC_SIGPASS 0 /* significance */
|
||||
#define JPC_REFPASS 1 /* refinement */
|
||||
#define JPC_CLNPASS 2 /* cleanup */
|
||||
|
||||
/*
|
||||
* Per-sample state information for tier-1 coding.
|
||||
*/
|
||||
|
||||
/* The northeast neighbour has been found to be significant. */
|
||||
#define JPC_NESIG 0x0001
|
||||
/* The southeast neighbour has been found to be significant. */
|
||||
#define JPC_SESIG 0x0002
|
||||
/* The southwest neighbour has been found to be significant. */
|
||||
#define JPC_SWSIG 0x0004
|
||||
/* The northwest neighbour has been found to be significant. */
|
||||
#define JPC_NWSIG 0x0008
|
||||
/* The north neighbour has been found to be significant. */
|
||||
#define JPC_NSIG 0x0010
|
||||
/* The east neighbour has been found to be significant. */
|
||||
#define JPC_ESIG 0x0020
|
||||
/* The south neighbour has been found to be significant. */
|
||||
#define JPC_SSIG 0x0040
|
||||
/* The west neighbour has been found to be significant. */
|
||||
#define JPC_WSIG 0x0080
|
||||
/* The significance mask for 8-connected neighbours. */
|
||||
#define JPC_OTHSIGMSK \
|
||||
(JPC_NSIG | JPC_NESIG | JPC_ESIG | JPC_SESIG | JPC_SSIG | JPC_SWSIG | JPC_WSIG | JPC_NWSIG)
|
||||
/* The significance mask for 4-connected neighbours. */
|
||||
#define JPC_PRIMSIGMSK (JPC_NSIG | JPC_ESIG | JPC_SSIG | JPC_WSIG)
|
||||
|
||||
/* The north neighbour is negative in value. */
|
||||
#define JPC_NSGN 0x0100
|
||||
/* The east neighbour is negative in value. */
|
||||
#define JPC_ESGN 0x0200
|
||||
/* The south neighbour is negative in value. */
|
||||
#define JPC_SSGN 0x0400
|
||||
/* The west neighbour is negative in value. */
|
||||
#define JPC_WSGN 0x0800
|
||||
/* The sign mask for 4-connected neighbours. */
|
||||
#define JPC_SGNMSK (JPC_NSGN | JPC_ESGN | JPC_SSGN | JPC_WSGN)
|
||||
|
||||
/* This sample has been found to be significant. */
|
||||
#define JPC_SIG 0x1000
|
||||
/* The sample has been refined. */
|
||||
#define JPC_REFINE 0x2000
|
||||
/* This sample has been processed during the significance pass. */
|
||||
#define JPC_VISIT 0x4000
|
||||
|
||||
/* The number of aggregation contexts. */
|
||||
#define JPC_NUMAGGCTXS 1
|
||||
/* The number of zero coding contexts. */
|
||||
#define JPC_NUMZCCTXS 9
|
||||
/* The number of magnitude contexts. */
|
||||
#define JPC_NUMMAGCTXS 3
|
||||
/* The number of sign coding contexts. */
|
||||
#define JPC_NUMSCCTXS 5
|
||||
/* The number of uniform contexts. */
|
||||
#define JPC_NUMUCTXS 1
|
||||
|
||||
/* The context ID for the first aggregation context. */
|
||||
#define JPC_AGGCTXNO 0
|
||||
/* The context ID for the first zero coding context. */
|
||||
#define JPC_ZCCTXNO (JPC_AGGCTXNO + JPC_NUMAGGCTXS)
|
||||
/* The context ID for the first magnitude context. */
|
||||
#define JPC_MAGCTXNO (JPC_ZCCTXNO + JPC_NUMZCCTXS)
|
||||
/* The context ID for the first sign coding context. */
|
||||
#define JPC_SCCTXNO (JPC_MAGCTXNO + JPC_NUMMAGCTXS)
|
||||
/* The context ID for the first uniform context. */
|
||||
#define JPC_UCTXNO (JPC_SCCTXNO + JPC_NUMSCCTXS)
|
||||
/* The total number of contexts. */
|
||||
#define JPC_NUMCTXS (JPC_UCTXNO + JPC_NUMUCTXS)
|
||||
|
||||
/******************************************************************************\
|
||||
* External data.
|
||||
\******************************************************************************/
|
||||
|
||||
/* These lookup tables are used by various macros/functions. */
|
||||
/* Do not access these lookup tables directly. */
|
||||
extern int jpc_zcctxnolut[];
|
||||
extern int jpc_spblut[];
|
||||
extern int jpc_scctxnolut[];
|
||||
extern int jpc_magctxnolut[];
|
||||
extern jpc_fix_t jpc_refnmsedec[];
|
||||
extern jpc_fix_t jpc_signmsedec[];
|
||||
extern jpc_fix_t jpc_refnmsedec0[];
|
||||
extern jpc_fix_t jpc_signmsedec0[];
|
||||
|
||||
/* The initial settings for the MQ contexts. */
|
||||
extern jpc_mqctx_t jpc_mqctxs[];
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions and macros.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Initialize the MQ contexts. */
|
||||
void jpc_initctxs(jpc_mqctx_t *ctxs);
|
||||
|
||||
/* Get the zero coding context. */
|
||||
int jpc_getzcctxno(int f, int orient);
|
||||
#define JPC_GETZCCTXNO(f, orient) \
|
||||
(jpc_zcctxnolut[((orient) << 8) | ((f) & JPC_OTHSIGMSK)])
|
||||
|
||||
/* Get the sign prediction bit. */
|
||||
int jpc_getspb(int f);
|
||||
#define JPC_GETSPB(f) \
|
||||
(jpc_spblut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
|
||||
|
||||
/* Get the sign coding context. */
|
||||
int jpc_getscctxno(int f);
|
||||
#define JPC_GETSCCTXNO(f) \
|
||||
(jpc_scctxnolut[((f) & (JPC_PRIMSIGMSK | JPC_SGNMSK)) >> 4])
|
||||
|
||||
/* Get the magnitude context. */
|
||||
int jpc_getmagctxno(int f);
|
||||
#define JPC_GETMAGCTXNO(f) \
|
||||
(jpc_magctxnolut[((f) & JPC_OTHSIGMSK) | ((((f) & JPC_REFINE) != 0) << 11)])
|
||||
|
||||
/* Get the normalized MSE reduction for significance passes. */
|
||||
#define JPC_GETSIGNMSEDEC(x, bitpos) jpc_getsignmsedec_macro(x, bitpos)
|
||||
jpc_fix_t jpc_getsignmsedec_func(jpc_fix_t x, int bitpos);
|
||||
#define jpc_getsignmsedec_macro(x, bitpos) \
|
||||
((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_signmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
|
||||
(jpc_signmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
|
||||
|
||||
/* Get the normalized MSE reduction for refinement passes. */
|
||||
#define JPC_GETREFNMSEDEC(x, bitpos) jpc_getrefnmsedec_macro(x, bitpos)
|
||||
jpc_fix_t jpc_refsignmsedec_func(jpc_fix_t x, int bitpos);
|
||||
#define jpc_getrefnmsedec_macro(x, bitpos) \
|
||||
((bitpos > JPC_NMSEDEC_FRACBITS) ? jpc_refnmsedec[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)] : \
|
||||
(jpc_refnmsedec0[JPC_ASR(x, bitpos - JPC_NMSEDEC_FRACBITS) & JAS_ONES(JPC_NMSEDEC_BITS)]))
|
||||
|
||||
/* Arithmetic shift right (with ability to shift left also). */
|
||||
#define JPC_ASR(x, n) \
|
||||
(((n) >= 0) ? ((x) >> (n)) : ((x) << (-(n))))
|
||||
|
||||
/* Update the per-sample state information. */
|
||||
#define JPC_UPDATEFLAGS4(fp, rowstep, s, vcausalflag) \
|
||||
{ \
|
||||
register jpc_fix_t *np = (fp) - (rowstep); \
|
||||
register jpc_fix_t *sp = (fp) + (rowstep); \
|
||||
if ((vcausalflag)) { \
|
||||
sp[-1] |= JPC_NESIG; \
|
||||
sp[1] |= JPC_NWSIG; \
|
||||
if (s) { \
|
||||
*sp |= JPC_NSIG | JPC_NSGN; \
|
||||
(fp)[-1] |= JPC_ESIG | JPC_ESGN; \
|
||||
(fp)[1] |= JPC_WSIG | JPC_WSGN; \
|
||||
} else { \
|
||||
*sp |= JPC_NSIG; \
|
||||
(fp)[-1] |= JPC_ESIG; \
|
||||
(fp)[1] |= JPC_WSIG; \
|
||||
} \
|
||||
} else { \
|
||||
np[-1] |= JPC_SESIG; \
|
||||
np[1] |= JPC_SWSIG; \
|
||||
sp[-1] |= JPC_NESIG; \
|
||||
sp[1] |= JPC_NWSIG; \
|
||||
if (s) { \
|
||||
*np |= JPC_SSIG | JPC_SSGN; \
|
||||
*sp |= JPC_NSIG | JPC_NSGN; \
|
||||
(fp)[-1] |= JPC_ESIG | JPC_ESGN; \
|
||||
(fp)[1] |= JPC_WSIG | JPC_WSGN; \
|
||||
} else { \
|
||||
*np |= JPC_SSIG; \
|
||||
*sp |= JPC_NSIG; \
|
||||
(fp)[-1] |= JPC_ESIG; \
|
||||
(fp)[1] |= JPC_WSIG; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/* Initialize the lookup tables used by the codec. */
|
||||
void jpc_initluts(void);
|
||||
|
||||
/* Get the nominal gain associated with a particular band. */
|
||||
int JPC_NOMINALGAIN(int qmfbid, int numlvls, int lvlno, int orient);
|
||||
|
||||
/* Get the coding pass type. */
|
||||
int JPC_PASSTYPE(int passno);
|
||||
|
||||
/* Get the segment type. */
|
||||
int JPC_SEGTYPE(int passno, int firstpassno, int bypass);
|
||||
|
||||
/* Get the number of coding passess in the segment. */
|
||||
int JPC_SEGPASSCNT(int passno, int firstpassno, int numpasses, int bypass,
|
||||
int termall);
|
||||
|
||||
/* Is the coding pass terminated? */
|
||||
int JPC_ISTERMINATED(int passno, int firstpassno, int numpasses, int termall,
|
||||
int lazy);
|
||||
|
||||
#endif
|
||||
Vendored
+922
@@ -0,0 +1,922 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 1 Decoder
|
||||
*
|
||||
* $Id: jpc_t1dec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
#include "jpc_bs.h"
|
||||
#include "jpc_mqdec.h"
|
||||
#include "jpc_t1dec.h"
|
||||
#include "jpc_t1cod.h"
|
||||
#include "jpc_dec.h"
|
||||
|
||||
/******************************************************************************\
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band,
|
||||
jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs);
|
||||
static int dec_sigpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient,
|
||||
int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
|
||||
static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos,
|
||||
int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
|
||||
static int dec_refpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int vcausalflag,
|
||||
jas_matrix_t *flags, jas_matrix_t *data);
|
||||
static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos,
|
||||
int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data);
|
||||
static int dec_clnpass(jpc_dec_t *dec, jpc_mqdec_t *mqdec, int bitpos, int orient,
|
||||
int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data);
|
||||
|
||||
#if defined(DEBUG)
|
||||
static long t1dec_cnt = 0;
|
||||
#endif
|
||||
|
||||
#if !defined(DEBUG)
|
||||
#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \
|
||||
((v) = jpc_mqdec_getbit(mqdec))
|
||||
#else
|
||||
#define JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename) \
|
||||
{ \
|
||||
(v) = jpc_mqdec_getbit(mqdec); \
|
||||
if (jas_getdbglevel() >= 100) { \
|
||||
jas_eprintf("index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \
|
||||
++t1dec_cnt; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
#define JPC_T1D_GETBITNOSKEW(mqdec, v, passtypename, symtypename) \
|
||||
JPC_T1D_GETBIT(mqdec, v, passtypename, symtypename)
|
||||
|
||||
#if !defined(DEBUG)
|
||||
#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \
|
||||
((v) = jpc_bitstream_getbit(bitstream))
|
||||
#else
|
||||
#define JPC_T1D_RAWGETBIT(bitstream, v, passtypename, symtypename) \
|
||||
{ \
|
||||
(v) = jpc_bitstream_getbit(bitstream); \
|
||||
if (jas_getdbglevel() >= 100) { \
|
||||
jas_eprintf("index = %ld; passtype = %s; symtype = %s; sym = %d\n", t1dec_cnt, passtypename, symtypename, v); \
|
||||
++t1dec_cnt; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile)
|
||||
{
|
||||
jpc_dec_tcomp_t *tcomp;
|
||||
int compcnt;
|
||||
jpc_dec_rlvl_t *rlvl;
|
||||
int rlvlcnt;
|
||||
jpc_dec_band_t *band;
|
||||
int bandcnt;
|
||||
jpc_dec_prc_t *prc;
|
||||
int prccnt;
|
||||
jpc_dec_cblk_t *cblk;
|
||||
int cblkcnt;
|
||||
|
||||
for (compcnt = dec->numcomps, tcomp = tile->tcomps; compcnt > 0;
|
||||
--compcnt, ++tcomp) {
|
||||
for (rlvlcnt = tcomp->numrlvls, rlvl = tcomp->rlvls;
|
||||
rlvlcnt > 0; --rlvlcnt, ++rlvl) {
|
||||
if (!rlvl->bands) {
|
||||
continue;
|
||||
}
|
||||
for (bandcnt = rlvl->numbands, band = rlvl->bands;
|
||||
bandcnt > 0; --bandcnt, ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
for (prccnt = rlvl->numprcs, prc = band->prcs;
|
||||
prccnt > 0; --prccnt, ++prc) {
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
for (cblkcnt = prc->numcblks,
|
||||
cblk = prc->cblks; cblkcnt > 0;
|
||||
--cblkcnt, ++cblk) {
|
||||
if (jpc_dec_decodecblk(dec, tile, tcomp,
|
||||
band, cblk, 1, JPC_MAXLYRS)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jpc_dec_decodecblk(jpc_dec_t *dec, jpc_dec_tile_t *tile, jpc_dec_tcomp_t *tcomp, jpc_dec_band_t *band,
|
||||
jpc_dec_cblk_t *cblk, int dopartial, int maxlyrs)
|
||||
{
|
||||
jpc_dec_seg_t *seg;
|
||||
int i;
|
||||
int bpno;
|
||||
int passtype;
|
||||
int ret;
|
||||
int compno;
|
||||
int filldata;
|
||||
int fillmask;
|
||||
jpc_dec_ccp_t *ccp;
|
||||
|
||||
compno = tcomp - tile->tcomps;
|
||||
|
||||
if (!cblk->flags) {
|
||||
/* Note: matrix is assumed to be zeroed */
|
||||
if (!(cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) +
|
||||
2, jas_matrix_numcols(cblk->data) + 2))) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
seg = cblk->segs.head;
|
||||
while (seg && (seg != cblk->curseg || dopartial) && (maxlyrs < 0 ||
|
||||
seg->lyrno < maxlyrs)) {
|
||||
assert(seg->numpasses >= seg->maxpasses || dopartial);
|
||||
assert(seg->stream);
|
||||
jas_stream_rewind(seg->stream);
|
||||
jas_stream_setrwcount(seg->stream, 0);
|
||||
if (seg->type == JPC_SEG_MQ) {
|
||||
if (!cblk->mqdec) {
|
||||
if (!(cblk->mqdec = jpc_mqdec_create(JPC_NUMCTXS, 0))) {
|
||||
return -1;
|
||||
}
|
||||
jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs);
|
||||
}
|
||||
jpc_mqdec_setinput(cblk->mqdec, seg->stream);
|
||||
jpc_mqdec_init(cblk->mqdec);
|
||||
} else {
|
||||
assert(seg->type == JPC_SEG_RAW);
|
||||
if (!cblk->nulldec) {
|
||||
if (!(cblk->nulldec = jpc_bitstream_sopen(seg->stream, "r"))) {
|
||||
assert(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < seg->numpasses; ++i) {
|
||||
if (cblk->numimsbs > band->numbps) {
|
||||
ccp = &tile->cp->ccps[compno];
|
||||
if (ccp->roishift <= 0) {
|
||||
jas_eprintf("warning: corrupt code stream\n");
|
||||
} else {
|
||||
if (cblk->numimsbs < ccp->roishift - band->numbps) {
|
||||
jas_eprintf("warning: corrupt code stream\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
bpno = band->roishift + band->numbps - 1 - (cblk->numimsbs +
|
||||
(seg->passno + i - cblk->firstpassno + 2) / 3);
|
||||
if (bpno < 0) {
|
||||
goto premature_exit;
|
||||
}
|
||||
#if 1
|
||||
passtype = (seg->passno + i + 2) % 3;
|
||||
#else
|
||||
passtype = JPC_PASSTYPE(seg->passno + i + 2);
|
||||
#endif
|
||||
assert(bpno >= 0 && bpno < 31);
|
||||
switch (passtype) {
|
||||
case JPC_SIGPASS:
|
||||
ret = (seg->type == JPC_SEG_MQ) ? dec_sigpass(dec,
|
||||
cblk->mqdec, bpno, band->orient,
|
||||
(tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
|
||||
cblk->flags, cblk->data) :
|
||||
dec_rawsigpass(dec, cblk->nulldec, bpno,
|
||||
(tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
|
||||
cblk->flags, cblk->data);
|
||||
break;
|
||||
case JPC_REFPASS:
|
||||
ret = (seg->type == JPC_SEG_MQ) ?
|
||||
dec_refpass(dec, cblk->mqdec, bpno,
|
||||
(tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
|
||||
cblk->flags, cblk->data) :
|
||||
dec_rawrefpass(dec, cblk->nulldec, bpno,
|
||||
(tile->cp->ccps[compno].cblkctx & JPC_COX_VSC) != 0,
|
||||
cblk->flags, cblk->data);
|
||||
break;
|
||||
case JPC_CLNPASS:
|
||||
assert(seg->type == JPC_SEG_MQ);
|
||||
ret = dec_clnpass(dec, cblk->mqdec, bpno,
|
||||
band->orient, (tile->cp->ccps[compno].cblkctx &
|
||||
JPC_COX_VSC) != 0, (tile->cp->ccps[compno].cblkctx &
|
||||
JPC_COX_SEGSYM) != 0, cblk->flags,
|
||||
cblk->data);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
/* Do we need to reset after each coding pass? */
|
||||
if (tile->cp->ccps[compno].cblkctx & JPC_COX_RESET) {
|
||||
jpc_mqdec_setctxs(cblk->mqdec, JPC_NUMCTXS, jpc_mqctxs);
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
jas_eprintf("coding pass failed passtype=%d segtype=%d\n", passtype, seg->type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (seg->type == JPC_SEG_MQ) {
|
||||
/* Note: dont destroy mq decoder because context info will be lost */
|
||||
} else {
|
||||
assert(seg->type == JPC_SEG_RAW);
|
||||
if (tile->cp->ccps[compno].cblkctx & JPC_COX_PTERM) {
|
||||
fillmask = 0x7f;
|
||||
filldata = 0x2a;
|
||||
} else {
|
||||
fillmask = 0;
|
||||
filldata = 0;
|
||||
}
|
||||
if ((ret = jpc_bitstream_inalign(cblk->nulldec, fillmask,
|
||||
filldata)) < 0) {
|
||||
return -1;
|
||||
} else if (ret > 0) {
|
||||
jas_eprintf("warning: bad termination pattern detected\n");
|
||||
}
|
||||
jpc_bitstream_close(cblk->nulldec);
|
||||
cblk->nulldec = 0;
|
||||
}
|
||||
|
||||
cblk->curseg = seg->next;
|
||||
jpc_seglist_remove(&cblk->segs, seg);
|
||||
jpc_seg_destroy(seg);
|
||||
seg = cblk->curseg;
|
||||
}
|
||||
|
||||
assert(dopartial ? (!cblk->curseg) : 1);
|
||||
|
||||
premature_exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for significance pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf, orient, mqdec, vcausalflag) \
|
||||
{ \
|
||||
int f; \
|
||||
int v; \
|
||||
f = *(fp); \
|
||||
if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
|
||||
jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO(f, (orient))); \
|
||||
JPC_T1D_GETBIT((mqdec), v, "SIG", "ZC"); \
|
||||
if (v) { \
|
||||
jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \
|
||||
JPC_T1D_GETBIT((mqdec), v, "SIG", "SC"); \
|
||||
v ^= JPC_GETSPB(f); \
|
||||
JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
*(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \
|
||||
} \
|
||||
*(fp) |= JPC_VISIT; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int dec_sigpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient,
|
||||
int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int one;
|
||||
int half;
|
||||
int oneplushalf;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
jpc_fix_t *fp;
|
||||
int frowstep;
|
||||
int fstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
int drowstep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
int k;
|
||||
|
||||
/* Avoid compiler warning about unused parameters. */
|
||||
dec = 0;
|
||||
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << bitpos;
|
||||
half = one >> 1;
|
||||
oneplushalf = one | half;
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
/* Process first sample in vertical scan. */
|
||||
jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
|
||||
orient, mqdec, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process second sample in vertical scan. */
|
||||
jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
|
||||
orient, mqdec, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process third sample in vertical scan. */
|
||||
jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
|
||||
orient, mqdec, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process fourth sample in vertical scan. */
|
||||
jpc_sigpass_step(fp, frowstep, dp, bitpos, oneplushalf,
|
||||
orient, mqdec, 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf, in, vcausalflag) \
|
||||
{ \
|
||||
jpc_fix_t f = *(fp); \
|
||||
jpc_fix_t v; \
|
||||
if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
|
||||
JPC_T1D_RAWGETBIT(in, v, "SIG", "ZC"); \
|
||||
if (v < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
if (v) { \
|
||||
JPC_T1D_RAWGETBIT(in, v, "SIG", "SC"); \
|
||||
if (v < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
*(dp) = v ? (-oneplushalf) : (oneplushalf); \
|
||||
} \
|
||||
*(fp) |= JPC_VISIT; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int dec_rawsigpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag,
|
||||
jas_matrix_t *flags, jas_matrix_t *data)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int one;
|
||||
int half;
|
||||
int oneplushalf;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
jpc_fix_t *fp;
|
||||
int frowstep;
|
||||
int fstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
int drowstep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
|
||||
/* Avoid compiler warning about unused parameters. */
|
||||
dec = 0;
|
||||
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << bitpos;
|
||||
half = one >> 1;
|
||||
oneplushalf = one | half;
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
/* Process first sample in vertical scan. */
|
||||
jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
|
||||
in, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process second sample in vertical scan. */
|
||||
jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
|
||||
in, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process third sample in vertical scan. */
|
||||
jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
|
||||
in, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process fourth sample in vertical scan. */
|
||||
jpc_rawsigpass_step(fp, frowstep, dp, oneplushalf,
|
||||
in, 0);
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for refinement pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, vcausalflag) \
|
||||
{ \
|
||||
int v; \
|
||||
int t; \
|
||||
if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
|
||||
jpc_mqdec_setcurctx((mqdec), JPC_GETMAGCTXNO(*(fp))); \
|
||||
JPC_T1D_GETBITNOSKEW((mqdec), v, "REF", "MR"); \
|
||||
t = (v ? (poshalf) : (neghalf)); \
|
||||
*(dp) += (*(dp) < 0) ? (-t) : t; \
|
||||
*(fp) |= JPC_REFINE; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int dec_refpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos,
|
||||
int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
int one;
|
||||
int poshalf;
|
||||
int neghalf;
|
||||
jpc_fix_t *fp;
|
||||
int frowstep;
|
||||
int fstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
int drowstep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
int k;
|
||||
|
||||
/* Avoid compiler warning about unused parameters. */
|
||||
dec = 0;
|
||||
vcausalflag = 0;
|
||||
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << bitpos;
|
||||
poshalf = one >> 1;
|
||||
neghalf = (bitpos > 0) ? (-poshalf) : (-1);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
/* Process first sample in vertical scan. */
|
||||
jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec,
|
||||
vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process second sample in vertical scan. */
|
||||
jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process third sample in vertical scan. */
|
||||
jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process fourth sample in vertical scan. */
|
||||
jpc_refpass_step(fp, dp, poshalf, neghalf, mqdec, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, vcausalflag) \
|
||||
{ \
|
||||
jpc_fix_t v; \
|
||||
jpc_fix_t t; \
|
||||
if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
|
||||
JPC_T1D_RAWGETBIT(in, v, "REF", "MAGREF"); \
|
||||
if (v < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
t = (v ? poshalf : neghalf); \
|
||||
*(dp) += (*(dp) < 0) ? (-t) : t; \
|
||||
*(fp) |= JPC_REFINE; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int dec_rawrefpass(jpc_dec_t *dec, jpc_bitstream_t *in, int bitpos, int vcausalflag,
|
||||
jas_matrix_t *flags, jas_matrix_t *data)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
int one;
|
||||
int poshalf;
|
||||
int neghalf;
|
||||
jpc_fix_t *fp;
|
||||
int frowstep;
|
||||
int fstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
int drowstep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
|
||||
/* Avoid compiler warning about unused parameters. */
|
||||
dec = 0;
|
||||
vcausalflag = 0;
|
||||
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << bitpos;
|
||||
poshalf = one >> 1;
|
||||
neghalf = (bitpos > 0) ? (-poshalf) : (-1);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
/* Process first sample in vertical scan. */
|
||||
jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in,
|
||||
vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process second sample in vertical scan. */
|
||||
jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process third sample in vertical scan. */
|
||||
jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process fourth sample in vertical scan. */
|
||||
jpc_rawrefpass_step(fp, dp, poshalf, neghalf, in, 0);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for cleanup pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient, mqdec, flabel, plabel, vcausalflag) \
|
||||
{ \
|
||||
int v; \
|
||||
flabel \
|
||||
if (!((f) & (JPC_SIG | JPC_VISIT))) { \
|
||||
jpc_mqdec_setcurctx((mqdec), JPC_GETZCCTXNO((f), (orient))); \
|
||||
JPC_T1D_GETBIT((mqdec), v, "CLN", "ZC"); \
|
||||
if (v) { \
|
||||
plabel \
|
||||
/* Coefficient is significant. */ \
|
||||
jpc_mqdec_setcurctx((mqdec), JPC_GETSCCTXNO(f)); \
|
||||
JPC_T1D_GETBIT((mqdec), v, "CLN", "SC"); \
|
||||
v ^= JPC_GETSPB(f); \
|
||||
*(dp) = (v) ? (-(oneplushalf)) : (oneplushalf); \
|
||||
JPC_UPDATEFLAGS4((fp), (frowstep), v, (vcausalflag)); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
} \
|
||||
} \
|
||||
/* XXX - Is this correct? Can aggregation cause some VISIT bits not to be reset? Check. */ \
|
||||
*(fp) &= ~JPC_VISIT; \
|
||||
}
|
||||
|
||||
static int dec_clnpass(jpc_dec_t *dec, register jpc_mqdec_t *mqdec, int bitpos, int orient,
|
||||
int vcausalflag, int segsymflag, jas_matrix_t *flags, jas_matrix_t *data)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int vscanlen;
|
||||
int v;
|
||||
int half;
|
||||
int runlen;
|
||||
int f;
|
||||
int width;
|
||||
int height;
|
||||
int one;
|
||||
int oneplushalf;
|
||||
|
||||
jpc_fix_t *fp;
|
||||
int frowstep;
|
||||
int fstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
|
||||
jpc_fix_t *dp;
|
||||
int drowstep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
|
||||
/* Avoid compiler warning about unused parameters. */
|
||||
dec = 0;
|
||||
|
||||
one = 1 << bitpos;
|
||||
half = one >> 1;
|
||||
oneplushalf = one | half;
|
||||
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = 0; i < height; i += 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(4, height - i);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
if (vscanlen >= 4 && (!((*fp) & (JPC_SIG | JPC_VISIT |
|
||||
JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) & (JPC_SIG |
|
||||
JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) &
|
||||
(JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep,
|
||||
!((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) {
|
||||
|
||||
jpc_mqdec_setcurctx(mqdec, JPC_AGGCTXNO);
|
||||
JPC_T1D_GETBIT(mqdec, v, "CLN", "AGG");
|
||||
if (!v) {
|
||||
continue;
|
||||
}
|
||||
jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO);
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL");
|
||||
runlen = v;
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "RL");
|
||||
runlen = (runlen << 1) | v;
|
||||
f = *(fp = fvscanstart + frowstep * runlen);
|
||||
dp = dvscanstart + drowstep * runlen;
|
||||
k = vscanlen - runlen;
|
||||
switch (runlen) {
|
||||
case 0:
|
||||
goto clnpass_partial0;
|
||||
break;
|
||||
case 1:
|
||||
goto clnpass_partial1;
|
||||
break;
|
||||
case 2:
|
||||
goto clnpass_partial2;
|
||||
break;
|
||||
case 3:
|
||||
goto clnpass_partial3;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
f = *(fp = fvscanstart);
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
goto clnpass_full0;
|
||||
}
|
||||
|
||||
/* Process first sample in vertical scan. */
|
||||
jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
|
||||
mqdec, clnpass_full0:, clnpass_partial0:,
|
||||
vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process second sample in vertical scan. */
|
||||
f = *fp;
|
||||
jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
|
||||
mqdec, ;, clnpass_partial1:, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process third sample in vertical scan. */
|
||||
f = *fp;
|
||||
jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
|
||||
mqdec, ;, clnpass_partial2:, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
/* Process fourth sample in vertical scan. */
|
||||
f = *fp;
|
||||
jpc_clnpass_step(f, fp, frowstep, dp, oneplushalf, orient,
|
||||
mqdec, ;, clnpass_partial3:, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (segsymflag) {
|
||||
int segsymval;
|
||||
segsymval = 0;
|
||||
jpc_mqdec_setcurctx(mqdec, JPC_UCTXNO);
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
|
||||
segsymval = (segsymval << 1) | (v & 1);
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
|
||||
segsymval = (segsymval << 1) | (v & 1);
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
|
||||
segsymval = (segsymval << 1) | (v & 1);
|
||||
JPC_T1D_GETBITNOSKEW(mqdec, v, "CLN", "SEGSYM");
|
||||
segsymval = (segsymval << 1) | (v & 1);
|
||||
if (segsymval != 0xa) {
|
||||
jas_eprintf("warning: bad segmentation symbol\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 1 Decoder
|
||||
*
|
||||
* $Id: jpc_t1dec.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T1DEC_H
|
||||
#define JPC_T1DEC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jpc_dec.h"
|
||||
#include "jpc_mqdec.h"
|
||||
#include "jpc_t1cod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Decode all of the code blocks for a particular tile. */
|
||||
int jpc_dec_decodecblks(jpc_dec_t *dec, jpc_dec_tile_t *tile);
|
||||
|
||||
#endif
|
||||
Vendored
+959
@@ -0,0 +1,959 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 1 Encoder
|
||||
*
|
||||
* $Id: jpc_t1enc.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
#include "jpc_t1enc.h"
|
||||
#include "jpc_t1cod.h"
|
||||
#include "jpc_enc.h"
|
||||
#include "jpc_cod.h"
|
||||
#include "jpc_math.h"
|
||||
|
||||
static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int,
|
||||
jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
|
||||
|
||||
static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int, jas_matrix_t *flags,
|
||||
jas_matrix_t *data, int term, long *nmsedec);
|
||||
|
||||
static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int,
|
||||
int, jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
|
||||
|
||||
static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int,
|
||||
jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
|
||||
|
||||
static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int,
|
||||
jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for encoding code blocks.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encode all of the code blocks associated with the current tile. */
|
||||
int jpc_enc_enccblks(jpc_enc_t *enc)
|
||||
{
|
||||
jpc_enc_tcmpt_t *tcmpt;
|
||||
jpc_enc_tcmpt_t *endcomps;
|
||||
jpc_enc_rlvl_t *lvl;
|
||||
jpc_enc_rlvl_t *endlvls;
|
||||
jpc_enc_band_t *band;
|
||||
jpc_enc_band_t *endbands;
|
||||
jpc_enc_cblk_t *cblk;
|
||||
jpc_enc_cblk_t *endcblks;
|
||||
int i;
|
||||
int j;
|
||||
int mx;
|
||||
int bmx;
|
||||
int v;
|
||||
jpc_enc_tile_t *tile;
|
||||
uint_fast32_t prcno;
|
||||
jpc_enc_prc_t *prc;
|
||||
|
||||
tile = enc->curtile;
|
||||
|
||||
endcomps = &tile->tcmpts[tile->numtcmpts];
|
||||
for (tcmpt = tile->tcmpts; tcmpt != endcomps; ++tcmpt) {
|
||||
endlvls = &tcmpt->rlvls[tcmpt->numrlvls];
|
||||
for (lvl = tcmpt->rlvls; lvl != endlvls; ++lvl) {
|
||||
if (!lvl->bands) {
|
||||
continue;
|
||||
}
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
bmx = 0;
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
mx = 0;
|
||||
for (i = 0; i < jas_matrix_numrows(cblk->data); ++i) {
|
||||
for (j = 0; j < jas_matrix_numcols(cblk->data); ++j) {
|
||||
v = abs(jas_matrix_get(cblk->data, i, j));
|
||||
if (v > mx) {
|
||||
mx = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mx > bmx) {
|
||||
bmx = mx;
|
||||
}
|
||||
cblk->numbps = JAS_MAX(jpc_firstone(mx) + 1 - JPC_NUMEXTRABITS, 0);
|
||||
}
|
||||
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
cblk->numimsbs = band->numbps - cblk->numbps;
|
||||
assert(cblk->numimsbs >= 0);
|
||||
}
|
||||
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
if (jpc_enc_enccblk(enc, cblk->stream, tcmpt, band, cblk)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getthebyte(jas_stream_t *in, long off)
|
||||
{
|
||||
int c;
|
||||
long oldpos;
|
||||
oldpos = jas_stream_tell(in);
|
||||
assert(oldpos >= 0);
|
||||
jas_stream_seek(in, off, SEEK_SET);
|
||||
c = jas_stream_peekc(in);
|
||||
jas_stream_seek(in, oldpos, SEEK_SET);
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Encode a single code block. */
|
||||
int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *tcmpt, jpc_enc_band_t *band, jpc_enc_cblk_t *cblk)
|
||||
{
|
||||
jpc_enc_pass_t *pass;
|
||||
jpc_enc_pass_t *endpasses;
|
||||
int bitpos;
|
||||
int n;
|
||||
int adjust;
|
||||
int ret;
|
||||
int passtype;
|
||||
int t;
|
||||
jpc_bitstream_t *bout;
|
||||
jpc_enc_pass_t *termpass;
|
||||
jpc_enc_rlvl_t *rlvl;
|
||||
int vcausal;
|
||||
int segsym;
|
||||
int termmode;
|
||||
int c;
|
||||
|
||||
bout = 0;
|
||||
rlvl = band->rlvl;
|
||||
|
||||
cblk->stream = jas_stream_memopen(0, 0);
|
||||
assert(cblk->stream);
|
||||
cblk->mqenc = jpc_mqenc_create(JPC_NUMCTXS, cblk->stream);
|
||||
assert(cblk->mqenc);
|
||||
jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs);
|
||||
|
||||
cblk->numpasses = (cblk->numbps > 0) ? (3 * cblk->numbps - 2) : 0;
|
||||
if (cblk->numpasses > 0) {
|
||||
cblk->passes = jas_alloc2(cblk->numpasses, sizeof(jpc_enc_pass_t));
|
||||
assert(cblk->passes);
|
||||
} else {
|
||||
cblk->passes = 0;
|
||||
}
|
||||
endpasses = &cblk->passes[cblk->numpasses];
|
||||
for (pass = cblk->passes; pass != endpasses; ++pass) {
|
||||
pass->start = 0;
|
||||
pass->end = 0;
|
||||
pass->term = JPC_ISTERMINATED(pass - cblk->passes, 0, cblk->numpasses, (tcmpt->cblksty & JPC_COX_TERMALL) != 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0);
|
||||
pass->type = JPC_SEGTYPE(pass - cblk->passes, 0, (tcmpt->cblksty & JPC_COX_LAZY) != 0);
|
||||
pass->lyrno = -1;
|
||||
if (pass == endpasses - 1) {
|
||||
assert(pass->term == 1);
|
||||
pass->term = 1;
|
||||
}
|
||||
}
|
||||
|
||||
cblk->flags = jas_matrix_create(jas_matrix_numrows(cblk->data) + 2,
|
||||
jas_matrix_numcols(cblk->data) + 2);
|
||||
assert(cblk->flags);
|
||||
|
||||
|
||||
bitpos = cblk->numbps - 1;
|
||||
pass = cblk->passes;
|
||||
n = cblk->numpasses;
|
||||
while (--n >= 0) {
|
||||
|
||||
if (pass->type == JPC_SEG_MQ) {
|
||||
/* NOP */
|
||||
} else {
|
||||
assert(pass->type == JPC_SEG_RAW);
|
||||
if (!bout) {
|
||||
bout = jpc_bitstream_sopen(cblk->stream, "w");
|
||||
assert(bout);
|
||||
}
|
||||
}
|
||||
|
||||
#if 1
|
||||
passtype = (pass - cblk->passes + 2) % 3;
|
||||
#else
|
||||
passtype = JPC_PASSTYPE(pass - cblk->passes + 2);
|
||||
#endif
|
||||
pass->start = jas_stream_tell(cblk->stream);
|
||||
#if 0
|
||||
assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream));
|
||||
#endif
|
||||
assert(bitpos >= 0);
|
||||
vcausal = (tcmpt->cblksty & JPC_COX_VSC) != 0;
|
||||
segsym = (tcmpt->cblksty & JPC_COX_SEGSYM) != 0;
|
||||
if (pass->term) {
|
||||
termmode = ((tcmpt->cblksty & JPC_COX_PTERM) ?
|
||||
JPC_MQENC_PTERM : JPC_MQENC_DEFTERM) + 1;
|
||||
} else {
|
||||
termmode = 0;
|
||||
}
|
||||
switch (passtype) {
|
||||
case JPC_SIGPASS:
|
||||
ret = (pass->type == JPC_SEG_MQ) ? jpc_encsigpass(cblk->mqenc,
|
||||
bitpos, band->orient, vcausal, cblk->flags,
|
||||
cblk->data, termmode, &pass->nmsedec) :
|
||||
jpc_encrawsigpass(bout, bitpos, vcausal, cblk->flags,
|
||||
cblk->data, termmode, &pass->nmsedec);
|
||||
break;
|
||||
case JPC_REFPASS:
|
||||
ret = (pass->type == JPC_SEG_MQ) ? jpc_encrefpass(cblk->mqenc,
|
||||
bitpos, vcausal, cblk->flags, cblk->data, termmode,
|
||||
&pass->nmsedec) : jpc_encrawrefpass(bout, bitpos,
|
||||
vcausal, cblk->flags, cblk->data, termmode,
|
||||
&pass->nmsedec);
|
||||
break;
|
||||
case JPC_CLNPASS:
|
||||
assert(pass->type == JPC_SEG_MQ);
|
||||
ret = jpc_encclnpass(cblk->mqenc, bitpos, band->orient,
|
||||
vcausal, segsym, cblk->flags, cblk->data, termmode,
|
||||
&pass->nmsedec);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pass->type == JPC_SEG_MQ) {
|
||||
if (pass->term) {
|
||||
jpc_mqenc_init(cblk->mqenc);
|
||||
}
|
||||
jpc_mqenc_getstate(cblk->mqenc, &pass->mqencstate);
|
||||
pass->end = jas_stream_tell(cblk->stream);
|
||||
if (tcmpt->cblksty & JPC_COX_RESET) {
|
||||
jpc_mqenc_setctxs(cblk->mqenc, JPC_NUMCTXS, jpc_mqctxs);
|
||||
}
|
||||
} else {
|
||||
if (pass->term) {
|
||||
if (jpc_bitstream_pending(bout)) {
|
||||
jpc_bitstream_outalign(bout, 0x2a);
|
||||
}
|
||||
jpc_bitstream_close(bout);
|
||||
bout = 0;
|
||||
pass->end = jas_stream_tell(cblk->stream);
|
||||
} else {
|
||||
pass->end = jas_stream_tell(cblk->stream) +
|
||||
jpc_bitstream_pending(bout);
|
||||
/* NOTE - This will not work. need to adjust by # of pending output bytes */
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
/* XXX - This assertion fails sometimes when various coding modes are used.
|
||||
This seems to be harmless, but why does it happen at all? */
|
||||
assert(jas_stream_tell(cblk->stream) == jas_stream_getrwcount(cblk->stream));
|
||||
#endif
|
||||
|
||||
pass->wmsedec = jpc_fixtodbl(band->rlvl->tcmpt->synweight) *
|
||||
jpc_fixtodbl(band->rlvl->tcmpt->synweight) *
|
||||
jpc_fixtodbl(band->synweight) *
|
||||
jpc_fixtodbl(band->synweight) *
|
||||
jpc_fixtodbl(band->absstepsize) * jpc_fixtodbl(band->absstepsize) *
|
||||
((double) (1 << bitpos)) * ((double)(1 << bitpos)) *
|
||||
jpc_fixtodbl(pass->nmsedec);
|
||||
pass->cumwmsedec = pass->wmsedec;
|
||||
if (pass != cblk->passes) {
|
||||
pass->cumwmsedec += pass[-1].cumwmsedec;
|
||||
}
|
||||
if (passtype == JPC_CLNPASS) {
|
||||
--bitpos;
|
||||
}
|
||||
++pass;
|
||||
}
|
||||
|
||||
#if 0
|
||||
dump_passes(cblk->passes, cblk->numpasses, cblk);
|
||||
#endif
|
||||
|
||||
n = 0;
|
||||
endpasses = &cblk->passes[cblk->numpasses];
|
||||
for (pass = cblk->passes; pass != endpasses; ++pass) {
|
||||
if (pass->start < n) {
|
||||
pass->start = n;
|
||||
}
|
||||
if (pass->end < n) {
|
||||
pass->end = n;
|
||||
}
|
||||
if (!pass->term) {
|
||||
termpass = pass;
|
||||
while (termpass - pass < cblk->numpasses &&
|
||||
!termpass->term) {
|
||||
++termpass;
|
||||
}
|
||||
if (pass->type == JPC_SEG_MQ) {
|
||||
t = (pass->mqencstate.lastbyte == 0xff) ? 1 : 0;
|
||||
if (pass->mqencstate.ctreg >= 5) {
|
||||
adjust = 4 + t;
|
||||
} else {
|
||||
adjust = 5 + t;
|
||||
}
|
||||
pass->end += adjust;
|
||||
}
|
||||
if (pass->end > termpass->end) {
|
||||
pass->end = termpass->end;
|
||||
}
|
||||
if ((c = getthebyte(cblk->stream, pass->end - 1)) == EOF) {
|
||||
abort();
|
||||
}
|
||||
if (c == 0xff) {
|
||||
++pass->end;
|
||||
}
|
||||
n = JAS_MAX(n, pass->end);
|
||||
} else {
|
||||
n = JAS_MAX(n, pass->end);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
dump_passes(cblk->passes, cblk->numpasses, cblk);
|
||||
#endif
|
||||
|
||||
if (bout) {
|
||||
jpc_bitstream_close(bout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for significance pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define sigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, orient, mqenc, vcausalflag) \
|
||||
{ \
|
||||
int f; \
|
||||
int v; \
|
||||
f = *(fp); \
|
||||
if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
|
||||
v = (abs(*(dp)) & (one)) ? 1 : 0; \
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \
|
||||
jpc_mqenc_putbit(mqenc, v); \
|
||||
if (v) { \
|
||||
*(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
|
||||
v = ((*(dp) < 0) ? 1 : 0); \
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_GETSCCTXNO(f)); \
|
||||
jpc_mqenc_putbit(mqenc, v ^ JPC_GETSPB(f)); \
|
||||
JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
} \
|
||||
*(fp) |= JPC_VISIT; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int jpc_encsigpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag,
|
||||
jas_matrix_t *flags, jas_matrix_t *data, int term, long *nmsedec)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int one;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
int frowstep;
|
||||
int drowstep;
|
||||
int fstripestep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *fp;
|
||||
jpc_fix_t *dp;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
int k;
|
||||
|
||||
*nmsedec = 0;
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << (bitpos + JPC_NUMEXTRABITS);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
sigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, orient, mqenc, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
sigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, orient, mqenc, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
sigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, orient, mqenc, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
sigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, orient, mqenc, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (term) {
|
||||
jpc_mqenc_flush(mqenc, term - 1);
|
||||
}
|
||||
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
|
||||
#define rawsigpass_step(fp, frowstep, dp, bitpos, one, nmsedec, out, vcausalflag) \
|
||||
{ \
|
||||
jpc_fix_t f = *(fp); \
|
||||
jpc_fix_t v; \
|
||||
if ((f & JPC_OTHSIGMSK) && !(f & (JPC_SIG | JPC_VISIT))) { \
|
||||
v = (abs(*(dp)) & (one)) ? 1 : 0; \
|
||||
if ((jpc_bitstream_putbit((out), v)) == EOF) { \
|
||||
return -1; \
|
||||
} \
|
||||
if (v) { \
|
||||
*(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
|
||||
v = ((*(dp) < 0) ? 1 : 0); \
|
||||
if (jpc_bitstream_putbit(out, v) == EOF) { \
|
||||
return -1; \
|
||||
} \
|
||||
JPC_UPDATEFLAGS4(fp, frowstep, v, vcausalflag); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
} \
|
||||
*(fp) |= JPC_VISIT; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int jpc_encrawsigpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags,
|
||||
jas_matrix_t *data, int term, long *nmsedec)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int one;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
int frowstep;
|
||||
int drowstep;
|
||||
int fstripestep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *fp;
|
||||
jpc_fix_t *dp;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
|
||||
*nmsedec = 0;
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << (bitpos + JPC_NUMEXTRABITS);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
rawsigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, out, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
rawsigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, out, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
rawsigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, out, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
rawsigpass_step(fp, frowstep, dp, bitpos, one,
|
||||
nmsedec, out, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (term) {
|
||||
jpc_bitstream_outalign(out, 0x2a);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for refinement pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define refpass_step(fp, dp, bitpos, one, nmsedec, mqenc, vcausalflag) \
|
||||
{ \
|
||||
int v; \
|
||||
if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
|
||||
(d) = *(dp); \
|
||||
*(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \
|
||||
jpc_mqenc_setcurctx((mqenc), JPC_GETMAGCTXNO(*(fp))); \
|
||||
v = (abs(d) & (one)) ? 1 : 0; \
|
||||
jpc_mqenc_putbit((mqenc), v); \
|
||||
*(fp) |= JPC_REFINE; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int jpc_encrefpass(jpc_mqenc_t *mqenc, int bitpos, int vcausalflag, jas_matrix_t *flags, jas_matrix_t *data,
|
||||
int term, long *nmsedec)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int one;
|
||||
int vscanlen;
|
||||
int d;
|
||||
int width;
|
||||
int height;
|
||||
int frowstep;
|
||||
int drowstep;
|
||||
int fstripestep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
jpc_fix_t *fp;
|
||||
int k;
|
||||
|
||||
*nmsedec = 0;
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << (bitpos + JPC_NUMEXTRABITS);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
refpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
mqenc, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
refpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
mqenc, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
refpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
mqenc, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
refpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
mqenc, 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (term) {
|
||||
jpc_mqenc_flush(mqenc, term - 1);
|
||||
}
|
||||
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
|
||||
#define rawrefpass_step(fp, dp, bitpos, one, nmsedec, out, vcausalflag) \
|
||||
{ \
|
||||
jpc_fix_t d; \
|
||||
jpc_fix_t v; \
|
||||
if (((*(fp)) & (JPC_SIG | JPC_VISIT)) == JPC_SIG) { \
|
||||
d = *(dp); \
|
||||
*(nmsedec) += JPC_GETREFNMSEDEC(abs(d), (bitpos) + JPC_NUMEXTRABITS); \
|
||||
v = (abs(d) & (one)) ? 1 : 0; \
|
||||
if (jpc_bitstream_putbit((out), v) == EOF) { \
|
||||
return -1; \
|
||||
} \
|
||||
*(fp) |= JPC_REFINE; \
|
||||
} \
|
||||
}
|
||||
|
||||
static int jpc_encrawrefpass(jpc_bitstream_t *out, int bitpos, int vcausalflag, jas_matrix_t *flags,
|
||||
jas_matrix_t *data, int term, long *nmsedec)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int one;
|
||||
int vscanlen;
|
||||
int width;
|
||||
int height;
|
||||
int frowstep;
|
||||
int drowstep;
|
||||
int fstripestep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
jpc_fix_t *dp;
|
||||
jpc_fix_t *fp;
|
||||
|
||||
*nmsedec = 0;
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << (bitpos + JPC_NUMEXTRABITS);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
|
||||
rawrefpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
out, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
rawrefpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
out, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
rawrefpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
out, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
rawrefpass_step(fp, dp, bitpos, one, nmsedec,
|
||||
out, vcausalflag);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (term) {
|
||||
jpc_bitstream_outalign(out, 0x2a);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for cleanup pass.
|
||||
\******************************************************************************/
|
||||
|
||||
#define clnpass_step(fp, frowstep, dp, bitpos, one, orient, nmsedec, mqenc, label1, label2, vcausalflag) \
|
||||
{ \
|
||||
int f; \
|
||||
int v; \
|
||||
label1 \
|
||||
f = *(fp); \
|
||||
if (!(f & (JPC_SIG | JPC_VISIT))) { \
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_GETZCCTXNO(f, (orient))); \
|
||||
v = (abs(*(dp)) & (one)) ? 1 : 0; \
|
||||
jpc_mqenc_putbit((mqenc), v); \
|
||||
if (v) { \
|
||||
label2 \
|
||||
f = *(fp); \
|
||||
/* Coefficient is significant. */ \
|
||||
*(nmsedec) += JPC_GETSIGNMSEDEC(abs(*(dp)), (bitpos) + JPC_NUMEXTRABITS); \
|
||||
jpc_mqenc_setcurctx((mqenc), JPC_GETSCCTXNO(f)); \
|
||||
v = ((*(dp) < 0) ? 1 : 0); \
|
||||
jpc_mqenc_putbit((mqenc), v ^ JPC_GETSPB(f)); \
|
||||
JPC_UPDATEFLAGS4((fp), (frowstep), v, vcausalflag); \
|
||||
*(fp) |= JPC_SIG; \
|
||||
} \
|
||||
} \
|
||||
*(fp) &= ~JPC_VISIT; \
|
||||
}
|
||||
|
||||
static int jpc_encclnpass(jpc_mqenc_t *mqenc, int bitpos, int orient, int vcausalflag, int segsymflag, jas_matrix_t *flags,
|
||||
jas_matrix_t *data, int term, long *nmsedec)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int vscanlen;
|
||||
int v;
|
||||
int runlen;
|
||||
jpc_fix_t *fp;
|
||||
int width;
|
||||
int height;
|
||||
jpc_fix_t *dp;
|
||||
int one;
|
||||
int frowstep;
|
||||
int drowstep;
|
||||
int fstripestep;
|
||||
int dstripestep;
|
||||
jpc_fix_t *fstripestart;
|
||||
jpc_fix_t *dstripestart;
|
||||
jpc_fix_t *fvscanstart;
|
||||
jpc_fix_t *dvscanstart;
|
||||
|
||||
*nmsedec = 0;
|
||||
width = jas_matrix_numcols(data);
|
||||
height = jas_matrix_numrows(data);
|
||||
frowstep = jas_matrix_rowstep(flags);
|
||||
drowstep = jas_matrix_rowstep(data);
|
||||
fstripestep = frowstep << 2;
|
||||
dstripestep = drowstep << 2;
|
||||
|
||||
one = 1 << (bitpos + JPC_NUMEXTRABITS);
|
||||
|
||||
fstripestart = jas_matrix_getref(flags, 1, 1);
|
||||
dstripestart = jas_matrix_getref(data, 0, 0);
|
||||
for (i = height; i > 0; i -= 4, fstripestart += fstripestep,
|
||||
dstripestart += dstripestep) {
|
||||
fvscanstart = fstripestart;
|
||||
dvscanstart = dstripestart;
|
||||
vscanlen = JAS_MIN(i, 4);
|
||||
for (j = width; j > 0; --j, ++fvscanstart, ++dvscanstart) {
|
||||
|
||||
fp = fvscanstart;
|
||||
if (vscanlen >= 4 && !((*fp) & (JPC_SIG | JPC_VISIT |
|
||||
JPC_OTHSIGMSK)) && (fp += frowstep, !((*fp) & (JPC_SIG |
|
||||
JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep, !((*fp) &
|
||||
(JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK))) && (fp += frowstep,
|
||||
!((*fp) & (JPC_SIG | JPC_VISIT | JPC_OTHSIGMSK)))) {
|
||||
dp = dvscanstart;
|
||||
for (k = 0; k < vscanlen; ++k) {
|
||||
v = (abs(*dp) & one) ? 1 : 0;
|
||||
if (v) {
|
||||
break;
|
||||
}
|
||||
dp += drowstep;
|
||||
}
|
||||
runlen = k;
|
||||
if (runlen >= 4) {
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO);
|
||||
jpc_mqenc_putbit(mqenc, 0);
|
||||
continue;
|
||||
}
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_AGGCTXNO);
|
||||
jpc_mqenc_putbit(mqenc, 1);
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO);
|
||||
jpc_mqenc_putbit(mqenc, runlen >> 1);
|
||||
jpc_mqenc_putbit(mqenc, runlen & 1);
|
||||
fp = fvscanstart + frowstep * runlen;
|
||||
dp = dvscanstart + drowstep * runlen;
|
||||
k = vscanlen - runlen;
|
||||
switch (runlen) {
|
||||
case 0:
|
||||
goto clnpass_partial0;
|
||||
break;
|
||||
case 1:
|
||||
goto clnpass_partial1;
|
||||
break;
|
||||
case 2:
|
||||
goto clnpass_partial2;
|
||||
break;
|
||||
case 3:
|
||||
goto clnpass_partial3;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
runlen = 0;
|
||||
fp = fvscanstart;
|
||||
dp = dvscanstart;
|
||||
k = vscanlen;
|
||||
goto clnpass_full0;
|
||||
}
|
||||
clnpass_step(fp, frowstep, dp, bitpos, one,
|
||||
orient, nmsedec, mqenc, clnpass_full0:, clnpass_partial0:, vcausalflag);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
clnpass_step(fp, frowstep, dp, bitpos, one,
|
||||
orient, nmsedec, mqenc, ;, clnpass_partial1:, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
clnpass_step(fp, frowstep, dp, bitpos, one,
|
||||
orient, nmsedec, mqenc, ;, clnpass_partial2:, 0);
|
||||
if (--k <= 0) {
|
||||
continue;
|
||||
}
|
||||
fp += frowstep;
|
||||
dp += drowstep;
|
||||
clnpass_step(fp, frowstep, dp, bitpos, one,
|
||||
orient, nmsedec, mqenc, ;, clnpass_partial3:, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (segsymflag) {
|
||||
jpc_mqenc_setcurctx(mqenc, JPC_UCTXNO);
|
||||
jpc_mqenc_putbit(mqenc, 1);
|
||||
jpc_mqenc_putbit(mqenc, 0);
|
||||
jpc_mqenc_putbit(mqenc, 1);
|
||||
jpc_mqenc_putbit(mqenc, 0);
|
||||
}
|
||||
|
||||
if (term) {
|
||||
jpc_mqenc_flush(mqenc, term - 1);
|
||||
}
|
||||
|
||||
return jpc_mqenc_error(mqenc) ? (-1) : 0;
|
||||
}
|
||||
Vendored
+93
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 1 Encoder
|
||||
*
|
||||
* $Id: jpc_t1enc.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T1ENC_H
|
||||
#define JPC_T1ENC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
#include "jpc_enc.h"
|
||||
#include "jpc_t1cod.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encode all of the code blocks. */
|
||||
int jpc_enc_enccblks(jpc_enc_t *enc);
|
||||
|
||||
/* Encode a single code block. */
|
||||
int jpc_enc_enccblk(jpc_enc_t *enc, jas_stream_t *out, jpc_enc_tcmpt_t *comp,
|
||||
jpc_enc_band_t *band, jpc_enc_cblk_t *cblk);
|
||||
|
||||
#endif
|
||||
Vendored
+684
@@ -0,0 +1,684 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier-2 Coding Library
|
||||
*
|
||||
* $Id: jpc_t2cod.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_t2cod.h"
|
||||
#include "jpc_math.h"
|
||||
|
||||
static int jpc_pi_nextlrcp(jpc_pi_t *pi);
|
||||
static int jpc_pi_nextrlcp(jpc_pi_t *pi);
|
||||
static int jpc_pi_nextrpcl(jpc_pi_t *pi);
|
||||
static int jpc_pi_nextpcrl(jpc_pi_t *pi);
|
||||
static int jpc_pi_nextcprl(jpc_pi_t *pi);
|
||||
|
||||
int jpc_pi_next(jpc_pi_t *pi)
|
||||
{
|
||||
jpc_pchg_t *pchg;
|
||||
int ret;
|
||||
|
||||
|
||||
for (;;) {
|
||||
|
||||
pi->valid = false;
|
||||
|
||||
if (!pi->pchg) {
|
||||
++pi->pchgno;
|
||||
pi->compno = 0;
|
||||
pi->rlvlno = 0;
|
||||
pi->prcno = 0;
|
||||
pi->lyrno = 0;
|
||||
pi->prgvolfirst = true;
|
||||
if (pi->pchgno < jpc_pchglist_numpchgs(pi->pchglist)) {
|
||||
pi->pchg = jpc_pchglist_get(pi->pchglist, pi->pchgno);
|
||||
} else if (pi->pchgno == jpc_pchglist_numpchgs(pi->pchglist)) {
|
||||
pi->pchg = &pi->defaultpchg;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
pchg = pi->pchg;
|
||||
switch (pchg->prgord) {
|
||||
case JPC_COD_LRCPPRG:
|
||||
ret = jpc_pi_nextlrcp(pi);
|
||||
break;
|
||||
case JPC_COD_RLCPPRG:
|
||||
ret = jpc_pi_nextrlcp(pi);
|
||||
break;
|
||||
case JPC_COD_RPCLPRG:
|
||||
ret = jpc_pi_nextrpcl(pi);
|
||||
break;
|
||||
case JPC_COD_PCRLPRG:
|
||||
ret = jpc_pi_nextpcrl(pi);
|
||||
break;
|
||||
case JPC_COD_CPRLPRG:
|
||||
ret = jpc_pi_nextcprl(pi);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
if (!ret) {
|
||||
pi->valid = true;
|
||||
++pi->pktno;
|
||||
return 0;
|
||||
}
|
||||
pi->pchg = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int jpc_pi_nextlrcp(register jpc_pi_t *pi)
|
||||
{
|
||||
jpc_pchg_t *pchg;
|
||||
int *prclyrno;
|
||||
|
||||
pchg = pi->pchg;
|
||||
if (!pi->prgvolfirst) {
|
||||
prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->prgvolfirst = false;
|
||||
}
|
||||
|
||||
for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno <
|
||||
JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
|
||||
for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls &&
|
||||
pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) {
|
||||
for (pi->compno = pchg->compnostart, pi->picomp =
|
||||
&pi->picomps[pi->compno]; pi->compno < pi->numcomps
|
||||
&& pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
|
||||
++pi->picomp) {
|
||||
if (pi->rlvlno >= pi->picomp->numrlvls) {
|
||||
continue;
|
||||
}
|
||||
pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
|
||||
for (pi->prcno = 0, prclyrno =
|
||||
pi->pirlvl->prclyrnos; pi->prcno <
|
||||
pi->pirlvl->numprcs; ++pi->prcno,
|
||||
++prclyrno) {
|
||||
if (pi->lyrno >= *prclyrno) {
|
||||
*prclyrno = pi->lyrno;
|
||||
++(*prclyrno);
|
||||
return 0;
|
||||
}
|
||||
skip:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int jpc_pi_nextrlcp(register jpc_pi_t *pi)
|
||||
{
|
||||
jpc_pchg_t *pchg;
|
||||
int *prclyrno;
|
||||
|
||||
pchg = pi->pchg;
|
||||
if (!pi->prgvolfirst) {
|
||||
assert(pi->prcno < pi->pirlvl->numprcs);
|
||||
prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
|
||||
goto skip;
|
||||
} else {
|
||||
pi->prgvolfirst = 0;
|
||||
}
|
||||
|
||||
for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pi->maxrlvls &&
|
||||
pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno) {
|
||||
for (pi->lyrno = 0; pi->lyrno < pi->numlyrs && pi->lyrno <
|
||||
JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
|
||||
for (pi->compno = pchg->compnostart, pi->picomp =
|
||||
&pi->picomps[pi->compno]; pi->compno < pi->numcomps &&
|
||||
pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno, ++pi->picomp) {
|
||||
if (pi->rlvlno >= pi->picomp->numrlvls) {
|
||||
continue;
|
||||
}
|
||||
pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
|
||||
for (pi->prcno = 0, prclyrno = pi->pirlvl->prclyrnos;
|
||||
pi->prcno < pi->pirlvl->numprcs; ++pi->prcno, ++prclyrno) {
|
||||
if (pi->lyrno >= *prclyrno) {
|
||||
*prclyrno = pi->lyrno;
|
||||
++(*prclyrno);
|
||||
return 0;
|
||||
}
|
||||
skip:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int jpc_pi_nextrpcl(register jpc_pi_t *pi)
|
||||
{
|
||||
int rlvlno;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
jpc_pchg_t *pchg;
|
||||
int prchind;
|
||||
int prcvind;
|
||||
int *prclyrno;
|
||||
int compno;
|
||||
jpc_picomp_t *picomp;
|
||||
int xstep;
|
||||
int ystep;
|
||||
uint_fast32_t r;
|
||||
uint_fast32_t rpx;
|
||||
uint_fast32_t rpy;
|
||||
uint_fast32_t trx0;
|
||||
uint_fast32_t try0;
|
||||
|
||||
pchg = pi->pchg;
|
||||
if (!pi->prgvolfirst) {
|
||||
goto skip;
|
||||
} else {
|
||||
pi->xstep = 0;
|
||||
pi->ystep = 0;
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
|
||||
++compno, ++picomp) {
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
xstep = picomp->hsamp * (1 << (pirlvl->prcwidthexpn +
|
||||
picomp->numrlvls - rlvlno - 1));
|
||||
ystep = picomp->vsamp * (1 << (pirlvl->prcheightexpn +
|
||||
picomp->numrlvls - rlvlno - 1));
|
||||
pi->xstep = (!pi->xstep) ? xstep : JAS_MIN(pi->xstep, xstep);
|
||||
pi->ystep = (!pi->ystep) ? ystep : JAS_MIN(pi->ystep, ystep);
|
||||
}
|
||||
}
|
||||
pi->prgvolfirst = 0;
|
||||
}
|
||||
|
||||
for (pi->rlvlno = pchg->rlvlnostart; pi->rlvlno < pchg->rlvlnoend &&
|
||||
pi->rlvlno < pi->maxrlvls; ++pi->rlvlno) {
|
||||
for (pi->y = pi->ystart; pi->y < pi->yend; pi->y +=
|
||||
pi->ystep - (pi->y % pi->ystep)) {
|
||||
for (pi->x = pi->xstart; pi->x < pi->xend; pi->x +=
|
||||
pi->xstep - (pi->x % pi->xstep)) {
|
||||
for (pi->compno = pchg->compnostart,
|
||||
pi->picomp = &pi->picomps[pi->compno];
|
||||
pi->compno < JAS_CAST(int, pchg->compnoend) && pi->compno <
|
||||
pi->numcomps; ++pi->compno, ++pi->picomp) {
|
||||
if (pi->rlvlno >= pi->picomp->numrlvls) {
|
||||
continue;
|
||||
}
|
||||
pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
|
||||
if (pi->pirlvl->numprcs == 0) {
|
||||
continue;
|
||||
}
|
||||
r = pi->picomp->numrlvls - 1 - pi->rlvlno;
|
||||
rpx = r + pi->pirlvl->prcwidthexpn;
|
||||
rpy = r + pi->pirlvl->prcheightexpn;
|
||||
trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
|
||||
try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
|
||||
if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx)))
|
||||
|| !(pi->x % (1 << rpx))) &&
|
||||
((pi->y == pi->ystart && ((try0 << r) % (1 << rpy)))
|
||||
|| !(pi->y % (1 << rpy)))) {
|
||||
prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
|
||||
<< r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
|
||||
pi->pirlvl->prcwidthexpn);
|
||||
prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
|
||||
<< r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
|
||||
pi->pirlvl->prcheightexpn);
|
||||
pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind;
|
||||
|
||||
assert(pi->prcno < pi->pirlvl->numprcs);
|
||||
for (pi->lyrno = 0; pi->lyrno <
|
||||
pi->numlyrs && pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
|
||||
prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
|
||||
if (pi->lyrno >= *prclyrno) {
|
||||
++(*prclyrno);
|
||||
return 0;
|
||||
}
|
||||
skip:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int jpc_pi_nextpcrl(register jpc_pi_t *pi)
|
||||
{
|
||||
int rlvlno;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
jpc_pchg_t *pchg;
|
||||
int prchind;
|
||||
int prcvind;
|
||||
int *prclyrno;
|
||||
int compno;
|
||||
jpc_picomp_t *picomp;
|
||||
int xstep;
|
||||
int ystep;
|
||||
uint_fast32_t trx0;
|
||||
uint_fast32_t try0;
|
||||
uint_fast32_t r;
|
||||
uint_fast32_t rpx;
|
||||
uint_fast32_t rpy;
|
||||
|
||||
pchg = pi->pchg;
|
||||
if (!pi->prgvolfirst) {
|
||||
goto skip;
|
||||
} else {
|
||||
pi->xstep = 0;
|
||||
pi->ystep = 0;
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
|
||||
++compno, ++picomp) {
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
xstep = picomp->hsamp * (1 <<
|
||||
(pirlvl->prcwidthexpn + picomp->numrlvls -
|
||||
rlvlno - 1));
|
||||
ystep = picomp->vsamp * (1 <<
|
||||
(pirlvl->prcheightexpn + picomp->numrlvls -
|
||||
rlvlno - 1));
|
||||
pi->xstep = (!pi->xstep) ? xstep :
|
||||
JAS_MIN(pi->xstep, xstep);
|
||||
pi->ystep = (!pi->ystep) ? ystep :
|
||||
JAS_MIN(pi->ystep, ystep);
|
||||
}
|
||||
}
|
||||
pi->prgvolfirst = 0;
|
||||
}
|
||||
|
||||
for (pi->y = pi->ystart; pi->y < pi->yend; pi->y += pi->ystep -
|
||||
(pi->y % pi->ystep)) {
|
||||
for (pi->x = pi->xstart; pi->x < pi->xend; pi->x += pi->xstep -
|
||||
(pi->x % pi->xstep)) {
|
||||
for (pi->compno = pchg->compnostart, pi->picomp =
|
||||
&pi->picomps[pi->compno]; pi->compno < pi->numcomps
|
||||
&& pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
|
||||
++pi->picomp) {
|
||||
for (pi->rlvlno = pchg->rlvlnostart,
|
||||
pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
|
||||
pi->rlvlno < pi->picomp->numrlvls &&
|
||||
pi->rlvlno < pchg->rlvlnoend; ++pi->rlvlno,
|
||||
++pi->pirlvl) {
|
||||
if (pi->pirlvl->numprcs == 0) {
|
||||
continue;
|
||||
}
|
||||
r = pi->picomp->numrlvls - 1 - pi->rlvlno;
|
||||
trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
|
||||
try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
|
||||
rpx = r + pi->pirlvl->prcwidthexpn;
|
||||
rpy = r + pi->pirlvl->prcheightexpn;
|
||||
if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) ||
|
||||
!(pi->x % (pi->picomp->hsamp << rpx))) &&
|
||||
((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) ||
|
||||
!(pi->y % (pi->picomp->vsamp << rpy)))) {
|
||||
prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
|
||||
<< r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
|
||||
pi->pirlvl->prcwidthexpn);
|
||||
prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
|
||||
<< r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
|
||||
pi->pirlvl->prcheightexpn);
|
||||
pi->prcno = prcvind * pi->pirlvl->numhprcs + prchind;
|
||||
assert(pi->prcno < pi->pirlvl->numprcs);
|
||||
for (pi->lyrno = 0; pi->lyrno < pi->numlyrs &&
|
||||
pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
|
||||
prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
|
||||
if (pi->lyrno >= *prclyrno) {
|
||||
++(*prclyrno);
|
||||
return 0;
|
||||
}
|
||||
skip:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int jpc_pi_nextcprl(register jpc_pi_t *pi)
|
||||
{
|
||||
int rlvlno;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
jpc_pchg_t *pchg;
|
||||
int prchind;
|
||||
int prcvind;
|
||||
int *prclyrno;
|
||||
uint_fast32_t trx0;
|
||||
uint_fast32_t try0;
|
||||
uint_fast32_t r;
|
||||
uint_fast32_t rpx;
|
||||
uint_fast32_t rpy;
|
||||
|
||||
pchg = pi->pchg;
|
||||
if (!pi->prgvolfirst) {
|
||||
goto skip;
|
||||
} else {
|
||||
pi->prgvolfirst = 0;
|
||||
}
|
||||
|
||||
for (pi->compno = pchg->compnostart, pi->picomp =
|
||||
&pi->picomps[pi->compno]; pi->compno < JAS_CAST(int, pchg->compnoend); ++pi->compno,
|
||||
++pi->picomp) {
|
||||
pirlvl = pi->picomp->pirlvls;
|
||||
pi->xstep = pi->picomp->hsamp * (1 << (pirlvl->prcwidthexpn +
|
||||
pi->picomp->numrlvls - 1));
|
||||
pi->ystep = pi->picomp->vsamp * (1 << (pirlvl->prcheightexpn +
|
||||
pi->picomp->numrlvls - 1));
|
||||
for (rlvlno = 1, pirlvl = &pi->picomp->pirlvls[1];
|
||||
rlvlno < pi->picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
pi->xstep = JAS_MIN(pi->xstep, pi->picomp->hsamp * (1 <<
|
||||
(pirlvl->prcwidthexpn + pi->picomp->numrlvls -
|
||||
rlvlno - 1)));
|
||||
pi->ystep = JAS_MIN(pi->ystep, pi->picomp->vsamp * (1 <<
|
||||
(pirlvl->prcheightexpn + pi->picomp->numrlvls -
|
||||
rlvlno - 1)));
|
||||
}
|
||||
for (pi->y = pi->ystart; pi->y < pi->yend;
|
||||
pi->y += pi->ystep - (pi->y % pi->ystep)) {
|
||||
for (pi->x = pi->xstart; pi->x < pi->xend;
|
||||
pi->x += pi->xstep - (pi->x % pi->xstep)) {
|
||||
for (pi->rlvlno = pchg->rlvlnostart,
|
||||
pi->pirlvl = &pi->picomp->pirlvls[pi->rlvlno];
|
||||
pi->rlvlno < pi->picomp->numrlvls && pi->rlvlno <
|
||||
pchg->rlvlnoend; ++pi->rlvlno, ++pi->pirlvl) {
|
||||
if (pi->pirlvl->numprcs == 0) {
|
||||
continue;
|
||||
}
|
||||
r = pi->picomp->numrlvls - 1 - pi->rlvlno;
|
||||
trx0 = JPC_CEILDIV(pi->xstart, pi->picomp->hsamp << r);
|
||||
try0 = JPC_CEILDIV(pi->ystart, pi->picomp->vsamp << r);
|
||||
rpx = r + pi->pirlvl->prcwidthexpn;
|
||||
rpy = r + pi->pirlvl->prcheightexpn;
|
||||
if (((pi->x == pi->xstart && ((trx0 << r) % (1 << rpx))) ||
|
||||
!(pi->x % (pi->picomp->hsamp << rpx))) &&
|
||||
((pi->y == pi->ystart && ((try0 << r) % (1 << rpy))) ||
|
||||
!(pi->y % (pi->picomp->vsamp << rpy)))) {
|
||||
prchind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->x, pi->picomp->hsamp
|
||||
<< r), pi->pirlvl->prcwidthexpn) - JPC_FLOORDIVPOW2(trx0,
|
||||
pi->pirlvl->prcwidthexpn);
|
||||
prcvind = JPC_FLOORDIVPOW2(JPC_CEILDIV(pi->y, pi->picomp->vsamp
|
||||
<< r), pi->pirlvl->prcheightexpn) - JPC_FLOORDIVPOW2(try0,
|
||||
pi->pirlvl->prcheightexpn);
|
||||
pi->prcno = prcvind *
|
||||
pi->pirlvl->numhprcs +
|
||||
prchind;
|
||||
assert(pi->prcno <
|
||||
pi->pirlvl->numprcs);
|
||||
for (pi->lyrno = 0; pi->lyrno <
|
||||
pi->numlyrs && pi->lyrno < JAS_CAST(int, pchg->lyrnoend); ++pi->lyrno) {
|
||||
prclyrno = &pi->pirlvl->prclyrnos[pi->prcno];
|
||||
if (pi->lyrno >= *prclyrno) {
|
||||
++(*prclyrno);
|
||||
return 0;
|
||||
}
|
||||
skip:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void pirlvl_destroy(jpc_pirlvl_t *rlvl)
|
||||
{
|
||||
if (rlvl->prclyrnos) {
|
||||
jas_free(rlvl->prclyrnos);
|
||||
}
|
||||
}
|
||||
|
||||
static void jpc_picomp_destroy(jpc_picomp_t *picomp)
|
||||
{
|
||||
int rlvlno;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
if (picomp->pirlvls) {
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
pirlvl_destroy(pirlvl);
|
||||
}
|
||||
jas_free(picomp->pirlvls);
|
||||
}
|
||||
}
|
||||
|
||||
void jpc_pi_destroy(jpc_pi_t *pi)
|
||||
{
|
||||
jpc_picomp_t *picomp;
|
||||
int compno;
|
||||
if (pi->picomps) {
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
|
||||
++compno, ++picomp) {
|
||||
jpc_picomp_destroy(picomp);
|
||||
}
|
||||
jas_free(pi->picomps);
|
||||
}
|
||||
if (pi->pchglist) {
|
||||
jpc_pchglist_destroy(pi->pchglist);
|
||||
}
|
||||
jas_free(pi);
|
||||
}
|
||||
|
||||
jpc_pi_t *jpc_pi_create0()
|
||||
{
|
||||
jpc_pi_t *pi;
|
||||
if (!(pi = jas_malloc(sizeof(jpc_pi_t)))) {
|
||||
return 0;
|
||||
}
|
||||
pi->picomps = 0;
|
||||
pi->pchgno = 0;
|
||||
if (!(pi->pchglist = jpc_pchglist_create())) {
|
||||
jas_free(pi);
|
||||
return 0;
|
||||
}
|
||||
return pi;
|
||||
}
|
||||
|
||||
int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg)
|
||||
{
|
||||
return jpc_pchglist_insert(pi->pchglist, -1, pchg);
|
||||
}
|
||||
|
||||
jpc_pchglist_t *jpc_pchglist_create()
|
||||
{
|
||||
jpc_pchglist_t *pchglist;
|
||||
if (!(pchglist = jas_malloc(sizeof(jpc_pchglist_t)))) {
|
||||
return 0;
|
||||
}
|
||||
pchglist->numpchgs = 0;
|
||||
pchglist->maxpchgs = 0;
|
||||
pchglist->pchgs = 0;
|
||||
return pchglist;
|
||||
}
|
||||
|
||||
int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg)
|
||||
{
|
||||
int i;
|
||||
int newmaxpchgs;
|
||||
jpc_pchg_t **newpchgs;
|
||||
if (pchgno < 0) {
|
||||
pchgno = pchglist->numpchgs;
|
||||
}
|
||||
if (pchglist->numpchgs >= pchglist->maxpchgs) {
|
||||
newmaxpchgs = pchglist->maxpchgs + 128;
|
||||
if (!(newpchgs = jas_realloc2(pchglist->pchgs, newmaxpchgs, sizeof(jpc_pchg_t *)))) {
|
||||
return -1;
|
||||
}
|
||||
pchglist->maxpchgs = newmaxpchgs;
|
||||
pchglist->pchgs = newpchgs;
|
||||
}
|
||||
for (i = pchglist->numpchgs; i > pchgno; --i) {
|
||||
pchglist->pchgs[i] = pchglist->pchgs[i - 1];
|
||||
}
|
||||
pchglist->pchgs[pchgno] = pchg;
|
||||
++pchglist->numpchgs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno)
|
||||
{
|
||||
int i;
|
||||
jpc_pchg_t *pchg;
|
||||
assert(pchgno < pchglist->numpchgs);
|
||||
pchg = pchglist->pchgs[pchgno];
|
||||
for (i = pchgno + 1; i < pchglist->numpchgs; ++i) {
|
||||
pchglist->pchgs[i - 1] = pchglist->pchgs[i];
|
||||
}
|
||||
--pchglist->numpchgs;
|
||||
return pchg;
|
||||
}
|
||||
|
||||
jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg)
|
||||
{
|
||||
jpc_pchg_t *newpchg;
|
||||
if (!(newpchg = jas_malloc(sizeof(jpc_pchg_t)))) {
|
||||
return 0;
|
||||
}
|
||||
*newpchg = *pchg;
|
||||
return newpchg;
|
||||
}
|
||||
|
||||
jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist)
|
||||
{
|
||||
jpc_pchglist_t *newpchglist;
|
||||
jpc_pchg_t *newpchg;
|
||||
int pchgno;
|
||||
if (!(newpchglist = jpc_pchglist_create())) {
|
||||
return 0;
|
||||
}
|
||||
for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) {
|
||||
if (!(newpchg = jpc_pchg_copy(pchglist->pchgs[pchgno])) ||
|
||||
jpc_pchglist_insert(newpchglist, -1, newpchg)) {
|
||||
jpc_pchglist_destroy(newpchglist);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return newpchglist;
|
||||
}
|
||||
|
||||
void jpc_pchglist_destroy(jpc_pchglist_t *pchglist)
|
||||
{
|
||||
int pchgno;
|
||||
if (pchglist->pchgs) {
|
||||
for (pchgno = 0; pchgno < pchglist->numpchgs; ++pchgno) {
|
||||
jpc_pchg_destroy(pchglist->pchgs[pchgno]);
|
||||
}
|
||||
jas_free(pchglist->pchgs);
|
||||
}
|
||||
jas_free(pchglist);
|
||||
}
|
||||
|
||||
void jpc_pchg_destroy(jpc_pchg_t *pchg)
|
||||
{
|
||||
jas_free(pchg);
|
||||
}
|
||||
|
||||
jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno)
|
||||
{
|
||||
return pchglist->pchgs[pchgno];
|
||||
}
|
||||
|
||||
int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist)
|
||||
{
|
||||
return pchglist->numpchgs;
|
||||
}
|
||||
|
||||
int jpc_pi_init(jpc_pi_t *pi)
|
||||
{
|
||||
int compno;
|
||||
int rlvlno;
|
||||
int prcno;
|
||||
jpc_picomp_t *picomp;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
int *prclyrno;
|
||||
|
||||
pi->prgvolfirst = 0;
|
||||
pi->valid = 0;
|
||||
pi->pktno = -1;
|
||||
pi->pchgno = -1;
|
||||
pi->pchg = 0;
|
||||
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps;
|
||||
++compno, ++picomp) {
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
for (prcno = 0, prclyrno = pirlvl->prclyrnos;
|
||||
prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
|
||||
*prclyrno = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Vendored
+299
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier-2 Coding Library
|
||||
*
|
||||
* $Id: jpc_t2cod.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T2COD_H
|
||||
#define JPC_T2COD_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jpc_cs.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Progression change list. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of progression changes. */
|
||||
int numpchgs;
|
||||
|
||||
/* The maximum number of progression changes that can be accomodated
|
||||
without growing the progression change array. */
|
||||
int maxpchgs;
|
||||
|
||||
/* The progression changes. */
|
||||
jpc_pchg_t **pchgs;
|
||||
|
||||
} jpc_pchglist_t;
|
||||
|
||||
/* Packet iterator per-resolution-level information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of precincts. */
|
||||
int numprcs;
|
||||
|
||||
/* The last layer processed for each precinct. */
|
||||
int *prclyrnos;
|
||||
|
||||
/* The precinct width exponent. */
|
||||
int prcwidthexpn;
|
||||
|
||||
/* The precinct height exponent. */
|
||||
int prcheightexpn;
|
||||
|
||||
/* The number of precincts spanning the resolution level in the horizontal
|
||||
direction. */
|
||||
int numhprcs;
|
||||
|
||||
} jpc_pirlvl_t;
|
||||
|
||||
/* Packet iterator per-component information. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of resolution levels. */
|
||||
int numrlvls;
|
||||
|
||||
/* The per-resolution-level information. */
|
||||
jpc_pirlvl_t *pirlvls;
|
||||
|
||||
/* The horizontal sampling period. */
|
||||
int hsamp;
|
||||
|
||||
/* The vertical sampling period. */
|
||||
int vsamp;
|
||||
|
||||
} jpc_picomp_t;
|
||||
|
||||
/* Packet iterator class. */
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of layers. */
|
||||
int numlyrs;
|
||||
|
||||
/* The number of resolution levels. */
|
||||
int maxrlvls;
|
||||
|
||||
/* The number of components. */
|
||||
int numcomps;
|
||||
|
||||
/* The per-component information. */
|
||||
jpc_picomp_t *picomps;
|
||||
|
||||
/* The current component. */
|
||||
jpc_picomp_t *picomp;
|
||||
|
||||
/* The current resolution level. */
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
|
||||
/* The number of the current component. */
|
||||
int compno;
|
||||
|
||||
/* The number of the current resolution level. */
|
||||
int rlvlno;
|
||||
|
||||
/* The number of the current precinct. */
|
||||
int prcno;
|
||||
|
||||
/* The number of the current layer. */
|
||||
int lyrno;
|
||||
|
||||
/* The x-coordinate of the current position. */
|
||||
int x;
|
||||
|
||||
/* The y-coordinate of the current position. */
|
||||
int y;
|
||||
|
||||
/* The horizontal step size. */
|
||||
int xstep;
|
||||
|
||||
/* The vertical step size. */
|
||||
int ystep;
|
||||
|
||||
/* The x-coordinate of the top-left corner of the tile on the reference
|
||||
grid. */
|
||||
int xstart;
|
||||
|
||||
/* The y-coordinate of the top-left corner of the tile on the reference
|
||||
grid. */
|
||||
int ystart;
|
||||
|
||||
/* The x-coordinate of the bottom-right corner of the tile on the
|
||||
reference grid (plus one). */
|
||||
int xend;
|
||||
|
||||
/* The y-coordinate of the bottom-right corner of the tile on the
|
||||
reference grid (plus one). */
|
||||
int yend;
|
||||
|
||||
/* The current progression change. */
|
||||
jpc_pchg_t *pchg;
|
||||
|
||||
/* The progression change list. */
|
||||
jpc_pchglist_t *pchglist;
|
||||
|
||||
/* The progression to use in the absense of explicit specification. */
|
||||
jpc_pchg_t defaultpchg;
|
||||
|
||||
/* The current progression change number. */
|
||||
int pchgno;
|
||||
|
||||
/* Is this the first time in the current progression volume? */
|
||||
bool prgvolfirst;
|
||||
|
||||
/* Is the current iterator value valid? */
|
||||
bool valid;
|
||||
|
||||
/* The current packet number. */
|
||||
int pktno;
|
||||
|
||||
} jpc_pi_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for packet iterators.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a packet iterator. */
|
||||
jpc_pi_t *jpc_pi_create0(void);
|
||||
|
||||
/* Destroy a packet iterator. */
|
||||
void jpc_pi_destroy(jpc_pi_t *pi);
|
||||
|
||||
/* Add a progression change to a packet iterator. */
|
||||
int jpc_pi_addpchg(jpc_pi_t *pi, jpc_pocpchg_t *pchg);
|
||||
|
||||
/* Prepare a packet iterator for iteration. */
|
||||
int jpc_pi_init(jpc_pi_t *pi);
|
||||
|
||||
/* Set the iterator to the first packet. */
|
||||
int jpc_pi_begin(jpc_pi_t *pi);
|
||||
|
||||
/* Proceed to the next packet in sequence. */
|
||||
int jpc_pi_next(jpc_pi_t *pi);
|
||||
|
||||
/* Get the index of the current packet. */
|
||||
#define jpc_pi_getind(pi) ((pi)->pktno)
|
||||
|
||||
/* Get the component number of the current packet. */
|
||||
#define jpc_pi_cmptno(pi) (assert(pi->valid), (pi)->compno)
|
||||
|
||||
/* Get the resolution level of the current packet. */
|
||||
#define jpc_pi_rlvlno(pi) (assert(pi->valid), (pi)->rlvlno)
|
||||
|
||||
/* Get the layer number of the current packet. */
|
||||
#define jpc_pi_lyrno(pi) (assert(pi->valid), (pi)->lyrno)
|
||||
|
||||
/* Get the precinct number of the current packet. */
|
||||
#define jpc_pi_prcno(pi) (assert(pi->valid), (pi)->prcno)
|
||||
|
||||
/* Get the progression order for the current packet. */
|
||||
#define jpc_pi_prg(pi) (assert(pi->valid), (pi)->pchg->prgord)
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for progression change lists.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a progression change list. */
|
||||
jpc_pchglist_t *jpc_pchglist_create(void);
|
||||
|
||||
/* Destroy a progression change list. */
|
||||
void jpc_pchglist_destroy(jpc_pchglist_t *pchglist);
|
||||
|
||||
/* Insert a new element into a progression change list. */
|
||||
int jpc_pchglist_insert(jpc_pchglist_t *pchglist, int pchgno, jpc_pchg_t *pchg);
|
||||
|
||||
/* Remove an element from a progression change list. */
|
||||
jpc_pchg_t *jpc_pchglist_remove(jpc_pchglist_t *pchglist, int pchgno);
|
||||
|
||||
/* Get an element from a progression change list. */
|
||||
jpc_pchg_t *jpc_pchglist_get(jpc_pchglist_t *pchglist, int pchgno);
|
||||
|
||||
/* Copy a progression change list. */
|
||||
jpc_pchglist_t *jpc_pchglist_copy(jpc_pchglist_t *pchglist);
|
||||
|
||||
/* Get the number of elements in a progression change list. */
|
||||
int jpc_pchglist_numpchgs(jpc_pchglist_t *pchglist);
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions/macros for progression changes.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Destroy a progression change. */
|
||||
void jpc_pchg_destroy(jpc_pchg_t *pchg);
|
||||
|
||||
/* Copy a progression change. */
|
||||
jpc_pchg_t *jpc_pchg_copy(jpc_pchg_t *pchg);
|
||||
|
||||
#endif
|
||||
Vendored
+581
@@ -0,0 +1,581 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 2 Decoder
|
||||
*
|
||||
* $Id: jpc_t2dec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_types.h"
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jpc_bs.h"
|
||||
#include "jpc_dec.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_mqdec.h"
|
||||
#include "jpc_t2dec.h"
|
||||
#include "jpc_t1cod.h"
|
||||
#include "jpc_math.h"
|
||||
|
||||
/******************************************************************************\
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
long jpc_dec_lookahead(jas_stream_t *in);
|
||||
static int jpc_getcommacode(jpc_bitstream_t *in);
|
||||
static int jpc_getnumnewpasses(jpc_bitstream_t *in);
|
||||
static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int lvlno,
|
||||
int prcno, int lyrno);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
static int jpc_getcommacode(jpc_bitstream_t *in)
|
||||
{
|
||||
int n;
|
||||
int v;
|
||||
|
||||
n = 0;
|
||||
for (;;) {
|
||||
if ((v = jpc_bitstream_getbit(in)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (jpc_bitstream_eof(in)) {
|
||||
return -1;
|
||||
}
|
||||
if (!v) {
|
||||
break;
|
||||
}
|
||||
++n;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int jpc_getnumnewpasses(jpc_bitstream_t *in)
|
||||
{
|
||||
int n;
|
||||
|
||||
if ((n = jpc_bitstream_getbit(in)) > 0) {
|
||||
if ((n = jpc_bitstream_getbit(in)) > 0) {
|
||||
if ((n = jpc_bitstream_getbits(in, 2)) == 3) {
|
||||
if ((n = jpc_bitstream_getbits(in, 5)) == 31) {
|
||||
if ((n = jpc_bitstream_getbits(in, 7)) >= 0) {
|
||||
n += 36 + 1;
|
||||
}
|
||||
} else if (n >= 0) {
|
||||
n += 5 + 1;
|
||||
}
|
||||
} else if (n >= 0) {
|
||||
n += 2 + 1;
|
||||
}
|
||||
} else if (!n) {
|
||||
n += 2;
|
||||
}
|
||||
} else if (!n) {
|
||||
++n;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
static int jpc_dec_decodepkt(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in, int compno, int rlvlno,
|
||||
int prcno, int lyrno)
|
||||
{
|
||||
jpc_bitstream_t *inb;
|
||||
jpc_dec_tcomp_t *tcomp;
|
||||
jpc_dec_rlvl_t *rlvl;
|
||||
jpc_dec_band_t *band;
|
||||
jpc_dec_cblk_t *cblk;
|
||||
int n;
|
||||
int m;
|
||||
int i;
|
||||
jpc_tagtreenode_t *leaf;
|
||||
int included;
|
||||
int ret;
|
||||
int numnewpasses;
|
||||
jpc_dec_seg_t *seg;
|
||||
int len;
|
||||
int present;
|
||||
int savenumnewpasses;
|
||||
int mycounter;
|
||||
jpc_ms_t *ms;
|
||||
jpc_dec_tile_t *tile;
|
||||
jpc_dec_ccp_t *ccp;
|
||||
jpc_dec_cp_t *cp;
|
||||
int bandno;
|
||||
jpc_dec_prc_t *prc;
|
||||
int usedcblkcnt;
|
||||
int cblkno;
|
||||
uint_fast32_t bodylen;
|
||||
bool discard;
|
||||
int passno;
|
||||
int maxpasses;
|
||||
int hdrlen;
|
||||
int hdroffstart;
|
||||
int hdroffend;
|
||||
|
||||
/* Avoid compiler warning about possible use of uninitialized
|
||||
variable. */
|
||||
bodylen = 0;
|
||||
|
||||
discard = (lyrno >= dec->maxlyrs);
|
||||
|
||||
tile = dec->curtile;
|
||||
cp = tile->cp;
|
||||
ccp = &cp->ccps[compno];
|
||||
|
||||
/*
|
||||
* Decode the packet header.
|
||||
*/
|
||||
|
||||
/* Decode the SOP marker segment if present. */
|
||||
if (cp->csty & JPC_COD_SOP) {
|
||||
if (jpc_dec_lookahead(in) == JPC_MS_SOP) {
|
||||
if (!(ms = jpc_getms(in, dec->cstate))) {
|
||||
return -1;
|
||||
}
|
||||
if (jpc_ms_gettype(ms) != JPC_MS_SOP) {
|
||||
jpc_ms_destroy(ms);
|
||||
jas_eprintf("missing SOP marker segment\n");
|
||||
return -1;
|
||||
}
|
||||
jpc_ms_destroy(ms);
|
||||
}
|
||||
}
|
||||
|
||||
hdroffstart = jas_stream_getrwcount(pkthdrstream);
|
||||
|
||||
if (!(inb = jpc_bitstream_sopen(pkthdrstream, "r"))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((present = jpc_bitstream_getbit(inb)) < 0) {
|
||||
return 1;
|
||||
}
|
||||
JAS_DBGLOG(10, ("\n", present));
|
||||
JAS_DBGLOG(10, ("present=%d ", present));
|
||||
|
||||
/* Is the packet non-empty? */
|
||||
if (present) {
|
||||
/* The packet is non-empty. */
|
||||
tcomp = &tile->tcomps[compno];
|
||||
rlvl = &tcomp->rlvls[rlvlno];
|
||||
bodylen = 0;
|
||||
for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
|
||||
++bandno, ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
prc = &band->prcs[prcno];
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
usedcblkcnt = 0;
|
||||
for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
|
||||
++cblkno, ++cblk) {
|
||||
++usedcblkcnt;
|
||||
if (!cblk->numpasses) {
|
||||
leaf = jpc_tagtree_getleaf(prc->incltagtree, usedcblkcnt - 1);
|
||||
if ((included = jpc_tagtree_decode(prc->incltagtree, leaf, lyrno + 1, inb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if ((included = jpc_bitstream_getbit(inb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
JAS_DBGLOG(10, ("\n"));
|
||||
JAS_DBGLOG(10, ("included=%d ", included));
|
||||
if (!included) {
|
||||
continue;
|
||||
}
|
||||
if (!cblk->numpasses) {
|
||||
i = 1;
|
||||
leaf = jpc_tagtree_getleaf(prc->numimsbstagtree, usedcblkcnt - 1);
|
||||
for (;;) {
|
||||
if ((ret = jpc_tagtree_decode(prc->numimsbstagtree, leaf, i, inb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
cblk->numimsbs = i - 1;
|
||||
cblk->firstpassno = cblk->numimsbs * 3;
|
||||
}
|
||||
if ((numnewpasses = jpc_getnumnewpasses(inb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
|
||||
seg = cblk->curseg;
|
||||
savenumnewpasses = numnewpasses;
|
||||
mycounter = 0;
|
||||
if (numnewpasses > 0) {
|
||||
if ((m = jpc_getcommacode(inb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
cblk->numlenbits += m;
|
||||
JAS_DBGLOG(10, ("increment=%d ", m));
|
||||
while (numnewpasses > 0) {
|
||||
passno = cblk->firstpassno + cblk->numpasses + mycounter;
|
||||
/* XXX - the maxpasses is not set precisely but this doesn't matter... */
|
||||
maxpasses = JPC_SEGPASSCNT(passno, cblk->firstpassno, 10000, (ccp->cblkctx & JPC_COX_LAZY) != 0, (ccp->cblkctx & JPC_COX_TERMALL) != 0);
|
||||
if (!discard && !seg) {
|
||||
if (!(seg = jpc_seg_alloc())) {
|
||||
return -1;
|
||||
}
|
||||
jpc_seglist_insert(&cblk->segs, cblk->segs.tail, seg);
|
||||
if (!cblk->curseg) {
|
||||
cblk->curseg = seg;
|
||||
}
|
||||
seg->passno = passno;
|
||||
seg->type = JPC_SEGTYPE(seg->passno, cblk->firstpassno, (ccp->cblkctx & JPC_COX_LAZY) != 0);
|
||||
seg->maxpasses = maxpasses;
|
||||
}
|
||||
n = JAS_MIN(numnewpasses, maxpasses);
|
||||
mycounter += n;
|
||||
numnewpasses -= n;
|
||||
if ((len = jpc_bitstream_getbits(inb, cblk->numlenbits + jpc_floorlog2(n))) < 0) {
|
||||
return -1;
|
||||
}
|
||||
JAS_DBGLOG(10, ("len=%d ", len));
|
||||
if (!discard) {
|
||||
seg->lyrno = lyrno;
|
||||
seg->numpasses += n;
|
||||
seg->cnt = len;
|
||||
seg = seg->next;
|
||||
}
|
||||
bodylen += len;
|
||||
}
|
||||
}
|
||||
cblk->numpasses += savenumnewpasses;
|
||||
}
|
||||
}
|
||||
|
||||
jpc_bitstream_inalign(inb, 0, 0);
|
||||
|
||||
} else {
|
||||
if (jpc_bitstream_inalign(inb, 0x7f, 0)) {
|
||||
jas_eprintf("alignment failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
jpc_bitstream_close(inb);
|
||||
|
||||
hdroffend = jas_stream_getrwcount(pkthdrstream);
|
||||
hdrlen = hdroffend - hdroffstart;
|
||||
if (jas_getdbglevel() >= 5) {
|
||||
jas_eprintf("hdrlen=%lu bodylen=%lu \n", (unsigned long) hdrlen,
|
||||
(unsigned long) bodylen);
|
||||
}
|
||||
|
||||
if (cp->csty & JPC_COD_EPH) {
|
||||
if (jpc_dec_lookahead(pkthdrstream) == JPC_MS_EPH) {
|
||||
if (!(ms = jpc_getms(pkthdrstream, dec->cstate))) {
|
||||
jas_eprintf("cannot get (EPH) marker segment\n");
|
||||
return -1;
|
||||
}
|
||||
if (jpc_ms_gettype(ms) != JPC_MS_EPH) {
|
||||
jpc_ms_destroy(ms);
|
||||
jas_eprintf("missing EPH marker segment\n");
|
||||
return -1;
|
||||
}
|
||||
jpc_ms_destroy(ms);
|
||||
}
|
||||
}
|
||||
|
||||
/* decode the packet body. */
|
||||
|
||||
if (jas_getdbglevel() >= 1) {
|
||||
jas_eprintf("packet body offset=%06ld\n", (long) jas_stream_getrwcount(in));
|
||||
}
|
||||
|
||||
if (!discard) {
|
||||
tcomp = &tile->tcomps[compno];
|
||||
rlvl = &tcomp->rlvls[rlvlno];
|
||||
for (bandno = 0, band = rlvl->bands; bandno < rlvl->numbands;
|
||||
++bandno, ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
prc = &band->prcs[prcno];
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
for (cblkno = 0, cblk = prc->cblks; cblkno < prc->numcblks;
|
||||
++cblkno, ++cblk) {
|
||||
seg = cblk->curseg;
|
||||
while (seg) {
|
||||
if (!seg->stream) {
|
||||
if (!(seg->stream = jas_stream_memopen(0, 0))) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
jas_eprintf("lyrno=%02d, compno=%02d, lvlno=%02d, prcno=%02d, bandno=%02d, cblkno=%02d, passno=%02d numpasses=%02d cnt=%d numbps=%d, numimsbs=%d\n", lyrno, compno, rlvlno, prcno, band - rlvl->bands, cblk - prc->cblks, seg->passno, seg->numpasses, seg->cnt, band->numbps, cblk->numimsbs);
|
||||
#endif
|
||||
if (seg->cnt > 0) {
|
||||
if (jpc_getdata(in, seg->stream, seg->cnt) < 0) {
|
||||
return -1;
|
||||
}
|
||||
seg->cnt = 0;
|
||||
}
|
||||
if (seg->numpasses >= seg->maxpasses) {
|
||||
cblk->curseg = seg->next;
|
||||
}
|
||||
seg = seg->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (jas_stream_gobble(in, bodylen) != JAS_CAST(int, bodylen)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
/********************************************************************************************/
|
||||
|
||||
int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream, jas_stream_t *in)
|
||||
{
|
||||
jpc_dec_tile_t *tile;
|
||||
jpc_pi_t *pi;
|
||||
int ret;
|
||||
|
||||
tile = dec->curtile;
|
||||
pi = tile->pi;
|
||||
for (;;) {
|
||||
if (!tile->pkthdrstream || jas_stream_peekc(tile->pkthdrstream) == EOF) {
|
||||
switch (jpc_dec_lookahead(in)) {
|
||||
case JPC_MS_EOC:
|
||||
case JPC_MS_SOT:
|
||||
return 0;
|
||||
break;
|
||||
case JPC_MS_SOP:
|
||||
case JPC_MS_EPH:
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((ret = jpc_pi_next(pi))) {
|
||||
return ret;
|
||||
}
|
||||
if (dec->maxpkts >= 0 && dec->numpkts >= dec->maxpkts) {
|
||||
jas_eprintf("warning: stopping decode prematurely as requested\n");
|
||||
return 0;
|
||||
}
|
||||
if (jas_getdbglevel() >= 1) {
|
||||
jas_eprintf("packet offset=%08ld prg=%d cmptno=%02d "
|
||||
"rlvlno=%02d prcno=%03d lyrno=%02d\n", (long)
|
||||
jas_stream_getrwcount(in), jpc_pi_prg(pi), jpc_pi_cmptno(pi),
|
||||
jpc_pi_rlvlno(pi), jpc_pi_prcno(pi), jpc_pi_lyrno(pi));
|
||||
}
|
||||
if (jpc_dec_decodepkt(dec, pkthdrstream, in, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi),
|
||||
jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) {
|
||||
return -1;
|
||||
}
|
||||
++dec->numpkts;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile)
|
||||
{
|
||||
jpc_pi_t *pi;
|
||||
int compno;
|
||||
jpc_picomp_t *picomp;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
jpc_dec_tcomp_t *tcomp;
|
||||
int rlvlno;
|
||||
jpc_dec_rlvl_t *rlvl;
|
||||
int prcno;
|
||||
int *prclyrno;
|
||||
jpc_dec_cmpt_t *cmpt;
|
||||
|
||||
if (!(pi = jpc_pi_create0())) {
|
||||
return 0;
|
||||
}
|
||||
pi->numcomps = dec->numcomps;
|
||||
if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno,
|
||||
++picomp) {
|
||||
picomp->pirlvls = 0;
|
||||
}
|
||||
|
||||
for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps;
|
||||
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
|
||||
picomp->numrlvls = tcomp->numrlvls;
|
||||
if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls,
|
||||
sizeof(jpc_pirlvl_t)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
pirlvl->prclyrnos = 0;
|
||||
}
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
|
||||
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
|
||||
/* XXX sizeof(long) should be sizeof different type */
|
||||
pirlvl->numprcs = rlvl->numprcs;
|
||||
if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs,
|
||||
sizeof(long)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pi->maxrlvls = 0;
|
||||
for (compno = 0, tcomp = tile->tcomps, picomp = pi->picomps, cmpt =
|
||||
dec->cmpts; compno < pi->numcomps; ++compno, ++tcomp, ++picomp,
|
||||
++cmpt) {
|
||||
picomp->hsamp = cmpt->hstep;
|
||||
picomp->vsamp = cmpt->vstep;
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
|
||||
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
|
||||
pirlvl->prcwidthexpn = rlvl->prcwidthexpn;
|
||||
pirlvl->prcheightexpn = rlvl->prcheightexpn;
|
||||
for (prcno = 0, prclyrno = pirlvl->prclyrnos;
|
||||
prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
|
||||
*prclyrno = 0;
|
||||
}
|
||||
pirlvl->numhprcs = rlvl->numhprcs;
|
||||
}
|
||||
if (pi->maxrlvls < tcomp->numrlvls) {
|
||||
pi->maxrlvls = tcomp->numrlvls;
|
||||
}
|
||||
}
|
||||
|
||||
pi->numlyrs = tile->cp->numlyrs;
|
||||
pi->xstart = tile->xstart;
|
||||
pi->ystart = tile->ystart;
|
||||
pi->xend = tile->xend;
|
||||
pi->yend = tile->yend;
|
||||
|
||||
pi->picomp = 0;
|
||||
pi->pirlvl = 0;
|
||||
pi->x = 0;
|
||||
pi->y = 0;
|
||||
pi->compno = 0;
|
||||
pi->rlvlno = 0;
|
||||
pi->prcno = 0;
|
||||
pi->lyrno = 0;
|
||||
pi->xstep = 0;
|
||||
pi->ystep = 0;
|
||||
|
||||
pi->pchgno = -1;
|
||||
|
||||
pi->defaultpchg.prgord = tile->cp->prgord;
|
||||
pi->defaultpchg.compnostart = 0;
|
||||
pi->defaultpchg.compnoend = pi->numcomps;
|
||||
pi->defaultpchg.rlvlnostart = 0;
|
||||
pi->defaultpchg.rlvlnoend = pi->maxrlvls;
|
||||
pi->defaultpchg.lyrnoend = pi->numlyrs;
|
||||
pi->pchg = 0;
|
||||
|
||||
pi->valid = 0;
|
||||
|
||||
return pi;
|
||||
}
|
||||
|
||||
long jpc_dec_lookahead(jas_stream_t *in)
|
||||
{
|
||||
uint_fast16_t x;
|
||||
if (jpc_getuint16(in, &x)) {
|
||||
return -1;
|
||||
}
|
||||
if (jas_stream_ungetc(in, x & 0xff) == EOF ||
|
||||
jas_stream_ungetc(in, x >> 8) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
if (x >= JPC_MS_INMIN /*&& x <= JPC_MS_INMAX*/) {
|
||||
return x;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Vendored
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 2 Decoder
|
||||
*
|
||||
* $Id: jpc_t2dec.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T2DEC_H
|
||||
#define JPC_T2DEC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_stream.h"
|
||||
|
||||
#include "jpc_bs.h"
|
||||
#include "jpc_dec.h"
|
||||
#include "jpc_mqdec.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Decode the packets for a tile-part. */
|
||||
int jpc_dec_decodepkts(jpc_dec_t *dec, jas_stream_t *pkthdrstream,
|
||||
jas_stream_t *in);
|
||||
|
||||
/* Create a packet iterator for the decoder. */
|
||||
jpc_pi_t *jpc_dec_pi_create(jpc_dec_t *dec, jpc_dec_tile_t *tile);
|
||||
|
||||
#endif
|
||||
Vendored
+655
@@ -0,0 +1,655 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 2 Encoder
|
||||
*
|
||||
* $Id: jpc_t2enc.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_fix.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_debug.h"
|
||||
|
||||
#include "jpc_flt.h"
|
||||
#include "jpc_t2enc.h"
|
||||
#include "jpc_t2cod.h"
|
||||
#include "jpc_tagtree.h"
|
||||
#include "jpc_enc.h"
|
||||
#include "jpc_math.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
static int jpc_putcommacode(jpc_bitstream_t *out, int n)
|
||||
{
|
||||
assert(n >= 0);
|
||||
|
||||
while (--n >= 0) {
|
||||
if (jpc_bitstream_putbit(out, 1) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (jpc_bitstream_putbit(out, 0) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int jpc_putnumnewpasses(jpc_bitstream_t *out, int n)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (n <= 0) {
|
||||
return -1;
|
||||
} else if (n == 1) {
|
||||
ret = jpc_bitstream_putbit(out, 0);
|
||||
} else if (n == 2) {
|
||||
ret = jpc_bitstream_putbits(out, 2, 2);
|
||||
} else if (n <= 5) {
|
||||
ret = jpc_bitstream_putbits(out, 4, 0xc | (n - 3));
|
||||
} else if (n <= 36) {
|
||||
ret = jpc_bitstream_putbits(out, 9, 0x1e0 | (n - 6));
|
||||
} else if (n <= 164) {
|
||||
ret = jpc_bitstream_putbits(out, 16, 0xff80 | (n - 37));
|
||||
} else {
|
||||
/* The standard has no provision for encoding a larger value.
|
||||
In practice, however, it is highly unlikely that this
|
||||
limitation will ever be encountered. */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (ret != EOF) ? 0 : (-1);
|
||||
}
|
||||
|
||||
int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out)
|
||||
{
|
||||
jpc_enc_tile_t *tile;
|
||||
jpc_pi_t *pi;
|
||||
|
||||
tile = enc->curtile;
|
||||
|
||||
jpc_init_t2state(enc, 0);
|
||||
pi = tile->pi;
|
||||
jpc_pi_init(pi);
|
||||
|
||||
if (!jpc_pi_next(pi)) {
|
||||
for (;;) {
|
||||
if (jpc_enc_encpkt(enc, out, jpc_pi_cmptno(pi), jpc_pi_rlvlno(pi),
|
||||
jpc_pi_prcno(pi), jpc_pi_lyrno(pi))) {
|
||||
return -1;
|
||||
}
|
||||
if (jpc_pi_next(pi)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno, int prcno, int lyrno)
|
||||
{
|
||||
jpc_enc_tcmpt_t *comp;
|
||||
jpc_enc_rlvl_t *lvl;
|
||||
jpc_enc_band_t *band;
|
||||
jpc_enc_band_t *endbands;
|
||||
jpc_enc_cblk_t *cblk;
|
||||
jpc_enc_cblk_t *endcblks;
|
||||
jpc_bitstream_t *outb;
|
||||
jpc_enc_pass_t *pass;
|
||||
jpc_enc_pass_t *startpass;
|
||||
jpc_enc_pass_t *lastpass;
|
||||
jpc_enc_pass_t *endpass;
|
||||
jpc_enc_pass_t *endpasses;
|
||||
int i;
|
||||
int included;
|
||||
int ret;
|
||||
jpc_tagtreenode_t *leaf;
|
||||
int n;
|
||||
int t1;
|
||||
int t2;
|
||||
int adjust;
|
||||
int maxadjust;
|
||||
int datalen;
|
||||
int numnewpasses;
|
||||
int passcount;
|
||||
jpc_enc_tile_t *tile;
|
||||
jpc_enc_prc_t *prc;
|
||||
jpc_enc_cp_t *cp;
|
||||
jpc_ms_t *ms;
|
||||
|
||||
tile = enc->curtile;
|
||||
cp = enc->cp;
|
||||
|
||||
if (cp->tcp.csty & JPC_COD_SOP) {
|
||||
if (!(ms = jpc_ms_create(JPC_MS_SOP))) {
|
||||
return -1;
|
||||
}
|
||||
ms->parms.sop.seqno = jpc_pi_getind(tile->pi);
|
||||
if (jpc_putms(out, enc->cstate, ms)) {
|
||||
return -1;
|
||||
}
|
||||
jpc_ms_destroy(ms);
|
||||
}
|
||||
|
||||
outb = jpc_bitstream_sopen(out, "w+");
|
||||
assert(outb);
|
||||
|
||||
if (jpc_bitstream_putbit(outb, 1) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
JAS_DBGLOG(10, ("\n"));
|
||||
JAS_DBGLOG(10, ("present. "));
|
||||
|
||||
comp = &tile->tcmpts[compno];
|
||||
lvl = &comp->rlvls[lvlno];
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
prc = &band->prcs[prcno];
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
if (!lyrno) {
|
||||
leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
|
||||
jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs);
|
||||
}
|
||||
pass = cblk->curpass;
|
||||
included = (pass && pass->lyrno == lyrno);
|
||||
if (included && (!cblk->numencpasses)) {
|
||||
assert(pass->lyrno == lyrno);
|
||||
leaf = jpc_tagtree_getleaf(prc->incltree,
|
||||
cblk - prc->cblks);
|
||||
jpc_tagtree_setvalue(prc->incltree, leaf, pass->lyrno);
|
||||
}
|
||||
}
|
||||
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
pass = cblk->curpass;
|
||||
included = (pass && pass->lyrno == lyrno);
|
||||
if (!cblk->numencpasses) {
|
||||
leaf = jpc_tagtree_getleaf(prc->incltree,
|
||||
cblk - prc->cblks);
|
||||
if (jpc_tagtree_encode(prc->incltree, leaf, lyrno
|
||||
+ 1, outb) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (jpc_bitstream_putbit(outb, included) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
JAS_DBGLOG(10, ("included=%d ", included));
|
||||
if (!included) {
|
||||
continue;
|
||||
}
|
||||
if (!cblk->numencpasses) {
|
||||
i = 1;
|
||||
leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
|
||||
for (;;) {
|
||||
if ((ret = jpc_tagtree_encode(prc->nlibtree, leaf, i, outb)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
assert(leaf->known_ && i == leaf->value_ + 1);
|
||||
}
|
||||
|
||||
endpasses = &cblk->passes[cblk->numpasses];
|
||||
startpass = pass;
|
||||
endpass = startpass;
|
||||
while (endpass != endpasses && endpass->lyrno == lyrno){
|
||||
++endpass;
|
||||
}
|
||||
numnewpasses = endpass - startpass;
|
||||
if (jpc_putnumnewpasses(outb, numnewpasses)) {
|
||||
return -1;
|
||||
}
|
||||
JAS_DBGLOG(10, ("numnewpasses=%d ", numnewpasses));
|
||||
|
||||
lastpass = endpass - 1;
|
||||
n = startpass->start;
|
||||
passcount = 1;
|
||||
maxadjust = 0;
|
||||
for (pass = startpass; pass != endpass; ++pass) {
|
||||
if (pass->term || pass == lastpass) {
|
||||
datalen = pass->end - n;
|
||||
t1 = jpc_firstone(datalen) + 1;
|
||||
t2 = cblk->numlenbits + jpc_floorlog2(passcount);
|
||||
adjust = JAS_MAX(t1 - t2, 0);
|
||||
maxadjust = JAS_MAX(adjust, maxadjust);
|
||||
n += datalen;
|
||||
passcount = 1;
|
||||
} else {
|
||||
++passcount;
|
||||
}
|
||||
}
|
||||
if (jpc_putcommacode(outb, maxadjust)) {
|
||||
return -1;
|
||||
}
|
||||
cblk->numlenbits += maxadjust;
|
||||
|
||||
lastpass = endpass - 1;
|
||||
n = startpass->start;
|
||||
passcount = 1;
|
||||
for (pass = startpass; pass != endpass; ++pass) {
|
||||
if (pass->term || pass == lastpass) {
|
||||
datalen = pass->end - n;
|
||||
assert(jpc_firstone(datalen) < cblk->numlenbits + jpc_floorlog2(passcount));
|
||||
if (jpc_bitstream_putbits(outb, cblk->numlenbits + jpc_floorlog2(passcount), datalen) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
n += datalen;
|
||||
passcount = 1;
|
||||
} else {
|
||||
++passcount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jpc_bitstream_outalign(outb, 0);
|
||||
jpc_bitstream_close(outb);
|
||||
|
||||
if (cp->tcp.csty & JPC_COD_EPH) {
|
||||
if (!(ms = jpc_ms_create(JPC_MS_EPH))) {
|
||||
return -1;
|
||||
}
|
||||
jpc_putms(out, enc->cstate, ms);
|
||||
jpc_ms_destroy(ms);
|
||||
}
|
||||
|
||||
comp = &tile->tcmpts[compno];
|
||||
lvl = &comp->rlvls[lvlno];
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
prc = &band->prcs[prcno];
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
pass = cblk->curpass;
|
||||
|
||||
if (!pass) {
|
||||
continue;
|
||||
}
|
||||
if (pass->lyrno != lyrno) {
|
||||
assert(pass->lyrno < 0 || pass->lyrno > lyrno);
|
||||
continue;
|
||||
}
|
||||
|
||||
endpasses = &cblk->passes[cblk->numpasses];
|
||||
startpass = pass;
|
||||
endpass = startpass;
|
||||
while (endpass != endpasses && endpass->lyrno == lyrno){
|
||||
++endpass;
|
||||
}
|
||||
lastpass = endpass - 1;
|
||||
numnewpasses = endpass - startpass;
|
||||
|
||||
jas_stream_seek(cblk->stream, startpass->start, SEEK_SET);
|
||||
assert(jas_stream_tell(cblk->stream) == startpass->start);
|
||||
if (jas_stream_copy(out, cblk->stream, lastpass->end - startpass->start)) {
|
||||
return -1;
|
||||
}
|
||||
cblk->curpass = (endpass != endpasses) ? endpass : 0;
|
||||
cblk->numencpasses += numnewpasses;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void jpc_save_t2state(jpc_enc_t *enc)
|
||||
{
|
||||
/* stream pos in embedded T1 stream may be wrong since not saved/restored! */
|
||||
|
||||
jpc_enc_tcmpt_t *comp;
|
||||
jpc_enc_tcmpt_t *endcomps;
|
||||
jpc_enc_rlvl_t *lvl;
|
||||
jpc_enc_rlvl_t *endlvls;
|
||||
jpc_enc_band_t *band;
|
||||
jpc_enc_band_t *endbands;
|
||||
jpc_enc_cblk_t *cblk;
|
||||
jpc_enc_cblk_t *endcblks;
|
||||
jpc_enc_tile_t *tile;
|
||||
int prcno;
|
||||
jpc_enc_prc_t *prc;
|
||||
|
||||
tile = enc->curtile;
|
||||
|
||||
endcomps = &tile->tcmpts[tile->numtcmpts];
|
||||
for (comp = tile->tcmpts; comp != endcomps; ++comp) {
|
||||
endlvls = &comp->rlvls[comp->numrlvls];
|
||||
for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
|
||||
if (!lvl->bands) {
|
||||
continue;
|
||||
}
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
jpc_tagtree_copy(prc->savincltree, prc->incltree);
|
||||
jpc_tagtree_copy(prc->savnlibtree, prc->nlibtree);
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
cblk->savedcurpass = cblk->curpass;
|
||||
cblk->savednumencpasses = cblk->numencpasses;
|
||||
cblk->savednumlenbits = cblk->numlenbits;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void jpc_restore_t2state(jpc_enc_t *enc)
|
||||
{
|
||||
|
||||
jpc_enc_tcmpt_t *comp;
|
||||
jpc_enc_tcmpt_t *endcomps;
|
||||
jpc_enc_rlvl_t *lvl;
|
||||
jpc_enc_rlvl_t *endlvls;
|
||||
jpc_enc_band_t *band;
|
||||
jpc_enc_band_t *endbands;
|
||||
jpc_enc_cblk_t *cblk;
|
||||
jpc_enc_cblk_t *endcblks;
|
||||
jpc_enc_tile_t *tile;
|
||||
int prcno;
|
||||
jpc_enc_prc_t *prc;
|
||||
|
||||
tile = enc->curtile;
|
||||
|
||||
endcomps = &tile->tcmpts[tile->numtcmpts];
|
||||
for (comp = tile->tcmpts; comp != endcomps; ++comp) {
|
||||
endlvls = &comp->rlvls[comp->numrlvls];
|
||||
for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
|
||||
if (!lvl->bands) {
|
||||
continue;
|
||||
}
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
jpc_tagtree_copy(prc->incltree, prc->savincltree);
|
||||
jpc_tagtree_copy(prc->nlibtree, prc->savnlibtree);
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
cblk->curpass = cblk->savedcurpass;
|
||||
cblk->numencpasses = cblk->savednumencpasses;
|
||||
cblk->numlenbits = cblk->savednumlenbits;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void jpc_init_t2state(jpc_enc_t *enc, int raflag)
|
||||
{
|
||||
/* It is assumed that band->numbps and cblk->numbps precomputed */
|
||||
|
||||
jpc_enc_tcmpt_t *comp;
|
||||
jpc_enc_tcmpt_t *endcomps;
|
||||
jpc_enc_rlvl_t *lvl;
|
||||
jpc_enc_rlvl_t *endlvls;
|
||||
jpc_enc_band_t *band;
|
||||
jpc_enc_band_t *endbands;
|
||||
jpc_enc_cblk_t *cblk;
|
||||
jpc_enc_cblk_t *endcblks;
|
||||
jpc_enc_pass_t *pass;
|
||||
jpc_enc_pass_t *endpasses;
|
||||
jpc_tagtreenode_t *leaf;
|
||||
jpc_enc_tile_t *tile;
|
||||
int prcno;
|
||||
jpc_enc_prc_t *prc;
|
||||
|
||||
tile = enc->curtile;
|
||||
|
||||
endcomps = &tile->tcmpts[tile->numtcmpts];
|
||||
for (comp = tile->tcmpts; comp != endcomps; ++comp) {
|
||||
endlvls = &comp->rlvls[comp->numrlvls];
|
||||
for (lvl = comp->rlvls; lvl != endlvls; ++lvl) {
|
||||
if (!lvl->bands) {
|
||||
continue;
|
||||
}
|
||||
endbands = &lvl->bands[lvl->numbands];
|
||||
for (band = lvl->bands; band != endbands; ++band) {
|
||||
if (!band->data) {
|
||||
continue;
|
||||
}
|
||||
for (prcno = 0, prc = band->prcs; prcno < lvl->numprcs; ++prcno, ++prc) {
|
||||
if (!prc->cblks) {
|
||||
continue;
|
||||
}
|
||||
jpc_tagtree_reset(prc->incltree);
|
||||
jpc_tagtree_reset(prc->nlibtree);
|
||||
endcblks = &prc->cblks[prc->numcblks];
|
||||
for (cblk = prc->cblks; cblk != endcblks; ++cblk) {
|
||||
if (jas_stream_rewind(cblk->stream)) {
|
||||
assert(0);
|
||||
}
|
||||
cblk->curpass = (cblk->numpasses > 0) ? cblk->passes : 0;
|
||||
cblk->numencpasses = 0;
|
||||
cblk->numlenbits = 3;
|
||||
cblk->numimsbs = band->numbps - cblk->numbps;
|
||||
assert(cblk->numimsbs >= 0);
|
||||
leaf = jpc_tagtree_getleaf(prc->nlibtree, cblk - prc->cblks);
|
||||
jpc_tagtree_setvalue(prc->nlibtree, leaf, cblk->numimsbs);
|
||||
|
||||
if (raflag) {
|
||||
endpasses = &cblk->passes[cblk->numpasses];
|
||||
for (pass = cblk->passes; pass != endpasses; ++pass) {
|
||||
pass->lyrno = -1;
|
||||
pass->lyrno = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile)
|
||||
{
|
||||
jpc_pi_t *pi;
|
||||
int compno;
|
||||
jpc_picomp_t *picomp;
|
||||
jpc_pirlvl_t *pirlvl;
|
||||
jpc_enc_tcmpt_t *tcomp;
|
||||
int rlvlno;
|
||||
jpc_enc_rlvl_t *rlvl;
|
||||
int prcno;
|
||||
int *prclyrno;
|
||||
|
||||
if (!(pi = jpc_pi_create0())) {
|
||||
return 0;
|
||||
}
|
||||
pi->pktno = -1;
|
||||
pi->numcomps = cp->numcmpts;
|
||||
if (!(pi->picomps = jas_alloc2(pi->numcomps, sizeof(jpc_picomp_t)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
for (compno = 0, picomp = pi->picomps; compno < pi->numcomps; ++compno,
|
||||
++picomp) {
|
||||
picomp->pirlvls = 0;
|
||||
}
|
||||
|
||||
for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps;
|
||||
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
|
||||
picomp->numrlvls = tcomp->numrlvls;
|
||||
if (!(picomp->pirlvls = jas_alloc2(picomp->numrlvls,
|
||||
sizeof(jpc_pirlvl_t)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls; rlvlno <
|
||||
picomp->numrlvls; ++rlvlno, ++pirlvl) {
|
||||
pirlvl->prclyrnos = 0;
|
||||
}
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
|
||||
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
|
||||
/* XXX sizeof(long) should be sizeof different type */
|
||||
pirlvl->numprcs = rlvl->numprcs;
|
||||
if (rlvl->numprcs) {
|
||||
if (!(pirlvl->prclyrnos = jas_alloc2(pirlvl->numprcs,
|
||||
sizeof(long)))) {
|
||||
jpc_pi_destroy(pi);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
pirlvl->prclyrnos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pi->maxrlvls = 0;
|
||||
for (compno = 0, tcomp = tile->tcmpts, picomp = pi->picomps;
|
||||
compno < pi->numcomps; ++compno, ++tcomp, ++picomp) {
|
||||
picomp->hsamp = cp->ccps[compno].sampgrdstepx;
|
||||
picomp->vsamp = cp->ccps[compno].sampgrdstepy;
|
||||
for (rlvlno = 0, pirlvl = picomp->pirlvls, rlvl = tcomp->rlvls;
|
||||
rlvlno < picomp->numrlvls; ++rlvlno, ++pirlvl, ++rlvl) {
|
||||
pirlvl->prcwidthexpn = rlvl->prcwidthexpn;
|
||||
pirlvl->prcheightexpn = rlvl->prcheightexpn;
|
||||
for (prcno = 0, prclyrno = pirlvl->prclyrnos;
|
||||
prcno < pirlvl->numprcs; ++prcno, ++prclyrno) {
|
||||
*prclyrno = 0;
|
||||
}
|
||||
pirlvl->numhprcs = rlvl->numhprcs;
|
||||
}
|
||||
if (pi->maxrlvls < tcomp->numrlvls) {
|
||||
pi->maxrlvls = tcomp->numrlvls;
|
||||
}
|
||||
}
|
||||
|
||||
pi->numlyrs = tile->numlyrs;
|
||||
pi->xstart = tile->tlx;
|
||||
pi->ystart = tile->tly;
|
||||
pi->xend = tile->brx;
|
||||
pi->yend = tile->bry;
|
||||
|
||||
pi->picomp = 0;
|
||||
pi->pirlvl = 0;
|
||||
pi->x = 0;
|
||||
pi->y = 0;
|
||||
pi->compno = 0;
|
||||
pi->rlvlno = 0;
|
||||
pi->prcno = 0;
|
||||
pi->lyrno = 0;
|
||||
pi->xstep = 0;
|
||||
pi->ystep = 0;
|
||||
|
||||
pi->pchgno = -1;
|
||||
|
||||
pi->defaultpchg.prgord = tile->prg;
|
||||
pi->defaultpchg.compnostart = 0;
|
||||
pi->defaultpchg.compnoend = pi->numcomps;
|
||||
pi->defaultpchg.rlvlnostart = 0;
|
||||
pi->defaultpchg.rlvlnoend = pi->maxrlvls;
|
||||
pi->defaultpchg.lyrnoend = pi->numlyrs;
|
||||
pi->pchg = 0;
|
||||
|
||||
pi->valid = 0;
|
||||
|
||||
return pi;
|
||||
}
|
||||
Vendored
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tier 2 Encoder
|
||||
*
|
||||
* $Id: jpc_t2enc.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_T2ENC_H
|
||||
#define JPC_T2ENC_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "jpc_enc.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Encode the packets for a tile. */
|
||||
int jpc_enc_encpkts(jpc_enc_t *enc, jas_stream_t *out);
|
||||
|
||||
/* Encode the specified packet. */
|
||||
int jpc_enc_encpkt(jpc_enc_t *enc, jas_stream_t *out, int compno, int lvlno,
|
||||
int prcno, int lyrno);
|
||||
|
||||
/* Save the tier-2 coding state. */
|
||||
void jpc_save_t2state(jpc_enc_t *enc);
|
||||
|
||||
/* Restore the tier-2 coding state. */
|
||||
void jpc_restore_t2state(jpc_enc_t *enc);
|
||||
|
||||
/* Initialize the tier-2 coding state. */
|
||||
void jpc_init_t2state(jpc_enc_t *enc, int raflag);
|
||||
|
||||
/* Create a packet iterator for the encoder. */
|
||||
jpc_pi_t *jpc_enc_pi_create(jpc_enc_cp_t *cp, jpc_enc_tile_t *tile);
|
||||
|
||||
#endif
|
||||
Vendored
+393
@@ -0,0 +1,393 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tag Tree Library
|
||||
*
|
||||
* $Id: jpc_tagtree.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
|
||||
#include "jpc_tagtree.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Prototypes.
|
||||
\******************************************************************************/
|
||||
|
||||
static jpc_tagtree_t *jpc_tagtree_alloc(void);
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for creating and destroying tag trees.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a tag tree. */
|
||||
|
||||
jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv)
|
||||
{
|
||||
int nplh[JPC_TAGTREE_MAXDEPTH];
|
||||
int nplv[JPC_TAGTREE_MAXDEPTH];
|
||||
jpc_tagtreenode_t *node;
|
||||
jpc_tagtreenode_t *parentnode;
|
||||
jpc_tagtreenode_t *parentnode0;
|
||||
jpc_tagtree_t *tree;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int numlvls;
|
||||
int n;
|
||||
|
||||
assert(numleafsh > 0 && numleafsv > 0);
|
||||
|
||||
if (!(tree = jpc_tagtree_alloc())) {
|
||||
return 0;
|
||||
}
|
||||
tree->numleafsh_ = numleafsh;
|
||||
tree->numleafsv_ = numleafsv;
|
||||
|
||||
numlvls = 0;
|
||||
nplh[0] = numleafsh;
|
||||
nplv[0] = numleafsv;
|
||||
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);
|
||||
|
||||
if (!(tree->nodes_ = jas_alloc2(tree->numnodes_, sizeof(jpc_tagtreenode_t)))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Initialize the parent links for all nodes in the tree. */
|
||||
|
||||
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;
|
||||
|
||||
/* Initialize the data values to something sane. */
|
||||
|
||||
jpc_tagtree_reset(tree);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* Destroy a tag tree. */
|
||||
|
||||
void jpc_tagtree_destroy(jpc_tagtree_t *tree)
|
||||
{
|
||||
if (tree->nodes_) {
|
||||
jas_free(tree->nodes_);
|
||||
}
|
||||
jas_free(tree);
|
||||
}
|
||||
|
||||
static jpc_tagtree_t *jpc_tagtree_alloc()
|
||||
{
|
||||
jpc_tagtree_t *tree;
|
||||
|
||||
if (!(tree = jas_malloc(sizeof(jpc_tagtree_t)))) {
|
||||
return 0;
|
||||
}
|
||||
tree->numleafsh_ = 0;
|
||||
tree->numleafsv_ = 0;
|
||||
tree->numnodes_ = 0;
|
||||
tree->nodes_ = 0;
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Copy state information from one tag tree to another. */
|
||||
|
||||
void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree)
|
||||
{
|
||||
int n;
|
||||
jpc_tagtreenode_t *srcnode;
|
||||
jpc_tagtreenode_t *dstnode;
|
||||
|
||||
/* The two tag trees must have similar sizes. */
|
||||
assert(srctree->numleafsh_ == dsttree->numleafsh_ &&
|
||||
srctree->numleafsv_ == dsttree->numleafsv_);
|
||||
|
||||
n = srctree->numnodes_;
|
||||
srcnode = srctree->nodes_;
|
||||
dstnode = dsttree->nodes_;
|
||||
while (--n >= 0) {
|
||||
dstnode->value_ = srcnode->value_;
|
||||
dstnode->low_ = srcnode->low_;
|
||||
dstnode->known_ = srcnode->known_;
|
||||
++dstnode;
|
||||
++srcnode;
|
||||
}
|
||||
}
|
||||
|
||||
/* Reset all of the state information associated with a tag tree. */
|
||||
|
||||
void jpc_tagtree_reset(jpc_tagtree_t *tree)
|
||||
{
|
||||
int n;
|
||||
jpc_tagtreenode_t *node;
|
||||
|
||||
n = tree->numnodes_;
|
||||
node = tree->nodes_;
|
||||
|
||||
while (--n >= 0) {
|
||||
node->value_ = INT_MAX;
|
||||
node->low_ = 0;
|
||||
node->known_ = 0;
|
||||
++node;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the value associated with the specified leaf node, updating
|
||||
the other nodes as necessary. */
|
||||
|
||||
void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int value)
|
||||
{
|
||||
jpc_tagtreenode_t *node;
|
||||
|
||||
/* Avoid compiler warnings about unused parameters. */
|
||||
tree = 0;
|
||||
|
||||
assert(value >= 0);
|
||||
|
||||
node = leaf;
|
||||
while (node && node->value_ > value) {
|
||||
node->value_ = value;
|
||||
node = node->parent_;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a particular leaf node. */
|
||||
|
||||
jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n)
|
||||
{
|
||||
return &tree->nodes_[n];
|
||||
}
|
||||
|
||||
/* Invoke the tag tree encoding procedure. */
|
||||
|
||||
int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int threshold, jpc_bitstream_t *out)
|
||||
{
|
||||
jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1];
|
||||
jpc_tagtreenode_t **stkptr;
|
||||
jpc_tagtreenode_t *node;
|
||||
int low;
|
||||
|
||||
/* Avoid compiler warnings about unused parameters. */
|
||||
tree = 0;
|
||||
|
||||
assert(leaf);
|
||||
assert(threshold >= 0);
|
||||
|
||||
/* Traverse to the root of the tree, recording the path taken. */
|
||||
stkptr = stk;
|
||||
node = leaf;
|
||||
while (node->parent_) {
|
||||
*stkptr++ = node;
|
||||
node = node->parent_;
|
||||
}
|
||||
|
||||
low = 0;
|
||||
for (;;) {
|
||||
if (low > node->low_) {
|
||||
/* Deferred propagation of the lower bound downward in
|
||||
the tree. */
|
||||
node->low_ = low;
|
||||
} else {
|
||||
low = node->low_;
|
||||
}
|
||||
|
||||
while (low < threshold) {
|
||||
if (low >= node->value_) {
|
||||
if (!node->known_) {
|
||||
if (jpc_bitstream_putbit(out, 1) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
node->known_ = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (jpc_bitstream_putbit(out, 0) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
++low;
|
||||
}
|
||||
node->low_ = low;
|
||||
if (stkptr == stk) {
|
||||
break;
|
||||
}
|
||||
node = *--stkptr;
|
||||
|
||||
}
|
||||
return (leaf->low_ < threshold) ? 1 : 0;
|
||||
|
||||
}
|
||||
|
||||
/* Invoke the tag tree decoding procedure. */
|
||||
|
||||
int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int threshold, jpc_bitstream_t *in)
|
||||
{
|
||||
jpc_tagtreenode_t *stk[JPC_TAGTREE_MAXDEPTH - 1];
|
||||
jpc_tagtreenode_t **stkptr;
|
||||
jpc_tagtreenode_t *node;
|
||||
int low;
|
||||
int ret;
|
||||
|
||||
/* Avoid compiler warnings about unused parameters. */
|
||||
tree = 0;
|
||||
|
||||
assert(threshold >= 0);
|
||||
|
||||
/* Traverse to the root of the tree, recording the path taken. */
|
||||
stkptr = stk;
|
||||
node = leaf;
|
||||
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 ((ret = jpc_bitstream_getbit(in)) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (ret) {
|
||||
node->value_ = low;
|
||||
} else {
|
||||
++low;
|
||||
}
|
||||
}
|
||||
node->low_ = low;
|
||||
if (stkptr == stk) {
|
||||
break;
|
||||
}
|
||||
node = *--stkptr;
|
||||
}
|
||||
|
||||
return (node->value_ < threshold) ? 1 : 0;
|
||||
}
|
||||
|
||||
/******************************************************************************\
|
||||
* Code for debugging.
|
||||
\******************************************************************************/
|
||||
|
||||
void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out)
|
||||
{
|
||||
jpc_tagtreenode_t *node;
|
||||
int n;
|
||||
|
||||
node = tree->nodes_;
|
||||
n = tree->numnodes_;
|
||||
while (--n >= 0) {
|
||||
fprintf(out, "node %p, parent %p, value %d, lower %d, known %d\n",
|
||||
(void *) node, (void *) node->parent_, node->value_, node->low_,
|
||||
node->known_);
|
||||
++node;
|
||||
}
|
||||
}
|
||||
Vendored
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tag Tree Library
|
||||
*
|
||||
* $Id: jpc_tagtree.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_TAGTREE_H
|
||||
#define JPC_TAGTREE_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jpc_bs.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants
|
||||
\******************************************************************************/
|
||||
|
||||
/* The maximum allowable depth for a tag tree. */
|
||||
#define JPC_TAGTREE_MAXDEPTH 32
|
||||
|
||||
/******************************************************************************\
|
||||
* Types
|
||||
\******************************************************************************/
|
||||
|
||||
/*
|
||||
* Tag tree node.
|
||||
*/
|
||||
|
||||
typedef struct jpc_tagtreenode_ {
|
||||
|
||||
/* The parent of this node. */
|
||||
struct jpc_tagtreenode_ *parent_;
|
||||
|
||||
/* The value associated with this node. */
|
||||
int value_;
|
||||
|
||||
/* The lower bound on the value associated with this node. */
|
||||
int low_;
|
||||
|
||||
/* A flag indicating if the value is known exactly. */
|
||||
int known_;
|
||||
|
||||
} jpc_tagtreenode_t;
|
||||
|
||||
/*
|
||||
* Tag tree.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
|
||||
/* The number of leaves in the horizontal direction. */
|
||||
int numleafsh_;
|
||||
|
||||
/* The number of leaves in the vertical direction. */
|
||||
int numleafsv_;
|
||||
|
||||
/* The total number of nodes in the tree. */
|
||||
int numnodes_;
|
||||
|
||||
/* The nodes. */
|
||||
jpc_tagtreenode_t *nodes_;
|
||||
|
||||
} jpc_tagtree_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a tag tree. */
|
||||
jpc_tagtree_t *jpc_tagtree_create(int numleafsh, int numleafsv);
|
||||
|
||||
/* Destroy a tag tree. */
|
||||
void jpc_tagtree_destroy(jpc_tagtree_t *tree);
|
||||
|
||||
/* Copy data from one tag tree to another. */
|
||||
void jpc_tagtree_copy(jpc_tagtree_t *dsttree, jpc_tagtree_t *srctree);
|
||||
|
||||
/* Reset the tag tree state. */
|
||||
void jpc_tagtree_reset(jpc_tagtree_t *tree);
|
||||
|
||||
/* Set the value associated with a particular leaf node of a tag tree. */
|
||||
void jpc_tagtree_setvalue(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int value);
|
||||
|
||||
/* Get a pointer to a particular leaf node. */
|
||||
jpc_tagtreenode_t *jpc_tagtree_getleaf(jpc_tagtree_t *tree, int n);
|
||||
|
||||
/* Invoke the tag tree decoding procedure. */
|
||||
int jpc_tagtree_decode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int threshold, jpc_bitstream_t *in);
|
||||
|
||||
/* Invoke the tag tree encoding procedure. */
|
||||
int jpc_tagtree_encode(jpc_tagtree_t *tree, jpc_tagtreenode_t *leaf,
|
||||
int threshold, jpc_bitstream_t *out);
|
||||
|
||||
/* Dump a tag tree (for debugging purposes). */
|
||||
void jpc_tagtree_dump(jpc_tagtree_t *tree, FILE *out);
|
||||
|
||||
#endif
|
||||
Vendored
+288
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2004 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tree-Structured Filter Bank (TSFB) Library
|
||||
*
|
||||
* $Id: jpc_tsfb.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "jasper/jas_malloc.h"
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
#include "jpc_tsfb.h"
|
||||
#include "jpc_cod.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_util.h"
|
||||
#include "jpc_math.h"
|
||||
|
||||
void jpc_tsfb_getbands2(jpc_tsfb_t *tsfb, int locxstart, int locystart,
|
||||
int xstart, int ystart, int xend, int yend, jpc_tsfb_band_t **bands,
|
||||
int numlvls);
|
||||
|
||||
/******************************************************************************\
|
||||
*
|
||||
\******************************************************************************/
|
||||
|
||||
jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlvls)
|
||||
{
|
||||
jpc_tsfb_t *tsfb;
|
||||
|
||||
if (!(tsfb = malloc(sizeof(jpc_tsfb_t))))
|
||||
return 0;
|
||||
|
||||
if (numlvls > 0) {
|
||||
switch (qmfbid) {
|
||||
case JPC_COX_INS:
|
||||
tsfb->qmfb = &jpc_ns_qmfb2d;
|
||||
break;
|
||||
default:
|
||||
case JPC_COX_RFT:
|
||||
tsfb->qmfb = &jpc_ft_qmfb2d;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
tsfb->qmfb = 0;
|
||||
}
|
||||
tsfb->numlvls = numlvls;
|
||||
return tsfb;
|
||||
}
|
||||
|
||||
void jpc_tsfb_destroy(jpc_tsfb_t *tsfb)
|
||||
{
|
||||
free(tsfb);
|
||||
}
|
||||
|
||||
int jpc_tsfb_analyze(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
|
||||
{
|
||||
return (tsfb->numlvls > 0) ? jpc_tsfb_analyze2(tsfb, jas_seq2d_getref(a,
|
||||
jas_seq2d_xstart(a), jas_seq2d_ystart(a)), jas_seq2d_xstart(a),
|
||||
jas_seq2d_ystart(a), jas_seq2d_width(a),
|
||||
jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
|
||||
}
|
||||
|
||||
int jpc_tsfb_analyze2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
|
||||
int width, int height, int stride, int numlvls)
|
||||
{
|
||||
if (width > 0 && height > 0) {
|
||||
if ((*tsfb->qmfb->analyze)(a, xstart, ystart, width, height, stride))
|
||||
return -1;
|
||||
if (numlvls > 0) {
|
||||
if (jpc_tsfb_analyze2(tsfb, a, JPC_CEILDIVPOW2(xstart,
|
||||
1), JPC_CEILDIVPOW2(ystart, 1), JPC_CEILDIVPOW2(
|
||||
xstart + width, 1) - JPC_CEILDIVPOW2(xstart, 1),
|
||||
JPC_CEILDIVPOW2(ystart + height, 1) -
|
||||
JPC_CEILDIVPOW2(ystart, 1), stride, numlvls - 1)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *a)
|
||||
{
|
||||
return (tsfb->numlvls > 0) ? jpc_tsfb_synthesize2(tsfb,
|
||||
jas_seq2d_getref(a, jas_seq2d_xstart(a), jas_seq2d_ystart(a)),
|
||||
jas_seq2d_xstart(a), jas_seq2d_ystart(a), jas_seq2d_width(a),
|
||||
jas_seq2d_height(a), jas_seq2d_rowstep(a), tsfb->numlvls - 1) : 0;
|
||||
}
|
||||
|
||||
int jpc_tsfb_synthesize2(jpc_tsfb_t *tsfb, int *a, int xstart, int ystart,
|
||||
int width, int height, int stride, int numlvls)
|
||||
{
|
||||
if (numlvls > 0) {
|
||||
if (jpc_tsfb_synthesize2(tsfb, a, JPC_CEILDIVPOW2(xstart, 1),
|
||||
JPC_CEILDIVPOW2(ystart, 1), JPC_CEILDIVPOW2(xstart + width,
|
||||
1) - JPC_CEILDIVPOW2(xstart, 1), JPC_CEILDIVPOW2(ystart +
|
||||
height, 1) - JPC_CEILDIVPOW2(ystart, 1), stride, numlvls -
|
||||
1)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (width > 0 && height > 0) {
|
||||
if ((*tsfb->qmfb->synthesize)(a, xstart, ystart, width, height, stride)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart,
|
||||
uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend,
|
||||
jpc_tsfb_band_t *bands)
|
||||
{
|
||||
jpc_tsfb_band_t *band;
|
||||
|
||||
band = bands;
|
||||
if (tsfb->numlvls > 0) {
|
||||
jpc_tsfb_getbands2(tsfb, xstart, ystart, xstart, ystart, xend, yend,
|
||||
&band, tsfb->numlvls);
|
||||
} else {
|
||||
|
||||
band->xstart = xstart;
|
||||
band->ystart = ystart;
|
||||
band->xend = xend;
|
||||
band->yend = yend;
|
||||
band->locxstart = xstart;
|
||||
band->locystart = ystart;
|
||||
band->locxend = band->locxstart + band->xend - band->xstart;
|
||||
band->locyend = band->locystart + band->yend - band->ystart;
|
||||
band->orient = JPC_TSFB_LL;
|
||||
band->synenergywt = JPC_FIX_ONE;
|
||||
++band;
|
||||
}
|
||||
return band - bands;
|
||||
}
|
||||
|
||||
void jpc_tsfb_getbands2(jpc_tsfb_t *tsfb, int locxstart, int locystart,
|
||||
int xstart, int ystart, int xend, int yend, jpc_tsfb_band_t **bands,
|
||||
int numlvls)
|
||||
{
|
||||
int newxstart;
|
||||
int newystart;
|
||||
int newxend;
|
||||
int newyend;
|
||||
jpc_tsfb_band_t *band;
|
||||
|
||||
newxstart = JPC_CEILDIVPOW2(xstart, 1);
|
||||
newystart = JPC_CEILDIVPOW2(ystart, 1);
|
||||
newxend = JPC_CEILDIVPOW2(xend, 1);
|
||||
newyend = JPC_CEILDIVPOW2(yend, 1);
|
||||
|
||||
if (numlvls > 0) {
|
||||
|
||||
jpc_tsfb_getbands2(tsfb, locxstart, locystart, newxstart, newystart,
|
||||
newxend, newyend, bands, numlvls - 1);
|
||||
|
||||
band = *bands;
|
||||
band->xstart = JPC_FLOORDIVPOW2(xstart, 1);
|
||||
band->ystart = newystart;
|
||||
band->xend = JPC_FLOORDIVPOW2(xend, 1);
|
||||
band->yend = newyend;
|
||||
band->locxstart = locxstart + newxend - newxstart;
|
||||
band->locystart = locystart;
|
||||
band->locxend = band->locxstart + band->xend - band->xstart;
|
||||
band->locyend = band->locystart + band->yend - band->ystart;
|
||||
band->orient = JPC_TSFB_HL;
|
||||
band->synenergywt = jpc_dbltofix(tsfb->qmfb->hpenergywts[
|
||||
tsfb->numlvls - numlvls] * tsfb->qmfb->lpenergywts[
|
||||
tsfb->numlvls - numlvls]);
|
||||
++(*bands);
|
||||
|
||||
band = *bands;
|
||||
band->xstart = newxstart;
|
||||
band->ystart = JPC_FLOORDIVPOW2(ystart, 1);
|
||||
band->xend = newxend;
|
||||
band->yend = JPC_FLOORDIVPOW2(yend, 1);
|
||||
band->locxstart = locxstart;
|
||||
band->locystart = locystart + newyend - newystart;
|
||||
band->locxend = band->locxstart + band->xend - band->xstart;
|
||||
band->locyend = band->locystart + band->yend - band->ystart;
|
||||
band->orient = JPC_TSFB_LH;
|
||||
band->synenergywt = jpc_dbltofix(tsfb->qmfb->lpenergywts[
|
||||
tsfb->numlvls - numlvls] * tsfb->qmfb->hpenergywts[
|
||||
tsfb->numlvls - numlvls]);
|
||||
++(*bands);
|
||||
|
||||
band = *bands;
|
||||
band->xstart = JPC_FLOORDIVPOW2(xstart, 1);
|
||||
band->ystart = JPC_FLOORDIVPOW2(ystart, 1);
|
||||
band->xend = JPC_FLOORDIVPOW2(xend, 1);
|
||||
band->yend = JPC_FLOORDIVPOW2(yend, 1);
|
||||
band->locxstart = locxstart + newxend - newxstart;
|
||||
band->locystart = locystart + newyend - newystart;
|
||||
band->locxend = band->locxstart + band->xend - band->xstart;
|
||||
band->locyend = band->locystart + band->yend - band->ystart;
|
||||
band->orient = JPC_TSFB_HH;
|
||||
band->synenergywt = jpc_dbltofix(tsfb->qmfb->hpenergywts[
|
||||
tsfb->numlvls - numlvls] * tsfb->qmfb->hpenergywts[
|
||||
tsfb->numlvls - numlvls]);
|
||||
++(*bands);
|
||||
|
||||
} else {
|
||||
|
||||
band = *bands;
|
||||
band->xstart = xstart;
|
||||
band->ystart = ystart;
|
||||
band->xend = xend;
|
||||
band->yend = yend;
|
||||
band->locxstart = locxstart;
|
||||
band->locystart = locystart;
|
||||
band->locxend = band->locxstart + band->xend - band->xstart;
|
||||
band->locyend = band->locystart + band->yend - band->ystart;
|
||||
band->orient = JPC_TSFB_LL;
|
||||
band->synenergywt = jpc_dbltofix(tsfb->qmfb->lpenergywts[
|
||||
tsfb->numlvls - numlvls - 1] * tsfb->qmfb->lpenergywts[
|
||||
tsfb->numlvls - numlvls - 1]);
|
||||
++(*bands);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2004 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tree-Structured Filter Bank (TSFB) Library
|
||||
*
|
||||
* $Id: jpc_tsfb.h,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
#ifndef JPC_TSFB_H
|
||||
#define JPC_TSFB_H
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes.
|
||||
\******************************************************************************/
|
||||
|
||||
#include "jasper/jas_seq.h"
|
||||
|
||||
#include "jpc_fix.h"
|
||||
#include "jpc_qmfb.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Constants.
|
||||
\******************************************************************************/
|
||||
|
||||
#define JPC_TSFB_MAXBANDS (JPC_TSFB_MAXDEPTH * 3 + 1)
|
||||
#define JPC_TSFB_MAXDEPTH 32
|
||||
#define JPC_TSFB_RITIMODE JPC_QMFB1D_RITIMODE
|
||||
|
||||
#define JPC_TSFB_LL 0
|
||||
#define JPC_TSFB_LH 1
|
||||
#define JPC_TSFB_HL 2
|
||||
#define JPC_TSFB_HH 3
|
||||
|
||||
/******************************************************************************\
|
||||
* Types.
|
||||
\******************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
int xstart;
|
||||
int ystart;
|
||||
int xend;
|
||||
int yend;
|
||||
int orient;
|
||||
int locxstart;
|
||||
int locystart;
|
||||
int locxend;
|
||||
int locyend;
|
||||
jpc_fix_t synenergywt;
|
||||
} jpc_tsfb_band_t;
|
||||
|
||||
typedef struct {
|
||||
int numlvls;
|
||||
jpc_qmfb2d_t *qmfb;
|
||||
} jpc_tsfb_t;
|
||||
|
||||
/******************************************************************************\
|
||||
* Functions.
|
||||
\******************************************************************************/
|
||||
|
||||
/* Create a TSFB. */
|
||||
jpc_tsfb_t *jpc_cod_gettsfb(int qmfbid, int numlevels);
|
||||
|
||||
/* Destroy a TSFB. */
|
||||
void jpc_tsfb_destroy(jpc_tsfb_t *tsfb);
|
||||
|
||||
/* Perform analysis. */
|
||||
int jpc_tsfb_analyze(jpc_tsfb_t *tsfb, jas_seq2d_t *x);
|
||||
|
||||
/* Perform synthesis. */
|
||||
int jpc_tsfb_synthesize(jpc_tsfb_t *tsfb, jas_seq2d_t *x);
|
||||
|
||||
/* Get band information for a TSFB. */
|
||||
int jpc_tsfb_getbands(jpc_tsfb_t *tsfb, uint_fast32_t xstart,
|
||||
uint_fast32_t ystart, uint_fast32_t xend, uint_fast32_t yend,
|
||||
jpc_tsfb_band_t *bands);
|
||||
|
||||
#endif
|
||||
Vendored
+194
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2000 Image Power, Inc. and the University of
|
||||
* British Columbia.
|
||||
* Copyright (c) 2001-2003 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: jpc_util.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
|
||||
*/
|
||||
|
||||
/******************************************************************************\
|
||||
* Includes
|
||||
\******************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "jasper/jas_math.h"
|
||||
#include "jasper/jas_malloc.h"
|
||||
|
||||
#include "jpc_fix.h"
|
||||
#include "jpc_cs.h"
|
||||
#include "jpc_flt.h"
|
||||
#include "jpc_util.h"
|
||||
|
||||
/******************************************************************************\
|
||||
* Miscellaneous Functions
|
||||
\******************************************************************************/
|
||||
|
||||
int jpc_atoaf(char *s, int *numvalues, double **values)
|
||||
{
|
||||
static char delim[] = ", \t\n";
|
||||
char buf[4096];
|
||||
int n;
|
||||
double *vs;
|
||||
char *cp;
|
||||
|
||||
strncpy(buf, s, sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
n = 0;
|
||||
if ((cp = strtok(buf, delim))) {
|
||||
++n;
|
||||
while ((cp = strtok(0, delim))) {
|
||||
if (cp != '\0') {
|
||||
++n;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (n) {
|
||||
if (!(vs = jas_alloc2(n, sizeof(double)))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(buf, s, sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
n = 0;
|
||||
if ((cp = strtok(buf, delim))) {
|
||||
vs[n] = atof(cp);
|
||||
++n;
|
||||
while ((cp = strtok(0, delim))) {
|
||||
if (cp != '\0') {
|
||||
vs[n] = atof(cp);
|
||||
++n;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vs = 0;
|
||||
}
|
||||
|
||||
*numvalues = n;
|
||||
*values = vs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
jas_seq_t *jpc_seq_upsample(jas_seq_t *x, int m)
|
||||
{
|
||||
jas_seq_t *z;
|
||||
int i;
|
||||
|
||||
if (!(z = jas_seq_create(jas_seq_start(x) * m, (jas_seq_end(x) - 1) * m + 1)))
|
||||
return 0;
|
||||
for (i = jas_seq_start(z); i < jas_seq_end(z); i++) {
|
||||
*jas_seq_getref(z, i) = (!JAS_MOD(i, m)) ? jas_seq_get(x, i / m) :
|
||||
jpc_inttofix(0);
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
jpc_fix_t jpc_seq_norm(jas_seq_t *x)
|
||||
{
|
||||
jpc_fix_t s;
|
||||
int i;
|
||||
|
||||
s = jpc_inttofix(0);
|
||||
for (i = jas_seq_start(x); i < jas_seq_end(x); i++) {
|
||||
s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(x, i), jas_seq_get(x, i)));
|
||||
}
|
||||
|
||||
return jpc_dbltofix(sqrt(jpc_fixtodbl(s)));
|
||||
}
|
||||
|
||||
jas_seq_t *jpc_seq_conv(jas_seq_t *x, jas_seq_t *y)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
jas_seq_t *z;
|
||||
jpc_fix_t s;
|
||||
jpc_fix_t v;
|
||||
|
||||
z = jas_seq_create(jas_seq_start(x) + jas_seq_start(y),
|
||||
jas_seq_end(x) + jas_seq_end(y) - 1);
|
||||
assert(z);
|
||||
for (i = jas_seq_start(z); i < jas_seq_end(z); i++) {
|
||||
s = jpc_inttofix(0);
|
||||
for (j = jas_seq_start(y); j < jas_seq_end(y); j++) {
|
||||
k = i - j;
|
||||
if (k < jas_seq_start(x) || k >= jas_seq_end(x)) {
|
||||
v = JPC_FIX_ZERO;
|
||||
} else {
|
||||
v = jas_seq_get(x, k);
|
||||
}
|
||||
s = jpc_fix_add(s, jpc_fix_mul(jas_seq_get(y, j), v));
|
||||
}
|
||||
*jas_seq_getref(z, i) = s;
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
Vendored
+77
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2002 Michael David Adams.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
/* __START_OF_JASPER_LICENSE__
|
||||
*
|
||||
* JasPer License Version 2.0
|
||||
*
|
||||
* Copyright (c) 2001-2006 Michael David Adams
|
||||
* Copyright (c) 1999-2000 Image Power, Inc.
|
||||
* Copyright (c) 1999-2000 The University of British Columbia
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person (the
|
||||
* "User") obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge,
|
||||
* publish, distribute, and/or sell copies of the Software, and to permit
|
||||
* persons to whom the Software is furnished to do so, subject to the
|
||||
* following conditions:
|
||||
*
|
||||
* 1. The above copyright notices and this permission notice (which
|
||||
* includes the disclaimer below) shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* 2. The name of a copyright holder shall not be used to endorse or
|
||||
* promote products derived from the Software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
|
||||
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
|
||||
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
|
||||
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
||||
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
|
||||
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
|
||||
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
|
||||
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
|
||||
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
|
||||
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
|
||||
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
|
||||
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
|
||||
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
|
||||
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
|
||||
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
|
||||
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
|
||||
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
|
||||
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
|
||||
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
|
||||
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
|
||||
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
|
||||
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
|
||||
*
|
||||
* __END_OF_JASPER_LICENSE__
|
||||
*/
|
||||
|
||||
#ifndef JPC_UTIL_H
|
||||
#define JPC_UTIL_H
|
||||
|
||||
/* Parse a comma separated list of real numbers into an array of doubles. */
|
||||
int jpc_atoaf(char *s, int *numvalues, double **values);
|
||||
|
||||
/* Upsample a sequence. */
|
||||
jas_seq_t *jpc_seq_upsample(jas_seq_t *seq, int n);
|
||||
|
||||
/* Convolve two sequences. */
|
||||
jas_seq_t *jpc_seq_conv(jas_seq_t *seq0, jas_seq_t *seq1);
|
||||
|
||||
/* Compute the norm of a sequence. */
|
||||
jpc_fix_t jpc_seq_norm(jas_seq_t *x);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user