sync with scummvm
This commit is contained in:
parent
ce9e1899e4
commit
0f5de71f70
110 changed files with 1342 additions and 544 deletions
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "common/algorithm.h"
|
||||
#include "common/util.h"
|
||||
#include "common/endian.h"
|
||||
#include "common/rect.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "graphics/primitives.h"
|
||||
#include "graphics/surface.h"
|
||||
|
@ -41,23 +41,23 @@ static void plotPoint(int x, int y, int color, void *data) {
|
|||
}
|
||||
|
||||
void Surface::drawLine(int x0, int y0, int x1, int y1, uint32 color) {
|
||||
if (bytesPerPixel == 1)
|
||||
if (format.bytesPerPixel == 1)
|
||||
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<byte>, this);
|
||||
else if (bytesPerPixel == 2)
|
||||
else if (format.bytesPerPixel == 2)
|
||||
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint16>, this);
|
||||
else
|
||||
error("Surface::drawLine: bytesPerPixel must be 1 or 2");
|
||||
}
|
||||
|
||||
void Surface::create(uint16 width, uint16 height, uint8 bytesPP) {
|
||||
void Surface::create(uint16 width, uint16 height, const PixelFormat &f) {
|
||||
free();
|
||||
|
||||
w = width;
|
||||
h = height;
|
||||
bytesPerPixel = bytesPP;
|
||||
pitch = w * bytesPP;
|
||||
format = f;
|
||||
pitch = w * format.bytesPerPixel;
|
||||
|
||||
pixels = calloc(width * height, bytesPP);
|
||||
pixels = calloc(width * height, format.bytesPerPixel);
|
||||
assert(pixels);
|
||||
}
|
||||
|
||||
|
@ -65,11 +65,11 @@ void Surface::free() {
|
|||
::free(pixels);
|
||||
pixels = 0;
|
||||
w = h = pitch = 0;
|
||||
bytesPerPixel = 0;
|
||||
format = PixelFormat();
|
||||
}
|
||||
|
||||
void Surface::copyFrom(const Surface &surf) {
|
||||
create(surf.w, surf.h, surf.bytesPerPixel);
|
||||
create(surf.w, surf.h, surf.format);
|
||||
memcpy(pixels, surf.pixels, h * pitch);
|
||||
}
|
||||
|
||||
|
@ -89,10 +89,10 @@ void Surface::hLine(int x, int y, int x2, uint32 color) {
|
|||
if (x2 < x)
|
||||
return;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
if (format.bytesPerPixel == 1) {
|
||||
byte *ptr = (byte *)getBasePtr(x, y);
|
||||
memset(ptr, (byte)color, x2-x+1);
|
||||
} else if (bytesPerPixel == 2) {
|
||||
} else if (format.bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(x, y);
|
||||
Common::set_to(ptr, ptr + (x2-x+1), (uint16)color);
|
||||
} else {
|
||||
|
@ -113,13 +113,13 @@ void Surface::vLine(int x, int y, int y2, uint32 color) {
|
|||
if (y2 >= h)
|
||||
y2 = h - 1;
|
||||
|
||||
if (bytesPerPixel == 1) {
|
||||
if (format.bytesPerPixel == 1) {
|
||||
byte *ptr = (byte *)getBasePtr(x, y);
|
||||
while (y++ <= y2) {
|
||||
*ptr = (byte)color;
|
||||
ptr += pitch;
|
||||
}
|
||||
} else if (bytesPerPixel == 2) {
|
||||
} else if (format.bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(x, y);
|
||||
while (y++ <= y2) {
|
||||
*ptr = (uint16)color;
|
||||
|
@ -141,13 +141,13 @@ void Surface::fillRect(Common::Rect r, uint32 color) {
|
|||
int height = r.height();
|
||||
bool useMemset = true;
|
||||
|
||||
if (bytesPerPixel == 2) {
|
||||
if (format.bytesPerPixel == 2) {
|
||||
lineLen *= 2;
|
||||
if ((uint16)color != ((color & 0xff) | (color & 0xff) << 8))
|
||||
useMemset = false;
|
||||
} else if (bytesPerPixel == 4) {
|
||||
} else if (format.bytesPerPixel == 4) {
|
||||
useMemset = false;
|
||||
} else if (bytesPerPixel != 1) {
|
||||
} else if (format.bytesPerPixel != 1) {
|
||||
error("Surface::fillRect: bytesPerPixel must be 1, 2 or 4");
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ void Surface::fillRect(Common::Rect r, uint32 color) {
|
|||
ptr += pitch;
|
||||
}
|
||||
} else {
|
||||
if (bytesPerPixel == 2) {
|
||||
if (format.bytesPerPixel == 2) {
|
||||
uint16 *ptr = (uint16 *)getBasePtr(r.left, r.top);
|
||||
while (height--) {
|
||||
Common::set_to(ptr, ptr + width, (uint16)color);
|
||||
|
@ -186,7 +186,7 @@ void Surface::move(int dx, int dy, int height) {
|
|||
if ((dx == 0 && dy == 0) || height <= 0)
|
||||
return;
|
||||
|
||||
if (bytesPerPixel != 1 && bytesPerPixel != 2)
|
||||
if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2)
|
||||
error("Surface::move: bytesPerPixel must be 1 or 2");
|
||||
|
||||
byte *src, *dst;
|
||||
|
@ -216,37 +216,37 @@ void Surface::move(int dx, int dy, int height) {
|
|||
// horizontal movement
|
||||
if (dx > 0) {
|
||||
// move right - copy from right to left
|
||||
dst = (byte *)pixels + (pitch - bytesPerPixel);
|
||||
src = dst - (dx * bytesPerPixel);
|
||||
dst = (byte *)pixels + (pitch - format.bytesPerPixel);
|
||||
src = dst - (dx * format.bytesPerPixel);
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = dx; x < w; x++) {
|
||||
if (bytesPerPixel == 1) {
|
||||
if (format.bytesPerPixel == 1) {
|
||||
*dst-- = *src--;
|
||||
} else if (bytesPerPixel == 2) {
|
||||
} else if (format.bytesPerPixel == 2) {
|
||||
*(uint16 *)dst = *(const uint16 *)src;
|
||||
src -= 2;
|
||||
dst -= 2;
|
||||
}
|
||||
}
|
||||
src += pitch + (pitch - dx * bytesPerPixel);
|
||||
dst += pitch + (pitch - dx * bytesPerPixel);
|
||||
src += pitch + (pitch - dx * format.bytesPerPixel);
|
||||
dst += pitch + (pitch - dx * format.bytesPerPixel);
|
||||
}
|
||||
} else if (dx < 0) {
|
||||
// move left - copy from left to right
|
||||
dst = (byte *)pixels;
|
||||
src = dst - (dx * bytesPerPixel);
|
||||
src = dst - (dx * format.bytesPerPixel);
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = -dx; x < w; x++) {
|
||||
if (bytesPerPixel == 1) {
|
||||
if (format.bytesPerPixel == 1) {
|
||||
*dst++ = *src++;
|
||||
} else if (bytesPerPixel == 2) {
|
||||
} else if (format.bytesPerPixel == 2) {
|
||||
*(uint16 *)dst = *(const uint16 *)src;
|
||||
src += 2;
|
||||
dst += 2;
|
||||
}
|
||||
}
|
||||
src += pitch - (pitch + dx * bytesPerPixel);
|
||||
dst += pitch - (pitch + dx * bytesPerPixel);
|
||||
src += pitch - (pitch + dx * format.bytesPerPixel);
|
||||
dst += pitch - (pitch + dx * format.bytesPerPixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue