]> gitweb.factorcode.org Git - factor.git/blob - extra/cap/cap.factor
functors: inline the parts of interpolate this needs
[factor.git] / extra / cap / cap.factor
1 ! Copyright (C) 2008 Doug Coleman, Joe Groff.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors byte-arrays images images.normalization
4 images.viewer kernel math namespaces opengl opengl.gl
5 sequences ui ui.gadgets.worlds ;
6 IN: cap
7
8 <PRIVATE
9
10 : screenshot-array ( world -- byte-array )
11     dim>> [ first 4 * ] [ second ] bi
12     [ gl-scale ] bi@ * >fixnum <byte-array> ;
13
14 : gl-screenshot ( gadget -- byte-array )
15     [ find-gl-context ]
16     [
17         [
18             GL_BACK glReadBuffer
19             GL_PACK_ALIGNMENT 4 glPixelStorei
20             0 0
21         ] dip
22         dim>> first2 [ gl-scale >fixnum ] bi@
23         GL_RGBA GL_UNSIGNED_BYTE
24     ]
25     [ screenshot-array ] tri
26     [ glReadPixels ] keep ;
27
28 PRIVATE>
29
30 :: screenshot ( window -- bitmap )
31     <image>
32         gl-scale-factor get-global [ 2.0 = >>2x? ] when*
33         window gl-screenshot >>bitmap
34         window dim>> [ gl-scale >fixnum ] map >>dim
35         ubyte-components >>component-type
36         RGBA >>component-order
37         t >>upside-down?
38     normalize-image ;
39
40 : screenshot. ( window -- )
41     [ screenshot <image-gadget> ] [ title>> ] bi open-window ;