[2.0] Backport all changes from trunk

We only backport change that do not affect API or ABI
Update issue 313
This commit is contained in:
Mathieu Malaterre 2014-03-25 15:16:07 +00:00
commit f776cffbc6
127 changed files with 21162 additions and 19576 deletions

View File

@ -30,7 +30,7 @@ include_regular_expression("^.*$")
# OPENJPEG version number, useful for packaging and doxygen doc:
set(OPENJPEG_VERSION_MAJOR 2)
set(OPENJPEG_VERSION_MINOR 0)
set(OPENJPEG_VERSION_BUILD 0)
set(OPENJPEG_VERSION_BUILD 1)
set(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
set(PACKAGE_VERSION
@ -47,11 +47,12 @@ set(PACKAGE_VERSION
# 1.5 | 5
# 1.5.1 | 5
# 2.0 | 6
# 2.0.1 | 6
# above is the recommendation by the OPJ team. If you really need to override this default,
# you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
# cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
if(NOT OPENJPEG_SOVERSION)
SET(OPENJPEG_SOVERSION 6)
SET(OPENJPEG_SOVERSION 7)
endif(NOT OPENJPEG_SOVERSION)
set(OPENJPEG_LIBRARY_PROPERTIES
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
@ -181,14 +182,28 @@ endif()
#-----------------------------------------------------------------------------
# opj_config.h generation (1/2)
# Check if some include files are provided by the system
include(EnsureFileInclude)
# These files are mandatory
ensure_file_include("string.h" HAVE_STRING_H YES)
ensure_file_include("memory.h" HAVE_MEMORY_H YES)
ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
ensure_file_include("stdio.h" HAVE_STDIO_H YES)
ensure_file_include("math.h" HAVE_MATH_H YES)
ensure_file_include("float.h" HAVE_FLOAT_H YES)
ensure_file_include("time.h" HAVE_TIME_H YES)
ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
ensure_file_include("assert.h" HAVE_ASSERT_H YES)
# For the following files, we provide an alternative, they are not mandatory
ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
# why check this one ? for openjpip ?
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H)
CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
@ -199,7 +214,15 @@ OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
#-----------------------------------------------------------------------------
# Build Library
add_subdirectory(src)
if(BUILD_JPIP_SERVER)
find_package(CURL REQUIRED)
find_package(FCGI REQUIRED)
find_package(Threads REQUIRED)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR "Only pthread are supported")
endif()
endif()
add_subdirectory(src/lib)
#-----------------------------------------------------------------------------
# Build Applications
@ -233,6 +256,12 @@ configure_file(
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
@ONLY
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
@ONLY
)
#-----------------------------------------------------------------------------
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
@ -253,9 +282,8 @@ if(BUILD_TESTING)
# They could be found via svn on the OpenJPEG google code project
# svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
find_path(OPJ_DATA_ROOT README-OPJ-Data
PATHS
$ENV{OPJ_DATA_ROOT}
${CMAKE_SOURCE_DIR}/../data
PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../../data
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
)
# Add repository where to find tests
@ -319,4 +347,5 @@ if(UNIX)
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
endif()
endif()
#-----------------------------------------------------------------------------

View File

@ -27,6 +27,9 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION
# Suppress warning caused by intentional messages about deprecation
".*warning,.* is deprecated"
# java also warns about deprecated API
".*java.*deprecation"
".*deprecation.*"
# supress warnings caused by 3rd party libs:
".*thirdparty.*"
"libtiff.*has no symbols"

View File

@ -0,0 +1,26 @@
# Ensure that an include file is provided by the system
# Add the check about the mandatory status to the check_include_file macro
# provided by cmake
include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
macro(ensure_file_include INCLUDE_FILENAME VARIABLE_NAME MANDATORY_STATUS)
#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n"
# "VARIABLE_NAME=${VARIABLE_NAME} \n"
# "MANDATORY_STATUS=${MANDATORY_STATUS}")
CHECK_INCLUDE_FILE(${INCLUDE_FILENAME} ${VARIABLE_NAME})
#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n"
# "VARIABLE_NAME=${VARIABLE_NAME} \n"
# "VARIABLE_NAME_VALUE=${${VARIABLE_NAME}} \n"
# "MANDATORY_STATUS=${MANDATORY_STATUS}")
if (NOT ${${VARIABLE_NAME}})
if (${MANDATORY_STATUS})
message(FATAL_ERROR "The file ${INCLUDE_FILENAME} is mandatory but not found on your system")
endif()
endif()
endmacro()

View File

@ -1,9 +1,9 @@
#
# this module looks for KAKADu
# this module looks for KAKADU
# http://www.kakadusoftware.com/
#
#
# Copyright (c) 2006-2011 Mathieu Malaterre <mathieu.malaterre@gmail.com>
# Copyright (c) 2006-2014 Mathieu Malaterre <mathieu.malaterre@gmail.com>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
@ -14,6 +14,11 @@ find_program(KDU_EXPAND_EXECUTABLE
kdu_expand
)
find_program(KDU_COMPRESS_EXECUTABLE
kdu_compress
)
mark_as_advanced(
KDU_EXPAND_EXECUTABLE
KDU_COMPRESS_EXECUTABLE
)

View File

@ -7,7 +7,7 @@
# _LARGE_FILES
# _LARGEFILE_SOURCE
# _FILE_OFFSET_BITS 64
# HAVE_FSEEKO
# OPJ_HAVE_FSEEKO
#
# However, it is YOUR job to make sure these defines are set in a #cmakedefine so they
# end up in a config.h file that is included in your source if necessary!
@ -113,10 +113,10 @@ macro(OPJ_TEST_LARGE_FILES VARIABLE)
endif()
if(FSEEKO_COMPILE_OK)
set(HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello")
set(OPJ_HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello")
else()
message(STATUS "Checking for fseeko/ftello - not found")
set(HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello")
set(OPJ_HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello")
endif()
if(FILE64_OK AND FSEEKO_COMPILE_OK)

View File

@ -1,12 +1,12 @@
# required dep for server:
if(BUILD_JPIP_SERVER)
find_package(CURL REQUIRED)
find_package(FCGI REQUIRED)
find_package(Threads REQUIRED)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR "Only pthread are supported")
endif()
endif()
#if(BUILD_JPIP_SERVER)
# find_package(CURL REQUIRED)
# find_package(FCGI REQUIRED)
# find_package(Threads REQUIRED)
# if(NOT CMAKE_USE_PTHREADS_INIT)
# message(FATAL_ERROR "Only pthread are supported")
# endif()
#endif()
add_subdirectory(lib)
#add_subdirectory(lib)
#add_subdirectory(bin)

View File

@ -0,0 +1,7 @@
#-----------------------------------------------------------------------------
# opj_apps_config.h generation
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/opj_apps_config.h.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/opj_apps_config.h
@ONLY
)

View File

@ -33,15 +33,16 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "opj_config.h"
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "color.h"
#ifdef HAVE_LIBLCMS2
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
@ -86,19 +87,19 @@ static void sycc444_to_rgb(opj_image_t *img)
const int *y, *cb, *cr;
int maxw, maxh, max, i, offset, upb;
i = img->comps[0].prec;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = img->comps[0].w; maxh = img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
d0 = r = (int*)malloc(sizeof(int) * (size_t)max);
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i = 0; i < max; ++i)
{
@ -119,19 +120,19 @@ static void sycc422_to_rgb(opj_image_t *img)
int maxw, maxh, max, offset, upb;
int i, j;
i = img->comps[0].prec;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = img->comps[0].w; maxh = img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
d0 = r = (int*)malloc(sizeof(int) * (size_t)max);
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; ++i)
{
@ -150,8 +151,13 @@ static void sycc422_to_rgb(opj_image_t *img)
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw; img->comps[1].h = maxh;
img->comps[2].w = maxw; img->comps[2].h = maxh;
#else
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh;
#endif
img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx;
img->comps[1].dy = img->comps[0].dy;
@ -166,19 +172,19 @@ static void sycc420_to_rgb(opj_image_t *img)
int maxw, maxh, max, offset, upb;
int i, j;
i = img->comps[0].prec;
i = (int)img->comps[0].prec;
offset = 1<<(i - 1); upb = (1<<i)-1;
maxw = img->comps[0].w; maxh = img->comps[0].h;
maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h;
max = maxw * maxh;
y = img->comps[0].data;
cb = img->comps[1].data;
cr = img->comps[2].data;
d0 = r = (int*)malloc(sizeof(int) * max);
d1 = g = (int*)malloc(sizeof(int) * max);
d2 = b = (int*)malloc(sizeof(int) * max);
d0 = r = (int*)malloc(sizeof(int) * (size_t)max);
d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0; i < maxh; i += 2)
{
@ -209,8 +215,13 @@ static void sycc420_to_rgb(opj_image_t *img)
free(img->comps[1].data); img->comps[1].data = d1;
free(img->comps[2].data); img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw; img->comps[1].h = maxh;
img->comps[2].w = maxw; img->comps[2].h = maxh;
#else
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh;
#endif
img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx;
img->comps[1].dy = img->comps[0].dy;
@ -265,8 +276,8 @@ void color_sycc_to_rgb(opj_image_t *img)
}/* color_sycc_to_rgb() */
#if defined(HAVE_LIBLCMS2) || defined(HAVE_LIBLCMS1)
#ifdef HAVE_LIBLCMS1
#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1)
#ifdef OPJ_HAVE_LIBLCMS1
/* Bob Friesenhahn proposed:*/
#define cmsSigXYZData icSigXYZData
#define cmsSigLabData icSigLabData
@ -280,8 +291,9 @@ void color_sycc_to_rgb(opj_image_t *img)
#define cmsColorSpaceSignature icColorSpaceSignature
#define cmsGetHeaderRenderingIntent cmsTakeRenderingIntent
#endif /* HAVE_LIBLCMS1 */
#endif /* OPJ_HAVE_LIBLCMS1 */
/*#define DEBUG_PROFILE*/
void color_apply_icc_profile(opj_image_t *image)
{
cmsHPROFILE in_prof, out_prof;
@ -294,6 +306,11 @@ void color_apply_icc_profile(opj_image_t *image)
in_prof =
cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len);
#ifdef DEBUG_PROFILE
FILE *icm = fopen("debug.icm","wb");
fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm);
fclose(icm);
#endif
if(in_prof == NULL) return;
@ -302,14 +319,23 @@ void color_apply_icc_profile(opj_image_t *image)
intent = cmsGetHeaderRenderingIntent(in_prof);
max_w = image->comps[0].w; max_h = image->comps[0].h;
prec = image->comps[0].prec;
max_w = (int)image->comps[0].w;
max_h = (int)image->comps[0].h;
prec = (int)image->comps[0].prec;
oldspace = image->color_space;
if(out_space == cmsSigRgbData) /* enumCS 16 */
{
if( prec <= 8 )
{
in_type = TYPE_RGB_8;
out_type = TYPE_RGB_8;
}
else
{
in_type = TYPE_RGB_16;
out_type = TYPE_RGB_16;
}
out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB;
}
@ -360,12 +386,15 @@ out_space,
in_type,out_type
);
#else
(void)prec;
(void)in_space;
#endif /* DEBUG_PROFILE */
transform = cmsCreateTransform(in_prof, in_type,
out_prof, out_type, intent, 0);
#ifdef HAVE_LIBLCMS2
#ifdef OPJ_HAVE_LIBLCMS2
/* Possible for: LCMS_VERSION >= 2000 :*/
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
@ -378,7 +407,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
"ICC Profile ignored.\n",__FILE__,__LINE__);
#endif
image->color_space = oldspace;
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
#endif
@ -387,8 +416,44 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
if(image->numcomps > 2)/* RGB, RGBA */
{
if( prec <= 8 )
{
unsigned char *inbuf, *outbuf, *in, *out;
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char);
in = inbuf = (unsigned char*)malloc(nr_samples);
out = outbuf = (unsigned char*)malloc(nr_samples);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i)
{
*in++ = (unsigned char)*r++;
*in++ = (unsigned char)*g++;
*in++ = (unsigned char)*b++;
}
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
b = image->comps[2].data;
for(i = 0; i < max; ++i)
{
*r++ = (int)*out++;
*g++ = (int)*out++;
*b++ = (int)*out++;
}
free(inbuf); free(outbuf);
}
else
{
unsigned short *inbuf, *outbuf, *in, *out;
max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned short);
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short);
in = inbuf = (unsigned short*)malloc(nr_samples);
out = outbuf = (unsigned short*)malloc(nr_samples);
@ -403,7 +468,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
*in++ = (unsigned short)*b++;
}
cmsDoTransform(transform, inbuf, outbuf, max);
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
@ -416,12 +481,13 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
*b++ = (int)*out++;
}
free(inbuf); free(outbuf);
}
}
else /* GRAY, GRAYA */
{
unsigned char *in, *inbuf, *out, *outbuf;
max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned char);
max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
in = inbuf = (unsigned char*)malloc(nr_samples);
out = outbuf = (unsigned char*)malloc(nr_samples);
@ -434,8 +500,8 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
image->comps[1] = image->comps[0];
image->comps[2] = image->comps[0];
image->comps[1].data = (int*)calloc(max, sizeof(int));
image->comps[2].data = (int*)calloc(max, sizeof(int));
image->comps[1].data = (int*)calloc((size_t)max, sizeof(int));
image->comps[2].data = (int*)calloc((size_t)max, sizeof(int));
image->numcomps += 2;
@ -445,7 +511,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
{
*in++ = (unsigned char)*r++;
}
cmsDoTransform(transform, inbuf, outbuf, max);
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
r = image->comps[0].data;
g = image->comps[1].data;
@ -461,11 +527,11 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
cmsDeleteTransform(transform);
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in_prof);
cmsCloseProfile(out_prof);
#endif
}/* color_apply_icc_profile() */
#endif /* HAVE_LIBLCMS2 || HAVE_LIBLCMS1 */
#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */

View File

@ -41,9 +41,9 @@
#define BMP_DFMT 12
#define YUV_DFMT 13
#define TIF_DFMT 14
#define RAW_DFMT 15
#define RAW_DFMT 15 /* MSB / Big Endian */
#define TGA_DFMT 16
#define PNG_DFMT 17
#define RAWL_DFMT 18
#define RAWL_DFMT 18 /* LSB / Little Endian */
#endif /* _OPJ_FORMAT_DEFS_H_ */

View File

@ -0,0 +1,13 @@
/* create opj_apps_config.h for CMake */
#cmakedefine OPJ_HAVE_LIBPNG @HAVE_LIBPNG@
#cmakedefine OPJ_HAVE_PNG_H @HAVE_PNG_H@
#cmakedefine OPJ_HAVE_LIBTIFF @HAVE_LIBTIFF@
#cmakedefine OPJ_HAVE_TIFF_H @HAVE_TIFF_H@
#cmakedefine OPJ_HAVE_LIBLCMS1
#cmakedefine OPJ_HAVE_LIBLCMS2
#cmakedefine OPJ_HAVE_LCMS1_H
#cmakedefine OPJ_HAVE_LCMS2_H

View File

@ -10,11 +10,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*

View File

@ -11,6 +11,7 @@ set(common_SRCS
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
${OPENJPEG_SOURCE_DIR}/src/bin/common
${LCMS_INCLUDE_DIRNAME}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_config.h"
#include "opj_apps_config.h"
#include <stdio.h>
#include <string.h>
@ -57,10 +57,10 @@
#include "convert.h"
#include "index.h"
#ifdef HAVE_LIBLCMS2
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
@ -271,7 +271,7 @@ static int infile_format(const char *fname)
const char *s, *magic_s;
int ext_format, magic_format;
unsigned char buf[12];
unsigned int l_nb_read;
OPJ_SIZE_T l_nb_read;
reader = fopen(fname, "rb");
@ -447,7 +447,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case 'r': /* reduce option */
{
sscanf(opj_optarg, "%d", &parameters->cp_reduce);
sscanf(opj_optarg, "%ud", &parameters->cp_reduce);
}
break;
@ -456,7 +456,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case 'l': /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer);
sscanf(opj_optarg, "%ud", &parameters->cp_layer);
}
break;
@ -481,7 +481,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case 'd': /* Input decode ROI */
{
int size_optarg = (int)strlen(opj_optarg) + 1;
char *ROI_values = (char*) malloc(size_optarg);
char *ROI_values = (char*) malloc((size_t)size_optarg);
ROI_values[0] = '\0';
strncpy(ROI_values, opj_optarg, strlen(opj_optarg));
ROI_values[strlen(opj_optarg)] = '\0';
@ -496,7 +496,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
case 't': /* Input tile index */
{
sscanf(opj_optarg, "%d", &parameters->tile_index);
sscanf(opj_optarg, "%ud", &parameters->tile_index);
parameters->nb_tile_to_decode = 1;
}
break;
@ -639,8 +639,8 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
return EXIT_FAILURE;
}
else{
*DA_x0 = values[0]; *DA_y0 = values[1];
*DA_x1 = values[2]; *DA_y1 = values[3];
*DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1];
*DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3];
return EXIT_SUCCESS;
}
}
@ -689,6 +689,7 @@ int main(int argc, char **argv)
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
int failed = 0;
/* set decoding parameters to default values */
opj_set_default_decoder_parameters(&parameters);
@ -711,8 +712,8 @@ int main(int argc, char **argv)
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){
return EXIT_FAILURE;
@ -794,7 +795,7 @@ int main(int argc, char **argv)
/* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ){
fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n");
fprintf(stderr, "ERROR -> opj_compress: failed to setup the decoder\n");
opj_stream_destroy(l_stream);
fclose(fsrc);
opj_destroy_codec(l_codec);
@ -814,8 +815,8 @@ int main(int argc, char **argv)
if (!parameters.nb_tile_to_decode) {
/* Optional if you want decode the entire image */
if (!opj_set_decode_area(l_codec, image, parameters.DA_x0,
parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){
if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
(OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){
fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
@ -864,9 +865,16 @@ int main(int argc, char **argv)
if(image->color_space == OPJ_CLRSPC_SYCC){
color_sycc_to_rgb(image); /* FIXME */
}
if( image->color_space != OPJ_CLRSPC_SYCC
&& image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy
&& image->comps[1].dx != 1 )
image->color_space = OPJ_CLRSPC_SYCC;
else if (image->numcomps <= 2)
image->color_space = OPJ_CLRSPC_GRAY;
if(image->icc_profile_buf) {
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image); /* FIXME */
#endif
free(image->icc_profile_buf);
@ -878,7 +886,8 @@ int main(int argc, char **argv)
switch (parameters.cod_format) {
case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
@ -887,7 +896,8 @@ int main(int argc, char **argv)
case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
@ -896,25 +906,28 @@ int main(int argc, char **argv)
case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* HAVE_LIBTIFF */
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
@ -923,7 +936,8 @@ int main(int argc, char **argv)
case RAWL_DFMT: /* RAWL */
if(imagetorawl(image, parameters.outfile)){
fprintf(stdout,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
@ -932,27 +946,30 @@ int main(int argc, char **argv)
case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)){
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
fprintf(stderr,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* HAVE_LIBPNG */
#endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG
* and HAVE_LIBTIF or HAVE_LIBPNG is undefined
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
failed = 1;
}
/* free remaining structures */
@ -968,7 +985,7 @@ int main(int argc, char **argv)
opj_destroy_cstr_index(&cstr_index);
}
return EXIT_SUCCESS;
return failed ? EXIT_FAILURE : EXIT_SUCCESS;
}
/*end main*/

View File

@ -71,18 +71,18 @@ typedef struct img_folder{
/** Enable Cod Format for output*/
char set_out_format;
int flag;
}img_fol_t;
/* -------------------------------------------------------------------------- */
/* Declarations */
int get_num_images(char *imgdirpath);
int load_images(dircnt_t *dirptr, char *imgdirpath);
int get_file_format(const char *filename);
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
static int get_num_images(char *imgdirpath);
static int load_images(dircnt_t *dirptr, char *imgdirpath);
static int get_file_format(const char *filename);
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters);
static int infile_format(const char *fname);
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1);
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
/* -------------------------------------------------------------------------- */
static void decode_help_display(void) {
@ -116,7 +116,7 @@ static void decode_help_display(void) {
}
/* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){
static int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
@ -138,7 +138,7 @@ int get_num_images(char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
int load_images(dircnt_t *dirptr, char *imgdirpath){
static int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@ -164,7 +164,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
}
/* -------------------------------------------------------------------------- */
int get_file_format(const char *filename) {
static int get_file_format(const char *filename) {
unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@ -184,7 +184,7 @@ int get_file_format(const char *filename) {
}
/* -------------------------------------------------------------------------- */
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -221,7 +221,7 @@ static int infile_format(const char *fname)
const char *s, *magic_s;
int ext_format, magic_format;
unsigned char buf[12];
unsigned int l_nb_read;
size_t l_nb_read;
reader = fopen(fname, "rb");
@ -269,12 +269,12 @@ static int infile_format(const char *fname)
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
};
const char optlist[] = "i:o:hv";
const char optlist[] = "i:o:f:hv";
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
@ -314,6 +314,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
break;
/* ----------------------------------------------------- */
case 'f': /* flag */
img_fol->flag = atoi(opj_optarg);
break;
/* ----------------------------------------------------- */
case 'h': /* display an help description */
decode_help_display();
@ -425,6 +429,7 @@ int main(int argc, char *argv[])
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND;
/* Parse input and get user encoding parameters */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
@ -438,8 +443,8 @@ int main(int argc, char *argv[])
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*));
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){
return EXIT_FAILURE;
@ -553,7 +558,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
opj_dump_codec(l_codec, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout );
opj_dump_codec(l_codec, img_fol.flag, fout );
cstr_info = opj_get_cstr_info(l_codec);

View File

@ -488,7 +488,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
case 's': /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 2) {
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) {
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
return 1;
}

View File

@ -518,7 +518,8 @@ int main(int argc, char **argv) {
fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ",
(volume->comps[0].w >> volume->comps[0].factor[0]),
(volume->comps[0].h >> volume->comps[0].factor[1]),
(volume->comps[0].l >> volume->comps[0].factor[2]),volume->comps[0].prec);
(volume->comps[0].l >> volume->comps[0].factor[2]),
volume->comps[0].prec);
if(original){
psnr = calc_PSNR(original,volume);

View File

@ -23,7 +23,7 @@ if(BUILD_JPIP_SERVER)
# Build executable
add_executable(opj_server ${OPJ_SERVER_SRCS})
target_link_libraries(opj_server openjpip_server)
target_link_libraries(opj_server ${FCGI_LIBRARIES} openjpip_server)
set_property(
TARGET opj_server
APPEND PROPERTY
@ -59,6 +59,14 @@ endforeach()
# Build the two java clients:
find_package(Java 1.5 COMPONENTS Development) # javac, jar
# User can override this:
if(NOT DEFINED JAVA_SOURCE_VERSION)
set(JAVA_SOURCE_VERSION 1.5)
endif()
if(NOT DEFINED JAVA_TARGET_VERSION)
set(JAVA_TARGET_VERSION 1.5)
endif()
# Only build the java viewer if dev is found:
if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
set(jflags $ENV{JFLAGS})
@ -97,6 +105,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
add_custom_command(
OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags}
-source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION}
-classpath ${APACHE_XERCES_JAR}
${java2_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes2
COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
@ -127,6 +136,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
add_custom_command(
OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags}
-source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION}
${java1_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes1
COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar
${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/dist/manifest.txt -C

View File

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

View File

@ -48,6 +48,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fcgi_stdio.h"
#include "openjpip.h"
#ifndef QUIT_SIGNAL

View File

@ -11,6 +11,7 @@ set(common_SRCS
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openmj2
${OPENJPEG_SOURCE_DIR}/src/bin/common
${LCMS_INCLUDE_DIRNAME}

View File

@ -29,21 +29,21 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_config.h"
#include "opj_apps_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
#include <tiffio.h>
#endif /* HAVE_LIBTIFF */
#endif /* OPJ_HAVE_LIBTIFF */
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
#include <zlib.h>
#include <png.h>
#endif /* HAVE_LIBPNG */
#endif /* OPJ_HAVE_LIBPNG */
#include "openjpeg.h"
#include "convert.h"
@ -94,7 +94,7 @@ struct tga_header
static unsigned short get_ushort(unsigned short val) {
#ifdef WORDS_BIGENDIAN
#ifdef OPJ_BIG_ENDIAN
return( ((val & 0xff) << 8) + (val >> 8) );
#else
return( val );
@ -179,7 +179,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
return 1;
}
#if WORDS_BIGENDIAN == 1
#ifdef OPJ_BIG_ENDIAN
static inline int16_t swap16(int16_t x)
{
@ -226,7 +226,7 @@ static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
image_w = (unsigned short)width;
image_h = (unsigned short) height;
#if WORDS_BIGENDIAN == 0
#ifndef OPJ_BIG_ENDIAN
if(fwrite(&image_w, 2, 1, fp) != 1) goto fails;
if(fwrite(&image_h, 2, 1, fp) != 1) goto fails;
#else
@ -2074,7 +2074,7 @@ int imagetopnm(opj_image_t * image, const char *outfile)
return 0;
}/* imagetopnm() */
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
/* -->> -->> -->> -->>
TIFF IMAGE FORMAT
@ -2781,7 +2781,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
}/* tiftoimage() */
#endif /* HAVE_LIBTIFF */
#endif /* OPJ_HAVE_LIBTIFF */
/* -->> -->> -->> -->>
@ -3027,7 +3027,7 @@ int imagetoraw(opj_image_t * image, const char *outfile)
return 0;
}
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
#define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a"
#define MAGIC_SIZE 8
@ -3560,4 +3560,4 @@ fin:
return fails;
}/* imagetopng() */
#endif /* HAVE_LIBPNG */
#endif /* OPJ_HAVE_LIBPNG */

View File

@ -49,7 +49,7 @@
#include <strings.h>
#endif /* _WIN32 */
#include "opj_config.h"
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "opj_getopt.h"
#include "convert.h"
@ -1627,7 +1627,7 @@ int main(int argc, char **argv) {
return 1;
}
break;
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT:
image = tiftoimage(parameters.infile, &parameters);
if (!image) {
@ -1635,7 +1635,7 @@ int main(int argc, char **argv) {
return 1;
}
break;
#endif /* HAVE_LIBTIFF */
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT:
image = rawtoimage(parameters.infile, &parameters, &raw_cp);
if (!image) {
@ -1651,7 +1651,7 @@ int main(int argc, char **argv) {
return 1;
}
break;
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT:
image = pngtoimage(parameters.infile, &parameters);
if (!image) {
@ -1659,10 +1659,10 @@ int main(int argc, char **argv) {
return 1;
}
break;
#endif /* HAVE_LIBPNG */
#endif /* OPJ_HAVE_LIBPNG */
}
/* Can happen if input file is TIFF or PNG
* and HAVE_LIBTIF or HAVE_LIBPNG is undefined
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
if( !image)
{

View File

@ -49,16 +49,16 @@
#define _strnicmp strncasecmp
#endif /* _WIN32 */
#include "opj_config.h"
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "opj_getopt.h"
#include "convert.h"
#include "index.h"
#ifdef HAVE_LIBLCMS2
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
@ -753,7 +753,7 @@ int main(int argc, char **argv) {
if(image->icc_profile_buf)
{
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image);
#endif
@ -790,7 +790,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)){
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
@ -799,7 +799,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* HAVE_LIBTIFF */
#endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)){
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
@ -817,7 +817,7 @@ int main(int argc, char **argv) {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)){
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
@ -826,9 +826,9 @@ int main(int argc, char **argv) {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
}
break;
#endif /* HAVE_LIBPNG */
#endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG
* and HAVE_LIBTIF or HAVE_LIBPNG is undefined
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/
default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);

View File

@ -13,6 +13,7 @@ endif()
# Headers file are located here:
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
${OPENJPEG_SOURCE_DIR}/src/lib/openmj2
${OPENJPEG_SOURCE_DIR}/src/bin/common
${LCMS_INCLUDE_DIRNAME}
@ -31,6 +32,10 @@ foreach(exe
${MJ2_SRCS}
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
)
set_property(
TARGET ${exe}
APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2
)
target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2)
if(UNIX)

View File

@ -29,7 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include "opj_config.h"
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "j2k_lib.h"
#include "cio.h"
@ -61,13 +61,6 @@ static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */

View File

@ -29,7 +29,7 @@
#include <stdlib.h>
#include <string.h>
#include "opj_config.h"
#include "opj_apps_config.h"
#include "openjpeg.h"
#include "j2k_lib.h"
#include "cio.h"
@ -38,10 +38,10 @@
#include "mj2.h"
#include "mj2_convert.h"
#ifdef HAVE_LIBLCMS2
#ifdef OPJ_HAVE_LIBLCMS2
#include <lcms2.h>
#endif
#ifdef HAVE_LIBLCMS1
#ifdef OPJ_HAVE_LIBLCMS1
#include <lcms.h>
#endif
#include "color.h"
@ -61,13 +61,6 @@ static void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
static void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
@ -188,7 +181,7 @@ int main(int argc, char *argv[]) {
if(img->icc_profile_buf)
{
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img);
#endif

View File

@ -9,6 +9,7 @@ include_directories(
${OPENJPEG_SOURCE_DIR}/src/lib
${OPENJPEG_SOURCE_DIR}/src/bin
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
)
# original flags:

View File

@ -5,7 +5,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
include_directories(
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
)
# Defines the source code for the library
set(OPENJPEG_SRCS

View File

@ -146,17 +146,17 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
}
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) {
OPJ_INT32 i;
for (i = n - 1; i >= 0; i--) {
OPJ_UINT32 i;
for (i = n - 1; i < n; i--) {
opj_bio_putbit(bio, (v >> i) & 1);
}
}
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
OPJ_INT32 i;
OPJ_UINT32 i;
OPJ_UINT32 v;
v = 0;
for (i = n - 1; i >= 0; i--) {
for (i = n - 1; i < n; i--) {
v += opj_bio_getbit(bio) << i;
}
return v;

View File

@ -79,25 +79,25 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
opj_write_manf( i, num_box, box, cio,p_manager);
num_box = 0;
box[num_box].length = opj_write_mainmhix( offset, cstr_info, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
box[num_box].type = JPIP_MHIX;
num_box++;
box[num_box].length = opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
box[num_box].type = JPIP_TPIX;
num_box++;
box[num_box].length = opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
box[num_box].type = JPIP_THIX;
num_box++;
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
box[num_box].length = opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PPIX;
num_box++;
box[num_box].length = opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
box[num_box].type = JPIP_PHIX;
num_box++;
@ -110,7 +110,7 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
opj_free( box);
return len;
return (int)len;
}
@ -128,8 +128,8 @@ void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */
opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */
opj_write_bytes( l_data_header+6, 0, 2); /* CONT */
opj_write_bytes( l_data_header+8, coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, clen, 8); /* CLEN */
opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */
opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,p_manager);
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
@ -179,7 +179,7 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [8];
int i;
OPJ_UINT32 i;
OPJ_UINT32 len;
OPJ_OFF_T lenp;
@ -188,16 +188,16 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
@ -207,7 +207,7 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,

View File

@ -241,12 +241,16 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_strea
void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data)
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream)
return;
l_stream->m_user_data = p_data;
}
void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length)
{
opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream;
if (!l_stream)
return;
l_stream->m_user_data_length = data_length;
}
@ -503,7 +507,6 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si
if (! l_is_written) {
p_stream->m_status |= opj_stream_e_error;
p_stream->m_bytes_in_buffer = 0;
p_stream->m_current_data = p_stream->m_current_data;
return (OPJ_OFF_T) -1;
}
/* then skip */

View File

@ -389,23 +389,20 @@ INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_fun
OPJ_INT32 rw; /* width of the resolution level computed */
OPJ_INT32 rh; /* height of the resolution level computed */
OPJ_INT32 l_data_size;
OPJ_UINT32 l_data_size;
opj_tcd_resolution_t * l_cur_res = 0;
opj_tcd_resolution_t * l_last_res = 0;
w = tilec->x1-tilec->x0;
l = tilec->numresolutions-1;
l = (OPJ_INT32)tilec->numresolutions-1;
a = tilec->data;
l_cur_res = tilec->resolutions + l;
l_last_res = l_cur_res - 1;
rw = l_cur_res->x1 - l_cur_res->x0;
rh = l_cur_res->y1 - l_cur_res->y0;
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc(l_data_size);
l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32);
bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size);
if (! bj) {
return OPJ_FALSE;
}
@ -531,7 +528,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
OPJ_FLOAT64 norm = opj_dwt_norms_real[orient][level];
stepsize = (1 << (gain)) / norm;
}
opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]);
opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), (OPJ_INT32)(prec + gain), &tccp->stepsizes[bandno]);
}
}
@ -543,9 +540,9 @@ OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i
OPJ_UINT32 w;
while( --i ) {
++r;
if( mr < ( w = r->x1 - r->x0 ) )
if( mr < ( w = (OPJ_UINT32)(r->x1 - r->x0) ) )
mr = w ;
if( mr < ( w = r->y1 - r->y0 ) )
if( mr < ( w = (OPJ_UINT32)(r->y1 - r->y0) ) )
mr = w ;
}
return mr ;
@ -560,10 +557,10 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
opj_tcd_resolution_t* tr = tilec->resolutions;
OPJ_UINT32 rw = tr->x1 - tr->x0; /* width of the resolution level computed */
OPJ_UINT32 rh = tr->y1 - tr->y0; /* height of the resolution level computed */
OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resolution level computed */
OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolution level computed */
OPJ_UINT32 w = tilec->x1 - tilec->x0;
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
h.mem = (OPJ_INT32*)
opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
@ -578,13 +575,13 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
OPJ_UINT32 j;
++tr;
h.sn = rw;
v.sn = rh;
h.sn = (OPJ_INT32)rw;
v.sn = (OPJ_INT32)rh;
rw = tr->x1 - tr->x0;
rh = tr->y1 - tr->y0;
rw = (OPJ_UINT32)(tr->x1 - tr->x0);
rh = (OPJ_UINT32)(tr->y1 - tr->y0);
h.dn = rw - h.sn;
h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn);
h.cas = tr->x0 % 2;
for(j = 0; j < rh; ++j) {
@ -593,12 +590,12 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D
memcpy(&tiledp[j*w], h.mem, rw * sizeof(OPJ_INT32));
}
v.dn = rh - v.sn;
v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn);
v.cas = tr->y0 % 2;
for(j = 0; j < rw; ++j){
OPJ_UINT32 k;
opj_dwt_interleave_v(&v, &tiledp[j], w);
opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w);
(dwt_1D)(&v);
for(k = 0; k < rh; ++k) {
tiledp[k * w + j] = v.mem[k];
@ -657,14 +654,14 @@ void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a ,
OPJ_INT32 i;
for(i = 0; i < v->sn; ++i){
memcpy(&bi[i*2], &a[i*x], nb_elts_read * sizeof(OPJ_FLOAT32));
memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32));
}
a += v->sn * x;
bi = v->wavelet + 1 - v->cas;
for(i = 0; i < v->dn; ++i){
memcpy(&bi[i*2], &a[i*x], nb_elts_read * sizeof(OPJ_FLOAT32));
memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32));
}
}
@ -833,40 +830,40 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
opj_tcd_resolution_t* res = tilec->resolutions;
OPJ_UINT32 rw = res->x1 - res->x0; /* width of the resolution level computed */
OPJ_UINT32 rh = res->y1 - res->y0; /* height of the resolution level computed */
OPJ_UINT32 rw = (OPJ_UINT32)(res->x1 - res->x0); /* width of the resolution level computed */
OPJ_UINT32 rh = (OPJ_UINT32)(res->y1 - res->y0); /* height of the resolution level computed */
OPJ_UINT32 w = tilec->x1 - tilec->x0;
OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t));
v.wavelet = h.wavelet;
while( --numres) {
OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data;
OPJ_UINT32 bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0);
OPJ_UINT32 bufsize = (OPJ_UINT32)((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0));
OPJ_INT32 j;
h.sn = rw;
v.sn = rh;
h.sn = (OPJ_INT32)rw;
v.sn = (OPJ_INT32)rh;
++res;
rw = res->x1 - res->x0; /* width of the resolution level computed */
rh = res->y1 - res->y0; /* height of the resolution level computed */
rw = (OPJ_UINT32)(res->x1 - res->x0); /* width of the resolution level computed */
rh = (OPJ_UINT32)(res->y1 - res->y0); /* height of the resolution level computed */
h.dn = rw - h.sn;
h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn);
h.cas = res->x0 % 2;
for(j = rh; j > 3; j -= 4) {
for(j = (OPJ_INT32)rh; j > 3; j -= 4) {
OPJ_INT32 k;
opj_v4dwt_interleave_h(&h, aj, w, bufsize);
opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize);
opj_v4dwt_decode(&h);
for(k = rw; --k >= 0;){
aj[k ] = h.wavelet[k].f[0];
aj[k+w ] = h.wavelet[k].f[1];
aj[k+w*2] = h.wavelet[k].f[2];
aj[k+w*3] = h.wavelet[k].f[3];
for(k = (OPJ_INT32)rw; --k >= 0;){
aj[k ] = h.wavelet[k].f[0];
aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
aj[k+(OPJ_INT32)w*3] = h.wavelet[k].f[3];
}
aj += w*4;
@ -876,25 +873,25 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
if (rh & 0x03) {
OPJ_INT32 k;
j = rh & 0x03;
opj_v4dwt_interleave_h(&h, aj, w, bufsize);
opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize);
opj_v4dwt_decode(&h);
for(k = rw; --k >= 0;){
for(k = (OPJ_INT32)rw; --k >= 0;){
switch(j) {
case 3: aj[k+w*2] = h.wavelet[k].f[2];
case 2: aj[k+w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
case 3: aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 2: aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1: aj[k ] = h.wavelet[k].f[0];
}
}
}
v.dn = rh - v.sn;
v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn);
v.cas = res->y0 % 2;
aj = (OPJ_FLOAT32*) tilec->data;
for(j = rw; j > 3; j -= 4){
for(j = (OPJ_INT32)rw; j > 3; j -= 4){
OPJ_UINT32 k;
opj_v4dwt_interleave_v(&v, aj, w, 4);
opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, 4);
opj_v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
@ -908,11 +905,11 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
j = rw & 0x03;
opj_v4dwt_interleave_v(&v, aj, w, j);
opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, j);
opj_v4dwt_decode(&v);
for(k = 0; k < rh; ++k){
memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32));
memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * sizeof(OPJ_FLOAT32));
}
}
}

