[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
@ -234,6 +257,12 @@ configure_file(
@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)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
@ -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
@ -386,9 +415,45 @@ 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

View File

@ -53,7 +53,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"
@ -61,11 +61,6 @@
#include "format_defs.h"
#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/
#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/
#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
char *filename_buf;
@ -82,8 +77,6 @@ typedef struct img_folder{
char set_imgdir;
/** Enable Cod Format for output*/
char set_out_format;
/** User specified rate stored in case of cinema option*/
float *rates;
}img_fol_t;
static void encode_help_display(void) {
@ -109,6 +102,7 @@ static void encode_help_display(void) {
fprintf(stdout,"\n");
fprintf(stdout," * Lossless\n");
fprintf(stdout," * 1 tile\n");
fprintf(stdout," * RGB->YCC conversion if at least 3 components\n");
fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n");
fprintf(stdout," * Size of code-block : 64 x 64\n");
fprintf(stdout," * Number of resolutions: 6\n");
@ -140,7 +134,7 @@ static void encode_help_display(void) {
fprintf(stdout,"-OutFor \n");
fprintf(stdout," REQUIRED only if -ImgDir is used\n");
fprintf(stdout," Need to specify only format without filename <BMP> \n");
fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW, RAWL and TGA formats\n");
fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW (MSB), RAWL (LSB) and TGA formats\n");
fprintf(stdout,"\n");
fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n");
fprintf(stdout," When using this option -o must be used\n");
@ -197,7 +191,7 @@ static void encode_help_display(void) {
fprintf(stdout," Indicate multiple modes by adding their values. \n");
fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
fprintf(stdout,"\n");
fprintf(stdout,"-TP : devide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
fprintf(stdout,"-TP : divide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
fprintf(stdout,"\n");
fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n");
@ -215,8 +209,14 @@ static void encode_help_display(void) {
fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stdout,"\n");
fprintf(stdout,"-m : use array-based MCT, values are coma separated, line by line\n");
fprintf(stdout,"-mct {0,1,2} : explicitely specifies if an Multiple Component Transform has to be used.\n");
fprintf(stdout," 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n");
fprintf(stdout," If custom MCT, \"-m\" option has to be used (see hereunder).\n");
fprintf(stdout," By default, RGB->YCC conversion is used if there are 3 components or more,\n");
fprintf(stdout," no conversion otherwise.\n");
fprintf(stdout,"-m <file> : use array-based MCT, values are coma separated, line by line\n");
fprintf(stdout," no specific separators between lines, no space allowed between values\n");
fprintf(stdout," If this option is used, it automatically sets \"-mct\" option to 2.\n");
fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n");
fprintf(stdout," NOTICE: currently supports only RPCL order\n");
fprintf(stdout,"\n");
@ -415,9 +415,7 @@ static int get_file_format(char *filename) {
}
static char * get_file_name(char *name){
char *fname;
fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char));
fname= strtok(name,".");
char *fname = strtok(name,".");
return fname;
}
@ -446,145 +444,12 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
return 0;
}
static int initialise_4K_poc(opj_poc_t *POC, int numres){
POC[0].tile = 1;
POC[0].resno0 = 0;
POC[0].compno0 = 0;
POC[0].layno1 = 1;
POC[0].resno1 = numres-1;
POC[0].compno1 = 3;
POC[0].prg1 = OPJ_CPRL;
POC[1].tile = 1;
POC[1].resno0 = numres-1;
POC[1].compno0 = 0;
POC[1].layno1 = 1;
POC[1].resno1 = numres;
POC[1].compno1 = 3;
POC[1].prg1 = OPJ_CPRL;
return 2;
}
static void cinema_parameters(opj_cparameters_t *parameters){
parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1;
parameters->cp_tdy=1;
/*Tile part*/
parameters->tp_flag = 'C';
parameters->tp_on = 1;
/*Tile and Image shall be at (0,0)*/
parameters->cp_tx0 = 0;
parameters->cp_ty0 = 0;
parameters->image_offset_x0 = 0;
parameters->image_offset_y0 = 0;
/*Codeblock size= 32*32*/
parameters->cblockw_init = 32;
parameters->cblockh_init = 32;
parameters->csty |= 0x01;
/*The progression order shall be CPRL*/
parameters->prog_order = OPJ_CPRL;
/* No ROI */
parameters->roi_compno = -1;
parameters->subsampling_dx = 1; parameters->subsampling_dy = 1;
/* 9-7 transform */
parameters->irreversible = 1;
}
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
int i;
float temp_rate;
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA2K_48:
if(parameters->numresolution > 6){
parameters->numresolution = 6;
}
if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){
fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
"(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = OPJ_STD_RSIZ;
}
break;
case OPJ_CINEMA4K_24:
if(parameters->numresolution < 1){
parameters->numresolution = 1;
}else if(parameters->numresolution > 7){
parameters->numresolution = 7;
}
if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){
fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
"(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
image->comps[0].w,image->comps[0].h);
parameters->cp_rsiz = OPJ_STD_RSIZ;
}
parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution);
break;
default :
break;
}
switch (parameters->cp_cinema){
case OPJ_CINEMA2K_24:
case OPJ_CINEMA4K_24:
for(i=0 ; i<parameters->tcp_numlayers ; i++){
temp_rate = 0 ;
if (img_fol->rates[i]== 0){
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_24_CS ){
parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
parameters->tcp_rates[i]= img_fol->rates[i];
}
}
}
parameters->max_comp_size = COMP_24_CS;
break;
case OPJ_CINEMA2K_48:
for(i=0 ; i<parameters->tcp_numlayers ; i++){
temp_rate = 0 ;
if (img_fol->rates[i]== 0){
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{
parameters->tcp_rates[i]= img_fol->rates[i];
}
}
}
parameters->max_comp_size = COMP_48_CS;
break;
default:
break;
}
parameters->cp_disto_alloc = 1;
}
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
int i, j, totlen, c;
OPJ_UINT32 i, j;
int totlen, c;
opj_option_t long_option[]={
{"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4K",NO_ARG, NULL ,'y'},
@ -595,11 +460,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
{"OutFor",REQ_ARG, NULL ,'O'},
{"POC",REQ_ARG, NULL ,'P'},
{"ROI",REQ_ARG, NULL ,'R'},
{"jpip",NO_ARG, NULL, 'J'}
{"jpip",NO_ARG, NULL, 'J'},
{"mct",REQ_ARG, NULL, 'Y'}
};
/* parse the command line */
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J"
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:"
#ifdef USE_JPWL
"W:"
#endif /* USE_JPWL */
@ -757,16 +623,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
case 'f': /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0;
OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0;
char *s = opj_optarg;
sscanf(s, "%d", &numlayers);
sscanf(s, "%ud", &numlayers);
s++;
if (numlayers > 9)
s++;
parameters->tcp_numlayers = numlayers;
numresolution = parameters->numresolution;
parameters->tcp_numlayers = (int)numlayers;
numresolution = (OPJ_UINT32)parameters->numresolution;
matrix_width = numresolution * 3;
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
s = s + 2;
@ -823,10 +689,17 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
int res_spec = 0;
char *s = opj_optarg;
int ret;
do {
sep = 0;
sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep);
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') )
{
fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep);
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n");
return 1;
}
parameters->csty |= 0x01;
res_spec++;
s = strpbrk(s, "]") + 2;
@ -920,7 +793,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
char *s = opj_optarg;
POC = parameters->POC;
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
while (sscanf(s, "T%ud=%ud,%ud,%ud,%ud,%ud,%4s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
&POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
@ -934,7 +807,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
s++;
}
parameters->numpocs = numpocs;
parameters->numpocs = (OPJ_UINT32)numpocs;
}
break;
@ -1045,8 +918,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
return 1;
}
fprintf(stdout,"CINEMA 2K compliant codestream\n");
parameters->cp_rsiz = OPJ_CINEMA2K;
fprintf(stdout,"CINEMA 2K profile activated\n"
"Other options specified could be overriden\n");
}
break;
@ -1056,12 +929,28 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
case 'y': /* Digital Cinema 4K profile compliance*/
{
parameters->cp_cinema = OPJ_CINEMA4K_24;
fprintf(stdout,"CINEMA 4K compliant codestream\n");
parameters->cp_rsiz = OPJ_CINEMA4K;
fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overriden\n");
}
break;
/* ------------------------------------------------------ */
case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
{
int mct_mode=0;
sscanf(opj_optarg,"%d",&mct_mode);
if(mct_mode < 0 || mct_mode > 2){
fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n");
return 1;
}
parameters->tcp_mct = (char) mct_mode;
}
break;
/* ------------------------------------------------------ */
case 'm': /* mct input file */
{
char *lFilename = opj_optarg;
@ -1070,7 +959,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
float *lCurrentDoublePtr;
float *lSpace;
int *l_int_ptr;
int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen;
int lNbComp = 0, lTotalComp, lMctComp, i2;
size_t lStrLen, lStrFread;
/* Open file */
FILE * lFile = fopen(lFilename,"r");
@ -1080,11 +970,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* Set size of file and read its content*/
fseek(lFile,0,SEEK_END);
lStrLen = ftell(lFile);
lStrLen = (size_t)ftell(lFile);
fseek(lFile,0,SEEK_SET);
lMatrix = (char *) malloc(lStrLen + 1);
fread(lMatrix, lStrLen, 1, lFile);
lStrFread = fread(lMatrix, 1, lStrLen, lFile);
fclose(lFile);
if( lStrLen != lStrFread ) return 1;
lMatrix[lStrLen] = 0;
lCurrentPtr = lMatrix;
@ -1103,23 +994,23 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5);
lMctComp = lNbComp * lNbComp;
lTotalComp = lMctComp + lNbComp;
lSpace = (float *) malloc(lTotalComp * sizeof(float));
lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float));
lCurrentDoublePtr = lSpace;
for (i=0;i<lMctComp;++i) {
for (i2=0;i2<lMctComp;++i2) {
lStrLen = strlen(lCurrentPtr) + 1;
*lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
lCurrentPtr += lStrLen;
}
l_int_ptr = (int*) lCurrentDoublePtr;
for (i=0;i<lNbComp;++i) {
for (i2=0;i2<lNbComp;++i2) {
lStrLen = strlen(lCurrentPtr) + 1;
*l_int_ptr++ = atoi(lCurrentPtr);
lCurrentPtr += lStrLen;
}
/* TODO should not be here ! */
opj_set_MCT(parameters, lSpace, (int *)(lSpace + lMctComp), lNbComp);
opj_set_MCT(parameters, lSpace, (int *)(lSpace + lMctComp), (OPJ_UINT32)lNbComp);
/* Free memory*/
free(lSpace);
@ -1465,13 +1356,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}while(c != -1);
/* check for possible errors */
if (parameters->cp_cinema){
if(parameters->tcp_numlayers > 1){
parameters->cp_rsiz = OPJ_STD_RSIZ;
fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n");
}
}
if(img_fol->set_imgdir == 1){
if(!(parameters->infile[0] == 0)){
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
@ -1538,28 +1422,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* -------------------------------------------------------------------------- */
/**
sample error callback expecting a FILE* client object
*/
static void error_file_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_file_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_file_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}
/**
sample error debug callback expecting no client object
*/
@ -1615,18 +1477,11 @@ int main(int argc, char **argv) {
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
parameters.tcp_mct = -1; /* This will be set later according to the input image or the provided option */
if(parse_cmdline_encoder(argc, argv, &parameters,&img_fol, &raw_cp, indexfilename) == 1) {
return 1;
}
if (parameters.cp_cinema){
img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float));
for(i=0; i< parameters.tcp_numlayers; i++){
img_fol.rates[i] = parameters.tcp_rates[i];
}
cinema_parameters(&parameters);
}
/* Create comment for codestream */
if(parameters.cp_comment == NULL) {
const char comment[] = "Created by OpenJPEG version ";
@ -1673,7 +1528,7 @@ int main(int argc, char **argv) {
fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
if (get_next_file((int)imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n");
continue;
}
@ -1728,7 +1583,7 @@ int main(int argc, char **argv) {
}
break;
#ifdef HAVE_LIBTIFF
#ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT:
image = tiftoimage(parameters.infile, &parameters);
if (!image) {
@ -1736,7 +1591,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);
@ -1762,7 +1617,7 @@ int main(int argc, char **argv) {
}
break;
#ifdef HAVE_LIBPNG
#ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT:
image = pngtoimage(parameters.infile, &parameters);
if (!image) {
@ -1770,11 +1625,11 @@ 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) {
fprintf(stderr, "Unable to load file: got no image\n");
@ -1782,10 +1637,19 @@ int main(int argc, char **argv) {
}
/* Decide if MCT should be used */
parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;
if(parameters.cp_cinema){
cinema_setup_encoder(&parameters,image,&img_fol);
if (parameters.tcp_mct == -1) { /* mct mode has not been set in commandline */
parameters.tcp_mct = image->numcomps >= 3 ? 1 : 0;
} else { /* mct mode has been set in commandline */
if ((parameters.tcp_mct == 1) && (image->numcomps < 3)){
fprintf(stderr, "RGB->YCC conversion cannot be used:\n");
fprintf(stderr, "Input image has less than 3 components\n");
return 1;
}
if ((parameters.tcp_mct == 2) && (!parameters.mct_data)){
fprintf(stderr, "Custom MCT has been set but no array-based MCT\n");
fprintf(stderr, "has been provided. Aborting.\n");
return 1;
}
}
/* encode the destination image */
@ -1897,7 +1761,6 @@ int main(int argc, char **argv) {
/* free user parameters structure */
if(parameters.cp_comment) free(parameters.cp_comment);
if(parameters.cp_matrice) free(parameters.cp_matrice);
if(parameters.cp_cinema) free(img_fol.rates);
return 0;
}

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);
@ -865,8 +866,15 @@ int main(int argc, char **argv)
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;
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;){
for(k = (OPJ_INT32)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];
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 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_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;
}
@ -453,12 +451,20 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2);
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,12 +473,13 @@ 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;
}
@ -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,39 +857,51 @@ 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;
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)
{
/* 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];
dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
}
}
}
@ -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_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;
@ -973,10 +1088,19 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
for(i = 0; i < n; ++i)
{
/* WATCH: acn = asoc - 1 ! */
if((asoc = info[i].asoc) == 0) continue;
asoc = info[i].asoc;
if(asoc == 0 || asoc == 65535)
{
continue;
}
cn = info[i].cn;
acn = asoc - 1;
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)
{
@ -1120,12 +1261,15 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
}
}
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;
}
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;
}
@ -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*/ /**< */
@ -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)

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

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

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

