46 |
46 |
47 static ColorData *BufImg_SetupICM(JNIEnv *env, BufImgSDOps *bisdo); |
47 static ColorData *BufImg_SetupICM(JNIEnv *env, BufImgSDOps *bisdo); |
48 |
48 |
49 static jfieldID rgbID; |
49 static jfieldID rgbID; |
50 static jfieldID mapSizeID; |
50 static jfieldID mapSizeID; |
51 static jfieldID CMpDataID; |
51 static jfieldID colorDataID; |
|
52 static jfieldID pDataID; |
52 static jfieldID allGrayID; |
53 static jfieldID allGrayID; |
53 |
54 |
|
55 static jclass clsICMCD; |
|
56 static jmethodID initICMCDmID; |
54 /* |
57 /* |
55 * Class: sun_awt_image_BufImgSurfaceData |
58 * Class: sun_awt_image_BufImgSurfaceData |
56 * Method: initIDs |
59 * Method: initIDs |
57 * Signature: ()V |
60 * Signature: ()V |
58 */ |
61 */ |
59 JNIEXPORT void JNICALL |
62 JNIEXPORT void JNICALL |
60 Java_sun_awt_image_BufImgSurfaceData_initIDs |
63 Java_sun_awt_image_BufImgSurfaceData_initIDs |
61 (JNIEnv *env, jclass bisd, jclass icm) |
64 (JNIEnv *env, jclass bisd, jclass icm, jclass cd) |
62 { |
65 { |
63 if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) { |
66 if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) { |
64 JNU_ThrowInternalError(env, "Private RasInfo structure too large!"); |
67 JNU_ThrowInternalError(env, "Private RasInfo structure too large!"); |
65 return; |
68 return; |
66 } |
69 } |
67 |
70 |
|
71 clsICMCD = (*env)->NewWeakGlobalRef(env, cd); |
|
72 initICMCDmID = (*env)->GetMethodID(env, cd, "<init>", "(J)V"); |
|
73 pDataID = (*env)->GetFieldID(env, cd, "pData", "J"); |
|
74 |
68 rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I"); |
75 rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I"); |
69 allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z"); |
76 allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z"); |
70 mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I"); |
77 mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I"); |
71 CMpDataID = (*env)->GetFieldID(env, icm, "pData", "J"); |
78 colorDataID = (*env)->GetFieldID(env, icm, "colorData", |
72 if (allGrayID == 0 || rgbID == 0 || mapSizeID == 0 || CMpDataID == 0) { |
79 "Lsun/awt/image/BufImgSurfaceData$ICMColorData;"); |
|
80 if (allGrayID == 0 || rgbID == 0 || mapSizeID == 0 || pDataID == 0|| colorDataID == 0 || initICMCDmID == 0) { |
73 JNU_ThrowInternalError(env, "Could not get field IDs"); |
81 JNU_ThrowInternalError(env, "Could not get field IDs"); |
74 } |
82 } |
75 } |
83 } |
76 |
84 |
77 /* |
85 /* |
79 * Method: freeNativeICMData |
87 * Method: freeNativeICMData |
80 * Signature: (Ljava/awt/image/IndexColorModel;)V |
88 * Signature: (Ljava/awt/image/IndexColorModel;)V |
81 */ |
89 */ |
82 JNIEXPORT void JNICALL |
90 JNIEXPORT void JNICALL |
83 Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData |
91 Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData |
84 (JNIEnv *env, jclass sd, jobject icm) |
92 (JNIEnv *env, jclass sd, jlong pData) |
85 { |
93 { |
86 jlong pData; |
94 ColorData *cdata = (ColorData*)jlong_to_ptr(pData); |
87 ColorData *cdata; |
|
88 |
|
89 if (JNU_IsNull(env, icm)) { |
|
90 JNU_ThrowNullPointerException(env, "IndexColorModel cannot be null"); |
|
91 return; |
|
92 } |
|
93 |
|
94 pData = (*env)->GetLongField (env, icm, CMpDataID); |
|
95 cdata = (ColorData *)pData; |
|
96 freeICMColorData(cdata); |
95 freeICMColorData(cdata); |
97 } |
96 } |
98 |
97 |
99 /* |
98 /* |
100 * Class: sun_awt_image_BufImgSurfaceData |
99 * Class: sun_awt_image_BufImgSurfaceData |
261 } |
260 } |
262 |
261 |
263 static ColorData *BufImg_SetupICM(JNIEnv *env, |
262 static ColorData *BufImg_SetupICM(JNIEnv *env, |
264 BufImgSDOps *bisdo) |
263 BufImgSDOps *bisdo) |
265 { |
264 { |
266 ColorData *cData; |
265 ColorData *cData = NULL; |
|
266 jobject colorData; |
267 |
267 |
268 if (JNU_IsNull(env, bisdo->icm)) { |
268 if (JNU_IsNull(env, bisdo->icm)) { |
269 return (ColorData *) NULL; |
269 return (ColorData *) NULL; |
270 } |
270 } |
271 |
271 |
272 cData = (ColorData *) JNU_GetLongFieldAsPtr(env, bisdo->icm, CMpDataID); |
272 colorData = (*env)->GetObjectField(env, bisdo->icm, colorDataID); |
273 |
273 |
274 if (cData == NULL) { |
274 if (JNU_IsNull(env, colorData)) { |
275 cData = (ColorData*)calloc(1, sizeof(ColorData)); |
275 if (JNU_IsNull(env, clsICMCD)) { |
276 |
276 // we are unable to create a wrapper object |
277 if (cData != NULL) { |
277 return (ColorData*)NULL; |
278 jboolean allGray |
|
279 = (*env)->GetBooleanField(env, bisdo->icm, allGrayID); |
|
280 int *pRgb = (int *) |
|
281 ((*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL)); |
|
282 cData->img_clr_tbl = initCubemap(pRgb, bisdo->lutsize, 32); |
|
283 if (allGray == JNI_TRUE) { |
|
284 initInverseGrayLut(pRgb, bisdo->lutsize, cData); |
|
285 } |
|
286 (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray, pRgb, |
|
287 JNI_ABORT); |
|
288 |
|
289 initDitherTables(cData); |
|
290 |
|
291 JNU_SetLongFieldFromPtr(env, bisdo->icm, CMpDataID, cData); |
|
292 } |
278 } |
|
279 } else { |
|
280 cData = (ColorData*)JNU_GetLongFieldAsPtr(env, colorData, pDataID); |
|
281 } |
|
282 |
|
283 if (cData != NULL) { |
|
284 return cData; |
|
285 } |
|
286 |
|
287 cData = (ColorData*)calloc(1, sizeof(ColorData)); |
|
288 |
|
289 if (cData != NULL) { |
|
290 jboolean allGray |
|
291 = (*env)->GetBooleanField(env, bisdo->icm, allGrayID); |
|
292 int *pRgb = (int *) |
|
293 ((*env)->GetPrimitiveArrayCritical(env, bisdo->lutarray, NULL)); |
|
294 cData->img_clr_tbl = initCubemap(pRgb, bisdo->lutsize, 32); |
|
295 if (allGray == JNI_TRUE) { |
|
296 initInverseGrayLut(pRgb, bisdo->lutsize, cData); |
|
297 } |
|
298 (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray, pRgb, |
|
299 JNI_ABORT); |
|
300 |
|
301 initDitherTables(cData); |
|
302 |
|
303 if (JNU_IsNull(env, colorData)) { |
|
304 jlong pData = ptr_to_jlong(cData); |
|
305 colorData = (*env)->NewObjectA(env, clsICMCD, initICMCDmID, (jvalue *)&pData); |
|
306 (*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData); |
|
307 } |
293 } |
308 } |
294 |
309 |
295 return cData; |
310 return cData; |
296 } |
311 } |