View File

@ -118,7 +118,7 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const
str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt);
(void)str_length;
/* parse the format string and put the result in 'message' */
vsprintf(message, fmt, arg); /* UniPG */
vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */
va_end(arg);

View File

@ -40,7 +40,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);
@ -106,23 +106,23 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj
OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
opj_image_comp_t* l_img_comp = NULL;
l_x0 = opj_int_max(p_cp->tx0 , p_image_header->x0);
l_y0 = opj_int_max(p_cp->ty0 , p_image_header->y0);
l_x1 = opj_int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image_header->x1);
l_y1 = opj_int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image_header->y1);
l_x0 = opj_int_max((OPJ_INT32)p_cp->tx0 , (OPJ_INT32)p_image_header->x0);
l_y0 = opj_int_max((OPJ_INT32)p_cp->ty0 , (OPJ_INT32)p_image_header->y0);
l_x1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + p_cp->tw * p_cp->tdx), (OPJ_INT32)p_image_header->x1);
l_y1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + p_cp->th * p_cp->tdy), (OPJ_INT32)p_image_header->y1);
l_img_comp = p_image_header->comps;
for (i = 0; i < p_image_header->numcomps; ++i) {
l_comp_x0 = opj_int_ceildiv(l_x0, l_img_comp->dx);
l_comp_y0 = opj_int_ceildiv(l_y0, l_img_comp->dy);
l_comp_x1 = opj_int_ceildiv(l_x1, l_img_comp->dx);
l_comp_y1 = opj_int_ceildiv(l_y1, l_img_comp->dy);
l_width = opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor);
l_height = opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor);
l_comp_x0 = opj_int_ceildiv(l_x0, (OPJ_INT32)l_img_comp->dx);
l_comp_y0 = opj_int_ceildiv(l_y0, (OPJ_INT32)l_img_comp->dy);
l_comp_x1 = opj_int_ceildiv(l_x1, (OPJ_INT32)l_img_comp->dx);
l_comp_y1 = opj_int_ceildiv(l_y1, (OPJ_INT32)l_img_comp->dy);
l_width = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, (OPJ_INT32)l_img_comp->factor);
l_height = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, (OPJ_INT32)l_img_comp->factor);
l_img_comp->w = l_width;
l_img_comp->h = l_height;
l_img_comp->x0 = l_comp_x0/*l_x0*/;
l_img_comp->y0 = l_comp_y0/*l_y0*/;
l_img_comp->x0 = (OPJ_UINT32)l_comp_x0/*l_x0*/;
l_img_comp->y0 = (OPJ_UINT32)l_comp_y0/*l_y0*/;
++l_img_comp;
}
}

View File

@ -67,8 +67,8 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix,
OPJ_UINT32 nb_compo)
{
OPJ_BYTE * l_data = 00;
OPJ_UINT32 l_permutation_size = nb_compo * sizeof(OPJ_UINT32);
OPJ_UINT32 l_swap_size = nb_compo * sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32);
OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size;
OPJ_UINT32 * lPermutations = 00;
OPJ_FLOAT32 * l_double_data = 00;
@ -109,7 +109,7 @@ OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_UINT32 i,j,k;
OPJ_FLOAT32 p;
OPJ_UINT32 lLastColum = nb_compo - 1;
OPJ_UINT32 lSwapSize = nb_compo * sizeof(OPJ_FLOAT32);
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_FLOAT32 * lTmpMatrix = matrix;
OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix;
OPJ_UINT32 offset = 1;
@ -250,7 +250,7 @@ void opj_lupSolve (OPJ_FLOAT32 * pResult,
lTmpMatrix = lLineMatrix;
u = *(lTmpMatrix++);
lCurrentPtr = lDestPtr--;
for (j = k + 1; j < nb_compo; ++j) {
for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) {
/* sum += matrix[k][j] * x[j] */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
}
@ -272,7 +272,7 @@ void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix,
OPJ_UINT32 j,i;
OPJ_FLOAT32 * lCurrentPtr;
OPJ_FLOAT32 * lLineMatrix = pDestMatrix;
OPJ_UINT32 lSwapSize = nb_compo * sizeof(OPJ_FLOAT32);
OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
for (j = 0; j < nb_compo; ++j) {
lCurrentPtr = lLineMatrix++;

File diff suppressed because it is too large Load Diff

View File

@ -428,12 +428,10 @@ static void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2);
static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
/* ----------------------------------------------------------------------- */
OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
OPJ_UINT32 * p_number_bytes_read,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager
)
OPJ_UINT32 * p_number_bytes_read,
opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
/* read header from file */
OPJ_BYTE l_data_header [8];
@ -444,7 +442,7 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
assert(p_number_bytes_read != 00);
assert(p_manager != 00);
*p_number_bytes_read = opj_stream_read_data(cio,l_data_header,8,p_manager);
*p_number_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager);
if (*p_number_bytes_read != 8) {
return OPJ_FALSE;
}
@ -452,13 +450,21 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
/* process read data */
opj_read_bytes(l_data_header,&(box->length), 4);
opj_read_bytes(l_data_header+4,&(box->type), 4);
if(box->length == 0)/* last box */
{
const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio);
box->length = (OPJ_UINT32)bleft;
assert( (OPJ_OFF_T)box->length == bleft );
return OPJ_TRUE;
}
/* do we have a "special very large box ?" */
/* read then the XLBox */
if (box->length == 1) {
OPJ_UINT32 l_xl_part_size;
OPJ_UINT32 l_nb_bytes_read = opj_stream_read_data(cio,l_data_header,8,p_manager);
OPJ_UINT32 l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager);
if (l_nb_bytes_read != 8) {
if (l_nb_bytes_read > 0) {
*p_number_bytes_read += l_nb_bytes_read;
@ -467,14 +473,15 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
return OPJ_FALSE;
}
*p_number_bytes_read = 16;
opj_read_bytes(l_data_header,&l_xl_part_size, 4);
if (l_xl_part_size != 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
return OPJ_FALSE;
}
opj_read_bytes(l_data_header,&(box->length), 4);
opj_read_bytes(l_data_header+4,&(box->length), 4);
}
return OPJ_TRUE;
return OPJ_TRUE;
}
#if 0
@ -607,7 +614,7 @@ OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2,
{
OPJ_UINT32 i;
/* room for 8 bytes for box and 1 byte for each component */
OPJ_INT32 l_bpcc_size = 8 + jp2->numcomps;
OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps;
OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr;
/* preconditions */
@ -747,6 +754,85 @@ void opj_jp2_free_pclr(opj_jp2_color_t *color)
opj_free(color->jp2_pclr); color->jp2_pclr = NULL;
}
static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager)
{
OPJ_UINT16 i;
/* testcase 4149.pdf.SIGSEGV.cf7.3501 */
if (color->jp2_cdef) {
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
OPJ_UINT16 n = color->jp2_cdef->n;
for (i = 0; i < n; i++) {
if (info[i].cn >= image->numcomps) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, image->numcomps);
return OPJ_FALSE;
}
if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= image->numcomps) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, image->numcomps);
return OPJ_FALSE;
}
}
}
/* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and
66ea31acbb0f23a2bbc91f64d69a03f5_signal_sigsegv_13937c0_7030_5725.pdf */
if (color->jp2_pclr && color->jp2_pclr->cmap) {
OPJ_UINT16 nr_channels = color->jp2_pclr->nr_channels;
opj_jp2_cmap_comp_t *cmap = color->jp2_pclr->cmap;
OPJ_BOOL *pcol_usage, is_sane = OPJ_TRUE;
/* verify that all original components match an existing one */
for (i = 0; i < nr_channels; i++) {
if (cmap[i].cmp >= image->numcomps) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", cmap[i].cmp, image->numcomps);
is_sane = OPJ_FALSE;
}
}
pcol_usage = opj_calloc(nr_channels, sizeof(OPJ_BOOL));
if (!pcol_usage) {
opj_event_msg(p_manager, EVT_ERROR, "Unexpected OOM.\n");
return OPJ_FALSE;
}
/* verify that no component is targeted more than once */
for (i = 0; i < nr_channels; i++) {
OPJ_UINT16 pcol = cmap[i].pcol;
assert(cmap[i].mtyp == 0 || cmap[i].mtyp == 1);
if (pcol >= nr_channels) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol);
is_sane = OPJ_FALSE;
}
else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol);
is_sane = OPJ_FALSE;
}
else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
/* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then
* the value of this field shall be 0. */
opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol);
is_sane = OPJ_FALSE;
}
else
pcol_usage[pcol] = OPJ_TRUE;
}
/* verify that all components are targeted at least once */
for (i = 0; i < nr_channels; i++) {
if (!pcol_usage[i] && cmap[i].mtyp != 0) {
opj_event_msg(p_manager, EVT_ERROR, "Component %d doesn't have a mapping.\n", i);
is_sane = OPJ_FALSE;
}
}
opj_free(pcol_usage);
if (!is_sane) {
return OPJ_FALSE;
}
}
return OPJ_TRUE;
}
/* file9.jp2 */
void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
{
opj_image_comp_t *old_comps, *new_comps;
@ -771,40 +857,52 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp;
new_comps[pcol] = old_comps[cmp];
/* Direct use */
if(cmap[i].mtyp == 0){
old_comps[cmp].data = NULL; continue;
}
if(cmap[i].mtyp == 0){
assert( pcol == 0 );
new_comps[i] = old_comps[cmp];
} else {
assert( i == pcol );
new_comps[pcol] = old_comps[cmp];
}
/* Palette mapping: */
new_comps[pcol].data = (OPJ_INT32*)
new_comps[i].data = (OPJ_INT32*)
opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32));
new_comps[pcol].prec = channel_size[i];
new_comps[pcol].sgnd = channel_sign[i];
new_comps[i].prec = channel_size[i];
new_comps[i].sgnd = channel_sign[i];
}
top_k = color->jp2_pclr->nr_entries - 1;
for(i = 0; i < nr_channels; ++i) {
/* Direct use: */
if(cmap[i].mtyp == 0) continue;
/* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol;
src = old_comps[cmp].data;
dst = new_comps[pcol].data;
assert( src );
max = new_comps[pcol].w * new_comps[pcol].h;
for(j = 0; j < max; ++j)
{
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
/* Direct use: */
if(cmap[i].mtyp == 0) {
assert( cmp == 0 );
dst = new_comps[i].data;
assert( dst );
for(j = 0; j < max; ++j) {
dst[j] = src[j];
}
}
else {
assert( i == pcol );
dst = new_comps[pcol].data;
assert( dst );
for(j = 0; j < max; ++j) {
/* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k;
/* The colour */
dst[j] = entries[k * nr_channels + pcol];
}
/* The colour */
dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
}
}
}
max = image->numcomps;
@ -832,6 +930,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
OPJ_UINT16 nr_entries,nr_channels;
OPJ_UINT16 i, j;
OPJ_UINT32 l_value;
OPJ_BYTE *orig_header_data = p_pclr_header_data;
/* preconditions */
assert(p_pclr_header_data != 00);
@ -842,6 +941,9 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
if(jp2->color.jp2_pclr)
return OPJ_FALSE;
if (p_pclr_header_size < 3)
return OPJ_FALSE;
opj_read_bytes(p_pclr_header_data, &l_value , 2); /* NE */
p_pclr_header_data += 2;
nr_entries = (OPJ_UINT16) l_value;
@ -850,7 +952,10 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
++p_pclr_header_data;
nr_channels = (OPJ_UINT16) l_value;
entries = (OPJ_UINT32*) opj_malloc(nr_channels * nr_entries * sizeof(OPJ_UINT32));
if (p_pclr_header_size < 3 + (OPJ_UINT32)nr_channels || nr_channels == 0 || nr_entries >= (OPJ_UINT32)-1 / nr_channels)
return OPJ_FALSE;
entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof(OPJ_UINT32));
if (!entries)
return OPJ_FALSE;
channel_size = (OPJ_BYTE*) opj_malloc(nr_channels);
@ -889,13 +994,18 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
opj_read_bytes(p_pclr_header_data, &l_value , 1); /* Bi */
++p_pclr_header_data;
channel_size[i] = (l_value & 0x7f) + 1;
channel_sign[i] = (l_value & 0x80)? 1 : 0;
channel_size[i] = (OPJ_BYTE)((l_value & 0x7f) + 1);
channel_sign[i] = (l_value & 0x80) ? 1 : 0;
}
for(j = 0; j < nr_entries; ++j) {
for(i = 0; i < nr_channels; ++i) {
OPJ_INT32 bytes_to_read = (channel_size[i]+7)>>3;
OPJ_UINT32 bytes_to_read = (OPJ_UINT32)((channel_size[i]+7)>>3);
if (bytes_to_read > sizeof(OPJ_UINT32))
bytes_to_read = sizeof(OPJ_UINT32);
if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read)
return OPJ_FALSE;
opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */
p_pclr_header_data += bytes_to_read;
@ -938,6 +1048,11 @@ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2,
}
nr_channels = jp2->color.jp2_pclr->nr_channels;
if (p_cmap_header_size < (OPJ_UINT32)nr_channels * 4) {
opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CMAP box.\n");
return OPJ_FALSE;
}
cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t));
if (!cmap)
return OPJ_FALSE;
@ -970,13 +1085,22 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
info = color->jp2_cdef->info;
n = color->jp2_cdef->n;
for(i = 0; i < n; ++i)
{
/* WATCH: acn = asoc - 1 ! */
if((asoc = info[i].asoc) == 0) continue;
for(i = 0; i < n; ++i)
{
/* WATCH: acn = asoc - 1 ! */
asoc = info[i].asoc;
if(asoc == 0 || asoc == 65535)
{
continue;
}
cn = info[i].cn;
acn = asoc - 1;
cn = info[i].cn;
acn = (OPJ_UINT16)(asoc - 1);
if( cn >= image->numcomps || acn >= image->numcomps )
{
fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps);
continue;
}
if(cn != acn)
{
@ -986,9 +1110,10 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t));
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
info[i].asoc = cn + 1;
info[acn].asoc = info[acn].cn + 1;
info[i].asoc = (OPJ_UINT16)(cn + 1);
info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1);
}
}
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
@ -1017,6 +1142,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
* inside a JP2 Header box.'*/
if(jp2->color.jp2_cdef) return OPJ_FALSE;
if (p_cdef_header_size < 2) {
opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n");
return OPJ_FALSE;
}
opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */
p_cdef_header_data+= 2;
@ -1025,6 +1155,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
return OPJ_FALSE;
}
if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) {
opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n");
return OPJ_FALSE;
}
cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t));
if (!cdef_info)
return OPJ_FALSE;
@ -1092,26 +1227,32 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
++p_colr_header_data;
if (jp2->meth == 1) {
if (p_colr_header_size != 7) {
opj_event_msg(p_manager, EVT_ERROR, "Bad BPCC header box (bad size)\n");
if (p_colr_header_size < 7) {
opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
return OPJ_FALSE;
}
if (p_colr_header_size > 7) {
/* testcase Altona_Technical_v20_x4.pdf */
opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (bad size: %d)\n", p_colr_header_size);
}
opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */
jp2->color.jp2_has_colr = 1;
}
else if (jp2->meth == 2) {
/* ICC profile */
OPJ_INT32 it_icc_value = 0;
OPJ_INT32 icc_len = p_colr_header_size - 3;
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc(icc_len);
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)icc_len);
if (!jp2->color.icc_profile_buf)
{
jp2->color.icc_profile_len = 0;
return OPJ_FALSE;
}
memset(jp2->color.icc_profile_buf, 0, icc_len * sizeof(OPJ_BYTE));
memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE));
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value)
{
@ -1119,14 +1260,17 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
++p_colr_header_data;
jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
}
jp2->color.jp2_has_colr = 1;
}
else
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), so we will skip the fields following the approx field.\n", jp2->meth);
jp2->color.jp2_has_colr = 1;
return OPJ_TRUE;
else if (jp2->meth > 2)
{
/* ISO/IEC 15444-1:2004 (E), Table I.9 ­ Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
}
return OPJ_TRUE;
}
OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
@ -1144,6 +1288,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
}
if (!jp2->ignore_pclr_cmap_cdef){
if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
return OPJ_FALSE;
}
/* Set Image Color Space */
if (jp2->enumcs == 16)
@ -1188,7 +1335,7 @@ OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
OPJ_INT32 i, l_nb_pass;
/* size of data for super box*/
OPJ_INT32 l_jp2h_size = 8;
OPJ_UINT32 l_jp2h_size = 8;
OPJ_BOOL l_result = OPJ_TRUE;
/* to store the data of the super box */
@ -1415,7 +1562,8 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
opj_event_mgr_t * p_manager)
{
OPJ_UINT32 i;
OPJ_INT32 depth_0, sign;
OPJ_UINT32 depth_0;
OPJ_UINT32 sign;
if(!jp2 || !parameters || !image)
return;
@ -1464,7 +1612,7 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2,
sign = image->comps[0].sgnd;
jp2->bpc = depth_0 + (sign << 7);
for (i = 1; i < image->numcomps; i++) {
OPJ_INT32 depth = image->comps[i].prec - 1;
OPJ_UINT32 depth = image->comps[i].prec - 1;
sign = image->comps[i].sgnd;
if (depth_0 != depth)
jp2->bpc = 255;
@ -1675,6 +1823,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
opj_free(l_current_data);
return OPJ_FALSE;
}
/* testcase 1851.pdf.SIGSEGV.ce9.948 */
else if (box.length < l_nb_bytes_read) {
opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type);
opj_free(l_current_data);
return OPJ_FALSE;
}
l_current_handler = opj_jp2_find_handler(box.type);
l_current_data_size = box.length - l_nb_bytes_read;
@ -1682,7 +1836,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
if (l_current_handler != 00) {
if (l_current_data_size > l_last_data_size) {
OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size);
if (!l_current_data){
if (!new_current_data) {
opj_free(l_current_data);
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 box\n");
return OPJ_FALSE;
@ -1691,7 +1845,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
l_last_data_size = l_current_data_size;
}
l_nb_bytes_read = opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager);
if (l_nb_bytes_read != l_current_data_size) {
opj_event_msg(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n");
opj_free(l_current_data);
@ -2064,11 +2218,11 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
/* process read data */
opj_read_bytes(p_data, &l_value, 4);
p_data += 4;
box->length = (OPJ_INT32)(l_value);
box->length = (OPJ_UINT32)(l_value);
opj_read_bytes(p_data, &l_value, 4);
p_data += 4;
box->type = (OPJ_INT32)(l_value);
box->type = (OPJ_UINT32)(l_value);
*p_number_bytes_read = 8;
@ -2093,7 +2247,7 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
opj_read_bytes(p_data, &l_value, 4);
*p_number_bytes_read += 4;
box->length = (OPJ_INT32)(l_value);
box->length = (OPJ_UINT32)(l_value);
if (box->length == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
@ -2324,6 +2478,10 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
return OPJ_FALSE;
}
if (!opj_jp2_check_color(p_image, &(p_jp2->color), p_manager)) {
return OPJ_FALSE;
}
/* Set Image Color Space */
if (p_jp2->enumcs == 16)
p_image->color_space = OPJ_CLRSPC_SRGB;
@ -2551,6 +2709,7 @@ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2,
return OPJ_TRUE;
}
#if 0
static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
@ -2583,8 +2742,10 @@ static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int le
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
}
#endif
#if 0
static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
@ -2606,4 +2767,5 @@ static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int len
return len;
}
#endif
#endif /* USE_JPIP */

View File

@ -10,4 +10,5 @@ Description: JPEG2000 library (Part 1 and 2)
URL: http://www.openjpeg.org/
Version: @OPENJPEG_VERSION@
Libs: -L${libdir} -lopenjp2
Libs.private: -lm
Cflags: -I${includedir}

View File

