/*
 * Class:     magick_MontageInfo
 * Method:    init
 * Signature: (Lmagick/ImageInfo;)V
 */
JNIEXPORT void JNICALL Java_magick_MontageInfo_init
  (JNIEnv *env, jobject self, jobject imageInfo)
{
    ImageInfo *info;
    MontageInfo *montageInfo;

    /* Obtain the ImageInfo */
    info = (ImageInfo*) getHandle(env, imageInfo, "imageInfoHandle", NULL);
    if (info == NULL) {
        throwMagickException(env, "Unable to obtain ImageInfo handle");
        return;
    }

    /* Initialise the MontageInfo handle, allocating memory if required */
    montageInfo =
        (MontageInfo*) getHandle(env, self, "montageInfoHandle", NULL);
    if (montageInfo == NULL) {
        montageInfo = (MontageInfo*) AcquireMemory(sizeof(MontageInfo));
        if (montageInfo == NULL) {
            throwMagickException(env,
                                 "Unable to allocate "
                                 "memory for MontageInfo");
            return;
        }
    }
    GetMontageInfo(info, montageInfo);
    setHandle(env, self, "montageInfoHandle", (void*) montageInfo, NULL);
}
Ejemplo n.º 2
0
/*
 * Class:     magick_ImageInfo
 * Method:    setImageOption
 * Signature: (Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_magick_ImageInfo_setImageOption
    (JNIEnv *env, jobject self, jstring option, jstring value)
{                                                                             
    ImageInfo *info = NULL;
    const char *cstr1 = NULL;
    const char *cstr2 = NULL;
                                                                              
    info = (ImageInfo *) getHandle(env, self, "imageInfoHandle", NULL);             
    if (info == NULL) {                                                       
        throwMagickException(env, "Unable to retrieve handle");               
        return;                                                               
    }                                                                         
                                                                              
    cstr1 = (*env)->GetStringUTFChars(env, option, 0);                          
    if (cstr1 == NULL) {                                                       
        throwMagickException(env, "Unable to retrieve Java string chars");    
        return;                                                               
    }                        

    cstr2 = (*env)->GetStringUTFChars(env, value, 0);                          
    if (cstr2 == NULL) {                                                       
        throwMagickException(env, "Unable to retrieve Java string chars");    
        return;                                                               
    }                        
             
    SetImageOption(info, (char *)AcquireString(cstr1), (char *)AcquireString(cstr2));
    
    (*env)->ReleaseStringUTFChars(env, option, cstr1);
    (*env)->ReleaseStringUTFChars(env, value, cstr2);                          
}
Ejemplo n.º 3
0
/*
 * Class:     magick_Magick
 * Method:    parseImageGeometry
 * Signature: (Ljava/lang/String;Ljava/awt/Rectangle;)I
 */
JNIEXPORT jint JNICALL Java_magick_Magick_parseImageGeometry
  (JNIEnv *env, jclass magickClass, jstring geometry, jobject rect)
{
    unsigned long x, y, width, height;
    jint flags;
    const char *cstr;

    if (!getIntFieldValue(env, rect, "width", NULL, (jint *) &width) ||
	!getIntFieldValue(env, rect, "height", NULL, (jint *) &height) ||
	!getIntFieldValue(env, rect, "x", NULL, (jint *) &x) ||
	!getIntFieldValue(env, rect, "y", NULL, (jint *) &y)) {
        throwMagickException(env, "Unable to obtain Rectangle values");
        return 0;
    }

    cstr = (const char *) (*env)->GetStringUTFChars(env, geometry, 0);
    flags = ParseImageGeometry(cstr, &x, &y, &width, &height);
    (*env)->ReleaseStringUTFChars(env, geometry, cstr);

    if (!setIntFieldValue(env, rect, "width", NULL, width) ||
	!setIntFieldValue(env, rect, "height", NULL, height) ||
	!setIntFieldValue(env, rect, "x", NULL, x) ||
	!setIntFieldValue(env, rect, "y", NULL, y)) {
        throwMagickException(env, "Unable to set Rectangle values");
        return 0;
    }

    return flags;
}
Ejemplo n.º 4
0
/*
 * Class:     magick_ImageInfo
 * Method:    setFileName
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_magick_ImageInfo_setFileName
    (JNIEnv *env, jobject obj, jstring fileName)
{
    ImageInfo *imageInfo = NULL;
    jfieldID handleFid = 0;
    const char *cstr = NULL;

    imageInfo = (ImageInfo*) getHandle(env, obj,
				       "imageInfoHandle", &handleFid);

    if (imageInfo == NULL) {
	imageInfo = (ImageInfo *) AcquireMemory(sizeof(ImageInfo));
	if (imageInfo == NULL) {
	    throwMagickException(env, "Unable to allow memory for handle");
	    return;
	}
	GetImageInfo(imageInfo);
	setHandle(env, obj, "imageInfoHandle", (void*) imageInfo, &handleFid);
    }

    cstr = (*env)->GetStringUTFChars(env, fileName, 0);
    strcpy(imageInfo->filename, cstr);
    (*env)->ReleaseStringUTFChars(env, fileName, cstr);

#ifdef DIAGNOSTIC
    fprintf(stderr, "Set the file name in ImageInfo to %s\n",
            imageInfo->filename);
#endif
}
Ejemplo n.º 5
0
/*
 * Class:     magick_ImageInfo
 * Method:    getMagick
 * Signature: ()Ljava/lang/String;
 *
 * Contributed by Abdulbaset Gaddah <*****@*****.**>
 */
