Graphics
The Storm standard library provides basic primitives for storing graphics in order to facilitate interoperability between libraries, particularly libraries written in C++. As such, the facilities provided by the standard library are quite sparse. However, the graphics library provides facilities for loading images from streams, and the UI library allows drawing them to the screen.
The graphics part of the standard library is located in the graphics
package (i.e. not in core
),
and contains the classes graphics.Color
and graphics.Image
.
Color
The graphics.Color
class stores a color in RGB + alpha format. Each component is stored
as a 32-bit Float
in the range 0-1. The alpha component is in the range from 0 (transparent) to 1
(opaque). The alpha component is not premultiplied in the Color
class.
The Color
class contains constructors that allow creating colors from color components (both with
and without alpha), both as Floats
and as Bytes
(range 0-255). It also contains operators +
and -
for mixing colors, and *
and /
for scaling the color values (except alpha) with a
scalar.
There are also convenience functions for creating various colors:
-
graphics.Color transparent()
- Transparent color, based on the color black. -
graphics.Color black()
-
graphics.Color white()
-
graphics.Color red()
-
graphics.Color green()
-
graphics.Color blue()
-
graphics.Color yellow()
-
graphics.Color cyan()
-
graphics.Color pink()
The presentation library contains definitions of the
DVIPS colors in the package presentation.colors
.
Image
The graphics.Image
class stores an image in RGB + alpha format. Conceptually, the image
consists of a 2D-array of graphics.Color
s. For increased efficiency, however, each image
is stored as a 32-bit RGBA value (i.e. 8 bits per channel). In C++, the Image
provides access to
the underlying buffer in a format that is often efficient for other libraries to consume. It also
allows accessing individual pixels from Storm.
The interface is as follows:
-
init()
Empty image.
-
init(core.geometry.Size size)
Create an image with the specified size. The image is initially entirely transparent (based on the color black).
-
init(core.Nat w, core.Nat h)
Create an image with the specified size. The image is initially entirely transparent (based on the color black).
-
graphics.Color get(core.Nat x, core.Nat y)
Get the pixel at a coordinate.
-
graphics.Color get(core.geometry.Point at)
Get the pixel at the specified coordinate. Truncates any fractions, does not perform any interpolation.
-
void set(core.Nat x, core.Nat y, graphics.Color c)
Set the pixel at the specified coordinate.
-
void set(core.geometry.Point p, graphics.Color c)
Set the pixel at the specified coordinate.
-
core.Bool hasAlpha()
Does this image contain any pixels that are transparent or semi-transparent?