]> gitweb.factorcode.org Git - factor.git/blob - basis/images/memory/memory.factor
factor: trim using lists
[factor.git] / basis / images / memory / memory.factor
1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.data destructors images
4 kernel libc math sequences ;
5 IN: images.memory
6
7 ! Some code shared by core-graphics and cairo for constructing
8 ! images from off-screen graphics contexts. There is probably
9 ! no reason to call it directly.
10
11 <PRIVATE
12
13 : bitmap-size ( dim -- n ) product uint heap-size * ;
14
15 : malloc-bitmap-data ( dim -- alien ) bitmap-size 1 calloc &free ;
16
17 : bitmap-data ( alien dim -- data ) bitmap-size memory>byte-array ;
18
19 : <bitmap-image> ( alien dim -- image )
20     [ bitmap-data ] keep
21     <image>
22         swap >>dim
23         swap >>bitmap ;
24
25 PRIVATE>
26
27 : make-memory-bitmap ( dim quot -- image )
28     '[
29         [ malloc-bitmap-data ] keep _ [ <bitmap-image> ] 2bi
30     ] with-destructors ; inline