JNIEXPORT jstring JNICALL Java_magick_ImageInfo_getMagick
    (JNIEnv *env, jobject obj)
{
    ImageInfo *imageInfo = NULL;

    imageInfo = (ImageInfo*) getHandle(env, obj, "imageInfoHandle", NULL);
    if (imageInfo == NULL) {
	throwMagickException(env, "Unable to retrieve ImageInfo handle");
	return NULL;
    }

    return (*env)->NewStringUTF(env, imageInfo->magick);
}
/*
 * Class:     magick_MontageInfo
 * Method:    getFileName
 * Signature: ()Ljava/lang/String;
 */
JNIEXPORT jstring JNICALL Java_magick_MontageInfo_getFileName
  (JNIEnv *env, jobject self)
{
    MontageInfo *montageInfo = NULL;

    montageInfo =
        (MontageInfo*) getHandle(env, self, "montageInfoHandle", NULL);
    if (montageInfo == NULL) {
	throwMagickException(env, "Unable to retrieve MontageInfo handle");
	return NULL;
    }

    return (*env)->NewStringUTF(env, montageInfo->filename);
}
/*
 * Class:     magick_MontageInfo
 * Method:    setFileName
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_magick_MontageInfo_setFileName
  (JNIEnv *env, jobject self, jstring fileName)
{
    MontageInfo *montageInfo = NULL;
    const char *cstr = NULL;

    montageInfo = (MontageInfo*) getHandle(env, self,
                                           "montageInfoHandle", NULL);

    if (montageInfo == NULL) {
        throwMagickException(env, "Unable to obtain MontageInfo handle");
        return;
    }

    cstr = (*env)->GetStringUTFChars(env, fileName, 0);
    strcpy(montageInfo->filename, cstr);
    (*env)->ReleaseStringUTFChars(env, fileName, cstr);
}
Ejemplo n.º 8
0
/*
 * Class:     magick_ImageInfo
 * Method:    init
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_magick_ImageInfo_init
    (JNIEnv *env, jobject obj)
{
    ImageInfo *imageInfo = NULL;
    jfieldID fid = 0;

    imageInfo = (ImageInfo*) getHandle(env, obj, "imageInfoHandle", &fid);

    if (imageInfo == NULL) {
	imageInfo = (ImageInfo *) AcquireMemory(sizeof(ImageInfo));
	if (imageInfo == NULL) {
	    throwMagickException(env, "Unable to allocate memory for handle");
	    return;
	}
    }
    GetImageInfo(imageInfo);

    setHandle(env, obj, "imageInfoHandle", (void*) imageInfo, &fid);
}
Ejemplo n.º 9
0
/*
 * Class:     magick_QuantizeInfo
 * Method:    init
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_magick_QuantizeInfo_init
  (JNIEnv *env, jobject self)
{
    QuantizeInfo *quantizeInfo = NULL;
    jfieldID fid = 0;

    quantizeInfo =
	(QuantizeInfo*) getHandle(env, self, "quantizeInfoHandle", &fid);

    if (quantizeInfo == NULL) {
	quantizeInfo = (QuantizeInfo *) AcquireMemory(sizeof(QuantizeInfo));
	if (quantizeInfo == NULL) {
	    throwMagickException(env, "Unable to allow memory for handle");
	    return;
	}
    }
    GetQuantizeInfo(quantizeInfo);

    setHandle(env, self, "quantizeInfoHandle", (void*) quantizeInfo, &fid);
}
Ejemplo n.º 10
0
/*
 * Given the C ProfileInfo structure and the Java ProfileInfo object,
 * acquire the contents of the Java ProfileInfo object and store it in
 * the C ProfileInfo structure.
 *
 * Input:
 *   env            JNI environment
 *   profileObj     Java ProfileInfo object for which field values are to be
 *                  obtain to store into the C ProfileInfo structure
 * Output:
 *   profileInfo    C ProfileINfo structure to store field values
 */
