2011-09-02 21:59:58 -04:00
|
|
|
! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-06-27 15:29:21 -04:00
|
|
|
USING: accessors alien.data cocoa cocoa.classes cocoa.messages
|
2011-09-02 21:59:58 -04:00
|
|
|
combinators core-foundation.data core-graphics
|
|
|
|
core-graphics.types fry locals images images.loader io kernel
|
|
|
|
math sequences ;
|
2011-09-24 22:19:34 -04:00
|
|
|
FROM: system => os macosx? ;
|
2010-06-27 15:29:21 -04:00
|
|
|
IN: images.cocoa
|
|
|
|
|
|
|
|
SINGLETON: ns-image
|
2011-09-24 22:19:34 -04:00
|
|
|
|
|
|
|
os macosx? [
|
|
|
|
"png" ns-image register-image-class
|
|
|
|
"tif" ns-image register-image-class
|
|
|
|
"tiff" ns-image register-image-class
|
|
|
|
"gif" ns-image register-image-class
|
|
|
|
"jpg" ns-image register-image-class
|
|
|
|
"jpeg" ns-image register-image-class
|
|
|
|
"bmp" ns-image register-image-class
|
|
|
|
"ico" ns-image register-image-class
|
|
|
|
] when
|
2010-06-27 15:29:21 -04:00
|
|
|
|
2011-09-02 21:59:58 -04:00
|
|
|
: <CGImage> ( byte-array -- image-rep )
|
|
|
|
[ NSBitmapImageRep ] dip
|
|
|
|
<CFData> -> autorelease
|
|
|
|
-> imageRepWithData:
|
|
|
|
-> CGImage ;
|
2010-06-27 15:29:21 -04:00
|
|
|
|
2011-09-02 21:59:58 -04:00
|
|
|
:: CGImage>image ( image -- image )
|
|
|
|
image CGImageGetWidth :> w
|
|
|
|
image CGImageGetHeight :> h
|
|
|
|
{ w h } [
|
|
|
|
0 0 w h <CGRect> image CGContextDrawImage
|
2011-09-09 02:08:16 -04:00
|
|
|
] make-bitmap-image ;
|
2010-06-27 15:29:21 -04:00
|
|
|
|
|
|
|
M: ns-image stream>image
|
2011-09-02 21:59:58 -04:00
|
|
|
drop stream-contents <CGImage> CGImage>image ;
|