aboutsummaryrefslogtreecommitdiff
path: root/graphics/surface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/surface.cpp')
-rw-r--r--graphics/surface.cpp17
1 files changed, 16 insertions, 1 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);
}