CD - Canvas Draw

Server Images

It is a high performance image compatible with a specific canvas. It is faster than user image functions, but less flexible. It is commonly used for off-screen drawing in Window Systems.

You can make gets and puts on several canvases but they must be created using the same driver. It is possible to specify a part of the image to be drawn, but it is not possible to zoom.

It is called "server" images because the data is stored in a system private format, that the application (or the client) does not have access.

To create a server image there must be an active canvas of a driver with server image support.


void* cdCreateImage(int w, int h); [in C]
cd.CreateImage(w, h: number) -> (image: image_tag) [in Lua]

Creates a compatible image with size = w x h pixels. A compatible image has the same color representation (number of bits per pixel) of the active canvas. Once the server image is created it is independent of the active canvas. The server image can only be used with an other canvas of the same type as the canvas that was active when the image was created. The default background is the same as the canvas, CD_WHITE.

void cdKillImage(void *image); [in C]
cd.KillImage(image: image_tag) [in Lua]

Liberates memory allocated for the image. It is not necessary to have an active canvas to call this function.

void cdGetImage(void *image, int x, int y); [in C]
cd.GetImage(image: image_tag; x, y: number) [in Lua]

Copies a rectangular region from the current rectangular context to the memory (image). (x,y) is the coordinate of the bottom left corner of the rectangular region. The width and length of the rectangular region are defined in the image structure (when the image is created).

void cdPutImageRect(void *image, int x, int y, int xmin, int xmax, int ymin, int ymax); [in C]
void wdPutImageRect(void* image, double x, double y, int xmin, int xmax, int ymin, int ymax); (WC) [in C]
cd.PutImageRect(image: image_tag; x, y, xmin, xmax, ymin, ymax: number) [in Lua]
cd.wPutImageRect(image: image_tag; x, y, xmin, xmax, ymin, ymax: number) (WC) [in Lua]

Copies an image in a rectangular region of the canvas with the bottom left corner in (x,y). Allows specifying a rectangle inside the image to be drawn, if xmin, xmax, ymin and ymax are 0, then the whole image is assumed.

void cdScrollArea(int xmin, int xmax, int ymin, int ymax, int dx, int dy); [in C]
cd.ScrollArea(xmin, xmax, ymin, ymax, dx, dy: number) [in Lua]

Copies the rectangle defined by the coordinates (xmin,ymin) and (xmax,ymax) to the rectangle defined by (xmin+dx,ymin+dy) and (xmax+dx,ymax+dy). It has the same effect as cdGetImage followed by cdPutImage, but it should be faster and does not require the explicit creation of an image to be executed. Note that the region belonging to the first rectangle, but not to the second, remains unchanged (the function does not clean this region).