@ -230,7 +230,7 @@ OPJ_BOOL opj_mct_encode_custom(
lCurrentMatrix = lCurrentData + pNbComp;
for (i =0;i<lNbMatCoeff;++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * lMultiplicator);
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
}
for (i = 0; i < n; ++i) {

View File

@ -199,13 +199,13 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
void opj_mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->bp++;
*mqc->bp = mqc->c >> 20;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */
mqc->bp++;
*mqc->bp = mqc->c >> 19;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
} else {
@ -213,12 +213,12 @@ void opj_mqc_byteout(opj_mqc_t *mqc) {
if (*mqc->bp == 0xff) {
mqc->c &= 0x7ffffff;
mqc->bp++;
*mqc->bp = mqc->c >> 20;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
mqc->c &= 0xfffff;
mqc->ct = 7;
} else {
mqc->bp++;
*mqc->bp = mqc->c >> 19;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 19);
mqc->c &= 0x7ffff;
mqc->ct = 8;
}
@ -274,10 +274,10 @@ void opj_mqc_setbits(opj_mqc_t *mqc) {
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
d = 1 - (*mqc->curctx)->mps;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
} else {
d = (*mqc->curctx)->mps;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
}
@ -288,11 +288,11 @@ static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval;
d = (*mqc->curctx)->mps;
d = (OPJ_INT32)(*mqc->curctx)->mps;
*mqc->curctx = (*mqc->curctx)->nmps;
} else {
mqc->a = (*mqc->curctx)->qeval;
d = 1 - (*mqc->curctx)->mps;
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
*mqc->curctx = (*mqc->curctx)->nlps;
}
@ -371,7 +371,11 @@ void opj_mqc_destroy(opj_mqc_t *mqc) {
}
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
return mqc->bp - mqc->start;
const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
#endif
return (OPJ_UINT32)diff;
}
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
@ -420,7 +424,7 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) {
mqc->bp++;
*mqc->bp = mqc->c;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
if (*mqc->bp == 0xff) {
mqc->ct = 7;
@ -437,11 +441,11 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
if (mqc->ct != 0) {
while (mqc->ct > 0) {
mqc->ct--;
mqc->c += bit_padding << mqc->ct;
mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct);
bit_padding = (bit_padding + 1) & 0x01;
}
mqc->bp++;
*mqc->bp = mqc->c;
*mqc->bp = (OPJ_BYTE)mqc->c;
mqc->ct = 8;
mqc->c = 0;
}
@ -460,11 +464,11 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) {
OPJ_UINT32 correction = 1;
/* <flush part> */
OPJ_INT32 n = 27 - 15 - mqc->ct;
OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct);
mqc->c <<= mqc->ct;
while (n > 0) {
opj_mqc_byteout(mqc);
n -= mqc->ct;
n -= (OPJ_INT32)mqc->ct;
mqc->c <<= mqc->ct;
}
opj_mqc_byteout(mqc);
@ -485,13 +489,13 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
}
void opj_mqc_erterm_enc(opj_mqc_t *mqc) {
OPJ_INT32 k = 11 - mqc->ct + 1;
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) {
mqc->c <<= mqc->ct;
mqc->ct = 0;
opj_mqc_byteout(mqc);
k -= mqc->ct;
k -= (OPJ_INT32)mqc->ct;
}
if (*mqc->bp != 0xff) {
@ -514,7 +518,7 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
mqc->end = bp + len;
mqc->bp = bp;
if (len==0) mqc->c = 0xff << 16;
else mqc->c = *mqc->bp << 16;
else mqc->c = (OPJ_UINT32)(*mqc->bp << 16);
#ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */
{
@ -579,7 +583,7 @@ OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
d = opj_mqc_mpsexchange(mqc);
opj_mqc_renormd(mqc);
} else {
d = (*mqc->curctx)->mps;
d = (OPJ_INT32)(*mqc->curctx)->mps;
}
}
@ -594,7 +598,7 @@ void opj_mqc_resetstates(opj_mqc_t *mqc) {
}
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) {
mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
}

View File

@ -30,126 +30,8 @@
#include <windows.h>
#endif /* _WIN32 */
#include "opj_config.h"
#include "opj_includes.h"
/**
* Decompression handler.
*/
typedef struct opj_decompression
{
/** Main header reading function handler*/
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
opj_image_t **p_image,
struct opj_event_mgr * p_manager);
/** Decoding function */
OPJ_BOOL (*opj_decode) ( void * p_codec,
struct opj_stream_private *p_cio,
opj_image_t *p_image,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
OPJ_BOOL (*opj_read_tile_header)( void * p_codec,
OPJ_UINT32 * p_tile_index,
OPJ_UINT32* p_data_size,
OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
OPJ_UINT32 * p_nb_comps,
OPJ_BOOL * p_should_go_on,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
OPJ_BOOL (*opj_decode_tile_data)( void * p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
/** Reading function used after codestream if necessary */
OPJ_BOOL (* opj_end_decompress) ( void *p_codec,
struct opj_stream_private *cio,
struct opj_event_mgr * p_manager);
/** Codec destroy function handler*/
void (*opj_destroy) (void * p_codec);
/** Setup decoder function handler */
void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
/** Set decode area function handler */
OPJ_BOOL (*opj_set_decode_area) ( void * p_codec,
opj_image_t* p_image,
OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
struct opj_event_mgr * p_manager);
/** Get tile function */
OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec,
opj_stream_private_t *p_cio,
opj_image_t *p_image,
struct opj_event_mgr * p_manager,
OPJ_UINT32 tile_index);
/** Set the decoded resolution factor */
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
}opj_decompression_t;
/**
* Compression handler. FIXME DOC
*/
typedef struct opj_compression
{
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private *cio,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_encode) ( void * p_codec,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_write_tile) ( void * p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
struct opj_stream_private * p_cio,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_end_compress) ( void * p_codec,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
void (* opj_destroy) (void * p_codec);
void (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
}opj_compression_t;
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private
{
/** FIXME DOC */
union
{
opj_decompression_t m_decompression;
opj_compression_t m_compression;
} m_codec_data;
/** FIXME DOC*/
void * m_codec;
/** Event handler */
opj_event_mgr_t m_event_mgr;
/** Flag to indicate if the codec is used to decode or encode*/
OPJ_BOOL is_decompressor;
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
}
opj_codec_private_t;
/* ---------------------------------------------------------------------- */
/* Functions to set the message handlers */
@ -212,10 +94,10 @@ static OPJ_UINT64 opj_get_data_length_from_file (FILE * p_file)
OPJ_OFF_T file_length = 0;
OPJ_FSEEK(p_file, 0, SEEK_END);
file_length = (OPJ_UINT64)OPJ_FTELL(p_file);
file_length = (OPJ_OFF_T)OPJ_FTELL(p_file);
OPJ_FSEEK(p_file, 0, SEEK_SET);
return file_length;
return (OPJ_UINT64)file_length;
}
static OPJ_SIZE_T opj_write_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file)
@ -851,10 +733,9 @@ OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream)
opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream;
if (! l_codec->is_decompressor) {
l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec,
return l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec,
l_stream,
&(l_codec->m_event_mgr));
return OPJ_TRUE;
}
}
@ -902,8 +783,8 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
OPJ_FLOAT32 * pEncodingMatrix,
OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp)
{
OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_dc_shift_size = pNbComp * sizeof(OPJ_INT32);
OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32);
OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32);
OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size;
/* add MCT capability */

View File

@ -43,14 +43,31 @@
==========================================================
*/
/*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
*/
#ifndef INLINE
#if defined(_MSC_VER)
#define INLINE __forceinline
#elif defined(__GNUC__)
#define INLINE __inline__
#elif defined(__MWERKS__)
#define INLINE inline
#else
/* add other compilers here ... */
#define INLINE
#endif /* defined(<Compiler>) */
#endif /* INLINE */
/* deprecated attribute */
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
#define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#define OPJ_DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#define OPJ_DEPRECATED(func) func
#endif
#if defined(OPJ_STATIC) || !defined(_WIN32)
@ -143,7 +160,7 @@ typedef size_t OPJ_SIZE_T;
#define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
#define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
#define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
/*FIXME #define OPJ_J2K_CSTR_INFO 6*/ /**< */
#define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */
#define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
#define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
/*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
@ -193,10 +210,10 @@ typedef enum PROG_ORDER {
*/
typedef enum COLOR_SPACE {
OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
OPJ_CLRSPC_SRGB = 1, /**< sRGB */
OPJ_CLRSPC_GRAY = 2, /**< grayscale */
OPJ_CLRSPC_SYCC = 3 /**< YUV */
OPJ_CLRSPC_SYCC = 3 /**< YUV */
} OPJ_COLOR_SPACE;
/**
@ -387,7 +404,8 @@ typedef struct opj_cparameters {
char tcp_mct;
/** Enable JPIP indexing*/
OPJ_BOOL jpip_on;
/** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */
/** Naive implementation of MCT restricted to a single reversible array based
encoding without offset concerning all the components. */
void * mct_data;
} opj_cparameters_t;
@ -1217,7 +1235,8 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_c
* @param p_codec the jpeg2000 codec.
* @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
* @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
* @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of
* tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
* @param p_stream the stream to write data to.
*
* @return true if the data could be written.

View File

@ -51,9 +51,9 @@ OPJ_FLOAT64 opj_clock(void) {
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec;
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif
}

160
src/lib/openjp2/opj_codec.h Normal file
View File

@ -0,0 +1,160 @@
/*
* Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2007, Professor Benoit Macq
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __OPJ_CODEC_H
#define __OPJ_CODEC_H
/**
@file opj_codec.h
*/
/**
* Main codec handler used for compression or decompression.
*/
typedef struct opj_codec_private
{
/** FIXME DOC */
union
{
/**
* Decompression handler.
*/
struct opj_decompression
{
/** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec,
opj_image_t **p_image,
struct opj_event_mgr * p_manager);
/** Decoding function */
OPJ_BOOL (*opj_decode) ( void * p_codec,
struct opj_stream_private * p_cio,
opj_image_t * p_image,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
OPJ_BOOL (*opj_read_tile_header)( void * p_codec,
OPJ_UINT32 * p_tile_index,
OPJ_UINT32 * p_data_size,
OPJ_INT32 * p_tile_x0,
OPJ_INT32 * p_tile_y0,
OPJ_INT32 * p_tile_x1,
OPJ_INT32 * p_tile_y1,
OPJ_UINT32 * p_nb_comps,
OPJ_BOOL * p_should_go_on,
struct opj_stream_private * p_cio,
struct opj_event_mgr * p_manager);
/** FIXME DOC */
OPJ_BOOL (*opj_decode_tile_data)( void * p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
struct opj_stream_private * p_cio,
struct opj_event_mgr * p_manager);
/** Reading function used after codestream if necessary */
OPJ_BOOL (* opj_end_decompress) ( void *p_codec,
struct opj_stream_private * cio,
struct opj_event_mgr * p_manager);
/** Codec destroy function handler */
void (*opj_destroy) (void * p_codec);
/** Setup decoder function handler */
void (*opj_setup_decoder) ( void * p_codec, opj_dparameters_t * p_param);
/** Set decode area function handler */
OPJ_BOOL (*opj_set_decode_area) ( void * p_codec,
opj_image_t * p_image,
OPJ_INT32 p_start_x,
OPJ_INT32 p_end_x,
OPJ_INT32 p_start_y,
OPJ_INT32 p_end_y,
struct opj_event_mgr * p_manager);
/** Get tile function */
OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec,
opj_stream_private_t * p_cio,
opj_image_t *p_image,
struct opj_event_mgr * p_manager,
OPJ_UINT32 tile_index);
/** Set the decoded resolution factor */
OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
OPJ_UINT32 res_factor,
opj_event_mgr_t * p_manager);
} m_decompression;
/**
* Compression handler. FIXME DOC
*/
struct opj_compression
{
OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_encode) ( void * p_codec,
struct opj_stream_private *p_cio,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_write_tile) ( void * p_codec,
OPJ_UINT32 p_tile_index,
OPJ_BYTE * p_data,
OPJ_UINT32 p_data_size,
struct opj_stream_private * p_cio,
struct opj_event_mgr * p_manager);
OPJ_BOOL (* opj_end_compress) ( void * p_codec,
struct opj_stream_private * p_cio,
struct opj_event_mgr * p_manager);
void (* opj_destroy) (void * p_codec);
void (* opj_setup_encoder) ( void * p_codec,
opj_cparameters_t * p_param,
struct opj_image * p_image,
struct opj_event_mgr * p_manager);
} m_compression;
} m_codec_data;
/** FIXME DOC*/
void * m_codec;
/** Event handler */
opj_event_mgr_t m_event_mgr;
/** Flag to indicate if the codec is used to decode or encode*/
OPJ_BOOL is_decompressor;
void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
}
opj_codec_private_t;
#endif /* __OPJ_CODEC_H */

View File

@ -1,41 +1,2 @@
/* create config.h for CMake */
#cmakedefine OPJ_HAVE_STDINT_H @HAVE_STDINT_H@
#define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@"
#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@
#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@
#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@
#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@
#cmakedefine HAVE_STRING_H @HAVE_STRING_H@
#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@
#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
#cmakedefine HAVE_LIBPNG @HAVE_LIBPNG@
#cmakedefine HAVE_PNG_H @HAVE_PNG_H@
#cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@
#cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@
#cmakedefine _LARGEFILE_SOURCE
#cmakedefine _LARGE_FILES
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
#cmakedefine HAVE_FSEEKO @HAVE_FSEEKO@
#cmakedefine HAVE_LIBLCMS1
#cmakedefine HAVE_LIBLCMS2
#cmakedefine HAVE_LCMS1_H
#cmakedefine HAVE_LCMS2_H
/* Byte order. */
/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or
__LITTLE_ENDIAN__ to match the endianness of the architecture being
compiled for. This is not necessarily the same as the architecture of the
machine doing the building. In order to support Universal Binaries on
Mac OS X, we prefer those defines to decide the endianness.
On other platforms we use the result of the TRY_RUN. */
#if !defined(__APPLE__)
#cmakedefine OPJ_BIG_ENDIAN
#elif defined(__BIG_ENDIAN__)
# define OPJ_BIG_ENDIAN
#endif
/* create opj_config.h for CMake */
#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@

View File

@ -0,0 +1,31 @@
/* create opj_config_private.h for CMake */
#cmakedefine OPJ_HAVE_INTTYPES_H @OPJ_HAVE_INTTYPES_H@
#define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@"
/* Not used by openjp2*/
/*#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@*/
/*#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@*/
/*#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@*/
/*#cmakedefine HAVE_STRING_H @HAVE_STRING_H@*/
/*#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@*/
/*#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ */
/*#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@*/
#cmakedefine _LARGEFILE_SOURCE
#cmakedefine _LARGE_FILES
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@
/* Byte order. */
/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or
__LITTLE_ENDIAN__ to match the endianness of the architecture being
compiled for. This is not necessarily the same as the architecture of the
machine doing the building. In order to support Universal Binaries on
Mac OS X, we prefer those defines to decide the endianness.
On other platforms we use the result of the TRY_RUN. */
#if !defined(__APPLE__)
#cmakedefine OPJ_BIG_ENDIAN
#elif defined(__BIG_ENDIAN__)
# define OPJ_BIG_ENDIAN
#endif

View File

@ -32,7 +32,7 @@
* This must be included before any system headers,
* since they can react to macro defined there
*/
#include "opj_config.h"
#include "opj_config_private.h"
/*
==========================================================
@ -56,7 +56,7 @@
ftello() only on systems with special LFS support since some systems
(e.g. FreeBSD) support a 64-bit off_t by default.
*/
#if defined(HAVE_FSEEKO)
#if defined(OPJ_HAVE_FSEEKO) && !defined(fseek)
# define fseek fseeko
# define ftell ftello
#endif
@ -102,22 +102,6 @@
#define __attribute__(x) /* __attribute__(x) */
#endif
/*
The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ...
*/
#ifndef INLINE
#if defined(_MSC_VER)
#define INLINE __forceinline
#elif defined(__GNUC__)
#define INLINE __inline__
#elif defined(__MWERKS__)
#define INLINE inline
#else
/* add other compilers here ... */
#define INLINE
#endif /* defined(<Compiler>) */
#endif /* INLINE */
/* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L)
@ -129,8 +113,8 @@ Most compilers implement their own version of this keyword ...
#endif
#endif
/* MSVC and Borland C do not have lrintf */
#if defined(_MSC_VER) || defined(__BORLANDC__)
/* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER) && (_MSC_VER < 1800) || defined(__BORLANDC__)
static INLINE long lrintf(float f){
#ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
@ -185,6 +169,7 @@ static INLINE long lrintf(float f){
/* <<JPWL */
/* V2 */
#include "opj_codec.h"
#endif /* OPJ_INCLUDES_H */

View File

@ -102,6 +102,7 @@ Divide an integer and round upwards
@return Returns a divided by b
*/
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
assert(b);
return (a + b - 1) / b;
}
@ -118,7 +119,7 @@ Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b
*/
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
return (a + (1 << b) - 1) >> b;
return (OPJ_INT32)((a + (OPJ_INT64)(1 << b) - 1) >> b);
}
/**
Divide an integer by a power of 2 and round downwards

View File

@ -26,8 +26,8 @@
#ifndef OPJ_INTTYPES_H
#define OPJ_INTTYPES_H
#include "opj_config.h"
#ifdef HAVE_INTTYPES_H
#include "opj_config_private.h"
#ifdef OPJ_HAVE_INTTYPES_H
#include <inttypes.h>
#else
#if defined(_WIN32)

View File

@ -48,8 +48,13 @@ Allocate an uninitialized memory block
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_malloc(size_t size);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_malloc(size) ((size_t)(size) >= (size_t)-0x100 ? NULL : malloc(size))
#else
#define opj_malloc(size) malloc(size)
#endif
#endif
/**
Allocate a memory block with elements initialized to 0
@ -60,8 +65,13 @@ Allocate a memory block with elements initialized to 0
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_calloc(num, size) ((size_t)(num) != 0 && (size_t)(num) >= (size_t)-0x100 / (size_t)(size) ? NULL : calloc(num, size))
#else
#define opj_calloc(num, size) calloc(num, size)
#endif
#endif
/**
Allocate memory aligned to a 16 byte boundry
@ -139,8 +149,13 @@ Reallocate memory blocks.
#ifdef ALLOC_PERF_OPT
void * OPJ_CALLCONV opj_realloc(void * m, size_t s);
#else
/* prevent assertion on overflow for MSVC */
#ifdef _MSC_VER
#define opj_realloc(m, s) ((size_t)(s) >= (size_t)-0x100 ? NULL : realloc(m, s))
#else
#define opj_realloc(m, s) realloc(m, s)
#endif
#endif
/**
Deallocates or frees a memory block.

View File

@ -52,11 +52,11 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [8];
int len, compno, i;
OPJ_UINT32 len, compno, i;
opj_jp2_box_t *box;
OPJ_OFF_T lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for( i=0;i<2;i++){
if (i)
@ -67,10 +67,10 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager );
opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager );
for( compno=0; compno<cstr_info.numcomps; compno++){
box[compno].length = opj_write_phixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++){
box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX;
}
@ -83,17 +83,18 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_free(box);
return len;
return (int)len;
}
int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager )
{
int tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno, num_packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
OPJ_BYTE l_data_header [8];
OPJ_OFF_T lenp;
@ -120,15 +121,15 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
opj_stream_write_data(cio,l_data_header,1,p_manager);
nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){
tile_Idx = &cstr_info.tile[ tileno];
num_packet = 0;
@ -186,5 +187,5 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}

View File

@ -320,8 +320,8 @@ OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
for (resno = 0; resno < comp->numresolutions; resno++) {
OPJ_UINT32 dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
}
@ -334,8 +334,8 @@ if (!pi->tp_on){
pi->poc.tx1 = pi->tx1;
}
for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) {
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
OPJ_UINT32 levelno;
OPJ_INT32 trx0, try0;
@ -348,16 +348,16 @@ if (!pi->tp_on){
}
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
@ -365,11 +365,11 @@ if (!pi->tp_on){
if ((trx0==trx1)||(try0==try1)) continue;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- opj_int_floordivpow2(trx0, res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- opj_int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
- opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
- opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
@ -404,8 +404,8 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
for (resno = 0; resno < comp->numresolutions; resno++) {
OPJ_UINT32 dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
}
@ -417,8 +417,8 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
pi->poc.ty1 = pi->ty1;
pi->poc.tx1 = pi->tx1;
}
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
comp = &pi->comps[pi->compno];
for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
@ -429,16 +429,16 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
OPJ_INT32 prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
@ -446,11 +446,11 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
if ((trx0==trx1)||(try0==try1)) continue;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- opj_int_floordivpow2(trx0, res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- opj_int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
- opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
- opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
@ -487,8 +487,8 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
for (resno = 0; resno < comp->numresolutions; resno++) {
OPJ_UINT32 dx, dy;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno));
dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno));
pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
}
@ -498,8 +498,8 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
pi->poc.ty1 = pi->ty1;
pi->poc.tx1 = pi->tx1;
}
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) {
for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) {
for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) {
OPJ_UINT32 levelno;
OPJ_INT32 trx0, try0;
@ -508,16 +508,16 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
OPJ_INT32 prci, prcj;
res = &comp->resolutions[pi->resno];
levelno = comp->numresolutions - 1 - pi->resno;
trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno);
try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno);
trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno);
try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno);
trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno));
try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno));
trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno));
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno;
rpy = res->pdy + levelno;
if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){
continue;
}
if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){
continue;
}
@ -525,11 +525,11 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
if ((trx0==trx1)||(try0==try1)) continue;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx)
- opj_int_floordivpow2(trx0, res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy)
- opj_int_floordivpow2(try0, res->pdy);
pi->precno = prci + prcj * res->pw;
prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx)
- opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx);
prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy)
- opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy);
pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw);
for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) {
index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p;
if (!pi->include[index]) {
@ -583,10 +583,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
q = p_tileno / p_cp->tw;
/* find extent of tile */
*p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
*p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
*p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
*p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
*p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0);
*p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1);
*p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0);
*p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1);
/* max precision is 0 (can only grow) */
*p_max_prec = 0;
@ -606,10 +606,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
OPJ_UINT32 l_product;
OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1;
l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx);
l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy);
l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx);
l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy);
l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx);
l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy);
l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx);
l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy);
if (l_tccp->numresolutions > *p_max_res) {
*p_max_res = l_tccp->numresolutions;
@ -623,8 +623,8 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
l_pdx = l_tccp->prcw[resno];
l_pdy = l_tccp->prch[resno];
l_dx = l_img_comp->dx * (1 << (l_pdx + l_tccp->numresolutions - 1 - resno));
l_dy = l_img_comp->dy * (1 << (l_pdy + l_tccp->numresolutions - 1 - resno));
l_dx = l_img_comp->dx * (1u << (l_pdx + l_tccp->numresolutions - 1 - resno));
l_dy = l_img_comp->dy * (1u << (l_pdy + l_tccp->numresolutions - 1 - resno));
/* take the minimum size for dx for each comp and resolution */
*p_dx_min = opj_uint_min(*p_dx_min, l_dx);
@ -633,19 +633,19 @@ void opj_get_encoding_parameters( const opj_image_t *p_image,
/* various calculations of extents */
l_level_no = l_tccp->numresolutions - 1 - resno;
l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no);
l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no);
l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no);
l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no);
l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no);
l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no);
l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no);
l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no);
l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx;
l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy;
l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx;
l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy;
l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx;
py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy;
l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
l_pw = (l_rx0==l_rx1)?0:(OPJ_UINT32)((l_px1 - l_px0) >> l_pdx);
l_ph = (l_ry0==l_ry1)?0:(OPJ_UINT32)((py1 - l_py0) >> l_pdy);
l_product = l_pw * l_ph;
@ -702,10 +702,10 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image,
q = tileno / p_cp->tw;
/* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */
*p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0);
*p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1);
*p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0);
*p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1);
*p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0);
*p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1);
*p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0);
*p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1);
/* max precision and resolution is 0 (can only grow)*/
*p_max_prec = 0;
@ -726,10 +726,10 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image,
lResolutionPtr = p_resolutions[compno];
l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx);
l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy);
l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx);
l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy);
l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx);
l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy);
l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx);
l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy);
if (l_tccp->numresolutions > *p_max_res) {
*p_max_res = l_tccp->numresolutions;
@ -745,23 +745,23 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image,
l_pdy = l_tccp->prch[resno];
*lResolutionPtr++ = l_pdx;
*lResolutionPtr++ = l_pdy;
l_dx = l_img_comp->dx * (1 << (l_pdx + l_level_no));
l_dy = l_img_comp->dy * (1 << (l_pdy + l_level_no));
l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no));
l_dy = l_img_comp->dy * (1u << (l_pdy + l_level_no));
/* take the minimum size for l_dx for each comp and resolution*/
*p_dx_min = opj_int_min(*p_dx_min, l_dx);
*p_dy_min = opj_int_min(*p_dy_min, l_dy);
*p_dx_min = (OPJ_UINT32)opj_int_min((OPJ_INT32)*p_dx_min, (OPJ_INT32)l_dx);
*p_dy_min = (OPJ_UINT32)opj_int_min((OPJ_INT32)*p_dy_min, (OPJ_INT32)l_dy);
/* various calculations of extents*/
l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no);
l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no);
l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no);
l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no);
l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx;
l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy;
l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx;
py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy;
l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx);
l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy);
l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no);
l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no);
l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no);
l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no);
l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx;
l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy;
l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx;
py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy;
l_pw = (l_rx0==l_rx1)?0:(OPJ_UINT32)((l_px1 - l_px0) >> l_pdx);
l_ph = (l_ry0==l_ry1)?0:(OPJ_UINT32)((py1 - l_py0) >> l_pdy);
*lResolutionPtr++ = l_pw;
*lResolutionPtr++ = l_ph;
l_product = l_pw * l_ph;
@ -890,10 +890,10 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
l_current_poc->prcS = 0;
l_current_poc->prcE = p_max_prec;
l_current_poc->txS = p_tx0;
l_current_poc->txE = p_tx1;
l_current_poc->tyS = p_ty0;
l_current_poc->tyE = p_ty1;
l_current_poc->txS = (OPJ_UINT32)p_tx0;
l_current_poc->txE = (OPJ_UINT32)p_tx1;
l_current_poc->tyS = (OPJ_UINT32)p_ty0;
l_current_poc->tyE = (OPJ_UINT32)p_ty1;
l_current_poc->dx = p_dx_min;
l_current_poc->dy = p_dy_min;
@ -910,10 +910,10 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
l_current_poc->layS = (l_current_poc->layE > (l_current_poc-1)->layE) ? l_current_poc->layE : 0;
l_current_poc->prcE = p_max_prec;
l_current_poc->txS = p_tx0;
l_current_poc->txE = p_tx1;
l_current_poc->tyS = p_ty0;
l_current_poc->tyE = p_ty1;
l_current_poc->txS = (OPJ_UINT32)p_tx0;
l_current_poc->txE = (OPJ_UINT32)p_tx1;
l_current_poc->tyS = (OPJ_UINT32)p_ty0;
l_current_poc->tyE = (OPJ_UINT32)p_ty1;
l_current_poc->dx = p_dx_min;
l_current_poc->dy = p_dy_min;
++ l_current_poc;
@ -965,10 +965,10 @@ void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp,
l_current_poc->prg = l_tcp->prg;
l_current_poc->prcS = 0;
l_current_poc->prcE = p_max_prec;
l_current_poc->txS = p_tx0;
l_current_poc->txE = p_tx1;
l_current_poc->tyS = p_ty0;
l_current_poc->tyE = p_ty1;
l_current_poc->txS = (OPJ_UINT32)p_tx0;
l_current_poc->txE = (OPJ_UINT32)p_tx1;
l_current_poc->tyS = (OPJ_UINT32)p_ty0;
l_current_poc->tyE = (OPJ_UINT32)p_ty1;
l_current_poc->dx = p_dx_min;
l_current_poc->dy = p_dy_min;
++ l_current_poc;
@ -1001,16 +1001,16 @@ void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
l_current_poc = p_tcp->pocs;
for (pino = 0;pino<l_bound;++pino) {
l_current_pi->poc.prg = l_current_poc->prg;
l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */
l_current_pi->first = 1;
l_current_pi->poc.resno0 = l_current_poc->resno0;
l_current_pi->poc.compno0 = l_current_poc->compno0;
l_current_pi->poc.resno0 = l_current_poc->resno0; /* Resolution Level Index #0 (Start) */
l_current_pi->poc.compno0 = l_current_poc->compno0; /* Component Index #0 (Start) */
l_current_pi->poc.layno0 = 0;
l_current_pi->poc.precno0 = 0;
l_current_pi->poc.resno1 = l_current_poc->resno1;
l_current_pi->poc.compno1 = l_current_poc->compno1;
l_current_pi->poc.layno1 = l_current_poc->layno1;
l_current_pi->poc.resno1 = l_current_poc->resno1; /* Resolution Level Index #0 (End) */
l_current_pi->poc.compno1 = l_current_poc->compno1; /* Component Index #0 (End) */
l_current_pi->poc.layno1 = l_current_poc->layno1; /* Layer Index #0 (End) */
l_current_pi->poc.precno1 = p_max_precision;
++l_current_pi;
++l_current_poc;
@ -1557,10 +1557,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.layno1 = tcp->layE;
pi[pino].poc.precno0 = tcp->prcS;
pi[pino].poc.precno1 = tcp->prcE;
pi[pino].poc.tx0 = tcp->txS;
pi[pino].poc.ty0 = tcp->tyS;
pi[pino].poc.tx1 = tcp->txE;
pi[pino].poc.ty1 = tcp->tyE;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS;
pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS;
pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE;
pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE;
}else {
for(i=tppos+1;i<4;i++){
switch(prog[i]){
@ -1584,10 +1584,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.precno1 = tcp->prcE;
break;
default:
pi[pino].poc.tx0 = tcp->txS;
pi[pino].poc.ty0 = tcp->tyS;
pi[pino].poc.tx1 = tcp->txE;
pi[pino].poc.ty1 = tcp->tyE;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS;
pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS;
pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE;
pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE;
break;
}
break;
@ -1627,12 +1627,12 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
default:
tcp->tx0_t = tcp->txS;
tcp->ty0_t = tcp->tyS;
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx);
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->tx0_t = pi[pino].poc.tx1;
tcp->ty0_t = pi[pino].poc.ty1;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx));
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
break;
}
break;
@ -1662,10 +1662,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.precno1 = tcp->prc_t;
break;
default:
pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx);
pi[pino].poc.tx1 = tcp->tx0_t ;
pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy);
pi[pino].poc.ty1 = tcp->ty0_t ;
pi[pino].poc.tx0 = (OPJ_INT32)(tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx));
pi[pino].poc.tx1 = (OPJ_INT32)tcp->tx0_t ;
pi[pino].poc.ty0 = (OPJ_INT32)(tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy));
pi[pino].poc.ty1 = (OPJ_INT32)tcp->ty0_t ;
break;
}
break;
@ -1752,29 +1752,29 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
if(tcp->ty0_t >= tcp->tyE){
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){
tcp->ty0_t = tcp->tyS;
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->ty0_t = pi[pino].poc.ty1;
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=1;resetX=1;
}else{
incr_top=0;resetX=0;
}
}else{
pi[pino].poc.ty0 = tcp->ty0_t;
pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy);
tcp->ty0_t = pi[pino].poc.ty1;
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=0;resetX=1;
}
if(resetX==1){
tcp->tx0_t = tcp->txS;
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
tcp->tx0_t = pi[pino].poc.tx1;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx));
tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
}
}else{
pi[pino].poc.tx0 = tcp->tx0_t;
pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx);
tcp->tx0_t = pi[pino].poc.tx1;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx));
tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
incr_top=0;
}
break;

