ScummVM
Graphics::Surface Struct Reference

An arbitrary graphics surface, which can be the target (or source) of blit operations, font rendering, etc. More...

#include <surface.h>

Inheritance diagram for Graphics::Surface:
Collaboration diagram for Graphics::Surface:

Public Member Functions

 Surface ()
 Construct a simple Surface object. More...
 
const voidgetPixels () const
 Return a pointer to the pixel data. More...
 
voidgetPixels ()
 Return a pointer to the pixel data. More...
 
void setPixels (void *newPixels)
 Sets the pixel data. More...
 
const voidgetBasePtr (int x, int y) const
 Return a pointer to the pixel at the specified point. More...
 
voidgetBasePtr (int x, int y)
 Return a pointer to the pixel at the specified point. More...
 
void create (uint16 width, uint16 height, const PixelFormat &format)
 Allocate memory for the pixel data of the surface. More...
 
void free ()
 Release the memory used by the pixels memory of this surface. More...
 
void init (uint16 width, uint16 height, uint16 pitch, void *pixels, const PixelFormat &format)
 Set up the Surface with user specified data. More...
 
void copyFrom (const Surface &surf)
 Copy the data from another Surface. More...
 
Surface getSubArea (const Common::Rect &area)
 Creates a Surface which represents a sub-area of this Surface object. More...
 
const Surface getSubArea (const Common::Rect &area) const
 Creates a Surface which represents a sub-area of this Surface object. More...
 
void copyRectToSurface (const void *buffer, int srcPitch, int destX, int destY, int width, int height)
 Copies a bitmap to the Surface internal buffer. More...
 
void copyRectToSurface (const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect)
 Copies a bitmap to the Surface internal buffer. More...
 
void convertToInPlace (const PixelFormat &dstFormat, const byte *palette=0)
 Convert the data to another pixel format. More...
 
Graphics::SurfaceconvertTo (const PixelFormat &dstFormat, const byte *palette=0) const
 Convert the data to another pixel format. More...
 
void drawLine (int x0, int y0, int x1, int y1, uint32 color)
 Draw a line. More...
 
void drawThickLine (int x0, int y0, int x1, int y1, int penX, int penY, uint32 color)
 Draw a thick line. More...
 
void hLine (int x, int y, int x2, uint32 color)
 Draw a horizontal line. More...
 
void vLine (int x, int y, int y2, uint32 color)
 Draw a vertical line. More...
 
void fillRect (Common::Rect r, uint32 color)
 Fill a rect with a given color. More...
 
void frameRect (const Common::Rect &r, uint32 color)
 Draw a frame around a specified rect. More...
 
void move (int dx, int dy, int height)
 

Public Attributes

uint16 w
 The width of the surface. More...
 
uint16 h
 The height of the surface. More...
 
uint16 pitch
 The number of bytes a pixel line has. More...
 
PixelFormat format
 The pixel format of the surface. More...
 

Protected Attributes

voidpixels
 The surface's pixel data. More...
 

Detailed Description

An arbitrary graphics surface, which can be the target (or source) of blit operations, font rendering, etc.

Definition at line 42 of file surface.h.

Constructor & Destructor Documentation

◆ Surface()

Graphics::Surface::Surface ( )
inline

Construct a simple Surface object.

Definition at line 82 of file surface.h.

Member Function Documentation

◆ convertTo()

Graphics::Surface * Graphics::Surface::convertTo ( const PixelFormat dstFormat,
const byte palette = 0 
) const

Convert the data to another pixel format.

The calling code must call free on the returned surface and then delete it.

Parameters
dstFormatThe desired format
paletteThe palette (in RGB888), if the source format has a Bpp of 1

Definition at line 423 of file surface.cpp.

◆ convertToInPlace()

void Graphics::Surface::convertToInPlace ( const PixelFormat dstFormat,
const byte palette = 0 
)

Convert the data to another pixel format.

This works in-place. This means it will not create an additional buffer for the conversion process. The value of 'pixels' might change though (that means it might realloc the pixel data).

Note that you should only use this, when you created the Surface data via create! Otherwise this function has undefined behavior.

