An image is a two-dimensional array of pixels. Images
are used as:
bitmap graphical;
<-kind
bitmap, in which case it is interpreted as a black/white
mask: white pixels paint with the current foreground, black pixels with
the background. pixmap (full RGBA) is the default.
The most common case is the read-only image loaded from a file —
typically used for icons. Such images are pooled in @images
and shared across callers; see image->initialise
and image<-lookup.
Read-write images backing a single bitmap are constructed
with explicit dimensions; see image<->access.
The image loader is SDL_image: PNG, JPEG, BMP, GIF, SVG and
the other formats that SDL_image supports are all accepted. SVG is sized
using the image's image<-size.
Saving currently only supports PNG output.
~/.local/share/swi-prolog/bitmaps:$PCEHOME/bitmaps"->load
(and indirectly by image<-convert)
to locate image files. See also pce_image_directory/1.
pixmap (default) — each pixel is a 32-bit RGBA
colour.
bitmap — each pixel is either black or white. When
the image is painted, white pixels are mapped to the current foreground
and black pixels to the background. Used for monochrome icons.
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.
source_sink) from which the image was
loaded.
@nil for
anonymous images.<-access
is both; at most one bitmap per image.
->load
to drive the rendered size (see image->load).
new(I, image(File)).
The constructor first looks File up in @images;
on a hit it returns the existing instance. Otherwise it builds a new
image and image->loads
its pixels from the file. Such images get image<-access read.
new(I, image(@nil, Width, Height)). These images are not
pooled and have image<-access both.
The kind argument selects between pixmap
(default) and
bitmap.
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:
<-width and image<-height
non-zero → SVG is rendered at exactly that size;
Streams that are not SVG fall back to a built-in PNM reader when SDL_image cannot interpret them.
png is currently supported;
omitting format saves as PNG. Other format values are
rejected with a console message.<-scale.->draw_in
to blit an image into a sub-area instead.graphical (or image) onto the
receiver at the given offset (default point(0,0)).pixmap, 0 for bitmap).|bool(x, y) to the given colour (for pixmap)
or boolean (for bitmap).alpha < 255).
<-bitmap
when that is non-@nil.|colour(x, y). Returns a colour for pixmap
images and a boolean for bitmap images.
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.
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)).
|resource -> image->initialise.|name|resource|graphical -> image
bitmap object — yields its image<-image;
.path
— loads and pools the image;
rc resource term — yields the resource's image;
graphical — produces a fresh image by rendering the
graphical into it via image->draw_in.