View File

@ -60,7 +60,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
/* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for (i=0;i<2;i++){
if (i)
@ -75,7 +75,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager);
for (compno=0; compno<cstr_info.numcomps; compno++){
box[compno].length = opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX;
}
@ -89,7 +89,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_free(box);
return len;
return (int)len;
}
@ -98,12 +98,13 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [8];
int tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
OPJ_UINT32 tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
OPJ_UINT32 len;
OPJ_OFF_T lenp;
opj_tile_info_t *tile_Idx;
opj_packet_info_t packet;
int resno, precno, layno, num_packet;
int resno, precno, layno;
OPJ_UINT32 num_packet;
int numOfres, numOfprec, numOflayers;
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */
@ -124,15 +125,15 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++)
nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++)
nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers);
opj_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){
tile_Idx = &cstr_info.tile[ tileno];
num_packet=0;
@ -189,5 +190,5 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}

View File

@ -54,7 +54,9 @@ void opj_raw_destroy(opj_raw_t *raw) {
}
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) {
return raw->bp - raw->start;
const ptrdiff_t diff = raw->bp - raw->start;
assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */
return (OPJ_UINT32)diff;
}
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {

View File

@ -62,6 +62,7 @@ static void opj_t1_enc_sigpass_step(opj_t1_t *t1,
/**
Decode significant pass
*/
#if 0
static void opj_t1_dec_sigpass_step(opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@ -69,6 +70,7 @@ static void opj_t1_dec_sigpass_step(opj_t1_t *t1,
OPJ_INT32 oneplushalf,
OPJ_BYTE type,
OPJ_UINT32 vsc);
#endif
static INLINE void opj_t1_dec_sigpass_step_raw(
opj_t1_t *t1,
@ -161,6 +163,7 @@ static void opj_t1_dec_refpass_mqc_vsc(
/**
Decode refinement pass
*/
#if 0
static void opj_t1_dec_refpass_step(opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@ -168,6 +171,7 @@ static void opj_t1_dec_refpass_step(opj_t1_t *t1,
OPJ_INT32 neghalf,
OPJ_BYTE type,
OPJ_UINT32 vsc);
#endif
static INLINE void opj_t1_dec_refpass_step_raw(
opj_t1_t *t1,
@ -367,25 +371,25 @@ void opj_t1_enc_sigpass_step( opj_t1_t *t1,
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
v = opj_int_abs(*datap) & one ? 1 : 0;
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
opj_mqc_bypass_enc(mqc, v);
opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v);
} else {
opj_mqc_encode(mqc, v);
opj_mqc_encode(mqc, (OPJ_UINT32)v);
}
if (v) {
v = *datap < 0 ? 1 : 0;
*nmsedec += opj_t1_getnmsedec_sig(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
opj_mqc_bypass_enc(mqc, v);
opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v);
} else {
opj_mqc_encode(mqc, v ^ opj_t1_getspb(flag));
opj_mqc_encode(mqc, (OPJ_UINT32)(v ^ opj_t1_getspb((OPJ_UINT32)flag)));
}
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
@ -407,9 +411,9 @@ static INLINE void opj_t1_dec_sigpass_step_raw(
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
if (opj_raw_decode(raw)) {
v = opj_raw_decode(raw); /* ESSAI */
v = (OPJ_INT32)opj_raw_decode(raw); /* ESSAI */
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
@ -428,12 +432,12 @@ INLINE void opj_t1_dec_sigpass_step_mqc(
flag = *flagsp;
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient));
if (opj_mqc_decode(mqc)) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag);
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag);
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
@ -453,12 +457,12 @@ INLINE void opj_t1_dec_sigpass_step_mqc_vsc(
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient));
if (opj_mqc_decode(mqc)) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag);
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag);
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
*flagsp |= T1_VISIT;
}
@ -537,7 +541,7 @@ void opj_t1_dec_sigpass_mqc(
one = 1 << bpno;
half = one >> 1;
oneplushalf = one | half;
for (k = 0; k < (t1->h & ~3); k += 4) {
for (k = 0; k < (t1->h & ~3u); k += 4) {
for (i = 0; i < t1->w; ++i) {
OPJ_INT32 *data2 = data1 + i;
opj_flag_t *flags2 = flags1 + i;
@ -610,15 +614,15 @@ void opj_t1_enc_refpass_step( opj_t1_t *t1,
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
*nmsedec += opj_t1_getnmsedec_ref(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
v = opj_int_abs(*datap) & one ? 1 : 0;
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */
if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */
opj_mqc_bypass_enc(mqc, v);
opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v);
} else {
opj_mqc_encode(mqc, v);
opj_mqc_encode(mqc, (OPJ_UINT32)v);
}
*flagsp |= T1_REFINE;
}
@ -638,7 +642,7 @@ INLINE void opj_t1_dec_refpass_step_raw(
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
v = opj_raw_decode(raw);
v = (OPJ_INT32)opj_raw_decode(raw);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
*flagsp |= T1_REFINE;
@ -658,7 +662,7 @@ INLINE void opj_t1_dec_refpass_step_mqc(
flag = *flagsp;
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag((OPJ_UINT32)flag)); /* ESSAI */
v = opj_mqc_decode(mqc);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
@ -680,7 +684,7 @@ INLINE void opj_t1_dec_refpass_step_mqc_vsc(
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */
opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag((OPJ_UINT32)flag)); /* ESSAI */
v = opj_mqc_decode(mqc);
t = v ? poshalf : neghalf;
*datap += *datap < 0 ? -t : t;
@ -757,7 +761,7 @@ void opj_t1_dec_refpass_mqc(
one = 1 << bpno;
poshalf = one >> 1;
neghalf = bpno > 0 ? -poshalf : -1;
for (k = 0; k < (t1->h & ~3); k += 4) {
for (k = 0; k < (t1->h & ~3u); k += 4) {
for (i = 0; i < t1->w; ++i) {
OPJ_INT32 *data2 = data1 + i;
opj_flag_t *flags2 = flags1 + i;
@ -831,21 +835,21 @@ void opj_t1_enc_clnpass_step(
opj_mqc_t *mqc = t1->mqc; /* MQC component */
flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp);
flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp);
if (partial) {
goto LABEL_PARTIAL;
}
if (!(*flagsp & (T1_SIG | T1_VISIT))) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient));
v = opj_int_abs(*datap) & one ? 1 : 0;
opj_mqc_encode(mqc, v);
opj_mqc_encode(mqc, (OPJ_UINT32)v);
if (v) {
LABEL_PARTIAL:
*nmsedec += opj_t1_getnmsedec_sig(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS);
*nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = *datap < 0 ? 1 : 0;
opj_mqc_encode(mqc, v ^ opj_t1_getspb(flag));
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_mqc_encode(mqc, (OPJ_UINT32)(v ^ opj_t1_getspb((OPJ_UINT32)flag)));
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
@ -864,10 +868,10 @@ static void opj_t1_dec_clnpass_step_partial(
OPJ_ARG_NOT_USED(orient);
flag = *flagsp;
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag);
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag);
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
*flagsp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */
@ -884,12 +888,12 @@ static void opj_t1_dec_clnpass_step(
flag = *flagsp;
if (!(flag & (T1_SIG | T1_VISIT))) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient));
if (opj_mqc_decode(mqc)) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag);
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag);
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
@ -913,13 +917,13 @@ static void opj_t1_dec_clnpass_step_vsc(
goto LABEL_PARTIAL;
}
if (!(flag & (T1_SIG | T1_VISIT))) {
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient));
opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient));
if (opj_mqc_decode(mqc)) {
LABEL_PARTIAL:
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag);
opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag));
v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag);
*datap = v ? -oneplushalf : oneplushalf;
opj_t1_updateflags(flagsp, v, t1->flags_stride);
opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride);
}
}
*flagsp &= ~T1_VISIT;
@ -1029,7 +1033,7 @@ static void opj_t1_dec_clnpass(
} else {
runlen = 0;
}
for (j = k + runlen; j < k + 4 && j < t1->h; ++j) {
for (j = k + (OPJ_UINT32)runlen; j < k + 4 && j < t1->h; ++j) {
vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0;
opj_t1_dec_clnpass_step_vsc(
t1,
@ -1037,7 +1041,7 @@ static void opj_t1_dec_clnpass(
&t1->data[(j * t1->w) + i],
orient,
oneplushalf,
agg && (j == k + runlen),
agg && (j == k + (OPJ_UINT32)runlen),
vsc);
}
}
@ -1045,7 +1049,7 @@ static void opj_t1_dec_clnpass(
} else {
OPJ_INT32 *data1 = t1->data;
opj_flag_t *flags1 = &t1->flags[1];
for (k = 0; k < (t1->h & ~3); k += 4) {
for (k = 0; k < (t1->h & ~3u); k += 4) {
for (i = 0; i < t1->w; ++i) {
OPJ_INT32 *data2 = data1 + i;
opj_flag_t *flags2 = flags1 + i;
@ -1061,11 +1065,11 @@ static void opj_t1_dec_clnpass(
opj_mqc_setcurctx(mqc, T1_CTXNO_UNI);
runlen = opj_mqc_decode(mqc);
runlen = (runlen << 1) | opj_mqc_decode(mqc);
flags2 += runlen * t1->flags_stride;
data2 += runlen * t1->w;
for (j = k + runlen; j < k + 4 && j < t1->h; ++j) {
flags2 += (OPJ_UINT32)runlen * t1->flags_stride;
data2 += (OPJ_UINT32)runlen * t1->w;
for (j = k + (OPJ_UINT32)runlen; j < k + 4 && j < t1->h; ++j) {
flags2 += t1->flags_stride;
if (agg && (j == k + runlen)) {
if (agg && (j == k + (OPJ_UINT32)runlen)) {
opj_t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf);
} else {
opj_t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf);
@ -1256,7 +1260,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
)
{
OPJ_UINT32 resno, bandno, precno, cblkno;
OPJ_UINT32 tile_w = tilec->x1 - tilec->x0;
OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
for (resno = 0; resno < tilec->minimum_num_resolutions; ++resno) {
opj_tcd_resolution_t* res = &tilec->resolutions[resno];
@ -1279,7 +1283,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
t1,
cblk,
band->bandno,
tccp->roishift,
(OPJ_UINT32)tccp->roishift,
tccp->cblksty)) {
return OPJ_FALSE;
}
@ -1315,7 +1319,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
/*tiledp=(void*)&tilec->data[(y * tile_w) + x];*/
if (tccp->qmfbid == 1) {
OPJ_INT32* restrict tiledp = &tilec->data[(y * tile_w) + x];
OPJ_INT32* restrict tiledp = &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x];
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
OPJ_INT32 tmp = datap[(j * cblk_w) + i];
@ -1323,11 +1327,11 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1,
}
}
} else { /* if (tccp->qmfbid == 0) */
OPJ_FLOAT32* restrict tiledp = (OPJ_FLOAT32*) &tilec->data[(y * tile_w) + x];
OPJ_FLOAT32* restrict tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x];
for (j = 0; j < cblk_h; ++j) {
OPJ_FLOAT32* restrict tiledp2 = tiledp;
for (i = 0; i < cblk_w; ++i) {
OPJ_FLOAT32 tmp = *datap * band->stepsize;
OPJ_FLOAT32 tmp = (OPJ_FLOAT32)*datap * band->stepsize;
*tiledp2 = tmp;
datap++;
tiledp2++;
@ -1366,13 +1370,13 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
if(!opj_t1_allocate_buffers(
t1,
cblk->x1 - cblk->x0,
cblk->y1 - cblk->y0))
(OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0)))
{
return OPJ_FALSE;
}
bpno = roishift + cblk->numbps - 1;
bpno = (OPJ_INT32)(roishift + cblk->numbps - 1);
passtype = 2;
opj_mqc_resetstates(mqc);
@ -1401,18 +1405,18 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
switch (passtype) {
case 0:
if (type == T1_TYPE_RAW) {
opj_t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty);
opj_t1_dec_sigpass_raw(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
opj_t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient);
opj_t1_dec_sigpass_mqc_vsc(t1, bpno+1, (OPJ_INT32)orient);
} else {
opj_t1_dec_sigpass_mqc(t1, bpno+1, orient);
opj_t1_dec_sigpass_mqc(t1, bpno+1, (OPJ_INT32)orient);
}
}
break;
case 1:
if (type == T1_TYPE_RAW) {
opj_t1_dec_refpass_raw(t1, bpno+1, cblksty);
opj_t1_dec_refpass_raw(t1, bpno+1, (OPJ_INT32)cblksty);
} else {
if (cblksty & J2K_CCP_CBLKSTY_VSC) {
opj_t1_dec_refpass_mqc_vsc(t1, bpno+1);
@ -1422,7 +1426,7 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
}
break;
case 2:
opj_t1_dec_clnpass(t1, bpno+1, orient, cblksty);
opj_t1_dec_clnpass(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty);
break;
}
@ -1457,7 +1461,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
for (compno = 0; compno < tile->numcomps; ++compno) {
opj_tcd_tilecomp_t* tilec = &tile->comps[compno];
opj_tccp_t* tccp = &tcp->tccps[compno];
OPJ_UINT32 tile_w = tilec->x1 - tilec->x0;
OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
for (resno = 0; resno < tilec->numresolutions; ++resno) {
opj_tcd_resolution_t *res = &tilec->resolutions[resno];
@ -1490,8 +1494,8 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
if(!opj_t1_allocate_buffers(
t1,
cblk->x1 - cblk->x0,
cblk->y1 - cblk->y0))
(OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0)))
{
return OPJ_FALSE;
}
@ -1500,7 +1504,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
cblk_w = t1->w;
cblk_h = t1->h;
tiledp=&tilec->data[(y * tile_w) + x];
tiledp=&tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x];
if (tccp->qmfbid == 1) {
for (j = 0; j < cblk_h; ++j) {
for (i = 0; i < cblk_w; ++i) {
@ -1573,9 +1577,9 @@ void opj_t1_encode_cblk(opj_t1_t *t1,
max = opj_int_max(max, tmp);
}
cblk->numbps = max ? (opj_int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0;
cblk->numbps = max ? (OPJ_UINT32)((opj_int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS) : 0;
bpno = cblk->numbps - 1;
bpno = (OPJ_INT32)(cblk->numbps - 1);
passtype = 2;
opj_mqc_resetstates(mqc);
@ -1678,6 +1682,7 @@ void opj_t1_encode_cblk(opj_t1_t *t1,
}
}
#if 0
void opj_t1_dec_refpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@ -1705,9 +1710,11 @@ void opj_t1_dec_refpass_step( opj_t1_t *t1,
*flagsp |= T1_REFINE;
}
} /* VSC and BYPASS by Antonin */
#endif
#if 0
void opj_t1_dec_sigpass_step( opj_t1_t *t1,
opj_flag_t *flagsp,
OPJ_INT32 *datap,
@ -1741,4 +1748,4 @@ void opj_t1_dec_sigpass_step( opj_t1_t *t1,
*flagsp |= T1_VISIT;
}
} /* VSC and BYPASS by Antonin */
#endif

View File

@ -181,7 +181,8 @@ static void dump_array16(int array[],int size){
printf("0x%04x\n};\n\n", array[size]);
}
int main(){
int main(int argc, char **argv)
{
int i, j;
double u, v, t;
@ -190,6 +191,7 @@ int main(){
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc; (void)argv;
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");

View File

@ -311,6 +311,19 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
return OPJ_TRUE;
}
/* see issue 80 */
#if 0
#define JAS_FPRINTF fprintf
#else
/* issue 290 */
static void opj_null_jas_fprintf(FILE* file, const char * format, ...)
{
(void)file;
(void)format;
}
#define JAS_FPRINTF opj_null_jas_fprintf
#endif
OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
OPJ_UINT32 p_tile_no,
opj_tcd_tile_t *p_tile,
@ -354,8 +367,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
for (pino = 0; pino <= l_tcp->numpocs; ++pino) {
/* if the resolution needed is to low, one dim of the tilec could be equal to zero
* and no packets are used to encode this resolution and
/* if the resolution needed is too low, one dim of the tilec could be equal to zero
* and no packets are used to decode this resolution and
* l_current_pi->resno is always >= p_tile->comps[l_current_pi->compno].minimum_num_resolutions
* and no l_img_comp->resno_decoded are computed
*/
@ -368,7 +381,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL));
while (opj_pi_next(l_current_pi)) {
JAS_FPRINTF( stderr, "packet offset=00000166 prg=%d cmptno=%02d rlvlno=%02d prcno=%03d lyrno=%02d\n\n",
l_current_pi->poc.prg1, l_current_pi->compno, l_current_pi->resno, l_current_pi->precno, l_current_pi->layno );
if (l_tcp->num_layers_to_decode > l_current_pi->layno
&& l_current_pi->resno < p_tile->comps[l_current_pi->compno].minimum_num_resolutions) {
@ -441,7 +455,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
/* don't forget to release pi */
opj_pi_destroy(l_pi,l_nb_pocs);
*p_data_read = l_current_data - p_src;
*p_data_read = (OPJ_UINT32)(l_current_data - p_src);
return OPJ_TRUE;
}
@ -546,8 +560,13 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
c[1] = 145;
c[2] = 0;
c[3] = 4;
#if 0
c[4] = (tile->packno % 65536) / 256;
c[5] = (tile->packno % 65536) % 256;
#else
c[4] = (tile->packno >> 8) & 0xff; /* packno is uint32_t */
c[5] = tile->packno & 0xff;
#endif
c += 6;
length -= 6;
}
@ -567,7 +586,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
cblk = &prc->cblks.enc[cblkno];
cblk->numpasses = 0;
opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps);
opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - (OPJ_INT32)cblk->numbps);
}
++band;
}
@ -589,7 +608,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
opj_tcd_layer_t *layer = &cblk->layers[layno];
if (!cblk->numpasses && layer->numpasses) {
opj_tgt_setvalue(prc->incltree, cblkno, layno);
opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno);
}
++cblk;
@ -605,7 +624,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
/* cblk inclusion bits */
if (!cblk->numpasses) {
opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1);
opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1));
} else {
opj_bio_write(bio, layer->numpasses != 0, 1);
}
@ -633,14 +652,15 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
increment = opj_int_max(increment, opj_int_floorlog2(len) + 1 - (cblk->numlenbits + opj_int_floorlog2(nump)));
increment = (OPJ_UINT32)opj_int_max((OPJ_INT32)increment, opj_int_floorlog2((OPJ_INT32)len) + 1
- ((OPJ_INT32)cblk->numlenbits + opj_int_floorlog2((OPJ_INT32)nump)));
len = 0;
nump = 0;
}
++pass;
}
opj_t2_putcommacode(bio, increment);
opj_t2_putcommacode(bio, (OPJ_INT32)increment);
/* computation of the new Length indicator */
cblk->numlenbits += increment;
@ -652,7 +672,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump));
opj_bio_write(bio, (OPJ_UINT32)len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump));
len = 0;
nump = 0;
}
@ -670,7 +690,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
return OPJ_FALSE; /* modified to eliminate longjmp !! */
}
l_nb_bytes = opj_bio_numbytes(bio);
l_nb_bytes = (OPJ_UINT32)opj_bio_numbytes(bio);
c += l_nb_bytes;
length -= l_nb_bytes;
@ -734,7 +754,8 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno,
++band;
}
* p_data_written += (c - dest);
assert( c >= dest );
* p_data_written += (OPJ_UINT32)(c - dest);
return OPJ_TRUE;
}
@ -778,7 +799,6 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2,
}
OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_tcd_tile_t *p_tile,
opj_tcp_t *p_tcp,
@ -835,8 +855,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* SOP markers */
if (p_tcp->csty & J2K_CP_CSTY_SOP) {
if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) {
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
if (p_max_length < 6) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */
printf("Not enough space for expected SOP marker\n");
} else if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) {
/* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */
printf("Expected SOP marker\n");
fprintf(stderr, "Error : expected SOP marker\n");
} else {
l_current_data += 6;
}
@ -870,13 +895,14 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
else { /* Normal Case */
l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start;
l_remaining_length = p_src_data+p_max_length-l_header_data;
l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data);
l_modified_length_ptr = &(l_remaining_length);
}
opj_bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr);
l_present = opj_bio_read(l_bio, 1);
JAS_FPRINTF(stderr, "present=%d \n", l_present );
if (!l_present) {
/* TODO MSD: no test to control the output of this function*/
opj_bio_inalign(l_bio);
@ -885,14 +911,16 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
printf("Error : expected EPH marker\n");
if (p_max_length < 2) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
}
l_header_length = (l_header_data - *l_header_data_start);
l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start);
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
@ -905,7 +933,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* INDEX >> */
* p_is_data_present = OPJ_FALSE;
*p_data_read = l_current_data - p_src_data;
*p_data_read = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
@ -926,7 +954,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* if cblk not yet included before --> inclusion tagtree */
if (!l_cblk->numsegs) {
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1);
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1));
/* else one bit */
}
else {
@ -937,6 +965,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (!l_included) {
l_cblk->numnewpasses = 0;
++l_cblk;
JAS_FPRINTF(stderr, "included=%d \n", l_included);
continue;
}
@ -944,11 +973,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (!l_cblk->numsegs) {
OPJ_UINT32 i = 0;
while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) {
while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) {
++i;
}
l_cblk->numbps = l_band->numbps + 1 - i;
l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i;
l_cblk->numlenbits = 3;
}
@ -976,13 +1005,14 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
}
}
}
n = l_cblk->numnewpasses;
n = (OPJ_INT32)l_cblk->numnewpasses;
do {
l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n);
l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n);
l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses));
JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, l_cblk->segs[l_segno].newlen );
n -= l_cblk->segs[l_segno].numnewpasses;
n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses;
if (n > 0) {
++l_segno;
@ -1009,14 +1039,19 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* EPH markers */
if (p_tcp->csty & J2K_CP_CSTY_EPH) {
if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
if (p_max_length < 2) {
fprintf(stderr, "Not enough space for expected EPH marker\n");
} else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) {
/* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */
fprintf(stderr, "Error : expected EPH marker\n");
} else {
l_header_data += 2;
}
}
l_header_length = (l_header_data - *l_header_data_start);
l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start);
JAS_FPRINTF( stderr, "hdrlen=%d \n", l_header_length );
JAS_FPRINTF( stderr, "packet body\n");
*l_modified_length_ptr -= l_header_length;
*l_header_data_start += l_header_length;
@ -1029,7 +1064,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
/* INDEX >> */
*p_is_data_present = OPJ_TRUE;
*p_data_read = l_current_data - p_src_data;
*p_data_read = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
@ -1089,6 +1124,8 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
do {
if (l_current_data + l_seg->newlen > p_src_data + p_max_length) {
fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
@ -1152,7 +1189,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
++l_band;
}
*(p_data_read) = l_current_data - p_src_data;
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
return OPJ_TRUE;
}
@ -1212,6 +1249,8 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
do {
if (* p_data_read + l_seg->newlen > p_max_length) {
fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno);
return OPJ_FALSE;
}
@ -1234,6 +1273,7 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
};
#endif /* USE_JPWL */
JAS_FPRINTF(stderr, "p_data_read (%d) newlen (%d) \n", *p_data_read, l_seg->newlen );
*(p_data_read) += l_seg->newlen;
l_seg->numpasses += l_seg->numnewpasses;

View File

@ -301,7 +301,7 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
for (j = 0; j < tilec->numresolutions; j++) {
for (k = 0; k < 3; k++) {
matrice[i][j][k] =
(OPJ_INT32) (cp->m_specific_param.m_enc.m_matrice[i * tilec->numresolutions * 3 + j * 3 + k]
(OPJ_INT32) ((OPJ_FLOAT32)cp->m_specific_param.m_enc.m_matrice[i * tilec->numresolutions * 3 + j * 3 + k]
* (OPJ_FLOAT32) (tcd->image->comps[compno].prec / 16.0));
}
}
@ -320,7 +320,7 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno];
opj_tcd_layer_t *layer = &cblk->layers[layno];
OPJ_UINT32 n;
OPJ_INT32 imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */
OPJ_INT32 imsb = (OPJ_INT32)(tcd->image->comps[compno].prec - cblk->numbps); /* number of bit-plan equal to zero */
/* Correction of the matrix of coefficient to include the IMSB information */
if (layno == 0) {
@ -347,12 +347,12 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
n = cblk->numpassesinlayers;
if (cblk->numpassesinlayers == 0) {
if (value != 0) {
n = 3 * value - 2 + cblk->numpassesinlayers;
n = 3 * (OPJ_UINT32)value - 2 + cblk->numpassesinlayers;
} else {
n = cblk->numpassesinlayers;
}
} else {
n = 3 * value + cblk->numpassesinlayers;
n = 3 * (OPJ_UINT32)value + cblk->numpassesinlayers;
}
layer->numpasses = n - cblk->numpassesinlayers;
@ -421,10 +421,10 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
OPJ_FLOAT64 dd, rdslope;
if (passno == 0) {
dr = pass->rate;
dr = (OPJ_INT32)pass->rate;
dd = pass->distortiondec;
} else {
dr = pass->rate - cblk->passes[passno - 1].rate;
dr = (OPJ_INT32)(pass->rate - cblk->passes[passno - 1].rate);
dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec;
}
@ -580,7 +580,7 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
}
memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t));
l_tile_comp_size = p_image->numcomps * sizeof(opj_tcd_tilecomp_t);
l_tile_comp_size = p_image->numcomps * (OPJ_UINT32)sizeof(opj_tcd_tilecomp_t);
p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size);
if (! p_tcd->tcd_image->tiles->comps ) {
return OPJ_FALSE;
@ -659,10 +659,15 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
/*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ \
\
/* 4 borders of the tile rescale on the image if necessary */ \
l_tile->x0 = opj_int_max(l_cp->tx0 + p * l_cp->tdx, l_image->x0); \
l_tile->y0 = opj_int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \
l_tile->x1 = opj_int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \
l_tile->y1 = opj_int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \
l_tile->x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + p * l_cp->tdx), (OPJ_INT32)l_image->x0); \
l_tile->y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + q * l_cp->tdy), (OPJ_INT32)l_image->y0); \
l_tile->x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (p + 1) * l_cp->tdx), (OPJ_INT32)l_image->x1); \
l_tile->y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (q + 1) * l_cp->tdy), (OPJ_INT32)l_image->y1); \
/* testcase 1888.pdf.asan.35.988 */ \
if (l_tccp->numresolutions == 0) { \
fprintf(stderr, "tiles require at least one resolution\n"); \
return OPJ_FALSE; \
} \
/*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,l_tile->x1,l_tile->y1);*/ \
\
/*tile->numcomps = image->numcomps; */ \
@ -670,14 +675,14 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
/*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \
\
/* border of each l_tile component (global) */ \
l_tilec->x0 = opj_int_ceildiv(l_tile->x0, l_image_comp->dx); \
l_tilec->y0 = opj_int_ceildiv(l_tile->y0, l_image_comp->dy); \
l_tilec->x1 = opj_int_ceildiv(l_tile->x1, l_image_comp->dx); \
l_tilec->y1 = opj_int_ceildiv(l_tile->y1, l_image_comp->dy); \
l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_comp->dx); \
l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_comp->dy); \
l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_comp->dx); \
l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (OPJ_INT32)l_image_comp->dy); \
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ \
\
l_data_size = (l_tilec->x1 - l_tilec->x0) \
* (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 );\
l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0) \
* (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0) * (OPJ_UINT32)sizeof(OPJ_UINT32 );\
l_tilec->numresolutions = l_tccp->numresolutions; \
if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) { \
l_tilec->minimum_num_resolutions = 1; \
@ -711,7 +716,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
l_tilec->data_size = l_data_size; \
} \
\
l_data_size = l_tilec->numresolutions * sizeof(opj_tcd_resolution_t); \
l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_tcd_resolution_t); \
\
if (l_tilec->resolutions == 00) { \
l_tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(l_data_size); \
@ -756,28 +761,28 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \
\
/* border for each resolution level (global) */ \
l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, l_level_no); \
l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, l_level_no); \
l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, l_level_no); \
l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, l_level_no); \
l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no); \
l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); \
l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no); \
l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no); \
/*fprintf(stderr, "\t\t\tres_x0= %d, res_y0 =%d, res_x1=%d, res_y1=%d\n", l_res->x0, l_res->y0, l_res->x1, l_res->y1);*/ \
/* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ \
l_pdx = l_tccp->prcw[resno]; \
l_pdy = l_tccp->prch[resno]; \
/*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy);*/ \
/* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ \
l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, l_pdx) << l_pdx; \
l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, l_pdy) << l_pdy; \
l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, l_pdx) << l_pdx; \
l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, l_pdy) << l_pdy; \
l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_INT32)l_pdx) << l_pdx; \
l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_INT32)l_pdy) << l_pdy; \
l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT32)l_pdx) << l_pdx; \
l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT32)l_pdy) << l_pdy; \
/*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ \
\
l_res->pw = (l_res->x0 == l_res->x1) ? 0 : ((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \
l_res->ph = (l_res->y0 == l_res->y1) ? 0 : ((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \
l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \
l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \
/*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/ \
\
l_nb_precincts = l_res->pw * l_res->ph; \
l_nb_precinct_size = l_nb_precincts * sizeof(opj_tcd_precinct_t); \
l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof(opj_tcd_precinct_t); \
if (resno == 0) { \
tlcbgxstart = l_tl_prc_x_start; \
tlcbgystart = l_tl_prc_y_start; \
@ -807,29 +812,29 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
\
if (resno == 0) { \
l_band->bandno = 0 ; \
l_band->x0 = opj_int_ceildivpow2(l_tilec->x0, l_level_no); \
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, l_level_no); \
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, l_level_no); \
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, l_level_no); \
l_band->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no); \
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); \
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no); \
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no); \
} \
else { \
l_band->bandno = bandno + 1; \
/* x0b = 1 if bandno = 1 or 3 */ \
l_x0b = l_band->bandno&1; \
/* y0b = 1 if bandno = 2 or 3 */ \
l_y0b = (l_band->bandno)>>1; \
l_y0b = (OPJ_INT32)((l_band->bandno)>>1); \
/* l_band border (global) */ \
l_band->x0 = opj_int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, l_level_no + 1); \
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, l_level_no + 1); \
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, l_level_no + 1); \
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, l_level_no + 1); \
l_band->x0 = opj_int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \
} \
\
/** avoid an if with storing function pointer */ \
l_gain = (*l_gain_ptr) (l_band->bandno); \
numbps = l_image_comp->prec + l_gain; \
numbps = (OPJ_INT32)(l_image_comp->prec + l_gain); \
l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FRACTION; \
l_band->numbps = l_step_size->expn + l_tccp->numgbits - 1; /* WHY -1 ? */ \
l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits - 1; /* WHY -1 ? */ \
\
if (! l_band->precincts) { \
l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size); \
@ -860,8 +865,8 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
l_current_precinct = l_band->precincts; \
for (precno = 0; precno < l_nb_precincts; ++precno) { \
OPJ_INT32 tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; \
OPJ_INT32 cbgxstart = tlcbgxstart + (precno % l_res->pw) * (1 << cbgwidthexpn); \
OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \
OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ_INT32)(precno % l_res->pw) * (1 << cbgwidthexpn); \
OPJ_INT32 cbgystart = tlcbgystart + (OPJ_INT32)(precno / l_res->pw) * (1 << cbgheightexpn); \
OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \
OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \
/*fprintf(stderr, "\t precno=%d; bandno=%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ \
@ -876,20 +881,20 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
l_current_precinct->y1 = opj_int_min(cbgyend, l_band->y1); \
/*fprintf(stderr, "\t prc_x0=%d; prc_y0=%d, prc_x1=%d; prc_y1=%d\n",l_current_precinct->x0, l_current_precinct->y0 ,l_current_precinct->x1, l_current_precinct->y1);*/ \
\
tlcblkxstart = opj_int_floordivpow2(l_current_precinct->x0, cblkwidthexpn) << cblkwidthexpn; \
tlcblkxstart = opj_int_floordivpow2(l_current_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \
/*fprintf(stderr, "\t tlcblkxstart =%d\n",tlcblkxstart );*/ \
tlcblkystart = opj_int_floordivpow2(l_current_precinct->y0, cblkheightexpn) << cblkheightexpn; \
tlcblkystart = opj_int_floordivpow2(l_current_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \
/*fprintf(stderr, "\t tlcblkystart =%d\n",tlcblkystart );*/ \
brcblkxend = opj_int_ceildivpow2(l_current_precinct->x1, cblkwidthexpn) << cblkwidthexpn; \
brcblkxend = opj_int_ceildivpow2(l_current_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \
/*fprintf(stderr, "\t brcblkxend =%d\n",brcblkxend );*/ \
brcblkyend = opj_int_ceildivpow2(l_current_precinct->y1, cblkheightexpn) << cblkheightexpn; \
brcblkyend = opj_int_ceildivpow2(l_current_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \
/*fprintf(stderr, "\t brcblkyend =%d\n",brcblkyend );*/ \
l_current_precinct->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; \
l_current_precinct->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; \
l_current_precinct->cw = (OPJ_UINT32)((brcblkxend - tlcblkxstart) >> cblkwidthexpn); \
l_current_precinct->ch = (OPJ_UINT32)((brcblkyend - tlcblkystart) >> cblkheightexpn); \
\
l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; \
/*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ \
l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \
l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof(TYPE); \
\
if (! l_current_precinct->cblks.ELEMENT) { \
l_current_precinct->cblks.ELEMENT = (TYPE*) opj_malloc(l_nb_code_blocks_size); \
@ -957,8 +962,8 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \
l_code_block = l_current_precinct->cblks.ELEMENT; \
\
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { \
OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \
OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \
OPJ_INT32 cblkxstart = tlcblkxstart + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \
OPJ_INT32 cblkystart = tlcblkystart + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \
OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \
OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \
\
@ -1001,7 +1006,7 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block)
{
if (! p_code_block->data) {
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); //why +1 ?
p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE*2); /*why +1 ?*/
if(! p_code_block->data) {
return OPJ_FALSE;
}
@ -1085,7 +1090,7 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size ( opj_tcd_t *p_tcd )
}
l_res = l_tile_comp->resolutions + l_tile_comp->minimum_num_resolutions - 1;
l_data_size += l_size_comp * (l_res->x1 - l_res->x0) * (l_res->y1 - l_res->y0);
l_data_size += l_size_comp * (OPJ_UINT32)((l_res->x1 - l_res->x0) * (l_res->y1 - l_res->y0));
++l_img_comp;
++l_tile_comp;
}
@ -1116,14 +1121,14 @@ OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd,
for (i = 0; i < l_tilec_idx->numresolutions; i++) {
opj_tcd_resolution_t *l_res_idx = &l_tilec_idx->resolutions[i];
p_cstr_info->tile[p_tile_no].pw[i] = l_res_idx->pw;
p_cstr_info->tile[p_tile_no].ph[i] = l_res_idx->ph;
p_cstr_info->tile[p_tile_no].pw[i] = (int)l_res_idx->pw;
p_cstr_info->tile[p_tile_no].ph[i] = (int)l_res_idx->ph;
l_num_packs += l_res_idx->pw * l_res_idx->ph;
p_cstr_info->tile[p_tile_no].pdx[i] = l_tccp->prcw[i];
p_cstr_info->tile[p_tile_no].pdy[i] = l_tccp->prch[i];
p_cstr_info->tile[p_tile_no].pdx[i] = (int)l_tccp->prcw[i];
p_cstr_info->tile[p_tile_no].pdy[i] = (int)l_tccp->prch[i];
}
p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc(p_cstr_info->numcomps * p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t));
p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc((size_t)p_cstr_info->numcomps * (size_t)p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t));
}
/* << INDEX */
@ -1286,9 +1291,9 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
l_width = (l_res->x1 - l_res->x0);
l_height = (l_res->y1 - l_res->y0);
l_stride = (l_tilec->x1 - l_tilec->x0) - l_width;
l_width = (OPJ_UINT32)(l_res->x1 - l_res->x0);
l_height = (OPJ_UINT32)(l_res->y1 - l_res->y0);
l_stride = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0) - l_width;
if (l_remaining) {
++l_size_comp;
@ -1316,7 +1321,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
else {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (OPJ_BYTE) ((*(l_src_ptr++))&0xff);
*(l_dest_ptr++) = (OPJ_CHAR) ((*(l_src_ptr++))&0xff);
}
l_src_ptr += l_stride;
}
@ -1341,7 +1346,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
else {
for (j=0;j<l_height;++j) {
for (k=0;k<l_width;++k) {
*(l_dest_ptr++) = (OPJ_UINT16) ((*(l_src_ptr++))&0xffff);
*(l_dest_ptr++) = (OPJ_INT16) ((*(l_src_ptr++))&0xffff);
}
l_src_ptr += l_stride;
}
@ -1570,10 +1575,17 @@ OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd )
return OPJ_TRUE;
}
l_samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0);
l_samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0));
if (l_tile->numcomps >= 3 ){
if (l_tcp->mct == 2) {
/* testcase 1336.pdf.asan.47.376 */
if ((l_tile->comps[0].x1 - l_tile->comps[0].x0) * (l_tile->comps[0].y1 - l_tile->comps[0].y0) < (OPJ_INT32)l_samples ||
(l_tile->comps[1].x1 - l_tile->comps[1].x0) * (l_tile->comps[1].y1 - l_tile->comps[1].y0) < (OPJ_INT32)l_samples ||
(l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) {
fprintf(stderr, "Tiles don't all have the same dimension. Skip the MCT step.\n");
return OPJ_FALSE;
}
else if (l_tcp->mct == 2) {
OPJ_BYTE ** l_data;
if (! l_tcp->m_mct_decoding_matrix) {
@ -1650,9 +1662,11 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
for (compno = 0; compno < l_tile->numcomps; compno++) {
l_res = l_tile_comp->resolutions + l_img_comp->resno_decoded;
l_width = (l_res->x1 - l_res->x0);
l_height = (l_res->y1 - l_res->y0);
l_stride = (l_tile_comp->x1 - l_tile_comp->x0) - l_width;
l_width = (OPJ_UINT32)(l_res->x1 - l_res->x0);
l_height = (OPJ_UINT32)(l_res->y1 - l_res->y0);
l_stride = (OPJ_UINT32)(l_tile_comp->x1 - l_tile_comp->x0) - l_width;
assert(l_height == 0 || l_width + l_stride <= l_tile_comp->data_size / l_height); /*MUPDF*/
if (l_img_comp->sgnd) {
l_min = -(1 << (l_img_comp->prec - 1));
@ -1678,7 +1692,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
for (j=0;j<l_height;++j) {
for (i = 0; i < l_width; ++i) {
OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr);
*l_current_ptr = opj_int_clamp(lrintf(l_value) + l_tccp->m_dc_level_shift, l_min, l_max); ;
*l_current_ptr = opj_int_clamp((OPJ_INT32)lrintf(l_value) + l_tccp->m_dc_level_shift, l_min, l_max); ;
++l_current_ptr;
}
l_current_ptr += l_stride;
@ -1789,7 +1803,7 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd )
l_size_comp = 4;
}
l_data_size += l_size_comp * (l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0);
l_data_size += l_size_comp * (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0));
++l_img_comp;
++l_tilec;
}
@ -1814,7 +1828,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd )
for (compno = 0; compno < l_tile->numcomps; compno++) {
l_current_ptr = l_tile_comp->data;
l_nb_elem = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0);
l_nb_elem = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0));
if (l_tccp->qmfbid == 1) {
for (i = 0; i < l_nb_elem; ++i) {
@ -1841,7 +1855,7 @@ OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
{
opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps;
OPJ_UINT32 samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0);
OPJ_UINT32 samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0));
OPJ_UINT32 i;
OPJ_BYTE ** l_data = 00;
opj_tcp_t * l_tcp = p_tcd->tcp;
@ -2038,7 +2052,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
for (i=0;i<p_tcd->image->numcomps;++i) {
l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/
l_remaining = l_img_comp->prec & 7; /* (%8) */
l_nb_elem = (l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0);
l_nb_elem = (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0));
if (l_remaining) {
++l_size_comp;

View File

@ -53,7 +53,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
if(!tree) {
fprintf(stderr, "ERROR in tgt_create_v2 while allocating tree\n");
fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
return 00;
}
memset(tree,0,sizeof(opj_tgt_tree_t));
@ -62,11 +62,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
tree->numleafsv = numleafsv;
numlvls = 0;
nplh[0] = numleafsh;
nplv[0] = numleafsv;
nplh[0] = (OPJ_INT32)numleafsh;
nplv[0] = (OPJ_INT32)numleafsv;
tree->numnodes = 0;
do {
n = nplh[numlvls] * nplv[numlvls];
n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]);
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
tree->numnodes += n;
@ -76,18 +76,18 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
/* ADD */
if (tree->numnodes == 0) {
opj_free(tree);
fprintf(stderr, "WARNING in tgt_create_v2 tree->numnodes == 0, no tree created.\n");
fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no tree created.\n");
return 00;
}
tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
if(!tree->nodes) {
fprintf(stderr, "ERROR in tgt_create_v2 while allocating node of the tree\n");
fprintf(stderr, "ERROR in tgt_create while allocating node of the tree\n");
opj_free(tree);
return 00;
}
memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
tree->nodes_size = tree->numnodes * sizeof(opj_tgt_node_t);
tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
node = tree->nodes;
l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
@ -119,7 +119,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
}
/**
* Reinitialises a tag-tree from an exixting one. (V2 framevork)
* Reinitialises a tag-tree from an existing one.
*
* @param p_tree the tree to reinitialize.
* @param p_num_leafs_h the width of the array of leafs of the tree
@ -148,12 +148,12 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
p_tree->numleafsv = p_num_leafs_v;
l_num_levels = 0;
l_nplh[0] = p_num_leafs_h;
l_nplv[0] = p_num_leafs_v;
l_nplh[0] = (OPJ_INT32)p_num_leafs_h;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v;
p_tree->numnodes = 0;
do
{
n = l_nplh[l_num_levels] * l_nplv[l_num_levels];
n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]);
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
p_tree->numnodes += n;
@ -166,7 +166,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
opj_tgt_destroy(p_tree);
return 00;
}
l_node_size = p_tree->numnodes * sizeof(opj_tgt_node_t);
l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);
if (l_node_size > p_tree->nodes_size) {
opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size);

View File

@ -48,7 +48,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
OPJ_OFF_T lenp;
lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));
box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t));
for ( i = 0; i < 2 ; i++ ){
if (i)
@ -62,7 +62,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager);
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
box[tileno].length = opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].type = JPIP_MHIX;
}
@ -76,7 +76,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
opj_free(box);
return len;
return (int)len;
}
/*
@ -107,7 +107,7 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o
tile = cstr_info.tile[tileno];
tp = tile.tp[0];
opj_write_bytes(l_data_header,tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_header-tp.tp_start_pos+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager);
marker = cstr_info.tile[tileno].marker;
@ -118,7 +118,7 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, (OPJ_UINT32)(marker[i].pos-coff), 8);
opj_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, marker[i].len, 2);
opj_write_bytes( l_data_header, (OPJ_UINT32)marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager);
}
@ -130,5 +130,5 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}

View File

@ -80,7 +80,7 @@ int opj_write_tpix( int coff,
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}
int opj_write_tpixfaix( int coff,
@ -92,15 +92,15 @@ int opj_write_tpixfaix( int coff,
{
OPJ_UINT32 len;
OPJ_OFF_T lenp;
int i, j;
int Aux;
int num_max_tile_parts;
int size_of_coding; /* 4 or 8 */
OPJ_UINT32 i, j;
OPJ_UINT32 Aux;
OPJ_UINT32 num_max_tile_parts;
OPJ_UINT32 size_of_coding; /* 4 or 8 */
opj_tp_info_t tp;
OPJ_BYTE l_data_header [8];
int version;
OPJ_UINT32 version;
num_max_tile_parts = get_num_max_tile_parts( cstr_info);
num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info);
if( j2klen > pow( 2, 32)){
size_of_coding = 8;
@ -120,24 +120,24 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < cstr_info.tw*cstr_info.th; i++)
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++)
{
for (j = 0; j < cstr_info.tile[i].num_tps; j++)
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
{
tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,tp.tp_start_pos-coff,size_of_coding); /* start position */
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,tp.tp_end_pos-tp.tp_start_pos+1,size_of_coding); /* length */
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02)
{
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = cstr_info.numdecompos[compno] + 1;
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else
Aux = j + 1;
@ -171,7 +171,7 @@ int opj_write_tpixfaix( int coff,
opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager);
return len;
return (int)len;
}
int get_num_max_tile_parts( opj_codestream_info_t cstr_info)

378
src/lib/openjp3d/bio.c Executable file → Normal file
View File

@ -1,189 +1,189 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
/** @name Local static functions */
/*@{*/
/**
Write a bit
@param bio BIO handle
@param b Bit to write (0 or 1)
*/
static void bio_putbit(opj_bio_t *bio, int b);
/**
Read a bit
@param bio BIO handle
@return Returns the read bit
*/
static int bio_getbit(opj_bio_t *bio);
/**
Write a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_byteout(opj_bio_t *bio);
/**
Read a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_bytein(opj_bio_t *bio);
/*@}*/
/*@}*/
/*
==========================================================
local functions
==========================================================
*/
static int bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
*bio->bp++ = bio->buf >> 8;
return 0;
}
static int bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
bio->buf |= *bio->bp++;
return 0;
}
static void bio_putbit(opj_bio_t *bio, int b) {
if (bio->ct == 0) {
bio_byteout(bio);
}
bio->ct--;
bio->buf |= b << bio->ct;
}
/* MOD antonin */
static int bio_getbit(opj_bio_t *bio) {
/* DOM */
if (bio->ct == 0) {
bio_bytein(bio);
}
bio->ct--;
return (bio->buf >> bio->ct) & 1;
}
/*
==========================================================
Bit Input/Output interface
==========================================================
*/
opj_bio_t* bio_create() {
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
}
int bio_numbytes(opj_bio_t *bio) {
return (bio->bp - bio->start);
}
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 8;
}
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 0;
}
void bio_write(opj_bio_t *bio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1);
}
}
int bio_read(opj_bio_t *bio, int n) {
int i, v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += bio_getbit(bio) << i;
}
return v;
}
int bio_flush(opj_bio_t *bio) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
if (bio->ct == 7) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
}
return 0;
}
int bio_inalign(opj_bio_t *bio) {
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) {
return 1;
}
bio->ct = 0;
}
return 0;
}
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
/** @name Local static functions */
/*@{*/
/**
Write a bit
@param bio BIO handle
@param b Bit to write (0 or 1)
*/
static void bio_putbit(opj_bio_t *bio, int b);
/**
Read a bit
@param bio BIO handle
@return Returns the read bit
*/
static int bio_getbit(opj_bio_t *bio);
/**
Write a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_byteout(opj_bio_t *bio);
/**
Read a byte
@param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise
*/
static int bio_bytein(opj_bio_t *bio);
/*@}*/
/*@}*/
/*
==========================================================
local functions
==========================================================
*/
static int bio_byteout(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
*bio->bp++ = bio->buf >> 8;
return 0;
}
static int bio_bytein(opj_bio_t *bio) {
bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) {
return 1;
}
bio->buf |= *bio->bp++;
return 0;
}
static void bio_putbit(opj_bio_t *bio, int b) {
if (bio->ct == 0) {
bio_byteout(bio);
}
bio->ct--;
bio->buf |= b << bio->ct;
}
/* MOD antonin */
static int bio_getbit(opj_bio_t *bio) {
/* DOM */
if (bio->ct == 0) {
bio_bytein(bio);
}
bio->ct--;
return (bio->buf >> bio->ct) & 1;
}
/*
==========================================================
Bit Input/Output interface
==========================================================
*/
opj_bio_t* bio_create() {
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio;
}
void bio_destroy(opj_bio_t *bio) {
if(bio) {
opj_free(bio);
}
}
int bio_numbytes(opj_bio_t *bio) {
return (bio->bp - bio->start);
}
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 8;
}
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
bio->start = bp;
bio->end = bp + len;
bio->bp = bp;
bio->buf = 0;
bio->ct = 0;
}
void bio_write(opj_bio_t *bio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1);
}
}
int bio_read(opj_bio_t *bio, int n) {
int i, v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += bio_getbit(bio) << i;
}
return v;
}
int bio_flush(opj_bio_t *bio) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
if (bio->ct == 7) {
bio->ct = 0;
if (bio_byteout(bio)) {
return 1;
}
}
return 0;
}
int bio_inalign(opj_bio_t *bio) {
bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) {
return 1;
}
bio->ct = 0;
}
return 0;
}

264
src/lib/openjp3d/bio.h Executable file → Normal file
View File

@ -1,132 +1,132 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BIO_H
#define __BIO_H
/**
@file bio.h
@brief Implementation of an individual bit input-output (BIO)
The functions in BIO.C have for goal to realize an individual bit input - output.
*/
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
/**
Individual bit input-output stream (BIO)
*/
typedef struct opj_bio {
/** pointer to the start of the buffer */
unsigned char *start;
/** pointer to the end of the buffer */
unsigned char *end;
/** pointer to the present position in the buffer */
unsigned char *bp;
/** temporary place where each byte is read or written */
unsigned int buf;
/** coder : number of bits free to write. decoder : number of bits read */
int ct;
} opj_bio_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise
*/
opj_bio_t* bio_create(void);
/**
Destroy a previously created BIO handle
@param bio BIO handle to destroy
*/
void bio_destroy(opj_bio_t *bio);
/**
Number of bytes written.
@param bio BIO handle
@return Returns the number of bytes written
*/
int bio_numbytes(opj_bio_t *bio);
/**
Init encoder
@param bio BIO handle
@param bp Output buffer
@param len Output buffer length
*/
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len);
/**
Init decoder
@param bio BIO handle
@param bp Input buffer
@param len Input buffer length
*/
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len);
/**
Write bits
@param bio BIO handle
@param v Value of bits
@param n Number of bits to write
*/
void bio_write(opj_bio_t *bio, int v, int n);
/**
Read bits
@param bio BIO handle
@param n Number of bits to read
@return Returns the corresponding read number
*/
int bio_read(opj_bio_t *bio, int n);
/**
Flush bits
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_flush(opj_bio_t *bio);
/**
Passes the ending bits (coming from flushing)
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_inalign(opj_bio_t *bio);
/**
Read a bit
@param bio BIO handle
@return Returns the read bit
*/
/* MOD antonin */
/*int bio_getbit(opj_bio_t *bio);*/
/* DOM */
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __BIO_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __BIO_H
#define __BIO_H
/**
@file bio.h
@brief Implementation of an individual bit input-output (BIO)
The functions in BIO.C have for goal to realize an individual bit input - output.
*/
/** @defgroup BIO BIO - Individual bit input-output stream */
/*@{*/
/**
Individual bit input-output stream (BIO)
*/
typedef struct opj_bio {
/** pointer to the start of the buffer */
unsigned char *start;
/** pointer to the end of the buffer */
unsigned char *end;
/** pointer to the present position in the buffer */
unsigned char *bp;
/** temporary place where each byte is read or written */
unsigned int buf;
/** coder : number of bits free to write. decoder : number of bits read */
int ct;
} opj_bio_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new BIO handle
@return Returns a new BIO handle if successful, returns NULL otherwise
*/
opj_bio_t* bio_create(void);
/**
Destroy a previously created BIO handle
@param bio BIO handle to destroy
*/
void bio_destroy(opj_bio_t *bio);
/**
Number of bytes written.
@param bio BIO handle
@return Returns the number of bytes written
*/
int bio_numbytes(opj_bio_t *bio);
/**
Init encoder
@param bio BIO handle
@param bp Output buffer
@param len Output buffer length
*/
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len);
/**
Init decoder
@param bio BIO handle
@param bp Input buffer
@param len Input buffer length
*/
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len);
/**
Write bits
@param bio BIO handle
@param v Value of bits
@param n Number of bits to write
*/
void bio_write(opj_bio_t *bio, int v, int n);
/**
Read bits
@param bio BIO handle
@param n Number of bits to read
@return Returns the corresponding read number
*/
int bio_read(opj_bio_t *bio, int n);
/**
Flush bits
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_flush(opj_bio_t *bio);
/**
Passes the ending bits (coming from flushing)
@param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise
*/
int bio_inalign(opj_bio_t *bio);
/**
Read a bit
@param bio BIO handle
@return Returns the read bit
*/
/* MOD antonin */
/*int bio_getbit(opj_bio_t *bio);*/
/* DOM */
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __BIO_H */

435
src/lib/openjp3d/cio.c Executable file → Normal file
View File

@ -1,217 +1,218 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL;
cio->cinfo = cinfo;
if(buffer && length) {
/* wrap a user buffer containing the encoded image */
cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer;
cio->length = length;
}
else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) {
case CODEC_J3D:
case CODEC_J2K:
cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp;
break;
default:
opj_free(cio);
return NULL;
}
cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4;
cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) {
opj_free(cio);
return NULL;
}
}
else {
opj_free(cio);
return NULL;
}
/* Initialize byte IO */
cio->start = cio->buffer;
cio->end = cio->buffer + cio->length;
cio->bp = cio->buffer;
return cio;
}
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */
opj_free(cio->buffer);
}
/* destroy the cio */
opj_free(cio);
}
}
/* ----------------------------------------------------------------------- */
/*
* Get position in byte stream.
*/
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
return cio->bp - cio->start;
}
/*
* Set position in byte stream.
*
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
cio->bp = cio->start + pos;
}
/*
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio) {
return cio->end - cio->bp;
}
/*
* Get pointer to the current position in the stream.
*/
unsigned char *cio_getbp(opj_cio_t *cio) {
return cio->bp;
}
/*
* Write a byte.
*/
static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false;
}
*cio->bp++ = v;
return true;
}
/*
* Read a byte.
*/
static unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0;
}
return *cio->bp++;
}
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n) {
int i;
unsigned int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}
/*
* Skip some bytes.
*
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n) {
cio->bp += n;
}
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
int cio_write_int(opj_cio_t *cio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n) {
int i;
int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) {
opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL;
cio->cinfo = cinfo;
if(buffer && length) {
/* wrap a user buffer containing the encoded image */
cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer;
cio->length = length;
}
else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) {
case CODEC_J3D:
case CODEC_J2K:
cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp;
break;
default:
opj_free(cio);
return NULL;
}
cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4;
cio->buffer = (unsigned char *)opj_malloc(cio->length);
if(!cio->buffer) {
opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n");
opj_free(cio);
return NULL;
}
}
else {
opj_free(cio);
return NULL;
}
/* Initialize byte IO */
cio->start = cio->buffer;
cio->end = cio->buffer + cio->length;
cio->bp = cio->buffer;
return cio;
}
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */
opj_free(cio->buffer);
}
/* destroy the cio */
opj_free(cio);
}
}
/* ----------------------------------------------------------------------- */
/*
* Get position in byte stream.
*/
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
return cio->bp - cio->start;
}
/*
* Set position in byte stream.
*
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
cio->bp = cio->start + pos;
}
/*
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio) {
return cio->end - cio->bp;
}
/*
* Get pointer to the current position in the stream.
*/
unsigned char *cio_getbp(opj_cio_t *cio) {
return cio->bp;
}
/*
* Write a byte.
*/
static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false;
}
*cio->bp++ = v;
return true;
}
/*
* Read a byte.
*/
static unsigned char cio_bytein(opj_cio_t *cio) {
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0;
}
return *cio->bp++;
}
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n) {
int i;
unsigned int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}
/*
* Skip some bytes.
*
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n) {
cio->bp += n;
}
/*
* Write some bytes.
*
* v : value to write
* n : number of bytes to write
*/
int cio_write_int(opj_cio_t *cio, int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
return 0;
}
return n;
}
/*
* Read some bytes.
*
* n : number of bytes to read
*
* return : value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n) {
int i;
int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += cio_bytein(cio) << (i << 3);
}
return v;
}

200
src/lib/openjp3d/cio.h Executable file → Normal file
View File

@ -1,100 +1,100 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __CIO_H
#define __CIO_H
/**
@file cio.h
@brief Implementation of a byte input-output process (CIO)
The functions in CIO.C have for goal to realize a byte input / output process.
*/
/** @defgroup CIO CIO - byte input-output stream */
/*@{*/
/** @name Funciones generales (see also openjp3d.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Number of bytes left before the end of the stream
@param cio CIO handle
@return Returns the number of bytes before the end of the stream
*/
int cio_numbytesleft(opj_cio_t *cio);
/**
Get pointer to the current position in the stream
@param cio CIO handle
@return Returns a pointer to the current position
*/
unsigned char *cio_getbp(opj_cio_t *cio);
/**
Write some bytes
@param cio CIO handle
@param v Value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n);
/**
Skip some bytes
@param cio CIO handle
@param n Number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n);
/**
Write some bytes
@param cio CIO handle
@param v Signed integer value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
int cio_write_int(opj_cio_t *cio, int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __CIO_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __CIO_H
#define __CIO_H
/**
@file cio.h
@brief Implementation of a byte input-output process (CIO)
The functions in CIO.C have for goal to realize a byte input / output process.
*/
/** @defgroup CIO CIO - byte input-output stream */
/*@{*/
/** @name Funciones generales (see also openjp3d.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Number of bytes left before the end of the stream
@param cio CIO handle
@return Returns the number of bytes before the end of the stream
*/
int cio_numbytesleft(opj_cio_t *cio);
/**
Get pointer to the current position in the stream
@param cio CIO handle
@return Returns a pointer to the current position
*/
unsigned char *cio_getbp(opj_cio_t *cio);
/**
Write some bytes
@param cio CIO handle
@param v Value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
unsigned int cio_read(opj_cio_t *cio, int n);
/**
Skip some bytes
@param cio CIO handle
@param n Number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n);
/**
Write some bytes
@param cio CIO handle
@param v Signed integer value to write
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
int cio_write_int(opj_cio_t *cio, int v, int n);
/**
Read some bytes
@param cio CIO handle
@param n Number of bytes to read
@return Returns the value of the n bytes read
*/
int cio_read_int(opj_cio_t *cio, int n);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __CIO_H */

