]> gitweb.factorcode.org Git - factor.git/commitdiff
images.cocoa: fix it to work on OS X 10.5 by drawing the image into a CGContext inste...
authorSlava Pestov <slava@factorcode.org>
Sat, 3 Sep 2011 01:59:58 +0000 (18:59 -0700)
committerSlava Pestov <slava@factorcode.org>
Sat, 3 Sep 2011 01:59:58 +0000 (18:59 -0700)
basis/core-graphics/core-graphics.factor
basis/core-graphics/types/types.factor
basis/images/cocoa/cocoa.factor

index 8463bf145ff2f6db508bf7c5b17173cc1c992798..45a6ddc72b41e6636bfbc8ee53feb2a842e9e496 100644 (file)
@@ -99,6 +99,20 @@ FUNCTION: void CGContextSetShouldSmoothFonts (
    bool shouldSmoothFonts
 ) ;
 
+FUNCTION: void CGContextDrawImage (
+   CGContextRef c,
+   CGRect rect,
+   CGImageRef image
+) ;
+
+FUNCTION: size_t CGImageGetWidth (
+   CGImageRef image
+) ;
+
+FUNCTION: size_t CGImageGetHeight (
+   CGImageRef image
+) ;
+
 FUNCTION: void* CGBitmapContextGetData ( CGContextRef c ) ;
 
 CONSTANT: kCGLRendererGenericFloatID HEX: 00020400
index ac0ba31270525e829cf8b6dcc9d18d49fe377d8e..d6df20de90aa37835ac0c27833efc44ea714f927 100644 (file)
@@ -76,6 +76,8 @@ STRUCT: CGAffineTransform
 TYPEDEF: void* CGColorRef
 TYPEDEF: void* CGColorSpaceRef
 TYPEDEF: void* CGContextRef
+TYPEDEF: void* CGImageRef
+
 TYPEDEF: uint CGBitmapInfo
 
 TYPEDEF: int CGLError
index 6d4b97da1f4d13a99fc835a7d3bb95307748f905..a308d3f47531c7a74080420a5711cc9199f6aae2 100644 (file)
@@ -1,7 +1,9 @@
-! (c)2010 Joe Groff bsd license
+! Copyright (C) 2010, 2011 Joe Groff, Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien.data cocoa cocoa.classes cocoa.messages
-combinators core-foundation.data core-graphics.types fry images
-images.loader io kernel math sequences ;
+combinators core-foundation.data core-graphics
+core-graphics.types fry locals images images.loader io kernel
+math sequences ;
 IN: images.cocoa
 
 SINGLETON: ns-image
@@ -44,23 +46,18 @@ ERROR: ns-image-planar-images-not-supported ;
 
 PRIVATE>
 
-: load-image-rep ( -- image-rep )
-    NSBitmapImageRep contents <CFData> -> autorelease -> imageRepWithData:
-    NSColorSpace -> genericRGBColorSpace
-    NSColorRenderingIntentDefault
-    -> bitmapImageRepByConvertingToColorSpace:renderingIntent: ;
+: <CGImage> ( byte-array -- image-rep )
+    [ NSBitmapImageRep ] dip
+    <CFData> -> autorelease
+    -> imageRepWithData:
+    -> CGImage ;
 
-: image-rep>image ( image-rep -- image )
-    image new swap {
-        [ -> size CGSize>dim [ >integer ] map >>dim ]
-        [ -> bitmapData ]
-        [ -> bytesPerPlane memory>byte-array >>bitmap ]
-    } cleave
-        RGBA >>component-order
-        ubyte-components >>component-type
-        t >>premultiplied-alpha?
-        f >>upside-down? ;
+:: CGImage>image ( image -- image )
+    image CGImageGetWidth :> w
+    image CGImageGetHeight :> h
+    { w h } [
+        0 0 w h <CGRect> image CGContextDrawImage
+    ] make-bitmap-image ;
 
 M: ns-image stream>image
-    drop
-    [ load-image-rep ] with-input-stream image-rep>image ;
+    drop stream-contents <CGImage> CGImage>image ;