Bitmap

Thin wrap around SDL_Surface including loading [png, webp, tiff, bmp] using SDL_Image.

Constructors

this
this(int width, int height, int depth = 24, int redChannel = 0, int greenChannel = 0, int blueChannel = 0, int alphaChannel = 0)

Creates a new width x height bitmap with a specified bit depth.

this
this(void[] pixels, int width, int height, int depth = 24, int redChannel = 0, int greenChannel = 0, int blueChannel = 0, int alphaChannel = 0)

Creates a new width x height bitmap with a specified bit depth containing pixel data.

Destructor

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

Members

Functions

convert
Bitmap convert(const SDL_PixelFormat* format)

Copies the bitmap and creates a new bitmap in the given pixelformat.

dispose
void dispose()

Deallocates the memory and invalidates this.

fill
void fill(Color color)

Fills the entire bitmap with one color.

fill
void fill(int x, int y, int width, int height, Color color)

Fills a rectangle with one color.

getPixel
Color getPixel(int x, int y)

Gets the RGB color at position x, y. (0, 0) is top left.

getPixelRGBA
ubyte[] getPixelRGBA(int x, int y)

Gets the RGBA color at position x, y as R, G, B, A ubyte array. (0, 0) is top left.

mapRGB
uint mapRGB(Color color)

Gets the rgb hex from the color based on the bitmap format.

mapRGBA
uint mapRGBA(ubyte r, ubyte g, ubyte b, ubyte a)

Gets the rgb hex from the color based on the bitmap format.

save
void save(string file)

Saves the bitmap to a .bmp file.

setPixel
void setPixel(int x, int y, Color color)

Sets the RGB color at position x, y. (0, 0) is top left.

setPixelRGBA
void setPixelRGBA(int x, int y, ubyte r, ubyte g, ubyte b, ubyte a)

Sets the RGBA color at position x, y. (0, 0) is top left.

Properties

height
int height [@property getter]

Height of this bitmap. Returns 0 if invalid.

surface
SDL_Surface* surface [@property getter]

Handle to the SDL_Surface*.

valid
bool valid [@property getter]

Checks if the handle is not null.

width
int width [@property getter]

Width of this bitmap. Returns 0 if invalid.

Static functions

fromSurface
Bitmap fromSurface(SDL_Surface* surface)

Creates a bitmap from a SDL_Surface*.

load
Bitmap load(string file)

Loads a png/webp/tiff/bmp from a file on the filesystem.

Meta