#include <surface.h>
Public Member Functions | |
Surface () | |
const void * | getPixels () const |
void * | getPixels () |
void | setPixels (void *newPixels) |
const void * | getBasePtr (int x, int y) const |
void * | getBasePtr (int x, int y) |
uint32 | getPixel (int x, int y) const |
void | setPixel (int x, int y, int pixel) |
void | create (int16 width, int16 height, const PixelFormat &format) |
void | free () |
void | init (int16 width, int16 height, int16 pitch, void *pixels, const PixelFormat &format) |
void | copyFrom (const Surface &surf) |
void | convertFrom (const Surface &surf, const PixelFormat &format) |
Surface | getSubArea (const Common::Rect &area) |
const Surface | getSubArea (const Common::Rect &area) const |
bool | clip (Common::Rect &srcBounds, Common::Rect &destBounds) const |
void | copyRectToSurface (const void *buffer, int srcPitch, int destX, int destY, int width, int height) |
void | copyRectToSurface (const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) |
void | copyRectToSurfaceWithKey (const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key) |
void | copyRectToSurfaceWithKey (const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key) |
void | convertToInPlace (const PixelFormat &dstFormat) |
void | convertToInPlace (const PixelFormat &dstFormat, const byte *palette, uint16 paletteCount) |
Graphics::Surface * | convertTo (const PixelFormat &dstFormat, const byte *srcPalette=0, int srcPaletteCount=256, const byte *dstPalette=0, int dstPaletteCount=0, DitherMethod method=kDitherFloyd) const |
void | drawLine (int x0, int y0, int x1, int y1, uint32 color) |
void | drawThickLine (int x0, int y0, int x1, int y1, int penX, int penY, uint32 color) |
void | hLine (int x, int y, int x2, uint32 color) |
void | vLine (int x, int y, int y2, uint32 color) |
void | fillRect (Common::Rect r, uint32 color) |
void | frameRect (const Common::Rect &r, uint32 color) |
void | move (int dx, int dy, int height) |
void | flipVertical (const Common::Rect &r) |
void | flipHorizontal (const Common::Rect &r) |
bool | applyColorKey (uint8 rKey, uint8 gKey, uint8 bKey, bool overwriteAlpha=false) |
bool | applyColorKey (uint8 rKey, uint8 gKey, uint8 bKey, bool overwriteAlpha, uint8 rNew, uint8 gNew, uint8 bNew) |
bool | setAlpha (uint8 alpha, bool skipTransparent=false) |
AlphaType | detectAlpha () const |
Graphics::Surface * | scale (int16 newWidth, int16 newHeight, bool filtering=false) const |
Graphics::Surface * | rotoscale (const TransformStruct &transform, bool filtering=false) const |
Rotoscale function; this returns a transformed version of this surface after rotation and scaling. Please do not use this if angle == 0, use plain old scaling function. More... | |
void | debugPrint (int debuglevel=0, int width=0, int height=0, int x=0, int y=0, int scale=-1, int maxwidth=160, const byte *palette=NULL) const |
Public Attributes | |
int16 | w |
int16 | h |
int32 | pitch |
PixelFormat | format |
Protected Member Functions | |
void | ditherFloyd (const byte *srcPalette, int srcPaletteCount, Surface *dstSurf, const byte *dstPalette, int dstPaletteCount, DitherMethod method, const PixelFormat &dstFormat) const |
Protected Attributes | |
void * | pixels |
An arbitrary graphics surface that can be the target (or source) of blit operations, font rendering, etc.
|
inline |
Construct a simple Surface object.
|
inline |
Return a pointer to the pixel data.
|
inline |
Return a pointer to the pixel data.
|
inline |
Set the pixel data.
Note that this is a simply a setter. Be aware of that when using it.
newPixels | The new pixel data. |
|
inline |
Return a pointer to the pixel at the specified point.
x | The x coordinate of the pixel. |
y | The y coordinate of the pixel. |
|
inline |
Return a pointer to the pixel at the specified point.
x | The x coordinate of the pixel. |
y | The y coordinate of the pixel. |
|
inline |
Return the pixel at the specified point.
x | The x coordinate of the pixel. |
y | The y coordinate of the pixel. |
|
inline |
Set the pixel at the specified point.
x | The x coordinate of the pixel. |
y | The y coordinate of the pixel. |
pixel | The value of the pixel. |
void Graphics::Surface::create | ( | int16 | width, |
int16 | height, | ||
const PixelFormat & | format | ||
) |
Allocate memory for the pixel data of the surface.
The client code is responsible for calling free.
width | Width of the surface object. |
height | Height of the surface object. |
format | The pixel format to be used by the surface. |
void Graphics::Surface::free | ( | ) |
void Graphics::Surface::init | ( | int16 | width, |
int16 | height, | ||
int16 | pitch, | ||
void * | pixels, | ||
const PixelFormat & | format | ||
) |
Set up a surface with user-specified data.
This simply sets the 'internal' attributes of the surface. It does free old data using free or similar methods.
width | Width of the pixel data. |
height | Height of the pixel data. |
pitch | Pitch of the pixel data. |
pixels | Pixel data. |
format | Pixel format of the pixel data. |
void Graphics::Surface::copyFrom | ( | const Surface & | surf | ) |
void Graphics::Surface::convertFrom | ( | const Surface & | surf, |
const PixelFormat & | format | ||
) |
Convert the data from another surface to the specified format.
This calls free on the current surface to assure that it is clean. Make sure that the current data was created using create. Otherwise, the results are undefined.
surf | The surface to convert from. |
format | The pixel format to convert to. |
Surface Graphics::Surface::getSubArea | ( | const Common::Rect & | area | ) |
Create a surface that represents a sub-area of this Surface object.
The pixel (0, 0) of the returned Surface will be the same as pixel (area.x, area.y) of the parent surface. Changes to any of the parent surface objects will change the shared pixel data.
The returned surface is only valid as long as this Surface object still exists, that is, its pixel data is not destroyed or reallocated.
Important: Never attempt to free the returned surface.
area | The area to be represented. Note that the area will get clipped in case it does not fit. |
const Surface Graphics::Surface::getSubArea | ( | const Common::Rect & | area | ) | const |
Create a surface that represents a sub-area of this Surface object.
The pixel (0, 0) of the returned surface will be the same as pixel (area.x, area.y) of the parent surface.
The returned surface is only valid as long as this Surface object still exists, that is, its pixel data is not destroyed or reallocated.
Important: Never attempt to free the returned surface.
area | The area to be represented. Note that the area will get clipped in case it does not fit. |
bool Graphics::Surface::clip | ( | Common::Rect & | srcBounds, |
Common::Rect & | destBounds | ||
) | const |
Clip the given source bounds so the passed destBounds will be entirely on-screen.
void Graphics::Surface::copyRectToSurface | ( | const void * | buffer, |
int | srcPitch, | ||
int | destX, | ||
int | destY, | ||
int | width, | ||
int | height | ||
) |
Copy a bitmap to the internal buffer of the surface.
The pixel format of the buffer must match the pixel format of the surface.
buffer | Buffer containing the graphics data source. |
srcPitch | Pitch of the buffer (number of bytes in a scanline). |
destX | The x coordinate of the destination rectangle. |
destY | The y coordinate of the destination rectangle. |
width | Width of the destination rectangle. |
height | Height of the destination rectangle. |
void Graphics::Surface::copyRectToSurface | ( | const Graphics::Surface & | srcSurface, |
int | destX, | ||
int | destY, | ||
const Common::Rect | subRect | ||
) |
Copy a bitmap to the internal buffer of the surface.
The pixel format of the buffer must match the pixel format of the surface.
srcSurface | Source of the bitmap data. |
destX | The x coordinate of the destination rectangle. |
destY | The y coordinate of the destination rectangle. |
subRect | The subRect of the surface to be blitted. |
void Graphics::Surface::copyRectToSurfaceWithKey | ( | const void * | buffer, |
int | srcPitch, | ||
int | destX, | ||
int | destY, | ||
int | width, | ||
int | height, | ||
uint32 | key | ||
) |
Copy a bitmap to the internal buffer of the surface.
The pixel format of the buffer must match the pixel format of the surface.
buffer | Buffer containing the graphics data source. |
srcPitch | Pitch of the buffer (number of bytes in a scanline). |
destX | The x coordinate of the destination rectangle. |
destY | The y coordinate of the destination rectangle. |
width | Width of the destination rectangle. |
height | Height of the destination rectangle. |
key |
void Graphics::Surface::copyRectToSurfaceWithKey | ( | const Graphics::Surface & | srcSurface, |
int | destX, | ||
int | destY, | ||
const Common::Rect | subRect, | ||
uint32 | key | ||
) |
Copy a bitmap to the internal buffer of the surface.
The pixel format of the buffer must match the pixel format of the surface.
srcSurface | Source of the bitmap data. |
destX | The x coordinate of the destination rectangle. |
destY | The y coordinate of the destination rectangle. |
subRect | The subRect of the surface to be blitted. |
key |
|
inline |
Convert the data to another pixel format.
This works in-place. This means it does not create an additional buffer for the conversion process. The value of 'pixels' might change though (that means it might realloc the pixel data).
Important: Only use this if you created the surface data using create. Otherwise, this function has undefined behavior.
dstFormat | The desired format. |
void Graphics::Surface::convertToInPlace | ( | const PixelFormat & | dstFormat, |
const byte * | palette, | ||
uint16 | paletteCount | ||
) |
Convert the data to another pixel format.
This works in-place. This means it does not create an additional buffer for the conversion process. The value of 'pixels' might change though (that means it might realloc the pixel data).
Important: Only use this if you created the surface data using create. Otherwise, this function has undefined behavior.
dstFormat | The desired format. |
palette | The palette (in RGB888), if the source format has one. |
paletteCount | The number of colors in the palette. |
Graphics::Surface* Graphics::Surface::convertTo | ( | const PixelFormat & | dstFormat, |
const byte * | srcPalette = 0 , |
||
int | srcPaletteCount = 256 , |
||
const byte * | dstPalette = 0 , |
||
int | dstPaletteCount = 0 , |
||
DitherMethod | method = kDitherFloyd |
||
) | const |
Convert the data to another pixel format.
The client code must call free on the returned surface and then delete it.
dstFormat | The desired format. |
srcPalette | The palette (in RGB888), if the source format has a bpp of 1. |
srcPaletteCount | The color count in the for the srcPalette. |
dstPalette | The palette (in RGB888), If the destination format has a bpp of 1. |
dstaletteCount | The color count in the for the dstPalette. |
method | The dithering method if destination format has a bpp of 1. Default is Floyd-Steinberg. |
void Graphics::Surface::drawLine | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
uint32 | color | ||
) |
Draw a line.
x0 | The x coordinate of the start point. |
y0 | The y coordinate of the start point. |
x1 | The x coordinate of the end point. |
y1 | The y coordinate of the end point. |
color | Color of the line. |
void Graphics::Surface::drawThickLine | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | penX, | ||
int | penY, | ||
uint32 | color | ||
) |
Draw a thick line.
x0 | The x coordinate of the start point. |
y0 | The y coordinate of the start point. |
x1 | The x coordinate of the end point. |
y1 | The y coordinate of the end point. |
penX | Width of the pen (thickness in the x direction). |
penY | Height of the pen (thickness in the y direction). |
color | Color of the line. |
void Graphics::Surface::hLine | ( | int | x, |
int | y, | ||
int | x2, | ||
uint32 | color | ||
) |
Draw a horizontal line.
x | The start x coordinate of the line. |
y | The y coordinate of the line. |
x2 | The end x coordinate of the line. In case x > x2, the coordinates are swapped. |
color | Color of the line. |
void Graphics::Surface::vLine | ( | int | x, |
int | y, | ||
int | y2, | ||
uint32 | color | ||
) |
Draw a vertical line.
x | The x coordinate of the line. |
y | The start y coordinate of the line. |
y2 | The end y coordinate of the line. In case y > y2, the coordinates are swapped. |
color | Color of the line. |
void Graphics::Surface::fillRect | ( | Common::Rect | r, |
uint32 | color | ||
) |
Fill a rect with a given color.
r | The rectangle to fill. |
color | The color to fill the rect with. |
void Graphics::Surface::frameRect | ( | const Common::Rect & | r, |
uint32 | color | ||
) |
Draw a frame around a specified rect.
r | The rectangle to frame. |
color | The color of the frame. |
void Graphics::Surface::move | ( | int | dx, |
int | dy, | ||
int | height | ||
) |
Move the content of the surface horizontally or vertically by the given number of pixels.
void Graphics::Surface::flipVertical | ( | const Common::Rect & | r | ) |
Flip the specified rect vertically.
r | The rectangle to flip. |
void Graphics::Surface::flipHorizontal | ( | const Common::Rect & | r | ) |
Flip the specified rect horizontally.
r | The rectangle to flip. |
bool Graphics::Surface::applyColorKey | ( | uint8 | rKey, |
uint8 | gKey, | ||
uint8 | bKey, | ||
bool | overwriteAlpha = false |
||
) |
Writes a color key to the alpha channel of the surface
rKey | the red component of the color key |
gKey | the green component of the color key |
bKey | the blue component of the color key |
overwriteAlpha | if true, all other alpha will be set fully opaque |
bool Graphics::Surface::applyColorKey | ( | uint8 | rKey, |
uint8 | gKey, | ||
uint8 | bKey, | ||
bool | overwriteAlpha, | ||
uint8 | rNew, | ||
uint8 | gNew, | ||
uint8 | bNew | ||
) |
Writes a color key to the alpha channel of the surface
rKey | the red component of the color key |
gKey | the green component of the color key |
bKey | the blue component of the color key |
overwriteAlpha | if true, all other alpha will be set fully opaque |
rNew | the red component to replace the color key with |
gNew | the green component to replace the color key with |
bNew | the blue component to replace the color key with |
bool Graphics::Surface::setAlpha | ( | uint8 | alpha, |
bool | skipTransparent = false |
||
) |
Sets alpha channel for all pixels to specified value
alpha | value of the alpha channel to set |
skipTransparent | if set to true, then do not touch pixels with alpha=0 |
AlphaType Graphics::Surface::detectAlpha | ( | ) | const |
Checks if the given surface contains alpha transparency
Graphics::Surface* Graphics::Surface::scale | ( | int16 | newWidth, |
int16 | newHeight, | ||
bool | filtering = false |
||
) | const |
Scale the data to the given size.
The client code must call free on the returned surface and then delete it.
newWidth | The resulting width. |
newHeight | The resulting height. |
filtering | Whether or not to use bilinear filtering. |
Graphics::Surface* Graphics::Surface::rotoscale | ( | const TransformStruct & | transform, |
bool | filtering = false |
||
) | const |
Rotoscale function; this returns a transformed version of this surface after rotation and scaling. Please do not use this if angle == 0, use plain old scaling function.
The client code must call free on the returned surface and then delete it.
transform | a TransformStruct wrapping the required info. |
filtering | Whether or not to use bilinear filtering. |
void Graphics::Surface::debugPrint | ( | int | debuglevel = 0 , |
int | width = 0 , |
||
int | height = 0 , |
||
int | x = 0 , |
||
int | y = 0 , |
||
int | scale = -1 , |
||
int | maxwidth = 160 , |
||
const byte * | palette = NULL |
||
) | const |
Print surface content on console in pseudographics
debuglevel | debug level to print at, default is 0. |
width | width of the printed area in pixels. Default is 0 which is whole surface. |
height | height of the printed area in pixels. Default is 0 which is whole surface. |
x | horizontal offset to the print area. Default is 0. |
y | vertical offset to the print area. Default is 0. |
scale | number of pixels per single character. Default is -1, fit whole surface to maxwidth |
maxwidth | horizontal size of the print out in characters. Default is 160. Note that 2 characters are taken by the frame |
palette | palette to use for 1bpp pixels. If omitted, we assume grayscale palette |
int16 Graphics::Surface::w |
Width of the surface.
int16 Graphics::Surface::h |
Height of the surface.
int32 Graphics::Surface::pitch |
Number of bytes in a pixel line.
|
protected |
Pixel data of the surface.
PixelFormat Graphics::Surface::format |
Pixel format of the surface.