Compare commits

..

3 Commits

Author SHA1 Message Date
Antonin Descampe
7d97b181d3 update OpenJPEGCPack.cmake with correct package names 2012-02-07 22:10:09 +00:00
Antonin Descampe
d9b74ea6a8 [tag1.5] add CHANGES to the 1.5 tagged version 2012-02-07 10:45:12 +00:00
Antonin Descampe
166b42eb54 New tag for openjpeg-1.5 release 2012-02-07 10:37:49 +00:00
149 changed files with 15963 additions and 16251 deletions

1465
CHANGES

File diff suppressed because it is too large Load Diff

View File

@@ -28,7 +28,5 @@ SET(CTEST_CUSTOM_WARNING_EXCEPTION
# Suppress warning caused by intentional messages about deprecation
".*warning,.* is deprecated"
# supress warnings caused by 3rd party libs:
".*thirdparty.*"
"libtiff.*has no symbols"
"libpng.*has no symbols"
".*/thirdparty/.*"
)

View File

@@ -17,4 +17,4 @@ ELSE(FCGI_FOUND)
SET(FCGI_INCLUDE_DIRS)
ENDIF(FCGI_FOUND)
MARK_AS_ADVANCED(FCGI_INCLUDE_DIR FCGI_LIBRARY)
MARK_AS_ADVANCED(FCGI_INCLUDE_DIRS FCGI_LIBRARIES)

20
CMake/FindPTHREAD.cmake Normal file
View File

@@ -0,0 +1,20 @@
# Look for the header file.
FIND_PATH(PTHREAD_INCLUDE_DIR NAMES pthread.h)
# Look for the library.
FIND_LIBRARY(PTHREAD_LIBRARY NAMES pthread)
# Handle the QUIETLY and REQUIRED arguments and set PTHREAD_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PTHREAD DEFAULT_MSG PTHREAD_LIBRARY PTHREAD_INCLUDE_DIR)
# Copy the results to the output variables.
IF(PTHREAD_FOUND)
SET(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY})
SET(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR})
ELSE(PTHREAD_FOUND)
SET(PTHREAD_LIBRARIES)
SET(PTHREAD_INCLUDE_DIRS)
ENDIF(PTHREAD_FOUND)
MARK_AS_ADVANCED(PTHREAD_INCLUDE_DIRS PTHREAD_LIBRARIES)

View File

@@ -11,28 +11,22 @@ SET(OPENJPEG_MINOR_VERSION "@OPENJPEG_VERSION_MINOR@")
SET(OPENJPEG_BUILD_VERSION "@OPENJPEG_VERSION_BUILD@")
# The libraries.
SET(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARY_NAME@")
SET(OPENJPEG_LIBRARIES "@OPENJPEG_LIBRARIES@")
# The CMake macros dir.
SET(OPENJPEG_CMAKE_DIR "@OPENJPEG_INSTALL_PACKAGE_DIR@")
SET(OPENJPEG_CMAKE_DIR "@OPENJPEG_CMAKE_DIR_CONFIG@")
# The configuration options.
SET(OPENJPEG_BUILD_SHARED_LIBS "@BUILD_SHARED_LIBS@")
SET(OPENJPEG_BUILD_SHARED_LIBS "@OPENJPEG_BUILD_SHARED_LIBS@")
# The "use" file.
SET(OPENJPEG_USE_FILE "@OPENJPEG_USE_FILE_CONFIG@")
get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
# The following is inspired from:
# http://www.cmake.org/Wiki/CMake/Tutorials/Packaging#Packaging_and_Exporting
# However the following is difficult to handle:
# get_filename_component(myproj_INCLUDE_DIRS "${SELF_DIR}/../../include/myproj" ABSOLUTE)
# it asssumes a non multi-arch system, where 'include' is located '../include' from lib
# therefore we need to take into account the number of subdirs in OPENJPEG_INSTALL_LIB_DIR
if(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)
# This is an install tree
include(${SELF_DIR}/OpenJPEGTargets.cmake)
get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/@relative_parent@/@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE)
get_filename_component(OPENJPEG_INCLUDE_ROOT "${SELF_DIR}/../../@OPENJPEG_INSTALL_INCLUDE_DIR@" ABSOLUTE)
set(OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_ROOT})
else(EXISTS ${SELF_DIR}/OpenJPEGTargets.cmake)

View File

@@ -29,32 +29,14 @@ INCLUDE_REGULAR_EXPRESSION("^.*$")
# OPENJPEG version number, useful for packaging and doxygen doc:
SET(OPENJPEG_VERSION_MAJOR 1)
SET(OPENJPEG_VERSION_MINOR 5)
SET(OPENJPEG_VERSION_BUILD 2)
SET(OPENJPEG_VERSION_BUILD 0)
SET(OPENJPEG_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
SET(PACKAGE_VERSION
"${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
# Because autotools does not support X.Y notation for SOVERSION, we have to use
# two numerorations, one for the openjpeg version and one for openjpeg soversion
# version | soversion
# 1.0 | 0
# 1.1 | 1
# 1.2 | 2
# 1.3 | 3
# 1.4 | 4
# 1.5 | 5
# 1.5.1 | 5
# 2.0 | 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 5)
endif(NOT OPENJPEG_SOVERSION)
SET(OPENJPEG_LIBRARY_PROPERTIES
VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
SOVERSION "${OPENJPEG_SOVERSION}"
SOVERSION "${OPENJPEG_VERSION_MAJOR}"
)
# --------------------------------------------------------------------------
@@ -104,18 +86,6 @@ IF(NOT OPENJPEG_INSTALL_LIB_DIR)
SET(OPENJPEG_INSTALL_LIB_DIR "lib")
ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
# The following will compute the amount of parent dir to go
# from include to lib. it works nicely with
# OPENJPEG_INSTALL_LIB_DIR=lib
# OPENJPEG_INSTALL_LIB_DIR=lib/
# OPENJPEG_INSTALL_LIB_DIR=/lib
# OPENJPEG_INSTALL_LIB_DIR=lib/gnu-linux-x64
STRING(REPLACE "/" ";" relative_to_lib ${OPENJPEG_INSTALL_LIB_DIR})
set(relative_parent "..")
foreach( elem ${relative_to_lib})
set( relative_parent "${relative_parent}/.." )
endforeach()
IF(NOT OPENJPEG_INSTALL_SHARE_DIR)
SET(OPENJPEG_INSTALL_SHARE_DIR "share")
ENDIF(NOT OPENJPEG_INSTALL_SHARE_DIR)
@@ -125,7 +95,7 @@ IF(NOT OPENJPEG_INSTALL_DATA_DIR)
ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/")
ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
IF(NOT OPENJPEG_INSTALL_MAN_DIR)
@@ -136,19 +106,8 @@ IF(NOT OPENJPEG_INSTALL_DOC_DIR)
SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
if(NOT OPENJPEG_INSTALL_JNI_DIR)
if(WIN32)
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
else()
set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
endif()
endif()
IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
# We could install *.cmake files in share/ however those files contains
# hardcoded path to libraries on a multi-arch system (fedora/debian) those
# path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
SET(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
SET(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
#-----------------------------------------------------------------------------
@@ -184,14 +143,13 @@ ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
#-----------------------------------------------------------------------------
# pkgconfig support
IF(UNIX)
# install in lib and not share (see multi-arch note above)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libopenjpeg1.pc.cmake
${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc @ONLY)
INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc DESTINATION
${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
${OPENJPEG_INSTALL_SHARE_DIR}/pkgconfig )
INSTALL( CODE "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink
\"libopenjpeg1.pc\"
\"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_SHARE_DIR}/pkgconfig/libopenjpeg.pc\")")
\"\$ENV{DESTDIR}${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig/libopenjpeg.pc\")")
ENDIF(UNIX)
#-----------------------------------------------------------------------------
@@ -233,8 +191,6 @@ IF(BUILD_JPIP)
ENDIF(BUILD_JPIP)
OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
OPTION(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
OPTION(USE_SYSTEM_GETOPT "Prefer system installed getopt()" OFF)
MARK_AS_ADVANCED(USE_SYSTEM_GETOPT)
MARK_AS_ADVANCED(BUILD_VIEWER)
MARK_AS_ADVANCED(BUILD_JAVA)
@@ -272,9 +228,9 @@ 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
${CMAKE_SOURCE_DIR}/../../data
NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
PATHS
$ENV{OPJ_DATA_ROOT}
${CMAKE_SOURCE_DIR}/../data
)
# Add repository where to find tests
@@ -298,9 +254,9 @@ INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
#-----------------------------------------------------------------------------
# install CHANGES and LICENSE
IF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
INSTALL(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
ENDIF(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
INSTALL(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
INSTALL(
FILES CHANGES
LICENSE
DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
INCLUDE (CMake/OpenJPEGCPack.cmake)

View File

@@ -66,12 +66,11 @@ Type:
If you are root:
make install
make clean
else if you have sudo power:
else:
sudo make install
else
DESTDIR=$HOME/local make install
make clean
To build the Doxygen documentation (Doxygen needs to be found on the system):
(A 'html' directory is generated in the 'doc' directory)
@@ -80,7 +79,7 @@ To build the Doxygen documentation (Doxygen needs to be found on the system):
Binaries are located in the 'bin' directory.
Main available cmake flags:
* To specify the install path: '-DCMAKE_INSTALL_PREFIX=/path', or use DESTDIR env variable (see above)
* To specify the install path: '-DCMAKE_INSTALL_PREFIX=/path'
* To build the shared libraries and links the executables against it: '-DBUILD_SHARED_LIBS:bool=on' (default: 'ON')
Note: when using this option, static libraries are not built and executables are dynamically linked.
* To build the CODEC executables: '-DBUILD_CODEC:bool=on' (default: 'ON')

35
NEWS
View File

@@ -2,24 +2,33 @@
OpenJPEG NEWS - user visible changes
====================================
Changes from OpenJPEG 1.5.2 to OpenJPEG 1.5.1
Changes from OpenJPEG 1.4.0 to OpenJPEG 1.5.0
----------------------------------------------
Security:
* Fixes: CVE-2013-4289 CVE-2013-4290
* Fixes: CVE-2013-1447 CVE-2013-6045 CVE-2013-6052 CVE-2013-6054 CVE-2013-6053 CVE-2013-6887
New Features:
* Compile Java with source/target specific java version
* Do not set SONAME for Java module, fix linking (missing math lib)
* Support some BMP/RGB8 files
* Fix compilation on ARM
* openjpip:
- complete client-server architecture for remote browsing of jpeg 2000 images.
- located in 'applications/jpip'.
- see corresponding README for more details.
API modifications:
* 'bool' type has been replaced by 'opj_bool' type. 'stdbool.h' is no more required.
Misc:
* Remove BSD-4 license from getopt copy, since upstream switched to BSD-3
* Support compilation against system installed getopt
* Fix Big Endian checking (autotools)
* added this NEWS file.
* improved cmake and autotools build methods.
* removed manual makefiles, VS project files and XCode project files.
* added a 'thirdparty' directory to contain all dependencies.
- These libraries will be build only if there are not found on the system.
- Note that libopenjpeg itself does not have any dependency.
* changed the directory hierarchy of the whole project. See README files for details.
* tests : a complete test suite has been setup.
- both JPEG 2000 conformance tests and non-regressions tests are configured.
- results are submitted to the OpenJPEG dashboard (http://my.cdash.org/index.php?project=OPENJPEG)
- images are located in 'http://openjpeg.googlecode.com/svn/data' folder.
- configuration files and utilities are located in 'tests' folder.
* OPJViewer re-activated (need wxWidgets)
* Huge amount of bug fixes. See CHANGES for details.

View File

@@ -4,10 +4,6 @@
SET(openjpegjni_SRCS
JavaOpenJPEGDecoder.c
JavaOpenJPEG.c
${OPENJPEG_SOURCE_DIR}/applications/codec/index.c
${OPENJPEG_SOURCE_DIR}/applications/codec/convert.c
#${OPENJPEG_SOURCE_DIR}/applications/common/color.c
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
# JNI binding:
@@ -24,19 +20,6 @@ include_directories(
add_library(openjpegjni MODULE
${openjpegjni_SRCS}
)
# Java module should not have a SONAME:
set_property(TARGET openjpegjni PROPERTY NO_SONAME 1)
TARGET_LINK_LIBRARIES(openjpegjni ${OPENJPEG_LIBRARY_NAME})
if(UNIX)
target_link_libraries(openjpegjni m)
endif()
INSTALL(TARGETS openjpegjni
EXPORT OpenJPEGTargets
LIBRARY DESTINATION ${OPENJPEG_INSTALL_JNI_DIR} COMPONENT Libraries
)
# build jar:
FIND_PACKAGE(Java 1.5 REQUIRED) # javac, jar
@@ -62,7 +45,3 @@ ADD_CUSTOM_TARGET(OpenJPEGJavaJar ALL
DEPENDS ${LIBRARY_OUTPUT_PATH}/openjpeg.jar
COMMENT "building openjpeg.jar"
)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/openjpeg.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule
)

View File

@@ -57,7 +57,7 @@
extern int get_file_format(char *filename);
extern void error_callback(const char *msg, void *client_data);
extern void warning_callback(const char *msg, void *client_data);
extern warning_callback(const char *msg, void *client_data);
extern void info_callback(const char *msg, void *client_data);
typedef struct callback_variables {
@@ -349,11 +349,10 @@ OPJ_PROG_ORDER give_progression(char progression[4]) {
return PROG_UNKNOWN;
}
/*
* <summary>
* Get logarithm of an integer and round downwards.
* </summary>
*/
/// <summary>
/// Get logarithm of an integer and round downwards.
/// </summary>
int int_floorlog2(int a) {
int l;
for (l=0; a>1; l++) {
@@ -495,7 +494,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
/* ------------------------------------------------------------------------------------ */
int parse_cmdline_encoder(int argc, char * const argv[], opj_cparameters_t *parameters,
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, char *indexfilename) {
int i, j,totlen;
opj_option_t long_option[]={
@@ -629,8 +628,6 @@ int parse_cmdline_encoder(int argc, char * const argv[], opj_cparameters_t *para
numresolution = parameters->numresolution;
matrix_width = numresolution * 3;
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
if(parameters->cp_matrice == NULL) return 1;
s = s + 2;
for (i = 0; i < numlayers; i++) {
@@ -859,9 +856,6 @@ int parse_cmdline_encoder(int argc, char * const argv[], opj_cparameters_t *para
case 'C': /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment == NULL) return 1;
if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg);
}
@@ -891,9 +885,6 @@ int parse_cmdline_encoder(int argc, char * const argv[], opj_cparameters_t *para
case 'z': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
if(img_fol->imgdirpath == NULL) return 1;
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
@@ -1361,7 +1352,7 @@ char* create_index_into_byte_array(opj_codestream_info_t *cstr_info, int* buffer
}
}
/* Compute the size of the index buffer, in number of bytes*/
// Compute the size of the index buffer, in number of bytes*/
*buffer_size =
1 /* version */
+ (10 /* image_w until decomposition */
@@ -1370,18 +1361,18 @@ char* create_index_into_byte_array(opj_codestream_info_t *cstr_info, int* buffer
+ cstr_info->tw * cstr_info->th * 4 /* tile info, without distorsion info */
+ cstr_info->tw*cstr_info->th * cstr_info->numlayers * (cstr_info->numdecompos[0] + 1) * cstr_info->numcomps * prec_max *8
) * sizeof(int);
/*printf("C: index buffer size = %d bytes\n", *buffer_size); */
//printf("C: index buffer size = %d bytes\n", *buffer_size);
buffer = (char*) malloc(*buffer_size);
if (!buffer) {
/* opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to allocate index buffer for writing %d int\n", *buffer_size); */
//opj_event_msg(j2k->cinfo, EVT_ERROR, "failed to allocate index buffer for writing %d int\n", *buffer_size);
fprintf(stderr, "failed to allocate index buffer for writing %d int\n", *buffer_size);
return 0;
}
buffer[0] = 1; /* Version stored on a byte */
buffer[0] = 1; // Version stored on a byte
buffer++;
/* Remaining informations are stored on a int. */
// Remaining informations are stored on a int.
((int*)buffer)[buffer_pos++] = cstr_info->image_w;
((int*)buffer)[buffer_pos++] = cstr_info->image_h;
((int*)buffer)[buffer_pos++] = cstr_info->prog;
@@ -1606,7 +1597,7 @@ char* create_index_into_byte_array(opj_codestream_info_t *cstr_info, int* buffer
} /* tileno */
if (buffer_pos > *buffer_size) {
/* opj_event_msg(j2k->cinfo, EVT_ERROR, "index creation: buffer_pos (%d) > buffer_size (%d)!\n", buffer_pos, *buffer_size); */
//opj_event_msg(j2k->cinfo, EVT_ERROR, "index creation: buffer_pos (%d) > buffer_size (%d)!\n", buffer_pos, *buffer_size);
fprintf(stderr, "index creation: buffer_pos (%d) > buffer_size (%d)!\n", buffer_pos, *buffer_size);
return 0;
}
@@ -1639,7 +1630,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
jint *jiBody;
jboolean isCopy;
/* Image width, height and depth */
// Image width, height and depth
fid = (*env)->GetFieldID(env, cls,"width", "I");
ji = (*env)->GetIntField(env, obj, fid);
w = ji;
@@ -1652,7 +1643,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
ji = (*env)->GetIntField(env, obj, fid);
depth = ji;
/* Read the image */
// Read the image
if (depth <=16) {
numcomps = 1;
color_space = CLRSPC_GRAY;
@@ -1667,10 +1658,8 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
cmptparm[0].y0 = parameters->image_offset_y0;
cmptparm[0].w = !cmptparm[0].x0 ? (w - 1) * parameters->subsampling_dx + 1 : cmptparm[0].x0 + (w - 1) * parameters->subsampling_dx + 1;
cmptparm[0].h = !cmptparm[0].y0 ? (h - 1) * parameters->subsampling_dy + 1 : cmptparm[0].y0 + (h - 1) * parameters->subsampling_dy + 1;
/* Java types are always signed but we use them as unsigned types
* (shift of the negative part of the pixels of the images in
* Telemis before entering the encoder).
*/
// Java types are always signed but we use them as unsigned types (shift of the negative part of
// the pixels of the images in Telemis before entering the encoder).
cmptparm[0].sgnd = 0;
if (depth<=16)
cmptparm[0].prec=depth;
@@ -1716,12 +1705,12 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
comp = &image->comps[compno];
max = -100000;
if (depth == 8) {
fid = (*env)->GetFieldID(env, cls,"image8", "[B");/* byteArray []*/
fid = (*env)->GetFieldID(env, cls,"image8", "[B"); // byteArray []
jba = (*env)->GetObjectField(env, obj, fid);
len = (*env)->GetArrayLength(env, jba);
jbBody = (*env)->GetPrimitiveArrayCritical(env, jba, &isCopy);
/* printf("C: before transfering 8 bpp image\n"); */
//printf("C: before transfering 8 bpp image\n");
if (comp->sgnd) {
for(i=0; i< len;i++) {
comp->data[i] = (char) jbBody[i];
@@ -1735,14 +1724,13 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
}
(*env)->ReleasePrimitiveArrayCritical(env, jba, jbBody, 0);
} else if(depth == 16) {
fid = (*env)->GetFieldID(env, cls,"image16", "[S");/*shortArray []*/
fid = (*env)->GetFieldID(env, cls,"image16", "[S"); // shortArray []
jsa = (*env)->GetObjectField(env, obj, fid);
len = (*env)->GetArrayLength(env, jsa);
jsBody = (*env)->GetPrimitiveArrayCritical(env, jsa, &isCopy);
/*printf("C: before transfering 16 bpp image\n"); */
if (comp->sgnd) {
/* Special behaviour to deal with signed elements ?? */
//printf("C: before transfering 16 bpp image\n");
if (comp->sgnd) { // Special behaviour to deal with signed elements ??
comp->data[i] = (short) jsBody[i];
for(i=0; i< len;i++) {
if (comp->data[i] > max) max = comp->data[i];
@@ -1755,15 +1743,14 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
}
(*env)->ReleasePrimitiveArrayCritical(env, jsa, jsBody, 0);
} else if (depth == 24) {
fid = (*env)->GetFieldID(env, cls,"image24", "[I");/* intArray []*/
fid = (*env)->GetFieldID(env, cls,"image24", "[I"); // intArray []
jia = (*env)->GetObjectField(env, obj, fid);
len = (*env)->GetArrayLength(env, jia);
shift = compno*8;
jiBody = (*env)->GetPrimitiveArrayCritical(env, jia, &isCopy);
/*printf("C: before transfering 24 bpp image (component %d, signed = %d)\n", compno, comp->sgnd);*/
if (comp->sgnd) {
/* Special behaviour to deal with signed elements ?? XXXXX */
//printf("C: before transfering 24 bpp image (component %d, signed = %d)\n", compno, comp->sgnd);
if (comp->sgnd) { // Special behaviour to deal with signed elements ?? XXXXX
for(i=0; i< len;i++) {
comp->data[i] = ( ((int) jiBody[i]) & (0xFF << shift) ) >> shift;
if (comp->data[i] > max) max = comp->data[i];
@@ -1778,7 +1765,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
}
comp->bpp = int_floorlog2(max)+1;
comp->prec = comp->bpp;
/*printf("C: component %d: max %d, real bpp = %d\n", compno, max, comp->bpp);*/
//printf("C: component %d: max %d, real bpp = %d\n", compno, max, comp->bpp);
}
return image;
}
@@ -1788,7 +1775,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImageToJ2K(JNIEnv *env, jobject obj, jobjectArray javaParameters) {
int argc; /* To simulate the command line parameters (taken from the javaParameters variable) and be able to re-use the */
const char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
opj_bool bSuccess;
opj_cparameters_t parameters; /* compression parameters */
img_fol_t img_fol;
@@ -1801,7 +1788,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
int* compressed_index = NULL;
int compressed_index_size=-1;
/* ==> Access variables to the Java member variables */
// ==> Access variables to the Java member variables
jsize arraySize;
jclass cls;
jobject object;
@@ -1810,20 +1797,18 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
jbyteArray jba;
jbyte *jbBody;
callback_variables_t msgErrorCallback_vars;
/* <== access variable to the Java member variables. */
jlong retval = -1;
/* For the encoding and storage into the file */
// <== access variable to the Java member variables.
// For the encoding and storage into the file
opj_cinfo_t* cinfo;
int codestream_length = -1;
int codestream_length;
opj_cio_t *cio = NULL;
FILE *f = NULL;
/* JNI reference to the calling class */
// JNI reference to the calling class
cls = (*env)->GetObjectClass(env, obj);
/* Pointers to be able to call a Java method
* for all the info and error messages
*/
// Pointers to be able to call a Java method for all the info and error messages
msgErrorCallback_vars.env = env;
msgErrorCallback_vars.jobj = &obj;
msgErrorCallback_vars.message_mid = (*env)->GetMethodID(env, cls, "logMessage", "(Ljava/lang/String;)V");
@@ -1831,11 +1816,8 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
arraySize = (*env)->GetArrayLength(env, javaParameters);
argc = (int) arraySize +1;
argv = (const char **)malloc(argc*sizeof(char*));
if(argv == NULL) return -1;
argv[0] = "ProgramName.exe";/* The program name: useless */
argv = malloc(argc*sizeof(char*));
argv[0] = "ProgramName.exe"; // The program name: useless
j=0;
for (i=1; i<argc; i++) {
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
@@ -1859,21 +1841,23 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);
parameters.cod_format = J2K_CFMT;
/* parameters.index_on = 1; */
//parameters.index_on = 1;
/* Initialize indexfilename and img_fol */
*indexfilename = 0;
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
j = parse_cmdline_encoder(argc, (char *const*)argv, &parameters,&img_fol, indexfilename);
/* Release the Java arguments array */
if (parse_cmdline_encoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
// Release the Java arguments array
for (i=1; i<argc; i++)
(*env)->ReleaseStringUTFChars(env,
(*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
(*env)->ReleaseStringUTFChars(env, (*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
return -1;
}
if(j == 1) goto fin; /* failure */
// Release the Java arguments array
for (i=1; i<argc; i++)
(*env)->ReleaseStringUTFChars(env, (*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
if (parameters.cp_cinema){
cinema_parameters(&parameters);
@@ -1888,15 +1872,9 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
/* UniPG>> */
#ifdef USE_JPWL
parameters.cp_comment = (char*)malloc(clen+strlen(version)+11);
if(parameters.cp_comment == NULL) goto fin;
sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version);
#else
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
if(parameters.cp_comment == NULL) goto fin;
sprintf(parameters.cp_comment,"%s%s", comment, version);
#endif
/* <<UniPG */
@@ -1913,10 +1891,10 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
fprintf(stderr,"\n");
image = loadImage(&parameters, env, obj, cls);
/* printf("C: after load image: image = %d\n", image); */
//printf("C: after load image: image = %d\n", image);
if (!image) {
fprintf(stderr, "Unable to load image\n");
goto fin;
return -1;
}
/* Decide if MCT should be used */
@@ -1950,7 +1928,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
goto fin;
return -1;
}
codestream_length = cio_tell(cio);
@@ -1962,8 +1940,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
}
}
compressed_index = (int*)
create_index_into_byte_array(&cstr_info, &compressed_index_size);
compressed_index = create_index_into_byte_array(&cstr_info, &compressed_index_size);
/* Allocates the Java compressedIndex byte[] and sends this index into the Java object */
fid = (*env)->GetFieldID(env, cls,"compressedIndex", "[B");
jba = (*env)->NewByteArray(env, compressed_index_size+1);
@@ -1978,7 +1955,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
f = fopen(parameters.outfile, "wb");
if (!f) {
fprintf(stderr, "failed to open [%s] for writing\n", parameters.outfile);
goto fin;
return -1;
}
fwrite(cio->buffer, 1, codestream_length, f);
fclose(f);
@@ -2007,10 +1984,5 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
if(parameters.cp_comment) free(parameters.cp_comment);
if(parameters.cp_matrice) free(parameters.cp_matrice);
retval = codestream_length;
fin:
free(argv);
return retval;
return codestream_length;
}

View File

@@ -203,7 +203,7 @@ int get_file_format(char *filename) {
/* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char * const argv[], opj_dparameters_t *parameters,img_fol_t *img_fol) {
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
/* parse the command line */
int totlen;
opj_option_t long_option[]={
@@ -339,9 +339,6 @@ int parse_cmdline_decoder(int argc, char * const argv[], opj_dparameters_t *para
case 'y': /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
if(img_fol->imgdirpath == NULL) return 1;
strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1;
}
@@ -429,7 +426,7 @@ int parse_cmdline_decoder(int argc, char * const argv[], opj_dparameters_t *para
/* No check for possible errors before the -i and -o options are of course not mandatory*/
return 0;
}/* parse_cmdline_decoder() */
}
/* -------------------------------------------------------------------------- */
@@ -491,13 +488,12 @@ void info_callback(const char *msg, void *client_data) {
(*env)->DeleteLocalRef(env, jbuffer);
}
#define FAILS -1
#define OK 0
/* --------------------------------------------------------------------------
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2KtoImage(JNIEnv *env, jobject obj, jobjectArray javaParameters) {
int argc; /* To simulate the command line parameters (taken from the javaParameters variable) and be able to re-use the */
const char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */
@@ -512,7 +508,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
int w,h;
long min_value, max_value;
short tempS; unsigned char tempUC, tempUC1, tempUC2;
/* ==> Access variables to the Java member variables */
// ==> Access variables to the Java member variables
jsize arraySize;
jclass cls;
jobject object;
@@ -525,9 +521,8 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
jshort *jsBody, *ptrSBody;
jint *jiBody, *ptrIBody;
callback_variables_t msgErrorCallback_vars;
/* <=== access variable to Java member variables */
int *ptr, *ptr1, *ptr2;/* <== To transfer the decoded image to Java */
jint retval = FAILS;
// <=== access variable to Java member variables */
int *ptr, *ptr1, *ptr2; // <== To transfer the decoded image to Java
/* configure the event callbacks */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
@@ -535,26 +530,20 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
/* JNI reference to the calling class */
// JNI reference to the calling class
cls = (*env)->GetObjectClass(env, obj);
/* Pointers to be able to call a Java method
* for all the info and error messages
*/
// Pointers to be able to call a Java method for all the info and error messages
msgErrorCallback_vars.env = env;
msgErrorCallback_vars.jobj = &obj;
msgErrorCallback_vars.message_mid = (*env)->GetMethodID(env, cls, "logMessage", "(Ljava/lang/String;)V");
msgErrorCallback_vars.error_mid = (*env)->GetMethodID(env, cls, "logError", "(Ljava/lang/String;)V");
/* Get the String[] containing the parameters */
// Get the String[] containing the parameters, and converts it into a char** to simulate command line arguments.
arraySize = (*env)->GetArrayLength(env, javaParameters);
argc = (int) arraySize +1;
argv = (const char **)malloc(argc*sizeof(char*));
if(argv == NULL) return FAILS;
argv[0] = "ProgramName.exe";/* The program name: useless */
argv = malloc(argc*sizeof(char*));
argv[0] = "ProgramName.exe"; // The program name: useless
j=0;
for (i=1; i<argc; i++) {
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
@@ -572,18 +561,19 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
parameters.decod_format = J2K_CFMT;
/* parse input and get user encoding parameters */
j = parse_cmdline_decoder(argc, (char * const*)argv, &parameters,&img_fol);
/* Release the Java arguments array */
if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
// Release the Java arguments array
for (i=1; i<argc; i++)
(*env)->ReleaseStringUTFChars(env,
(*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
if(j == 1) goto fin; /* failure */
(*env)->ReleaseStringUTFChars(env, (*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
return -1;
}
// Release the Java arguments array
for (i=1; i<argc; i++)
(*env)->ReleaseStringUTFChars(env, (*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
num_images=1;
/* Get additional information from the Java object variables */
// Get additional information from the Java object variables
fid = (*env)->GetFieldID(env, cls,"skippedResolutions", "I");
parameters.cp_reduce = (short) (*env)->GetIntField(env, obj, fid);
@@ -597,25 +587,22 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
Implemented for debug purpose. */
/* -------------------------------------------------------------- */
if (parameters.infile && parameters.infile[0]!='\0') {
/* printf("C: opening [%s]\n", parameters.infile); */
//printf("C: opening [%s]\n", parameters.infile);
fsrc = fopen(parameters.infile, "rb");
if (!fsrc) {
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
goto fin;
return 1;
}
fseek(fsrc, 0, SEEK_END);
file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length);
if(src == NULL) goto fin;
fread(src, 1, file_length, fsrc);
fclose(fsrc);
/* printf("C: %d bytes read from file\n",file_length); */
//printf("C: %d bytes read from file\n",file_length);
} else {
/* Preparing the transfer of the codestream from Java to C */
/* printf("C: before transfering codestream\n"); */
// Preparing the transfer of the codestream from Java to C
//printf("C: before transfering codestream\n");
fid = (*env)->GetFieldID(env, cls,"compressedStream", "[B");
jba = (*env)->GetObjectField(env, obj, fid);
file_length = (*env)->GetArrayLength(env, jba);
@@ -649,7 +636,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
goto fin;
return 1;
}
/* close the byte stream */
@@ -679,7 +666,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
goto fin;
return 1;
}
/* close the byte stream */
@@ -710,7 +697,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
opj_destroy_decompress(dinfo);
opj_cio_close(cio);
goto fin;
return 1;
}
/* close the byte stream */
@@ -765,21 +752,17 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
}
/* ========= Return the image to the Java structure =============== */
// ========= Return the image to the Java structure ===============
#ifdef CHECK_THRESHOLDS
printf("C: checking thresholds\n");
#endif
/* First compute the real with and height,
* in function of the resolutions decoded.
*/
/*---
wr = (image->comps[0].w + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;
hr = (image->comps[0].h + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;
---*/
// First compute the real with and height, in function of the resolutions decoded.
//wr = (image->comps[0].w + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;
//hr = (image->comps[0].h + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;
w = image->comps[0].w;
h = image->comps[0].h;
if (image->numcomps==3) { /* 3 components color image */
if (image->numcomps==3) { // 3 components color image
ptr = image->comps[0].data;
ptr1 = image->comps[1].data;
ptr2 = image->comps[2].data;
@@ -792,7 +775,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
max_value = 255;
}
#endif
/* Get the pointer to the Java structure where the data must be copied */
// Get the pointer to the Java structure where the data must be copied
fid = (*env)->GetFieldID(env, cls,"image24", "[I");
jia = (*env)->GetObjectField(env, obj, fid);
jiBody = (*env)->GetIntArrayElements(env, jia, 0);
@@ -821,7 +804,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
}
(*env)->ReleaseIntArrayElements(env, jia, jiBody, 0);
} else { /* 1 component 8 or 16 bpp image */
} else { // 1 component 8 or 16 bpp image
ptr = image->comps[0].data;
printf("C: before transfering a %d bpp image to java (length = %d)\n",image->comps[0].prec ,w*h);
if (image->comps[0].prec<=8) {
@@ -838,7 +821,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
max_value = 255;
}
#endif
/* printf("C: transfering %d shorts to Java image8 pointer = %d\n", wr*hr,ptrSBody); */
//printf("C: transfering %d shorts to Java image8 pointer = %d\n", wr*hr,ptrSBody);
for (i=0; i<w*h; i++) {
tempUC = (unsigned char) (ptr[i]);
#ifdef CHECK_THRESHOLDS
@@ -894,12 +877,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
opj_image_destroy(image);
}
retval = OK;
fin:
free(argv);
return retval;
return 1; /* OK */
}
/* end main MAIN */
//end main

View File

@@ -5,12 +5,8 @@ SET(common_SRCS
convert.c
index.c
${OPENJPEG_SOURCE_DIR}/applications/common/color.c
)
if(NOT USE_SYSTEM_GETOPT)
list(APPEND common_SRCS
${OPENJPEG_SOURCE_DIR}/applications/common/opj_getopt.c
)
endif()
# Headers file are located here:
INCLUDE_DIRECTORIES(

View File

@@ -78,7 +78,7 @@ JPWL_j2k_to_image_CPPFLAGS = \
@LCMS1_CFLAGS@ \
@LCMS2_CFLAGS@
JPWL_j2k_to_image_CFLAGS =
JPWL_j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@ -lm
JPWL_j2k_to_image_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @LCMS1_LIBS@ @LCMS2_LIBS@ @TIFF_LIBS@ @PNG_LIBS@
JPWL_j2k_to_image_SOURCES = \
../common/color.c \
../common/opj_getopt.c \
@@ -96,7 +96,7 @@ JPWL_image_to_j2k_CPPFLAGS = \
@TIFF_CFLAGS@ \
@PNG_CFLAGS@
JPWL_image_to_j2k_CFLAGS =
JPWL_image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @TIFF_LIBS@ @PNG_LIBS@ -lm
JPWL_image_to_j2k_LDADD = $(top_builddir)/libopenjpeg/jpwl/libopenjpeg_JPWL.la @TIFF_LIBS@ @PNG_LIBS@
JPWL_image_to_j2k_SOURCES = \
../common/opj_getopt.c \

View File

@@ -94,7 +94,7 @@ struct tga_header
static unsigned short get_ushort(unsigned short val) {
#ifdef OPJ_BIG_ENDIAN
#ifdef ORDER_BIGENDIAN
return( ((val & 0xff) << 8) + (val >> 8) );
#else
return( val );
@@ -104,7 +104,7 @@ static unsigned short get_ushort(unsigned short val) {
#define TGA_HEADER_SIZE 18
static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
unsigned int *width, unsigned int *height, int *flip_image)
{
int palette_size;
@@ -116,28 +116,23 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (!bits_per_pixel || !width || !height || !flip_image)
return 0;
tga = (unsigned char*)malloc(TGA_HEADER_SIZE);
tga = (unsigned char*)malloc(18);
if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
free(tga);
return 0 ;
}
id_len = (unsigned char)tga[0];
cmap_type = (unsigned char)tga[1];
(void)cmap_type;
image_type = (unsigned char)tga[2];
cmap_index = get_ushort(*(unsigned short*)(&tga[3]));
(void)cmap_index;
cmap_len = get_ushort(*(unsigned short*)(&tga[5]));
cmap_entry_size = (unsigned char)tga[7];
x_origin = get_ushort(*(unsigned short*)(&tga[8]));
(void)x_origin;
y_origin = get_ushort(*(unsigned short*)(&tga[10]));
(void)y_origin;
image_w = get_ushort(*(unsigned short*)(&tga[12]));
image_h = get_ushort(*(unsigned short*)(&tga[14]));
pixel_depth = (unsigned char)tga[16];
@@ -184,17 +179,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
return 1;
}
#ifdef OPJ_BIG_ENDIAN
static inline int16_t swap16(int16_t x)
{
return((((u_int16_t)x & 0x00ffU) << 8) |
(((u_int16_t)x & 0xff00U) >> 8));
}
#endif
static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
opj_bool flip_image)
{
unsigned short image_w, image_h, us0;
@@ -231,15 +216,8 @@ static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height,
image_w = (unsigned short)width;
image_h = (unsigned short) height;
#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
image_w = swap16(image_w);
image_h = swap16(image_h);
if(fwrite(&image_w, 2, 1, fp) != 1) goto fails;
if(fwrite(&image_h, 2, 1, fp) != 1) goto fails;
#endif
if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails;
@@ -276,16 +254,12 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
return 0;
}
if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image)) {
fclose(f);
if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image))
return NULL;
}
/* We currently only support 24 & 32 bit tga's ... */
if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32))) {
fclose(f);
if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32)))
return NULL;
}
/* initialize image components */
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
@@ -318,10 +292,8 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
/* create the image */
image = opj_image_create(numcomps, &cmptparm[0], color_space);
if (!image) {
fclose(f);
if (!image)
return NULL;
}
/* set image offset and reference grid */
image->x0 = parameters->image_offset_x0;
@@ -349,21 +321,18 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
@@ -382,28 +351,24 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
if ( !fread(&a, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
fclose(f);
return NULL;
}
@@ -418,7 +383,6 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
fprintf(stderr, "Currently unsupported bit depth : %s\n", filename);
}
}
fclose(f);
return image;
}
@@ -444,7 +408,6 @@ int imagetotga(opj_image_t * image, const char *outfile) {
||(image->comps[0].dy != image->comps[i+1].dy)
||(image->comps[0].prec != image->comps[i+1].prec)) {
fprintf(stderr, "Unable to create a tga file with such J2K image charateristics.");
fclose(fdest);
return 1;
}
}
@@ -457,10 +420,8 @@ int imagetotga(opj_image_t * image, const char *outfile) {
/* Write TGA header */
bpp = write_alpha ? 32 : 24;
if (!tga_writeheader(fdest, bpp, width , height, OPJ_TRUE)) {
fclose(fdest);
if (!tga_writeheader(fdest, bpp, width , height, OPJ_TRUE))
return 1;
}
alpha_channel = image->numcomps-1;
@@ -490,7 +451,6 @@ int imagetotga(opj_image_t * image, const char *outfile) {
res = fwrite(&value,1,1,fdest);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(fdest);
return 1;
}
@@ -498,7 +458,6 @@ int imagetotga(opj_image_t * image, const char *outfile) {
res = fwrite(&value,1,1,fdest);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(fdest);
return 1;
}
@@ -506,7 +465,6 @@ int imagetotga(opj_image_t * image, const char *outfile) {
res = fwrite(&value,1,1,fdest);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(fdest);
return 1;
}
@@ -516,14 +474,12 @@ int imagetotga(opj_image_t * image, const char *outfile) {
res = fwrite(&value,1,1,fdest);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(fdest);
return 1;
}
}
}
}
fclose(fdest);
return 0;
}
@@ -537,7 +493,7 @@ int imagetotga(opj_image_t * image, const char *outfile) {
typedef unsigned short int WORD;
/* DWORD defines a four byte word */
typedef unsigned int DWORD;
typedef unsigned long int DWORD;
typedef struct {
WORD bfType; /* 'BM' for Bitmap (19776) */
@@ -561,37 +517,6 @@ typedef struct {
DWORD biClrImportant; /* Number of important color (0: ALL) */
} BITMAPINFOHEADER_t;
struct bmp_cmap
{
unsigned char blue;
unsigned char green;
unsigned char red;
unsigned char alpha;
};
static void BMP_read_RGB8(int *red, int *green, int *blue, unsigned int line,
BITMAPINFOHEADER_t *hdr, struct bmp_cmap bmap[256], FILE *reader,
unsigned int offset)
{
unsigned int w, start_pos, y, x, pixel;
unsigned int i = 0;
w = hdr->biWidth;
start_pos = (((w * hdr->biBitCount + 31) & ~0x1f) >> 3);
y = hdr->biHeight - line - 1;
fseek(reader,offset + y * start_pos,SEEK_SET);
for(x = 0; x < w; ++x)
{
pixel = fgetc(reader);
red[i] = (unsigned char)bmap[pixel].red;
green[i] = (unsigned char)bmap[pixel].green;
blue[i] = (unsigned char)bmap[pixel].blue;
++i;
}
}
opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
{
int subsampling_dx = parameters->subsampling_dx;
@@ -658,7 +583,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
if(Info_h.biSize != 40)
{
fprintf(stderr,"Error, unknown BMP header size %d\n", Info_h.biSize);
fprintf(stderr,"Error, unknown BMP header size %ld\n", Info_h.biSize);
fclose(IN);
return NULL;
}
@@ -785,24 +710,37 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
else
if (Info_h.biBitCount == 8 && Info_h.biCompression == 0)/*RGB */
{
struct bmp_cmap cmap [256];
if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256;
else
if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256;
fseek(IN, 14+Info_h.biSize, SEEK_SET);
memset(&cmap, 0, sizeof(struct bmp_cmap) * 256);
table_R = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_G = (unsigned char *) malloc(256 * sizeof(unsigned char));
table_B = (unsigned char *) malloc(256 * sizeof(unsigned char));
has_color = 0;
for (j = 0; j < Info_h.biClrUsed; j++)
{
cmap[j].blue = (unsigned char)getc(IN);
cmap[j].green = (unsigned char)getc(IN);
cmap[j].red = (unsigned char)getc(IN);
table_B[j] = (unsigned char)getc(IN);
table_G[j] = (unsigned char)getc(IN);
table_R[j] = (unsigned char)getc(IN);
getc(IN);
has_color +=
!(table_R[j] == table_G[j] && table_R[j] == table_B[j]);
}
numcomps = 3;
color_space = CLRSPC_SRGB;
if(has_color) gray_scale = 0;
/* Place the cursor at the beginning of the image information */
fseek(IN, 0, SEEK_SET);
fseek(IN, File_h.bfOffBits, SEEK_SET);
W = Info_h.biWidth;
H = Info_h.biHeight;
if (Info_h.biWidth % 2)
W++;
numcomps = gray_scale ? 1 : 3;
color_space = gray_scale ? CLRSPC_GRAY : CLRSPC_SRGB;
/* initialize image components */
memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t));
for(i = 0; i < numcomps; i++)
@@ -820,6 +758,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
if(!image)
{
fclose(IN);
free(table_R); free(table_G); free(table_B);
return NULL;
}
@@ -829,21 +768,55 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1;
image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1;
{
int *red = image->comps[0].data;
int *green = image->comps[1].data;
int *blue = image->comps[2].data;
unsigned int offset = File_h.bfOffBits;
int line;
/* set image data */
for(line = 0; line < h; ++line)
{
BMP_read_RGB8(red, green, blue, line, &Info_h, cmap, IN, offset);
red += w; green += w; blue += w;
RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char));
if ( fread(RGB, sizeof(unsigned char), W * H, IN) != W * H )
{
free(table_R);
free(table_G);
free(table_B);
free(RGB);
opj_image_destroy(image);
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return NULL;
}
if (gray_scale)
{
index = 0;
for (j = 0; j < W * H; j++)
{
if ((j % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2))
{
image->comps[0].data[index] =
table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]];
index++;
}
}
}
else
{
index = 0;
for (j = 0; j < W * H; j++)
{
if ((j % W < W - 1 && Info_h.biWidth % 2)
|| !(Info_h.biWidth % 2))
{
unsigned char pixel_index =
RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)];
image->comps[0].data[index] = table_R[pixel_index];
image->comps[1].data[index] = table_G[pixel_index];
image->comps[2].data[index] = table_B[pixel_index];
index++;
}
}
}
free(RGB);
free(table_R);
free(table_G);
free(table_B);
}/* RGB8 */
else
if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)/*RLE8*/
@@ -1020,11 +993,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
FILE *fdest = NULL;
int adjustR, adjustG, adjustB;
if (image->comps[0].prec < 8) {
fprintf(stderr, "Unsupported precision: %d\n", image->comps[0].prec);
return 1;
}
if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx
if (image->numcomps == 3 && image->comps[0].dx == image->comps[1].dx
&& image->comps[1].dx == image->comps[2].dx
&& image->comps[0].dy == image->comps[1].dy
&& image->comps[1].dy == image->comps[2].dy
@@ -1135,11 +1104,6 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
<<-- <<-- <<-- <<-- */
fdest = fopen(outfile, "wb");
if (!fdest) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
return 1;
}
w = image->comps[0].w;
h = image->comps[0].h;
@@ -1217,7 +1181,7 @@ PGX IMAGE FORMAT
<<-- <<-- <<-- <<-- */
static unsigned char readuchar(FILE * f)
unsigned char readuchar(FILE * f)
{
unsigned char c1;
if ( !fread(&c1, 1, 1, f) )
@@ -1228,7 +1192,7 @@ static unsigned char readuchar(FILE * f)
return c1;
}
static unsigned short readushort(FILE * f, int bigendian)
unsigned short readushort(FILE * f, int bigendian)
{
unsigned char c1, c2;
if ( !fread(&c1, 1, 1, f) )
@@ -1247,7 +1211,7 @@ static unsigned short readushort(FILE * f, int bigendian)
return (c2 << 8) + c1;
}
static unsigned int readuint(FILE * f, int bigendian)
unsigned int readuint(FILE * f, int bigendian)
{
unsigned char c1, c2, c3, c4;
if ( !fread(&c1, 1, 1, f) )
@@ -1283,7 +1247,6 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
OPJ_COLOR_SPACE color_space;
opj_image_cmptparm_t cmptparm; /* maximum of 1 component */
opj_image_t * image = NULL;
int adjustS, ushift, dshift, force8;
char endian1,endian2,sign;
char signtmp[32];
@@ -1308,7 +1271,6 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
fseek(f, 0, SEEK_SET);
if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){
fprintf(stderr, "ERROR: Failed to read the right number of element from the fscanf() function!\n");
fclose(f);
return NULL;
}
@@ -1326,7 +1288,6 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
bigendian = 0;
} else {
fprintf(stderr, "Bad pgx header, please check input file\n");
fclose(f);
return NULL;
}
@@ -1342,16 +1303,6 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
} else {
cmptparm.sgnd = 0;
}
if(prec < 8)
{
force8 = 1;
ushift = 8 - prec; dshift = prec - ushift;
if(cmptparm.sgnd) adjustS = (1<<(prec - 1)); else adjustS = 0;
cmptparm.sgnd = 0;
prec = 8;
}
else ushift = dshift = force8 = adjustS = 0;
cmptparm.prec = prec;
cmptparm.bpp = prec;
cmptparm.dx = parameters->subsampling_dx;
@@ -1375,17 +1326,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
for (i = 0; i < w * h; i++) {
int v;
if(force8)
{
v = readuchar(f) + adjustS;
v = (v<<ushift) + (v>>dshift);
comp->data[i] = (unsigned char)v;
if(v > max) max = v;
continue;
}
if (comp->prec == 8) {
if (comp->prec <= 8) {
if (!comp->sgnd) {
v = readuchar(f);
} else {
@@ -1447,6 +1388,10 @@ int imagetopgx(opj_image_t * image, const char *outfile) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
return 1;
}
/* dont need name anymore */
if( total > 256 ) {
free(name);
}
w = image->comps[compno].w;
h = image->comps[compno].h;
@@ -1466,19 +1411,10 @@ int imagetopgx(opj_image_t * image, const char *outfile) {
res = fwrite(&byte, 1, 1, fdest);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", name);
if( total > 256 ) {
free(name);
}
fclose(fdest);
return 1;
}
}
}
/* dont need name anymore */
if( total > 256 ) {
free(name);
}
fclose(fdest);
}
@@ -2103,6 +2039,16 @@ int imagetopnm(opj_image_t * image, const char *outfile)
<<-- <<-- <<-- <<-- */
typedef struct tiff_infoheader{
DWORD tiWidth; /* Width of Image in pixel*/
DWORD tiHeight; /* Height of Image in pixel */
DWORD tiPhoto; /* Photometric */
WORD tiBps; /* Bits per sample */
WORD tiSf; /* Sample Format */
WORD tiSpp; /* Sample per pixel 1-bilevel,gray scale , 2- RGB */
WORD tiPC; /* Planar config (1-Interleaved, 2-Planarcomp) */
}tiff_infoheader_t;
int imagetotif(opj_image_t * image, const char *outfile)
{
int width, height, imgsize;
@@ -2474,6 +2420,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy;
TIFF *tif;
tiff_infoheader_t Info;
tdata_t buf;
tstrip_t strip;
tsize_t strip_size;
@@ -2483,8 +2430,6 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
opj_image_t *image = NULL;
int imgsize = 0;
int has_alpha = 0;
unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC;
unsigned int tiWidth, tiHeight;
tif = TIFFOpen(filename, "r");
@@ -2493,34 +2438,32 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename);
return 0;
}
tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0;
tiWidth = tiHeight = 0;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps);
TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp);
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto);
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC);
w= tiWidth;
h= tiHeight;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &Info.tiWidth);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &Info.tiHeight);
TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &Info.tiBps);
TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &Info.tiSf);
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &Info.tiSpp);
Info.tiPhoto = 0;
TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &Info.tiPhoto);
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &Info.tiPC);
w= Info.tiWidth;
h= Info.tiHeight;
{
unsigned short b = tiBps, p = tiPhoto;
int b, p;
if(tiBps != 8 && tiBps != 16 && tiBps != 12) b = 0;
if(tiPhoto != 1 && tiPhoto != 2) p = 0;
if((b = Info.tiBps) != 8 && b != 16 && b != 12) b = 0;
if((p = Info.tiPhoto) != 1 && p != 2) p = 0;
if( !b || !p)
{
if( !b)
fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits"
" implemented\n",tiBps);
" implemented\n",Info.tiBps);
else
if( !p)
fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)"
" and GRAY(A) has been implemented\n",(int) tiPhoto);
" and GRAY(A) has been implemented\n",(int) Info.tiPhoto);
fprintf(stderr,"\tAborting\n");
TIFFClose(tif);
@@ -2528,6 +2471,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
return NULL;
}
}
{/* From: tiff-4.0.x/libtiff/tif_getimage.c : */
uint16* sampleinfo;
uint16 extrasamples;
@@ -2542,7 +2486,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
case EXTRASAMPLE_UNSPECIFIED:
/* Workaround for some images without correct info about alpha channel
*/
if(tiSpp > 3)
if(Info.tiSpp > 3)
has_alpha = 1;
break;
@@ -2552,15 +2496,12 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
break;
}
}
else /* extrasamples == 0 */
if(tiSpp == 4 || tiSpp == 2) has_alpha = 1;
}
/* initialize image components
*/
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */
if(Info.tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */
{
numcomps = 3 + has_alpha;
color_space = CLRSPC_SRGB;
@@ -2574,8 +2515,8 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
}
else
{
cmptparm[j].prec = tiBps;
cmptparm[j].bpp = tiBps;
cmptparm[j].prec = Info.tiBps;
cmptparm[j].bpp = Info.tiBps;
}
cmptparm[j].dx = subsampling_dx;
cmptparm[j].dy = subsampling_dy;
@@ -2614,7 +2555,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size);
dat8 = (unsigned char*)buf;
if(tiBps == 16)
if(Info.tiBps == 16)
{
step = 6 + has_alpha + has_alpha;
@@ -2647,9 +2588,9 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
else
break;
}/*for(i = 0)*/
}/*if(tiBps == 16)*/
}/*if(Info.tiBps == 16)*/
else
if(tiBps == 8)
if(Info.tiBps == 8)
{
step = 3 + has_alpha;
@@ -2678,9 +2619,9 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
else
break;
}/*for(i )*/
}/*if( tiBps == 8)*/
}/*if( Info.tiBps == 8)*/
else
if(tiBps == 12)/* CINEMA file */
if(Info.tiBps == 12)/* CINEMA file */
{
step = 9;
@@ -2711,15 +2652,15 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
return image;
}/*RGB(A)*/
if(tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */
if(Info.tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */
{
numcomps = 1 + has_alpha;
color_space = CLRSPC_GRAY;
for(j = 0; j < numcomps; ++j)
{
cmptparm[j].prec = tiBps;
cmptparm[j].bpp = tiBps;
cmptparm[j].prec = Info.tiBps;
cmptparm[j].bpp = Info.tiBps;
cmptparm[j].dx = subsampling_dx;
cmptparm[j].dy = subsampling_dy;
cmptparm[j].w = w;
@@ -2757,7 +2698,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size);
dat8 = (unsigned char*)buf;
if(tiBps == 16)
if(Info.tiBps == 16)
{
step = 2 + has_alpha + has_alpha;
@@ -2775,7 +2716,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
}/*for(i )*/
}
else
if(tiBps == 8)
if(Info.tiBps == 8)
{
step = 1 + has_alpha;
@@ -2859,7 +2800,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
image = opj_image_create(numcomps, &cmptparm[0], color_space);
if(!image) {
fclose(f);
free(cmptparm);
return NULL;
}
/* set image offset and reference grid */
@@ -2875,9 +2815,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
for (i = 0; i < w * h; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
fclose(f);
free(cmptparm);
opj_image_destroy(image);
return NULL;
}
image->comps[compno].data[i] = raw_cp->rawSigned?(char)value:value;
@@ -2892,17 +2829,11 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
unsigned char temp;
if (!fread(&temp, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
fclose(f);
free(cmptparm);
opj_image_destroy(image);
return NULL;
}
value = temp << 8;
if (!fread(&temp, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
fclose(f);
free(cmptparm);
opj_image_destroy(image);
return NULL;
}
value += temp;
@@ -2912,9 +2843,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
}
else {
fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n");
fclose(f);
free(cmptparm);
opj_image_destroy(image);
return NULL;
}
@@ -2922,7 +2850,6 @@ opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw
fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n");
}
fclose(f);
free(cmptparm);
return image;
}
@@ -2971,7 +2898,6 @@ int imagetoraw(opj_image_t * image, const char *outfile)
res = fwrite(&curr, sizeof(signed char), 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
ptr++;
@@ -2989,7 +2915,6 @@ int imagetoraw(opj_image_t * image, const char *outfile)
res = fwrite(&curr, sizeof(unsigned char), 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
ptr++;
@@ -3012,14 +2937,12 @@ int imagetoraw(opj_image_t * image, const char *outfile)
res = fwrite(&temp, 1, 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
temp = (unsigned char) curr;
res = fwrite(&temp, 1, 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
ptr++;
@@ -3039,14 +2962,12 @@ int imagetoraw(opj_image_t * image, const char *outfile)
res = fwrite(&temp, 1, 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
temp = (unsigned char) curr;
res = fwrite(&temp, 1, 1, rawFile);
if( res < 1 ) {
fprintf(stderr, "failed to write 1 byte for %s\n", outfile);
fclose(rawFile);
return 1;
}
ptr++;
@@ -3057,13 +2978,11 @@ int imagetoraw(opj_image_t * image, const char *outfile)
else if (image->comps[compno].prec <= 32)
{
fprintf(stderr,"More than 16 bits per component no handled yet\n");
fclose(rawFile);
return 1;
}
else
{
fprintf(stderr,"Error: invalid precision: %d\n", image->comps[compno].prec);
fclose(rawFile);
return 1;
}
}
@@ -3263,27 +3182,18 @@ int imagetopng(opj_image_t * image, const char *write_idf)
int *red, *green, *blue, *alpha;
unsigned char *row_buf, *d;
int has_alpha, width, height, nr_comp, color_type;
int adjustR, adjustG, adjustB, adjustA, x, y, fails;
int prec, ushift, dshift, is16, force16, force8;
int adjustR, adjustG, adjustB, x, y, fails, is16, force16;
int opj_prec, prec, ushift, dshift;
unsigned short mask = 0xffff;
png_color_8 sig_bit;
is16 = force16 = force8 = ushift = dshift = 0; fails = 1;
prec = image->comps[0].prec;
nr_comp = image->numcomps;
is16 = force16 = ushift = dshift = 0; fails = 1;
prec = opj_prec = image->comps[0].prec;
if(prec > 8 && prec < 16)
{
ushift = 16 - prec; dshift = prec - ushift;
prec = 16; force16 = 1;
}
else
if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */
{
ushift = 8 - prec; dshift = 8 - ushift;
prec = 8; force8 = 1;
}
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16)
{
fprintf(stderr,"imagetopng: can not create %s"
@@ -3331,14 +3241,6 @@ int imagetopng(opj_image_t * image, const char *write_idf)
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE.
* REQUIRED
*
* ERRORS:
*
* color_type == PNG_COLOR_TYPE_PALETTE && bit_depth > 8
* color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8
* color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8
* color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8
*
*/
png_set_compression_level(png, Z_BEST_COMPRESSION);
@@ -3352,6 +3254,8 @@ int imagetopng(opj_image_t * image, const char *write_idf)
else
if(prec == 1) mask = 0x0001;
nr_comp = image->numcomps;
if(nr_comp >= 3
&& image->comps[0].dx == image->comps[1].dx
&& image->comps[1].dx == image->comps[2].dx
@@ -3380,13 +3284,11 @@ int imagetopng(opj_image_t * image, const char *write_idf)
sig_bit.alpha = prec;
alpha = image->comps[3].data;
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0);
}
else
{
sig_bit.alpha = 0; alpha = NULL;
color_type = PNG_COLOR_TYPE_RGB;
adjustA = 0;
}
png_set_sBIT(png, info, &sig_bit);
@@ -3394,12 +3296,17 @@ int imagetopng(opj_image_t * image, const char *write_idf)
color_type,
PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/*=============================*/
png_write_info(png, info);
/*=============================*/
if(prec < 8)
if(opj_prec < 8)
{
png_set_packing(png);
}
if(force16)
{
ushift = 16 - opj_prec; dshift = opj_prec - ushift;
}
adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
@@ -3435,40 +3342,21 @@ int imagetopng(opj_image_t * image, const char *write_idf)
if(has_alpha)
{
v = *alpha + adjustA; ++alpha;
v = *alpha++;
if(force16) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v;
}
continue;
}/* if(is16) */
v = *red + adjustR; ++red;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
v = *green + adjustG; ++green;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
v = *blue + adjustB; ++blue;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
}
*d++ = (unsigned char)((*red + adjustR) & mask); ++red;
*d++ = (unsigned char)((*green + adjustG) & mask); ++green;
*d++ = (unsigned char)((*blue + adjustB) & mask); ++blue;
if(has_alpha)
{
v = *alpha + adjustA; ++alpha;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
*d++ = (unsigned char)(*alpha & mask); ++alpha;
}
} /* for(x) */
@@ -3489,9 +3377,13 @@ int imagetopng(opj_image_t * image, const char *write_idf)
red = image->comps[0].data;
if(force16)
{
ushift = 16 - opj_prec; dshift = opj_prec - ushift;
}
sig_bit.gray = prec;
sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0;
alpha = NULL; adjustA = 0;
alpha = NULL;
color_type = PNG_COLOR_TYPE_GRAY;
if(nr_comp == 2)
@@ -3499,7 +3391,6 @@ int imagetopng(opj_image_t * image, const char *write_idf)
has_alpha = 1; sig_bit.alpha = prec;
alpha = image->comps[1].data;
color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
}
width = image->comps[0].w;
height = image->comps[0].h;
@@ -3515,7 +3406,7 @@ int imagetopng(opj_image_t * image, const char *write_idf)
/*=============================*/
adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
if(prec < 8)
if(opj_prec < 8)
{
png_set_packing(png);
}
@@ -3561,19 +3452,11 @@ int imagetopng(opj_image_t * image, const char *write_idf)
for(x = 0; x < width; ++x)
{
v = *red + adjustR; ++red;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
*d++ = (unsigned char)((*red + adjustR) & mask); ++red;
if(has_alpha)
{
v = *alpha + adjustA; ++alpha;
if(force8) { v = (v<<ushift) + (v>>dshift); }
*d++ = (unsigned char)(v & mask);
*d++ = (unsigned char)(*alpha & mask); ++alpha;
}
}/* for(x) */

View File

@@ -82,7 +82,7 @@ typedef struct img_folder{
float *rates;
}img_fol_t;
static void encode_help_display(void) {
void encode_help_display(void) {
fprintf(stdout,"HELP for image_to_j2k\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -321,7 +321,7 @@ static void encode_help_display(void) {
fprintf(stdout,"TotalDisto\n\n");
}
static OPJ_PROG_ORDER give_progression(char progression[4]) {
OPJ_PROG_ORDER give_progression(char progression[4]) {
if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP;
}
@@ -341,7 +341,7 @@ static OPJ_PROG_ORDER give_progression(char progression[4]) {
return PROG_UNKNOWN;
}
static int get_num_images(char *imgdirpath){
int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -360,11 +360,10 @@ static int get_num_images(char *imgdirpath){
continue;
num_images++;
}
closedir(dir);
return num_images;
}
static int load_images(dircnt_t *dirptr, char *imgdirpath){
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -386,11 +385,10 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
static int get_file_format(char *filename) {
int get_file_format(char *filename) {
unsigned int i;
static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@@ -410,13 +408,14 @@ static int get_file_format(char *filename) {
return -1;
}
static char * get_file_name(char *name){
char * get_file_name(char *name){
char *fname;
fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char));
fname= strtok(name,".");
return fname;
}
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_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]="";
@@ -459,7 +458,7 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){
return 2;
}
static void cinema_parameters(opj_cparameters_t *parameters){
void cinema_parameters(opj_cparameters_t *parameters){
parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1;
parameters->cp_tdy=1;
@@ -492,7 +491,7 @@ static void cinema_parameters(opj_cparameters_t *parameters){
}
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){
int i;
float temp_rate;
@@ -577,7 +576,7 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
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_option_t long_option[]={
@@ -590,8 +589,7 @@ 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'},
{0,0,0,0} /* GNU getopt_long requirement */
{"jpip",NO_ARG, NULL, 'J'}
};
/* parse the command line */
@@ -601,16 +599,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#endif /* USE_JPWL */
"h";
totlen=sizeof(long_option)-1;
totlen=sizeof(long_option);
img_fol->set_out_format=0;
raw_cp->rawWidth = 0;
do{
#ifdef USE_SYSTEM_GETOPT
c = opj_getopt_long(argc, argv, optlist,long_option,0);
#else
c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
#endif
if (c == -1)
break;
switch (c) {
@@ -1472,21 +1466,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
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) {
void info_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Mathieu Malaterre, GDCM
* Copyright (c) 20010, Mathieu Malaterre, GDCM
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -121,7 +121,6 @@ int get_num_images(char *imgdirpath){
continue;
num_images++;
}
closedir(dir);
return num_images;
}
@@ -147,7 +146,6 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
@@ -201,20 +199,15 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{0,0,0,0} /* GNU getopt_long requirement */
};
const char optlist[] = "i:o:h";
OPJ_ARG_NOT_USED(indexfilename);
totlen=sizeof(long_option)-1;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
#ifdef USE_SYSTEM_GETOPT
c = opj_getopt_long(argc, argv,optlist,long_option,0);
#else
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
#endif
if (c == -1)
break;
switch (c) {
@@ -281,12 +274,12 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
return 1;
}
if(!(parameters->outfile[0] == 0)){
if(!((parameters->outfile[0] == 0))){
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
return 1;
}
}else{
if( parameters->infile[0] == 0 ) {
if((parameters->infile[0] == 0) ) {
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]);
return 1;

View File

@@ -85,7 +85,7 @@ typedef struct img_folder{
}img_fol_t;
static void decode_help_display(void) {
void decode_help_display(void) {
fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@@ -144,7 +144,7 @@ static void decode_help_display(void) {
/* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){
int get_num_images(char *imgdirpath){
DIR *dir;
struct dirent* content;
int num_images = 0;
@@ -162,11 +162,10 @@ static int get_num_images(char *imgdirpath){
continue;
num_images++;
}
closedir(dir);
return num_images;
}
static int load_images(dircnt_t *dirptr, char *imgdirpath){
int load_images(dircnt_t *dirptr, char *imgdirpath){
DIR *dir;
struct dirent* content;
int i = 0;
@@ -188,11 +187,10 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
closedir(dir);
return 0;
}
static int get_file_format(char *filename) {
int get_file_format(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 };
@@ -211,7 +209,7 @@ static int get_file_format(char *filename) {
return -1;
}
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){
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]="";
@@ -237,13 +235,12 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
}
/* -------------------------------------------------------------------------- */
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) {
/* parse the command line */
int totlen, c;
opj_option_t long_option[]={
{"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'},
{0,0,0,0} /* GNU getopt_long requirement */
};
const char optlist[] = "i:o:r:l:x:"
@@ -254,14 +251,10 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
#endif /* USE_JPWL */
/* <<UniPG */
"h" ;
totlen=sizeof(long_option) - 1;
totlen=sizeof(long_option);
img_fol->set_out_format = 0;
do {
#ifdef USE_SYSTEM_GETOPT
c = opj_getopt_long(argc, argv,optlist,long_option,0);
#else
c = opj_getopt_long(argc, argv,optlist,long_option,totlen);
#endif
if (c == -1)
break;
switch (c) {
@@ -497,21 +490,21 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/**
sample error callback expecting a FILE* client object
*/
static void error_callback(const char *msg, void *client_data) {
void error_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
static void warning_callback(const char *msg, void *client_data) {
void warning_callback(const char *msg, void *client_data) {
FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting no client object
*/
static void info_callback(const char *msg, void *client_data) {
void info_callback(const char *msg, void *client_data) {
(void)client_data;
fprintf(stdout, "[INFO] %s", msg);
}

View File

@@ -293,14 +293,12 @@ void color_apply_icc_profile(opj_image_t *image)
if(in_prof == NULL) return;
in_space = cmsGetPCS(in_prof);
(void)in_space;
out_space = cmsGetColorSpace(in_prof);
intent = cmsGetHeaderRenderingIntent(in_prof);
max_w = image->comps[0].w; max_h = image->comps[0].h;
prec = image->comps[0].prec;
(void)prec;
oldspace = image->color_space;
if(out_space == cmsSigRgbData) /* enumCS 16 */

View File

@@ -10,7 +10,11 @@
* 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. Neither the name of the University nor the names of its contributors
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -38,10 +42,6 @@ static char sccsid[] = "@(#)opj_getopt.c 8.3 (Berkeley) 4/27/95";
#include <string.h>
#include "opj_getopt.h"
#ifdef USE_SYSTEM_GETOPT
#error
#endif
int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */

View File

@@ -1,26 +1,5 @@
/* last review : october 29th, 2002 */
#include "opj_config.h"
#ifdef USE_SYSTEM_GETOPT
#include <getopt.h>
#define opj_opterr opterr
#define opj_optind optind
#define opj_optopt optopt
#define opj_optreset optreset
#define opj_optarg optarg
typedef struct option opj_option_t;
#define NO_ARG no_argument
#define REQ_ARG required_argument
#define OPT_ARG optional_argument
#define opj_getopt getopt
#define opj_getopt_long getopt_long
#else
#ifndef _GETOPT_H_
#define _GETOPT_H_
@@ -48,4 +27,3 @@ extern int opj_getopt_long(int argc, char * const argv[], const char *optstring,
extern void reset_options_reading(void);
#endif /* _GETOPT_H_ */
#endif /* USE_SYSTEM_GETOPT */

View File

@@ -5,14 +5,7 @@ What's New for OpenJPIP
! : changed
+ : added
Feburary 28, 2012
+ [kaori] enabled the opj_server to reply the first query consisting with len request from kakadu client
February 9, 2012
* [kaori] fixed Doxygen configuration file to document the utilities
+ [kaori] added execution argument to set port number for opj_dec_server, opj_viewer*
January 26, 2012
January 26, 2011
! [kaori] unapplied auxtrans_manager to the local mode
December 24, 2011

View File

@@ -2,10 +2,7 @@
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(NOT CMAKE_USE_PTHREADS_INIT)
FIND_PACKAGE(PTHREAD REQUIRED)
ENDIF(BUILD_JPIP_SERVER)
# JPIP library:

View File

@@ -96,7 +96,7 @@ Server:
Client:
1. Launch image decoding server, and keep it alive as long as image viewers are open
% ./opj_dec_server [portnumber (50000 by default)]
% ./opj_dec_server
You might prefer to implement this program from another directory since cache files are saved in the working directory.
% mkdir cache
@@ -104,12 +104,10 @@ Client:
% ../opj_dec_server
2. Open image viewers (as many as needed)
% java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [hostname] [portnumber] [stateless/session] [jptstream/jppstream] [tcp/udp]
% java -jar opj_viewer.jar http://hostname/myFCGI path/filename.jp2 [stateless/session] [jptstream/jppstream] [tcp/udp]
( The arguments
- http://hostname/myFCGI is the HTTP server URI (myFCGI refers to opj_server by the server setting)
- path/filename.jp2 is the server local path or URL of a JP2 file
- host name of opj_dec_server, localhost by default
- portnumber of opj_dec_server, 50000 by default
- request type stateless for no caching, session (default) for caching
- return media type, JPT-stream tile based stream, or JPP-stream (default) precinct based stream
- auxiliary return protocol, tcp or udp (udp is not implemented yet), if not given, return data is filled in http chunk
@@ -133,7 +131,7 @@ An example to encode a TIF image "copenhague1.tif" at resolution 4780x4050, 8bit
% ./image_to_j2k -i copenhague1.tif -o copenhague1.jp2 -p RPCL -c [64,64] -t 640,480 -jpip -TP R
options
-jpip : embed index table 'cidx' box into the output JP2 file (obligation for JPIP)
-jpip : embed index table box into the output JP2 file (obligation for JPIP)
-TP R : partition a tile into tile parts of different resolution levels (obligation for JPT-stream)
<Option>

View File

@@ -568,7 +568,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = .. ../libopenjpip ../util
INPUT = .. ../libopenjpip ../opj_server ../opj_client/opj_dec_server ../tools ../tools/indexer
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is

View File

@@ -4,6 +4,7 @@ INCLUDE_DIRECTORIES(
${OPENJPEG_SOURCE_DIR}/libopenjpeg
${FCGI_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
${PTHREAD_INCLUDE_DIRS}
)
# Defines the source code for the library
@@ -62,7 +63,7 @@ INSTALL(TARGETS openjpip_local
IF(BUILD_JPIP_SERVER)
ADD_LIBRARY(openjpip_server STATIC ${OPENJPIP_SRCS} ${SERVER_SRCS})
TARGET_LINK_LIBRARIES(openjpip_server ${FCGI_LIBRARIES} ${CURL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
TARGET_LINK_LIBRARIES(openjpip_server ${FCGI_LIBRARIES} ${CURL_LIBRARIES} ${PTHREAD_LIBRARIES})
SET_TARGET_PROPERTIES(openjpip_server
PROPERTIES COMPILE_FLAGS "-DSERVER")
INSTALL(TARGETS openjpip_server

View File

@@ -46,7 +46,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
auxtrans_param_t init_aux_transport( int tcp_auxport, int udp_auxport)
{
@@ -61,7 +61,7 @@ auxtrans_param_t init_aux_transport( int tcp_auxport, int udp_auxport)
auxtrans.tcplistensock = -1;
auxtrans.udplistensock = -1;
/* open listening socket for udp later */
// open listening socket for udp later
return auxtrans;
}
@@ -78,15 +78,15 @@ void close_aux_transport( auxtrans_param_t auxtrans)
}
/*!< auxiliary response parameters */
//!< auxiliary response parameters
typedef struct aux_response_param{
char *cid; /*!< channel ID */
unsigned char *data; /*!< sending data */
int datalen; /*!< length of data */
int maxlenPerFrame; /*!< maximum data length to send per frame */
SOCKET listensock; /*!< listeing socket */
char *cid; //!< channel ID
unsigned char *data; //!< sending data
int datalen; //!< length of data
int maxlenPerFrame; //!< maximum data length to send per frame
SOCKET listensock; //!< listeing socket
#ifdef _WIN32
HANDLE hTh; /*!< thread handle */
HANDLE hTh; //!< thread handle
#endif
} aux_response_param_t;

View File

@@ -161,7 +161,7 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset)
}
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[])
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[])
{
Byte8_t pos;
Byte_t *data;
@@ -221,7 +221,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char
return NULL;
}
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[])
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, char TBox[])
{
Byte8_t pos;
Byte_t *data;
@@ -272,7 +272,7 @@ box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset)
return gene_boxbyOffset( superbox->fd, get_DBoxoff( superbox)+offset);
}
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[])
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, char TBox[])
{
return gene_boxbyType( superbox->fd, get_DBoxoff( superbox)+offset, get_DBoxlen( superbox)-offset, TBox);
}
@@ -317,7 +317,7 @@ Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset)
return fetch_8bytebigendian( box->fd, get_DBoxoff( box)+offset);
}
box_param_t * search_box( const char type[], boxlist_param_t *boxlist)
box_param_t * search_box( char type[], boxlist_param_t *boxlist)
{
box_param_t *foundbox;

View File

@@ -97,7 +97,7 @@ box_param_t * gene_boxbyOffinStream( Byte_t *stream, Byte8_t offset);
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char TBox[]);
box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, char TBox[]);
/**
* generate(search) box from code stream
@@ -108,7 +108,7 @@ box_param_t * gene_boxbyType( int fd, Byte8_t offset, Byte8_t length, const char
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, const char TBox[]);
box_param_t * gene_boxbyTypeinStream( Byte_t *stream, Byte8_t offset, Byte8_t length, char TBox[]);
/**
* generate child box from JP2 file at the given offset
@@ -127,7 +127,7 @@ box_param_t * gene_childboxbyOffset( box_param_t *superbox, Byte8_t offset);
* @param[in] TBox Box Type
* @return pointer to the structure of generate/found box parameters
*/
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, const char TBox[]);
box_param_t * gene_childboxbyType( box_param_t *superbox, Byte8_t offset, char TBox[]);
/**
* get DBox offset
@@ -210,7 +210,7 @@ Byte8_t fetch_DBox8bytebigendian( box_param_t *box, long offset);
* @param[in] boxlist box list pointer
* @return found box pointer
*/
box_param_t * search_box( const char type[], boxlist_param_t *boxlist);
box_param_t * search_box( char type[], boxlist_param_t *boxlist);
/**
* print box parameters

View File

@@ -41,7 +41,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
@@ -55,7 +55,7 @@ boxheader_param_t * gene_boxheader( int fd, Byte8_t offset)
boxtype = (char *)fetch_bytes( fd, offset+4, 4);
headlen = 8;
if( boxlen == 1){ /* read XLBox */
if( boxlen == 1){ // read XLBox
boxlen = fetch_8bytebigendian( fd, offset+8);
headlen = 16;
}

View File

@@ -76,13 +76,13 @@ Byte_t fetch_1byte( int fd, long offset)
if( lseek( fd, offset, SEEK_SET)==-1){
fprintf( FCGI_stdout, "Reason: Target broken (seek error)\r\n");
fprintf( FCGI_stderr, "Error: error in fetch_1byte( %d, %lld)\n", fd, offset);
fprintf( FCGI_stderr, "Error: error in fetch_1byte( %d, %ld)\n", fd, offset);
return 0;
}
if( read( fd, &code, 1) != 1){
fprintf( FCGI_stdout, "Reason: Target broken (read error)\r\n");
fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %lld)\n", fd, offset);
fprintf( FCGI_stderr, "Error: error in fetch_bytes( %d, %ld)\n", fd, offset);
return 0;
}
return code;
@@ -94,7 +94,7 @@ Byte2_t fetch_2bytebigendian( int fd, long offset)
Byte2_t code;
if(!(data = fetch_bytes( fd, offset, 2))){
fprintf( FCGI_stderr, "Error: error in fetch_2bytebigendian( %d, %lld)\n", fd, offset);
fprintf( FCGI_stderr, "Error: error in fetch_2bytebigendian( %d, %ld)\n", fd, offset);
return 0;
}
code = big2(data);
@@ -109,7 +109,7 @@ Byte4_t fetch_4bytebigendian( int fd, long offset)
Byte4_t code;
if(!(data = fetch_bytes( fd, offset, 4))){
fprintf( FCGI_stderr, "Error: error in fetch_4bytebigendian( %d, %lld)\n", fd, offset);
fprintf( FCGI_stderr, "Error: error in fetch_4bytebigendian( %d, %ld)\n", fd, offset);
return 0;
}
code = big4(data);
@@ -124,7 +124,7 @@ Byte8_t fetch_8bytebigendian( int fd, long offset)
Byte8_t code;
if(!(data = fetch_bytes( fd, offset, 8))){
fprintf( FCGI_stderr, "Error: error in fetch_8bytebigendian( %d, %lld)\n", fd, offset);
fprintf( FCGI_stderr, "Error: error in fetch_8bytebigendian( %d, %ld)\n", fd, offset);
return 0;
}
code = big8(data);

View File

@@ -31,27 +31,17 @@
#ifndef BYTE_MANAGER_H_
# define BYTE_MANAGER_H_
#include "opj_config.h"
#ifdef HAVE_STDINT_H
#include <stdint.h>
typedef uint8_t Byte_t;
typedef uint16_t Byte2_t;
typedef uint32_t Byte4_t;
typedef uint64_t Byte8_t;
#else
#if defined(_WIN32)
/** 1Byte parameter type*/
typedef unsigned __int8 Byte_t;
typedef unsigned char Byte_t;
/** 2Byte parameter type*/
typedef unsigned __int16 Byte2_t;
typedef unsigned short int Byte2_t;
/** 4Byte parameter type*/
typedef unsigned __int32 Byte4_t;
typedef unsigned int Byte4_t;
/** 8Byte parameter type*/
typedef unsigned __int64 Byte8_t;
#else
#error unsupported platform
#endif
#endif
typedef unsigned long long int Byte8_t;
/**

View File

@@ -40,10 +40,10 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
cachemodellist_param_t * gene_cachemodellist(void)
cachemodellist_param_t * gene_cachemodellist()
{
cachemodellist_param_t *cachemodellist;
@@ -73,7 +73,7 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
cachemodel->jppstream = true;
else
cachemodel->jppstream = false;
} else{ /* reqJPT */
} else{ // reqJPT
if( target->jptstream)
cachemodel->jppstream = false;
else
@@ -95,9 +95,9 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
cachemodel->next = NULL;
if( cachemodellist){
if( cachemodellist->first) /* there are one or more entries */
if( cachemodellist->first) // there are one or more entries
cachemodellist->last->next = cachemodel;
else /* first entry */
else // first entry
cachemodellist->first = cachemodel;
cachemodellist->last = cachemodel;
}
@@ -112,10 +112,9 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
void print_cachemodel( cachemodel_param_t cachemodel)
{
target_param_t *target;
Byte8_t TPnum; /* num of tile parts in each tile */
Byte8_t Pmax; /* max num of packets per tile */
Byte8_t i, j, k;
int n; /* FIXME: Is this large enough ? */
Byte8_t TPnum; // num of tile parts in each tile
Byte8_t Pmax; // max num of packets per tile
int i, j, k, n;
target = cachemodel.target;
@@ -136,9 +135,9 @@ void print_cachemodel( cachemodel_param_t cachemodel)
fprintf( logstream, "\t tile header and precinct packet model:\n");
for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
fprintf( logstream, "\t tile.%llud %d\n", i, cachemodel.th_model[i]);
fprintf( logstream, "\t tile.%d %d\n", i, cachemodel.th_model[i]);
for( j=0; j<target->codeidx->SIZ.Csiz; j++){
fprintf( logstream, "\t compo.%llud: ", j);
fprintf( logstream, "\t compo.%d: ", j);
Pmax = get_nmax( target->codeidx->precpacket[j]);
for( k=0; k<Pmax; k++)
fprintf( logstream, "%d", cachemodel.pp_model[j][i*Pmax+k]);
@@ -198,10 +197,9 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
bool is_allsent( cachemodel_param_t cachemodel)
{
target_param_t *target;
Byte8_t TPnum; /* num of tile parts in each tile */
Byte8_t Pmax; /* max num of packets per tile */
Byte8_t i, j, k;
int n; /* FIXME: is this large enough ? */
Byte8_t TPnum; // num of tile parts in each tile
Byte8_t Pmax; // max num of packets per tile
int i, j, k, n;
target = cachemodel.target;

View File

@@ -57,7 +57,7 @@ typedef struct cachemodellist_param{
*
* @return pointer to the generated cache model list
*/
cachemodellist_param_t * gene_cachemodellist(void);
cachemodellist_param_t * gene_cachemodellist();
/**
* generate a cache model under a list

View File

@@ -32,9 +32,6 @@
#include <string.h>
#include <stdio.h>
#include "channel_manager.h"
#ifdef _WIN32
#define snprintf _snprintf /* Visual Studio */
#endif
#ifdef SERVER
#include "fcgi_stdio.h"
@@ -43,9 +40,9 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
channellist_param_t * gene_channellist(void)
channellist_param_t * gene_channellist()
{
channellist_param_t *channellist;
@@ -71,12 +68,12 @@ channel_param_t * gene_channel( query_param_t query_param, auxtrans_param_t auxt
channel = (channel_param_t *)malloc( sizeof(channel_param_t));
channel->cachemodel = cachemodel;
/* set channel ID and get present time */
// set channel ID and get present time
snprintf( channel->cid, MAX_LENOFCID, "%x%x", (unsigned int)time( &channel->start_tm), (unsigned int)rand());
channel->aux = query_param.cnew;
/* only tcp implemented for now */
// only tcp implemented for now
if( channel->aux == udp)
channel->aux = tcp;
@@ -104,9 +101,7 @@ channel_param_t * gene_channel( query_param_t query_param, auxtrans_param_t auxt
void set_channel_variable_param( query_param_t query_param, channel_param_t *channel)
{
/* set roi information */
(void)query_param;
(void)channel;
// set roi information
}

View File

@@ -62,7 +62,7 @@ typedef struct channellist_param{
*
* @return pointer to the generated channel list
*/
channellist_param_t * gene_channellist(void);
channellist_param_t * gene_channellist();
/**

View File

@@ -38,7 +38,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
codestream_param_t set_codestream( int fd, Byte8_t offset, Byte8_t length)
{

View File

@@ -0,0 +1,29 @@
ifdef jpipserver
CFLAGS = -O3 -Wall -m32 -DSERVER
LIBNAME = libopenjpip_server.a
else
J2KINCDIR = ../../../libopenjpeg
CFLAGS = -O3 -Wall -I$(J2KINCDIR)
LIBNAME = libopenjpip_local.a
endif
all: $(LIBNAME)
ifdef jpipserver
$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
session_manager.o jpip_parser.o sock_manager.o auxtrans_manager.o
ar r $@ $^
else
$(LIBNAME): openjpip.o target_manager.o byte_manager.o box_manager.o boxheader_manager.o manfbox_manager.o \
mhixbox_manager.o marker_manager.o codestream_manager.o faixbox_manager.o index_manager.o \
msgqueue_manager.o metadata_manager.o placeholder_manager.o ihdrbox_manager.o imgreg_manager.o \
cachemodel_manager.o j2kheader_manager.o jp2k_encoder.o query_parser.o channel_manager.o \
session_manager.o jpip_parser.o jp2k_decoder.o imgsock_manager.o jpipstream_manager.o cache_manager.o \
dec_clientmsg_handler.o sock_manager.o
ar r $@ $^
endif
clean:
rm -f $(LIBNAME) *.o *~

View File

@@ -40,7 +40,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
const int rx, const int ry,
@@ -106,13 +106,13 @@ void find_level( int maxlev, int *lev, int *fx, int *fy, int *xmin, int *ymin, i
int xwidth = *xmax - *xmin;
int ywidth = *ymax - *ymin;
/* Find smaller frame size for now (i.e. assume "round-down"). */
/// Find smaller frame size for now (i.e. assume "round-down").
if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)){
fprintf( FCGI_stderr, "Frame size must be strictly positive");
exit(-1);
}
else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
/* Simulate the ceil function. */
// Simulate the ceil function.
*xmin = ceil((double)*xmin/(double)2.0);
*ymin = ceil((double)*ymin/(double)2.0);
*xmax = ceil((double)*xmax/(double)2.0);
@@ -149,7 +149,5 @@ void print_imgreg( imgreg_param_t imgreg)
fprintf( logstream, "\t roff: %d, %d\n", imgreg.ox, imgreg.oy);
fprintf( logstream, "\t rsiz: %d, %d\n", imgreg.sx, imgreg.sy);
fprintf( logstream, "\t level: %d\n", imgreg.level);
#else
(void)imgreg;
#endif
}

View File

@@ -31,14 +31,14 @@
#ifndef IMGREG_MANAGER_H_
# define IMGREG_MANAGER_H_
/** image region parameters */
//! image region parameters
typedef struct imgreg_param{
int xosiz, yosiz; /** offset from the origin of the reference grid
at the decomposition level */
int fx, fy; /** frame size (fsiz) */
int ox, oy; /** offset (roff) */
int sx, sy; /** region size (rsiz) */
int level; /** decomposition level */
int xosiz, yosiz; //!< offset from the origin of the reference grid
//!at the decomposition level
int fx, fy; //!< frame size (fsiz)
int ox, oy; //!< offset (roff)
int sx, sy; //!< region size (rsiz)
int level; //!< decomposition level
} imgreg_param_t;

View File

@@ -42,7 +42,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
SIZmarker_param_t get_SIZmkrdata_from_j2kstream( Byte_t *SIZstream);
@@ -115,13 +115,6 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream)
if( *CODstream++ != 0xff || *CODstream++ != 0x52){
fprintf( FCGI_stderr, "Error, COD marker not found in the reconstructed j2kstream\n");
COD.Lcod = 0;
COD.Scod = 0;
COD.prog_order = 0;
COD.numOflayers = 0;
COD.numOfdecomp = 0;
COD.XPsiz = 0;
COD.YPsiz = 0;
return COD;
}
@@ -136,7 +129,7 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream)
COD.YPsiz = (Byte4_t *)malloc( (COD.numOfdecomp+1)*sizeof(Byte4_t));
for( i=0; i<=COD.numOfdecomp; i++){
/*precinct size */
//precinct size
COD.XPsiz[i] = pow( 2, *( CODstream+12+i) & 0x0F);
COD.YPsiz[i] = pow( 2, (*( CODstream+12+i) & 0xF0) >> 4);
}
@@ -195,7 +188,7 @@ bool modify_SIZmkrstream( SIZmarker_param_t SIZ, int difOfdecomplev, Byte_t *SIZ
SIZ.YTOsiz = ceil( (double)SIZ.YTOsiz/2.0);
}
SIZstream += 4; /* skip Lsiz + Rsiz */
SIZstream += 4; // skip Lsiz + Rsiz
modify_4Bytecode( SIZ.Xsiz, SIZstream);
modify_4Bytecode( SIZ.Ysiz, SIZstream+4);
@@ -229,9 +222,9 @@ Byte2_t modify_CODmkrstream( CODmarker_param_t COD, int numOfdecomp, Byte_t *COD
CODstream += 2;
}
CODstream += 5; /* skip Scod & SGcod */
CODstream += 5; // skip Scod & SGcod
/* SPcod */
// SPcod
*CODstream++ = (Byte_t) numOfdecomp;
return newLcod;
@@ -241,7 +234,7 @@ bool modify_COCmkrstream( int numOfdecomp, Byte_t *COCstream, Byte2_t Csiz, Byte
bool modify_tileheader( Byte_t *j2kstream, Byte8_t SOToffset, int numOfdecomp, Byte2_t Csiz, Byte8_t *j2klen)
{
Byte4_t Psot; /* tile part length ref A.4.2 Start of tile-part SOT */
Byte4_t Psot; // tile part length ref A.4.2 Start of tile-part SOT
Byte_t *thstream, *SOTstream, *Psot_stream;
Byte2_t oldLcoc, newLcoc;
@@ -252,14 +245,14 @@ bool modify_tileheader( Byte_t *j2kstream, Byte8_t SOToffset, int numOfdecomp, B
return false;
}
SOTstream += 4; /* skip Lsot & Isot */
SOTstream += 4; // skip Lsot & Isot
Psot = (SOTstream[0]<<24)+(SOTstream[1]<<16)+(SOTstream[2]<<8)+(SOTstream[3]);
Psot_stream = SOTstream;
thstream += 12; /* move to next marker (SOT always 12bytes) */
thstream += 12; // move to next marker (SOT always 12bytes)
while( !( *thstream == 0xff && *(thstream+1) == 0x93)){ /* search SOD */
if( numOfdecomp != -1 && *thstream == 0xff && *(thstream+1) == 0x53){ /* COC */
while( !( *thstream == 0xff && *(thstream+1) == 0x93)){ // search SOD
if( numOfdecomp != -1 && *thstream == 0xff && *(thstream+1) == 0x53){ // COC
if( !modify_COCmkrstream( numOfdecomp, thstream, Csiz, &oldLcoc, &newLcoc))
return false;
@@ -267,7 +260,7 @@ bool modify_tileheader( Byte_t *j2kstream, Byte8_t SOToffset, int numOfdecomp, B
*j2klen -= ( oldLcoc - newLcoc);
}
thstream += 2;
thstream += ((thstream[0]<<8)+(thstream[1])); /* marker length */
thstream += ((thstream[0]<<8)+(thstream[1])); // marker length
}
if( (*j2klen)-SOToffset != Psot){
@@ -289,7 +282,7 @@ bool modify_COCmkrstream( int numOfdecomp, Byte_t *COCstream, Byte2_t Csiz, Byte
*COCstream++ = (Byte_t)((Byte2_t)((*newLcoc) & 0xff00) >> 8);
*COCstream++ = (Byte_t)((*newLcoc) & 0x00ff);
if( Csiz < 257) COCstream +=2; /* skip Ccoc & Scoc */
if( Csiz < 257) COCstream +=2; // skip Ccoc & Scoc
else COCstream += 3;
*COCstream = numOfdecomp;

View File

@@ -125,8 +125,7 @@ void warning_callback(const char *msg, void *client_data) {
*/
void info_callback(const char *msg, void *client_data) {
(void)client_data;
(void)msg;
/* fprintf(stdout, "[INFO] %s", msg); */
// fprintf(stdout, "[INFO] %s", msg);
}
@@ -191,7 +190,7 @@ Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox)
r = image->comps[0].data[i];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
/* if( adjustR > 0) */
// if( adjustR > 0)
*(ptr++) = (Byte_t) ((r >> adjustR)+((r >> (adjustR-1))%2));
if( image->numcomps == 3){

View File

@@ -45,7 +45,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
/**
@@ -105,11 +105,11 @@ Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn
if( ptr->phld){
if( strncmp( (char *)ptr->phld->OrigBH+4, "jp2c", 4) == 0){
jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen;
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
}
else
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); // header only
}
jp2stream = add_msgstream( ptr, jpipstream, jp2stream, jp2len);
ptr = ptr->next;
@@ -203,7 +203,7 @@ Byte_t * recons_codestream_from_JPTstream( msgqueue_param_t *msgqueue, Byte_t *j
}
ptr = msgqueue->first;
while(( ptr = search_message( EXT_TILE_MSG, tileID, csn, ptr))!=NULL){
if( ptr->aux > mindeclev){ /* FIXME: pointer comparison ? */
if( ptr->aux > mindeclev){
if( ptr->bin_offset == binOffset){
found = true;
j2kstream = add_msgstream( ptr, jpipstream, j2kstream, j2klen);
@@ -625,7 +625,7 @@ Byte8_t get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn, bool isJPPstre
message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t csn, message_param_t *msg)
{
while( msg != NULL){
if( in_class_id == (Byte8_t)-1){
if( in_class_id == -1){
if( msg->class_id == class_id && msg->csn == csn)
return msg;
}

View File

@@ -43,7 +43,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
bool identify_target( query_param_t query_param, targetlist_param_t *targetlist, target_param_t **target)
@@ -132,35 +132,35 @@ bool close_channel( query_param_t query_param,
#ifndef SERVER
fprintf( logstream, "local log: close all\n");
#endif
/* all channels associatd with the session will be closed */
// all channels associatd with the session will be closed
if( !delete_session( cursession, sessionlist))
return false;
}
else{
/* check if all entry belonging to the same session */
// check if all entry belonging to the same session
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){
/* In case of the first entry of close cid */
// In case of the first entry of close cid
if( *cursession == NULL){
if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel))
return false;
}
else /* second or more entry of close cid */
else // second or more entry of close cid
if( !(*curchannel=search_channel( cclose, (*cursession)->channellist))){
fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose);
return false;
}
}
/* delete channels */
// delete channels
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)){
*curchannel = search_channel( cclose, (*cursession)->channellist);
delete_channel( curchannel, (*cursession)->channellist);
}
if( (*cursession)->channellist->first == NULL || (*cursession)->channellist->last == NULL)
/* In case of empty session */
// In case of empty session
delete_session( cursession, sessionlist);
}
return true;
@@ -181,9 +181,8 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue);
* @param[in] query_param structured query
* @param[in] metadatalist pointer to metadata bin list
* @param[in,out] msgqueue message queue pointer
* @return if succeeded (true) or failed (false)
*/
bool enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue);
bool gene_JPIPstream( query_param_t query_param,
@@ -195,14 +194,14 @@ bool gene_JPIPstream( query_param_t query_param,
index_param_t *codeidx;
cachemodel_param_t *cachemodel;
if( !cursession || !curchannel){ /* stateless */
if( !cursession || !curchannel){ // stateless
if( !target)
return false;
if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream)))
return false;
*msgqueue = gene_msgqueue( true, cachemodel);
}
else{ /* session */
else{ // session
cachemodel = curchannel->cachemodel;
target = cachemodel->target;
*msgqueue = gene_msgqueue( false, cachemodel);
@@ -222,22 +221,16 @@ bool gene_JPIPstream( query_param_t query_param,
}
}
/*meta*/
//meta
if( query_param.box_type[0][0] != 0 && query_param.len != 0)
if( !enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue))
return false;
enqueue_metabins( query_param, codeidx->metadatalist, *msgqueue);
if( query_param.metadata_only)
return true;
/* main header */
// image codestream
if( query_param.fx > 0 && query_param.fy > 0){
if( !cachemodel->mhead_model && query_param.len != 0)
enqueue_mainheader( *msgqueue);
/* image codestream */
if( (query_param.fx > 0 && query_param.fy > 0))
enqueue_imagedata( query_param, *msgqueue);
}
return true;
}
@@ -277,13 +270,13 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
index_param_t *codeidx;
imgreg_param_t imgreg;
range_param_t tile_Xrange, tile_Yrange;
Byte4_t u, v, tile_id;
int u, v, tile_id;
int xmin, xmax, ymin, ymax;
int numOfreslev;
codeidx = msgqueue->cachemodel->target->codeidx;
if( !(msgqueue->cachemodel->jppstream) && get_nmax( codeidx->tilepart) == 1) /* normally not the case */
if( !(msgqueue->cachemodel->jppstream) && get_nmax( codeidx->tilepart) == 1) // normally not the case
numOfreslev = 1;
else
numOfreslev = codeidx->COD.numOfdecomp+1;
@@ -303,20 +296,20 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
tile_Xrange = get_tile_Xrange( codeidx->SIZ, tile_id, imgreg.level);
if( tile_Xrange.minvalue < tile_Xrange.maxvalue && tile_Yrange.minvalue < tile_Yrange.maxvalue){
if( tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox) ||
tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) ||
tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy) ||
tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
/*printf("Tile completely excluded from view-window %d\n", tile_id);*/
/* Tile completely excluded from view-window */
if( tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox ||
tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox + imgreg.sx ||
tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy ||
tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy + imgreg.sy) {
//printf("Tile completely excluded from view-window %d\n", tile_id);
// Tile completely excluded from view-window
}
else if( tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) &&
tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) &&
tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) &&
tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
/* Tile completely contained within view-window */
/* high priority */
/*printf("Tile completely contained within view-window %d\n", tile_id);*/
else if( tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox &&
tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx &&
tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy &&
tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy) {
// Tile completely contained within view-window
// high priority
//printf("Tile completely contained within view-window %d\n", tile_id);
if( msgqueue->cachemodel->jppstream){
enqueue_tileheader( tile_id, msgqueue);
enqueue_allprecincts( tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
@@ -325,17 +318,16 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
enqueue_tile( tile_id, imgreg.level, msgqueue);
}
else{
/* Tile partially overlaps view-window */
/* low priority */
/*printf("Tile partially overlaps view-window %d\n", tile_id);*/
// Tile partially overlaps view-window
// low priority
//printf("Tile partially overlaps view-window %d\n", tile_id);
if( msgqueue->cachemodel->jppstream){
enqueue_tileheader( tile_id, msgqueue);
/* FIXME: The following code is suspicious it implicitely cast an unsigned int to int, which truncates values */
xmin = tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
xmax = tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) ? tile_Xrange.maxvalue - tile_Xrange.minvalue -1 : imgreg.xosiz + imgreg.ox + imgreg.sx - tile_Xrange.minvalue -1;
ymin = tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.minvalue;
ymax = tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy) ? tile_Yrange.maxvalue - tile_Yrange.minvalue -1 : imgreg.yosiz + imgreg.oy + imgreg.sy - tile_Yrange.minvalue -1;
xmin = tile_Xrange.minvalue >= imgreg.xosiz + imgreg.ox ? 0 : imgreg.xosiz + imgreg.ox - tile_Xrange.minvalue;
xmax = tile_Xrange.maxvalue <= imgreg.xosiz + imgreg.ox + imgreg.sx ? tile_Xrange.maxvalue - tile_Xrange.minvalue -1 : imgreg.xosiz + imgreg.ox + imgreg.sx - tile_Xrange.minvalue -1;
ymin = tile_Yrange.minvalue >= imgreg.yosiz + imgreg.oy ? 0 : imgreg.yosiz + imgreg.oy - tile_Yrange.minvalue;
ymax = tile_Yrange.maxvalue <= imgreg.yosiz + imgreg.oy + imgreg.sy ? tile_Yrange.maxvalue - tile_Yrange.minvalue -1 : imgreg.yosiz + imgreg.oy + imgreg.sy - tile_Yrange.minvalue -1;
enqueue_precincts( xmin, xmax, ymin, ymax, tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
}
else
@@ -347,7 +339,6 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
}
/* MM: shouldnt xmin/xmax be Byte4_t instead ? */
void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int level, int lastcomp, bool *comps, int layers, msgqueue_param_t *msgqueue)
{
index_param_t *codeidx;
@@ -383,16 +374,16 @@ void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int
xmaxP = XTsiz-1;
if( xmaxP < xmin || xminP > xmax || ymaxP < ymin || yminP > ymax){
/* Precinct completely excluded from view-window */
// Precinct completely excluded from view-window
}
else if( xminP >= xmin && xmaxP <= xmax && yminP >= ymin && ymaxP <= ymax){
/* Precinct completely contained within view-window
high priority */
// Precinct completely contained within view-window
// high priority
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
}
else{
/* Precinct partially overlaps view-window
low priority */
// Precinct partially overlaps view-window
// low priority
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
}
}
@@ -428,26 +419,18 @@ void enqueue_allprecincts( int tile_id, int level, int lastcomp, bool *comps, in
}
}
bool enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue)
void enqueue_metabins( query_param_t query_param, metadatalist_param_t *metadatalist, msgqueue_param_t *msgqueue)
{
int i;
for( i=0; query_param.box_type[i][0]!=0 && i<MAX_NUMOFBOX; i++){
if( query_param.box_type[i][0] == '*'){
fprintf( FCGI_stdout, "Status: 501\r\n");
fprintf( FCGI_stdout, "Reason: metareq with all box-property * not implemented\r\n");
return false;
// not implemented
}
else{
int idx = search_metadataidx( query_param.box_type[i], metadatalist);
if( idx != -1)
enqueue_metadata( idx, msgqueue);
else{
fprintf( FCGI_stdout, "Status: 400\r\n");
fprintf( FCGI_stdout, "Reason: box-type %.4s not found\r\n", query_param.box_type[i]);
return false;
}
}
}
return true;
}

View File

@@ -52,7 +52,7 @@ Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_s
return stream;
}
void save_codestream( Byte_t *codestream, Byte8_t streamlen, const char *fmt)
void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt)
{
time_t timer;
struct tm *t_st;
@@ -74,7 +74,7 @@ void save_codestream( Byte_t *codestream, Byte8_t streamlen, const char *fmt)
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox)
{
Byte_t *pnmstream;
Byte_t *j2kstream; /* j2k or jp2 codestream */
Byte_t *j2kstream; // j2k or jp2 codestream
Byte8_t j2klen;
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);

View File

@@ -34,7 +34,7 @@
Byte_t * update_JPIPstream( Byte_t *newstream, int newstreamlen, Byte_t *cache_stream, int *streamlen);
void save_codestream( Byte_t *codestream, Byte8_t streamlen, const char *fmt);
void save_codestream( Byte_t *codestream, Byte8_t streamlen, char *fmt);
Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte8_t csn, int fw, int fh, ihdrbox_param_t **ihdrbox);

View File

@@ -40,14 +40,14 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
manfbox_param_t * gene_manfbox( box_param_t *box)
{
manfbox_param_t *manf; /* manifest parameters */
boxheader_param_t *bh; /* current box pointer */
boxheader_param_t *last; /* last boxheader pointer of the list */
Byte8_t pos; /* current position in manf_box contents; */
manfbox_param_t *manf; // manifest parameters
boxheader_param_t *bh; // current box pointer
boxheader_param_t *last; // last boxheader pointer of the list
int pos; // current position in manf_box contents;
manf = ( manfbox_param_t *)malloc( sizeof( manfbox_param_t));
@@ -59,7 +59,7 @@ manfbox_param_t * gene_manfbox( box_param_t *box)
bh = gene_childboxheader( box, pos);
pos += bh->headlen;
/* insert into the list */
// insert into the list
if( manf->first)
last->next = bh;
else
@@ -77,7 +77,7 @@ void delete_manfbox( manfbox_param_t **manf)
while( bhPtr != NULL){
bhNext = bhPtr->next;
#ifndef SERVER
/* fprintf( logstream, "local log: boxheader %.4s deleted!\n", bhPtr->type); */
// fprintf( logstream, "local log: boxheader %.4s deleted!\n", bhPtr->type);
#endif
free(bhPtr);
bhPtr = bhNext;
@@ -96,7 +96,7 @@ void print_manfbox( manfbox_param_t *manf)
}
}
boxheader_param_t * search_boxheader( const char type[], manfbox_param_t *manf)
boxheader_param_t * search_boxheader( char type[], manfbox_param_t *manf)
{
boxheader_param_t *found;

View File

@@ -75,7 +75,7 @@ void print_manfbox( manfbox_param_t *manf);
* @param[in] manf manf box pointer
* @return found box pointer
*/
boxheader_param_t * search_boxheader( const char type[], manfbox_param_t *manf);
boxheader_param_t * search_boxheader( char type[], manfbox_param_t *manf);
#endif /* !MANFBOX_MANAGER_H_ */

View File

@@ -37,7 +37,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
marker_param_t set_marker( codestream_param_t cs, Byte2_t code, Byte8_t offset, Byte2_t length)
{

View File

@@ -43,7 +43,7 @@
#endif /*SERVER*/
metadatalist_param_t * gene_metadatalist(void)
metadatalist_param_t * gene_metadatalist()
{
metadatalist_param_t *list;
@@ -77,6 +77,10 @@ metadatalist_param_t * const_metadatalist( int fd)
phldlist = gene_placeholderlist();
metadatalist = gene_metadatalist();
delete_box_in_list_by_type( "iptr", toplev_boxlist);
delete_box_in_list_by_type( "cidx", toplev_boxlist);
delete_box_in_list_by_type( "fidx", toplev_boxlist);
box = toplev_boxlist->first;
idx = 0;
while( box){

View File

@@ -60,7 +60,7 @@ typedef struct metadatalist_param{
*
* @return pointer to the generated metadata list
*/
metadatalist_param_t * gene_metadatalist(void);
metadatalist_param_t * gene_metadatalist();
/**

View File

@@ -40,14 +40,14 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
mhixbox_param_t * gene_mhixbox( box_param_t *box)
{
mhixbox_param_t *mhix;
markeridx_param_t *mkridx, *lastmkidx;
Byte8_t pos = 0;
long pos = 0;
mhix = ( mhixbox_param_t *)malloc( sizeof( mhixbox_param_t));
@@ -129,7 +129,7 @@ void delete_mhixbox( mhixbox_param_t **mhix)
while( mkPtr != NULL){
mkNext=mkPtr->next;
#ifndef SERVER
/* fprintf( logstream, "local log: marker index %#x deleted!\n", mkPtr->code); */
// fprintf( logstream, "local log: marker index %#x deleted!\n", mkPtr->code);
#endif
free(mkPtr);
mkPtr=mkNext;

View File

@@ -677,7 +677,7 @@ placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength)
phld = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
phld->LBox = big4( datastream);
strncpy( phld->TBox, "phld", 4);
strcpy( phld->TBox, "phld");
phld->Flags = big4( datastream+8);
phld->OrigID = big8( datastream+12);
phld->OrigBHlen = metalength - 20;

View File

@@ -115,7 +115,7 @@ bool process_JPIPrequest( server_record_t *rec, QR_t *qr)
if( !close_channel( *(qr->query), rec->sessionlist, &cursession, &curchannel))
return false;
if( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0 || qr->query->len > 0)
if( (qr->query->fx > 0 && qr->query->fy > 0) || qr->query->box_type[0][0] != 0)
if( !gene_JPIPstream( *(qr->query), target, cursession, curchannel, &qr->msgqueue))
return false;
@@ -150,8 +150,6 @@ void send_responsedata( server_record_t *rec, QR_t *qr)
fprintf( FCGI_stdout, "\r\n");
if( len_of_jpipstream){
if( qr->channel)
if( qr->channel->aux == tcp || qr->channel->aux == udp){
send_responsedata_on_aux( qr->channel->aux==tcp, rec->auxtrans, qr->channel->cid, jpipstream, len_of_jpipstream, 1000); /* 1KB per frame*/
@@ -160,10 +158,8 @@ void send_responsedata( server_record_t *rec, QR_t *qr)
if( fwrite( jpipstream, len_of_jpipstream, 1, FCGI_stdout) != 1)
fprintf( FCGI_stderr, "Error: failed to write jpipstream\n");
}
free( jpipstream);
return;
}
@@ -183,7 +179,7 @@ void add_EORmsg( int fd, QR_t *qr)
void end_QRprocess( server_record_t *rec, QR_t **qr)
{
/* TODO: record client preferences if necessary*/
(void)rec; /* unused */
delete_query( &((*qr)->query));
delete_msgqueue( &((*qr)->msgqueue));
free( *qr);

View File

@@ -41,11 +41,11 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
placeholderlist_param_t * gene_placeholderlist(void)
placeholderlist_param_t * gene_placeholderlist()
{
placeholderlist_param_t *list;
@@ -81,7 +81,7 @@ placeholder_param_t * gene_placeholder( box_param_t *box, int origID)
placeholder = (placeholder_param_t *)malloc( sizeof(placeholder_param_t));
strncpy( placeholder->TBox, "phld", 4);
placeholder->Flags = 1; /* only the access to the original contents of this box, for now */
placeholder->Flags = 1; // only the access to the original contents of this box, for now
placeholder->OrigID = origID;
placeholder->OrigBH = fetch_headbytes( box);
placeholder->OrigBHlen = box->headlen;

View File

@@ -66,7 +66,7 @@ typedef struct placeholderlist_param{
*
* @return pointer to the generated placeholder list
*/
placeholderlist_param_t * gene_placeholderlist(void);
placeholderlist_param_t * gene_placeholderlist();
/**

View File

@@ -58,7 +58,7 @@
*
* @return initial query parameters
*/
query_param_t * get_initquery(void);
query_param_t * get_initquery();
/*
* get a pair of field name and value from the string starting fieldname=fieldval&... format
@@ -141,17 +141,14 @@ query_param_t * parse_query( char *query_string)
query_param->return_type = JPTstream;
}
else if( strcasecmp( fieldname, "len") == 0){
else if( strcasecmp( fieldname, "len") == 0)
sscanf( fieldval, "%d", &query_param->len);
if( query_param->len == 2000) /* for kakadu client*/
strncpy( query_param->box_type[0], "ftyp", 4);
}
}
}
return query_param;
}
query_param_t * get_initquery(void)
query_param_t * get_initquery()
{
query_param_t *query;
int i;

View File

@@ -41,10 +41,10 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER */
#endif //SERVER
sessionlist_param_t * gene_sessionlist(void)
sessionlist_param_t * gene_sessionlist()
{
sessionlist_param_t *sessionlist;
@@ -67,9 +67,9 @@ session_param_t * gene_session( sessionlist_param_t *sessionlist)
session->next = NULL;
if( sessionlist->first) /* there are one or more entries */
if( sessionlist->first) // there are one or more entries
sessionlist->last->next = session;
else /* first entry */
else // first entry
sessionlist->first = session;
sessionlist->last = session;

View File

@@ -54,7 +54,7 @@ typedef struct sessionlist_param{
*
* @return pointer to the generated session list
*/
sessionlist_param_t * gene_sessionlist(void);
sessionlist_param_t * gene_sessionlist();
/**

View File

@@ -34,10 +34,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#ifdef __FreeBSD__
#include <netinet/in.h>
#endif
#include <unistd.h>
#endif
#include <stdio.h>
@@ -52,7 +48,7 @@
#define FCGI_stdout stdout
#define FCGI_stderr stderr
#define logstream stderr
#endif /*SERVER*/
#endif //SERVER
SOCKET open_listeningsocket( int port)
{

View File

@@ -53,7 +53,7 @@
#define logstream stderr
#endif /*SERVER*/
targetlist_param_t * gene_targetlist(void)
targetlist_param_t * gene_targetlist()
{
targetlist_param_t *targetlist;

View File

@@ -67,7 +67,7 @@ typedef struct targetlist_param{
*
* @return pointer to the generated target list
*/
targetlist_param_t * gene_targetlist(void);
targetlist_param_t * gene_targetlist();
/**

View File

@@ -4,14 +4,6 @@ INCLUDE_DIRECTORIES(
${FCGI_INCLUDE_DIRS}
)
# Tool to embed metadata into JP2 file
ADD_EXECUTABLE(addXMLinJP2 addXMLinJP2.c)
# Install exe
INSTALL(TARGETS addXMLinJP2
EXPORT OpenJPEGTargets
DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
)
IF(BUILD_JPIP_SERVER)
SET(OPJ_SERVER_SRCS
@@ -55,19 +47,8 @@ FOREACH(exe ${EXES})
ENDFOREACH(exe)
# Build the two java clients:
FIND_PACKAGE(Java 1.5 COMPONENTS Development) # javac, jar
FIND_PACKAGE(Java 1.5 REQUIRED) # 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})
# 1. opj_viewer
# build dep list:
file(GLOB java1_srcs "opj_viewer/src/*.java")
@@ -77,8 +58,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
# Build java
ADD_CUSTOM_COMMAND(
OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_viewer.jar
COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags}
-source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION}
COMMAND ${Java_JAVAC_EXECUTABLE}
${java1_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes1
COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_viewer.jar
${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/dist/manifest.txt -C
@@ -94,10 +74,6 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
COMMENT "building opj_viewer.jar"
)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/opj_viewer.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule
)
# 2. opj_viewer_xerces
# search for package org.apache.xerces.parsers
find_file(APACHE_XERCES_JAR
@@ -132,8 +108,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
# Build java
ADD_CUSTOM_COMMAND(
OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_viewer_xerces.jar
COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags}
-source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION}
COMMAND ${Java_JAVAC_EXECUTABLE}
-classpath ${APACHE_XERCES_JAR}
${java2_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes2
COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_viewer_xerces.jar
@@ -149,11 +124,4 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE)
DEPENDS ${LIBRARY_OUTPUT_PATH}/opj_viewer_xerces.jar
COMMENT "building opj_viewer_xerces.jar"
)
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/opj_viewer_xerces.jar
DESTINATION ${OPENJPEG_INSTALL_SHARE_DIR} COMPONENT JavaModule
)
endif()
else(Java_Development_FOUND)
message(WARNING "No java compiler found. Wont be able to build java viewer")
endif()

View File

@@ -73,15 +73,15 @@ char * read_xmlfile( char filename[], long *fsize);
int main(int argc, char *argv[])
{
FILE *fp;
char *xmldata, type[]="xml ";
long fsize, boxsize;
if( argc<3){
fprintf( stderr, "USAGE: ./addXMLinJP2 modifing.jp2 adding.xml\n");
return -1;
}
FILE *fp;
char *xmldata, type[]="xml ";
long fsize, boxsize;
fp = open_jp2file( argv[1]);
if( !fp)
return -1;
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
fputc( (boxsize>>8)&0xff, fp);
fputc( boxsize&0xff, fp);
fwrite( type, 4, 1, fp);
fwrite( xmldata, (size_t)fsize, 1, fp);
fwrite( xmldata, fsize, 1, fp);
free( xmldata);
fclose(fp);
@@ -111,14 +111,14 @@ FILE * open_jp2file( char filename[])
fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL;
}
/* Check resource is a JP family file. */
// Check resource is a JP family file.
if( fseek( fp, 0, SEEK_SET)==-1){
fclose(fp);
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL;
}
data = (char *)malloc( 12); /* size of header */
data = (char *)malloc( 12); // size of header
if( fread( data, 12, 1, fp) != 1){
free( data);
fclose(fp);
@@ -142,7 +142,7 @@ char * read_xmlfile( char filename[], long *fsize)
FILE *fp;
char *data;
/* fprintf( stderr, "open %s\n", filename); */
// fprintf( stderr, "open %s\n", filename);
if(!(fp = fopen( filename, "r"))){
fprintf( stderr, "XML file %s not found\n", filename);
return NULL;
@@ -166,9 +166,9 @@ char * read_xmlfile( char filename[], long *fsize)
return NULL;
}
data = (char *)malloc( (size_t)*fsize);
data = (char *)malloc( *fsize);
if( fread( data, (size_t)*fsize, 1, fp) != 1){
if( fread( data, *fsize, 1, fp) != 1){
fprintf( stderr, "XML file %s broken (read error)\n", filename);
free( data);
fclose(fp);

View File

@@ -64,7 +64,7 @@ int main(int argc,char *argv[])
if(!( fwrite_jp2k( argv[2], dec)))
return -1;
/* output_log( true, false, false, dec); */
// output_log( true, false, false, dec);
destroy_jpipdecoder( &dec);

View File

@@ -33,12 +33,11 @@
*
* \section impinst Implementing instructions
* Launch opj_dec_server from a terminal in the same machine as JPIP client image viewers. \n
* % ./opj_dec_server [portnumber]\n
* ( portnumber=50000 by default)\n
* % ./opj_dec_server \n
* Keep it alive as long as image viewers are open.\n
*
* To quite the opj_dec_server, send a message "quit" through the telnet.\n
* % telnet localhost 50000\n
* % telnet localhost 5000\n
* quit\n
* Be sure all image viewers are closed.\n
* Cache file in JPT format is stored in the working directly before it quites.
@@ -46,7 +45,6 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include "openjpip.h"
#ifdef _WIN32
@@ -57,22 +55,16 @@ int main(int argc, char *argv[]){
dec_server_record_t *server_record;
client_t client;
int port = 50000;
int erreur;
(void)erreur;
if( argc > 1)
port = atoi( argv[1]);
#ifdef _WIN32
erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
if( erreur!=0)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
printf( "Initialisation Winsock\n");
#endif /*_WIN32*/
#endif //_WIN32
server_record = init_dec_server( port);
server_record = init_dec_server( 50000);
while(( client = accept_connection( server_record)) != -1 )
if(!handle_clientreq( client, server_record))

View File

@@ -56,14 +56,11 @@
#ifdef _WIN32
WSADATA initialisation_win32;
#endif /*_WIN32*/
#endif //_WIN32
int main(void)
{
server_record_t *server_record;
#ifdef SERVER
char *query_string;
#endif
#ifdef _WIN32
int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32);
@@ -71,11 +68,13 @@ int main(void)
fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError());
else
fprintf( stderr, "Initialisation Winsock\n");
#endif /*_WIN32*/
#endif //_WIN32
server_record = init_JPIPserver( 60000, 0);
#ifdef SERVER
char *query_string;
while(FCGI_Accept() >= 0)
#else
@@ -83,16 +82,17 @@ int main(void)
while( fgets( query_string, 128, stdin) && query_string[0]!='\n')
#endif
{
QR_t *qr;
bool parse_status;
#ifdef SERVER
query_string = getenv("QUERY_STRING");
#endif /*SERVER*/
#endif //SERVER
if( strcmp( query_string, QUIT_SIGNAL) == 0)
break;
QR_t *qr;
bool parse_status;
qr = parse_querystring( query_string);
parse_status = process_JPIPrequest( server_record, qr);
@@ -103,10 +103,8 @@ int main(void)
if( parse_status)
send_responsedata( server_record, qr);
else{
else
fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n");
}
end_QRprocess( server_record, &qr);
}

View File

@@ -35,12 +35,10 @@ public class ImageManager extends JPIPHttpClient
private PnmImage pnmimage;
private int origwidth;
private int origheight;
private ImgdecClient imgdecoder;
public ImageManager( String uri, String host, int port)
public ImageManager( String uri)
{
super( uri);
imgdecoder = new ImgdecClient( host, port);
pnmimage = null;
origwidth = 0;
origheight = 0;
@@ -49,7 +47,7 @@ public class ImageManager extends JPIPHttpClient
public int getOrigWidth(){
if( origwidth == 0){
if( cid != null || tid != null){
java.awt.Dimension dim = imgdecoder.query_imagesize( cid, tid);
java.awt.Dimension dim = ImgdecClient.query_imagesize( cid, tid);
if( dim != null){
origwidth = dim.width;
origheight = dim.height;
@@ -71,10 +69,10 @@ public class ImageManager extends JPIPHttpClient
// Todo: check if the cid is for the same stream type
if( reqcnew)
refcid = imgdecoder.query_cid( j2kfilename);
refcid = ImgdecClient.query_cid( j2kfilename);
if( refcid == null){
String reftid = imgdecoder.query_tid( j2kfilename);
String reftid = ImgdecClient.query_tid( j2kfilename);
if( reftid == null)
jpipstream = super.requestViewWindow( j2kfilename, reqfw, reqfh, reqcnew, reqaux, reqJPP, reqJPT);
else
@@ -84,7 +82,7 @@ public class ImageManager extends JPIPHttpClient
jpipstream = super.requestViewWindow( reqfw, reqfh, refcid, reqcnew, reqaux, reqJPP, reqJPT);
System.err.println( "decoding to PNM image");
if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){
if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, j2kfilename, tid, cid, fw, fh))!=null){
System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh);
}
@@ -101,7 +99,7 @@ public class ImageManager extends JPIPHttpClient
byte[] jpipstream = super.requestViewWindow( reqfw, reqfh, reqrx, reqry, reqrw, reqrh);
System.err.println( "decoding to PNM image");
if((pnmimage = imgdecoder.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){
if((pnmimage = ImgdecClient.decode_jpipstream( jpipstream, tid, cid, fw, fh)) != null){
System.err.println( " done");
return pnmimage.createROIImage( rx, ry, rw, rh);
}
@@ -119,9 +117,9 @@ public class ImageManager extends JPIPHttpClient
byte[] jpipstream = super.requestXML();
if( jpipstream != null){
imgdecoder.send_JPIPstream( jpipstream);
ImgdecClient.send_JPIPstream( jpipstream);
xmldata = imgdecoder.get_XMLstream( cid);
xmldata = ImgdecClient.get_XMLstream( cid);
}
return xmldata;
}
@@ -129,7 +127,7 @@ public class ImageManager extends JPIPHttpClient
public void closeChannel()
{
if( cid != null){
imgdecoder.destroy_cid( cid);
ImgdecClient.destroy_cid( cid);
super.closeChannel();
}
}

View File

@@ -37,11 +37,11 @@ public class ImageWindow extends JFrame
private ImageViewer imgviewer;
private ImageManager imgmanager;
public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux)
public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux)
{
super( j2kfilename);
imgmanager = new ImageManager( uri, host, port);
imgmanager = new ImageManager( uri);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque
@@ -66,36 +66,25 @@ public class ImageWindow extends JFrame
public static void main(String s[])
{
String j2kfilename, uri, host;
String j2kfilename, uri;
boolean session, jppstream;
int port, aux; // 0: none, 1: tcp, 2: udp
int aux; // 0: none, 1: tcp, 2: udp
if(s.length >= 2){
uri = s[0];
j2kfilename = s[1];
if( s.length > 2)
host = s[2];
else
host = "localhost";
if( s.length > 3)
port = Integer.valueOf( s[3]).intValue();
else
port = 50000;
if( s.length > 4)
session = !s[4].equalsIgnoreCase( "stateless");
session = !s[2].equalsIgnoreCase( "stateless");
else
session = true;
if( s.length > 5)
jppstream = !s[5].equalsIgnoreCase( "JPT");
if( s.length > 3)
jppstream = !s[3].equalsIgnoreCase( "JPT");
else
jppstream = true;
if( s.length > 6){
if( s[6].equalsIgnoreCase("udp"))
if( s.length > 4){
if( s[4].equalsIgnoreCase("udp"))
aux = 2;
else
aux = 1;
@@ -104,10 +93,10 @@ public class ImageWindow extends JFrame
aux = 0;
}
else{
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]");
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]");
return;
}
ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux);
ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@@ -33,32 +33,23 @@ import java.net.*;
public class ImgdecClient{
private String hostname;
private int portNo;
public ImgdecClient( String host, int port)
{
hostname = host;
portNo = port;
}
public PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
public static PnmImage decode_jpipstream( byte[] jpipstream, String tid, String cid, int fw, int fh)
{
if( jpipstream != null)
send_JPIPstream( jpipstream);
return get_PNMstream( cid, tid, fw, fh);
}
public PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh)
public static PnmImage decode_jpipstream( byte[] jpipstream, String j2kfilename, String tid, String cid, int fw, int fh)
{
send_JPIPstream( jpipstream, j2kfilename, tid, cid);
return get_PNMstream( cid, tid, fw, fh);
}
public void send_JPIPstream( byte[] jpipstream)
public static void send_JPIPstream( byte[] jpipstream)
{
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
@@ -80,10 +71,10 @@ public class ImgdecClient{
}
}
public void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
public static void send_JPIPstream( byte[] jpipstream, String j2kfilename, String tid, String cid)
{
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
int length = 0;
@@ -118,12 +109,12 @@ public class ImgdecClient{
}
}
public PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
public static PnmImage get_PNMstream( String cid, String tid, int fw, int fh)
{
PnmImage pnmstream = null;
try {
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[7];
@@ -175,12 +166,12 @@ public class ImgdecClient{
return pnmstream;
}
public byte [] get_XMLstream( String cid)
public static byte [] get_XMLstream( String cid)
{
byte []xmldata = null;
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[5];
@@ -206,7 +197,7 @@ public class ImgdecClient{
return xmldata;
}
public String query_cid( String j2kfilename)
public static String query_cid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 67;
@@ -216,7 +207,7 @@ public class ImgdecClient{
return query_id( "CID request", j2kfilename, retmsglabel);
}
public String query_tid( String j2kfilename)
public static String query_tid( String j2kfilename)
{
int []retmsglabel = new int[3];
retmsglabel[0] = 84;
@@ -226,12 +217,12 @@ public class ImgdecClient{
return query_id( "TID request", j2kfilename, retmsglabel);
}
public String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
public static String query_id( String reqmsghead, String j2kfilename, int[] retmsglabel)
{
String id = null;
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[4];
@@ -263,12 +254,12 @@ public class ImgdecClient{
return id;
}
public java.awt.Dimension query_imagesize( String cid, String tid)
public static java.awt.Dimension query_imagesize( String cid, String tid)
{
java.awt.Dimension dim = null;
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());
byte []header = new byte[3];
@@ -306,7 +297,7 @@ public class ImgdecClient{
return dim;
}
private static void read_stream( DataInputStream is, byte []stream, int length)
public static void read_stream( DataInputStream is, byte []stream, int length)
{
int remlen = length;
int off = 0;
@@ -327,10 +318,10 @@ public class ImgdecClient{
}
}
public void destroy_cid( String cid)
public static void destroy_cid( String cid)
{
try{
Socket imgdecSocket = new Socket( hostname, portNo);
Socket imgdecSocket = new Socket( "localhost", 50000);
DataOutputStream os = new DataOutputStream( imgdecSocket.getOutputStream());
DataInputStream is = new DataInputStream( imgdecSocket.getInputStream());

View File

@@ -38,11 +38,11 @@ public class ImageWindow extends JFrame
private OptionPanel optpanel;
private ImageManager imgmanager;
public ImageWindow( String uri, String j2kfilename, String host, int port, boolean session, boolean jppstream, int aux)
public ImageWindow( String uri, String j2kfilename, boolean session, boolean jppstream, int aux)
{
super( j2kfilename);
imgmanager = new ImageManager( uri, host, port);
imgmanager = new ImageManager( uri);
imgviewer = new ImageViewer( j2kfilename, imgmanager, session, jppstream, aux);
imgviewer.setOpaque(true); //content panes must be opaque
@@ -70,36 +70,25 @@ public class ImageWindow extends JFrame
public static void main(String s[])
{
String j2kfilename, uri, host;
String j2kfilename, uri;
boolean session, jppstream;
int port, aux; // 0: none, 1: tcp, 2: udp
int aux; // 0: none, 1: tcp, 2: udp
if(s.length >= 2){
uri = s[0];
j2kfilename = s[1];
if( s.length > 2)
host = s[2];
else
host = "localhost";
if( s.length > 3)
port = Integer.valueOf( s[3]).intValue();
else
port = 50000;
if( s.length > 4)
session = !s[4].equalsIgnoreCase( "stateless");
session = !s[2].equalsIgnoreCase( "stateless");
else
session = true;
if( s.length > 5)
jppstream = !s[5].equalsIgnoreCase( "JPT");
if( s.length > 3)
jppstream = !s[3].equalsIgnoreCase( "JPT");
else
jppstream = true;
if( s.length > 6){
if( s[6].equalsIgnoreCase("udp"))
if( s.length > 4){
if( s[4].equalsIgnoreCase("udp"))
aux = 2;
else
aux = 1;
@@ -108,10 +97,10 @@ public class ImageWindow extends JFrame
aux = 0;
}
else{
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [hostname] [portnumber] [stateless/session] [JPT/JPP] [tcp/udp]");
System.out.println("Usage: java -jar opj_viewer.jar HTTP_server_URI imagefile.jp2 [stateless/session] [JPT/JPP] [tcp/udp]");
return;
}
ImageWindow frame = new ImageWindow( uri, j2kfilename, host, port, session, jppstream, aux);
ImageWindow frame = new ImageWindow( uri, j2kfilename, session, jppstream, aux);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

View File

@@ -31,7 +31,6 @@
#include <string.h>
#include "openjpeg.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "mj2.h"
@@ -61,52 +60,34 @@ void info_callback(const char *msg, void *client_data) {
}
/* -------------------------------------------------------------------------- */
#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
int main(int argc, char *argv[]) {
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
int tnum, failed;
int tnum;
unsigned int snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *mj2file, *outfile;
char *outfilename;
FILE *file, *outfile;
char outfilename[50];
mj2_dparameters_t parameters;
if (argc != 3) {
printf("\nUsage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n\n",argv[0]);
printf("Usage: %s mj2filename output_location\n",argv[0]);
printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
return 1;
}
mj2file = fopen(argv[1], "rb");
file = fopen(argv[1], "rb");
if (!mj2file) {
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
{
unsigned char buf[28];
memset(buf, 0, 28);
fread(buf, 1, 24, mj2file);
if(memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0
&& memcmp(buf+20, "\x6d\x6a\x70\x32", 4) == 0)
{
rewind(mj2file);
}
else
{
fclose(mj2file);
fprintf(stderr,"%s:%d: %s\n\tThis file is not an MJ2 file."
"Quitting\n",__FILE__,__LINE__, argv[0]);
return 1;
}
}
/*
configure the event callbacks (not required)
setting of each callback is optionnal
@@ -116,15 +97,9 @@ int main(int argc, char *argv[]) {
event_mgr.warning_handler = warning_callback;
event_mgr.info_handler = info_callback;
failed = 1;
outfilename = (char*)malloc(strlen(argv[2]) + 32);
if(outfilename == NULL) goto fin;
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
if(dinfo == NULL) goto fin;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
@@ -133,62 +108,42 @@ int main(int argc, char *argv[]) {
movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(movie, &parameters);
/* Create the movie structure: */
if (mj2_read_struct(mj2file, movie))
goto fin;
if (mj2_read_struct(file, movie)) // Creating the movie structure
return 1;
/* Decode first video track : */
// Decode first video track
tnum = 0;
while (movie->tk[tnum].track_type != 0)
tnum ++;
track = &movie->tk[tnum];
if(track->jp2_struct.enumcs != ENUMCS_SRGB
&& track->jp2_struct.enumcs != ENUMCS_GRAY)
{
fprintf(stderr,"%s:%d: %s\n"
"\tERROR: this MJ2 file does not contain J2K frames.\n"
"\tPlease try mj2_to_frames for this file.\n",
__FILE__,__LINE__, argv[0]);
goto fin;
}
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++)
{
sample = &track->sample[snum];
frame_codestream = (unsigned char*)
malloc (sample->sample_size-8); /* Skipping JP2C marker */
fseek(mj2file,sample->offset+8,SEEK_SET);
/* Assuming that jp and ftyp markers size do: */
fread(frame_codestream,sample->sample_size-8,1, mj2file);
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); // Skipping JP2C marker
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream,sample->sample_size-8,1, file); // Assuming that jp and ftyp markers size do
sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
goto fin;
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
free(frame_codestream);
}
fclose(file);
fprintf(stdout, "%d frames correctly extracted\n", snum);
failed = 0;
fin:
fclose(mj2file);
free(outfilename);
/* free remaining structures */
if(dinfo)
{
mj2_destroy_decompress(movie);
free(dinfo);
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
return failed;
}/* main() */
return 0;
}

View File

@@ -31,9 +31,9 @@
#include "openjpeg.h"
#include "j2k_lib.h"
#include "cio.h"
#include "j2k.h"
#include "jp2.h"
#include "cio.h"
#include "mj2.h"
#include "mj2_convert.h"
#include "opj_getopt.h"
@@ -43,6 +43,10 @@ Size of memory first allocated for MOOV box
*/
#define TEMP_BUF 10000
#define ENUMCS_GRAY 16
#define ENUMCS_SRGB 17
#define ENUMCS_SYCC 18
/* -------------------------------------------------------------------------- */
/**
@@ -234,7 +238,7 @@ int main(int argc, char **argv)
opj_cparameters_t *j2k_parameters; /* J2K compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio;
int value, failed;
int value;
opj_mj2_t *movie;
opj_image_t *img;
int i, j;
@@ -253,13 +257,13 @@ int main(int argc, char **argv)
memset(&mj2_parameters, 0, sizeof(mj2_cparameters_t));
/* default value */
/* ------------- */
mj2_parameters.w = 352; /* CIF default value */
mj2_parameters.h = 288; /* CIF default value */
mj2_parameters.CbCr_subsampling_dx = 2; /* CIF default value */
mj2_parameters.CbCr_subsampling_dy = 2; /* CIF default value */
mj2_parameters.w = 352; // CIF default value
mj2_parameters.h = 288; // CIF default value
mj2_parameters.CbCr_subsampling_dx = 2; // CIF default value
mj2_parameters.CbCr_subsampling_dy = 2; // CIF default value
mj2_parameters.frame_rate = 25;
mj2_parameters.prec = 8; /* DEFAULT */
mj2_parameters.enumcs = ENUMCS_SYCC;
mj2_parameters.enumcs = ENUMCS_SYCC; /* FIXME: ENUMCS_YUV420 */
mj2_parameters.meth = 1; /* enumerated color space */
/*
@@ -616,7 +620,7 @@ int main(int argc, char **argv)
/* -------------- */
if (!mj2_parameters.cod_format || !mj2_parameters.decod_format) {
fprintf(stderr,
"\nUsage: %s -i yuv-file -o mj2-file (+ options)\n\n",argv[0]);
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1;
}
if(prec < 1 || prec > 16)
@@ -678,11 +682,9 @@ int main(int argc, char **argv)
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
failed = 1;
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
if(cinfo == NULL) goto fin;
movie = (opj_mj2_t*)cinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
@@ -695,33 +697,27 @@ int main(int argc, char **argv)
yuv_num_frames(&movie->tk[0],mj2_parameters.infile);
if (movie->tk[0].num_samples == 0) {
goto fin;
return 1;
}
/* One sample per chunk */
// One sample per chunk
movie->tk[0].chunk = (mj2_chunk_t*)
malloc(movie->tk[0].num_samples * sizeof(mj2_chunk_t));
movie->tk[0].sample = (mj2_sample_t*)
malloc(movie->tk[0].num_samples * sizeof(mj2_sample_t));
if(movie->tk[0].chunk == NULL || movie->tk[0].sample == NULL)
goto fin;
if (mj2_init_stdmovie(movie)) {
fprintf(stderr, "Error with movie initialization");
goto fin;
return 1;
}
/* Writing JP, FTYP and MDAT boxes */
/* Assuming that the JP and FTYP boxes won't be longer than 300 bytes:*/
// Writing JP, FTYP and MDAT boxes
// Assuming that the JP and FTYP boxes won't be longer than 300 bytes:
buf = (unsigned char*)
malloc (300 * sizeof(unsigned char));
if(buf == NULL) goto fin;
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, 300);
if(cio == NULL) goto fin;
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
@@ -733,52 +729,42 @@ int main(int argc, char **argv)
fwrite(buf,cio_tell(cio),1,mj2file);
offset = cio_tell(cio);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
buf = NULL; numframes = 0;
free(buf);
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++)
{
mj2_tk_t *track;
track = &movie->tk[i];
numframes = track->num_samples;
if(track->track_type != 0)
if(movie->tk[i].track_type != 0)
{
fprintf(stderr, "Unable to write sound or hint tracks\n");
}
else
{
mj2_tk_t *tk;
int buflen = 0;
track->num_chunks = track->num_samples;
track->depth = prec;
tk = &movie->tk[i];
tk->num_chunks = tk->num_samples;
numframes = tk->num_samples;
tk->depth = prec;
fprintf(stderr, "Video Track number %d\n", i);
img = mj2_image_create(track, j2k_parameters);
if(img == NULL) goto fin;
img = mj2_image_create(tk, j2k_parameters);
buflen = 2 * (track->w * track->h * 8);
buflen = 2 * (tk->w * tk->h * 8);
buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
if(buf == NULL)
{
opj_image_destroy(img);
goto fin;
}
for(sampleno = 0; sampleno < numframes; sampleno++)
{
double init_time = opj_clock();
double elapsed_time;
if(yuvtoimage(track, img, sampleno, j2k_parameters,
if(yuvtoimage(tk, img, sampleno, j2k_parameters,
mj2_parameters.infile))
{
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
opj_image_destroy(img);
goto fin;
return 1;
}
/* setup the encoder parameters using the current image and user parameters */
@@ -786,21 +772,16 @@ int main(int argc, char **argv)
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, buflen);
if(cio == NULL) goto fin;
cio_skip(cio, 4);
cio_write(cio, JP2_JP2C, 4);
cio_write(cio, JP2_JP2C, 4); // JP2C
/* encode the image */
bSuccess = opj_encode(cinfo, cio, img, NULL);
if (!bSuccess) {
opj_image_destroy(img);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
buf = NULL;
fprintf(stderr, "failed to encode image\n");
goto fin;
return 1;
}
len = cio_tell(cio) - 8;
@@ -808,9 +789,9 @@ int main(int argc, char **argv)
cio_write(cio, len+8,4);
opj_cio_close(cio);
track->sample[sampleno].sample_size = len+8;
track->sample[sampleno].offset = offset;
track->chunk[sampleno].offset = offset; /* There is one sample per chunk */
tk->sample[sampleno].sample_size = len+8;
tk->sample[sampleno].offset = offset;
tk->chunk[sampleno].offset = offset; // There is one sample per chunk
fwrite(buf, 1, len+8, mj2file);
offset += len+8;
@@ -820,59 +801,43 @@ int main(int argc, char **argv)
total_time += elapsed_time;
} /* for(sampleno */
free(buf); buf = NULL;
free(buf);
opj_image_destroy(img);
} /* if(track ) */
}
}/* for(i */
fseek(mj2file, mdat_initpos, SEEK_SET);
buf = (unsigned char*) malloc(4*sizeof(unsigned char));
if(buf == NULL) goto fin;
/* Init a cio to write box length variable in a little endian way */
// Init a cio to write box length variable in a little endian way
cio = opj_cio_open(NULL, buf, 4);
if(cio == NULL) goto fin;
cio_write(cio, offset - mdat_initpos, 4);
fwrite(buf, 4, 1, mj2file);
fseek(mj2file,0,SEEK_END);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
free(buf);
/* Writing MOOV box */
// Writing MOOV box
buf = (unsigned char*)
malloc ((TEMP_BUF+numframes*20) * sizeof(unsigned char));
if(buf == NULL) goto fin;
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+numframes*20));
if(cio == NULL) goto fin;
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
free(buf);
fprintf(stdout,"Total encoding time: %.2f s for %d frames (%.1f fps)\n",
total_time, numframes, (float)numframes/total_time);
failed = 0;
fin:
// Ending program
fclose(mj2file);
/* free remaining compression structures */
if(cinfo)
{
mj2_destroy_compress(movie);
free(cinfo);
}
if(j2k_parameters->cp_comment) free(j2k_parameters->cp_comment);
if(j2k_parameters->cp_matrice) free(j2k_parameters->cp_matrice);
opj_cio_close(cio);
if(failed) remove(mj2_parameters.outfile);
return failed;
return 0;
}

View File

@@ -1096,8 +1096,8 @@ int mj2_read_smj2(opj_image_t * img, mj2_tk_t * tk, opj_cio_t *cio)
{
mj2_box_t box;
mj2_box_t box2;
opj_jp2_color_t color;
int i;
opj_jp2_color_t color;
opj_bool ok;
mj2_read_boxhdr(&box, cio);
@@ -1236,10 +1236,10 @@ void mj2_write_stsd(mj2_tk_t * tk, opj_cio_t *cio)
if (tk->track_type == 0) {
mj2_write_smj2(tk, cio);
} else if (tk->track_type == 1) {
/* Not implemented */
// Not implemented
}
if (tk->track_type == 2) {
/* Not implemented */
// Not implemented
}
@@ -1287,10 +1287,10 @@ int mj2_read_stsd(mj2_tk_t * tk, opj_image_t * img, opj_cio_t *cio)
return 1;
}
} else if (tk->track_type == 1) {
len_2skip = cio_read(cio, 4); /* Not implemented -> skipping box */
len_2skip = cio_read(cio, 4); // Not implemented -> skipping box
cio_skip(cio,len_2skip - 4);
} else if (tk->track_type == 2) {
len_2skip = cio_read(cio, 4); /* Not implemented -> skipping box */
len_2skip = cio_read(cio, 4); // Not implemented -> skipping box
cio_skip(cio,len_2skip - 4);
}
@@ -2111,7 +2111,7 @@ int mj2_read_mdhd(mj2_tk_t * tk, opj_cio_t *cio)
mj2_box_t box;
mj2_read_boxhdr(&box, cio);
if (!(MJ2_MHDR == box.type || MJ2_MDHD == box.type)) { /* Kakadu writes MHDR instead of MDHD */
if (!(MJ2_MHDR == box.type || MJ2_MDHD == box.type)) { // Kakadu writes MHDR instead of MDHD
opj_event_msg(cio->cinfo, EVT_ERROR, "Error: Expected MDHD Marker\n");
return 1;
}
@@ -2765,10 +2765,10 @@ void mj2_destroy_decompress(opj_mj2_t *movie) {
tk = &movie->tk[i];
if (tk->name_size != 0)
opj_free(tk->name);
if (tk->track_type == 0) {/* Video track */
if (tk->jp2_struct.comps != NULL)
if (tk->track_type == 0) {// Video track
if (tk->jp2_struct.comps != 0)
opj_free(tk->jp2_struct.comps);
if (tk->jp2_struct.cl != NULL)
if (tk->jp2_struct.cl != 0)
opj_free(tk->jp2_struct.cl);
if (tk->num_jp2x != 0)
opj_free(tk->jp2xdata);
@@ -2821,20 +2821,20 @@ void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters) {
if(movie && parameters) {
opj_jp2_t *jp2_struct;
movie->num_htk = 0; /* No hint tracks */
movie->num_stk = 0; /* No sound tracks */
movie->num_vtk = 1; /* One video track */
movie->num_htk = 0; // No hint tracks
movie->num_stk = 0; // No sound tracks
movie->num_vtk = 1; // One video track
movie->brand = MJ2_MJ2; /* One brand: MJ2 */
movie->num_cl = 2; /* Two compatible brands: MJ2 and MJ2S */
movie->brand = MJ2_MJ2; // One brand: MJ2
movie->num_cl = 2; // Two compatible brands: MJ2 and MJ2S
movie->cl = (unsigned int*) opj_malloc(movie->num_cl * sizeof(unsigned int));
movie->cl[0] = MJ2_MJ2;
movie->cl[1] = MJ2_MJ2S;
movie->minversion = 0; /* Minimum version: 0 */
movie->minversion = 0; // Minimum version: 0
movie->tk = (mj2_tk_t*) opj_malloc(sizeof(mj2_tk_t)); /*Memory allocation for the video track*/
movie->tk[0].track_ID = 1; /* Track ID = 1 */
movie->tk[0].track_type = 0; /* Video track */
movie->tk = (mj2_tk_t*) opj_malloc(sizeof(mj2_tk_t)); //Memory allocation for the video track
movie->tk[0].track_ID = 1; // Track ID = 1
movie->tk[0].track_type = 0; // Video track
movie->tk[0].Dim[0] = parameters->Dim[0];
movie->tk[0].Dim[1] = parameters->Dim[1];
movie->tk[0].w = parameters->w;
@@ -2848,7 +2848,7 @@ void mj2_setup_encoder(opj_mj2_t *movie, mj2_cparameters_t *parameters) {
movie->tk[0].depth = parameters->prec;
jp2_struct = &movie->tk[0].jp2_struct;
jp2_struct->numcomps = parameters->numcomps; /* NC */
jp2_struct->numcomps = parameters->numcomps; // NC
jp2_struct->comps = (opj_jp2_comps_t*) opj_malloc(jp2_struct->numcomps * sizeof(opj_jp2_comps_t));
jp2_struct->precedence = 0; /* PRECEDENCE*/
jp2_struct->approx = 0; /* APPROX*/
@@ -2884,10 +2884,10 @@ void mj2_destroy_compress(opj_mj2_t *movie) {
tk = &movie->tk[i];
if (tk->name_size != 0)
opj_free(tk->name);
if (tk->track_type == 0) {/* Video track */
if (tk->jp2_struct.comps != NULL)
if (tk->track_type == 0) {// Video track
if (tk->jp2_struct.comps != 0)
opj_free(tk->jp2_struct.comps);
if (tk->jp2_struct.cl != NULL)
if (tk->jp2_struct.cl != 0)
opj_free(tk->jp2_struct.cl);
if (tk->num_jp2x != 0)
opj_free(tk->jp2xdata);

View File

@@ -137,7 +137,7 @@ typedef struct mj2_url {
URN
*/
typedef struct mj2_urn {
int name[4];
int name[2];
int location[4];
} mj2_urn_t;

View File

@@ -67,12 +67,12 @@ unsigned int yuv_num_frames(mj2_tk_t * tk, char *infile)
return (unsigned int)(end_of_f / frame_size);
}
/* -----------------------
YUV to IMAGE
-----------------------*/
// -----------------------
//
//
// YUV to IMAGE
//
// -----------------------
opj_image_t *mj2_image_create(mj2_tk_t * tk, opj_cparameters_t *parameters)
{
@@ -169,12 +169,12 @@ char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters
/* -----------------------
IMAGE to YUV
-----------------------*/
// -----------------------
//
//
// IMAGE to YUV
//
// -----------------------
opj_bool imagetoyuv(opj_image_t * img, char *outfile)
@@ -263,12 +263,12 @@ opj_bool imagetoyuv(opj_image_t * img, char *outfile)
return OPJ_TRUE;
}
/* -----------------------
IMAGE to BMP
-----------------------*/
// -----------------------
//
//
// IMAGE to BMP
//
// -----------------------
int imagetobmp(opj_image_t * img, char *outfile) {
int w,wr,h,hr,i,pad;
@@ -353,11 +353,11 @@ int imagetobmp(opj_image_t * img, char *outfile) {
for (i = 0; i < wr * hr; i++) {
unsigned char R, G, B;
/* a modifier */
/* R = img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];*/
// R = img->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
R = img->comps[0].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
/* G = img->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];*/
// G = img->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
G = img->comps[1].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
/* B = img->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];*/
// B = img->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
B = img->comps[2].data[w * hr - ((i) / (wr) + 1) * w + (i) % (wr)];
fprintf(f, "%c%c%c", B, G, R);

View File

@@ -69,67 +69,45 @@ void info_callback(const char *msg, void *client_data) {
}
/* -------------------------------------------------------------------------- */
#define JP2_RFC3745_MAGIC "\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a"
int main(int argc, char *argv[]) {
mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio = NULL;
unsigned int tnum, snum, failed;
unsigned int tnum, snum;
opj_mj2_t *movie;
mj2_tk_t *track;
mj2_sample_t *sample;
unsigned char* frame_codestream;
FILE *infile, *outfile;
FILE *file, *outfile;
char outfilename[50];
opj_image_t *img = NULL;
unsigned int max_codstrm_size = 0;
double total_time = 0;
unsigned int numframes = 0;
if (argc != 3) {
printf("\nUsage: %s inputfile.mj2 outputfile.yuv\n\n",argv[0]);
printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]);
return 1;
}
infile = fopen(argv[1], "rb");
file = fopen(argv[1], "rb");
if (!infile) {
if (!file) {
fprintf(stderr, "failed to open %s for reading\n", argv[1]);
return 1;
}
{
unsigned char buf[28];
size_t n;
memset(buf, 0, 28);
n = fread(buf, 1, 24, infile);
if(memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0
&& memcmp(buf+20, "\x6d\x6a\x70\x32", 4) == 0)
{
rewind(infile);
}
else
{
fclose(infile);
fprintf(stderr,"%s:%d: %s\n\tThis file is not an MJ2 file."
"Quitting\n",__FILE__,__LINE__,argv[0]);
return 1;
}
}
/* Checking output file: */
// Checking output file
outfile = fopen(argv[2], "w");
if (!outfile) {
if (!file) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
fclose(infile);
return 1;
}
fclose(outfile); remove(argv[2]);
fclose(outfile);
frame_codestream = NULL;
failed = 1;
/*
configure the event callbacks (not required)
setting of each callback is optionnal
@@ -141,8 +119,6 @@ int main(int argc, char *argv[]) {
/* get a MJ2 decompressor handle */
dinfo = mj2_create_decompress();
if(dinfo == NULL) goto fin;
movie = (opj_mj2_t*)dinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
@@ -155,11 +131,10 @@ int main(int argc, char *argv[]) {
/* setup the decoder decoding parameters using user parameters */
mj2_setup_decoder(movie, &mj2_parameters);
/* Create the movie structure: */
if (mj2_read_struct(infile, movie))
goto fin;
if (mj2_read_struct(file, movie)) // Creating the movie structure
return 1;
/* Decode first video track */
// Decode first video track
for (tnum=0; tnum < (unsigned int)(movie->num_htk + movie->num_stk + movie->num_vtk); tnum++) {
if (movie->tk[tnum].track_type == 0)
break;
@@ -167,27 +142,17 @@ int main(int argc, char *argv[]) {
if (movie->tk[tnum].track_type != 0) {
printf("Error. Movie does not contain any video track\n");
goto fin;
return 1;
}
track = &movie->tk[tnum];
if(track->jp2_struct.enumcs != ENUMCS_SYCC)
{
fprintf(stderr,"%s:%d: %s\n"
"\tERROR: this MJ2 file does not contain YUV frames.\n"
"\tPlease try extract_j2k_from_mj2 for this file.\n",
__FILE__,__LINE__,argv[0]);
goto fin;
}
/* Output info on first video track: */
// Output info on first video tracl
fprintf(stdout,"The first video track contains %d frames.\nWidth: %d, Height: %d \n\n",
track->num_samples, track->w, track->h);
max_codstrm_size = track->sample[0].sample_size-8;
frame_codestream = (unsigned char*)
malloc(max_codstrm_size * sizeof(unsigned char));
if(frame_codestream == NULL) goto fin;
frame_codestream = (unsigned char*) malloc(max_codstrm_size * sizeof(unsigned char));
numframes = track->num_samples;
@@ -202,54 +167,85 @@ int main(int argc, char *argv[]) {
if ((frame_codestream = (unsigned char*)
realloc(frame_codestream, max_codstrm_size)) == NULL) {
printf("Error reallocation memory\n");
goto fin;
return 1;
};
}
fseek(infile,sample->offset+8,SEEK_SET);
/* Assuming that jp and ftyp markers size do: */
fread(frame_codestream, sample->sample_size-8, 1, infile);
fseek(file,sample->offset+8,SEEK_SET);
fread(frame_codestream, sample->sample_size-8, 1, file); // Assuming that jp and ftyp markers size do
/* open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
if(cio == NULL) goto fin;
img = opj_decode(dinfo, cio); // Decode J2K to image
img = opj_decode(dinfo, cio);
if(img == NULL) goto fin;
/* Convert frame to YUV: */
if (!imagetoyuv(img, argv[2]))
goto fin;
opj_cio_close(cio);
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n",
snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
}/* for (snum */
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n",
total_time, (float)numframes/total_time);
failed = 0;
fin:
fclose(infile);
if(frame_codestream) free(frame_codestream);
/* free remaining structures */
if(dinfo)
#ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC)
{
mj2_destroy_decompress(movie);
free(dinfo);
color_sycc_to_rgb(img);
}
#endif
if(img->icc_profile_buf)
{
#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
color_apply_icc_profile(img);
#endif
free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0;
}
return failed;
}/* main() */
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) {
if (!imagetoyuv(img, argv[2])) // Convert image to YUV
return 1;
}
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1))// If YUV 4:4:4 input --> to bmp
{
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) // Convert image to BMP
return 1;
}
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");
sprintf(outfilename,"output_%d.j2k",snum);
outfile = fopen(outfilename, "wb");
if (!outfile) {
fprintf(stderr, "failed to open %s for writing\n",outfilename);
return 1;
}
fwrite(frame_codestream,sample->sample_size-8,1,outfile);
fclose(outfile);
}
/* close the byte stream */
opj_cio_close(cio);
/* free image data structure */
opj_image_destroy(img);
elapsed_time = opj_clock()-init_time;
fprintf(stderr, "Frame number %d/%d decoded in %.2f mseconds\n", snum + 1, numframes, elapsed_time*1000);
total_time += elapsed_time;
}
free(frame_codestream);
fclose(file);
/* free remaining structures */
if(dinfo) {
mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
}
free(dinfo);
fprintf(stdout, "%d frame(s) correctly decompressed\n", snum);
fprintf(stdout,"Total decoding time: %.2f seconds (%.1f fps)\n", total_time, (float)numframes/total_time);
return 0;
}

View File

@@ -45,6 +45,10 @@ Size of memory first allocated for MOOV box
*/
#define TEMP_BUF 10000
#define ENUMCS_GRAY 16
#define ENUMCS_SRGB 17
#define ENUMCS_SYCC 18
#define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
/* -------------------------------------------------------------------------- */
@@ -73,8 +77,6 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0)
{
fprintf(stderr,"%s:%d:\n\tONLY J2K files are accepted. Quitting.\n",
__FILE__,__LINE__);
free(src); return success;
}
memset(&dparameters, 0, sizeof(opj_dparameters_t));
@@ -87,12 +89,8 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len);
if(cio == NULL) goto fin;
image = opj_decode(dinfo, cio);
if(image == NULL) goto fin;
free(src); cio->buffer = NULL;
opj_cio_close(cio);
@@ -103,17 +101,68 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec;
if(image->numcomps > 2)/* RGB or RGBA */
if(image->numcomps > 2 )
{
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))// horizontal and vertical
{
// Y420
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))// horizontal only
{
// Y422
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1;
}
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
{
// Y444 or RGB
if(image->color_space == CLRSPC_SRGB)
{
cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
// cp->CbCr_subsampling_dx = 0;
// cp->CbCr_subsampling_dy = 0;
}
else /* GRAY or GRAYA */
else
{
cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1;
}
}
else
{
goto fin;
}
}
else
{
cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */
// cp->CbCr_subsampling_dx = 0;
// cp->CbCr_subsampling_dy = 0;
}
if(image->icc_profile_buf)
{
@@ -181,8 +230,6 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len);
if(cio == NULL) goto fin;
cio_read(cio, 2); /* Rsiz (capabilities) */
image->x1 = cio_read(cio, 4); /* Xsiz */
image->y1 = cio_read(cio, 4); /* Ysiz */
@@ -206,8 +253,6 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
}
fseek(file, 0, SEEK_SET);
opj_cio_close(cio);
fin:
free(siz_buffer);
}
@@ -216,28 +261,50 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
movie->tk[0].h = int_ceildiv(image->y1 - image->y0, image->comps[0].dy);
mj2_init_stdmovie(movie);
movie->tk[0].depth = image->comps[0].prec;
movie->tk[0].CbCr_subsampling_dx = 0;
movie->tk[0].CbCr_subsampling_dy = 0;
if (image->numcomps==3) {
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
else
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
}
movie->tk[0].sample_rate = 25;
movie->tk[0].jp2_struct.numcomps = image->numcomps;/* NC */
movie->tk[0].jp2_struct.numcomps = image->numcomps; // NC
/* Init Standard jp2 structure */
movie->tk[0].jp2_struct.comps = (opj_jp2_comps_t *)
malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.comps =
(opj_jp2_comps_t *) malloc(movie->tk[0].jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
movie->tk[0].jp2_struct.precedence = 0; /* PRECEDENCE*/
movie->tk[0].jp2_struct.approx = 0; /* APPROX*/
movie->tk[0].jp2_struct.brand = JP2_JP2; /* BR */
movie->tk[0].jp2_struct.minversion = 0; /* MinV */
movie->tk[0].jp2_struct.numcl = 1;
movie->tk[0].jp2_struct.cl = (unsigned int *)
malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl = (unsigned int *) malloc(movie->tk[0].jp2_struct.numcl * sizeof(int));
movie->tk[0].jp2_struct.cl[0] = JP2_JP2; /* CL0 : JP2 */
movie->tk[0].jp2_struct.C = 7; /* C : Always 7*/
movie->tk[0].jp2_struct.UnkC = 0; /* UnkC, colorspace specified in colr box*/
@@ -266,6 +333,29 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
else
movie->tk[0].jp2_struct.meth = 2;
if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; // Grayscale
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; // RGB
else
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))
movie->tk[0].jp2_struct.enumcs = 18; // YUV
else
movie->tk[0].jp2_struct.enumcs = 0; // Unkown profile */
}
int main(int argc, char *argv[]) {
@@ -278,14 +368,14 @@ int main(int argc, char *argv[]) {
FILE *mj2file, *j2kfile;
char *j2kfilename;
unsigned char *buf;
int offset, mdat_initpos, failed;
int offset, mdat_initpos;
opj_image_t img;
opj_cio_t *cio;
mj2_cparameters_t parameters;
if (argc != 3) {
printf("\nUsage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n\n",argv[0]);
printf("Usage: %s source_location mj2_filename\n",argv[0]);
printf("Example: %s input/input output.mj2\n",argv[0]);
return 1;
}
@@ -295,7 +385,6 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "failed to open %s for writing\n", argv[2]);
return 1;
}
failed = 1;
memset(&img, 0, sizeof(opj_image_t));
/*
configure the event callbacks (not required)
@@ -309,8 +398,6 @@ int main(int argc, char *argv[]) {
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
if(cinfo == NULL) goto fin;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
@@ -319,7 +406,7 @@ int main(int argc, char *argv[]) {
movie = (opj_mj2_t*) cinfo->mj2_handle;
j2kfilename = (char*)malloc(strlen(argv[1]) + 12);/* max. '%6d' */
sprintf(j2kfilename, "%s_00000.j2k",argv[1]);
sprintf(j2kfilename, "%s_00001.j2k",argv[1]);
if(test_image(j2kfilename, &parameters) == 0) goto fin;
@@ -329,17 +416,10 @@ int main(int argc, char *argv[]) {
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes
*/
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
if(buf == NULL) goto fin;
cio = opj_cio_open(movie->cinfo, buf, 300);
if(cio == NULL) goto fin;
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
mdat_initpos = cio_tell(cio);
@@ -348,7 +428,7 @@ int main(int argc, char *argv[]) {
fwrite(buf,cio_tell(cio),1,mj2file);
free(buf);
/* Insert each j2k codestream in a JP2C box */
// Insert each j2k codestream in a JP2C box
snum=0;
offset = 0;
while(1)
@@ -356,44 +436,43 @@ int main(int argc, char *argv[]) {
sample = &movie->tk[0].sample[snum];
sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile)
{
/* No more files found: done. Leave while(1) loop: */
if (!j2kfile) {
if (snum==0) { // Could not open a single codestream
fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1;
}
else { // Tried to open a inexistant codestream
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break;
}
}
/* Calculating offset for samples and chunks: */
// Calculating offset for samples and chunks
offset += cio_tell(cio);
sample->offset = offset;
/* There will be one sample per chunk: */
movie->tk[0].chunk[snum].offset = offset;
movie->tk[0].chunk[snum].offset = offset; // There will be one sample per chunk
/* Calculating sample size: */
// Calculating sample size
fseek(j2kfile,0,SEEK_END);
/* Sample size is codestream + JP2C box header: */
sample->sample_size = ftell(j2kfile) + 8;
sample->sample_size = ftell(j2kfile) + 8; // Sample size is codestream + JP2C box header
fseek(j2kfile,0,SEEK_SET);
/* Reading siz marker of j2k image for the first codestream */
// Reading siz marker of j2k image for the first codestream
if (snum==0)
read_siz_marker(j2kfile, &img);
frame_codestream = (unsigned char*)
malloc (sample->sample_size+8);
// Writing JP2C box header
frame_codestream = (unsigned char*) malloc (sample->sample_size+8);
cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);
cio_write(cio,sample->sample_size, 4); // Sample size
cio_write(cio,JP2_JP2C, 4); // JP2C
if(cio == NULL) goto fin;
/* Writing JP2C box header: */
cio_write(cio,sample->sample_size, 4);
cio_write(cio,JP2_JP2C, 4);
/* Writing codestream from J2K file to MJ2 file */
// Writing codestream from J2K file to MJ2 file
fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
fwrite(frame_codestream,sample->sample_size,1,mj2file);
cio_skip(cio, sample->sample_size-8);
// Ending loop
fclose(j2kfile);
snum++;
movie->tk[0].sample = (mj2_sample_t*)
@@ -401,63 +480,37 @@ int main(int argc, char *argv[]) {
movie->tk[0].chunk = (mj2_chunk_t*)
realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
free(frame_codestream);
}/* while(1) */
}
/* Writing the MDAT box length in header */
// Writing the MDAT box length in header
offset += cio_tell(cio);
buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
if(buf == NULL) goto fin;
cio = opj_cio_open(movie->cinfo, buf, 4);
if(cio == NULL) goto fin;
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
fwrite(buf,4,1,mj2file);
fseek(mj2file,0,SEEK_END);
free(buf);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
/* Setting movie parameters: */
// Setting movie parameters
movie->tk[0].num_samples=snum;
movie->tk[0].num_chunks=snum;
setparams(movie, &img);
/* Writing MOOV box */
// Writing MOOV box
buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
if(buf == NULL) goto fin;
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
if(cio == NULL) goto fin;
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
// Ending program
free(img.comps);
/* if(cio->openmode == OPJ_STREAM_READ) */ free(buf);
opj_cio_close(cio);
failed = 0; buf = NULL;
fin:
fclose(mj2file);
if(failed) remove(argv[2]);
if(buf) free(buf);
if(cinfo)
{
mj2_destroy_compress(movie);
free(cinfo);
}
free(j2kfilename);
return failed;
return 0;
}

View File

@@ -7,7 +7,7 @@
m4_define([OPJ_MAJOR], [1])
m4_define([OPJ_MINOR], [5])
m4_define([OPJ_MICRO], [2])
m4_define([OPJ_MICRO], [0])
m4_define([lt_cur], m4_eval(OPJ_MAJOR + OPJ_MINOR))
m4_define([lt_rev], OPJ_MICRO)
@@ -23,6 +23,7 @@ AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([opj_config.h])
AC_CANONICAL_SYSTEM
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([1.11 foreign dist-bzip2 dist-xz dist-zip])
@@ -465,14 +466,8 @@ AC_HEADER_DIRENT
### Checks for compiler characteristics
AM_PROG_CC_C_O
ac_cv_c_big_endian=0
AC_C_BIGENDIAN([ac_cv_c_big_endian=yes], [ac_cv_c_big_endian=no],[])
#
if test "x${ac_cv_c_big_endian}" = "xyes" ; then
AC_DEFINE(OPJ_BIG_ENDIAN, [1], [define to 1 if your machine has BE])
AC_DEFINE(WORDS_BIGENDIAN, [1], [define to 1 if your machine has BE])
fi
#
AC_C_BIGENDIAN
#OPJ_COMPILER_FLAG([-Wall])
#OPJ_COMPILER_FLAG([-Wextra])
#OPJ_COMPILER_FLAG([-Wshadow])

View File

@@ -10,11 +10,6 @@ IF(DOXYGEN_FOUND)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.dox.cmake.in
${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox @ONLY)
# Configure the html mainpage file of the doxygen documentation with variable
# from CMake and move it
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/mainpage.dox.cmake
${CMAKE_BINARY_DIR}/doc/mainpage.dox @ONLY)
# Generate new target to build the html documentation
ADD_CUSTOM_TARGET(doc ALL
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/doc/Doxyfile-html.dox)

View File

@@ -147,7 +147,7 @@ HTML_STYLESHEET =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_TIMESTAMP = YES
HTML_ALIGN_MEMBERS = YES
HTML_DYNAMIC_SECTIONS = NO
GENERATE_DOCSET = NO

View File

@@ -101,12 +101,11 @@ WARN_LOGFILE =
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = @OPENJPEG_SOURCE_DIR@/libopenjpeg \
@OPENJPEG_BINARY_DIR@/doc
@OPENJPEG_SOURCE_DIR@/libopenjpeg/jpwl
INPUT_ENCODING = UTF-8
FILE_PATTERNS = *.h \
*.c \
*.dox
RECURSIVE = YES
*.c
RECURSIVE = NO
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
@@ -148,7 +147,7 @@ HTML_STYLESHEET =
HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = NO
HTML_TIMESTAMP = YES
HTML_ALIGN_MEMBERS = YES
HTML_DYNAMIC_SECTIONS = NO
GENERATE_DOCSET = NO

View File

@@ -34,7 +34,7 @@ doc:
endif
docsdir = $(docdir)-$(MAJOR_NR).$(MINOR_NR)
docs_DATA = $(top_builddir)/LICENSE
docs_DATA = $(top_builddir)/LICENSE $(top_builddir)/CHANGES
dist_man1_MANS = \
man/man1/image_to_j2k.1 \
@@ -45,11 +45,6 @@ dist_man3_MANS = \
man/man3/libopenjpeg.3
install-data-hook:
@echo -e " (MAN)\t$(man1dir)/image_to_j2k.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man1dir)/j2k_dump.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man1dir)/j2k_to_image.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man3dir)/libopenjpeg.3" >> $(top_builddir)/report.txt
if WANT_JPWL
cd $(DESTDIR)$(man1dir) && \
rm -f jpwl_image_to_j2k.1 && \
$(LN_S) image_to_j2k.1 jpwl_image_to_j2k.1
@@ -59,17 +54,18 @@ if WANT_JPWL
cd $(DESTDIR)$(man3dir) && \
rm -f jpwl_libopenjpeg.3 && \
$(LN_S) libopenjpeg.3 jpwl_libopenjpeg.3
@echo -e " (MAN)\t$(man1dir)/image_to_j2k.1" >> $(top_builddir)/report.txt
@echo -e " (LN)\t$(man1dir)/jpwl_image_to_j2k.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man1dir)/j2k_dump.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man1dir)/j2k_to_image.1" >> $(top_builddir)/report.txt
@echo -e " (LN)\t$(man1dir)//jpwl_j2k_to_image.1" >> $(top_builddir)/report.txt
@echo -e " (MAN)\t$(man3dir)/libopenjpeg.3" >> $(top_builddir)/report.txt
@echo -e " (LN)\t$(man3dir)/jpwl_libopenjpeg.3" >> $(top_builddir)/report.txt
endif
uninstall-hook:
if WANT_JPWL
rm -f $(DESTDIR)$(man1dir)/jpwl_image_to_j2k.1
rm -f $(DESTDIR)$(man1dir)/jpwl_j2k_to_image.1
rm -f $(DESTDIR)$(man3dir)/jpwl_libopenjpeg.3
endif
EXTRA_DIST = \
CMakeLists.txt \

View File

@@ -1,62 +0,0 @@
/*
* $Id: mainpage.dox.cmake 2011-09-21 Mickael Savinaud $
*
* Copyright (c) 2002-2011, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
* 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.
*/
/*! \mainpage OpenJPEG v@OPENJPEG_VERSION@ Documentation
*
* \section intro Introduction
* This manual documents the low-level OpenJPEG C API.\n
* The OpenJPEG library is an open-source JPEG 2000 library developed in order to promote the use of JPEG 2000.\n
* This documents is focused on the main part of the library which try to implement Part 1 and Part 2 of the JPEG2000 norm.\n
*
* \section home Home page
*
* The Home Page of the OpenJPEG library can be found at:
*
* http://code.google.com/p/openjpeg/
*
* More information about the OpenJPEG library is available here:
*
* http://www.openjpeg.org/
*
* The OpenJPEG mailing list is located here:
*
* http://groups.google.com/group/openjpeg
*
* All the source code is online and can be retrieved using svn from here:
*
* http://openjpeg.googlecode.com/svn/
*
* \section license License
* This software is released under the BSD license, anybody can use or modify the library, even for commercial applications.\n
* The only restriction is to retain the copyright in the sources or the binaries documentation.\n
* Neither the author, nor the university accept any responsibility for any kind of error or data loss which may occur during usage.
*
* \author OpenJPEG Team
*
*/

View File

@@ -49,7 +49,7 @@ Valid output image extensions are
.P
.B image_to_j2k -h \fRPrint a help message and exit.
.P
See JPWL OPTIONS for special options
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^b " n,n"

View File

@@ -49,7 +49,7 @@ Valid output image extensions are
.P
.B j2k_to_image -h \fRPrint help message and exit
.P
See JPWL OPTIONS for special options
.R See JPWL OPTIONS for special options
.SH OPTIONS
.TP
.B \-\^i "name"

View File

@@ -124,7 +124,7 @@ a library for reading and writing JPEG2000 image files.
.B CLRSPC_UNKNOWN\fR or \fBCLRSPC_UNSPECIFIED\fR or \fBCLRSPC_SRGB\fR or \fBCLRSPC_GRAY\fR or \fBCLRSPC_SYCC
.P
.SH DECOMPRESSION PARAMETERS
.P
.p
typedef struct opj_dparameters
.br
{

View File

@@ -1,7 +1,7 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@/openjpeg-@MAJOR_NR@.@MINOR_NR@
includedir=@includedir@
Name: openjpeg
Description: JPEG2000 Wireless (Part 11 - JPWL) library

View File

@@ -55,17 +55,10 @@ INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}
# Install includes files
INSTALL(FILES openjpeg.h
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers
DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers
)
# install man page of the library
INSTALL(
FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjpeg.3
DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
# internal utilities to generate t1_luts.h
# no need to install:
ADD_EXECUTABLE(t1_generate_luts t1_generate_luts.c)
IF(UNIX)
TARGET_LINK_LIBRARIES(t1_generate_luts m)
ENDIF()

View File

@@ -35,6 +35,7 @@ openjpeg.c \
pi.c \
raw.c \
t1.c \
t1_generate_luts.c \
t2.c \
tcd.c \
tgt.c \
@@ -72,7 +73,10 @@ EXTRA_DIST = \
CMakeLists.txt
install-data-hook:
cd $(DESTDIR)$(includedir) && rm -f openjpeg.h
cd $(DESTDIR)$(includedir) && \
rm -f openjpeg.h && \
$(LN_S) openjpeg-$(MAJOR_NR).$(MINOR_NR)/openjpeg.h \
openjpeg.h
@rm -rf $(top_builddir)/report.txt
@echo -e " (LA)\t$(libdir)/libopenjpeg.la" >> $(top_builddir)/report.txt
if BUILD_SHARED
@@ -82,6 +86,7 @@ if BUILD_STATIC
@echo -e " (A)\t$(base)/$(a)" >> $(top_builddir)/report.txt
endif
@echo -e " (H)\t$(includedir)/openjpeg-$(MAJOR_NR).$(MINOR_NR)/openjpeg.h" >> $(top_builddir)/report.txt
@echo -e " (LN)\t$(includedir)/openjpeg.h" >> $(top_builddir)/report.txt
uninstall-hook:
rm -f $(DESTDIR)$(includedir)/openjpeg.h

View File

@@ -42,7 +42,7 @@ Write a bit
@param bio BIO handle
@param b Bit to write (0 or 1)
*/
static void bio_putbit(opj_bio_t *bio, unsigned int b);
static void bio_putbit(opj_bio_t *bio, int b);
/**
Read a bit
@param bio BIO handle
@@ -78,7 +78,7 @@ static int bio_byteout(opj_bio_t *bio) {
if (bio->bp >= bio->end) {
return 1;
}
*bio->bp++ = (unsigned char)(bio->buf >> 8);
*bio->bp++ = bio->buf >> 8;
return 0;
}
@@ -92,7 +92,7 @@ static int bio_bytein(opj_bio_t *bio) {
return 0;
}
static void bio_putbit(opj_bio_t *bio, unsigned int b) {
static void bio_putbit(opj_bio_t *bio, int b) {
if (bio->ct == 0) {
bio_byteout(bio);
}
@@ -126,7 +126,7 @@ void bio_destroy(opj_bio_t *bio) {
}
int bio_numbytes(opj_bio_t *bio) {
return (int)(bio->bp - bio->start);
return (bio->bp - bio->start);
}
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {

View File

@@ -29,6 +29,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include "opj_includes.h"

View File

@@ -30,7 +30,6 @@
*/
#include "opj_includes.h"
#include <assert.h>
/* ----------------------------------------------------------------------- */
@@ -107,7 +106,6 @@ int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
* pos : position, in number of bytes, from the beginning of the stream
*/
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
assert((cio->start + pos) <= cio->end);
cio->bp = cio->start + pos;
}
@@ -115,7 +113,6 @@ void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) {
* Number of bytes left before the end of the stream.
*/
int cio_numbytesleft(opj_cio_t *cio) {
assert((cio->end - cio->bp) >= 0);
return cio->end - cio->bp;
}
@@ -142,7 +139,6 @@ opj_bool cio_byteout(opj_cio_t *cio, unsigned char v) {
* Read a byte.
*/
unsigned char cio_bytein(opj_cio_t *cio) {
assert(cio->bp >= cio->start);
if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error: passed the end of the codestream (start = %d, current = %d, end = %d\n", cio->start, cio->bp, cio->end);
return 0;
@@ -156,7 +152,7 @@ unsigned char cio_bytein(opj_cio_t *cio) {
* v : value to write
* n : number of bytes to write
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n) {
unsigned int cio_write(opj_cio_t *cio, unsigned long long int v, int n) {
int i;
for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
@@ -177,7 +173,7 @@ unsigned int cio_read(opj_cio_t *cio, int n) {
unsigned int v;
v = 0;
for (i = n - 1; i >= 0; i--) {
v += (unsigned int)cio_bytein(cio) << (i << 3);
v += cio_bytein(cio) << (i << 3);
}
return v;
}
@@ -188,10 +184,6 @@ unsigned int cio_read(opj_cio_t *cio, int n) {
* n : number of bytes to skip
*/
void cio_skip(opj_cio_t *cio, int n) {
assert((cio->bp + n) >= cio->bp);
if (((cio->bp + n) < cio->start) || ((cio->bp + n) > cio->end)) {
assert(0);
}
cio->bp += n;
}

View File

@@ -31,13 +31,6 @@
#ifndef __CIO_H
#define __CIO_H
#if defined(_MSC_VER) || defined(__BORLANDC__)
#define int64 __int64
#else
#define int64 long long
#endif
/**
@file cio.h
@brief Implementation of a byte input-output process (CIO)
@@ -70,7 +63,7 @@ Write some bytes
@param n Number of bytes to write
@return Returns the number of bytes written or 0 if an error occured
*/
unsigned int cio_write(opj_cio_t *cio, unsigned int64 v, int n);
unsigned int cio_write(opj_cio_t *cio, unsigned long long int v, int n);
/**
Read some bytes
@param cio CIO handle

View File

@@ -103,17 +103,18 @@ opj_bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ..
va_list arg;
int str_length/*, i, j*/; /* UniPG */
char message[MSG_SIZE];
memset(message, 0, MSG_SIZE);
/* initialize the optional parameter list */
va_start(arg, fmt);
/* check the length of the format string */
str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt);
/* parse the format string and put the result in 'message' */
str_length = vsnprintf(message, MSG_SIZE, fmt, arg); /* UniPG */
vsprintf(message, fmt, arg); /* UniPG */
/* deinitialize the optional parameter list */
va_end(arg);
/* output the message to the user program */
if( str_length > -1 && str_length < MSG_SIZE )
msg_handler(message, cinfo->client_data);
else return OPJ_FALSE;
}
return OPJ_TRUE;

View File

@@ -40,7 +40,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *c
image->color_space = clrspc;
image->numcomps = numcmpts;
/* allocate memory for the per-component information */
image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t));
image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
if(!image->comps) {
fprintf(stderr,"Unable to allocate memory for image.\n");
opj_image_destroy(image);

View File

@@ -32,7 +32,6 @@
*/
#include "opj_includes.h"
#include <assert.h>
/** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
/*@{*/
@@ -405,7 +404,6 @@ static void j2k_write_siz(opj_j2k_t *j2k) {
static void j2k_read_siz(opj_j2k_t *j2k) {
int len, i;
int n_comps;
opj_cio_t *cio = j2k->cio;
opj_image_t *image = j2k->image;
@@ -424,32 +422,12 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
if ((image->x0<0)||(image->x1<0)||(image->y0<0)||(image->y1<0)) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
"%s: invalid image size (x0:%d, x1:%d, y0:%d, y1:%d)\n",
image->x0,image->x1,image->y0,image->y1);
return;
}
n_comps = (len - 36 - 2 ) / 3;
assert( (len - 36 - 2 ) % 3 == 0 );
image->numcomps = cio_read(cio, 2); /* Csiz */
assert( n_comps == image->numcomps );
/* testcase 4035.pdf.SIGSEGV.d8b.3375 */
if (image->x0 > image->x1 || image->y0 > image->y1) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error with SIZ marker: negative image size (%d x %d)\n", image->x1 - image->x0, image->y1 - image->y0);
return;
}
/* testcase 2539.pdf.SIGFPE.706.1712 (also 3622.pdf.SIGFPE.706.2916 and 4008.pdf.SIGFPE.706.3345 and maybe more) */
if (!(cp->tdx * cp->tdy)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error with SIZ marker: invalid tile size (tdx: %d, tdy: %d)\n", cp->tdx, cp->tdy);
return;
}
/* testcase 1610.pdf.SIGSEGV.59c.681 */
if (((int64)image->x1) * ((int64)image->y1) != (image->x1 * image->y1)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Prevent buffer overflow (x1: %d, y1: %d)\n", image->x1, image->y1);
return;
}
#ifdef USE_JPWL
if (j2k->cp->correct) {
@@ -488,19 +466,11 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
/* update components number in the jpwl_exp_comps filed */
cp->exp_comps = image->numcomps;
}
#else
(void)len;
#endif /* USE_JPWL */
/* prevent division by zero */
if (!(cp->tdx * cp->tdy)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "invalid tile size (tdx: %d, tdy: %d)\n", cp->tdx, cp->tdy);
return;
}
image->comps = (opj_image_comp_t*) opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
for (i = 0; i < image->numcomps; i++) {
int tmp;
int tmp, w, h;
tmp = cio_read(cio, 1); /* Ssiz_i */
image->comps[i].prec = (tmp & 0x7f) + 1;
image->comps[i].sgnd = tmp >> 7;
@@ -536,11 +506,9 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
}
#endif /* USE_JPWL */
/* prevent division by zero */
if (!(image->comps[i].dx * image->comps[i].dy)) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "JPWL: invalid component size (dx: %d, dy: %d)\n", image->comps[i].dx, image->comps[i].dy);
return;
}
/* TODO: unused ? */
w = int_ceildiv(image->x1 - image->x0, image->comps[i].dx);
h = int_ceildiv(image->y1 - image->y0, image->comps[i].dy);
image->comps[i].resno_decoded = 0; /* number of resolution decoded */
image->comps[i].factor = cp->reduce; /* reducing factor per component */
@@ -549,15 +517,6 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
cp->tw = int_ceildiv(image->x1 - cp->tx0, cp->tdx);
cp->th = int_ceildiv(image->y1 - cp->ty0, cp->tdy);
/* gdal_fuzzer_check_number_of_tiles.jp2 */
if (cp->tw == 0 || cp->th == 0 || cp->tw > 65535 / cp->th) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"Invalid number of tiles : %u x %u (maximum fixed by jpeg2000 norm is 65535 tiles)\n",
cp->tw, cp->th);
return;
}
#ifdef USE_JPWL
if (j2k->cp->correct) {
/* if JPWL is on, we check whether TX errors have damaged
@@ -599,17 +558,7 @@ static void j2k_read_siz(opj_j2k_t *j2k) {
#endif /* USE_JPWL */
cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t));
if (cp->tcps == NULL)
{
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
return;
}
cp->tileno = (int*) opj_malloc(cp->tw * cp->th * sizeof(int));
if (cp->tileno == NULL)
{
opj_event_msg(j2k->cinfo, EVT_ERROR, "Out of memory\n");
return;
}
cp->tileno_size = 0;
#ifdef USE_JPWL
@@ -734,12 +683,6 @@ static void j2k_read_cox(opj_j2k_t *j2k, int compno) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions to remove is higher than the number "
"of resolutions of this component\nModify the cp_reduce parameter.\n\n", compno);
j2k->state |= J2K_STATE_ERR;
}
if( tccp->numresolutions > J2K_MAXRLVLS ) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Error decoding component %d.\nThe number of resolutions is too big: %d vs max= %d. Truncating.\n\n",
compno, tccp->numresolutions, J2K_MAXRLVLS);
j2k->state |= J2K_STATE_ERR;
tccp->numresolutions = J2K_MAXRLVLS;
}
tccp->cblkw = cio_read(cio, 1) + 2; /* SPcox (E) */
@@ -810,7 +753,6 @@ static void j2k_read_cod(opj_j2k_t *j2k) {
opj_image_t *image = j2k->image;
len = cio_read(cio, 2); /* Lcod */
(void)len;
tcp->csty = cio_read(cio, 1); /* Scod */
tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* SGcod (A) */
tcp->numlayers = cio_read(cio, 2); /* SGcod (B) */
@@ -864,14 +806,7 @@ static void j2k_read_coc(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2); /* Lcoc */
(void)len;
compno = cio_read(cio, image->numcomps <= 256 ? 1 : 2); /* Ccoc */
if (compno >= image->numcomps) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"bad component number in COC (%d out of a maximum of %d)\n",
compno, image->numcomps);
return;
}
tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */
j2k_read_cox(j2k, compno);
}
@@ -942,8 +877,6 @@ static void j2k_read_qcx(opj_j2k_t *j2k, int compno, int len) {
opj_event_msg(j2k->cinfo, EVT_WARNING ,
"bad number of subbands in Sqcx (%d) regarding to J2K_MAXBANDS (%d) \n"
"- limiting number of bands to J2K_MAXBANDS and try to move to the next markers\n", numbands, J2K_MAXBANDS);
/* edf_c2_1013627.jp2 */
numbands = 1;
}
#endif /* USE_JPWL */
@@ -1055,16 +988,9 @@ static void j2k_read_qcc(opj_j2k_t *j2k) {
/* keep your private count of tiles */
backup_compno++;
}
};
#endif /* USE_JPWL */
if ((compno < 0) || (compno >= numcomp)) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"bad component number in QCC (%d out of a maximum of %d)\n",
compno, j2k->image->numcomps);
return;
}
j2k_read_qcx(j2k, compno, len - 2 - (numcomp <= 256 ? 1 : 2));
}
@@ -1110,15 +1036,6 @@ static void j2k_read_poc(opj_j2k_t *j2k) {
len = cio_read(cio, 2); /* Lpoc */
numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2));
if( numpchgs >= 32 )
{
/* edf_c2_1103421.jp2 */
opj_event_msg(j2k->cinfo, EVT_ERROR,
"bad number of POCS (%d out of a maximum of %d)\n",
numpchgs, 32);
numpchgs = 0;
}
for (i = old_poc; i < numpchgs + old_poc; i++) {
opj_poc_t *poc;
poc = &tcp->pocs[i];
@@ -1141,12 +1058,9 @@ static void j2k_read_crg(opj_j2k_t *j2k) {
int numcomps = j2k->image->numcomps;
len = cio_read(cio, 2); /* Lcrg */
(void)len;
for (i = 0; i < numcomps; i++) {
Xcrg_i = cio_read(cio, 2); /* Xcrg_i */
(void)Xcrg_i;
Ycrg_i = cio_read(cio, 2); /* Ycrg_i */
(void)Ycrg_i;
}
}
@@ -1158,16 +1072,13 @@ static void j2k_read_tlm(opj_j2k_t *j2k) {
len = cio_read(cio, 2); /* Ltlm */
Ztlm = cio_read(cio, 1); /* Ztlm */
(void)Ztlm;
Stlm = cio_read(cio, 1); /* Stlm */
ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02);
SP = (Stlm >> 6) & 0x01;
tile_tlm = (len - 4) / ((SP + 1) * 2 + ST);
for (i = 0; i < tile_tlm; i++) {
Ttlm_i = cio_read(cio, ST); /* Ttlm_i */
(void)Ttlm_i;
Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */
(void)Ptlm_i;
}
}
@@ -1178,7 +1089,6 @@ static void j2k_read_plm(opj_j2k_t *j2k) {
len = cio_read(cio, 2); /* Lplm */
Zplm = cio_read(cio, 1); /* Zplm */
(void)Zplm;
len -= 3;
while (len > 0) {
Nplm = cio_read(cio, 4); /* Nplm */
@@ -1204,7 +1114,6 @@ static void j2k_read_plt(opj_j2k_t *j2k) {
len = cio_read(cio, 2); /* Lplt */
Zplt = cio_read(cio, 1); /* Zplt */
(void)Zplt;
for (i = len - 3; i > 0; i--) {
add = cio_read(cio, 1);
packet_len = (packet_len << 7) + add; /* Iplt_i */
@@ -1352,7 +1261,6 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
opj_cio_t *cio = j2k->cio;
len = cio_read(cio, 2);
(void)len;
tileno = cio_read(cio, 2);
#ifdef USE_JPWL
@@ -1361,7 +1269,7 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
static int backup_tileno = 0;
/* tileno is negative or larger than the number of tiles!!! */
if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) {
if ((tileno < 0) || (tileno > (cp->tw * cp->th))) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad tile number (%d out of a maximum of %d)\n",
tileno, (cp->tw * cp->th));
@@ -1378,18 +1286,8 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
/* keep your private count of tiles */
backup_tileno++;
}
else
};
#endif /* USE_JPWL */
{
/* tileno is negative or larger than the number of tiles!!! */
if ((tileno < 0) || (tileno >= (cp->tw * cp->th))) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad tile number (%d out of a maximum of %d)\n",
tileno, (cp->tw * cp->th));
return;
}
}
if (cp->tileno_size == 0) {
cp->tileno[cp->tileno_size] = tileno;
@@ -1427,18 +1325,8 @@ static void j2k_read_sot(opj_j2k_t *j2k) {
totlen);
}
}
else
};
#endif /* USE_JPWL */
{
/* totlen is negative or larger than the bytes left!!! */
if ((totlen < 0) || (totlen > (cio_numbytesleft(cio) + 8))) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"JPWL: bad tile byte size (%d bytes against %d bytes left)\n",
totlen, cio_numbytesleft(cio) + 8);
return;
}
}
if (!totlen)
totlen = cio_numbytesleft(cio) + 8;
@@ -1590,13 +1478,7 @@ static void j2k_read_sod(opj_j2k_t *j2k) {
}
data = j2k->tile_data[curtileno];
data_ptr = data; /* store in case of failure */
data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char));
if( data == NULL ) {
opj_event_msg(j2k->cinfo, EVT_ERROR, "Could not reallocated\n" );
opj_free( data_ptr );
return;
}
data_ptr = data + j2k->tile_len[curtileno];
for (i = 0; i < len; i++) {
@@ -1636,10 +1518,8 @@ static void j2k_read_rgn(opj_j2k_t *j2k) {
int numcomps = j2k->image->numcomps;
len = cio_read(cio, 2); /* Lrgn */
(void)len;
compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */
roisty = cio_read(cio, 1); /* Srgn */
(void)roisty;
#ifdef USE_JPWL
if (j2k->cp->correct) {
@@ -1656,13 +1536,6 @@ static void j2k_read_rgn(opj_j2k_t *j2k) {
};
#endif /* USE_JPWL */
if (compno >= numcomps) {
opj_event_msg(j2k->cinfo, EVT_ERROR,
"bad component number in RGN (%d out of a maximum of %d)\n",
compno, j2k->image->numcomps);
return;
}
tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */
}
@@ -1681,7 +1554,7 @@ static void j2k_write_eoc(opj_j2k_t *j2k) {
static void j2k_read_eoc(opj_j2k_t *j2k) {
int i, tileno;
opj_bool success = OPJ_FALSE;
opj_bool success;
/* if packets should be decoded */
if (j2k->cp->limit_decoding != DECODE_ALL_BUT_PACKETS) {
@@ -1689,17 +1562,11 @@ static void j2k_read_eoc(opj_j2k_t *j2k) {
tcd_malloc_decode(tcd, j2k->image, j2k->cp);
for (i = 0; i < j2k->cp->tileno_size; i++) {
tcd_malloc_decode_tile(tcd, j2k->image, j2k->cp, i, j2k->cstr_info);
if (j2k->cp->tileno[i] != -1)
{
tileno = j2k->cp->tileno[i];
success = tcd_decode_tile(tcd, j2k->tile_data[tileno], j2k->tile_len[tileno], tileno, j2k->cstr_info);
assert( tileno != -1 );
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
tcd_free_decode_tile(tcd, i);
}
else
success = OPJ_FALSE;
if (success == OPJ_FALSE) {
j2k->state |= J2K_STATE_ERR;
break;
@@ -1870,17 +1737,6 @@ void j2k_destroy_decompress(opj_j2k_t *j2k) {
opj_free(j2k->tile_len);
}
if(j2k->tile_data != NULL) {
if(j2k->cp != NULL) {
for (i = 0; i < j2k->cp->tileno_size; i++) {
int tileno = j2k->cp->tileno[i];
if( tileno != -1 )
{
opj_free(j2k->tile_data[tileno]);
j2k->tile_data[tileno] = NULL;
}
}
}
opj_free(j2k->tile_data);
}
if(j2k->default_tcp != NULL) {
@@ -2000,15 +1856,9 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
#endif /* USE_JPWL */
if (id >> 8 != 0xff) {
if(cio_numbytesleft(cio) != 0) /* not end of file reached and no EOC */
{
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
return 0;
}
opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
j2k->state = J2K_STATE_NEOC;
break;
}
e = j2k_dec_mstab_lookup(id);
/* Check if the marker is known*/
@@ -2027,10 +1877,7 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
(*e->handler)(j2k);
}
if (j2k->state & J2K_STATE_ERR)
{
opj_image_destroy(image);
return NULL;
}
if (j2k->state == J2K_STATE_MT) {
break;
@@ -2041,11 +1888,6 @@ opj_image_t* j2k_decode(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestream_info_t *c
}
if (j2k->state == J2K_STATE_NEOC) {
j2k_read_eoc(j2k);
/* Check one last time for errors during decoding before returning */
if (j2k->state & J2K_STATE_ERR) {
opj_image_destroy(image);
return NULL;
}
}
if (j2k->state != J2K_STATE_MT) {
@@ -2107,15 +1949,9 @@ opj_image_t* j2k_decode_jpt_stream(opj_j2k_t *j2k, opj_cio_t *cio, opj_codestre
id = cio_read(cio, 2);
if (id >> 8 != 0xff) {
if(cio_numbytesleft(cio) != 0) /* no end of file reached and no EOC */
{
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
opj_image_destroy(image);
opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
return 0;
}
opj_event_msg(cinfo, EVT_WARNING, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id);
j2k->state = J2K_STATE_NEOC;
break;
}
e = j2k_dec_mstab_lookup(id);
if (!(j2k->state & e->states)) {

View File

@@ -30,7 +30,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "opj_includes.h"
#include <assert.h>
/** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
/*@{*/
@@ -173,9 +172,6 @@ static opj_bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_bo
}
else if (box->length == 0) {
box->length = cio_numbytesleft(cio) + 8;
} else if (box->length < 0) {
opj_event_msg(cinfo, EVT_ERROR, "Integer overflow in box->length\n");
return OPJ_FALSE; /* TODO: actually check jp2_read_boxhdr's return value */
}
return OPJ_TRUE;
@@ -210,10 +206,7 @@ static opj_bool jp2_read_ihdr(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_common_ptr cinfo = jp2->cinfo;
if(jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
return OPJ_FALSE;
}
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_IHDR != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected IHDR Marker\n");
return OPJ_FALSE;
@@ -286,10 +279,7 @@ static opj_bool jp2_read_bpcc(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_common_ptr cinfo = jp2->cinfo;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
return OPJ_FALSE;
}
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_BPCC != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected BPCC Marker\n");
return OPJ_FALSE;
@@ -479,7 +469,7 @@ static opj_bool jp2_read_pclr(opj_jp2_t *jp2, opj_cio_t *cio,
for(i = 0; i < nr_channels; ++i)
{
/* Cji */
*entries++ = cio_read(cio, (channel_size[i]+7)>>3);
*entries++ = cio_read(cio, channel_size[i]>>3);
}
}
@@ -522,8 +512,10 @@ static opj_bool jp2_read_cmap(opj_jp2_t *jp2, opj_cio_t *cio,
static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
{
opj_jp2_cdef_info_t *info;
int color_space;
unsigned short i, n, cn, typ, asoc, acn;
color_space = image->color_space;
info = color->jp2_cdef->info;
n = color->jp2_cdef->n;
@@ -533,7 +525,6 @@ static void jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color)
if((asoc = info[i].asoc) == 0) continue;
cn = info[i].cn; typ = info[i].typ; acn = asoc - 1;
(void)typ;
if(cn != acn)
{
@@ -648,8 +639,9 @@ opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
opj_common_ptr cinfo = jp2->cinfo;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
do {
jp2_read_boxhdr(cinfo, cio, &box);
do
{
if (JP2_JP2H != box.type)
{
if (box.type == JP2_JP2C)
@@ -657,12 +649,11 @@ opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
opj_event_msg(cinfo, EVT_ERROR, "Expected JP2H Marker\n");
return OPJ_FALSE;
}
if (box.length <= 8) return OPJ_FALSE;
cio_skip(cio, box.length - 8);
if(cio->bp >= cio->end) return OPJ_FALSE;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2H != box.type);
@@ -675,7 +666,7 @@ opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
if (!jp2_read_bpcc(jp2, cio))
return OPJ_FALSE;
}
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
while(cio_tell(cio) < jp2h_end)
{
@@ -683,50 +674,45 @@ opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
{
if( !jp2_read_colr(jp2, cio, &box, color))
{
if (box.length <= 8) return OPJ_FALSE;
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_CDEF && !jp2->ignore_pclr_cmap_cdef)
{
if( !jp2_read_cdef(jp2, cio, &box, color))
{
if (box.length <= 8) return OPJ_FALSE;
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_PCLR && !jp2->ignore_pclr_cmap_cdef)
{
if( !jp2_read_pclr(jp2, cio, &box, color))
{
if (box.length <= 8) return OPJ_FALSE;
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if(box.type == JP2_CMAP && !jp2->ignore_pclr_cmap_cdef)
{
if( !jp2_read_cmap(jp2, cio, &box, color))
{
if (box.length <= 8) return OPJ_FALSE;
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
}
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
continue;
}
if (box.length <= 8) return OPJ_FALSE;
cio_seek(cio, box.init_pos + 8);
cio_skip(cio, box.length - 8);
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
}/* while(cio_tell(cio) < box_end) */
@@ -737,84 +723,6 @@ opj_bool jp2_read_jp2h(opj_jp2_t *jp2, opj_cio_t *cio, opj_jp2_color_t *color)
}/* jp2_read_jp2h() */
static opj_bool opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_common_ptr cinfo)
{
int i;
/* testcase 4149.pdf.SIGSEGV.cf7.3501 */
if (color->jp2_cdef) {
opj_jp2_cdef_info_t *info = color->jp2_cdef->info;
int n = color->jp2_cdef->n;
for (i = 0; i < n; i++) {
if (info[i].cn >= image->numcomps) {
opj_event_msg(cinfo, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, image->numcomps);
return OPJ_FALSE;
}
if (info[i].asoc > 0 && (info[i].asoc - 1) >= image->numcomps) {
opj_event_msg(cinfo, 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) {
int 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(cinfo, 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(cinfo, EVT_ERROR, "Unexpected OOM.\n");
return OPJ_FALSE;
}
/* verify that no component is targeted more than once */
for (i = 0; i < nr_channels; i++) {
int pcol = cmap[i].pcol;
assert(cmap[i].mtyp == 0 || cmap[i].mtyp == 1);
if (pcol >= nr_channels) {
opj_event_msg(cinfo, 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(cinfo, 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(cinfo, 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(cinfo, 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;
}
opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
opj_codestream_info_t *cstr_info)
{
@@ -848,10 +756,6 @@ opj_image_t* opj_jp2_decode(opj_jp2_t *jp2, opj_cio_t *cio,
}
if (!jp2->ignore_pclr_cmap_cdef){
if (!opj_jp2_check_color(image, &color, cinfo)) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to decode PCRL box\n");
return NULL;
}
/* Set Image Color Space */
if (jp2->enumcs == 16)
@@ -935,10 +839,8 @@ static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_common_ptr cinfo = jp2->cinfo;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
return OPJ_FALSE;
}
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_FTYP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected FTYP Marker\n");
return OPJ_FALSE;
@@ -947,14 +849,6 @@ static opj_bool jp2_read_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
jp2->brand = cio_read(cio, 4); /* BR */
jp2->minversion = cio_read(cio, 4); /* MinV */
jp2->numcl = (box.length - 16) / 4;
/* edf_c2_1673169.jp2 */
if (cio_numbytesleft(cio) < ((int)jp2->numcl * 4)) {
opj_event_msg(cinfo, EVT_ERROR, "Not enough bytes in FTYP Box "
"(expected %d, but only %d left)\n",
((int)jp2->numcl * 4), cio_numbytesleft(cio));
return OPJ_FALSE;
}
jp2->cl = (unsigned int *) opj_malloc(jp2->numcl * sizeof(unsigned int));
for (i = 0; i < (int)jp2->numcl; i++) {
@@ -1003,20 +897,15 @@ static opj_bool jp2_read_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, unsigned int *j2k_
opj_common_ptr cinfo = jp2->cinfo;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
return OPJ_FALSE;
}
jp2_read_boxhdr(cinfo, cio, &box);
do {
if(JP2_JP2C != box.type) {
if (box.length <= 8) return OPJ_FALSE;
cio_skip(cio, box.length - 8);
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) return OPJ_FALSE;
jp2_read_boxhdr(cinfo, cio, &box);
}
} while(JP2_JP2C != box.type);
*j2k_codestream_offset = cio_tell(cio);
if (box.length <= 8) return OPJ_FALSE;
*j2k_codestream_length = box.length - 8;
return OPJ_TRUE;
@@ -1041,10 +930,7 @@ static opj_bool jp2_read_jp(opj_jp2_t *jp2, opj_cio_t *cio) {
opj_common_ptr cinfo = jp2->cinfo;
if( jp2_read_boxhdr(cinfo, cio, &box) == OPJ_FALSE ) {
opj_event_msg(cinfo, EVT_ERROR, "Failed to read boxhdr\n");
return OPJ_FALSE;
}
jp2_read_boxhdr(cinfo, cio, &box);
if (JP2_JP != box.type) {
opj_event_msg(cinfo, EVT_ERROR, "Expected JP Marker\n");
return OPJ_FALSE;
@@ -1184,7 +1070,6 @@ void jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) {
opj_jp2_t* jp2_create_compress(opj_common_ptr cinfo) {
opj_jp2_t *jp2 = (opj_jp2_t*)opj_malloc(sizeof(opj_jp2_t));
if(jp2) {
memset(jp2, 0, sizeof(opj_jp2_t));
jp2->cinfo = cinfo;
/* create the J2K codec */
jp2->j2k = j2k_create_compress(cinfo);

View File

@@ -23,16 +23,10 @@ IF(WIN32)
ENDIF(BUILD_SHARED_LIBS)
ENDIF(WIN32)
ADD_LIBRARY(${OPENJPEG_LIBRARY_NAME}_JPWL ${JPWL_SRCS} ${OPENJPEG_SRCS})
IF(UNIX)
TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME}_JPWL m)
ENDIF(UNIX)
SET_TARGET_PROPERTIES(${OPENJPEG_LIBRARY_NAME}_JPWL
PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
# Install library
INSTALL(TARGETS ${OPENJPEG_LIBRARY_NAME}_JPWL
EXPORT OpenJPEGTargets
RUNTIME DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
LIBRARY DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
ARCHIVE DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
)

View File

@@ -18,6 +18,7 @@ OPJ_SRC = \
../pi.c \
../raw.c \
../t1.c \
../t1_generate_luts.c \
../t2.c \
../tcd.c \
../tgt.c \

View File

@@ -90,7 +90,7 @@ const unsigned short CRC16_table[256] = {
void updateCRC16(unsigned short *crc, unsigned char data) {
*crc = CRC16_table[(*crc >> 8) & 0xFF] ^ (*crc << 8) ^ data;
}
};
/** file: CRC32.CPP
@@ -155,6 +155,6 @@ const unsigned long CRC32_table[256] = {
void updateCRC32(unsigned long *crc, unsigned char data) {
*crc = CRC32_table[(unsigned char) *crc ^ data] ^ ((*crc >> 8) & 0x00FFFFFF);
}
};
#endif /* USE_JPWL */

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