<commit_before>! Copyright (C) 2008 <NAME>, <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays byte-arrays kernel math namespaces
opengl.gl sequences math.vectors ui images images.normalization
images.viewer models ui.gadgets.worlds ui.gadgets fry alien.syntax ;
IN: cap

: screenshot-array ( world -- byte-array )
    dim>> [ first 4 * ] [ second ] bi * <byte-array> ;

: gl-screenshot ( gadget -- byte-array )
    [
        [
            GL_BACK glReadBuffer
            GL_PACK_ALIGNMENT 4 glPixelStorei
            0 0
        ] dip
        dim>> first2 GL_RGBA GL_UNSIGNED_BYTE
    ]
    [ screenshot-array ] bi
    [ glReadPixels ] keep ;

: screenshot ( window -- bitmap )
    [ <image> ] dip
    [ gl-screenshot >>bitmap ] [ dim>> >>dim ] bi
    ubyte-components >>component-type
    RGBA >>component-order<commit_msg>cap: make screenshots work on retina.<commit_after>! Copyright (C) 2008 <NAME>, <NAME>.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.syntax arrays byte-arrays fry images
images.normalization images.viewer kernel math math.vectors
models namespaces opengl opengl.gl sequences ui ui.gadgets
ui.gadgets.worlds ;
IN: cap

: screenshot-array ( world -- byte-array )
    dim>> [ first 4 * ] [ second ] bi
    [ gl-scale ] bi@ * >fixnum <byte-array> ;

: gl-screenshot ( gadget -- byte-array )
    [
        [
            GL_BACK glReadBuffer
            GL_PACK_ALIGNMENT 4 glPixelStorei
            0 0
        ] dip
        dim>> first2 [ gl-scale >fixnum ] bi@
        GL_RGBA GL_UNSIGNED_BYTE
    ]
    [ screenshot-array ] bi
    [ glReadPixels ] keep ;

: screenshot ( window -- bitmap )
    [ <image> t >>2x? ] dip
    [ gl-screenshot >>bitmap ]
    [ dim>> [ gl-scale >fixnum ] map >>dim ] bi
    ubyte-components >>component-type
    RGBA >>component-order
{'fraction_non_alphanumeric': 0.11463939720129171, 'fraction_numerical': 0.01022604951560818, 'mean_word_length': 2.5477099236641223, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2444185', 'n_tokens_mistral': 624, 'n_tokens_neox': 597, 'n_words': 164}