[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 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 {
|
||||||
|
@ -349,10 +349,11 @@ OPJ_PROG_ORDER give_progression(char progression[4]) {
|
||||||
return PROG_UNKNOWN;
|
return PROG_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/// <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++) {
|
||||||
|
@ -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) {
|
img_fol_t *img_fol, char *indexfilename) {
|
||||||
int i, j,totlen;
|
int i, j,totlen;
|
||||||
opj_option_t long_option[]={
|
opj_option_t long_option[]={
|
||||||
|
@ -628,6 +629,8 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
|
||||||
numresolution = parameters->numresolution;
|
numresolution = parameters->numresolution;
|
||||||
matrix_width = numresolution * 3;
|
matrix_width = numresolution * 3;
|
||||||
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
|
parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int));
|
||||||
|
if(parameters->cp_matrice == NULL) return 1;
|
||||||
|
|
||||||
s = s + 2;
|
s = s + 2;
|
||||||
|
|
||||||
for (i = 0; i < numlayers; i++) {
|
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 */
|
case 'C': /* add a comment */
|
||||||
{
|
{
|
||||||
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
|
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
|
||||||
|
|
||||||
|
if(parameters->cp_comment == NULL) return 1;
|
||||||
|
|
||||||
if(parameters->cp_comment) {
|
if(parameters->cp_comment) {
|
||||||
strcpy(parameters->cp_comment, opj_optarg);
|
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 */
|
case 'z': /* Image Directory path */
|
||||||
{
|
{
|
||||||
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
||||||
|
|
||||||
|
if(img_fol->imgdirpath == NULL) return 1;
|
||||||
|
|
||||||
strcpy(img_fol->imgdirpath,opj_optarg);
|
strcpy(img_fol->imgdirpath,opj_optarg);
|
||||||
img_fol->set_imgdir=1;
|
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 =
|
*buffer_size =
|
||||||
1 /* version */
|
1 /* version */
|
||||||
+ (10 /* image_w until decomposition */
|
+ (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 * 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 +1606,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 +1639,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 +1652,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 +1667,10 @@ 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
|
||||||
// the pixels of the images in Telemis before entering the encoder).
|
* (shift of the negative part of 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 +1716,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 +1735,14 @@ 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 +1755,15 @@ 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 +1778,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;
|
||||||
}
|
}
|
||||||
|
@ -1775,7 +1788,7 @@ opj_image_t* loadImage(opj_cparameters_t *parameters, JNIEnv *env, jobject obj,
|
||||||
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
|
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
|
||||||
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 */
|
const char **argv; /* 'parse_cmdline_decoder' method taken from the j2k_to_image project */
|
||||||
opj_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;
|
||||||
|
@ -1788,7 +1801,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
|
|
||||||
int* compressed_index = NULL;
|
int* 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 +1810,20 @@ 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. */
|
||||||
|
jlong retval = -1;
|
||||||
// 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 = -1;
|
||||||
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");
|
||||||
|
@ -1816,8 +1831,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 = (const char **)malloc(argc*sizeof(char*));
|
||||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
|
||||||
|
if(argv == NULL) return -1;
|
||||||
|
|
||||||
|
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);
|
||||||
|
@ -1841,23 +1859,21 @@ 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;
|
||||||
memset(&img_fol,0,sizeof(img_fol_t));
|
memset(&img_fol,0,sizeof(img_fol_t));
|
||||||
|
|
||||||
/* 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) {
|
j = parse_cmdline_encoder(argc, (char *const*)argv, ¶meters,&img_fol, indexfilename);
|
||||||
// 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
|
/* 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]);
|
||||||
|
|
||||||
|
if(j == 1) goto fin; /* failure */
|
||||||
|
|
||||||
if (parameters.cp_cinema){
|
if (parameters.cp_cinema){
|
||||||
cinema_parameters(¶meters);
|
cinema_parameters(¶meters);
|
||||||
|
@ -1872,9 +1888,15 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
/* UniPG>> */
|
/* UniPG>> */
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
parameters.cp_comment = (char*)malloc(clen+strlen(version)+11);
|
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);
|
sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version);
|
||||||
#else
|
#else
|
||||||
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
|
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
|
||||||
|
|
||||||
|
if(parameters.cp_comment == NULL) goto fin;
|
||||||
|
|
||||||
sprintf(parameters.cp_comment,"%s%s", comment, version);
|
sprintf(parameters.cp_comment,"%s%s", comment, version);
|
||||||
#endif
|
#endif
|
||||||
/* <<UniPG */
|
/* <<UniPG */
|
||||||
|
@ -1891,10 +1913,10 @@ 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;
|
goto fin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Decide if MCT should be used */
|
/* Decide if MCT should be used */
|
||||||
|
@ -1928,7 +1950,7 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
if (!bSuccess) {
|
if (!bSuccess) {
|
||||||
opj_cio_close(cio);
|
opj_cio_close(cio);
|
||||||
fprintf(stderr, "failed to encode image\n");
|
fprintf(stderr, "failed to encode image\n");
|
||||||
return -1;
|
goto fin;
|
||||||
}
|
}
|
||||||
codestream_length = cio_tell(cio);
|
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 */
|
/* Allocates the Java compressedIndex byte[] and sends this index into the Java object */
|
||||||
fid = (*env)->GetFieldID(env, cls,"compressedIndex", "[B");
|
fid = (*env)->GetFieldID(env, cls,"compressedIndex", "[B");
|
||||||
jba = (*env)->NewByteArray(env, compressed_index_size+1);
|
jba = (*env)->NewByteArray(env, compressed_index_size+1);
|
||||||
|
@ -1955,14 +1978,14 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
f = fopen(parameters.outfile, "wb");
|
f = fopen(parameters.outfile, "wb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(stderr, "failed to open [%s] for writing\n", parameters.outfile);
|
fprintf(stderr, "failed to open [%s] for writing\n", parameters.outfile);
|
||||||
return -1;
|
goto fin;
|
||||||
}
|
}
|
||||||
fwrite(cio->buffer, 1, codestream_length, f);
|
fwrite(cio->buffer, 1, codestream_length, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
fprintf(stdout,"Generated outfile [%s]\n",parameters.outfile);
|
fprintf(stdout,"Generated outfile [%s]\n",parameters.outfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the generated codestream to the Java pre-allocated compressedStream byte[] */
|
/* Write the generated codestream to the Java pre-allocated compressedStream byte[] */
|
||||||
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);
|
||||||
jbBody = (*env)->GetPrimitiveArrayCritical(env, jba, 0);
|
jbBody = (*env)->GetPrimitiveArrayCritical(env, jba, 0);
|
||||||
|
@ -1984,5 +2007,10 @@ JNIEXPORT jlong JNICALL Java_org_openJpeg_OpenJPEGJavaEncoder_internalEncodeImag
|
||||||
if(parameters.cp_comment) free(parameters.cp_comment);
|
if(parameters.cp_comment) free(parameters.cp_comment);
|
||||||
if(parameters.cp_matrice) free(parameters.cp_matrice);
|
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 */
|
/* parse the command line */
|
||||||
int totlen;
|
int totlen;
|
||||||
opj_option_t long_option[]={
|
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 */
|
case 'y': /* Image Directory path */
|
||||||
{
|
{
|
||||||
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
|
||||||
|
|
||||||
|
if(img_fol->imgdirpath == NULL) return 1;
|
||||||
|
|
||||||
strcpy(img_fol->imgdirpath,opj_optarg);
|
strcpy(img_fol->imgdirpath,opj_optarg);
|
||||||
img_fol->set_imgdir=1;
|
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*/
|
/* No check for possible errors before the -i and -o options are of course not mandatory*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}/* parse_cmdline_decoder() */
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
@ -488,12 +491,13 @@ void info_callback(const char *msg, void *client_data) {
|
||||||
(*env)->DeleteLocalRef(env, jbuffer);
|
(*env)->DeleteLocalRef(env, jbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define FAILS -1
|
||||||
|
#define OK 0
|
||||||
/* --------------------------------------------------------------------------
|
/* --------------------------------------------------------------------------
|
||||||
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
|
-------------------- MAIN METHOD, CALLED BY JAVA -----------------------*/
|
||||||
JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2KtoImage(JNIEnv *env, jobject obj, jobjectArray javaParameters) {
|
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 */
|
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 */
|
opj_dparameters_t parameters; /* decompression 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 */
|
||||||
|
@ -508,7 +512,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 +525,9 @@ 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 */
|
||||||
|
jint retval = FAILS;
|
||||||
|
|
||||||
/* 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,20 +535,26 @@ 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 */
|
||||||
|
|
||||||
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
arraySize = (*env)->GetArrayLength(env, javaParameters);
|
||||||
argc = (int) arraySize +1;
|
argc = (int) arraySize +1;
|
||||||
argv = malloc(argc*sizeof(char*));
|
argv = (const char **)malloc(argc*sizeof(char*));
|
||||||
argv[0] = "ProgramName.exe"; // The program name: useless
|
|
||||||
|
if(argv == NULL) return FAILS;
|
||||||
|
|
||||||
|
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);
|
||||||
|
@ -561,19 +572,18 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
parameters.decod_format = J2K_CFMT;
|
parameters.decod_format = J2K_CFMT;
|
||||||
|
|
||||||
/* parse input and get user encoding parameters */
|
/* parse input and get user encoding parameters */
|
||||||
if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) {
|
j = parse_cmdline_decoder(argc, (char * const*)argv, ¶meters,&img_fol);
|
||||||
// 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,
|
||||||
return -1;
|
(*env)->GetObjectArrayElement(env, javaParameters, i-1), argv[i]);
|
||||||
}
|
|
||||||
// Release the Java arguments array
|
if(j == 1) goto fin; /* failure */
|
||||||
for (i=1; i<argc; 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,22 +597,25 @@ 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);
|
||||||
return 1;
|
goto fin;
|
||||||
}
|
}
|
||||||
fseek(fsrc, 0, SEEK_END);
|
fseek(fsrc, 0, SEEK_END);
|
||||||
file_length = ftell(fsrc);
|
file_length = ftell(fsrc);
|
||||||
fseek(fsrc, 0, SEEK_SET);
|
fseek(fsrc, 0, SEEK_SET);
|
||||||
src = (unsigned char *) malloc(file_length);
|
src = (unsigned char *) malloc(file_length);
|
||||||
|
|
||||||
|
if(src == NULL) goto fin;
|
||||||
|
|
||||||
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);
|
||||||
|
@ -636,7 +649,7 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||||
opj_destroy_decompress(dinfo);
|
opj_destroy_decompress(dinfo);
|
||||||
opj_cio_close(cio);
|
opj_cio_close(cio);
|
||||||
return 1;
|
goto fin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the byte stream */
|
/* 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");
|
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||||
opj_destroy_decompress(dinfo);
|
opj_destroy_decompress(dinfo);
|
||||||
opj_cio_close(cio);
|
opj_cio_close(cio);
|
||||||
return 1;
|
goto fin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the byte stream */
|
/* 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");
|
fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n");
|
||||||
opj_destroy_decompress(dinfo);
|
opj_destroy_decompress(dinfo);
|
||||||
opj_cio_close(cio);
|
opj_cio_close(cio);
|
||||||
return 1;
|
goto fin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* close the byte stream */
|
/* 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
|
#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,
|
||||||
//wr = (image->comps[0].w + (1 << image->comps[0].factor) -1) >> image->comps[0].factor;
|
* in function of the resolutions decoded.
|
||||||
//hr = (image->comps[0].h + (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;
|
||||||
|
---*/
|
||||||
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 +792,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 +821,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 +838,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
|
||||||
|
@ -877,7 +894,12 @@ JNIEXPORT jint JNICALL Java_org_openJpeg_OpenJPEGJavaDecoder_internalDecodeJ2Kto
|
||||||
opj_image_destroy(image);
|
opj_image_destroy(image);
|
||||||
|
|
||||||
}
|
}
|
||||||
return 1; /* OK */
|
retval = OK;
|
||||||
}
|
|
||||||
//end main
|
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;
|
int adjustR, adjustG, adjustB;
|
||||||
|
|
||||||
if (image->comps[0].prec < 8) {
|
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;
|
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
|
||||||
|
@ -2484,16 +2484,19 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
|
||||||
w= tiWidth;
|
w= tiWidth;
|
||||||
h= tiHeight;
|
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"
|
fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits"
|
||||||
" implemented\n",tiBps);
|
" implemented\n",tiBps);
|
||||||
else
|
else
|
||||||
if( !tiPhoto)
|
if( !p)
|
||||||
fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)"
|
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) tiPhoto);
|
||||||
|
|
||||||
|
@ -2502,7 +2505,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
{/* From: tiff-4.0.x/libtiff/tif_getimage.c : */
|
{/* From: tiff-4.0.x/libtiff/tif_getimage.c : */
|
||||||
uint16* sampleinfo;
|
uint16* sampleinfo;
|
||||||
uint16 extrasamples;
|
uint16 extrasamples;
|
||||||
|
|
Loading…
Reference in New Issue