jboolean piscesutil_moduleInitialize() { if (_Pisces_convert8To5 == NULL) { jint i; jint* convert8To5; jint* convert8To6; convert8To5 = (jint*)PISCESmalloc(256*sizeof(jint)); ASSERT_ALLOC_BOOLEAN(convert8To5); convert8To6 = (jint*)PISCESmalloc(256*sizeof(jint)); ASSERT_ALLOC_BOOLEAN(convert8To6); if ((convert8To5 == NULL) || (convert8To6 == NULL)) { if (convert8To5 != NULL) { PISCESfree(convert8To5); } if (convert8To6 != NULL) { PISCESfree(convert8To6); } return XNI_FALSE; } for (i = 0; i < 256; i++) { convert8To5[i] = (i*31 + 127)/255; convert8To6[i] = (i*63 + 127)/255; } _Pisces_convert8To5 = convert8To5; _Pisces_convert8To6 = convert8To6; } return XNI_TRUE; }
JNIEXPORT void JNICALL Java_com_sun_pisces_NativeSurface_initialize(JNIEnv* env, jobject objectHandle, jint dataType, jint width, jint height) { AbstractSurface* surface; if (surface_initialize(env, objectHandle) && initializeSurfaceFieldIds(env, objectHandle)) { surface = my_malloc(AbstractSurface, 1); if (surface != NULL) { jint size = width * height * sizeof(jint); jint* data = (jint*)PISCESmalloc(size); if (data != NULL) { memset(data, 0, size); surface->super.width = width; surface->super.height = height; surface->super.offset = 0; surface->super.scanlineStride = width; surface->super.pixelStride = 1; surface->super.imageType = dataType; surface->super.data = data; surface->acquire = surface_acquire; surface->release = surface_release; surface->cleanup = surface_cleanup; (*env)->SetLongField(env, objectHandle, fieldIds[SURFACE_NATIVE_PTR], PointerToJLong(surface)); // KNI_registerCleanup(objectHandle, disposeNativeImpl); } else { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } else { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } else { JNI_ThrowNew(env, "java/lang/IllegalStateException", ""); } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setStrokeImpl(JNIEnv* env, jobject objectHandle, jint lineWidth, jint capStyle, jint joinStyle, jint miterLimit, jintArray arrayHandle, jint dashPhase) { jint* dashArray = NULL; jint dashArray_length = 0; Renderer* rdr; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); if (arrayHandle != NULL) { jsize length = (*env)->GetArrayLength(env, arrayHandle); dashArray = (jint*)PISCESmalloc(length * sizeof(jint)); //NOTE : dashArray is freed at finalization time by renderer_dispose() if (NULL == dashArray) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of renderer memory for stroke data failed."); } else { (*env)->GetIntArrayRegion(env, arrayHandle, 0, length, dashArray); dashArray_length = length; } } renderer_setStroke6(rdr, lineWidth, capStyle, joinStyle, miterLimit, dashArray, dashArray_length, dashPhase); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } }
JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_setTextureImpl(JNIEnv* env, jobject objectHandle, jint imageType, jintArray arrayHandle, jint width, jint height, jint offset, jint stride, jobject transformHandle, jboolean repeat) { Renderer* rdr; jint* data; Transform6 textureTransform; rdr = (Renderer*)JLongToPointer( (*env)->GetLongField(env, objectHandle, fieldIds[RENDERER_NATIVE_PTR])); data = (jint*)PISCESmalloc((width + 2) * (height + 2) * sizeof(jint)); //NOTE : data is freed at finalization time by renderer_dispose() if (NULL == data) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of renderer memory for texture failed."); } else { jint size = width * sizeof(jint); jint dadd = width + 2; jint* dest = data + dadd; jint h2 = height; jint copyToFirstCol; jint copyToLastCol; jint copyToFirstRow; jint copyToLastRow; /* prepare additional pixels for interpolation */ if (repeat) { copyToFirstCol = width - 1; copyToLastCol = 0; copyToFirstRow = height - 1; copyToLastRow = 0; } else { copyToFirstCol = 0; copyToLastCol = width - 1; copyToFirstRow = 0; copyToLastRow = height - 1; } for (; h2 > 0; --h2) { (*env)->GetIntArrayRegion(env, arrayHandle, offset, width, dest + 1); dest[0] = dest[copyToFirstCol + 1]; dest[width + 1] = dest[copyToLastCol + 1]; dest += dadd; offset += stride; } memcpy(data, data + (copyToFirstRow + 1) * (width + 2), size + 2 * sizeof(jint)); memcpy(dest, data + (copyToLastRow + 1) * (width + 2), size + 2 * sizeof(jint)); transform_get6(&textureTransform, env, transformHandle); renderer_setTexture(rdr, data, width, height, repeat, &textureTransform); if (JNI_TRUE == readAndClearMemErrorFlag()) { JNI_ThrowNew(env, "java/lang/OutOfMemoryError", "Allocation of internal renderer buffer failed."); } } }
KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_pisces_AbstractSurface_getRGB() { KNI_StartHandles(2); KNI_DeclareHandle(objectHandle); KNI_DeclareHandle(arrayHandle); jint offset = KNI_GetParameterAsInt(2); jint scanLength = KNI_GetParameterAsInt(3); jint x = KNI_GetParameterAsInt(4); jint y = KNI_GetParameterAsInt(5); jint width = KNI_GetParameterAsInt(6); jint height = KNI_GetParameterAsInt(7); jint dstX = 0; jint dstY = 0; Surface* surface; KNI_GetParameterAsObject(1, arrayHandle); KNI_GetThisPointer(objectHandle); surface = (Surface*)JLongToPointer( KNI_GetLongField(objectHandle, fieldIds[SURFACE_NATIVE_PTR])); CORRECT_DIMS(surface, x, y, width, height, dstX, dstY); if ((width > 0) && (height > 0)) { jint size = ((height - 1) * scanLength + width) * sizeof(jint); jint* tempArray = (jint*)PISCESmalloc(size); if (NULL == tempArray) { KNI_ThrowNew("java/lang/OutOfMemoryError", "Allocation of temporary renderer memory buffer failed."); } else { jint* src; jint* dst; jint srcScanRest = surface->width - width; jint dstScanRest = scanLength - width; ACQUIRE_SURFACE(surface, objectHandle); src = (jint*)surface->data + y * surface->width + x; dst = tempArray; for (; height > 0; --height) { jint w2 = width; for (; w2 > 0; --w2) { *dst++ = *src++; } src += srcScanRest; dst += dstScanRest; } offset += dstY * scanLength + dstX; KNI_SetRawArrayRegion(arrayHandle, offset * sizeof(jint), size, (const jbyte*)tempArray); RELEASE_SURFACE(surface, objectHandle); PISCESfree(tempArray); } } KNI_EndHandles(); KNI_ReturnVoid(); }