Added convenience methods create/free to Graphics::Surface (part of patch #1163026)
svn-id: r17973
This commit is contained in:
parent
cf936916db
commit
315943f19a
2 changed files with 30 additions and 0 deletions
|
@ -46,6 +46,25 @@ void Surface::drawLine(int x0, int y0, int x1, int y1, uint32 color) {
|
||||||
error("Surface::drawLine: bytesPerPixel must be 1 or 2");
|
error("Surface::drawLine: bytesPerPixel must be 1 or 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Surface::create(uint16 width, uint16 height, uint8 bytesPP) {
|
||||||
|
free();
|
||||||
|
|
||||||
|
w = width;
|
||||||
|
h = height;
|
||||||
|
bytesPerPixel = bytesPP;
|
||||||
|
pitch = w * bytesPP;
|
||||||
|
|
||||||
|
pixels = calloc(width * height, bytesPP);
|
||||||
|
assert(pixels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Surface::free() {
|
||||||
|
::free(pixels);
|
||||||
|
pixels = 0;
|
||||||
|
w = h = pitch = 0;
|
||||||
|
bytesPerPixel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Surface::hLine(int x, int y, int x2, uint32 color) {
|
void Surface::hLine(int x, int y, int x2, uint32 color) {
|
||||||
// Clipping
|
// Clipping
|
||||||
if (y < 0 || y >= h)
|
if (y < 0 || y >= h)
|
||||||
|
|
|
@ -47,6 +47,17 @@ struct Surface {
|
||||||
return static_cast<void *>(static_cast<byte *>(pixels) + y * pitch + x * bytesPerPixel);
|
return static_cast<void *>(static_cast<byte *>(pixels) + y * pitch + x * bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate pixels memory for this surface and for the specified dimension.
|
||||||
|
*/
|
||||||
|
void create(uint16 width, uint16 height, uint8 bytesPP);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release the memory used by the pixels memory of this surface. This is the
|
||||||
|
* counterpart to create().
|
||||||
|
*/
|
||||||
|
void free();
|
||||||
|
|
||||||
void drawLine(int x0, int y0, int x1, int y1, uint32 color);
|
void drawLine(int x0, int y0, int x1, int y1, uint32 color);
|
||||||
void hLine(int x, int y, int x2, uint32 color);
|
void hLine(int x, int y, int x2, uint32 color);
|
||||||
void vLine(int x, int y, int y2, uint32 color);
|
void vLine(int x, int y, int y2, uint32 color);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue