1.81 class image

An image is a two-dimensional array of pixels. Images are used as:

1.81.1 Class variables

image.path: string = ".:bitmaps:~/.local/share/swi-prolog/bitmaps:$PCEHOME/bitmaps"
Search path used by image->load (and indirectly by image<-convert) to locate image files. See also pce_image_directory/1.

1.81.2 Instance variables

image <- name: name*
Lookup key for the image. Used to populate @images; @nil for anonymous (read-write) images.
See also
image->initialise
image <- kind: {bitmap,pixmap}
Interpretation of the pixel values:

image <- access: {read,both}
read for reusable images (the file-loaded case): the pixels are immutable, the image can be shared by many callers. both for read-write scratch images. A both image may be associated with at most one bitmap graphical; edits propagate to that bitmap.
See also
image<-bitmap
image <- file: source_sink*
File (or other source_sink) from which the image was loaded. @nil for anonymous images.
image <- bitmap: bitmap*
Bitmap graphical backed by this image. Only meaningful when image<-access is both; at most one bitmap per image.
See also
- bitmap->image
- image<-access
image <- size: size
Pixel dimensions of the image. When loading from a file the size is derived from the file's contents; the default for a fresh anonymous image is 16x16 pixels. For SVG loads the size field can be set before image->load to drive the rendered size (see image->load).
image <-> hot_spot: point*
Hot-spot position used when this image is rendered as a cursor (typically the click point of a mouse cursor). May be set manually or loaded from an XPM file's hot-spot record.

1.81.3 Send methods

image ->initialise: name=[source_sink]*, width=[int], height=[int], kind=[{bitmap,pixmap}]
Two idiomatic ways to construct an image:

image ->unlink:
Release the pixel store and the cairo surface backing the image. Called automatically on destruction.
image ->load: from=[source_sink], path=[char_array]
Load pixels from a file or other source_sink. When the source is a file, it is first located via file->find on path (defaults to image.path).

The decoder is SDL_image, so PNG, JPEG, BMP, GIF, PCX and the other formats supported by SDL_image all load. SVG is recognised by file extension or by sniffing the stream and is rendered through SDL's size-aware SVG loader:

image ->save: in=[source_sink], format=[name]
Write the image to a file. Only png is currently supported; omitting format saves as PNG. Other format values are rejected with a console message.
image ->resize: width=int, height=int
Resize the image to the indicated dimensions, preserving the overlapping pixels. Newly-exposed area is cleared to the background. See also image<-scale.
image ->copy: from=image
Replace the receiver's pixels with an exact copy of the argument. Use image->draw_in to blit an image into a sub-area instead.
image ->draw_in: graphical, at=[point]
Render the given graphical (or image) onto the receiver at the given offset (default point(0,0)).
image ->clear:
Clear the entire image to the background (transparent for pixmap, 0 for bitmap).
image ->fill: colour, [area]
Fill the indicated area (default whole image) with the given colour.
image ->pixel: x=int, y=int, value=colour|bool
Set the pixel at (x, y) to the given colour (for pixmap) or boolean (for bitmap).
image ->has_alpha:
Succeed when the image is not fully opaque (at least one pixel has alpha < 255).

1.81.4 Get methods

image <-contained_in: -> bitmap
Equivalent to image<-bitmap when that is non-@nil.
image <-pixel: x=int, y=int -> value=bool|colour
Read the pixel at (x, y). Returns a colour for pixmap images and a boolean for bitmap images.
image <-clip: [area] -> image
New read/write image with the pixels of the indicated sub-area (default the whole image).
image <-scale: size -> image
New image scaled to the given dimensions. Scaling is done once at copy time, so passing a target size avoids the rounding problems of a multiplicative factor. To magnify by a factor:
magnify(Im, Factor, Magnified) :-
        get(Im, size, size(W, H)),
        NW is round(W * Factor),
        NH is round(H * Factor),
        get(Im, scale, size(NW, NH), Magnified).

See also image->resize and image<-rotate.

image <-rotate: degrees=num -> image
New image rotated anti-clockwise by the indicated number of degrees. The result is again a horizontal/vertical rectangle, so for non-multiples of 90 degrees it is larger than the original; the new area is cleared to the background (for pixmap) or to white (for bitmap). The image<-hot_spot is updated automatically.

For rotated text and other rotated graphicals, prefer a figure with a transform instead of pre-rendering into an image: the figure rotates its children on the fly via cairo, so the text stays glyph-accurate at every angle and the receiver remains interactive (hit-tested, repainted on demand, ...). Example:

draw_vertical(Dev, X, Y, String, Font) :-
        new(F, figure),
        send(F, display, text(String, left, Font)),
        send(F, rotate, 90),
        send(Dev, display, F, point(X, Y)).
image <-grayscale: -> image
New image with the pixels converted to grayscale.
image <-lookup: name|resource -> image
Return an existing image from @images matching the argument, or fail. Mirrors the lookup performed by image->initialise.
image <-convert: bitmap|name|resource|graphical -> image
Type-checker hook accepting: