|(require images/compile-time)||package: images-lib|
Producing computed bitmaps can take time. To reduce the startup time of programs that use computed bitmaps, use the macros exported by images/compile-time to compile them: to embed the computed bitmaps in fully expanded, compiled modules.
This is a form of constant folding, or equivalently a form of safe “3D” values. The macros defined here compute bitmaps at expansion time, and expand to the bitmap’s bytes and a simple wrapper that converts bytes to a bitmap%. Thus, fully expanded, compiled modules contain (more or less) literal bitmap values, which do not need to be computed again when the module is required by another.
To get the most from compiled bitmaps during development, it is best to put them in files that are changed infrequently. For example, for games, we suggest having a separate module called something like images.rkt or resources.rkt that provides all the game’s images.
If quality is 100, the bitmap is stored as a PNG. If quality is between 0 and 99 inclusive, it is stored as a JPEG with quality quality. (See save-file.) If the bitmap has an alpha channel, its alpha channel is stored as a separate JPEG. The default value is 100.
#lang racket (require images/compile-time (for-syntax images/logos)) (define the-logo (compiled-bitmap (plt-logo #:height 384)))
(compiled-bitmap-list expr [quality])
expr : (listof (is-a?/c bitmap%))
quality : (integer-in 0 100)
(require images/compile-time (for-syntax images/icons/stickman)) (begin-for-syntax (define num-stickman-frames 12)) (define running-stickman-frames (compiled-bitmap-list (for/list ([t (in-range 0 1 (/ 1 num-stickman-frames))]) (running-stickman-icon t #:height 32 #:body-color "red" #:arm-color "white" #:head-color "red")) 50))