void setProfileInfo(JNIEnv *env, ProfileInfo *profileInfo, jobject profileObj)
{
    char *name;
    unsigned char *info;
    int infoSize = 0;

    if (profileObj == NULL) {
        throwMagickException(env, "ProfileInfo cannot be null");
        return;
    }

    name = getStringFieldValue(env, profileObj, "name", NULL);
    info = getByteArrayFieldValue(env, profileObj, "info", NULL, &infoSize);
    if (profileInfo->name != NULL) {
       // RelinquishMagickMemory((void**) &profileInfo->name);
    }
    profileInfo->name = name;
    if (profileInfo->info != NULL) {
       // RelinquishMagickMemory((void**) &profileInfo->info);
    }
    profileInfo->info = info;
    profileInfo->length = infoSize;
}
Ejemplo n.º 11
0
/*
 * Given the C ProfileInfo structure, construct a Java ProfileInfo
 * object with values obtained from the C ProfileInfo structure.
 * Input:
 *   env           JNI environment
 *   profileInfo   C ProfileInfo structure
 * Return:
 *   Java ProfileInfo object
 */
jobject getProfileInfo(JNIEnv *env, ProfileInfo *profileInfo)
{
    jclass profileInfoClass;
    jmethodID consMethodID;
    jobject profileObject;
    jstring name;
    jbyteArray byteArray;
    unsigned char *byteElements;

    /* Get the ProfileInfo class ID */
    profileInfoClass = (*env)->FindClass(env, "magick/ProfileInfo");
    if (profileInfoClass == 0) {
        throwMagickException(env, "Unable to locate class "
                                   "magick.ProfileInfo");
        return NULL;
    }

    /* Get the constructor method ID */
    consMethodID = (*env)->GetMethodID(env, profileInfoClass,
                                       "<init>", "(Ljava/lang/String;[B)V");
    if (consMethodID == 0) {
        throwMagickException(env, "Unable to locate constructor "
                                  "ProfileInfo(String, byte[])");
        return NULL;
    }

    /* Construct the name */
    if (profileInfo->name != NULL) {
        name = (*env)->NewStringUTF(env, profileInfo->name);
        if (name == NULL) {
            throwMagickException(env, "Unable to allocate Java String "
                                      "for profile name");
            return NULL;
        }
    }
    else {
        name = NULL;
    }

    /* Construct the byte array */
    if (profileInfo->length > 0) {
        byteArray = (*env)->NewByteArray(env, profileInfo->length);
        if (byteArray == NULL) {
            throwMagickException(env, "Unable to allocate byte array "
                                      "for profile info");
            return NULL;
        }
        byteElements =
            (*env)->GetByteArrayElements(env, byteArray, JNI_FALSE);
        if (byteElements == NULL) {
            throwMagickException(env, "Unable to obtain byte array elements "
                                      "for profile info");
            return NULL;
        }
        memcpy(byteElements,
               profileInfo->info,
               profileInfo->length);
        (*env)->ReleaseByteArrayElements(env, byteArray, byteElements, 0);
    }
    else {
        byteArray = NULL;
    }

    /* Construct the ProfileInfo object */
    profileObject = (*env)->NewObject(env, profileInfoClass, consMethodID,
                                      name, byteArray);
    if (profileObject == NULL) {
        throwMagickException(env, "Unable to construct ProfileInfo object");
        return NULL;
    }

    return profileObject;
}