Parameters
dstFormatThe desired format
paletteThe palette (in RGB888), if the source format has a Bpp of 1

Definition at line 357 of file surface.cpp.

◆ copyFrom()

void Graphics::Surface::copyFrom ( const Surface surf)

Copy the data from another Surface.

Note that this calls free on the current surface, to assure it being clean. So be sure the current data was created via create, otherwise the results are undefined.

See also
create
free
Parameters
surfSurface to copy from.

Definition at line 94 of file surface.cpp.

◆ copyRectToSurface() [1/2]

void Graphics::Surface::copyRectToSurface ( const void buffer,
int  srcPitch,
int  destX,
int  destY,
int  width,
int  height 
)

Copies a bitmap to the Surface internal buffer.

The pixel format of buffer must match the pixel format of the Surface.

Parameters
bufferThe buffer containing the graphics data source
srcPitchThe pitch of the buffer (number of bytes in a scanline)
destXThe x coordinate of the destination rectangle
destYThe y coordinate of the destination rectangle
widthThe width of the destination rectangle
heightThe height of the destination rectangle

Definition at line 137 of file surface.cpp.

◆ copyRectToSurface() [2/2]

void Graphics::Surface::copyRectToSurface ( const Graphics::Surface srcSurface,
int  destX,
int  destY,
const Common::Rect  subRect 
)

Copies a bitmap to the Surface internal buffer.

The pixel format of buffer must match the pixel format of the Surface.

Parameters
srcSurfaceThe source of the bitmap data
destXThe x coordinate of the destination rectangle
destYThe y coordinate of the destination rectangle
subRectThe subRect of surface to be blitted

Definition at line 155 of file surface.cpp.

◆ create()

void Graphics::Surface::create ( uint16  width,
uint16  height,
const PixelFormat format 
)

Allocate memory for the pixel data of the surface.

Note that you are responsible for calling free yourself.

See also
free
Parameters
widthWidth of the surface object.
heightHeight of the surface object.
formatThe pixel format the surface should use.

Definition at line 65 of file surface.cpp.

◆ drawLine()

void Graphics::Surface::drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
uint32  color 
)

Draw a line.

Parameters
x0The x coordinate of the start point.
y0The y coordiante of the start point.
x1The x coordinate of the end point.
y1The y coordinate of the end point.
colorThe color of the line.
Note
This is just a wrapper around Graphics::drawLine

Definition at line 43 of file surface.cpp.

◆ drawThickLine()

void Graphics::Surface::drawThickLine ( int  x0,
int  y0,
int  x1,
int  y1,
int  penX,
int  penY,
uint32  color 
)

Draw a thick line.

Parameters
x0The x coordinate of the start point.
y0The y coordiante of the start point.
x1The x coordinate of the end point.
y1The y coordinate of the end point.
penXThe width of the pen (thickness in the x direction)
penYThe height of the pen (thickness in the y direction)
colorThe color of the line.
Note
This is just a wrapper around Graphics::drawThickLine
The x/y coordinates of the start and end points are the upper-left most part of the pen

Definition at line 54 of file surface.cpp.

◆ fillRect()

void Graphics::Surface::fillRect ( Common::Rect  r,
uint32  color 
)

Fill a rect with a given color.

Parameters
rRect to fill
colorThe color of the rect's contents.

Definition at line 228 of file surface.cpp.

◆ frameRect()

void Graphics::Surface::frameRect ( const Common::Rect r,
uint32  color 
)

Draw a frame around a specified rect.

Parameters
rRect to frame
colorThe color of the frame.

Definition at line 272 of file surface.cpp.

◆ free()

void Graphics::Surface::free ( )

Release the memory used by the pixels memory of this surface.

This is the counterpart to create().

Note that you should only use this, when you created the Surface data via create! Otherwise this function has undefined behavior.

See also
create

Definition at line 79 of file surface.cpp.

◆ getBasePtr() [1/2]

const void* Graphics::Surface::getBasePtr ( int  x,
int  y 
) const
inline

Return a pointer to the pixel at the specified point.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
Returns
Pointer to the pixel.

