cocoa: avoid 10.6-specific NSImage method
This commit is contained in:
parent
16b34c236a
commit
cdecd36359
|
@ -6,17 +6,20 @@
|
||||||
"utils.rkt"
|
"utils.rkt"
|
||||||
"types.rkt"
|
"types.rkt"
|
||||||
"const.rkt"
|
"const.rkt"
|
||||||
|
"cg.rkt"
|
||||||
"../../lock.rkt"
|
"../../lock.rkt"
|
||||||
(only-in '#%foreign ffi-callback))
|
(only-in '#%foreign ffi-callback))
|
||||||
|
|
||||||
(provide bitmap->image)
|
(provide bitmap->image)
|
||||||
|
|
||||||
(import-class NSImage)
|
(import-class NSImage NSGraphicsContext)
|
||||||
|
|
||||||
(define _CGImageRef (_cpointer 'CGImageRef))
|
(define _CGImageRef (_cpointer 'CGImageRef))
|
||||||
(define _CGColorSpaceRef (_cpointer 'CGColorSpaceRef))
|
(define _CGColorSpaceRef (_cpointer 'CGColorSpaceRef))
|
||||||
(define _CGDataProviderRef (_cpointer 'GCDataProviderRef))
|
(define _CGDataProviderRef (_cpointer 'GCDataProviderRef))
|
||||||
|
|
||||||
|
(define _CGRect _NSRect)
|
||||||
|
|
||||||
(define _size_t _long)
|
(define _size_t _long)
|
||||||
(define _off_t _long)
|
(define _off_t _long)
|
||||||
|
|
||||||
|
@ -36,6 +39,8 @@
|
||||||
_int ; intent
|
_int ; intent
|
||||||
-> _CGImageRef))
|
-> _CGImageRef))
|
||||||
|
|
||||||
|
(define-appserv CGContextDrawImage (_fun _CGContextRef _CGRect _CGImageRef -> _void))
|
||||||
|
|
||||||
(define free-it
|
(define free-it
|
||||||
(ffi-callback free (list _pointer) _void #f #t))
|
(ffi-callback free (list _pointer) _void #f #t))
|
||||||
|
|
||||||
|
@ -79,7 +84,22 @@
|
||||||
0)])
|
0)])
|
||||||
(CGDataProviderRelease provider)
|
(CGDataProviderRelease provider)
|
||||||
(CGColorSpaceRelease cs)
|
(CGColorSpaceRelease cs)
|
||||||
|
;; This works on 10.6 and later:
|
||||||
|
#;
|
||||||
(as-objc-allocation
|
(as-objc-allocation
|
||||||
(tell (tell NSImage alloc)
|
(tell (tell NSImage alloc)
|
||||||
initWithCGImage: #:type _CGImageRef image
|
initWithCGImage: #:type _CGImageRef image
|
||||||
size: #:type _NSSize (make-NSSize w h))))))))
|
size: #:type _NSSize (make-NSSize w h)))
|
||||||
|
;; To work with older versions:
|
||||||
|
(let* ([size (make-NSSize w h)]
|
||||||
|
[i (as-objc-allocation
|
||||||
|
(tell (tell NSImage alloc)
|
||||||
|
initWithSize: #:type _NSSize size))])
|
||||||
|
(tellv i lockFocus)
|
||||||
|
(CGContextDrawImage
|
||||||
|
(tell #:type _CGContextRef (tell NSGraphicsContext currentContext) graphicsPort)
|
||||||
|
(make-NSRect (make-NSPoint 0 0) size)
|
||||||
|
image)
|
||||||
|
(tellv i unlockFocus)
|
||||||
|
i))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user