factor/extra/cap/cap.factor

43 lines
1.1 KiB
Factor
Raw Normal View History

2008-11-01 16:48:35 -04:00
! Copyright (C) 2008 Doug Coleman, Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors byte-arrays images images.normalization
images.viewer kernel math namespaces opengl opengl.gl sequences
ui ui.backend ui.gadgets.worlds ;
2008-10-30 19:16:03 -04:00
IN: cap
<PRIVATE
2008-10-30 19:16:03 -04:00
: screenshot-array ( world -- byte-array )
2012-11-01 19:30:20 -04:00
dim>> [ first 4 * ] [ second ] bi
[ gl-scale ] bi@ * >fixnum <byte-array> ;
2008-10-30 19:16:03 -04:00
: gl-screenshot ( gadget -- byte-array )
[ find-world handle>> select-gl-context ]
2008-10-30 19:16:03 -04:00
[
[
GL_BACK glReadBuffer
GL_PACK_ALIGNMENT 4 glPixelStorei
0 0
] dip
2012-11-01 19:30:20 -04:00
dim>> first2 [ gl-scale >fixnum ] bi@
GL_RGBA GL_UNSIGNED_BYTE
]
[ screenshot-array ] tri
2008-10-30 19:16:03 -04:00
[ glReadPixels ] keep ;
PRIVATE>
2008-10-30 19:16:03 -04:00
: screenshot ( window -- bitmap )
[ <image>
gl-scale-factor get-global [ 2.0 = >>2x? ] when*
] dip
2012-11-01 19:30:20 -04:00
[ gl-screenshot >>bitmap ]
[ dim>> [ gl-scale >fixnum ] map >>dim ] bi
ubyte-components >>component-type
RGBA >>component-order
t >>upside-down?
normalize-image ;
2008-10-30 19:16:03 -04:00
: screenshot. ( window -- )
[ screenshot <image-gadget> ] [ title>> ] bi open-window ;