2010-06-27 15:29:21 -04:00
|
|
|
! (c)2010 Joe Groff bsd license
|
|
|
|
USING: accessors alien.data cocoa cocoa.classes cocoa.messages
|
|
|
|
combinators core-foundation.data core-graphics.types fry images
|
2011-09-02 01:29:14 -04:00
|
|
|
images.loader io kernel math sequences ;
|
2010-06-27 15:29:21 -04:00
|
|
|
IN: images.cocoa
|
|
|
|
|
|
|
|
SINGLETON: ns-image
|
2010-06-27 16:31:07 -04:00
|
|
|
"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
|
2010-06-27 15:29:21 -04:00
|
|
|
|
|
|
|
CONSTANT: NSImageRepLoadStatusUnknownType -1
|
|
|
|
CONSTANT: NSImageRepLoadStatusReadingHeader -2
|
|
|
|
CONSTANT: NSImageRepLoadStatusWillNeedAllData -3
|
|
|
|
CONSTANT: NSImageRepLoadStatusInvalidData -4
|
|
|
|
CONSTANT: NSImageRepLoadStatusUnexpectedEOF -5
|
|
|
|
CONSTANT: NSImageRepLoadStatusCompleted -6
|
|
|
|
|
|
|
|
CONSTANT: NSColorRenderingIntentDefault 0
|
|
|
|
CONSTANT: NSColorRenderingIntentAbsoluteColorimetric 1
|
|
|
|
CONSTANT: NSColorRenderingIntentRelativeColorimetric 2
|
|
|
|
CONSTANT: NSColorRenderingIntentPerceptual 3
|
|
|
|
CONSTANT: NSColorRenderingIntentSaturation 4
|
|
|
|
|
|
|
|
ERROR: ns-image-unknown-type ;
|
|
|
|
ERROR: ns-image-invalid-data ;
|
|
|
|
ERROR: ns-image-unexpected-eof ;
|
|
|
|
ERROR: ns-image-planar-images-not-supported ;
|
|
|
|
|
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: check-return ( n -- )
|
|
|
|
{
|
2011-09-02 01:29:14 -04:00
|
|
|
{ NSImageRepLoadStatusUnknownType [ ns-image-unknown-type ] }
|
|
|
|
{ NSImageRepLoadStatusInvalidData [ ns-image-invalid-data ] }
|
|
|
|
{ NSImageRepLoadStatusUnexpectedEOF [ ns-image-unexpected-eof ] }
|
2010-06-27 15:29:21 -04:00
|
|
|
[ drop ]
|
|
|
|
} case ;
|
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: load-image-rep ( -- image-rep )
|
|
|
|
NSBitmapImageRep contents <CFData> -> autorelease -> imageRepWithData:
|
|
|
|
NSColorSpace -> genericRGBColorSpace
|
|
|
|
NSColorRenderingIntentDefault
|
|
|
|
-> bitmapImageRepByConvertingToColorSpace:renderingIntent: ;
|
|
|
|
|
|
|
|
: image-rep>image ( image-rep -- image )
|
|
|
|
image new swap {
|
2010-06-27 16:44:16 -04:00
|
|
|
[ -> size CGSize>dim [ >integer ] map >>dim ]
|
2010-06-27 15:29:21 -04:00
|
|
|
[ -> bitmapData ]
|
|
|
|
[ -> bytesPerPlane memory>byte-array >>bitmap ]
|
|
|
|
} cleave
|
|
|
|
RGBA >>component-order
|
|
|
|
ubyte-components >>component-type
|
2010-06-27 16:44:16 -04:00
|
|
|
t >>premultiplied-alpha?
|
2010-06-27 15:29:21 -04:00
|
|
|
f >>upside-down? ;
|
|
|
|
|
|
|
|
M: ns-image stream>image
|
2010-06-27 16:31:07 -04:00
|
|
|
drop
|
|
|
|
[ load-image-rep ] with-input-stream image-rep>image ;
|