Surface

Surface is a wrapper for a SDL_Surface and can load and save images.

Constructors

this
this(SDL_Surface* srfc)

CTor

this
this(string filename)

CTor

this
this(uint width, uint height, ubyte depth = 32, const Masks masks = Masks.init)

Make a new Surface of the given width, height and depth.

this
this(void* memory, uint width, uint height, ubyte depth = 32, const Masks masks = Masks.init)

Make an new Surface of the given memory, width, height and depth.

Destructor

~this
~this()

DTor

Postblit

this(this)
this(this)

Postblit is allowed and increases the internal ref count

Members

Enums

BlendMode
enum BlendMode

Supported BlendModes

Functions

adaptTo
bool adaptTo(ref Surface srfc)

Use this function to adapt the format of another Surface to this surface.

adaptTo
bool adaptTo(ubyte depth)

Use this function to adapt the format of another Surface depth to this surface.

blit
bool blit(ref Surface srfc, const Rect* src = null, Rect* dst = null)

Use this function to perform a fast blit from the source surface to the this surface. src is the a pointer to a Rect structure which represents the rectangle to be copied, or null to copy the entire surface. dst is a pointer to a Rect structure which represents the rectangle that is copied into. null means, that the whole srfc is copied to (0|0).

blitScaled
bool blitScaled(ref Surface srfc, const Rect* src = null, Rect* dst = null)

Use this function to perform a fast, low quality, stretch blit between two surfaces of the same pixel format. src is the a pointer to a Rect structure which represents the rectangle to be copied, or null to copy the entire surface. dst is a pointer to a Rect structure which represents the rectangle that is copied into. null means, that the whole srfc is copied to (0|0).

fill
void fill(const Color4b col, const Rect* rect = null)

Fills a specific area of the surface with the given color. The second parameter is a pointer to the area. If it's null, the whole Surface is filled.

getAlphaMod
ubyte getAlphaMod()

Returns the current Alpha mod.

getBlendMode
BlendMode getBlendMode()

Returns the current Blendmode.

getClipRect
Rect getClipRect()

Returns the clip rect of this surface. The clip rect is the area of the surface which is drawn.

getColorAt
Color4b getColorAt(int x, int y)

Returns the color on the given position, or Color4b.Black if the position is out of range.

getColorAt
Color4b getColorAt(const Vector2i pos)

Returns the color on the given position.

getColorkey
Color4b getColorkey()

Returns the current colorkey, or Color4b.Black, if the Surface is invalid

getMasks
Masks getMasks()

Returns the Surface color Masks

getPixelAt
int getPixelAt(int x, int y)

Returns the pixel at the given coordinates.

getPixelAt
int getPixelAt(const Vector2i pos)

Returns the pixel at the given coordinates.

isLocked
bool isLocked()

Returns whether this Surface is locked or not.

isValid
bool isValid()

Returns if the Surface is valid. Which means that the Surface has valid data.

loadFromFile
bool loadFromFile(string filename)

Load from filename. If any data is already stored, the data will be freed.

loadFromMemory
bool loadFromMemory(void* memory, ushort width, ushort height, ubyte depth = 32, const Masks masks = Masks.init)

Load from memory.

lock
bool lock()

Use this function to set up a surface for directly accessing the pixels.

mustLock
bool mustLock()

Use this function to determine whether a surface must be locked for access.

optimizeRLE
bool optimizeRLE(bool enable)

Use this function to set the RLE acceleration hint for a surface. RLE (Run-Length-Encoding) is a way of compressing data. If RLE is enabled, color key and alpha blending blits are much faster, but the surface must be locked before directly accessing the pixels.

putPixelAt
void putPixelAt(const Vector2i pos, uint pixel)

Put a new pixel at the given coordinates.

saveToFile
bool saveToFile(string filename)

Save the current pixel data to the file.

setAlphaMod
void setAlphaMod(ubyte alpha)

Set the Alpha mod.

setBlendMode
void setBlendMode(BlendMode mode)

Set the Blendmode.

setClipRect
void setClipRect(const Rect clip)

Set the clip rect.

setColorkey
void setColorkey(const Color4b col)

Set the colorkey.

subSurface
Surface subSurface(const Rect rect)

Returns a subsurface from this surface. rect represents the viewport. The subsurface is a separate Surface object.

unlock
void unlock()

Use this function to release a surface after directly accessing the pixels.

Properties

bits
ubyte bits [@property getter]

Count the bits of this surface. Could be 32, 24, 16, 8, 0.

bytes
ubyte bytes [@property getter]

Count the bytes of this surface. Could be 4, 3, 2, 1, 0. (countBits / 8)

height
int height [@property getter]

Returns the height.

pitch
int pitch [@property getter]

Returns the Surface pitch or 0.

pixels
inout(void*) pixels [@property getter]

Returns the pixel data of this surface.

refCount
int refCount [@property getter]

Returns the current ref count / usage

width
int width [@property getter]

Returns the width.

Meta

Authors

Randy Schuett (rswhite4@googlemail.com)