Definition at line 119 of file surface.h.

◆ getBasePtr() [2/2]

void* Graphics::Surface::getBasePtr ( int  x,
int  y 
)
inline

Return a pointer to the pixel at the specified point.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
Returns
Pointer to the pixel.

Definition at line 130 of file surface.h.

◆ getPixels() [1/2]

const void* Graphics::Surface::getPixels ( ) const
inline

Return a pointer to the pixel data.

Returns
Pointer to the pixel data.

Definition at line 90 of file surface.h.

◆ getPixels() [2/2]

void* Graphics::Surface::getPixels ( )
inline

Return a pointer to the pixel data.

Returns
Pointer to the pixel data.

Definition at line 99 of file surface.h.

◆ getSubArea() [1/2]

Surface Graphics::Surface::getSubArea ( const Common::Rect area)

Creates a Surface which 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 this Surface. Changes to any of the Surface objects will change the shared pixel data.

Note that the Surface returned is only valid as long as this Surface object is still alive (i.e. its pixel data is not destroyed or reallocated). Do never try to free the returned Surface.

Parameters
areaThe area which should be represented. Note that the area will get clipped in case it does not fit!

Definition at line 109 of file surface.cpp.

◆ getSubArea() [2/2]

const Surface Graphics::Surface::getSubArea ( const Common::Rect area) const

Creates a Surface which 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 this Surface.

Note that the Surface returned is only valid as long as this Surface object is still alive (i.e. its pixel data is not destroyed or reallocated). Do never try to free the returned Surface.

Parameters
areaThe area which should be represented. Note that the area will get clipped in case it does not fit!

Definition at line 122 of file surface.cpp.

◆ hLine()

void Graphics::Surface::hLine ( int  x,
int  y,
int  x2,
uint32  color 
)

Draw a horizontal line.

Parameters
xThe start x coordinate of the line.
yThe y coordiante of the line.
x2The end x coordinate of the line. In case x > x2 the coordinates are swapped.
colorThe color of the line.

Definition at line 161 of file surface.cpp.

◆ init()

void Graphics::Surface::init ( uint16  width,
uint16  height,
uint16  pitch,
void pixels,
const PixelFormat format 
)

Set up the Surface with user specified data.

Note that this simply sets the 'internal' attributes of the Surface. It will not take care of freeing old data via free or similar!

Parameters
widthWidth of the pixel data.
heightHeight of the pixel data.
pitchThe pitch of the pixel data.
pixelsThe pixel data itself.
formatThe pixel format of the pixel data.

Definition at line 86 of file surface.cpp.

◆ move()

void Graphics::Surface::move ( int  dx,
int  dy,
int  height 
)

Definition at line 279 of file surface.cpp.

◆ setPixels()

void Graphics::Surface::setPixels ( void newPixels)
inline

Sets the pixel data.

Note that this is a simply a setter. Be careful what you are doing!

Parameters
newPixelsThe new pixel data.

Definition at line 110 of file surface.h.

◆ vLine()

void Graphics::Surface::vLine ( int  x,
int  y,
int  y2,
uint32  color 
)

Draw a vertical line.

Parameters
xThe x coordinate of the line.
yThe start y coordiante of the line.
y2The end y coordinate of the line. In case y > y2 the coordinates are swapped.
colorThe color of the line.

Definition at line 191 of file surface.cpp.

Member Data Documentation

◆ format

PixelFormat Graphics::Surface::format

The pixel format of the surface.

Definition at line 77 of file surface.h.

◆ h

uint16 Graphics::Surface::h

The height of the surface.

Definition at line 58 of file surface.h.

◆ pitch

uint16 Graphics::Surface::pitch

The number of bytes a pixel line has.

Note that this might not equal w * bytesPerPixel.

Definition at line 65 of file surface.h.

◆ pixels

void* Graphics::Surface::pixels
protected

The surface's pixel data.

Definition at line 71 of file surface.h.

◆ w

uint16 Graphics::Surface::w

The width of the surface.

Definition at line 53 of file surface.h.


The documentation for this struct was generated from the following files: