From 4fd3e3d6fe72b6b978fbc5e9e0b5218741d15c83 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 17 Apr 2011 15:17:42 +0200 Subject: GRAPHICS: Add a PixelFormat member to Surface. --- graphics/surface.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'graphics/surface.cpp') 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); } -- cgit v1.2.3