jdk/src/macosx/native/sun/awt/CImage.m
changeset 23652 11515e3c3f85
parent 23651 e41298d0da2f
child 24137 b4066d0e2bca
equal deleted inserted replaced
23651:e41298d0da2f 23652:11515e3c3f85
   110 (JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
   110 (JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
   111 {
   111 {
   112     jlong result = 0L;
   112     jlong result = 0L;
   113 
   113 
   114 JNF_COCOA_ENTER(env);
   114 JNF_COCOA_ENTER(env);
   115 
   115     
   116     NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
   116     NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
   117     if (imageRep) {
   117     if (imageRep) {
   118         NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain];
   118         NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(width, height)] retain];
   119         [nsImage addRepresentation:imageRep];
   119         [nsImage addRepresentation:imageRep];
   120         [imageRep release];
   120         [imageRep release];
   420 
   420 
   421 JNF_COCOA_EXIT(env);
   421 JNF_COCOA_EXIT(env);
   422 
   422 
   423     return jreturnArray;
   423     return jreturnArray;
   424 }
   424 }
       
   425 
       
   426 /*
       
   427  * Class:     sun_lwawt_macosx_CImage
       
   428  * Method:    nativeGetPlatformImageBytes
       
   429  * Signature: ([III)[B
       
   430  */
       
   431 JNIEXPORT jbyteArray JNICALL Java_sun_lwawt_macosx_CImage_nativeGetPlatformImageBytes
       
   432 (JNIEnv *env, jclass klass, jintArray buffer, jint width, jint height)
       
   433 {
       
   434     jbyteArray result = 0L;
       
   435 
       
   436     JNF_COCOA_ENTER(env);
       
   437 
       
   438     NSBitmapImageRep* imageRep = [CImage_CreateImageRep(env, buffer, width, height) autorelease];
       
   439     if (imageRep) {
       
   440         NSData *tiffImage = [imageRep TIFFRepresentation];
       
   441         jsize tiffSize = (jsize)[tiffImage length];
       
   442         result = (*env)->NewByteArray(env, tiffSize);
       
   443         CHECK_NULL_RETURN(result, nil);
       
   444         jbyte *tiffData = (jbyte *)(*env)->GetPrimitiveArrayCritical(env, result, 0);
       
   445         CHECK_NULL_RETURN(tiffData, nil);
       
   446         [tiffImage getBytes:tiffData];
       
   447         (*env)->ReleasePrimitiveArrayCritical(env, result, tiffData, 0);
       
   448     }
       
   449 
       
   450     JNF_COCOA_EXIT(env);
       
   451 
       
   452     return result;
       
   453 }
       
   454 
       
   455 /*
       
   456  * Class:     sun_lwawt_macosx_CImage
       
   457  * Method:    nativeCreateNSImageFromBytes
       
   458  * Signature: ([B)J
       
   459  */
       
   460 JNIEXPORT jlong JNICALL Java_sun_lwawt_macosx_CImage_nativeCreateNSImageFromBytes
       
   461 (JNIEnv *env, jclass klass, jbyteArray sourceData)
       
   462 {
       
   463     jlong result = 0L;
       
   464     CHECK_NULL_RETURN(sourceData, 0L);
       
   465 
       
   466     JNF_COCOA_ENTER(env);
       
   467 
       
   468     jsize sourceSize = (*env)->GetArrayLength(env, sourceData);
       
   469     if (sourceSize == 0) return 0L;
       
   470 
       
   471     jbyte *sourceBytes = (*env)->GetPrimitiveArrayCritical(env, sourceData, NULL);
       
   472     CHECK_NULL_RETURN(sourceBytes, 0L);
       
   473     NSData *rawData = [NSData dataWithBytes:sourceBytes length:sourceSize];
       
   474     NSImage *newImage = [[NSImage alloc] initWithData:rawData];
       
   475 
       
   476     (*env)->ReleasePrimitiveArrayCritical(env, sourceData, sourceBytes, JNI_ABORT);
       
   477     CHECK_NULL_RETURN(newImage, 0L);
       
   478 
       
   479     result = ptr_to_jlong(newImage);
       
   480     JNF_COCOA_EXIT(env);
       
   481 
       
   482     return result;
       
   483 }