- read-image #!key channelsprocedure
- load-image u8vector #!key channelsprocedure
Decodes an image into raw pixel data. read-image reads the image from from (current-input-port) while load-image gets this from the provided u8vector. The image type is detected by content, and may be: JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM as explained in the heading comments of stb_image.h.
Both procedures return 4 values:
- raw pixel data (as u8vector)
- number of channels
You can force the number of channels with the channels keyword. If channels is #f or not given, the number of channels in the original image will be used.
The size of the pixel data blob is always (* width height channels) bytes. The first pixel is the top-left-most in the image. Each pixel is channel number of bytes long. The number of channels define the pixel color, interleaved as follows:
- grey, alpha
- red, green, blue
- red, green, blue, alpha
read-image may read beyond the image data, so the data in current-input-port should contain only one image.