The OpenD Programming Language

Image

Represents an in-memory image in the format that the GUI expects, but with its raw data available to your program.

More...

Constructors

this
this(int width, int height, bool forcexshm, bool enableAlpha)
this
this(Size size, bool forcexshm, bool enableAlpha)

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

adjustmentForNextLine
int adjustmentForNextLine()
alphaByteOffset
int alphaByteOffset()

Only valid if enableAlpha is true

blueByteOffset
int blueByteOffset()
bytesPerLine
int bytesPerLine()

for use with getDataPointer

bytesPerPixel
int bytesPerPixel()

for use with getDataPointer

getDataPointer
ubyte* getDataPointer()

warning: this is not portable across platforms because the data format can change

getPixel
Color getPixel(int x, int y)
getRgbaBytes
ubyte[] getRgbaBytes(ubyte[] where)

this is here for interop with arsd.image. where can be a TrueColorImage's data member if you pass in a buffer, it will put it right there. length must be width*height*4 already if you pass null, it will allocate a new one.

greenByteOffset
int greenByteOffset()
offsetForPixel
int offsetForPixel(int x, int y)
offsetForTopLeftPixel
int offsetForTopLeftPixel()
opIndexAssign
void opIndexAssign(Color c, int x, int y)
putPixel
void putPixel(int x, int y, Color c)
redByteOffset
int redByteOffset()

once you have the position of a pixel, use these to get to the proper color

setRgbaBytes
void setRgbaBytes(ubyte[] from)

this is here for interop with arsd.image. from can be a TrueColorImage's data member

toTrueColorImage
TrueColorImage toTrueColorImage()

Static functions

fromMemoryImage
Image fromMemoryImage(MemoryImage i, bool enableAlpha, bool premultiply)

Variables

enableAlpha
bool enableAlpha;
height
int height;
width
int width;

Detailed Description

On Windows, this means a device-independent bitmap. On X11, it is an XImage.

If you are writing platform-aware code and need to know low-level details, uou may check if(Image.impl.xshmAvailable) to see if MIT-SHM is used on X11 targets to draw Images and Sprites. Use static if(UsingSimpledisplayX11) to determine if you are compiling for an X11 target.

Drawing an image to screen is not necessarily fast, but applying algorithms to draw to the image itself should be fast. An Image is also the first step in loading and displaying images loaded from files.

If you intend to draw an image to screen several times, you will want to convert it into a Sprite.

Image may represent a scarce, shared resource that persists across process termination, and should be disposed of properly. On X11, it uses the MIT-SHM extension, if available, which uses shared memory handles with the X server, which is a long-lived process that holds onto them after your program terminates if you don't free it.

It is possible for your user's system to run out of these handles over time, forcing them to clean it up with extraordinary measures - their GUI is liable to stop working!

Be sure these are cleaned up properly. simpledisplay will do its best to do the right thing, including cleaning them up in garbage collection sweeps (one of which is run at most normal program terminations) and catching some deadly signals. It will almost always do the right thing. But, this is no substitute for you managing the resource properly yourself. (And try not to segfault, as recovery from them is alway dicey!)

Please call destroy(image); when you are done with it. The easiest way to do this is with scope:

auto image = new Image(256, 256);
scope(exit) destroy(image);

As long as you don't hold on to it outside the scope.

I might change it to be an owned pointer at some point in the future.

Drawing pixels on the image may be simple, using the opIndexAssign function, but you can also often get a fair amount of speedup by getting the raw data format and writing some custom code.

FIXME INSERT EXAMPLES HERE

Meta