imgp_imagedatafactory_kni.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 589 行 · 第 1/2 页
C
589 行
* </pre> * * @param imageData The <tt>ImageData</tt> to be filled * @param intputData A byte array containing the encoded image data * @param offset The start of the image data within the byte array * @param length The length of the image data in the byte array */KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDecodeImage() { int length = KNI_GetParameterAsInt(4); int offset = KNI_GetParameterAsInt(3); unsigned char* srcBuffer = NULL; gxpport_image_native_handle newImagePtr; int imgWidth; int imgHeight; img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; KNI_StartHandles(2); KNI_DeclareHandle(pngData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, pngData); KNI_GetParameterAsObject(1, imageData); do { if ((offset < 0) || (length < 0) || (offset + length) > KNI_GetArrayLength(pngData)) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); break; } srcBuffer = (unsigned char *)JavaByteArray(pngData); SNI_BEGIN_RAW_POINTERS; gxpport_decodeimmutable_from_selfidentifying(srcBuffer + offset, length, &imgWidth, &imgHeight, &newImagePtr, &creationError); SNI_END_RAW_POINTERS; if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for immutable image"); break; } if (IMG_NATIVE_IMAGE_NO_ERROR != creationError) { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } { java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData); dstImageDataPtr->width = (jint)imgWidth; dstImageDataPtr->height = (jint)imgHeight; dstImageDataPtr->nativeImageData = (jint)newImagePtr; } } while (0); KNI_EndHandles(); KNI_ReturnVoid();}/** * boolean loadRomizedImage(IamgeData imageData, int imageDataArrayPtr, * int imageDataArrayLength); */KNIEXPORT KNI_RETURNTYPE_BOOLEANJava_javax_microedition_lcdui_ImageDataFactory_loadRomizedImage() { int status = KNI_FALSE; int imageDataArrayPtr = KNI_GetParameterAsInt(2); int imageDataArrayLength = KNI_GetParameterAsInt(3); int imgWidth, imgHeight; img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; /* pointer to native image structure */ gxpport_image_native_handle newImagePtr; KNI_StartHandles(1); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(1, imageData); do { unsigned char* buffer = (unsigned char*)imageDataArrayPtr; gxpport_loadimmutable_from_platformbuffer( buffer, imageDataArrayLength, KNI_TRUE, &imgWidth, &imgHeight, &newImagePtr, &creationError); if (IMG_NATIVE_IMAGE_NO_ERROR == creationError) { java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData); dstImageDataPtr->width = (jint)imgWidth; dstImageDataPtr->height = (jint)imgHeight; dstImageDataPtr->nativeImageData = (jint)newImagePtr; status = KNI_TRUE; break; } else if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } else if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for immutable image"); break; } else { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } while (0); KNI_EndHandles(); KNI_ReturnBoolean(status);}/** * Populates a passed in immutable <tt>ImageData</tt> * from the given ARGB integer * array. The array consists of values in the form of 0xAARRGGBB. * <p> * Java declaration: * <pre> * createImmutableImageDecodeRGBImage([Ljavax/microedition/lcdui/ImageData;III)V * </pre> * * @param imageData The <tt>ImadgeData</tt> to be populated * @param rgbData The array of argb image data * @param width The width of the new image * @param height The height of the new image * @param processAlpha If <tt>true</tt>, alpha channel bytes will * be used, otherwise, alpha channel bytes will * be ignored */KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_ImageDataFactory_createImmutableImageDecodeRGBImage() { jboolean processAlpha = KNI_GetParameterAsBoolean(5); int height = KNI_GetParameterAsInt(4); int width = KNI_GetParameterAsInt(3); jint *imageBuffer = NULL; int buflen; img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; /* pointer to native image structure */ gxpport_image_native_handle newImagePtr; KNI_StartHandles(2); KNI_DeclareHandle(rgbData); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(2, rgbData); KNI_GetParameterAsObject(1, imageData); do { if (KNI_IsNullHandle(rgbData)) { KNI_ThrowNew(midpNullPointerException, NULL); break; } if ((width <= 0) || (height <= 0)) { KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } buflen = KNI_GetArrayLength(rgbData); if ((width * height) > buflen) { KNI_ThrowNew(midpArrayIndexOutOfBoundsException, NULL); break; } imageBuffer = JavaIntArray(rgbData); SNI_BEGIN_RAW_POINTERS; gxpport_decodeimmutable_from_argb(imageBuffer, width, height, processAlpha, &newImagePtr, &creationError); SNI_END_RAW_POINTERS; if (IMG_NATIVE_IMAGE_NO_ERROR == creationError) { java_imagedata * dstImageDataPtr = IMGAPI_GET_IMAGEDATA_PTR(imageData); dstImageDataPtr->height = (jint)height; dstImageDataPtr->width = (jint)width; dstImageDataPtr->nativeImageData = (jint)newImagePtr; break; } if (IMG_NATIVE_IMAGE_OUT_OF_MEMORY_ERROR == creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); break; } if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for immutable image"); break; } KNI_ThrowNew(midpIllegalArgumentException, NULL); } while (0); KNI_EndHandles(); KNI_ReturnVoid();}/** * Creates the native data structures for a new <tt>ImageData</tt>. * <p> * Java declaration: * <pre> * createMutableImage(Ljavax/microedition/lcdui/ImageData;II)V * </pre> * * @param imageData to be populated * @param width the width of the new <tt>MutableImage</tt> * @param height the height of the new <tt>MutableImage</tt> */KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_ImageDataFactory_createMutableImageData() { int height = KNI_GetParameterAsInt(3); int width = KNI_GetParameterAsInt(2); /* pointer to native image structure */ gxpport_mutableimage_native_handle newImagePtr = NULL; /* variable to hold error codes */ img_native_error_codes creationError = IMG_NATIVE_IMAGE_NO_ERROR; if ((width < 0) || (height < 0)) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { /* initialize the internal members of the native image structure as required by the platform. */ gxpport_create_mutable(&newImagePtr, width, height, &creationError); if (IMG_NATIVE_IMAGE_RESOURCE_LIMIT == creationError) { KNI_ThrowNew(midpOutOfMemoryError, "Resource limit exceeded for" " Mutable image"); } else if (IMG_NATIVE_IMAGE_NO_ERROR != creationError) { KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { KNI_StartHandles(1); KNI_DeclareHandle(imageData); KNI_GetParameterAsObject(1, imageData); IMGAPI_GET_IMAGEDATA_PTR(imageData)->nativeImageData = (jint) newImagePtr; KNI_EndHandles(); } } KNI_ReturnVoid();}/** * Garbage collect any zombie Images to free up their resources. * <p> * Java declaration: * <pre> * garbageCollectImages(Z)V * </pre> * * @param doFullGC boolean indicating whether to do a full GC or not */KNIEXPORT KNI_RETURNTYPE_VOIDJava_javax_microedition_lcdui_ImageDataFactory_garbageCollectImages() { jboolean doFullGC = KNI_GetParameterAsBoolean(1); if (doFullGC == KNI_TRUE) { JVM_GarbageCollect(0, 0); } else { JVM_GarbageCollect(JVM_COLLECT_YOUNG_SPACE_ONLY, 0); } KNI_ReturnVoid();}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?