]> gitweb.factorcode.org Git - factor.git/commitdiff
Abstract out images.memory from core-graphics vocab
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 27 Feb 2009 05:29:39 +0000 (23:29 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Fri, 27 Feb 2009 05:29:39 +0000 (23:29 -0600)
basis/core-graphics/core-graphics.factor
basis/images/memory/authors.txt [new file with mode: 0644]
basis/images/memory/memory.factor [new file with mode: 0644]

index bfc83861415481b79e011ef50a503f6848d31bc4..4a53f5a05cb88ee045d555d2996fe8601cac8d69 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.destructors alien.syntax accessors
 destructors fry kernel math math.bitwise sequences libc colors
-images core-graphics.types core-foundation.utilities ;
+images images.memory core-graphics.types core-foundation.utilities ;
 IN: core-graphics
 
 ! CGImageAlphaInfo
@@ -110,12 +110,6 @@ FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pnam
 : bitmap-flags ( -- flags )
     { kCGImageAlphaPremultipliedFirst kCGBitmapByteOrder32Host } flags ;
 
-: bitmap-size ( dim -- n )
-    product "uint" heap-size * ;
-
-: malloc-bitmap-data ( dim -- alien )
-    bitmap-size 1 calloc &free ;
-
 : bitmap-color-space ( -- color-space )
     CGColorSpaceCreateDeviceRGB &CGColorSpaceRelease ;
 
@@ -124,16 +118,6 @@ FUNCTION: CGLError CGLSetParameter ( CGLContextObj ctx, CGLContextParameter pnam
     bitmap-color-space bitmap-flags CGBitmapContextCreate
     [ "CGBitmapContextCreate failed" throw ] unless* ;
 
-: bitmap-data ( bitmap dim -- data )
-    [ CGBitmapContextGetData ] [ bitmap-size ] bi*
-    memory>byte-array ;
-
-: <bitmap-image> ( bitmap dim -- image )
-    <image>
-        swap >>dim
-        swap >>bitmap
-        little-endian? ARGB BGRA ? >>component-order ;
-
 PRIVATE>
 
 : dummy-context ( -- context )
@@ -142,7 +126,4 @@ PRIVATE>
     ] initialize-alien ;
 
 : make-bitmap-image ( dim quot -- image )
-    [
-        [ [ [ malloc-bitmap-data ] keep <CGBitmapContext> &CGContextRelease ] keep ] dip
-        [ nip call ] [ drop [ bitmap-data ] keep <bitmap-image> ] 3bi
-    ] with-destructors ; inline
+    '[ <CGBitmapContext> &CGContextRelease @ ] make-memory-bitmap ; inline
diff --git a/basis/images/memory/authors.txt b/basis/images/memory/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/images/memory/memory.factor b/basis/images/memory/memory.factor
new file mode 100644 (file)
index 0000000..6790239
--- /dev/null
@@ -0,0 +1,31 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors alien.c-types destructors fry images kernel
+libc math sequences ;
+IN: images.memory
+
+! Some code shared by core-graphics and cairo for constructing
+! images from off-screen graphics contexts. There is probably
+! no reason to call it directly.
+
+<PRIVATE
+
+: bitmap-size ( dim -- n ) product "uint" heap-size * ;
+
+: malloc-bitmap-data ( dim -- alien ) bitmap-size 1 calloc &free ;
+
+: bitmap-data ( alien dim -- data ) bitmap-size memory>byte-array ;
+
+: <bitmap-image> ( alien dim -- image )
+    [ bitmap-data ] keep
+    <image>
+        swap >>dim
+        swap >>bitmap
+        little-endian? ARGB BGRA ? >>component-order ;
+
+PRIVATE>
+
+: make-memory-bitmap ( dim quot -- image )
+    '[
+        [ malloc-bitmap-data ] keep _ [ <bitmap-image> ] 2bi
+    ] with-destructors ; inline
\ No newline at end of file