[trunk] Fix advanced (and experimental) Java binding. As reported on the mailing list.
This commit is contained in:
parent
2e30886a0d
commit
e30818ce39
|
@ -13,7 +13,8 @@ include_directories(${JNI_INCLUDE_DIRS})
|
||||||
# required header file:
|
# required header file:
|
||||||
include_directories(
|
include_directories(
|
||||||
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
|
${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
|
||||||
${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
|
#${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
|
||||||
|
${OPENJPEG_SOURCE_DIR}/src/lib/openmj2
|
||||||
${OPENJPEG_SOURCE_DIR}/src/bin/common
|
${OPENJPEG_SOURCE_DIR}/src/bin/common
|
||||||
${OPENJPEG_SOURCE_DIR}/src/bin/jp2
|
${OPENJPEG_SOURCE_DIR}/src/bin/jp2
|
||||||
)
|
)
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
|
|
||||||
extern int get_file_format(char *filename);
|
extern int get_file_format(char *filename);
|
||||||
extern void error_callback(const char *msg, void *client_data);
|
extern void error_callback(const char *msg, void *client_data);
|
||||||
extern warning_callback(const char *msg, void *client_data);
|
extern void warning_callback(const char *msg, void *client_data);
|
||||||
extern void info_callback(const char *msg, void *client_data);
|
extern void info_callback(const char *msg, void *client_data);
|
||||||
|
|
||||||
typedef struct callback_variables {
|
typedef struct callback_variables {
|
||||||
|
@ -350,9 +350,9 @@ OPJ_PROG_ORDER give_progression(char progression[4]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/** <summary>
|
||||||
/// Get logarithm of an integer and round downwards.
|
Get logarithm of an integer and round downwards.
|
||||||
/// </summary>
|
</summary> */
|
||||||
int int_floorlog2(int a) {
|
int int_floorlog2(int a) {
|
||||||
int l;
|
int l;
|
||||||
for (l=0; a>1; l++) {
|
for (l=0; a>1; l++) {
|
||||||
|
@ -1352,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 =
|
*buffer_size =
|
||||||
1 /* version */
|
1 /* version */
|
||||||
+ (10 /* image_w until decomposition */
|
+ (10 /* image_w until decomposition */
|
||||||
|
@ -1361,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 * 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
|
+ cstr_info->tw*cstr_info->th * cstr_info->numlayers * (cstr_info->numdecompos[0] + 1) * cstr_info->numcomps * prec_max *8
|
||||||
) * sizeof(int);
|
) * 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);
|
buffer = (char*) malloc(*buffer_size);
|
||||||
|
|
||||||
if (!buffer) {
|
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);
|
fprintf(stderr, "failed to allocate index buffer for writing %d int\n", *buffer_size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[0] = 1; // Version stored on a byte
|
buffer[0] = 1; /* Version stored on a byte*/
|
||||||
buffer++;
|
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_w;
|
||||||
((int*)buffer)[buffer_pos++] = cstr_info->image_h;
|
((int*)buffer)[buffer_pos++] = cstr_info->image_h;
|
||||||
((int*)buffer)[buffer_pos++] = cstr_info->prog;
|
((int*)buffer)[buffer_pos++] = cstr_info->prog;
|
||||||
|
@ -1597,7 +1597,7 @@ char* create_index_into_byte_array(opj_codestream_info_t *cstr_info, int* buffer
|
||||||
} /* tileno */
|
} /* tileno */
|
||||||
|
|
||||||
if (buffer_pos > *buffer_size) {
|
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);
|
fprintf(stderr, "index creation: buffer_pos (%d) > buffer_size (%d)!\n", buffer_pos, *buffer_size);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1630,7 +1630,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
jint *jiBody;
|
jint *jiBody;
|
||||||
jboolean 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");
|
||||||
ji = (*env)->GetIntField(env, obj, fid);
|
ji = (*env)->GetIntField(env, obj, fid);
|
||||||
w = ji;
|
w = ji;
|
||||||
|
@ -1643,7 +1643,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
ji = (*env)->GetIntField(env, obj, fid);
|
ji = (*env)->GetIntField(env, obj, fid);
|
||||||
depth = ji;
|
depth = ji;
|
||||||
|
|
||||||
// Read the image
|
/* Read the image*/
|
||||||
if (depth <=16) {
|
if (depth <=16) {
|
||||||
numcomps = 1;
|
numcomps = 1;
|
||||||
color_space = CLRSPC_GRAY;
|
color_space = CLRSPC_GRAY;
|
||||||
|
@ -1658,8 +1658,8 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
cmptparm[0].y0 = parameters->image_offset_y0;
|
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].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;
|
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
|
/* 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).
|
the pixels of the images in Telemis before entering the encoder).*/
|
||||||
cmptparm[0].sgnd = 0;
|
cmptparm[0].sgnd = 0;
|
||||||
if (depth<=16)
|
if (depth<=16)
|
||||||
cmptparm[0].prec=depth;
|
cmptparm[0].prec=depth;
|
||||||
|
@ -1705,12 +1705,12 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
comp = &image->comps[compno];
|
comp = &image->comps[compno];
|
||||||
max = -100000;
|
max = -100000;
|
||||||
if (depth == 8) {
|
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);
|
jba = (*env)->GetObjectField(env, obj, fid);
|
||||||
len = (*env)->GetArrayLength(env, jba);
|
len = (*env)->GetArrayLength(env, jba);
|
||||||
|
|
||||||
jbBody = (*env)->GetPrimitiveArrayCritical(env, jba, &isCopy);
|
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) {
|
if (comp->sgnd) {
|
||||||
for(i=0; i< len;i++) {
|
for(i=0; i< len;i++) {
|
||||||
comp->data[i] = (char) jbBody[i];
|
comp->data[i] = (char) jbBody[i];
|
||||||
|
@ -1724,13 +1724,13 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
}
|
}
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, jba, jbBody, 0);
|
(*env)->ReleasePrimitiveArrayCritical(env, jba, jbBody, 0);
|
||||||
} else if(depth == 16) {
|
} 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);
|
jsa = (*env)->GetObjectField(env, obj, fid);
|
||||||
len = (*env)->GetArrayLength(env, jsa);
|
len = (*env)->GetArrayLength(env, jsa);
|
||||||
|
|
||||||
jsBody = (*env)->GetPrimitiveArrayCritical(env, jsa, &isCopy);
|
jsBody = (*env)->GetPrimitiveArrayCritical(env, jsa, &isCopy);
|
||||||
//printf("C: before transfering 16 bpp image\n");
|
/*printf("C: before transfering 16 bpp image\n");*/
|
||||||
if (comp->sgnd) { // Special behaviour to deal with signed elements ??
|
if (comp->sgnd) { /* Special behaviour to deal with signed elements ??*/
|
||||||
comp->data[i] = (short) jsBody[i];
|
comp->data[i] = (short) jsBody[i];
|
||||||
for(i=0; i< len;i++) {
|
for(i=0; i< len;i++) {
|
||||||
if (comp->data[i] > max) max = comp->data[i];
|
if (comp->data[i] > max) max = comp->data[i];
|
||||||
|
@ -1743,14 +1743,14 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
}
|
}
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, jsa, jsBody, 0);
|
(*env)->ReleasePrimitiveArrayCritical(env, jsa, jsBody, 0);
|
||||||
} else if (depth == 24) {
|
} 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);
|
jia = (*env)->GetObjectField(env, obj, fid);
|
||||||
len = (*env)->GetArrayLength(env, jia);
|
len = (*env)->GetArrayLength(env, jia);
|
||||||
shift = compno*8;
|
shift = compno*8;
|
||||||
|
|
||||||
jiBody = (*env)->GetPrimitiveArrayCritical(env, jia, &isCopy);
|
jiBody = (*env)->GetPrimitiveArrayCritical(env, jia, &isCopy);
|
||||||
//printf("C: before transfering 24 bpp image (component %d, signed = %d)\n", compno, comp->sgnd);
|
/*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
|
if (comp->sgnd) { /* Special behaviour to deal with signed elements ?? XXXXX*/
|
||||||
for(i=0; i< len;i++) {
|
for(i=0; i< len;i++) {
|
||||||
comp->data[i] = ( ((int) jiBody[i]) & (0xFF << shift) ) >> shift;
|
comp->data[i] = ( ((int) jiBody[i]) & (0xFF << shift) ) >> shift;
|
||||||
if (comp->data[i] > max) max = comp->data[i];
|
if (comp->data[i] > max) max = comp->data[i];
|
||||||
|
@ -1765,7 +1765,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
}
|
}
|
||||||
comp->bpp = int_floorlog2(max)+1;
|
comp->bpp = int_floorlog2(max)+1;
|
||||||
comp->prec = comp->bpp;
|
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;
|
return image;
|
||||||
}
|
}
|
||||||
|
@ -1786,9 +1786,9 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
opj_codestream_info_t cstr_info; /* Codestream information structure */
|
||||||
char indexfilename[OPJ_PATH_LEN]; /* index file name */
|
char indexfilename[OPJ_PATH_LEN]; /* index file name */
|
||||||
|
|
||||||
int* compressed_index = NULL;
|
char* compressed_index = NULL;
|
||||||
int compressed_index_size=-1;
|
int compressed_index_size=-1;
|
||||||
// ==> Access variables to the Java member variables
|
/* ==> Access variables to the Java member variables*/
|
||||||
jsize arraySize;
|
jsize arraySize;
|
||||||
jclass cls;
|
jclass cls;
|
||||||
jobject object;
|
jobject object;
|
||||||
|
@ -1797,18 +1797,18 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
jbyteArray jba;
|
jbyteArray jba;
|
||||||
jbyte *jbBody;
|
jbyte *jbBody;
|
||||||
callback_variables_t msgErrorCallback_vars;
|
callback_variables_t msgErrorCallback_vars;
|
||||||
// <== access variable to the Java member variables.
|
/* <== access variable to the Java member variables.*/
|
||||||
|
|
||||||
// For the encoding and storage into the file
|
/* For the encoding and storage into the file*/
|
||||||
opj_cinfo_t* cinfo;
|
opj_cinfo_t* cinfo;
|
||||||
int codestream_length;
|
int codestream_length;
|
||||||
opj_cio_t *cio = NULL;
|
opj_cio_t *cio = NULL;
|
||||||
FILE *f = NULL;
|
FILE *f = NULL;
|
||||||
|
|
||||||
// JNI reference to the calling class
|
/* JNI reference to the calling class*/
|
||||||
cls = (*env)->GetObjectClass(env, obj);
|
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.env = env;
|
||||||
msgErrorCallback_vars.jobj = &obj;
|
msgErrorCallback_vars.jobj = &obj;
|
||||||
msgErrorCallback_vars.message_mid = (*env)->GetMethodID(env, cls, "logMessage", "(Ljava/lang/String;)V");
|
msgErrorCallback_vars.message_mid = (*env)->GetMethodID(env, cls, "logMessage", "(Ljava/lang/String;)V");
|
||||||
|
@ -1817,11 +1817,11 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
||||||
argc = (int) arraySize +1;
|
argc = (int) arraySize +1;
|
||||||
argv = malloc(argc*sizeof(char*));
|
argv = malloc(argc*sizeof(char*));
|
||||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
argv[0] = "ProgramName.exe"; /* The program name: useless*/
|
||||||
j=0;
|
j=0;
|
||||||
for (i=1; i<argc; i++) {
|
for (i=1; i<argc; i++) {
|
||||||
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
||||||
argv[i] = (*env)->GetStringUTFChars(env, object, &isCopy);
|
argv[i] = (char*)(*env)->GetStringUTFChars(env, object, &isCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*printf("C: ");
|
/*printf("C: ");
|
||||||
|
@ -1841,7 +1841,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
/* set encoding parameters to default values */
|
/* set encoding parameters to default values */
|
||||||
opj_set_default_encoder_parameters(¶meters);
|
opj_set_default_encoder_parameters(¶meters);
|
||||||
parameters.cod_format = J2K_CFMT;
|
parameters.cod_format = J2K_CFMT;
|
||||||
//parameters.index_on = 1;
|
/*parameters.index_on = 1;*/
|
||||||
|
|
||||||
/* Initialize indexfilename and img_fol */
|
/* Initialize indexfilename and img_fol */
|
||||||
*indexfilename = 0;
|
*indexfilename = 0;
|
||||||
|
@ -1849,13 +1849,13 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
|
|
||||||
/* parse input and get user encoding parameters */
|
/* parse input and get user encoding parameters */
|
||||||
if (parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) {
|
if (parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, indexfilename) == 1) {
|
||||||
// Release the Java arguments array
|
/* Release the Java arguments array*/
|
||||||
for (i=1; i<argc; i++)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release the Java arguments array
|
/* Release the Java arguments array*/
|
||||||
for (i=1; i<argc; i++)
|
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]);
|
||||||
|
|
||||||
|
@ -1891,7 +1891,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
fprintf(stderr,"\n");
|
fprintf(stderr,"\n");
|
||||||
|
|
||||||
image = loadImage(¶meters, env, obj, cls);
|
image = loadImage(¶meters, env, obj, cls);
|
||||||
//printf("C: after load image: image = %d\n", image);
|
/*printf("C: after load image: image = %d\n", image);*/
|
||||||
if (!image) {
|
if (!image) {
|
||||||
fprintf(stderr, "Unable to load image\n");
|
fprintf(stderr, "Unable to load image\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -508,7 +508,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
int w,h;
|
int w,h;
|
||||||
long min_value, max_value;
|
long min_value, max_value;
|
||||||
short tempS; unsigned char tempUC, tempUC1, tempUC2;
|
short tempS; unsigned char tempUC, tempUC1, tempUC2;
|
||||||
// ==> Access variables to the Java member variables
|
/* ==> Access variables to the Java member variables*/
|
||||||
jsize arraySize;
|
jsize arraySize;
|
||||||
jclass cls;
|
jclass cls;
|
||||||
jobject object;
|
jobject object;
|
||||||
|
@ -521,8 +521,8 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
jshort *jsBody, *ptrSBody;
|
jshort *jsBody, *ptrSBody;
|
||||||
jint *jiBody, *ptrIBody;
|
jint *jiBody, *ptrIBody;
|
||||||
callback_variables_t msgErrorCallback_vars;
|
callback_variables_t msgErrorCallback_vars;
|
||||||
// <=== access variable to Java member variables */
|
/* <=== access variable to Java member variables */
|
||||||
int *ptr, *ptr1, *ptr2; // <== To transfer the decoded image to Java
|
int *ptr, *ptr1, *ptr2; /* <== To transfer the decoded image to Java*/
|
||||||
|
|
||||||
/* configure the event callbacks */
|
/* configure the event callbacks */
|
||||||
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
||||||
|
@ -530,24 +530,24 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
event_mgr.warning_handler = warning_callback;
|
event_mgr.warning_handler = warning_callback;
|
||||||
event_mgr.info_handler = info_callback;
|
event_mgr.info_handler = info_callback;
|
||||||
|
|
||||||
// JNI reference to the calling class
|
/* JNI reference to the calling class*/
|
||||||
cls = (*env)->GetObjectClass(env, obj);
|
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.env = env;
|
||||||
msgErrorCallback_vars.jobj = &obj;
|
msgErrorCallback_vars.jobj = &obj;
|
||||||
msgErrorCallback_vars.message_mid = (*env)->GetMethodID(env, cls, "logMessage", "(Ljava/lang/String;)V");
|
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");
|
msgErrorCallback_vars.error_mid = (*env)->GetMethodID(env, cls, "logError", "(Ljava/lang/String;)V");
|
||||||
|
|
||||||
// Get the String[] containing the parameters, and converts it into a char** to simulate command line arguments.
|
/* Get the String[] containing the parameters, and converts it into a char** to simulate command line arguments.*/
|
||||||
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
||||||
argc = (int) arraySize +1;
|
argc = (int) arraySize +1;
|
||||||
argv = malloc(argc*sizeof(char*));
|
argv = malloc(argc*sizeof(char*));
|
||||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
argv[0] = "ProgramName.exe"; /* The program name: useless*/
|
||||||
j=0;
|
j=0;
|
||||||
for (i=1; i<argc; i++) {
|
for (i=1; i<argc; i++) {
|
||||||
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
||||||
argv[i] = (*env)->GetStringUTFChars(env, object, &isCopy);
|
argv[i] = (char*)(*env)->GetStringUTFChars(env, object, &isCopy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*printf("C: decoder params = ");
|
/*printf("C: decoder params = ");
|
||||||
|
@ -562,18 +562,18 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
|
|
||||||
/* parse input and get user encoding parameters */
|
/* parse input and get user encoding parameters */
|
||||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) {
|
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) {
|
||||||
// Release the Java arguments array
|
/* Release the Java arguments array*/
|
||||||
for (i=1; i<argc; i++)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
// Release the Java arguments array
|
/* Release the Java arguments array*/
|
||||||
for (i=1; i<argc; i++)
|
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]);
|
||||||
|
|
||||||
num_images=1;
|
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");
|
fid = (*env)->GetFieldID(env, cls,"skippedResolutions", "I");
|
||||||
parameters.cp_reduce = (short) (*env)->GetIntField(env, obj, fid);
|
parameters.cp_reduce = (short) (*env)->GetIntField(env, obj, fid);
|
||||||
|
|
||||||
|
@ -587,7 +587,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
Implemented for debug purpose. */
|
Implemented for debug purpose. */
|
||||||
/* -------------------------------------------------------------- */
|
/* -------------------------------------------------------------- */
|
||||||
if (parameters.infile && parameters.infile[0]!='\0') {
|
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");
|
fsrc = fopen(parameters.infile, "rb");
|
||||||
if (!fsrc) {
|
if (!fsrc) {
|
||||||
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
|
fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile);
|
||||||
|
@ -599,10 +599,10 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
src = (unsigned char *) malloc(file_length);
|
src = (unsigned char *) malloc(file_length);
|
||||||
fread(src, 1, file_length, fsrc);
|
fread(src, 1, file_length, fsrc);
|
||||||
fclose(fsrc);
|
fclose(fsrc);
|
||||||
//printf("C: %d bytes read from file\n",file_length);
|
/*printf("C: %d bytes read from file\n",file_length);*/
|
||||||
} else {
|
} else {
|
||||||
// Preparing the transfer of the codestream from Java to C
|
/* Preparing the transfer of the codestream from Java to C*/
|
||||||
//printf("C: before transfering codestream\n");
|
/*printf("C: before transfering codestream\n");*/
|
||||||
fid = (*env)->GetFieldID(env, cls,"compressedStream", "[B");
|
fid = (*env)->GetFieldID(env, cls,"compressedStream", "[B");
|
||||||
jba = (*env)->GetObjectField(env, obj, fid);
|
jba = (*env)->GetObjectField(env, obj, fid);
|
||||||
file_length = (*env)->GetArrayLength(env, jba);
|
file_length = (*env)->GetArrayLength(env, jba);
|
||||||
|
@ -752,17 +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
|
#ifdef CHECK_THRESHOLDS
|
||||||
printf("C: checking thresholds\n");
|
printf("C: checking thresholds\n");
|
||||||
#endif
|
#endif
|
||||||
// First compute the real with and height, in function of the resolutions decoded.
|
/* 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;
|
/*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;
|
/*hr = (image->comps[0].h + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;*/
|
||||||
w = image->comps[0].w;
|
w = image->comps[0].w;
|
||||||
h = image->comps[0].h;
|
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;
|
ptr = image->comps[0].data;
|
||||||
ptr1 = image->comps[1].data;
|
ptr1 = image->comps[1].data;
|
||||||
ptr2 = image->comps[2].data;
|
ptr2 = image->comps[2].data;
|
||||||
|
@ -775,7 +775,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
max_value = 255;
|
max_value = 255;
|
||||||
}
|
}
|
||||||
#endif
|
#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");
|
fid = (*env)->GetFieldID(env, cls,"image24", "[I");
|
||||||
jia = (*env)->GetObjectField(env, obj, fid);
|
jia = (*env)->GetObjectField(env, obj, fid);
|
||||||
jiBody = (*env)->GetIntArrayElements(env, jia, 0);
|
jiBody = (*env)->GetIntArrayElements(env, jia, 0);
|
||||||
|
@ -804,7 +804,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
}
|
}
|
||||||
(*env)->ReleaseIntArrayElements(env, jia, jiBody, 0);
|
(*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;
|
ptr = image->comps[0].data;
|
||||||
printf("C: before transfering a %d bpp image to java (length = %d)\n",image->comps[0].prec ,w*h);
|
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) {
|
if (image->comps[0].prec<=8) {
|
||||||
|
@ -821,7 +821,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
max_value = 255;
|
max_value = 255;
|
||||||
}
|
}
|
||||||
#endif
|
#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++) {
|
for (i=0; i<w*h; i++) {
|
||||||
tempUC = (unsigned char) (ptr[i]);
|
tempUC = (unsigned char) (ptr[i]);
|
||||||
#ifdef CHECK_THRESHOLDS
|
#ifdef CHECK_THRESHOLDS
|
||||||
|
@ -879,5 +879,5 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
}
|
}
|
||||||
return 1; /* OK */
|
return 1; /* OK */
|
||||||
}
|
}
|
||||||
//end main
|
/*end main*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue