/* * 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; }
/* * From a java.awt.Rectangle object, construct a ImageMagick * RectangleInfo, as passed in from the parameter. * * Input: * env Java VM environment * jRect an instance of java.awt.Rectangle * * Output: * iRect to be initilised by values in jRect * * Return: * non-zero if successful * zero if failed */ int getRectangle(JNIEnv *env, jobject jRect, RectangleInfo *iRect) { jint width, height, x, y; int retVal = getIntFieldValue(env, jRect, "width", NULL, (jint *) &width) && getIntFieldValue(env, jRect, "height", NULL, (jint *) &height) && getIntFieldValue(env, jRect, "x", NULL, (jint *) &x) && getIntFieldValue(env, jRect, "y", NULL, (jint *) &y); if (retVal) { iRect->width = width; iRect->height = height; iRect->x = x; iRect->y = y; } return retVal; }
/* * From a magick.PixelPacket object, construct a ImageMagick * PixelPacket, as passed in from the parameter. * * Input: * env Java VM environment * jPixelPacket an instance of magick.PixelPacket * * Output: * iPixelPacket to be initilised by values in jPixelPacket * * Return: * non-zero if successful * zero if failed */ int getPixelPacket(JNIEnv *env, jobject jPixelPacket, PixelPacket *iPixelPacket) { jint red, green, blue, opacity; int successful = getIntFieldValue(env, jPixelPacket, "red", NULL, &red) && getIntFieldValue(env, jPixelPacket, "green", NULL, &green) && getIntFieldValue(env, jPixelPacket, "blue", NULL, &blue) && getIntFieldValue(env, jPixelPacket, "opacity", NULL, &opacity); if (!successful) { return successful; } iPixelPacket->red = (Quantum) red; iPixelPacket->green = (Quantum) green; iPixelPacket->blue = (Quantum) blue; iPixelPacket->opacity = (Quantum) opacity; return successful; }