Next: , Up: Working with external data


2.2.1 Loading and processing images

In order to be able to use the procedures documented here, one shall (use-modules (slayer image)). The module provides a symbol slayer-image to use with cond-expand (srfi-0).

— Procedure: load-image path

Loads an image from an external file, indicated by path. The supported file formats depend on the way the SDL_image library was compiled. The procedure returns an object that represents the image internally, and can be used with draw-image! and other procedures. FIXME: if something goes wrong (i.e. the file doesn't exist), the application will probably crash.

— Procedure: draw-image! image [x] [y] [target]

Display image on the target (which is the screen by default). Its top left corner will be located at (x, y), which default to (0, 0).

— Procedure: rectangle w h color

Generates and returns solid rectangle whose width is w, height h and color is color. color is a 32-bit integer value, which can be written as #xAARRGGBB, where AA means alpha channel, RR is red component, GG – green component, and BB – blue component.

— Procedure: image-size image

Returns (width height) of the image.

— Procedure: image->array image

Converts image to two-dimensional uniform array of integers.

— Procedure: array->image array

Converts two-dimensional uniform array of integers to image.

— Procedure: crop-image image x y [w] [h]

Return a newly allocated image that contains the part of image with upper left corner at (x, y). If given and positive, w and h designate the size of the new image. If non-positive, they tell how many pixels of image should be cropped from the right and the bottom (0 by default).

— Procedure: decompose-color-to-rgba color

Return a list of (red green blue alpha) components of 32-bit integer color. The returned values range between 0 and 255, the higher being more intensive.

— Procedure: compose-color-from-rgba red green blue alpha

Return a 32-bit integer value (as elements of the array returned by image->array are) that represents color with red, green, blue and alpha components.

— Procedure: image? x

Returns #t if x is an image, and #f otherwise. An image can be passed to functions like crop-image. An image can either be surface?, texture? or screen?.

— Procedure: texture? image

Returns #t when the given image is internally represented as an OpenGL texture, and #f otherwise.

— Procedure: surface? image

Returns #t when the given image is internally represented as an SDL surface, and #f otherwise.

— Procedure: screen? image

Returns #t when the given image is the screen, #f otherwise.

— Procedure: make-texture w h

Return a newly allocated w by h texture.

— Procedure: call-with-video-output-to image thunk

Call thunk and capture the video output to given image. In other words, it allows rendering to texture. The image must either be a texture? or the screen?.