Image¶
Usage
use Image;
or
import Image;
Warning
Image is unstable
The Image module provides a way to write arrays of pixels to an output image format.
For example, the following code creates a 3x3 array of pixels and writes it to a BMP file. The array is then scaled by a factor of 2 (creating a 9x9 image) and written to a second BMP file.
use Image;
var arr: [1..3, 1..3] int;
arr[1, ..] = [0xFF0000, 0x00FF00, 0x0000FF];
arr[2, ..] = [0x00FF00, 0x0000FF, 0xFF0000];
arr[3, ..] = [0x0000FF, 0xFF0000, 0x00FF00];
writeImage("pixels.bmp", imageType.bmp, arr);
writeImage("pixels2.bmp", imageType.bmp, scale(arr, 2));
- enum imageType { bmp }¶
Defines what kind of image to output
- enum constant bmp¶
A BMP image is written from a 2D array of pixels
- proc writeImage(image, format: imageType, pixels: [] pixelType) throws¶
Write an array of pixels as an image
- Arguments:
image – the output filename or an open fileWriter
format – the image format
pixels – an array of pixel values
- proc downSample(arr: [?d], newMin: int = 0, newMax: int = 0xFFFFFF) : [d] int where d.isRectangular() && d.rank == 2¶
Takes a 2D array of some element type and computes an integer color gradient between the newMin/Max. This is a simple interpolation of the values in the array to the new range.
- Arguments:
arr – the 2D array of values to sample
newMin – the new minimum value
newMax – the new maximum value
- Returns:
a new array of pixels with the same domain as
arr
- proc interpolateColor(arr: [?d], colorA: pixelType, colorB: pixelType, colorRange = interpolateColorDefaultColorRange(arr)) : [d] pixelType¶
Linearly interpolates between two colors to create an array of pixels.
- proc scale(arr: [?d], factor: int) : [] where d.isRectangular() && d.rank == 2¶
Scale a 2D array of pixels by a given factor
- Arguments:
arr – the 2D array of pixels
factor – the factor to scale by
- Returns:
a new array of pixels scaled by the factor
- record mediaPipe¶
Represents a ffmpeg stream that frame data can be written to to produce a mp4.
- proc init(image: string, imgType: imageType, framerate: int = 30, rateFactor: int = 1) throws¶
- proc ref deinit()¶
- proc writeFrame(pixelData: [] pixelType) throws¶
Write a frame into the media pipe.
- proc ref finish() throws¶