jdk/src/macosx/native/sun/awt/CImage.m
changeset 24554 55edf9459457
parent 24137 b4066d0e2bca
equal deleted inserted replaced
24553:6c9c0f5b07e0 24554:55edf9459457
    74     [oldContext release];
    74     [oldContext release];
    75 }
    75 }
    76 
    76 
    77 static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height)
    77 static NSBitmapImageRep* CImage_CreateImageRep(JNIEnv *env, jintArray buffer, jint width, jint height)
    78 {
    78 {
    79     NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
    79     NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
    80                                                                          pixelsWide:width
    80                                                                           pixelsWide:width
    81                                                                          pixelsHigh:height
    81                                                                           pixelsHigh:height
    82                                                                       bitsPerSample:8
    82                                                                        bitsPerSample:8
    83                                                                     samplesPerPixel:4
    83                                                                      samplesPerPixel:4
    84                                                                            hasAlpha:YES
    84                                                                             hasAlpha:YES
    85                                                                            isPlanar:NO
    85                                                                             isPlanar:NO
    86                                                                      colorSpaceName:NSDeviceRGBColorSpace
    86                                                                       colorSpaceName:NSDeviceRGBColorSpace
    87                                                                        bitmapFormat:NSAlphaFirstBitmapFormat
    87                                                                         bitmapFormat:NSAlphaFirstBitmapFormat
    88                                                                         bytesPerRow:width*4 // TODO: use explicit scanStride
    88                                                                          bytesPerRow:width*4 // TODO: use explicit scanStride
    89                                                                        bitsPerPixel:32];
    89                                                                         bitsPerPixel:32] autorelease];
    90 
    90 
    91     jint *imgData = (jint *)[imageRep bitmapData];
    91     jint *imgData = (jint *)[imageRep bitmapData];
    92     if (imgData == NULL) return 0L;
    92     if (imgData == NULL) return 0L;
    93 
    93 
    94     jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
    94     jint *src = (*env)->GetPrimitiveArrayCritical(env, buffer, NULL);
   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)];
   119         [nsImage addRepresentation:imageRep];
   119         [nsImage addRepresentation:imageRep];
   120         [imageRep release];
       
   121         result = ptr_to_jlong(nsImage);
   120         result = ptr_to_jlong(nsImage);
   122     }
   121     }
   123 
   122 
   124 JNF_COCOA_EXIT(env);
   123 JNF_COCOA_EXIT(env);
   125 
   124 
   158             (*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT);
   157             (*env)->ReleaseIntArrayElements(env, heights, hs, JNI_ABORT);
   159         }
   158         }
   160         (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
   159         (*env)->ReleaseIntArrayElements(env, widths, ws, JNI_ABORT);
   161     }
   160     }
   162     if ([reps count]) {
   161     if ([reps count]) {
   163         NSImage *nsImage = [[[NSImage alloc] initWithSize:NSMakeSize(0, 0)] retain];
   162         NSImage *nsImage = [[NSImage alloc] initWithSize:NSMakeSize(0, 0)];
   164         [nsImage addRepresentations: reps];
   163         [nsImage addRepresentations: reps];
   165         result = ptr_to_jlong(nsImage);
   164         result = ptr_to_jlong(nsImage);
   166     }
   165     }
   167 
   166 
   168 JNF_COCOA_EXIT(env);
   167 JNF_COCOA_EXIT(env);
   182 
   181 
   183 JNF_COCOA_ENTER(env);
   182 JNF_COCOA_ENTER(env);
   184 
   183 
   185     IconRef iconRef;
   184     IconRef iconRef;
   186     if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
   185     if (noErr == GetIconRef(kOnSystemDisk, kSystemIconsCreator, selector, &iconRef)) {
   187         image = [[[NSImage alloc] initWithIconRef:iconRef] retain];
   186         image = [[NSImage alloc] initWithIconRef:iconRef];
   188         ReleaseIconRef(iconRef);
   187         ReleaseIconRef(iconRef);
   189     }
   188     }
   190 
   189 
   191 JNF_COCOA_EXIT(env);
   190 JNF_COCOA_EXIT(env);
   192 
   191 
   204     NSImage *image = nil;
   203     NSImage *image = nil;
   205 
   204 
   206 JNF_COCOA_ENTER(env);
   205 JNF_COCOA_ENTER(env);
   207 
   206 
   208     NSString *path = JNFNormalizedNSStringForPath(env, file);
   207     NSString *path = JNFNormalizedNSStringForPath(env, file);
   209     image = [[[NSImage alloc] initByReferencingFile:path] retain];
   208     image = [[NSImage alloc] initByReferencingFile:path];
   210 
   209 
   211 JNF_COCOA_EXIT(env);
   210 JNF_COCOA_EXIT(env);
   212 
   211 
   213     return ptr_to_jlong(image);
   212     return ptr_to_jlong(image);
   214 }
   213 }
   433 {
   432 {
   434     jbyteArray result = 0L;
   433     jbyteArray result = 0L;
   435 
   434 
   436     JNF_COCOA_ENTER(env);
   435     JNF_COCOA_ENTER(env);
   437 
   436 
   438     NSBitmapImageRep* imageRep = [CImage_CreateImageRep(env, buffer, width, height) autorelease];
   437     NSBitmapImageRep* imageRep = CImage_CreateImageRep(env, buffer, width, height);
   439     if (imageRep) {
   438     if (imageRep) {
   440         NSData *tiffImage = [imageRep TIFFRepresentation];
   439         NSData *tiffImage = [imageRep TIFFRepresentation];
   441         jsize tiffSize = (jsize)[tiffImage length];
   440         jsize tiffSize = (jsize)[tiffImage length];
   442         result = (*env)->NewByteArray(env, tiffSize);
   441         result = (*env)->NewByteArray(env, tiffSize);
   443         CHECK_NULL_RETURN(result, nil);
   442         CHECK_NULL_RETURN(result, nil);