ScummVM API documentation
Graphics::Surface Struct Reference

#include <surface.h>

Inheritance diagram for Graphics::Surface:
Draci::Surface Mortevielle::GfxSurface Mortevielle::ScreenSurface N3DS::Sprite Saga::Surface Scumm::VirtScreen TeenAgent::Surface

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::SurfaceconvertTo (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::Surfacescale (int16 newWidth, int16 newHeight, bool filtering=false) const
 
Graphics::Surfacerotoscale (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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Surface()

Graphics::Surface::Surface ( )
inline

Construct a simple Surface object.

Member Function Documentation

◆ getPixels() [1/2]

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

Return a pointer to the pixel data.

Returns
Pointer to the pixel data.

◆ getPixels() [2/2]

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

Return a pointer to the pixel data.

Returns
Pointer to the pixel data.

◆ setPixels()

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

Set the pixel data.

Note that this is a simply a setter. Be aware of that when using it.

Parameters
newPixelsThe new pixel data.

◆ 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.

◆ 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.

◆ getPixel()

uint32 Graphics::Surface::getPixel ( int  x,
int  y 
) const
inline

Return the pixel at the specified point.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
Returns
The value of the pixel.

◆ setPixel()

void Graphics::Surface::setPixel ( int  x,
int  y,
int  pixel 
)
inline

Set the pixel at the specified point.

Parameters
xThe x coordinate of the pixel.
yThe y coordinate of the pixel.
pixelThe value of the pixel.

◆ create()

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.

Parameters
widthWidth of the surface object.
heightHeight of the surface object.
formatThe pixel format to be used by the surface.

◆ free()

void Graphics::Surface::free ( )

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

This is the counterpart of create().

Important: Only use this if you created the surface data using create. Otherwise, this function has undefined behavior.

◆ init()

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.

Parameters
widthWidth of the pixel data.
heightHeight of the pixel data.
pitchPitch of the pixel data.
pixelsPixel data.
formatPixel format of the pixel data.

◆ copyFrom()

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

Copy the data from another surface.

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.

Parameters
surfThe surface to copy from.

◆ convertFrom()

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.

Parameters
surfThe surface to convert from.
formatThe pixel format to convert to.

◆ getSubArea() [1/2]

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.

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

◆ getSubArea() [2/2]

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.

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

◆ clip()

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.

◆ copyRectToSurface() [1/2]

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.

Parameters
bufferBuffer containing the graphics data source.
srcPitchPitch of the buffer (number of bytes in a scanline).
destXThe x coordinate of the destination rectangle.
destYThe y coordinate of the destination rectangle.
widthWidth of the destination rectangle.
heightHeight of the destination rectangle.

◆ copyRectToSurface() [2/2]

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.

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

◆ copyRectToSurfaceWithKey() [1/2]

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.

Parameters
bufferBuffer containing the graphics data source.
srcPitchPitch of the buffer (number of bytes in a scanline).
destXThe x coordinate of the destination rectangle.
destYThe y coordinate of the destination rectangle.
widthWidth of the destination rectangle.
heightHeight of the destination rectangle.
key

◆ copyRectToSurfaceWithKey() [2/2]

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.

Parameters
srcSurfaceSource of the bitmap data.
destXThe x coordinate of the destination rectangle.
destYThe y coordinate of the destination rectangle.
subRectThe subRect of the surface to be blitted.
key

◆ convertToInPlace() [1/2]

void Graphics::Surface::convertToInPlace ( const PixelFormat dstFormat)
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.

Parameters
dstFormatThe desired format.

◆ convertToInPlace() [2/2]

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.

Parameters
dstFormatThe desired format.
paletteThe palette (in RGB888), if the source format has one.
paletteCountThe number of colors in the palette.

◆ convertTo()

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.

Parameters
dstFormatThe desired format.
srcPaletteThe palette (in RGB888), if the source format has a bpp of 1.
srcPaletteCountThe color count in the for the srcPalette.
dstPaletteThe palette (in RGB888), If the destination format has a bpp of 1.
dstaletteCountThe color count in the for the dstPalette.
methodThe dithering method if destination format has a bpp of 1. Default is Floyd-Steinberg.

◆ 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 coordinate of the start point.
x1The x coordinate of the end point.
y1The y coordinate of the end point.
colorColor of the line.
Note
This is just a wrapper around Graphics::drawLine.

◆ 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 coordinate of the start point.
x1The x coordinate of the end point.
y1The y coordinate of the end point.
penXWidth of the pen (thickness in the x direction).
penYHeight of the pen (thickness in the y direction).
colorColor 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 leftmost part of the pen.

◆ 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 coordinate of the line.
x2The end x coordinate of the line. In case x > x2, the coordinates are swapped.
colorColor of the line.

◆ 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 coordinate of the line.
y2The end y coordinate of the line. In case y > y2, the coordinates are swapped.
colorColor of the line.

◆ fillRect()

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

Fill a rect with a given color.

Parameters
rThe rectangle to fill.
colorThe color to fill the rect with.

◆ frameRect()

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

Draw a frame around a specified rect.

Parameters
rThe rectangle to frame.
colorThe color of the frame.

◆ move()

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.

◆ flipVertical()

void Graphics::Surface::flipVertical ( const Common::Rect r)

Flip the specified rect vertically.

Parameters
rThe rectangle to flip.

◆ flipHorizontal()

void Graphics::Surface::flipHorizontal ( const Common::Rect r)

Flip the specified rect horizontally.

Parameters
rThe rectangle to flip.

◆ applyColorKey() [1/2]

bool Graphics::Surface::applyColorKey ( uint8  rKey,
uint8  gKey,
uint8  bKey,
bool  overwriteAlpha = false 
)

Writes a color key to the alpha channel of the surface

Parameters
rKeythe red component of the color key
gKeythe green component of the color key
bKeythe blue component of the color key
overwriteAlphaif true, all other alpha will be set fully opaque

◆ applyColorKey() [2/2]

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

Parameters
rKeythe red component of the color key
gKeythe green component of the color key
bKeythe blue component of the color key
overwriteAlphaif true, all other alpha will be set fully opaque
rNewthe red component to replace the color key with
gNewthe green component to replace the color key with
bNewthe blue component to replace the color key with

◆ setAlpha()

bool Graphics::Surface::setAlpha ( uint8  alpha,
bool  skipTransparent = false 
)

Sets alpha channel for all pixels to specified value

Parameters
alphavalue of the alpha channel to set
skipTransparentif set to true, then do not touch pixels with alpha=0

◆ detectAlpha()

AlphaType Graphics::Surface::detectAlpha ( ) const

Checks if the given surface contains alpha transparency

◆ scale()

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.

Parameters
newWidthThe resulting width.
newHeightThe resulting height.
filteringWhether or not to use bilinear filtering.

◆ rotoscale()

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.

Parameters
transforma TransformStruct wrapping the required info.
See also
TransformStruct
Parameters
filteringWhether or not to use bilinear filtering.

◆ debugPrint()

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

Parameters
debugleveldebug level to print at, default is 0.
widthwidth of the printed area in pixels. Default is 0 which is whole surface.
heightheight of the printed area in pixels. Default is 0 which is whole surface.
xhorizontal offset to the print area. Default is 0.
yvertical offset to the print area. Default is 0.
scalenumber of pixels per single character. Default is -1, fit whole surface to maxwidth
maxwidthhorizontal size of the print out in characters. Default is 160. Note that 2 characters are taken by the frame
palettepalette to use for 1bpp pixels. If omitted, we assume grayscale palette

Member Data Documentation

◆ w

int16 Graphics::Surface::w

Width of the surface.

◆ h

int16 Graphics::Surface::h

Height of the surface.

◆ pitch

int32 Graphics::Surface::pitch

Number of bytes in a pixel line.

Note
This might not equal w * bytesPerPixel.

◆ pixels

void* Graphics::Surface::pixels
protected

Pixel data of the surface.

◆ format

PixelFormat Graphics::Surface::format

Pixel format of the surface.


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