Build conditionally the java binding

This commit is contained in:
Mathieu Malaterre 2012-01-20 14:08:59 +00:00
parent fc268dff90
commit 452403d393
5 changed files with 46 additions and 40 deletions

View File

@ -186,7 +186,9 @@ OPTION(BUILD_CODEC "Build the CODEC executables" ON)
OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF) OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF)
OPTION(BUILD_JPIP "Build the JPIP library and executables." OFF) OPTION(BUILD_JPIP "Build the JPIP library and executables." OFF)
OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF) OPTION(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
OPTION(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
MARK_AS_ADVANCED(BUILD_VIEWER) MARK_AS_ADVANCED(BUILD_VIEWER)
MARK_AS_ADVANCED(BUILD_JAVA)
IF(BUILD_JPIP) IF(BUILD_JPIP)
FIND_PACKAGE(CURL) FIND_PACKAGE(CURL)

View File

@ -15,3 +15,7 @@ ENDIF(BUILD_JPIP)
IF(BUILD_VIEWER) IF(BUILD_VIEWER)
ADD_SUBDIRECTORY(OPJViewer) ADD_SUBDIRECTORY(OPJViewer)
ENDIF(BUILD_VIEWER) ENDIF(BUILD_VIEWER)
IF(BUILD_JAVA)
ADD_SUBDIRECTORY(JavaOpenJPEG)
ENDIF(BUILD_JAVA)

View File

@ -1,33 +1,47 @@
#JavaOpenJPEG/CMakeLists.txt #JavaOpenJPEG/CMakeLists.txt
# First thing define the common source: # First thing define the common source:
SET(common_SRCS SET(openjpegjni_SRCS
../codec/convert.c JavaOpenJPEGDecoder.c
../codec/index.c JavaOpenJPEG.c
../common/opj_getopt.c
) )
# JNI binding:
find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
# Headers file are located here: # required header file:
INCLUDE_DIRECTORIES( include_directories(
${OPENJPEG_SOURCE_DIR}/libopenjpeg ${OPENJPEG_SOURCE_DIR}/libopenjpeg
${LCMS_INCLUDE_DIR} ${OPENJPEG_SOURCE_DIR}/applications/common
${PNG_INCLUDE_DIR} ${OPENJPEG_SOURCE_DIR}/applications/codec
${ZLIB_INCLUDE_DIR}
${TIFF_INCLUDE_DIR}
) )
# Loop over all executables: add_library(openjpegjni MODULE
FOREACH(exe j2k_to_image image_to_j2k) ${openjpegjni_SRCS}
ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS}) )
TARGET_LINK_LIBRARIES(${exe} ${OPJ_PREFIX}openjpeg ${TIFF_LIBRARIES}
${PNG_LIBRARIES} ${ZLIB_LIBRARY} ${LCMS_LIB})
# On unix you need to link to the math library:
IF(UNIX)
TARGET_LINK_LIBRARIES(${exe} -lm)
ENDIF(UNIX)
# Install exe
INSTALL_TARGETS(/bin/ ${exe})
ENDFOREACH(exe)
# build jar:
FIND_PACKAGE(Java 1.5 REQUIRED) # javac, jar
# build dep list:
file(GLOB java_srcs "java-sources/org/openJpeg/*.java")
# make sure target javac dir exists:
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/classes)
# Build java
ADD_CUSTOM_COMMAND(
OUTPUT ${LIBRARY_OUTPUT_PATH}/openjpeg.jar
COMMAND ${Java_JAVAC_EXECUTABLE} -sourcepath "${CMAKE_CURRENT_SOURCE_DIR}/java-sources"
${java_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes
COMMAND ${Java_JAR_EXECUTABLE} cvf ${LIBRARY_OUTPUT_PATH}/openjpeg.jar org
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/classes
DEPENDS ${java_srcs}
COMMENT "javac *.java; jar cvf -> openjpeg.jar"
)
# name the target
ADD_CUSTOM_TARGET(OpenJPEGJavaJar ALL
DEPENDS ${LIBRARY_OUTPUT_PATH}/openjpeg.jar
COMMENT "building openjpeg.jar"
)

View File

@ -380,7 +380,7 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){
} }
void cinema_parameters(opj_cparameters_t *parameters){ void cinema_parameters(opj_cparameters_t *parameters){
parameters->tile_size_on = false; parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1; parameters->cp_tdx=1;
parameters->cp_tdy=1; parameters->cp_tdy=1;
@ -663,7 +663,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
case 't': /* tiles */ case 't': /* tiles */
{ {
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy); sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = true; parameters->tile_size_on = OPJ_TRUE;
} }
break; break;
@ -1628,7 +1628,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
jbyte *jbBody; jbyte *jbBody;
jshort *jsBody; jshort *jsBody;
jint *jiBody; jint *jiBody;
boolean isCopy; jboolean isCopy;
// Image width, height and depth // Image width, height and depth
fid = (*env)->GetFieldID(env, cls,"width", "I"); fid = (*env)->GetFieldID(env, cls,"width", "I");
@ -1776,7 +1776,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImageToJ2K(JNIEnv *env, jobject obj, jobjectArray javaParameters) { 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 */ int argc; /* To simulate the command line parameters (taken from the javaParameters variable) and be able to re-use the */
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 */
bool bSuccess; opj_bool bSuccess;
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */
img_fol_t img_fol; img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */

View File

@ -1,14 +0,0 @@
# Makefile for the main OpenJPEG codecs: j2k_to_image and image_to_j2k
CFLAGS = -O3 -lstdc++ # -g -p -pg
all: j2k_to_image image_to_j2k
j2k_to_image: j2k_to_image.c ../libopenjpeg.a
gcc $(CFLAGS) ../common/opj_getopt.c convert.c j2k_to_image.c -o j2k_to_image -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
image_to_j2k: image_to_j2k.c ../libopenjpeg.a
gcc $(CFLAGS) ../common/opj_getopt.c convert.c image_to_j2k.c -o image_to_j2k -L.. -lopenjpeg -I ../libopenjpeg/ -lm -ltiff
clean:
rm -f j2k_to_image image_to_j2k