@ -58,6 +58,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
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;
}

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

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;

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

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

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

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

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

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

@ -58,15 +58,15 @@ Read the SIZ marker (2D volume and tile size)
*/
static void j3d_read_siz(opj_j3d_t *j3d);
/**
Write the ZSI marker (3rd volume and tile size)
Write the NSI marker (3rd volume and tile size)
@param j3d J3D handle
*/
static void j3d_write_zsi(opj_j3d_t *j3d);
static void j3d_write_nsi(opj_j3d_t *j3d);
/**
Read the ZSI marker (3rd volume and tile size)
Read the NSI marker (3rd volume and tile size)
@param j3d J3D handle
*/
static void j3d_read_zsi(opj_j3d_t *j3d);
static void j3d_read_nsi(opj_j3d_t *j3d);
/**
Write the COM marker (comment)
@param j3d J3D handle
@ -418,6 +418,10 @@ static void j3d_write_cap(opj_j3d_t *j3d){
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio,J3D_CAP_10, 4);
if( J3D_CAP_10 )
{
cio_write(cio, 0x0, 2);
}
len = cio_tell(cio) - lenp;
cio_seek(cio, lenp);
cio_write(cio, len, 2); /* Lsiz */
@ -430,18 +434,24 @@ static void j3d_read_cap(opj_j3d_t *j3d){
/*cio_read(cio, 2); CAP */
len = cio_read(cio, 2);
Cap = cio_read(cio, 4);
if(Cap) {
cio_read(cio, 2);
}
static void j3d_write_zsi(opj_j3d_t *j3d) {
assert( len == 2 + 4 + 2 );
}
static void j3d_write_nsi(opj_j3d_t *j3d) {
int i;
int lenp, len;
int ndim = 3;
opj_cio_t *cio = j3d->cio;
opj_volume_t *volume = j3d->volume;
opj_cp_t *cp = j3d->cp;
cio_write(cio, J3D_MS_ZSI, 2); /* ZSI */
cio_write(cio, J3D_MS_NSI, 2); /* NSI */
lenp = cio_tell(cio);
cio_skip(cio, 2);
cio_write(cio, ndim, 1); /* Ndim */
cio_write(cio, volume->z1, 4); /* Zsiz */
cio_write(cio, volume->z0, 4); /* Z0siz */
cio_write(cio, cp->tdz, 4); /* ZTsiz */
@ -455,14 +465,17 @@ static void j3d_write_zsi(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len);
}
static void j3d_read_zsi(opj_j3d_t *j3d) {
static void j3d_read_nsi(opj_j3d_t *j3d) {
int ndim;
int len, i;
opj_cio_t *cio = j3d->cio;
opj_volume_t *volume = j3d->volume;
opj_cp_t *cp = j3d->cp;
len = cio_read(cio, 2); /* Lsiz */
len = cio_read(cio, 2); /* Lnsi */
ndim = cio_read(cio, 1); /* Ndim */
assert( ndim == 3 );
volume->z1 = cio_read(cio, 4); /* Zsiz */
volume->z0 = cio_read(cio, 4); /* Z0siz */
cp->tdz = cio_read(cio, 4); /* ZTsiz */
@ -767,9 +780,7 @@ static void j3d_write_com(opj_j3d_t *j3d) {
cio_write(cio, J3D_MS_COM, 2);
lenp = cio_tell(cio);
cio_skip(cio, 2);
/*cio_write(cio, 0, 2);*/
cio_write(cio, j3d->cp->transform_format,1);
cio_write(cio, j3d->cp->encoding_format,1);
cio_write(cio, 1, 2);
/*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/
if (j3d->cp->comment != NULL) {
char *comment = j3d->cp->comment;
@ -788,9 +799,8 @@ static void j3d_read_com(opj_j3d_t *j3d) {
opj_cio_t *cio = j3d->cio;
len = cio_read(cio, 2);
cio_read(cio, 2); // read registration
j3d->cp->transform_format = (OPJ_TRANSFORM) cio_read(cio, 1);
j3d->cp->encoding_format = (OPJ_ENTROPY_CODING) cio_read(cio, 1);
/*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/
cio_skip(cio, len - 4); /*posible comments*/
@ -798,6 +808,7 @@ static void j3d_read_com(opj_j3d_t *j3d) {
static void j3d_write_cox(opj_j3d_t *j3d, int compno) {
int i;
int shift = 2;
opj_cp_t *cp = j3d->cp;
opj_tcp_t *tcp = &cp->tcps[j3d->curtileno];
@ -809,11 +820,15 @@ static void j3d_write_cox(opj_j3d_t *j3d, int compno) {
cio_write(cio, tccp->numresolution[1] - 1, 1); /* SPcox (E) No of decomposition levels in y-axis*/
cio_write(cio, tccp->numresolution[2] - 1, 1); /* SPcox (F) No of decomposition levels in z-axis*/
}
/* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/
cio_write(cio, tccp->cblk[0] - 2, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/
cio_write(cio, tccp->cblk[1] - 2, 1); /* SPcox (H) Cblk height*/
if (j3d->cinfo->codec_format == CODEC_J3D) {
cio_write(cio, tccp->cblk[2] - 2, 1); /* SPcox (I) Cblk depth*/
/* Table A.7 */
shift = 0;
}
/* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/
cio_write(cio, tccp->cblk[0] - shift, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/
cio_write(cio, tccp->cblk[1] - shift, 1); /* SPcox (H) Cblk height*/
if (j3d->cinfo->codec_format == CODEC_J3D) {
cio_write(cio, tccp->cblk[2] - shift, 1); /* SPcox (I) Cblk depth*/
}
cio_write(cio, tccp->cblksty, 1); /* SPcox (J) Cblk style*/
cio_write(cio, tccp->dwtid[0], 1); /* SPcox (K) WT in x-axis 15444-2 Table A10*/
@ -836,6 +851,7 @@ static void j3d_write_cox(opj_j3d_t *j3d, int compno) {
static void j3d_read_cox(opj_j3d_t *j3d, int compno) {
int i;
int shift = 2;
opj_cp_t *cp = j3d->cp;
opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp;
@ -855,10 +871,14 @@ static void j3d_read_cox(opj_j3d_t *j3d, int compno) {
cp->reduce[1] = int_min((tccp->numresolution[1])-1, cp->reduce[1]);
cp->reduce[2] = int_min((tccp->numresolution[2])-1, cp->reduce[2]);
tccp->cblk[0] = cio_read(cio, 1) + 2; /* SPcox (G) */
tccp->cblk[1] = cio_read(cio, 1) + 2; /* SPcox (H) */
if (j3d->cinfo->codec_format == CODEC_J3D) {
/* Table A.7 */
shift = 0;
}
tccp->cblk[0] = cio_read(cio, 1) + shift; /* SPcox (G) */
tccp->cblk[1] = cio_read(cio, 1) + shift; /* SPcox (H) */
if (j3d->cinfo->codec_format == CODEC_J3D)
tccp->cblk[2] = cio_read(cio, 1) + 2; /* SPcox (I) */
tccp->cblk[2] = cio_read(cio, 1) + shift; /* SPcox (I) */
else
tccp->cblk[2] = tccp->cblk[0];
@ -1545,7 +1565,7 @@ opj_dec_mstabent_t j3d_dec_mstab[] = {
{J3D_MS_EOC, J3D_STATE_TPHSOT, j3d_read_eoc},
{J3D_MS_CAP, J3D_STATE_MHSIZ, j3d_read_cap},
{J3D_MS_SIZ, J3D_STATE_MHSIZ, j3d_read_siz},
{J3D_MS_ZSI, J3D_STATE_MHSIZ, j3d_read_zsi},
{J3D_MS_NSI, J3D_STATE_MHSIZ, j3d_read_nsi},
{J3D_MS_COD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cod},
{J3D_MS_COC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_coc},
{J3D_MS_RGN, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_rgn},
@ -1665,8 +1685,9 @@ void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) {
cp->layer = parameters->cp_layer;
cp->bigendian = parameters->bigendian;
cp->encoding_format = ENCOD_2EB;
/* MM: Settings of the following two member variables would take
place during j3d_read_com. FIXME */
cp->encoding_format = ENCOD_3EB;
cp->transform_format = TRF_2D_DWT;
/* keep a link to cp so that we can destroy it later in j3d_destroy_decompress */
@ -2243,8 +2264,12 @@ bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *inde
j3d_write_siz(j3d);
if (j3d->cinfo->codec_format == CODEC_J3D) {
j3d_write_cap(j3d);
j3d_write_zsi(j3d);
j3d_write_nsi(j3d);
}
/*if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB)*/
j3d_write_com(j3d);
j3d_write_cod(j3d);
j3d_write_qcd(j3d);
for (compno = 0; compno < volume->numcomps; compno++) {
@ -2258,9 +2283,6 @@ bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *inde
if (j3d->volume->comps[0].dcoffset != 0)
j3d_write_dco(j3d);
if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB)
j3d_write_com(j3d);
/* INDEX >> */
if(volume_info && volume_info->index_on) {
volume_info->main_head_end = cio_tell(cio) - 1;

2
src/lib/openjp3d/jp3d.h Executable file → Normal file
View File

@ -65,7 +65,7 @@ The functions in J3D.C have for goal to read/write the several parts of the code
#define J3D_MS_EOC 0xffd9 /**< EOC marker value */
#define J3D_MS_CAP 0xff50 /**< CAP marker value */
#define J3D_MS_SIZ 0xff51 /**< SIZ marker value */
#define J3D_MS_ZSI 0xff54 /**< ZSI marker value */
#define J3D_MS_NSI 0xff54 /**< NSI marker value */
#define J3D_MS_COD 0xff52 /**< COD marker value */
#define J3D_MS_COC 0xff53 /**< COC marker value */
#define J3D_MS_RGN 0xff5e /**< RGN marker value */

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

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

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

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

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

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

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

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

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

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

@ -358,13 +358,16 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
comp = &pi->comps[pi->compno];
pi->dx = 0;
pi->dy = 0;
pi->dz = 0;
for (resno = 0; resno < comp->numresolution[0]; resno++) {
int dx, dy;
int dx, dy, dz;
res = &comp->resolutions[resno];
dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolution[0] - 1 - resno));
dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno));
dz = comp->dz * (1 << (res->pdz + comp->numresolution[2] - 1 - resno));
pi->dx = !pi->dx ? dx : int_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : int_min(pi->dy, dy);
pi->dz = !pi->dz ? dz : int_min(pi->dz, dz);
}
for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) {
for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) {

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

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

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

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

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

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

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

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

@ -479,6 +479,7 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
if (tcp->csty & J3D_CP_CSTY_EPH) {
if ((*hd) != 0xff || (*(hd + 1) != 0x92)) {
opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n");
return -999;
} else {
hd += 2;
}

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

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

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

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

@ -68,6 +68,7 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) {
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;
@ -108,38 +109,32 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) {
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;
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]*nplz[i];
k = nplh[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;
if(--k >= 0) {
node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/
++node; ++n;
++node;
}
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;
++parentnode;
}
if((j & 1) || j == nplv[i] - 1) {
parentnode0 = parentnode; p0 = p; /*fprintf(stdout,"parent = node[%d] \n",p);*/
parentnode0 = parentnode;
} else {
parentnode = parentnode0; p = p0; /*fprintf(stdout,"parent = node[%d] \n",p);*/
parentnode0 += nplh[i]*nplz[i]; p0 += nplh[i]*nplz[i];
parentnode = parentnode0;
}
}
if ((z & 1) || z == nplz[i] - 1) {
parentnode1 = parentnode;
} else {
parentnode0 = parentnode1;
parentnode = parentnode1;
}
}
}

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

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

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

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