<commit_before>USING: accessors arrays byte-arrays kernel math namespaces
opengl.gl sequences math.vectors ui graphics.bitmap graphics.viewer
models opengl.framebuffers ui.gadgets.worlds ui.gadgets fry ;
IN: cap

: screenshot-array ( world -- byte-array )
    dim>> product 3 * <byte-array> ;

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

: screenshot ( window -- bitmap )
    [ gl-screenshot ]
    [ dim>> first2 ] bi
    bgr>bitmap ;

: save-screenshot ( window path -- )
    [ screenshot ] dip save-bitmap ;

: screenshot. ( window -- )
    [ screenshot <graphics-gadget> ] [ title>> ] bi open-window ;


<commit_msg>fix potential garbled output<commit_after>! 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 graphics.bitmap graphics.viewer
models opengl.framebuffers ui.gadgets.worlds ui.gadgets fry alien.syntax ;
IN: cap

: screenshot-array ( world -- byte-array )
    dim>> product 3 * <byte-array> ;

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

: screenshot ( window -- bitmap )
    [ gl-screenshot ]
    [ dim>> first2 ] bi
    bgr>bitmap ;

: save-screenshot ( window path -- )
    [ screenshot ] dip save-bitmap ;

: screenshot. ( window -- )
    [ screenshot <graphics-gadget> ] [ title>> ] bi open-window ; 
{'fraction_non_alphanumeric': 0.11174458380843785, 'fraction_numerical': 0.009122006841505131, 'mean_word_length': 2.823529411764706, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '5132576', 'n_tokens_mistral': 599, 'n_tokens_neox': 578, 'n_words': 149}