4
src/lib/openjp3d/dwt.c Executable file → Normal file
View File

@ -58,7 +58,7 @@
/** @name Local static functions */
/*@{*/
unsigned int ops;
/*unsigned int ops;*/
/**
Forward lazy transform (horizontal)
*/
@ -668,7 +668,7 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]) {
int *bj = NULL;
int *cj = NULL;
ops = 0;
/*ops = 0;*/
memset(flagnorm,0,8000*sizeof(int));
w = tilec->x1-tilec->x0;

202
src/lib/openjp3d/dwt.h Executable file → Normal file
View File

@ -1,101 +1,101 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __DWT_H
#define __DWT_H
/**
@file dwt.h
@brief Implementation of a discrete wavelet transform (DWT)
The functions in DWT.C have for goal to realize forward and inverse discret wavelet
transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in
DWT.C are used by some function in TCD.C.
*/
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
/*@{*/
/**
DCCS-LIWT properties
*/
typedef struct opj_wtfilt {
double *LPS;
int lenLPS;
double *HPS;
int lenHPS;
} opj_wtfilt_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Forward 5-3 wavelet tranform in 3-D.
Apply a reversible DWT transform to a component of an volume.
@param tilec Tile component information (current tile)
@param dwtid Number of identification of wavelet kernel(s) used in DWT in each direction
*/
void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]);
/**
Inverse 5-3 wavelet tranform in 3-D.
Apply a reversible inverse DWT transform to a component of an volume.
@param tilec Tile component information (current tile)
@param stops Number of decoded resolution levels in each dimension
@param dwtid Number of identification of wavelet kernel(s) used in DWT in each dimension
*/
void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]);
/* ----------------------------------------------------------------------- */
/**
Get the gain of a subband for the reversible 3-D DWT.
@param orient Number that identifies the subband (0->LLL, 1->HLL, 2->LHL, 3->HHL, 4->LLH, 5->HLH, 6->LHH, 7->HHH)
@param reversible Wavelet transformation type
@return Returns 0 if orient = 0, returns 1 if orient = 1,2 or 4, returns 2 if orient = 3,5 or 6, returns 3 otherwise
*/
int dwt_getgain(int orient, int reversible);
/**
Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT or irreversible 9-7 in 3-D.
@param orient Band of the wavelet function
@param level Levels of the wavelet function in X,Y,Z axis
@param dwtid Wavelet transformation identifier
@return Returns the norm of the wavelet function
*/
double dwt_getnorm(int orient, int level[3], int dwtid[3]);
/* ----------------------------------------------------------------------- */
/**
Calcula el valor del escalón de cuantificación correspondiente a cada subbanda.
@param tccp Tile component coding parameters
@param prec Precision of data
*/
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec);
/*@}*/
/*@}*/
#endif /* __DWT_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __DWT_H
#define __DWT_H
/**
@file dwt.h
@brief Implementation of a discrete wavelet transform (DWT)
The functions in DWT.C have for goal to realize forward and inverse discret wavelet
transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in
DWT.C are used by some function in TCD.C.
*/
/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */
/*@{*/
/**
DCCS-LIWT properties
*/
typedef struct opj_wtfilt {
double *LPS;
int lenLPS;
double *HPS;
int lenHPS;
} opj_wtfilt_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Forward 5-3 wavelet tranform in 3-D.
Apply a reversible DWT transform to a component of an volume.
@param tilec Tile component information (current tile)
@param dwtid Number of identification of wavelet kernel(s) used in DWT in each direction
*/
void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]);
/**
Inverse 5-3 wavelet tranform in 3-D.
Apply a reversible inverse DWT transform to a component of an volume.
@param tilec Tile component information (current tile)
@param stops Number of decoded resolution levels in each dimension
@param dwtid Number of identification of wavelet kernel(s) used in DWT in each dimension
*/
void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]);
/* ----------------------------------------------------------------------- */
/**
Get the gain of a subband for the reversible 3-D DWT.
@param orient Number that identifies the subband (0->LLL, 1->HLL, 2->LHL, 3->HHL, 4->LLH, 5->HLH, 6->LHH, 7->HHH)
@param reversible Wavelet transformation type
@return Returns 0 if orient = 0, returns 1 if orient = 1,2 or 4, returns 2 if orient = 3,5 or 6, returns 3 otherwise
*/
int dwt_getgain(int orient, int reversible);
/**
Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT or irreversible 9-7 in 3-D.
@param orient Band of the wavelet function
@param level Levels of the wavelet function in X,Y,Z axis
@param dwtid Wavelet transformation identifier
@return Returns the norm of the wavelet function
*/
double dwt_getnorm(int orient, int level[3], int dwtid[3]);
/* ----------------------------------------------------------------------- */
/**
Calcula el valor del escalón de cuantificación correspondiente a cada subbanda.
@param tccp Tile component coding parameters
@param prec Precision of data
*/
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec);
/*@}*/
/*@}*/
#endif /* __DWT_H */

362
src/lib/openjp3d/event.c Executable file → Normal file
View File

@ -1,181 +1,181 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* ==========================================================
// Utility functions
// ==========================================================*/
#ifndef _WIN32
static char*
i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
}
/**
Transforms integer i into an ascii string and stores the result in a;
string is encoded in the base indicated by r.
@param i Number to be converted
@param a String result
@param r Base of value; must be in the range 2 - 36
@return Returns a
*/
static char *
_itoa(int i, char *a, int r) {
r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) {
*a = '-';
*i2a(-i, a+1, r) = 0;
}
else *i2a(i, a, r) = 0;
return a;
}
#endif /* !_WIN32 */
/* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
if(cinfo) {
opj_event_mgr_t *previous = cinfo->event_mgr;
cinfo->event_mgr = event_mgr;
cinfo->client_data = context;
return previous;
}
return NULL;
}
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL;
opj_event_mgr_t *event_mgr = cinfo->event_mgr;
if(event_mgr != NULL) {
switch(event_type) {
case EVT_ERROR:
msg_handler = event_mgr->error_handler;
break;
case EVT_WARNING:
msg_handler = event_mgr->warning_handler;
break;
case EVT_INFO:
msg_handler = event_mgr->info_handler;
break;
default:
break;
}
if(msg_handler == NULL) {
return false;
}
} else {
return false;
}
if ((fmt != NULL) && (event_mgr != NULL)) {
va_list arg;
int str_length, i, j;
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
/* parse the format string and put the result in 'message' */
for (i = 0, j = 0; i < str_length; ++i) {
if (fmt[i] == '%') {
if (i + 1 < str_length) {
switch(tolower(fmt[i + 1])) {
case '%' :
message[j++] = '%';
break;
case 'o' : /* octal numbers */
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 8);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'i' : /* decimal numbers */
case 'd' :
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 10);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'x' : /* hexadecimal numbers */
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 16);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 's' : /* strings */
{
char *tmp = va_arg(arg, char*);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'f' : /* floats */
{
char tmp[16];
double value = va_arg(arg, double);
sprintf(tmp, "%f", value);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
};
} else {
message[j++] = fmt[i];
}
} else {
message[j++] = fmt[i];
};
}
/* deinitialize the optional parameter list */
va_end(arg);
/* output the message to the user program */
msg_handler(message, cinfo->client_data);
}
return true;
}
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* ==========================================================
// Utility functions
// ==========================================================*/
#ifndef _WIN32
static char*
i2a(unsigned i, char *a, unsigned r) {
if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1;
}
/**
Transforms integer i into an ascii string and stores the result in a;
string is encoded in the base indicated by r.
@param i Number to be converted
@param a String result
@param r Base of value; must be in the range 2 - 36
@return Returns a
*/
static char *
_itoa(int i, char *a, int r) {
r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) {
*a = '-';
*i2a(-i, a+1, r) = 0;
}
else *i2a(i, a, r) = 0;
return a;
}
#endif /* !_WIN32 */
/* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) {
if(cinfo) {
opj_event_mgr_t *previous = cinfo->event_mgr;
cinfo->event_mgr = event_mgr;
cinfo->client_data = context;
return previous;
}
return NULL;
}
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL;
opj_event_mgr_t *event_mgr = cinfo->event_mgr;
if(event_mgr != NULL) {
switch(event_type) {
case EVT_ERROR:
msg_handler = event_mgr->error_handler;
break;
case EVT_WARNING:
msg_handler = event_mgr->warning_handler;
break;
case EVT_INFO:
msg_handler = event_mgr->info_handler;
break;
default:
break;
}
if(msg_handler == NULL) {
return false;
}
} else {
return false;
}
if ((fmt != NULL) && (event_mgr != NULL)) {
va_list arg;
int str_length, i, j;
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
/* parse the format string and put the result in 'message' */
for (i = 0, j = 0; i < str_length; ++i) {
if (fmt[i] == '%') {
if (i + 1 < str_length) {
switch(tolower(fmt[i + 1])) {
case '%' :
message[j++] = '%';
break;
case 'o' : /* octal numbers */
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 8);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'i' : /* decimal numbers */
case 'd' :
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 10);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'x' : /* hexadecimal numbers */
{
char tmp[16];
_itoa(va_arg(arg, int), tmp, 16);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 's' : /* strings */
{
char *tmp = va_arg(arg, char*);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
case 'f' : /* floats */
{
char tmp[16];
double value = va_arg(arg, double);
sprintf(tmp, "%f", value);
strcat(message, tmp);
j += strlen(tmp);
++i;
break;
}
};
} else {
message[j++] = fmt[i];
}
} else {
message[j++] = fmt[i];
};
}
/* deinitialize the optional parameter list */
va_end(arg);
/* output the message to the user program */
msg_handler(message, cinfo->client_data);
}
return true;
}

116
src/lib/openjp3d/event.h Executable file → Normal file
View File

@ -1,58 +1,58 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __EVENT_H
#define __EVENT_H
/**
@file event.h
@brief Implementation of a event callback system
The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user.
*/
#define EVT_ERROR 1 /**< Error event type */
#define EVT_WARNING 2 /**< Warning event type */
#define EVT_INFO 4 /**< Debug event type */
/** @defgroup EVENT EVENT - Implementation of a event callback system */
/*@{*/
/** @name Funciones generales (see also openjp3d.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Write formatted data to a string and send the string to a user callback.
@param cinfo Codec context info
@param event_type Event type or callback to use to send the message
@param fmt Format-control string (plus optionnal arguments)
@return Returns true if successful, returns false otherwise
*/
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __EVENT_H */
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __EVENT_H
#define __EVENT_H
/**
@file event.h
@brief Implementation of a event callback system
The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user.
*/
#define EVT_ERROR 1 /**< Error event type */
#define EVT_WARNING 2 /**< Warning event type */
#define EVT_INFO 4 /**< Debug event type */
/** @defgroup EVENT EVENT - Implementation of a event callback system */
/*@{*/
/** @name Funciones generales (see also openjp3d.h) */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Write formatted data to a string and send the string to a user callback.
@param cinfo Codec context info
@param event_type Event type or callback to use to send the message
@param fmt Format-control string (plus optionnal arguments)
@return Returns true if successful, returns false otherwise
*/
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __EVENT_H */

0
src/lib/openjp3d/fix.h Executable file → Normal file
View File

0
src/lib/openjp3d/int.h Executable file → Normal file
View File

4688
src/lib/openjp3d/jp3d.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

1036
src/lib/openjp3d/jp3d.h Executable file → Normal file

File diff suppressed because it is too large Load Diff

152
src/lib/openjp3d/jp3d_lib.c Executable file → Normal file
View File

@ -1,76 +1,76 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_includes.h"
double opj_clock() {
#ifdef _WIN32
/* WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(double) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
double procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec;
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif /* _WIN32 */
}
void* opj_malloc( size_t size ) {
void *memblock = malloc(size);
if(memblock) {
memset(memblock, 0, size);
}
return memblock;
}
void* opj_realloc( void *memblock, size_t size ) {
return realloc(memblock, size);
}
void opj_free( void *memblock ) {
free(memblock);
}
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#include <windows.h>
#else
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/times.h>
#endif /* _WIN32 */
#include "opj_includes.h"
double opj_clock() {
#ifdef _WIN32
/* WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ;
/* freq is the clock speed of the CPU */
QueryPerformanceFrequency(&freq) ;
/* cout << "freq = " << ((double) freq.QuadPart) << endl; */
/* t is the high resolution performance counter (see MSDN) */
QueryPerformanceCounter ( & t ) ;
return ( t.QuadPart /(double) freq.QuadPart ) ;
#else
/* Unix or Linux: use resource usage */
struct rusage t;
double procTime;
/* (1) Get the rusage data structure at this moment (man getrusage) */
getrusage(0,&t);
/* (2) What is the elapsed time ? - CPU time = User time + System time */
/* (2a) Get the seconds */
procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec;
/* (2b) More precisely! Get the microseconds part ! */
return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
#endif /* _WIN32 */
}
void* opj_malloc( size_t size ) {
void *memblock = malloc(size);
if(memblock) {
memset(memblock, 0, size);
}
return memblock;
}
void* opj_realloc( void *memblock, size_t size ) {
return realloc(memblock, size);
}
void opj_free( void *memblock ) {
free(memblock);
}

150
src/lib/openjp3d/jp3d_lib.h Executable file → Normal file
View File

@ -1,75 +1,75 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __J3D_LIB_H
#define __J3D_LIB_H
/**
@file jp3d_lib.h
@brief Internal functions
The functions in JP3D_LIB.C are internal utilities mainly used for memory management.
*/
/** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Difference in successive opj_clock() calls tells you the elapsed time
@return Returns time in seconds
*/
double opj_clock(void);
/**
Allocate a memory block with elements initialized to 0
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
void* opj_malloc( size_t size );
/**
Reallocate memory blocks.
@param memblock Pointer to previously allocated memory block
@param size New size in bytes
@return Returns a void pointer to the reallocated (and possibly moved) memory block
*/
void* opj_realloc( void *memblock, size_t size );
/**
Deallocates or frees a memory block.
@param memblock Previously allocated memory block to be freed
*/
void opj_free( void *memblock );
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __J3D_LIB_H */
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __J3D_LIB_H
#define __J3D_LIB_H
/**
@file jp3d_lib.h
@brief Internal functions
The functions in JP3D_LIB.C are internal utilities mainly used for memory management.
*/
/** @defgroup MISC MISC - Miscellaneous internal functions */
/*@{*/
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Difference in successive opj_clock() calls tells you the elapsed time
@return Returns time in seconds
*/
double opj_clock(void);
/**
Allocate a memory block with elements initialized to 0
@param size Bytes to allocate
@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available
*/
void* opj_malloc( size_t size );
/**
Reallocate memory blocks.
@param memblock Pointer to previously allocated memory block
@param size New size in bytes
@return Returns a void pointer to the reallocated (and possibly moved) memory block
*/
void* opj_realloc( void *memblock, size_t size );
/**
Deallocates or frees a memory block.
@param memblock Previously allocated memory block to be freed
*/
void opj_free( void *memblock );
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __J3D_LIB_H */

262
src/lib/openjp3d/mct.c Executable file → Normal file
View File

@ -1,131 +1,131 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* <summary> */
/* This table contains the norms of the basis function of the reversible MCT. */
/* </summary> */
static const double mct_norms[3] = { 1.732, .8292, .8292 };
/* <summary> */
/* This table contains the norms of the basis function of the irreversible MCT. */
/* </summary> */
static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
/* <summary> */
/* Foward reversible MCT. */
/* </summary> */
void mct_encode(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int r, g, b, y, u, v;
r = c0[i];
g = c1[i];
b = c2[i];
y = (r + (g << 1) + b) >> 2;
u = b - g;
v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
/* <summary> */
/* Inverse reversible MCT. */
/* </summary> */
void mct_decode(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int y, u, v, r, g, b;
y = c0[i];
u = c1[i];
v = c2[i];
g = y - ((u + v) >> 2);
r = v + g;
b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
double mct_getnorm(int compno) {
return mct_norms[compno];
}
/* <summary> */
/* Foward irreversible MCT. */
/* </summary> */
void mct_encode_real(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int r, g, b, y, u, v;
r = c0[i];
g = c1[i];
b = c2[i];
y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
/* <summary> */
/* Inverse irreversible MCT. */
/* </summary> */
void mct_decode_real(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int y, u, v, r, g, b;
y = c0[i];
u = c1[i];
v = c2[i];
r = y + fix_mul(v, 11485);
g = y - fix_mul(u, 2819) - fix_mul(v, 5850);
b = y + fix_mul(u, 14516);
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
double mct_getnorm_real(int compno) {
return mct_norms_real[compno];
}
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/* <summary> */
/* This table contains the norms of the basis function of the reversible MCT. */
/* </summary> */
static const double mct_norms[3] = { 1.732, .8292, .8292 };
/* <summary> */
/* This table contains the norms of the basis function of the irreversible MCT. */
/* </summary> */
static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
/* <summary> */
/* Foward reversible MCT. */
/* </summary> */
void mct_encode(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int r, g, b, y, u, v;
r = c0[i];
g = c1[i];
b = c2[i];
y = (r + (g << 1) + b) >> 2;
u = b - g;
v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
/* <summary> */
/* Inverse reversible MCT. */
/* </summary> */
void mct_decode(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int y, u, v, r, g, b;
y = c0[i];
u = c1[i];
v = c2[i];
g = y - ((u + v) >> 2);
r = v + g;
b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
double mct_getnorm(int compno) {
return mct_norms[compno];
}
/* <summary> */
/* Foward irreversible MCT. */
/* </summary> */
void mct_encode_real(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int r, g, b, y, u, v;
r = c0[i];
g = c1[i];
b = c2[i];
y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
c0[i] = y;
c1[i] = u;
c2[i] = v;
}
}
/* <summary> */
/* Inverse irreversible MCT. */
/* </summary> */
void mct_decode_real(int *c0, int *c1, int *c2, int n) {
int i;
for (i = 0; i < n; i++) {
int y, u, v, r, g, b;
y = c0[i];
u = c1[i];
v = c2[i];
r = y + fix_mul(v, 11485);
g = y - fix_mul(u, 2819) - fix_mul(v, 5850);
b = y + fix_mul(u, 14516);
c0[i] = r;
c1[i] = g;
c2[i] = b;
}
}
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
double mct_getnorm_real(int compno) {
return mct_norms_real[compno];
}

194
src/lib/openjp3d/mct.h Executable file → Normal file
View File

@ -1,97 +1,97 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MCT_H
#define __MCT_H
/**
@file mct.h
@brief Implementation of a multi-component transforms (MCT)
The functions in MCT.C have for goal to realize reversible and irreversible multicomponent
transform. The functions in MCT.C are used by some function in TCD.C.
*/
/** @defgroup MCT MCT - Implementation of a multi-component transform */
/*@{*/
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Apply a reversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode(int *c0, int *c1, int *c2, int n);
/**
Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode(int *c0, int *c1, int *c2, int n);
/**
Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm(int compno);
/**
Apply an irreversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode_real(int *c0, int *c1, int *c2, int n);
/**
Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode_real(int *c0, int *c1, int *c2, int n);
/**
Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm_real(int compno);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __MCT_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MCT_H
#define __MCT_H
/**
@file mct.h
@brief Implementation of a multi-component transforms (MCT)
The functions in MCT.C have for goal to realize reversible and irreversible multicomponent
transform. The functions in MCT.C are used by some function in TCD.C.
*/
/** @defgroup MCT MCT - Implementation of a multi-component transform */
/*@{*/
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Apply a reversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode(int *c0, int *c1, int *c2, int n);
/**
Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode(int *c0, int *c1, int *c2, int n);
/**
Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm(int compno);
/**
Apply an irreversible multi-component transform to an image
@param c0 Samples for red component
@param c1 Samples for green component
@param c2 Samples blue component
@param n Number of samples for each component
*/
void mct_encode_real(int *c0, int *c1, int *c2, int n);
/**
Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component
@param c1 Samples for red chrominance component
@param c2 Samples for blue chrominance component
@param n Number of samples for each component
*/
void mct_decode_real(int *c0, int *c1, int *c2, int n);
/**
Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm_real(int compno);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __MCT_H */

1096
src/lib/openjp3d/mqc.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

402
src/lib/openjp3d/mqc.h Executable file → Normal file
View File

@ -1,201 +1,201 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MQC_H
#define __MQC_H
/**
@file mqc.h
@brief Implementation of an MQ-Coder (MQC)
The functions in MQC.C have for goal to realize the MQ-coder operations. The functions
in MQC.C are used by some function in T1.C.
*/
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
/*@{*/
/**
This struct defines the state of a context.
*/
typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
unsigned int qeval;
/** the Most Probable Symbol (0 or 1) */
int mps;
/** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps;
} opj_mqc_state_t;
#define MQC_NUMCTXS 32
/**
MQ coder
*/
typedef struct opj_mqc {
unsigned int c;
unsigned int a;
unsigned int ct;
unsigned char *bp;
unsigned char *start;
unsigned char *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
} opj_mqc_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise
*/
opj_mqc_t* mqc_create(void);
/**
Destroy a previously created MQC handle
@param mqc MQC handle to destroy
*/
void mqc_destroy(opj_mqc_t *mqc);
/**
Return the number of bytes written/read since initialisation
@param mqc MQC handle
@return Returns the number of bytes already encoded
*/
int mqc_numbytes(opj_mqc_t *mqc);
/**
Reset the states of all the context of the coder/decoder
(each context is set to a state where 0 and 1 are more or less equiprobable)
@param mqc MQC handle
*/
void mqc_resetstates(opj_mqc_t *mqc);
/**
Set the state of a particular context
@param mqc MQC handle
@param ctxno Number that identifies the context
@param msb The MSB of the new state of the context
@param prob Number that identifies the probability of the symbols for the new state of the context
*/
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
/**
Initialize the encoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer where the bytes will be written
*/
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
/**
Set the current context used for coding/decoding
@param mqc MQC handle
@param ctxno Number that identifies the context
*/
void mqc_setcurctx(opj_mqc_t *mqc, int ctxno);
/**
Encode a symbol using the MQ-coder
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_encode(opj_mqc_t *mqc, int d);
/**
Flush the encoder, so that all remaining data is written
@param mqc MQC handle
*/
void mqc_flush(opj_mqc_t *mqc);
/**
BYPASS mode switch, initialization operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
*/
void mqc_bypass_init_enc(opj_mqc_t *mqc);
/**
BYPASS mode switch, coding operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_bypass_enc(opj_mqc_t *mqc, int d);
/**
BYPASS mode switch, flush operation
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_bypass_flush_enc(opj_mqc_t *mqc);
/**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc(opj_mqc_t *mqc);
/**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc_3(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL)
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_restart_enc(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL) reinitialisation
@param mqc MQC handle
*/
void mqc_restart_init_enc(opj_mqc_t *mqc);
/**
ERTERM mode switch (PTERM)
@param mqc MQC handle
*/
void mqc_erterm_enc(opj_mqc_t *mqc);
/**
SEGMARK mode switch (SEGSYM)
@param mqc MQC handle
*/
void mqc_segmark_enc(opj_mqc_t *mqc);
/**
Initialize the decoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
/**
Decode a symbol
@param mqc MQC handle
@return Returns the decoded symbol (0 or 1)
*/
int mqc_decode(opj_mqc_t *mqc);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __MQC_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __MQC_H
#define __MQC_H
/**
@file mqc.h
@brief Implementation of an MQ-Coder (MQC)
The functions in MQC.C have for goal to realize the MQ-coder operations. The functions
in MQC.C are used by some function in T1.C.
*/
/** @defgroup MQC MQC - Implementation of an MQ-Coder */
/*@{*/
/**
This struct defines the state of a context.
*/
typedef struct opj_mqc_state {
/** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */
unsigned int qeval;
/** the Most Probable Symbol (0 or 1) */
int mps;
/** next state if the next encoded symbol is the MPS */
struct opj_mqc_state *nmps;
/** next state if the next encoded symbol is the LPS */
struct opj_mqc_state *nlps;
} opj_mqc_state_t;
#define MQC_NUMCTXS 32
/**
MQ coder
*/
typedef struct opj_mqc {
unsigned int c;
unsigned int a;
unsigned int ct;
unsigned char *bp;
unsigned char *start;
unsigned char *end;
opj_mqc_state_t *ctxs[MQC_NUMCTXS];
opj_mqc_state_t **curctx;
} opj_mqc_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new MQC handle
@return Returns a new MQC handle if successful, returns NULL otherwise
*/
opj_mqc_t* mqc_create(void);
/**
Destroy a previously created MQC handle
@param mqc MQC handle to destroy
*/
void mqc_destroy(opj_mqc_t *mqc);
/**
Return the number of bytes written/read since initialisation
@param mqc MQC handle
@return Returns the number of bytes already encoded
*/
int mqc_numbytes(opj_mqc_t *mqc);
/**
Reset the states of all the context of the coder/decoder
(each context is set to a state where 0 and 1 are more or less equiprobable)
@param mqc MQC handle
*/
void mqc_resetstates(opj_mqc_t *mqc);
/**
Set the state of a particular context
@param mqc MQC handle
@param ctxno Number that identifies the context
@param msb The MSB of the new state of the context
@param prob Number that identifies the probability of the symbols for the new state of the context
*/
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob);
/**
Initialize the encoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer where the bytes will be written
*/
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp);
/**
Set the current context used for coding/decoding
@param mqc MQC handle
@param ctxno Number that identifies the context
*/
void mqc_setcurctx(opj_mqc_t *mqc, int ctxno);
/**
Encode a symbol using the MQ-coder
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_encode(opj_mqc_t *mqc, int d);
/**
Flush the encoder, so that all remaining data is written
@param mqc MQC handle
*/
void mqc_flush(opj_mqc_t *mqc);
/**
BYPASS mode switch, initialization operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
*/
void mqc_bypass_init_enc(opj_mqc_t *mqc);
/**
BYPASS mode switch, coding operation.
JPEG 2000 p 505.
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@param d The symbol to be encoded (0 or 1)
*/
void mqc_bypass_enc(opj_mqc_t *mqc, int d);
/**
BYPASS mode switch, flush operation
<h2>Not fully implemented and tested !!</h2>
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_bypass_flush_enc(opj_mqc_t *mqc);
/**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc(opj_mqc_t *mqc);
/**
RESET mode switch
@param mqc MQC handle
*/
void mqc_reset_enc_3(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL)
@param mqc MQC handle
@return Returns 1 (always)
*/
int mqc_restart_enc(opj_mqc_t *mqc);
/**
RESTART mode switch (TERMALL) reinitialisation
@param mqc MQC handle
*/
void mqc_restart_init_enc(opj_mqc_t *mqc);
/**
ERTERM mode switch (PTERM)
@param mqc MQC handle
*/
void mqc_erterm_enc(opj_mqc_t *mqc);
/**
SEGMARK mode switch (SEGSYM)
@param mqc MQC handle
*/
void mqc_segmark_enc(opj_mqc_t *mqc);
/**
Initialize the decoder
@param mqc MQC handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len);
/**
Decode a symbol
@param mqc MQC handle
@return Returns the decoded symbol (0 or 1)
*/
int mqc_decode(opj_mqc_t *mqc);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __MQC_H */

416
src/lib/openjp3d/openjp3d.c Executable file → Normal file
View File

@ -1,208 +1,208 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#include <windows.h>
#endif /* _WIN32 */
#include "opj_includes.h"
#include "openjp3d.h"
#define JP3D_VERSION "1.3.0"
/* ---------------------------------------------------------------------- */
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH :
break;
case DLL_PROCESS_DETACH :
break;
case DLL_THREAD_ATTACH :
case DLL_THREAD_DETACH :
break;
}
return TRUE;
}
#endif /* OPJ_STATIC */
#endif /* _WIN32 */
/* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version() {
return JP3D_VERSION;
}
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
if(!dinfo) return NULL;
dinfo->is_decompressor = true;
switch(format) {
case CODEC_J3D:
case CODEC_J2K:
/* get a J3D decoder handle */
dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo);
if(!dinfo->j3d_handle) {
opj_free(dinfo);
return NULL;
}
break;
default:
opj_free(dinfo);
return NULL;
}
dinfo->codec_format = format;
return dinfo;
}
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
if(dinfo) {
/* destroy the codec */
if(dinfo->codec_format != CODEC_UNKNOWN) {
j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle);
}
/* destroy the decompressor */
opj_free(dinfo);
}
}
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */
parameters->cp_layer = 0;
parameters->cp_reduce[0] = 0;
parameters->cp_reduce[1] = 0;
parameters->cp_reduce[2] = 0;
parameters->bigendian = 0;
parameters->decod_format = -1;
parameters->cod_format = -1;
}
}
void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
if(dinfo && parameters) {
if (dinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);
}
}
}
opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
if(dinfo && cio) {
if (dinfo->codec_format != CODEC_UNKNOWN) {
return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);
}
}
return NULL;
}
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
if(!cinfo) return NULL;
cinfo->is_decompressor = false;
switch(format) {
case CODEC_J3D:
case CODEC_J2K:
/* get a J3D coder handle */
cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo);
if(!cinfo->j3d_handle) {
opj_free(cinfo);
return NULL;
}
break;
default:
opj_free(cinfo);
return NULL;
}
cinfo->codec_format = format;
return cinfo;
}
void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
if(cinfo) {
/* destroy the codec */
if (cinfo->codec_format != CODEC_UNKNOWN) {
j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle);
}
/* destroy the decompressor */
opj_free(cinfo);
}
}
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
parameters->numresolution[0] = 3;
parameters->numresolution[1] = 3;
parameters->numresolution[2] = 1;
parameters->cblock_init[0] = 64;
parameters->cblock_init[1] = 64;
parameters->cblock_init[2] = 64;
parameters->prog_order = LRCP;
parameters->roi_compno = -1; /* no ROI */
parameters->atk_wt[0] = 1; /* 5-3 WT */
parameters->atk_wt[1] = 1; /* 5-3 WT */
parameters->atk_wt[2] = 1; /* 5-3 WT */
parameters->irreversible = 0;
parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
parameters->subsampling_dz = 1;
parameters->decod_format = -1;
parameters->cod_format = -1;
parameters->encoding_format = ENCOD_2EB;
parameters->transform_format = TRF_2D_DWT;
}
}
void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) {
if(cinfo && parameters && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);
}
}
}
bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) {
if(cinfo && cio && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) {
return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);
}
}
return false;
}
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef _WIN32
#include <windows.h>
#endif /* _WIN32 */
#include "opj_includes.h"
#include "openjp3d.h"
#define JP3D_VERSION "1.3.0"
/* ---------------------------------------------------------------------- */
#ifdef _WIN32
#ifndef OPJ_STATIC
BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH :
break;
case DLL_PROCESS_DETACH :
break;
case DLL_THREAD_ATTACH :
case DLL_THREAD_DETACH :
break;
}
return TRUE;
}
#endif /* OPJ_STATIC */
#endif /* _WIN32 */
/* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version() {
return JP3D_VERSION;
}
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
if(!dinfo) return NULL;
dinfo->is_decompressor = true;
switch(format) {
case CODEC_J3D:
case CODEC_J2K:
/* get a J3D decoder handle */
dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo);
if(!dinfo->j3d_handle) {
opj_free(dinfo);
return NULL;
}
break;
default:
opj_free(dinfo);
return NULL;
}
dinfo->codec_format = format;
return dinfo;
}
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
if(dinfo) {
/* destroy the codec */
if(dinfo->codec_format != CODEC_UNKNOWN) {
j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle);
}
/* destroy the decompressor */
opj_free(dinfo);
}
}
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */
parameters->cp_layer = 0;
parameters->cp_reduce[0] = 0;
parameters->cp_reduce[1] = 0;
parameters->cp_reduce[2] = 0;
parameters->bigendian = 0;
parameters->decod_format = -1;
parameters->cod_format = -1;
}
}
void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) {
if(dinfo && parameters) {
if (dinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);
}
}
}
opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
if(dinfo && cio) {
if (dinfo->codec_format != CODEC_UNKNOWN) {
return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);
}
}
return NULL;
}
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
if(!cinfo) return NULL;
cinfo->is_decompressor = false;
switch(format) {
case CODEC_J3D:
case CODEC_J2K:
/* get a J3D coder handle */
cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo);
if(!cinfo->j3d_handle) {
opj_free(cinfo);
return NULL;
}
break;
default:
opj_free(cinfo);
return NULL;
}
cinfo->codec_format = format;
return cinfo;
}
void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
if(cinfo) {
/* destroy the codec */
if (cinfo->codec_format != CODEC_UNKNOWN) {
j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle);
}
/* destroy the decompressor */
opj_free(cinfo);
}
}
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) {
if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */
parameters->numresolution[0] = 3;
parameters->numresolution[1] = 3;
parameters->numresolution[2] = 1;
parameters->cblock_init[0] = 64;
parameters->cblock_init[1] = 64;
parameters->cblock_init[2] = 64;
parameters->prog_order = LRCP;
parameters->roi_compno = -1; /* no ROI */
parameters->atk_wt[0] = 1; /* 5-3 WT */
parameters->atk_wt[1] = 1; /* 5-3 WT */
parameters->atk_wt[2] = 1; /* 5-3 WT */
parameters->irreversible = 0;
parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
parameters->subsampling_dz = 1;
parameters->decod_format = -1;
parameters->cod_format = -1;
parameters->encoding_format = ENCOD_2EB;
parameters->transform_format = TRF_2D_DWT;
}
}
void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) {
if(cinfo && parameters && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);
}
}
}
bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) {
if(cinfo && cio && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) {
return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);
}
}
return false;
}

