images.loader.cocoa: adding ability to save cocoa images to files.
parent
cf1b282ced
commit
140252f6f4
|
@ -1,9 +1,9 @@
|
||||||
! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
|
! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.data cocoa cocoa.classes cocoa.messages
|
USING: accessors cocoa cocoa.classes core-foundation
|
||||||
combinators core-foundation.data core-graphics
|
core-foundation.data core-foundation.urls core-graphics
|
||||||
core-graphics.types fry locals images images.loader io kernel
|
core-graphics.private core-graphics.types destructors
|
||||||
math sequences ;
|
images.loader io kernel locals math sequences ;
|
||||||
FROM: system => os macosx? ;
|
FROM: system => os macosx? ;
|
||||||
IN: images.loader.cocoa
|
IN: images.loader.cocoa
|
||||||
|
|
||||||
|
@ -33,5 +33,23 @@ os macosx? [
|
||||||
0 0 w h <CGRect> image CGContextDrawImage
|
0 0 w h <CGRect> image CGContextDrawImage
|
||||||
] make-bitmap-image ;
|
] make-bitmap-image ;
|
||||||
|
|
||||||
|
: image>CGImage ( image -- image )
|
||||||
|
[ bitmap>> ] [ dim>> first2 ] bi 8 pick 4 *
|
||||||
|
bitmap-color-space bitmap-flags
|
||||||
|
CGBitmapContextCreate -> autorelease
|
||||||
|
CGBitmapContextCreateImage ;
|
||||||
|
|
||||||
M: ns-image stream>image*
|
M: ns-image stream>image*
|
||||||
drop stream-contents <CGImage> CGImage>image ;
|
drop stream-contents <CGImage> CGImage>image ;
|
||||||
|
|
||||||
|
:: save-ns-image ( image path type -- )
|
||||||
|
[
|
||||||
|
path f <CFFileSystemURL> &CFRelease
|
||||||
|
type 1 f CGImageDestinationCreateWithURL &CFRelease
|
||||||
|
[
|
||||||
|
image image>CGImage &CFRelease
|
||||||
|
f CGImageDestinationAddImage
|
||||||
|
] [
|
||||||
|
CGImageDestinationFinalize drop
|
||||||
|
] bi
|
||||||
|
] with-destructors ;
|
||||||
|
|
Loading…
Reference in New Issue