2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2004-03-21 21:20:25 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2004-03-21 21:20:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GRAPHICS_SURFACE_H
|
|
|
|
#define GRAPHICS_SURFACE_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2016-06-02 21:44:43 +00:00
|
|
|
#include "common/list.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
struct Rect;
|
2016-06-02 21:44:43 +00:00
|
|
|
struct Point;
|
2011-04-24 08:34:27 +00:00
|
|
|
}
|
2004-03-21 21:20:25 +00:00
|
|
|
|
2011-04-17 13:17:42 +00:00
|
|
|
#include "graphics/pixelformat.h"
|
|
|
|
|
2004-03-21 21:20:25 +00:00
|
|
|
namespace Graphics {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An arbitrary graphics surface, which can be the target (or source) of blit
|
|
|
|
* operations, font rendering, etc.
|
|
|
|
*/
|
|
|
|
struct Surface {
|
2011-01-07 12:26:01 +00:00
|
|
|
/*
|
|
|
|
* IMPORTANT implementation specific detail:
|
|
|
|
*
|
|
|
|
* ARM code relies on the layout of the first 3 of these fields. Do not
|
|
|
|
* change them.
|
|
|
|
*/
|
|
|
|
|
2008-12-22 11:22:15 +00:00
|
|
|
/**
|
2011-01-07 12:26:01 +00:00
|
|
|
* The width of the surface.
|
2008-12-22 11:22:15 +00:00
|
|
|
*/
|
2004-03-21 21:20:25 +00:00
|
|
|
uint16 w;
|
2011-01-07 12:26:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The height of the surface.
|
|
|
|
*/
|
2004-03-21 21:20:25 +00:00
|
|
|
uint16 h;
|
2011-01-07 12:26:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of bytes a pixel line has.
|
|
|
|
*
|
|
|
|
* Note that this might not equal w * bytesPerPixel.
|
|
|
|
*/
|
2004-03-21 21:20:25 +00:00
|
|
|
uint16 pitch;
|
2011-01-07 12:26:01 +00:00
|
|
|
|
2013-08-06 01:51:49 +00:00
|
|
|
protected:
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* The surface's pixel data.
|
|
|
|
*/
|
2008-02-03 21:13:56 +00:00
|
|
|
void *pixels;
|
2011-01-07 12:26:01 +00:00
|
|
|
|
2013-08-06 01:51:49 +00:00
|
|
|
public:
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
2011-04-17 13:17:42 +00:00
|
|
|
* The pixel format of the surface.
|
2011-01-07 12:26:01 +00:00
|
|
|
*/
|
2011-04-17 13:17:42 +00:00
|
|
|
PixelFormat format;
|
2004-11-25 23:33:21 +00:00
|
|
|
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* Construct a simple Surface object.
|
|
|
|
*/
|
2011-04-17 19:27:34 +00:00
|
|
|
Surface() : w(0), h(0), pitch(0), pixels(0), format() {
|
2011-01-07 12:26:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 00:22:59 +00:00
|
|
|
/**
|
|
|
|
* Return a pointer to the pixel data.
|
|
|
|
*
|
|
|
|
* @return Pointer to the pixel data.
|
|
|
|
*/
|
|
|
|
inline const void *getPixels() const {
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the pixel data.
|
|
|
|
*
|
|
|
|
* @return Pointer to the pixel data.
|
|
|
|
*/
|
|
|
|
inline void *getPixels() {
|
|
|
|
return pixels;
|
|
|
|
}
|
|
|
|
|
2013-08-03 01:42:37 +00:00
|
|
|
/**
|
|
|
|
* Sets the pixel data.
|
|
|
|
*
|
2013-08-03 23:01:15 +00:00
|
|
|
* Note that this is a simply a setter. Be careful what you are doing!
|
2013-08-03 01:42:37 +00:00
|
|
|
*
|
|
|
|
* @param newPixels The new pixel data.
|
|
|
|
*/
|
|
|
|
void setPixels(void *newPixels) { pixels = newPixels; }
|
|
|
|
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* Return a pointer to the pixel at the specified point.
|
|
|
|
*
|
|
|
|
* @param x The x coordinate of the pixel.
|
|
|
|
* @param y The y coordinate of the pixel.
|
|
|
|
* @return Pointer to the pixel.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
inline const void *getBasePtr(int x, int y) const {
|
2011-04-17 15:30:44 +00:00
|
|
|
return (const byte *)(pixels) + y * pitch + x * format.bytesPerPixel;
|
2005-05-02 18:00:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* Return a pointer to the pixel at the specified point.
|
|
|
|
*
|
|
|
|
* @param x The x coordinate of the pixel.
|
|
|
|
* @param y The y coordinate of the pixel.
|
|
|
|
* @return Pointer to the pixel.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
inline void *getBasePtr(int x, int y) {
|
2011-04-17 15:30:44 +00:00
|
|
|
return static_cast<byte *>(pixels) + y * pitch + x * format.bytesPerPixel;
|
2004-11-25 23:33:21 +00:00
|
|
|
}
|
2005-05-08 12:33:55 +00:00
|
|
|
|
2005-05-08 21:24:33 +00:00
|
|
|
/**
|
2011-01-07 12:26:01 +00:00
|
|
|
* Allocate memory for the pixel data of the surface.
|
|
|
|
*
|
|
|
|
* Note that you are responsible for calling free yourself.
|
|
|
|
* @see free
|
|
|
|
*
|
|
|
|
* @param width Width of the surface object.
|
|
|
|
* @param height Height of the surface object.
|
2011-04-17 13:17:42 +00:00
|
|
|
* @param format The pixel format the surface should use.
|
2005-05-08 21:24:33 +00:00
|
|
|
*/
|
2011-04-17 13:17:42 +00:00
|
|
|
void create(uint16 width, uint16 height, const PixelFormat &format);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-05-08 21:24:33 +00:00
|
|
|
/**
|
|
|
|
* Release the memory used by the pixels memory of this surface. This is the
|
|
|
|
* counterpart to create().
|
2011-01-07 12:26:01 +00:00
|
|
|
*
|
|
|
|
* Note that you should only use this, when you created the Surface data via
|
|
|
|
* create! Otherwise this function has undefined behavior.
|
|
|
|
* @see create
|
2005-05-08 21:24:33 +00:00
|
|
|
*/
|
|
|
|
void free();
|
|
|
|
|
2013-08-03 01:42:37 +00:00
|
|
|
/**
|
|
|
|
* 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!
|
|
|
|
*
|
|
|
|
* @param width Width of the pixel data.
|
|
|
|
* @param height Height of the pixel data.
|
|
|
|
* @param pitch The pitch of the pixel data.
|
|
|
|
* @param pixels The pixel data itself.
|
|
|
|
* @param format The pixel format of the pixel data.
|
|
|
|
*/
|
|
|
|
void init(uint16 width, uint16 height, uint16 pitch, void *pixels, const PixelFormat &format);
|
|
|
|
|
2008-09-16 14:10:55 +00:00
|
|
|
/**
|
2011-01-07 12:26:01 +00:00
|
|
|
* 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 create
|
|
|
|
* @see free
|
|
|
|
*
|
|
|
|
* @param surf Surface to copy from.
|
2008-09-16 14:10:55 +00:00
|
|
|
*/
|
|
|
|
void copyFrom(const Surface &surf);
|
|
|
|
|
2013-08-02 16:37:12 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param area The area which should be represented. Note that the area
|
|
|
|
* will get clipped in case it does not fit!
|
|
|
|
*/
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param area The area which should be represented. Note that the area
|
|
|
|
* will get clipped in case it does not fit!
|
|
|
|
*/
|
|
|
|
const Surface getSubArea(const Common::Rect &area) const;
|
|
|
|
|
2013-08-15 00:42:56 +00:00
|
|
|
/**
|
|
|
|
* Copies a bitmap to the Surface internal buffer. The pixel format
|
|
|
|
* of buffer must match the pixel format of the Surface.
|
|
|
|
*
|
|
|
|
* @param buffer The buffer containing the graphics data source
|
2014-08-29 01:26:48 +00:00
|
|
|
* @param srcPitch The pitch of the buffer (number of bytes in a scanline)
|
2013-09-12 14:30:28 +00:00
|
|
|
* @param destX The x coordinate of the destination rectangle
|
|
|
|
* @param destY The y coordinate of the destination rectangle
|
2013-08-15 00:42:56 +00:00
|
|
|
* @param width The width of the destination rectangle
|
|
|
|
* @param height The height of the destination rectangle
|
|
|
|
*/
|
2013-09-22 20:53:15 +00:00
|
|
|
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height);
|
2013-09-12 14:30:28 +00:00
|
|
|
/**
|
|
|
|
* Copies a bitmap to the Surface internal buffer. The pixel format
|
|
|
|
* of buffer must match the pixel format of the Surface.
|
|
|
|
*
|
|
|
|
* @param srcSurface The source of the bitmap data
|
|
|
|
* @param destX The x coordinate of the destination rectangle
|
|
|
|
* @param destY The y coordinate of the destination rectangle
|
2014-09-03 12:27:41 +00:00
|
|
|
* @param subRect The subRect of surface to be blitted
|
2013-09-12 14:30:28 +00:00
|
|
|
*/
|
|
|
|
void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect);
|
2013-08-15 00:42:56 +00:00
|
|
|
|
2011-06-30 12:12:39 +00:00
|
|
|
/**
|
|
|
|
* Convert the data to another pixel format.
|
2012-07-14 04:03:04 +00:00
|
|
|
*
|
|
|
|
* This works in-place. This means it will not create an additional buffer
|
2013-08-02 16:37:12 +00:00
|
|
|
* for the conversion process. The value of 'pixels' might change though
|
|
|
|
* (that means it might realloc the pixel data).
|
2012-07-14 04:03:04 +00:00
|
|
|
*
|
|
|
|
* Note that you should only use this, when you created the Surface data via
|
|
|
|
* create! Otherwise this function has undefined behavior.
|
|
|
|
*
|
|
|
|
* @param dstFormat The desired format
|
|
|
|
* @param palette The palette (in RGB888), if the source format has a Bpp of 1
|
|
|
|
*/
|
|
|
|
void convertToInPlace(const PixelFormat &dstFormat, const byte *palette = 0);
|
|
|
|
|
2011-06-30 12:12:39 +00:00
|
|
|
/**
|
|
|
|
* Convert the data to another pixel format.
|
|
|
|
*
|
|
|
|
* The calling code must call free on the returned surface and then delete
|
|
|
|
* it.
|
|
|
|
*
|
|
|
|
* @param dstFormat The desired format
|
|
|
|
* @param palette The palette (in RGB888), if the source format has a Bpp of 1
|
|
|
|
*/
|
|
|
|
Graphics::Surface *convertTo(const PixelFormat &dstFormat, const byte *palette = 0) const;
|
|
|
|
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* Draw a line.
|
|
|
|
*
|
|
|
|
* @param x0 The x coordinate of the start point.
|
|
|
|
* @param y0 The y coordiante of the start point.
|
|
|
|
* @param x1 The x coordinate of the end point.
|
|
|
|
* @param y1 The y coordinate of the end point.
|
|
|
|
* @param color The color of the line.
|
2011-10-27 23:20:28 +00:00
|
|
|
* @note This is just a wrapper around Graphics::drawLine
|
2011-01-07 12:26:01 +00:00
|
|
|
*/
|
2005-05-08 12:33:55 +00:00
|
|
|
void drawLine(int x0, int y0, int x1, int y1, uint32 color);
|
2011-01-07 12:26:01 +00:00
|
|
|
|
2011-10-27 23:20:28 +00:00
|
|
|
/**
|
|
|
|
* Draw a thick line.
|
|
|
|
*
|
|
|
|
* @param x0 The x coordinate of the start point.
|
|
|
|
* @param y0 The y coordiante of the start point.
|
|
|
|
* @param x1 The x coordinate of the end point.
|
|
|
|
* @param y1 The y coordinate of the end point.
|
|
|
|
* @param penX The width of the pen (thickness in the x direction)
|
|
|
|
* @param penY The height of the pen (thickness in the y direction)
|
|
|
|
* @param color The color of the line.
|
|
|
|
* @note This is just a wrapper around Graphics::drawThickLine
|
|
|
|
* @note The x/y coordinates of the start and end points are the upper-left most part of the pen
|
|
|
|
*/
|
|
|
|
void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color);
|
|
|
|
|
2011-01-07 12:26:01 +00:00
|
|
|
/**
|
|
|
|
* Draw a horizontal line.
|
|
|
|
*
|
|
|
|
* @param x The start x coordinate of the line.
|
|
|
|
* @param y The y coordiante of the line.
|
|
|
|
* @param x2 The end x coordinate of the line.
|
|
|
|
* In case x > x2 the coordinates are swapped.
|
|
|
|
* @param color The color of the line.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
void hLine(int x, int y, int x2, uint32 color);
|
2011-01-07 12:26:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a vertical line.
|
|
|
|
*
|
|
|
|
* @param x The x coordinate of the line.
|
|
|
|
* @param y The start y coordiante of the line.
|
|
|
|
* @param y2 The end y coordinate of the line.
|
|
|
|
* In case y > y2 the coordinates are swapped.
|
|
|
|
* @param color The color of the line.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
void vLine(int x, int y, int y2, uint32 color);
|
2011-01-07 12:26:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill a rect with a given color.
|
|
|
|
*
|
|
|
|
* @param r Rect to fill
|
|
|
|
* @param color The color of the rect's contents.
|
|
|
|
*/
|
2007-11-06 23:03:19 +00:00
|
|
|
void fillRect(Common::Rect r, uint32 color);
|
2011-01-07 12:26:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a frame around a specified rect.
|
|
|
|
*
|
|
|
|
* @param r Rect to frame
|
|
|
|
* @param color The color of the frame.
|
|
|
|
*/
|
2005-05-02 18:00:05 +00:00
|
|
|
void frameRect(const Common::Rect &r, uint32 color);
|
2011-01-07 12:26:01 +00:00
|
|
|
|
2007-11-06 23:03:19 +00:00
|
|
|
// See comment in graphics/surface.cpp about it
|
2006-06-21 11:33:04 +00:00
|
|
|
void move(int dx, int dy, int height);
|
2004-03-21 21:20:25 +00:00
|
|
|
};
|
|
|
|
|
2008-09-16 14:10:55 +00:00
|
|
|
/**
|
2011-01-07 12:26:01 +00:00
|
|
|
* A deleter for Surface objects which can be used with SharedPtr.
|
2011-06-19 22:59:48 +00:00
|
|
|
*
|
2011-01-07 12:26:01 +00:00
|
|
|
* This deleter assures Surface::free is called on deletion.
|
2008-09-16 14:10:55 +00:00
|
|
|
*/
|
2017-11-18 05:28:15 +00:00
|
|
|
struct SurfaceDeleter {
|
2008-09-16 14:10:55 +00:00
|
|
|
void operator()(Surface *ptr) {
|
2013-11-27 18:44:54 +00:00
|
|
|
if (ptr) {
|
|
|
|
ptr->free();
|
|
|
|
}
|
2008-09-16 14:10:55 +00:00
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-03 14:39:03 +00:00
|
|
|
/**
|
|
|
|
* Stack-based flood fill algorithm for arbitrary Surfaces.
|
|
|
|
*
|
|
|
|
* It could be used in 2 ways. One is to fill the pixels of oldColor
|
|
|
|
* with fillColor. Second is when the surface stays intact but another
|
|
|
|
* surface with mask is created, where filled colors are marked with 255.
|
|
|
|
*
|
|
|
|
* Before running fill() or fillMask(), the initial pixels must be addSeed
|
|
|
|
* with addSeed() method.
|
|
|
|
*/
|
2016-06-02 21:44:43 +00:00
|
|
|
class FloodFill {
|
|
|
|
public:
|
2016-06-03 14:39:03 +00:00
|
|
|
/**
|
|
|
|
* Construct a simple Surface object.
|
|
|
|
*
|
|
|
|
* @param surface Input surface
|
|
|
|
* @param oldColor Color on the surface to change
|
|
|
|
* @param fillColor Color to fill with
|
|
|
|
*/
|
2016-06-14 18:29:50 +00:00
|
|
|
FloodFill(Surface *surface, uint32 oldColor, uint32 fillColor, bool maskMode = false);
|
2016-06-02 21:44:43 +00:00
|
|
|
~FloodFill();
|
2016-06-03 14:39:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add pixels to the fill queue.
|
|
|
|
*
|
|
|
|
* @param x The x coordinate of the pixel.
|
|
|
|
* @param y The x coordinate of the pixel.
|
|
|
|
*/
|
2016-06-02 21:44:43 +00:00
|
|
|
void addSeed(int x, int y);
|
2016-06-03 14:39:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fill the surface as requested.
|
|
|
|
*
|
|
|
|
* It uses pixels which were added with addSeed() method.
|
|
|
|
*
|
|
|
|
* @see addSeed
|
|
|
|
*/
|
2016-06-02 21:44:43 +00:00
|
|
|
void fill();
|
|
|
|
|
2016-06-03 14:39:03 +00:00
|
|
|
/**
|
|
|
|
* Fill the mask. The mask is a CLUT8 Surface with pixels 0 and 255.
|
|
|
|
* 255 means that the pixel has been filled.
|
|
|
|
*
|
|
|
|
* It uses pixels which were added with addSeed() method.
|
|
|
|
*
|
|
|
|
* @see addSeed
|
|
|
|
*/
|
|
|
|
void fillMask();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the resulting mask.
|
|
|
|
*
|
|
|
|
* @see fillMask
|
|
|
|
*/
|
|
|
|
Surface *getMask() { return _mask; }
|
|
|
|
|
2016-06-02 21:44:43 +00:00
|
|
|
private:
|
|
|
|
Common::List<Common::Point *> _queue;
|
|
|
|
Surface *_surface;
|
2016-06-03 14:39:03 +00:00
|
|
|
Surface *_mask;
|
2016-06-02 21:44:43 +00:00
|
|
|
uint32 _oldColor, _fillColor;
|
|
|
|
byte *_visited;
|
|
|
|
int _w, _h;
|
2016-06-03 14:39:03 +00:00
|
|
|
|
|
|
|
bool _maskMode;
|
2016-06-02 21:44:43 +00:00
|
|
|
};
|
2004-03-21 21:20:25 +00:00
|
|
|
|
|
|
|
} // End of namespace Graphics
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|