GRAPHICS: Add a PixelFormat member to Surface.
This commit is contained in:
parent
886ea29bbf
commit
4fd3e3d6fe
2 changed files with 36 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "common/scummsys.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#include "graphics/pixelformat.h"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
/**
|
||||
|
@ -69,10 +71,15 @@ 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() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,6 +116,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().
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue