[1.5] Integrate patch from winfried posted on the mailing list. See here for more info: https://groups.google.com/group/openjpeg/msg/6488859a0dce77
This commit is contained in:
parent
baa7e32f9c
commit
ce9d5083ef
|
@ -57,7 +57,7 @@
|
|||
|
||||
extern int get_file_format(char *filename);
|
||||
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);
|
||||
|
||||
typedef struct callback_variables {
|
||||
|
@ -349,10 +349,11 @@ 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++) {
|
||||
|
@ -494,7 +495,7 @@ void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_
|
|||
|
||||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
||||
int parse_cmdline_encoder(int argc, char * const argv[], opj_cparameters_t *parameters,
|
||||
img_fol_t *img_fol, char *indexfilename) {
|
||||
int i, j,totlen;
|
||||
opj_option_t long_option[]={
|
||||
|
@ -628,6 +629,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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++) {
|
||||
|
@ -856,6 +859,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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);
|
||||
}
|
||||
|
@ -885,6 +891,9 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
|||
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;
|
||||
}
|
||||
|
@ -1352,7 +1361,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 */
|
||||
|
@ -1361,18 +1370,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;
|
||||
|
@ -1597,7 +1606,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;
|
||||
}
|
||||
|
@ -1630,7 +1639,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;
|
||||
|
@ -1643,7 +1652,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;
|
||||
|
@ -1658,8 +1667,10 @@ 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;
|
||||
|
@ -1705,12 +1716,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];
|
||||
|
@ -1724,13 +1735,14 @@ 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];
|
||||
|
@ -1743,14 +1755,15 @@ 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];
|
||||
|
@ -1765,7 +1778,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;
|
||||
}
|
||||
|
@ -1775,7 +1788,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 */
|
||||
char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
|
||||
const 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;
|
||||
|
@ -1788,7 +1801,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;
|
||||
|
@ -1797,18 +1810,20 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
jbyteArray jba;
|
||||
jbyte *jbBody;
|
||||
callback_variables_t msgErrorCallback_vars;
|
||||
// <== access variable to the Java member variables.
|
||||
|
||||
// For the encoding and storage into the file
|
||||
/* <== access variable to the Java member variables. */
|
||||
jlong retval = -1;
|
||||
/* For the encoding and storage into the file */
|
||||
opj_cinfo_t* cinfo;
|
||||
int codestream_length;
|
||||
int codestream_length = -1;
|
||||
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");
|
||||
|
@ -1816,8 +1831,11 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
|
||||
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
||||
argc = (int) arraySize +1;
|
||||
argv = malloc(argc*sizeof(char*));
|
||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
||||
argv = (const char **)malloc(argc*sizeof(char*));
|
||||
|
||||
if(argv == NULL) return -1;
|
||||
|
||||
argv[0] = "ProgramName.exe";/* The program name: useless */
|
||||
j=0;
|
||||
for (i=1; i<argc; i++) {
|
||||
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
||||
|
@ -1841,23 +1859,21 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
/* set encoding parameters to default values */
|
||||
opj_set_default_encoder_parameters(¶meters);
|
||||
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 */
|
||||
if (parse_cmdline_encoder(argc, argv, ¶meters,&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]);
|
||||
return -1;
|
||||
}
|
||||
j = parse_cmdline_encoder(argc, (char *const*)argv, ¶meters,&img_fol, indexfilename);
|
||||
|
||||
// Release the Java arguments array
|
||||
/* 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]);
|
||||
|
||||
if(j == 1) goto fin; /* failure */
|
||||
|
||||
if (parameters.cp_cinema){
|
||||
cinema_parameters(¶meters);
|
||||
|
@ -1872,9 +1888,15 @@ 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 */
|
||||
|
@ -1891,10 +1913,10 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
fprintf(stderr,"\n");
|
||||
|
||||
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) {
|
||||
fprintf(stderr, "Unable to load image\n");
|
||||
return -1;
|
||||
goto fin;
|
||||
}
|
||||
|
||||
/* Decide if MCT should be used */
|
||||
|
@ -1928,7 +1950,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
if (!bSuccess) {
|
||||
opj_cio_close(cio);
|
||||
fprintf(stderr, "failed to encode image\n");
|
||||
return -1;
|
||||
goto fin;
|
||||
}
|
||||
codestream_length = cio_tell(cio);
|
||||
|
||||
|
@ -1940,7 +1962,8 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
}
|
||||
}
|
||||
|
||||
compressed_index = create_index_into_byte_array(&cstr_info, &compressed_index_size);
|
||||
compressed_index = (int*)
|
||||
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);
|
||||
|
@ -1955,7 +1978,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);
|
||||
return -1;
|
||||
goto fin;
|
||||
}
|
||||
fwrite(cio->buffer, 1, codestream_length, f);
|
||||
fclose(f);
|
||||
|
@ -1984,5 +2007,10 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
|||
if(parameters.cp_comment) free(parameters.cp_comment);
|
||||
if(parameters.cp_matrice) free(parameters.cp_matrice);
|
||||
|
||||
return codestream_length;
|
||||
retval = codestream_length;
|
||||
|
||||
fin:
|
||||
free(argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ int get_file_format(char *filename) {
|
|||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) {
|
||||
int parse_cmdline_decoder(int argc, char * const argv[], opj_dparameters_t *parameters,img_fol_t *img_fol) {
|
||||
/* parse the command line */
|
||||
int totlen;
|
||||
opj_option_t long_option[]={
|
||||
|
@ -339,6 +339,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
|||
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;
|
||||
}
|
||||
|
@ -426,7 +429,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
|
|||
/* No check for possible errors before the -i and -o options are of course not mandatory*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
}/* parse_cmdline_decoder() */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -488,12 +491,13 @@ 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 */
|
||||
char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
|
||||
const 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 */
|
||||
|
@ -508,7 +512,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;
|
||||
|
@ -521,8 +525,9 @@ 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
|
||||
/* <=== access variable to Java member variables */
|
||||
int *ptr, *ptr1, *ptr2;/* <== To transfer the decoded image to Java */
|
||||
jint retval = FAILS;
|
||||
|
||||
/* configure the event callbacks */
|
||||
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
|
||||
|
@ -530,20 +535,26 @@ 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, and converts it into a char** to simulate command line arguments.
|
||||
/* Get the String[] containing the parameters */
|
||||
|
||||
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
||||
argc = (int) arraySize +1;
|
||||
argv = malloc(argc*sizeof(char*));
|
||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
||||
argv = (const char **)malloc(argc*sizeof(char*));
|
||||
|
||||
if(argv == NULL) return FAILS;
|
||||
|
||||
argv[0] = "ProgramName.exe";/* The program name: useless */
|
||||
j=0;
|
||||
for (i=1; i<argc; i++) {
|
||||
object = (*env)->GetObjectArrayElement(env, javaParameters, i-1);
|
||||
|
@ -561,19 +572,18 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
|||
parameters.decod_format = J2K_CFMT;
|
||||
|
||||
/* parse input and get user encoding parameters */
|
||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) {
|
||||
// Release the Java arguments array
|
||||
j = parse_cmdline_decoder(argc, (char * const*)argv, ¶meters,&img_fol);
|
||||
|
||||
/* Release the Java arguments array */
|
||||
for (i=1; i<argc; i++)
|
||||
(*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]);
|
||||
(*env)->ReleaseStringUTFChars(env,
|
||||
(*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
|
||||
|
||||
if(j == 1) goto fin; /* failure */
|
||||
|
||||
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);
|
||||
|
||||
|
@ -587,22 +597,25 @@ 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);
|
||||
return 1;
|
||||
goto fin;
|
||||
}
|
||||
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);
|
||||
|
@ -636,7 +649,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);
|
||||
return 1;
|
||||
goto fin;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
|
@ -666,7 +679,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);
|
||||
return 1;
|
||||
goto fin;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
|
@ -697,7 +710,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);
|
||||
return 1;
|
||||
goto fin;
|
||||
}
|
||||
|
||||
/* close the byte stream */
|
||||
|
@ -752,17 +765,21 @@ 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;
|
||||
|
@ -775,7 +792,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);
|
||||
|
@ -804,7 +821,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) {
|
||||
|
@ -821,7 +838,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
|
||||
|
@ -877,7 +894,12 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
|||
opj_image_destroy(image);
|
||||
|
||||
}
|
||||
return 1; /* OK */
|
||||
}
|
||||
//end main
|
||||
retval = OK;
|
||||
|
||||
fin:
|
||||
free(argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
/* end main MAIN */
|
||||
|
||||
|
|
|
@ -1011,7 +1011,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
|
|||
int adjustR, adjustG, adjustB;
|
||||
|
||||
if (image->comps[0].prec < 8) {
|
||||
fprintf(stderr, "Unsupported number of components: %d\n", image->comps[0].prec);
|
||||
fprintf(stderr, "Unsupported precision: %d\n", image->comps[0].prec);
|
||||
return 1;
|
||||
}
|
||||
if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx
|
||||
|
@ -2484,16 +2484,19 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
|
|||
w= tiWidth;
|
||||
h= tiHeight;
|
||||
|
||||
if(tiBps != 8 && tiBps != 16 && tiBps != 12) tiBps = 0;
|
||||
if(tiPhoto != 1 && tiPhoto != 2) tiPhoto = 0;
|
||||
|
||||
if( !tiBps || !tiPhoto)
|
||||
{
|
||||
if( !tiBps)
|
||||
unsigned short b = tiBps, p = tiPhoto;
|
||||
|
||||
if(tiBps != 8 && tiBps != 16 && tiBps != 12) b = 0;
|
||||
if(tiPhoto != 1 && tiPhoto != 2) p = 0;
|
||||
|
||||
if( !b || !p)
|
||||
{
|
||||
if( !b)
|
||||
fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits"
|
||||
" implemented\n",tiBps);
|
||||
else
|
||||
if( !tiPhoto)
|
||||
if( !p)
|
||||
fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)"
|
||||
" and GRAY(A) has been implemented\n",(int) tiPhoto);
|
||||
|
||||
|
@ -2502,7 +2505,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;
|
||||
|
|
Loading…
Reference in New Issue