aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
authorJohannes Schickel2011-04-17 15:17:42 +0200
committerJohannes Schickel2011-04-17 15:17:42 +0200
commit4fd3e3d6fe72b6b978fbc5e9e0b5218741d15c83 (patch)
tree1f81a65bd83045e39794067a4e1adf958188ef10 /graphics
parent886ea29bbfe5556729843d97637ea9f691382ddc (diff)
downloadscummvm-rg350-4fd3e3d6fe72b6b978fbc5e9e0b5218741d15c83.tar.gz
scummvm-rg350-4fd3e3d6fe72b6b978fbc5e9e0b5218741d15c83.tar.bz2
scummvm-rg350-4fd3e3d6fe72b6b978fbc5e9e0b5218741d15c83.zip
GRAPHICS: Add a PixelFormat member to Surface.
Diffstat (limited to 'graphics')
-rw-r--r--graphics/surface.cpp17
-rw-r--r--graphics/surface.h21
2 files changed, 36 insertions, 2 deletions
diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index f06c24c2cd..eadc464da4 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -53,13 +53,27 @@ void Surface::create(uint16 width, uint16 height, uint8 bytesPP) {
w = width;
h = height;
- bytesPerPixel = bytesPP;
+ format = PixelFormat();
+ format.bytesPerPixel = bytesPerPixel = bytesPP;
pitch = w * bytesPP;
pixels = calloc(width * height, bytesPP);
assert(pixels);
}
+void Surface::create(uint16 width, uint16 height, const PixelFormat &f) {
+ free();
+
+ w = width;
+ h = height;
+ format = f;
+ bytesPerPixel = format.bytesPerPixel;
+ pitch = w * bytesPerPixel;
+
+ pixels = calloc(width * height, bytesPerPixel);
+ assert(pixels);
+}
+
void Surface::free() {
::free(pixels);
pixels = 0;
@@ -69,6 +83,7 @@ void Surface::free() {
void Surface::copyFrom(const Surface &surf) {
create(surf.w, surf.h, surf.bytesPerPixel);
+ format = surf.format;
memcpy(pixels, surf.pixels, h * pitch);
}
diff --git a/graphics/surface.h b/graphics/surface.h
index f9cb6cc474..3cc69fafdd 100644
--- a/graphics/surface.h
+++ b/graphics/surface.h
@@ -28,6 +28,8 @@
#include "common/scummsys.h"
#include "common/rect.h"
+#include "graphics/pixelformat.h"
+
namespace Graphics {
/**
@@ -70,9 +72,14 @@ struct Surface {
uint8 bytesPerPixel;
/**
+ * The pixel format of the surface.
+ */
+ PixelFormat format;
+
+ /**
* Construct a simple Surface object.
*/
- Surface() : w(0), h(0), pitch(0), pixels(0), bytesPerPixel(0) {
+ Surface() : w(0), h(0), pitch(0), pixels(0), bytesPerPixel(0), format() {
}
/**
@@ -110,6 +117,18 @@ struct Surface {
void create(uint16 width, uint16 height, uint8 bytesPP);
/**
+ * 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.
+ * @param format The pixel format the surface should use.
+ */
+ void create(uint16 width, uint16 height, const PixelFormat &format);
+
+ /**
* Release the memory used by the pixels memory of this surface. This is the
* counterpart to create().
*