Image structure in Xcas

### 26.1.1 Image structure in Xcas

Starting from version 1.9.0, images in Xcas are special objects which can be loaded from PNG, JPEG or GIF files and written to PNG files. Such objects allow for visualization, extraction and modification of the image data. An image object evaluates to a string describing the structure of the image.

In earlier versions of Xcas, an image is a list with the following elements (referred to as the legacy format in the further text):

1. A list of three integers:
   - the number of channels (3 or 4, depending on whether a transparency channel is present),
   - the number n, representing the height of the image in pixels,
   - the number p, representing the width of the image in pixels.
   Each channel will be an n× p matrix of integers between 0 and 255.
2. A matrix of red channel values.
3. A matrix of green channel values.
4. A matrix of transparency channel values.
5. A matrix of blue channel values.

The color of the point at line i and column j is determined by the values of the (i,j)th entry of the matrices. Note that the transparency channel data comes before the blue channel data since color values in Xcas are red=1, green=2 and blue=4, which allows for extraction of channel data using colors as indices.

Note that the number of points in the structure isn’t necessarily the same as the number of pixels on the screen when it is drawn. A single point in the structure can appear as a (small) rectangle of pixels when displayed on the screen.

Loading images to the legacy format is supported by the readrgb command.