1442
src/lib/openjp3d/openjp3d.h Executable file → Normal file

File diff suppressed because it is too large Load Diff

0
src/lib/openjp3d/opj_includes.h Executable file → Normal file
View File

1263
src/lib/openjp3d/pi.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

290
src/lib/openjp3d/pi.h Executable file → Normal file
View File

@ -1,145 +1,145 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PI_H
#define __PI_H
/**
@file pi.h
@brief Implementation of a packet iterator (PI)
The functions in PI.C have for goal to realize a packet iterator that permits to get the next
packet following the progression order and change of it. The functions in PI.C are used
by some function in T2.C.
*/
/** @defgroup PI PI - Implementation of a packet iterator */
/*@{*/
/**
Packet iterator : resolution level information
*/
typedef struct opj_pi_resolution {
/** Size of precints in horizontal axis */
int pdx;
/** Size of precints in vertical axis */
int pdy;
/** Size of precints in axial axis */
int pdz;
/** Number of precints in each axis */
int prctno[3];
} opj_pi_resolution_t;
/**
Packet iterator : component information
*/
typedef struct opj_pi_comp {
/** Size in horizontal axis */
int dx;
/** Size in vertical axis */
int dy;
/** Size in axial axis */
int dz;
/** Number of resolution levels */
int numresolution[3];
/** Packet iterator : resolution level information */
opj_pi_resolution_t *resolutions;
} opj_pi_comp_t;
/**
Packet iterator
*/
typedef struct opj_pi_iterator {
/** precise if the packet has been already used (usefull for progression order change) */
short int *include;
/** layer step used to localize the packet in the include vector */
int step_l;
/** resolution step used to localize the packet in the include vector */
int step_r;
/** component step used to localize the packet in the include vector */
int step_c;
/** precinct step used to localize the packet in the include vector */
int step_p;
/** component that identify the packet */
int compno;
/** resolution that identify the packet */
int resno;
/** precinct that identify the packet */
int precno;
/** layer that identify the packet */
int layno;
/** 0 if the first packet */
int first;
/** progression order change information */
opj_poc_t poc;
/** Packet iterator : component information */
opj_pi_comp_t *comps;
int numcomps;
int tx0, ty0, tz0;
int tx1, ty1, tz1;
int x, y, z;
int dx, dy, dz;
} opj_pi_iterator_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a packet iterator
@param volume Raw volume for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_create(opj_volume_t * volume, opj_cp_t * cp, int tileno);
/**
Destroy a packet iterator
@param pi Previously created packet iterator
@param cp Coding parameters
@param tileno Number that identifies the tile for which the packets were listed
@see pi_create
*/
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno);
/**
Modify the packet iterator to point to the next packet
@param pi Packet iterator to modify
@return Returns false if pi pointed to the last packet or else returns true
*/
bool pi_next(opj_pi_iterator_t * pi);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __PI_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PI_H
#define __PI_H
/**
@file pi.h
@brief Implementation of a packet iterator (PI)
The functions in PI.C have for goal to realize a packet iterator that permits to get the next
packet following the progression order and change of it. The functions in PI.C are used
by some function in T2.C.
*/
/** @defgroup PI PI - Implementation of a packet iterator */
/*@{*/
/**
Packet iterator : resolution level information
*/
typedef struct opj_pi_resolution {
/** Size of precints in horizontal axis */
int pdx;
/** Size of precints in vertical axis */
int pdy;
/** Size of precints in axial axis */
int pdz;
/** Number of precints in each axis */
int prctno[3];
} opj_pi_resolution_t;
/**
Packet iterator : component information
*/
typedef struct opj_pi_comp {
/** Size in horizontal axis */
int dx;
/** Size in vertical axis */
int dy;
/** Size in axial axis */
int dz;
/** Number of resolution levels */
int numresolution[3];
/** Packet iterator : resolution level information */
opj_pi_resolution_t *resolutions;
} opj_pi_comp_t;
/**
Packet iterator
*/
typedef struct opj_pi_iterator {
/** precise if the packet has been already used (usefull for progression order change) */
short int *include;
/** layer step used to localize the packet in the include vector */
int step_l;
/** resolution step used to localize the packet in the include vector */
int step_r;
/** component step used to localize the packet in the include vector */
int step_c;
/** precinct step used to localize the packet in the include vector */
int step_p;
/** component that identify the packet */
int compno;
/** resolution that identify the packet */
int resno;
/** precinct that identify the packet */
int precno;
/** layer that identify the packet */
int layno;
/** 0 if the first packet */
int first;
/** progression order change information */
opj_poc_t poc;
/** Packet iterator : component information */
opj_pi_comp_t *comps;
int numcomps;
int tx0, ty0, tz0;
int tx1, ty1, tz1;
int x, y, z;
int dx, dy, dz;
} opj_pi_iterator_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a packet iterator
@param volume Raw volume for which the packets will be listed
@param cp Coding parameters
@param tileno Number that identifies the tile for which to list the packets
@return Returns a packet iterator that points to the first packet of the tile
@see pi_destroy
*/
opj_pi_iterator_t *pi_create(opj_volume_t * volume, opj_cp_t * cp, int tileno);
/**
Destroy a packet iterator
@param pi Previously created packet iterator
@param cp Coding parameters
@param tileno Number that identifies the tile for which the packets were listed
@see pi_create
*/
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno);
/**
Modify the packet iterator to point to the next packet
@param pi Packet iterator to modify
@return Returns false if pi pointed to the last packet or else returns true
*/
bool pi_next(opj_pi_iterator_t * pi);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __PI_H */

172
src/lib/openjp3d/raw.c Executable file → Normal file
View File

@ -1,86 +1,86 @@
/*
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/*
==========================================================
local functions
==========================================================
*/
/*
==========================================================
RAW encoding interface
==========================================================
*/
opj_raw_t* raw_create() {
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void raw_destroy(opj_raw_t *raw) {
if(raw) {
opj_free(raw);
}
}
int raw_numbytes(opj_raw_t *raw) {
return raw->bp - raw->start;
}
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
raw->c = 0;
raw->ct = 0;
}
int raw_decode(opj_raw_t *raw) {
int d;
if (raw->ct == 0) {
raw->ct = 8;
if (raw->len == raw->lenmax) {
raw->c = 0xff;
} else {
if (raw->c == 0xff) {
raw->ct = 7;
}
raw->c = *(raw->start + raw->len);
raw->len++;
}
}
raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d;
}
/*
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/*
==========================================================
local functions
==========================================================
*/
/*
==========================================================
RAW encoding interface
==========================================================
*/
opj_raw_t* raw_create() {
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw;
}
void raw_destroy(opj_raw_t *raw) {
if(raw) {
opj_free(raw);
}
}
int raw_numbytes(opj_raw_t *raw) {
return raw->bp - raw->start;
}
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
raw->start = bp;
raw->lenmax = len;
raw->len = 0;
raw->c = 0;
raw->ct = 0;
}
int raw_decode(opj_raw_t *raw) {
int d;
if (raw->ct == 0) {
raw->ct = 8;
if (raw->len == raw->lenmax) {
raw->c = 0xff;
} else {
if (raw->c == 0xff) {
raw->ct = 7;
}
raw->c = *(raw->start + raw->len);
raw->len++;
}
}
raw->ct--;
d = (raw->c >> raw->ct) & 0x01;
return d;
}

198
src/lib/openjp3d/raw.h Executable file → Normal file
View File

@ -1,99 +1,99 @@
/*
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __RAW_H
#define __RAW_H
/**
@file raw.h
@brief Implementation of operations for raw encoding (RAW)
The functions in RAW.C have for goal to realize the operation of raw encoding linked
with the corresponding mode switch.
*/
/** @defgroup RAW RAW - Implementation of operations for raw encoding */
/*@{*/
/**
RAW encoding operations
*/
typedef struct opj_raw {
/** Temporary buffer where bits are coded or decoded */
unsigned char c;
/** Number of bits already read or free to write */
unsigned int ct;
/** Maximum length to decode */
unsigned int lenmax;
/** Length decoded */
unsigned int len;
/** Pointer to the current position in the buffer */
unsigned char *bp;
/** Pointer to the start of the buffer */
unsigned char *start;
/** Pointer to the end of the buffer */
unsigned char *end;
} opj_raw_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise
*/
opj_raw_t* raw_create(void);
/**
Destroy a previously created RAW handle
@param raw RAW handle to destroy
*/
void raw_destroy(opj_raw_t *raw);
/**
Return the number of bytes written/read since initialisation
@param raw RAW handle to destroy
@return Returns the number of bytes already encoded
*/
int raw_numbytes(opj_raw_t *raw);
/**
Initialize the decoder
@param raw RAW handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len);
/**
Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN
@param raw RAW handle
@return Returns the decoded symbol (0 or 1)
*/
int raw_decode(opj_raw_t *raw);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __RAW_H */
/*
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __RAW_H
#define __RAW_H
/**
@file raw.h
@brief Implementation of operations for raw encoding (RAW)
The functions in RAW.C have for goal to realize the operation of raw encoding linked
with the corresponding mode switch.
*/
/** @defgroup RAW RAW - Implementation of operations for raw encoding */
/*@{*/
/**
RAW encoding operations
*/
typedef struct opj_raw {
/** Temporary buffer where bits are coded or decoded */
unsigned char c;
/** Number of bits already read or free to write */
unsigned int ct;
/** Maximum length to decode */
unsigned int lenmax;
/** Length decoded */
unsigned int len;
/** Pointer to the current position in the buffer */
unsigned char *bp;
/** Pointer to the start of the buffer */
unsigned char *start;
/** Pointer to the end of the buffer */
unsigned char *end;
} opj_raw_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new RAW handle
@return Returns a new RAW handle if successful, returns NULL otherwise
*/
opj_raw_t* raw_create(void);
/**
Destroy a previously created RAW handle
@param raw RAW handle to destroy
*/
void raw_destroy(opj_raw_t *raw);
/**
Return the number of bytes written/read since initialisation
@param raw RAW handle to destroy
@return Returns the number of bytes already encoded
*/
int raw_numbytes(opj_raw_t *raw);
/**
Initialize the decoder
@param raw RAW handle
@param bp Pointer to the start of the buffer from which the bytes will be read
@param len Length of the input buffer
*/
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len);
/**
Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN
@param raw RAW handle
@return Returns the decoded symbol (0 or 1)
*/
int raw_decode(opj_raw_t *raw);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __RAW_H */

2362
src/lib/openjp3d/t1.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

346
src/lib/openjp3d/t1.h Executable file → Normal file
View File

@ -1,173 +1,173 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T1_H
#define __T1_H
/**
@file t1.h
@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
The functions in T1.C have for goal to realize the tier-1 coding operation. The functions
in T1.C are used by some function in TCD.C.
*/
/** @defgroup T1 T1 - Implementation of the tier-1 coding */
/*@{*/
/* ----------------------------------------------------------------------- */
#define T1_NMSEDEC_BITS 7
#define T1_MAXCBLKW 256 /*< Maximum size of code-block (width) */
#define T1_MAXCBLKH 256 /*< Maximum size of code-block (heigth) */
#define T1_MAXCBLKD 256 /*< Maximum size of code-block (depth) */
#define T1_MINCBLKW 4 /*< Minimum size of code-block (width) */
#define T1_MINCBLKH 4 /*< Minimum size of code-block (heigth) */
#define T1_MINCBLKD 4 /*< Minimum size of code-block (depth) */
#define T1_MAXWHD 18
#define T1_CBLKW 256
#define T1_CBLKH 256
#define T1_CBLKD 256
#define T1_SIG_NE 0x0001 /*< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002 /*< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004 /*< Context orientation : South-West direction */
#define T1_SIG_NW 0x0008 /*< Context orientation : North-West direction */
#define T1_SIG_N 0x0010 /*< Context orientation : North direction */
#define T1_SIG_E 0x0020 /*< Context orientation : East direction */
#define T1_SIG_S 0x0040 /*< Context orientation : South direction */
#define T1_SIG_W 0x0080 /*< Context orientation : West direction */
#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW)
#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W)
#define T1_SGN_N 0x0100
#define T1_SGN_E 0x0200
#define T1_SGN_S 0x0400
#define T1_SGN_W 0x0800
#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W)
#define T1_SIG 0x1000
#define T1_REFINE 0x2000
#define T1_VISIT 0x4000
#define T1_NUMCTXS_AGG 1
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_MAG 3
#define T1_NUMCTXS_SC 5
#define T1_NUMCTXS_UNI 1
#define T1_CTXNO_AGG 0
#define T1_CTXNO_ZC (T1_CTXNO_AGG+T1_NUMCTXS_AGG)
#define T1_CTXNO_MAG (T1_CTXNO_ZC+T1_NUMCTXS_ZC)
#define T1_CTXNO_SC (T1_CTXNO_MAG+T1_NUMCTXS_MAG)
#define T1_CTXNO_UNI (T1_CTXNO_SC+T1_NUMCTXS_SC)
#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI)
#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1)
#define T1_TYPE_MQ 0 /*< Normal coding using entropy coder */
#define T1_TYPE_RAW 1 /*< No encoding the information is store under raw format in codestream (mode switch RAW)*/
/* ----------------------------------------------------------------------- */
/**
Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1 {
/** codec context */
opj_common_ptr cinfo;
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
/** LUTs for context-based coding */
int lut_ctxno_zc[1024];
int lut_ctxno_sc[256];
int lut_ctxno_mag[4096];
int lut_spb[256];
/** LUTs for decoding normalised MSE */
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
/** Codeblock data */
int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];/*int ***data;*/
/** Context information for each voxel in codeblock */
int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];/*int ***flags;*/
} opj_t1_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new T1 handle
and initialize the look-up tables of the Tier-1 coder/decoder
@return Returns a new T1 handle if successful, returns NULL otherwise
@see t1_init_luts
*/
opj_t1_t* t1_create(opj_common_ptr cinfo);
/**
Destroy a previously created T1 handle
@param t1 T1 handle to destroy
*/
void t1_destroy(opj_t1_t *t1);
/**
Encode the code-blocks of a tile
@param t1 T1 handle
@param tile The tile to encode
@param tcp Tile coding parameters
*/
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Decode the code-blocks of a tile
@param t1 T1 handle
@param tile The tile to decode
@param tcp Tile coding parameters
*/
void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Get weigths of MSE decoding
@param nmsedec The normalized MSE reduction
@param compno
@param level
@param orient
@param bpno
@param stepsize
@param numcomps
@param dwtid
returns MSE associated to decoding pass
*/
double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T1_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T1_H
#define __T1_H
/**
@file t1.h
@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
The functions in T1.C have for goal to realize the tier-1 coding operation. The functions
in T1.C are used by some function in TCD.C.
*/
/** @defgroup T1 T1 - Implementation of the tier-1 coding */
/*@{*/
/* ----------------------------------------------------------------------- */
#define T1_NMSEDEC_BITS 7
#define T1_MAXCBLKW 256 /*< Maximum size of code-block (width) */
#define T1_MAXCBLKH 256 /*< Maximum size of code-block (heigth) */
#define T1_MAXCBLKD 256 /*< Maximum size of code-block (depth) */
#define T1_MINCBLKW 4 /*< Minimum size of code-block (width) */
#define T1_MINCBLKH 4 /*< Minimum size of code-block (heigth) */
#define T1_MINCBLKD 4 /*< Minimum size of code-block (depth) */
#define T1_MAXWHD 18
#define T1_CBLKW 256
#define T1_CBLKH 256
#define T1_CBLKD 256
#define T1_SIG_NE 0x0001 /*< Context orientation : North-East direction */
#define T1_SIG_SE 0x0002 /*< Context orientation : South-East direction */
#define T1_SIG_SW 0x0004 /*< Context orientation : South-West direction */
#define T1_SIG_NW 0x0008 /*< Context orientation : North-West direction */
#define T1_SIG_N 0x0010 /*< Context orientation : North direction */
#define T1_SIG_E 0x0020 /*< Context orientation : East direction */
#define T1_SIG_S 0x0040 /*< Context orientation : South direction */
#define T1_SIG_W 0x0080 /*< Context orientation : West direction */
#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW)
#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W)
#define T1_SGN_N 0x0100
#define T1_SGN_E 0x0200
#define T1_SGN_S 0x0400
#define T1_SGN_W 0x0800
#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W)
#define T1_SIG 0x1000
#define T1_REFINE 0x2000
#define T1_VISIT 0x4000
#define T1_NUMCTXS_AGG 1
#define T1_NUMCTXS_ZC 9
#define T1_NUMCTXS_MAG 3
#define T1_NUMCTXS_SC 5
#define T1_NUMCTXS_UNI 1
#define T1_CTXNO_AGG 0
#define T1_CTXNO_ZC (T1_CTXNO_AGG+T1_NUMCTXS_AGG)
#define T1_CTXNO_MAG (T1_CTXNO_ZC+T1_NUMCTXS_ZC)
#define T1_CTXNO_SC (T1_CTXNO_MAG+T1_NUMCTXS_MAG)
#define T1_CTXNO_UNI (T1_CTXNO_SC+T1_NUMCTXS_SC)
#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI)
#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1)
#define T1_TYPE_MQ 0 /*< Normal coding using entropy coder */
#define T1_TYPE_RAW 1 /*< No encoding the information is store under raw format in codestream (mode switch RAW)*/
/* ----------------------------------------------------------------------- */
/**
Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1 {
/** codec context */
opj_common_ptr cinfo;
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
/** LUTs for context-based coding */
int lut_ctxno_zc[1024];
int lut_ctxno_sc[256];
int lut_ctxno_mag[4096];
int lut_spb[256];
/** LUTs for decoding normalised MSE */
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
/** Codeblock data */
int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];/*int ***data;*/
/** Context information for each voxel in codeblock */
int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];/*int ***flags;*/
} opj_t1_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new T1 handle
and initialize the look-up tables of the Tier-1 coder/decoder
@return Returns a new T1 handle if successful, returns NULL otherwise
@see t1_init_luts
*/
opj_t1_t* t1_create(opj_common_ptr cinfo);
/**
Destroy a previously created T1 handle
@param t1 T1 handle to destroy
*/
void t1_destroy(opj_t1_t *t1);
/**
Encode the code-blocks of a tile
@param t1 T1 handle
@param tile The tile to encode
@param tcp Tile coding parameters
*/
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Decode the code-blocks of a tile
@param t1 T1 handle
@param tile The tile to decode
@param tcp Tile coding parameters
*/
void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Get weigths of MSE decoding
@param nmsedec The normalized MSE reduction
@param compno
@param level
@param orient
@param bpno
@param stepsize
@param numcomps
@param dwtid
returns MSE associated to decoding pass
*/
double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T1_H */

2460
src/lib/openjp3d/t1_3d.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

346
src/lib/openjp3d/t1_3d.h Executable file → Normal file
View File

@ -1,173 +1,173 @@
/*
* Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T1_3D_H
#define __T1_3D_H
/**
@file t1_3d.h
@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
The functions in T1_3D.C have for goal to realize the tier-1 coding operation of 3D-EBCOT.
The functions in T1_3D.C are used by some function in TCD.C.
*/
/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */
/*@{*/
/* ----------------------------------------------------------------------- */
/* Neighbourhood of 3D EBCOT (Significance context)*/
#define T1_3D_SIG_NE 0x00000001 /*< Context orientation : North-East direction */
#define T1_3D_SIG_SE 0x00000002 /*< Context orientation : South-East direction */
#define T1_3D_SIG_SW 0x00000004 /*< Context orientation : South-West direction */
#define T1_3D_SIG_NW 0x00000008 /* Context orientation : North-West direction */
#define T1_3D_SIG_N 0x00000010 /*< Context orientation : North direction */
#define T1_3D_SIG_E 0x00000020 /*< Context orientation : East direction */
#define T1_3D_SIG_S 0x00000040 /*< Context orientation : South direction */
#define T1_3D_SIG_W 0x00000080 /*< Context orientation : West direction */
#define T1_3D_SIG_FC 0x00000100 /*< Context orientation : Forward Central direction */
#define T1_3D_SIG_BC 0x00000200 /*< Context orientation : Backward Central direction */
#define T1_3D_SIG_FNE 0x00000400 /*< Context orientation : Forward North-East direction */
#define T1_3D_SIG_FSE 0x00000800 /*< Context orientation : Forward South-East direction */
#define T1_3D_SIG_FSW 0x00001000 /*< Context orientation : Forward South-West direction */
#define T1_3D_SIG_FNW 0x00002000 /*< Context orientation : Forward North-West direction */
#define T1_3D_SIG_FN 0x00004000 /*< Context orientation : Forward North direction */
#define T1_3D_SIG_FE 0x00008000 /*< Context orientation : Forward East direction */
#define T1_3D_SIG_FS 0x00010000 /*< Context orientation : Forward South direction */
#define T1_3D_SIG_FW 0x00020000 /*< Context orientation : Forward West direction */
#define T1_3D_SIG_BNE 0x00040000 /*< Context orientation : Backward North-East direction */
#define T1_3D_SIG_BSE 0x00080000 /*< Context orientation : Backward South-East direction */
#define T1_3D_SIG_BSW 0x00100000 /*< Context orientation : Backward South-West direction */
#define T1_3D_SIG_BNW 0x00200000 /*< Context orientation : Backward North-West direction */
#define T1_3D_SIG_BN 0x00400000 /*< Context orientation : Backward North direction */
#define T1_3D_SIG_BE 0x00800000 /*< Context orientation : Backward East direction */
#define T1_3D_SIG_BS 0x01000000 /*< Context orientation : Backward South direction */
#define T1_3D_SIG_BW 0x02000000 /*< Context orientation : Backward West direction */
#define T1_3D_SIG_COTH (T1_3D_SIG_N|T1_3D_SIG_NE|T1_3D_SIG_E|T1_3D_SIG_SE|T1_3D_SIG_S|T1_3D_SIG_SW|T1_3D_SIG_W|T1_3D_SIG_NW)
#define T1_3D_SIG_BOTH (T1_3D_SIG_BN|T1_3D_SIG_BNE|T1_3D_SIG_BE|T1_3D_SIG_BSE|T1_3D_SIG_BS|T1_3D_SIG_BSW|T1_3D_SIG_BW|T1_3D_SIG_BNW|T1_3D_SIG_BC)
#define T1_3D_SIG_FOTH (T1_3D_SIG_FN|T1_3D_SIG_FNE|T1_3D_SIG_FE|T1_3D_SIG_FSE|T1_3D_SIG_FS|T1_3D_SIG_FSW|T1_3D_SIG_FW|T1_3D_SIG_FNW|T1_3D_SIG_FC)
#define T1_3D_SIG_OTH (T1_3D_SIG_FOTH|T1_3D_SIG_BOTH|T1_3D_SIG_COTH)
#define T1_3D_SIG_PRIM (T1_3D_SIG_N|T1_3D_SIG_E|T1_3D_SIG_S|T1_3D_SIG_W|T1_3D_SIG_FC|T1_3D_SIG_BC)
#define T1_3D_SGN_N 0x0400
#define T1_3D_SGN_E 0x0800
#define T1_3D_SGN_S 0x1000
#define T1_3D_SGN_W 0x2000
#define T1_3D_SGN_F 0x4000
#define T1_3D_SGN_B 0x8000
#define T1_3D_SGN (T1_3D_SGN_N|T1_3D_SGN_E|T1_3D_SGN_S|T1_3D_SGN_W|T1_3D_SGN_F|T1_3D_SGN_B)
#define T1_3D_SIG 0x0001 /*Significance state*/
#define T1_3D_REFINE 0x0002 /*Delayed significance*/
#define T1_3D_VISIT 0x0004 /*First-pass membership*/
#define T1_3D_NUMCTXS_AGG 1
#define T1_3D_NUMCTXS_ZC 16
#define T1_3D_NUMCTXS_MAG 3
#define T1_3D_NUMCTXS_SC 6
#define T1_3D_NUMCTXS_UNI 1
#define T1_3D_CTXNO_AGG 0
#define T1_3D_CTXNO_ZC (T1_3D_CTXNO_AGG+T1_3D_NUMCTXS_AGG) /*1*/
#define T1_3D_CTXNO_MAG (T1_3D_CTXNO_ZC+T1_3D_NUMCTXS_ZC) /*17*/
#define T1_3D_CTXNO_SC (T1_3D_CTXNO_MAG+T1_3D_NUMCTXS_MAG) /*20*/
#define T1_3D_CTXNO_UNI (T1_3D_CTXNO_SC+T1_3D_NUMCTXS_SC) /*26*/
#define T1_3D_NUMCTXS (T1_3D_CTXNO_UNI+T1_3D_NUMCTXS_UNI) /*27*/
/* ----------------------------------------------------------------------- */
/**
Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1_3d {
/** Codec context */
opj_common_ptr cinfo;
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
/** LUTs for decoding normalised MSE */
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
/** Codeblock data */
int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];
/** Context information for each voxel in codeblock */
unsigned int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
/** Voxel information (significance/visited/refined) */
int flagSVR[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
} opj_t1_3d_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new T1_3D handle
and initialize the look-up tables of the Tier-1 coder/decoder
@return Returns a new T1 handle if successful, returns NULL otherwise
@see t1_init_luts
*/
opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo);
/**
Destroy a previously created T1_3D handle
@param t1 T1_3D handle to destroy
*/
void t1_3d_destroy(opj_t1_3d_t *t1);
/**
Encode the code-blocks of a tile
@param t1 T1_3D handle
@param tile The tile to encode
@param tcp Tile coding parameters
*/
void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Decode the code-blocks of a tile
@param t1 T1_3D handle
@param tile The tile to decode
@param tcp Tile coding parameters
*/
void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Get weigths of MSE decoding
@param nmsedec The normalized MSE reduction
@param compno
@param level
@param orient
@param bpno
@param reversible
@param stepsize
@param numcomps
@param dwtid
returns MSE associated to decoding pass
double t1_3d_getwmsedec(int nmsedec, int compno, int levelxy, int levelz, int orient, int bpno, int reversible, double stepsize, int numcomps, int dwtid);
*/
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T1_H */
/*
* Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T1_3D_H
#define __T1_3D_H
/**
@file t1_3d.h
@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1)
The functions in T1_3D.C have for goal to realize the tier-1 coding operation of 3D-EBCOT.
The functions in T1_3D.C are used by some function in TCD.C.
*/
/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */
/*@{*/
/* ----------------------------------------------------------------------- */
/* Neighbourhood of 3D EBCOT (Significance context)*/
#define T1_3D_SIG_NE 0x00000001 /*< Context orientation : North-East direction */
#define T1_3D_SIG_SE 0x00000002 /*< Context orientation : South-East direction */
#define T1_3D_SIG_SW 0x00000004 /*< Context orientation : South-West direction */
#define T1_3D_SIG_NW 0x00000008 /* Context orientation : North-West direction */
#define T1_3D_SIG_N 0x00000010 /*< Context orientation : North direction */
#define T1_3D_SIG_E 0x00000020 /*< Context orientation : East direction */
#define T1_3D_SIG_S 0x00000040 /*< Context orientation : South direction */
#define T1_3D_SIG_W 0x00000080 /*< Context orientation : West direction */
#define T1_3D_SIG_FC 0x00000100 /*< Context orientation : Forward Central direction */
#define T1_3D_SIG_BC 0x00000200 /*< Context orientation : Backward Central direction */
#define T1_3D_SIG_FNE 0x00000400 /*< Context orientation : Forward North-East direction */
#define T1_3D_SIG_FSE 0x00000800 /*< Context orientation : Forward South-East direction */
#define T1_3D_SIG_FSW 0x00001000 /*< Context orientation : Forward South-West direction */
#define T1_3D_SIG_FNW 0x00002000 /*< Context orientation : Forward North-West direction */
#define T1_3D_SIG_FN 0x00004000 /*< Context orientation : Forward North direction */
#define T1_3D_SIG_FE 0x00008000 /*< Context orientation : Forward East direction */
#define T1_3D_SIG_FS 0x00010000 /*< Context orientation : Forward South direction */
#define T1_3D_SIG_FW 0x00020000 /*< Context orientation : Forward West direction */
#define T1_3D_SIG_BNE 0x00040000 /*< Context orientation : Backward North-East direction */
#define T1_3D_SIG_BSE 0x00080000 /*< Context orientation : Backward South-East direction */
#define T1_3D_SIG_BSW 0x00100000 /*< Context orientation : Backward South-West direction */
#define T1_3D_SIG_BNW 0x00200000 /*< Context orientation : Backward North-West direction */
#define T1_3D_SIG_BN 0x00400000 /*< Context orientation : Backward North direction */
#define T1_3D_SIG_BE 0x00800000 /*< Context orientation : Backward East direction */
#define T1_3D_SIG_BS 0x01000000 /*< Context orientation : Backward South direction */
#define T1_3D_SIG_BW 0x02000000 /*< Context orientation : Backward West direction */
#define T1_3D_SIG_COTH (T1_3D_SIG_N|T1_3D_SIG_NE|T1_3D_SIG_E|T1_3D_SIG_SE|T1_3D_SIG_S|T1_3D_SIG_SW|T1_3D_SIG_W|T1_3D_SIG_NW)
#define T1_3D_SIG_BOTH (T1_3D_SIG_BN|T1_3D_SIG_BNE|T1_3D_SIG_BE|T1_3D_SIG_BSE|T1_3D_SIG_BS|T1_3D_SIG_BSW|T1_3D_SIG_BW|T1_3D_SIG_BNW|T1_3D_SIG_BC)
#define T1_3D_SIG_FOTH (T1_3D_SIG_FN|T1_3D_SIG_FNE|T1_3D_SIG_FE|T1_3D_SIG_FSE|T1_3D_SIG_FS|T1_3D_SIG_FSW|T1_3D_SIG_FW|T1_3D_SIG_FNW|T1_3D_SIG_FC)
#define T1_3D_SIG_OTH (T1_3D_SIG_FOTH|T1_3D_SIG_BOTH|T1_3D_SIG_COTH)
#define T1_3D_SIG_PRIM (T1_3D_SIG_N|T1_3D_SIG_E|T1_3D_SIG_S|T1_3D_SIG_W|T1_3D_SIG_FC|T1_3D_SIG_BC)
#define T1_3D_SGN_N 0x0400
#define T1_3D_SGN_E 0x0800
#define T1_3D_SGN_S 0x1000
#define T1_3D_SGN_W 0x2000
#define T1_3D_SGN_F 0x4000
#define T1_3D_SGN_B 0x8000
#define T1_3D_SGN (T1_3D_SGN_N|T1_3D_SGN_E|T1_3D_SGN_S|T1_3D_SGN_W|T1_3D_SGN_F|T1_3D_SGN_B)
#define T1_3D_SIG 0x0001 /*Significance state*/
#define T1_3D_REFINE 0x0002 /*Delayed significance*/
#define T1_3D_VISIT 0x0004 /*First-pass membership*/
#define T1_3D_NUMCTXS_AGG 1
#define T1_3D_NUMCTXS_ZC 16
#define T1_3D_NUMCTXS_MAG 3
#define T1_3D_NUMCTXS_SC 6
#define T1_3D_NUMCTXS_UNI 1
#define T1_3D_CTXNO_AGG 0
#define T1_3D_CTXNO_ZC (T1_3D_CTXNO_AGG+T1_3D_NUMCTXS_AGG) /*1*/
#define T1_3D_CTXNO_MAG (T1_3D_CTXNO_ZC+T1_3D_NUMCTXS_ZC) /*17*/
#define T1_3D_CTXNO_SC (T1_3D_CTXNO_MAG+T1_3D_NUMCTXS_MAG) /*20*/
#define T1_3D_CTXNO_UNI (T1_3D_CTXNO_SC+T1_3D_NUMCTXS_SC) /*26*/
#define T1_3D_NUMCTXS (T1_3D_CTXNO_UNI+T1_3D_NUMCTXS_UNI) /*27*/
/* ----------------------------------------------------------------------- */
/**
Tier-1 coding (coding of code-block coefficients)
*/
typedef struct opj_t1_3d {
/** Codec context */
opj_common_ptr cinfo;
/** MQC component */
opj_mqc_t *mqc;
/** RAW component */
opj_raw_t *raw;
/** LUTs for decoding normalised MSE */
int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
/** Codeblock data */
int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];
/** Context information for each voxel in codeblock */
unsigned int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
/** Voxel information (significance/visited/refined) */
int flagSVR[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];
} opj_t1_3d_t;
/** @name Exported functions */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a new T1_3D handle
and initialize the look-up tables of the Tier-1 coder/decoder
@return Returns a new T1 handle if successful, returns NULL otherwise
@see t1_init_luts
*/
opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo);
/**
Destroy a previously created T1_3D handle
@param t1 T1_3D handle to destroy
*/
void t1_3d_destroy(opj_t1_3d_t *t1);
/**
Encode the code-blocks of a tile
@param t1 T1_3D handle
@param tile The tile to encode
@param tcp Tile coding parameters
*/
void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Decode the code-blocks of a tile
@param t1 T1_3D handle
@param tile The tile to decode
@param tcp Tile coding parameters
*/
void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp);
/**
Get weigths of MSE decoding
@param nmsedec The normalized MSE reduction
@param compno
@param level
@param orient
@param bpno
@param reversible
@param stepsize
@param numcomps
@param dwtid
returns MSE associated to decoding pass
double t1_3d_getwmsedec(int nmsedec, int compno, int levelxy, int levelz, int orient, int bpno, int reversible, double stepsize, int numcomps, int dwtid);
*/
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T1_H */

1351
src/lib/openjp3d/t2.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

202
src/lib/openjp3d/t2.h Executable file → Normal file
View File

@ -1,101 +1,101 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T2_H
#define __T2_H
/**
@file t2.h
@brief Implementation of a tier-2 coding (packetization of code-block data) (T2)
*/
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
/*@{*/
/**
Tier-2 coding
*/
typedef struct opj_t2 {
/** Codec context */
opj_common_ptr cinfo;
/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */
opj_volume_t *volume;
/** Pointer to the volume coding parameters */
opj_cp_t *cp;
} opj_t2_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Encode the packets of a tile to a destination buffer
@param t2 T2 handle
@param tileno number of the tile encoded
@param tile the tile for which to write the packets
@param maxlayers maximum number of layers
@param dest the destination buffer
@param len the length of the destination buffer
@param volume_info structure to create an index file
@return Number of bytes written from packets
*/
int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle
@param src the source buffer
@param len length of the source buffer
@param tileno number that identifies the tile for which to decode the packets
@param tile tile for which to decode the packets
@return Number of bytes read from packets
*/
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile);
/**
Create a T2 handle
@param cinfo Codec context info
@param volume Source or destination volume
@param cp Volume coding parameters
@return Returns a new T2 handle if successful, returns NULL otherwise
*/
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp);
/**
Destroy a T2 handle
@param t2 T2 handle to destroy
*/
void t2_destroy(opj_t2_t *t2);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T2_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __T2_H
#define __T2_H
/**
@file t2.h
@brief Implementation of a tier-2 coding (packetization of code-block data) (T2)
*/
/** @defgroup T2 T2 - Implementation of a tier-2 coding */
/*@{*/
/**
Tier-2 coding
*/
typedef struct opj_t2 {
/** Codec context */
opj_common_ptr cinfo;
/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */
opj_volume_t *volume;
/** Pointer to the volume coding parameters */
opj_cp_t *cp;
} opj_t2_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Encode the packets of a tile to a destination buffer
@param t2 T2 handle
@param tileno number of the tile encoded
@param tile the tile for which to write the packets
@param maxlayers maximum number of layers
@param dest the destination buffer
@param len the length of the destination buffer
@param volume_info structure to create an index file
@return Number of bytes written from packets
*/
int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info);
/**
Decode the packets of a tile from a source buffer
@param t2 T2 handle
@param src the source buffer
@param len length of the source buffer
@param tileno number that identifies the tile for which to decode the packets
@param tile tile for which to decode the packets
@return Number of bytes read from packets
*/
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile);
/**
Create a T2 handle
@param cinfo Codec context info
@param volume Source or destination volume
@param cp Volume coding parameters
@return Returns a new T2 handle if successful, returns NULL otherwise
*/
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp);
/**
Destroy a T2 handle
@param t2 T2 handle to destroy
*/
void t2_destroy(opj_t2_t *t2);
/* ----------------------------------------------------------------------- */
/*@}*/
/*@}*/
#endif /* __T2_H */

3478
src/lib/openjp3d/tcd.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

0
src/lib/openjp3d/tcd.h Executable file → Normal file
View File

507
src/lib/openjp3d/tgt.c Executable file → Normal file
View File

@ -1,256 +1,251 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/*
==========================================================
Tag-tree coder interface
==========================================================
*/
void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){
int nodesno;
fprintf(fd, "TGT_TREE {\n");
fprintf(fd, " numnodes: %d \n", tree->numnodes);
fprintf(fd, " numleafsh: %d, numleafsv: %d, numleafsz: %d,\n", tree->numleafsh, tree->numleafsv, tree->numleafsz);
for (nodesno = 0; nodesno < tree->numnodes; nodesno++) {
fprintf(fd, "tgt_node %d {\n", nodesno);
fprintf(fd, " value: %d \n", tree->nodes[nodesno].value);
fprintf(fd, " low: %d \n", tree->nodes[nodesno].low);
fprintf(fd, " known: %d \n", tree->nodes[nodesno].known);
if (tree->nodes[nodesno].parent) {
fprintf(fd, " parent.value: %d \n", tree->nodes[nodesno].parent->value);
fprintf(fd, " parent.low: %d \n", tree->nodes[nodesno].parent->low);
fprintf(fd, " parent.known: %d \n", tree->nodes[nodesno].parent->known);
}
fprintf(fd, "}\n");
}
fprintf(fd, "}\n");
}
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) {
int nplh[32];
int nplv[32];
int nplz[32];
opj_tgt_node_t *node = NULL;
opj_tgt_node_t *parentnode = NULL;
opj_tgt_node_t *parentnode0 = NULL;
opj_tgt_tree_t *tree = NULL;
int i, j, k, p, p0;
int numlvls;
int n, z = 0;
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
if(!tree)
return NULL;
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
tree->numleafsz = numleafsz;
numlvls = 0;
nplh[0] = numleafsh;
nplv[0] = numleafsv;
nplz[0] = numleafsz;
tree->numnodes = 0;
do {
n = nplh[numlvls] * nplv[numlvls] * nplz[numlvls];
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
nplz[numlvls + 1] = (nplz[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
if (tree->numnodes == 0) {
opj_free(tree);
return NULL;
}
tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_free(tree);
return NULL;
}
node = tree->nodes;
parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv * tree->numleafsz];
parentnode0 = parentnode;
p = tree->numleafsh * tree->numleafsv * tree->numleafsz;
p0 = p;
n = 0;
/*fprintf(stdout,"\nH %d V %d Z %d numlvls %d nodes %d\n",tree->numleafsh,tree->numleafsv,tree->numleafsz,numlvls,tree->numnodes);*/
for (i = 0; i < numlvls - 1; ++i) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i]*nplz[i];
while (--k >= 0) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node; ++n;
if (--k >= 0 && n < p) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node; ++n;
}
if (nplz[i] != 1){ /*2D operation vs 3D operation*/
if (--k >= 0 && n < p) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node; ++n;
}
if (--k >= 0 && n < p) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node; ++n;
}
}
++parentnode; ++p;
}
if ((j & 1) || j == nplv[i] - 1) {
parentnode0 = parentnode; p0 = p; /*fprintf(stdout,"parent = node[%d] \n",p);*/
} else {
parentnode = parentnode0; p = p0; /*fprintf(stdout,"parent = node[%d] \n",p);*/
parentnode0 += nplh[i]*nplz[i]; p0 += nplh[i]*nplz[i];
}
}
}
node->parent = 0;
tgt_reset(tree);
return tree;
}
void tgt_destroy(opj_tgt_tree_t *tree) {
opj_free(tree->nodes);
opj_free(tree);
}
void tgt_reset(opj_tgt_tree_t *tree) {
int i;
if (NULL == tree)
return;
for (i = 0; i < tree->numnodes; i++) {
tree->nodes[i].value = 999;
tree->nodes[i].low = 0;
tree->nodes[i].known = 0;
}
}
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
node->value = value;
node = node->parent;
}
}
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold) {
if (low >= node->value) {
if (!node->known) {
bio_write(bio, 1, 1);
node->known = 1;
}
break;
}
bio_write(bio, 0, 1);
++low;
}
node->low = low;
if (stkptr == stk)
break;
node = *--stkptr;
}
}
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold && low < node->value) {
if (bio_read(bio, 1)) {
node->value = low;
} else {
++low;
}
}
node->low = low;
if (stkptr == stk) {
break;
}
node = *--stkptr;
}
return (node->value < threshold) ? 1 : 0;
}
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
/*
==========================================================
Tag-tree coder interface
==========================================================
*/
void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){
int nodesno;
fprintf(fd, "TGT_TREE {\n");
fprintf(fd, " numnodes: %d \n", tree->numnodes);
fprintf(fd, " numleafsh: %d, numleafsv: %d, numleafsz: %d,\n", tree->numleafsh, tree->numleafsv, tree->numleafsz);
for (nodesno = 0; nodesno < tree->numnodes; nodesno++) {
fprintf(fd, "tgt_node %d {\n", nodesno);
fprintf(fd, " value: %d \n", tree->nodes[nodesno].value);
fprintf(fd, " low: %d \n", tree->nodes[nodesno].low);
fprintf(fd, " known: %d \n", tree->nodes[nodesno].known);
if (tree->nodes[nodesno].parent) {
fprintf(fd, " parent.value: %d \n", tree->nodes[nodesno].parent->value);
fprintf(fd, " parent.low: %d \n", tree->nodes[nodesno].parent->low);
fprintf(fd, " parent.known: %d \n", tree->nodes[nodesno].parent->known);
}
fprintf(fd, "}\n");
}
fprintf(fd, "}\n");
}
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) {
int nplh[32];
int nplv[32];
int nplz[32];
opj_tgt_node_t *node = NULL;
opj_tgt_node_t *parentnode = NULL;
opj_tgt_node_t *parentnode0 = NULL;
opj_tgt_node_t *parentnode1 = NULL;
opj_tgt_tree_t *tree = NULL;
int i, j, k, p, p0;
int numlvls;
int n, z = 0;
tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
if(!tree)
return NULL;
tree->numleafsh = numleafsh;
tree->numleafsv = numleafsv;
tree->numleafsz = numleafsz;
numlvls = 0;
nplh[0] = numleafsh;
nplv[0] = numleafsv;
nplz[0] = numleafsz;
tree->numnodes = 0;
do {
n = nplh[numlvls] * nplv[numlvls] * nplz[numlvls];
nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
nplz[numlvls + 1] = (nplz[numlvls] + 1) / 2;
tree->numnodes += n;
++numlvls;
} while (n > 1);
if (tree->numnodes == 0) {
opj_free(tree);
return NULL;
}
tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t));
if(!tree->nodes) {
opj_free(tree);
return NULL;
}
node = tree->nodes;
parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv * tree->numleafsz];
parentnode0 = parentnode;
parentnode1 = parentnode;
/*fprintf(stdout,"\nH %d V %d Z %d numlvls %d nodes %d\n",tree->numleafsh,tree->numleafsv,tree->numleafsz,numlvls,tree->numnodes);*/
for (i = 0; i < numlvls - 1; ++i) {
for (z = 0; z < nplz[i]; ++z) {
for (j = 0; j < nplv[i]; ++j) {
k = nplh[i];
while(--k >= 0) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node;
if(--k >= 0) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node;
}
++parentnode;
}
if((j & 1) || j == nplv[i] - 1) {
parentnode0 = parentnode;
} else {
parentnode = parentnode0;
}
}
if ((z & 1) || z == nplz[i] - 1) {
parentnode1 = parentnode;
} else {
parentnode0 = parentnode1;
parentnode = parentnode1;
}
}
}
node->parent = 0;
tgt_reset(tree);
return tree;
}
void tgt_destroy(opj_tgt_tree_t *tree) {
opj_free(tree->nodes);
opj_free(tree);
}
void tgt_reset(opj_tgt_tree_t *tree) {
int i;
if (NULL == tree)
return;
for (i = 0; i < tree->numnodes; i++) {
tree->nodes[i].value = 999;
tree->nodes[i].low = 0;
tree->nodes[i].known = 0;
}
}
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
opj_tgt_node_t *node;
node = &tree->nodes[leafno];
while (node && node->value > value) {
node->value = value;
node = node->parent;
}
}
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold) {
if (low >= node->value) {
if (!node->known) {
bio_write(bio, 1, 1);
node->known = 1;
}
break;
}
bio_write(bio, 0, 1);
++low;
}
node->low = low;
if (stkptr == stk)
break;
node = *--stkptr;
}
}
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) {
opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr;
opj_tgt_node_t *node;
int low;
stkptr = stk;
node = &tree->nodes[leafno];
while (node->parent) {
*stkptr++ = node;
node = node->parent;
}
low = 0;
for (;;) {
if (low > node->low) {
node->low = low;
} else {
low = node->low;
}
while (low < threshold && low < node->value) {
if (bio_read(bio, 1)) {
node->value = low;
} else {
++low;
}
}
node->low = low;
if (stkptr == stk) {
break;
}
node = *--stkptr;
}
return (node->value < threshold) ? 1 : 0;
}

250
src/lib/openjp3d/tgt.h Executable file → Normal file
View File

@ -1,125 +1,125 @@
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TGT_H
#define __TGT_H
/**
@file tgt.h
@brief Implementation of a tag-tree coder (TGT)
The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C
are used by some function in T2.C.
*/
/** @defgroup TGT TGT - Implementation of a tag-tree coder */
/*@{*/
/**
Tag node
*/
typedef struct opj_tgt_node {
/** Node parent reference */
struct opj_tgt_node *parent;
/** */
int value;
/** */
int low;
/** */
int known;
} opj_tgt_node_t;
/**
Tag tree
*/
typedef struct opj_tgt_tree {
/** Number of leaves from horizontal axis */
int numleafsh;
/** Number of leaves from vertical axis */
int numleafsv;
/** Number of leaves from axial axis */
int numleafsz;
/** Number of nodes */
int numnodes;
/** Reference to each node instance */
opj_tgt_node_t *nodes;
} opj_tgt_tree_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a tag-tree
@param numleafsh Width of the array of leafs of the tree
@param numleafsv Height of the array of leafs of the tree
@param numleafsz Depth of the array of leafs of the tree
@return Returns a new tag-tree if successful, returns NULL otherwise
*/
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz);
/**
Destroy a tag-tree, liberating memory
@param tree Tag-tree to destroy
*/
void tgt_destroy(opj_tgt_tree_t *tree);
/**
Reset a tag-tree (set all leaves to 0)
@param tree Tag-tree to reset
*/
void tgt_reset(opj_tgt_tree_t *tree);
/**
Set the value of a leaf of a tag-tree
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to modify
@param value New value of the leaf
*/
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
/**
Encode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to encode
@param threshold Threshold to use when encoding value of the leaf
*/
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/**
Decode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to decode
@param leafno Number that identifies the leaf to decode
@param threshold Threshold to use when decoding value of the leaf
@return Returns 1 if the node's value < threshold, returns 0 otherwise
*/
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/*@}*/
/* ----------------------------------------------------------------------- */
void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree);
/*@}*/
#endif /* __TGT_H */
/*
* Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __TGT_H
#define __TGT_H
/**
@file tgt.h
@brief Implementation of a tag-tree coder (TGT)
The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C
are used by some function in T2.C.
*/
/** @defgroup TGT TGT - Implementation of a tag-tree coder */
/*@{*/
/**
Tag node
*/
typedef struct opj_tgt_node {
/** Node parent reference */
struct opj_tgt_node *parent;
/** */
int value;
/** */
int low;
/** */
int known;
} opj_tgt_node_t;
/**
Tag tree
*/
typedef struct opj_tgt_tree {
/** Number of leaves from horizontal axis */
int numleafsh;
/** Number of leaves from vertical axis */
int numleafsv;
/** Number of leaves from axial axis */
int numleafsz;
/** Number of nodes */
int numnodes;
/** Reference to each node instance */
opj_tgt_node_t *nodes;
} opj_tgt_tree_t;
/** @name Funciones generales */
/*@{*/
/* ----------------------------------------------------------------------- */
/**
Create a tag-tree
@param numleafsh Width of the array of leafs of the tree
@param numleafsv Height of the array of leafs of the tree
@param numleafsz Depth of the array of leafs of the tree
@return Returns a new tag-tree if successful, returns NULL otherwise
*/
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz);
/**
Destroy a tag-tree, liberating memory
@param tree Tag-tree to destroy
*/
void tgt_destroy(opj_tgt_tree_t *tree);
/**
Reset a tag-tree (set all leaves to 0)
@param tree Tag-tree to reset
*/
void tgt_reset(opj_tgt_tree_t *tree);
/**
Set the value of a leaf of a tag-tree
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to modify
@param value New value of the leaf
*/
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value);
/**
Encode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to modify
@param leafno Number that identifies the leaf to encode
@param threshold Threshold to use when encoding value of the leaf
*/
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/**
Decode the value of a leaf of the tag-tree up to a given threshold
@param bio Pointer to a BIO handle
@param tree Tag-tree to decode
@param leafno Number that identifies the leaf to decode
@param threshold Threshold to use when decoding value of the leaf
@return Returns 1 if the node's value < threshold, returns 0 otherwise
*/
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold);
/*@}*/
/* ----------------------------------------------------------------------- */
void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree);
/*@}*/
#endif /* __TGT_H */

182
src/lib/openjp3d/volume.c Executable file → Normal file
View File

@ -1,91 +1,91 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#include "volume.h"
#include "openjp3d.h"
opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
int compno;
opj_volume_t *volume = NULL;
volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t));
if(volume) {
volume->color_space = clrspc;
volume->numcomps = numcmpts;
/* allocate memory for the per-component information */
volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t));
if(!volume->comps) {
opj_volume_destroy(volume);
return NULL;
}
/* create the individual volume components */
for(compno = 0; compno < numcmpts; compno++) {
opj_volume_comp_t *comp = &volume->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->dz = cmptparms[compno].dz;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->l = cmptparms[compno].l;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->z0 = cmptparms[compno].z0;
comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
comp->bigendian = cmptparms[compno].bigendian;
comp->dcoffset = cmptparms[compno].dcoffset;
comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int));
if(!comp->data) {
fprintf(stdout,"Unable to malloc comp->data (%d x %d x %d x bytes)",comp->w,comp->h,comp->l);
opj_volume_destroy(volume);
return NULL;
}
/*fprintf(stdout,"%d %d %d %d %d %d %d %d %d", comp->w,comp->h, comp->l, comp->dx, comp->dy, comp->dz, comp->prec, comp->bpp, comp->sgnd);*/
}
}
return volume;
}
void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) {
int i;
if(volume) {
if(volume->comps) {
/* volume components */
for(i = 0; i < volume->numcomps; i++) {
opj_volume_comp_t *volume_comp = &volume->comps[i];
if(volume_comp->data) {
opj_free(volume_comp->data);
}
}
opj_free(volume->comps);
}
opj_free(volume);
}
}
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#include "volume.h"
#include "openjp3d.h"
opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
int compno;
opj_volume_t *volume = NULL;
volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t));
if(volume) {
volume->color_space = clrspc;
volume->numcomps = numcmpts;
/* allocate memory for the per-component information */
volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t));
if(!volume->comps) {
opj_volume_destroy(volume);
return NULL;
}
/* create the individual volume components */
for(compno = 0; compno < numcmpts; compno++) {
opj_volume_comp_t *comp = &volume->comps[compno];
comp->dx = cmptparms[compno].dx;
comp->dy = cmptparms[compno].dy;
comp->dz = cmptparms[compno].dz;
comp->w = cmptparms[compno].w;
comp->h = cmptparms[compno].h;
comp->l = cmptparms[compno].l;
comp->x0 = cmptparms[compno].x0;
comp->y0 = cmptparms[compno].y0;
comp->z0 = cmptparms[compno].z0;
comp->prec = cmptparms[compno].prec;
comp->bpp = cmptparms[compno].bpp;
comp->sgnd = cmptparms[compno].sgnd;
comp->bigendian = cmptparms[compno].bigendian;
comp->dcoffset = cmptparms[compno].dcoffset;
comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int));
if(!comp->data) {
fprintf(stdout,"Unable to malloc comp->data (%d x %d x %d x bytes)",comp->w,comp->h,comp->l);
opj_volume_destroy(volume);
return NULL;
}
/*fprintf(stdout,"%d %d %d %d %d %d %d %d %d", comp->w,comp->h, comp->l, comp->dx, comp->dy, comp->dz, comp->prec, comp->bpp, comp->sgnd);*/
}
}
return volume;
}
void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) {
int i;
if(volume) {
if(volume->comps) {
/* volume components */
for(i = 0; i < volume->numcomps; i++) {
opj_volume_comp_t *volume_comp = &volume->comps[i];
if(volume_comp->data) {
opj_free(volume_comp->data);
}
}
opj_free(volume->comps);
}
opj_free(volume);
}
}

86
src/lib/openjp3d/volume.h Executable file → Normal file
View File

@ -1,43 +1,43 @@
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __VOLUME_H
#define __VOLUME_H
/**
@file volume.h
@brief Implementation of operations on volumes (VOLUME)
The functions in VOLUME.C have for goal to realize operations on volumes.
*/
/** @defgroup VOLUME VOLUME - Implementation of operations on volumes */
/*@{*/
/*@}*/
#endif /* __VOLUME_H */
/*
* Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __VOLUME_H
#define __VOLUME_H
/**
@file volume.h
@brief Implementation of operations on volumes (VOLUME)
The functions in VOLUME.C have for goal to realize operations on volumes.
*/
/** @defgroup VOLUME VOLUME - Implementation of operations on volumes */
/*@{*/
/*@}*/
#endif /* __VOLUME_H */

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