Skip to content

Commit

Permalink
GRAPHICS: Allow auxiliary surface functions to be used for 32bpp surf…
Browse files Browse the repository at this point in the history
…aces
  • Loading branch information
Matthew Hoops committed May 19, 2011
1 parent e27dd8a commit 1ee5ef9
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions graphics/surface.cpp
Expand Up @@ -42,8 +42,10 @@ void Surface::drawLine(int x0, int y0, int x1, int y1, uint32 color) {
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<byte>, this);
else if (format.bytesPerPixel == 2)
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint16>, this);
else if (format.bytesPerPixel == 4)
Graphics::drawLine(x0, y0, x1, y1, color, plotPoint<uint32>, this);
else
error("Surface::drawLine: bytesPerPixel must be 1 or 2");
error("Surface::drawLine: bytesPerPixel must be 1, 2, or 4");
}

void Surface::create(uint16 width, uint16 height, const PixelFormat &f) {
Expand Down Expand Up @@ -92,8 +94,11 @@ void Surface::hLine(int x, int y, int x2, uint32 color) {
} else if (format.bytesPerPixel == 2) {
uint16 *ptr = (uint16 *)getBasePtr(x, y);
Common::set_to(ptr, ptr + (x2-x+1), (uint16)color);
} else if (format.bytesPerPixel == 4) {
uint32 *ptr = (uint32 *)getBasePtr(x, y);
Common::set_to(ptr, ptr + (x2-x+1), color);
} else {
error("Surface::hLine: bytesPerPixel must be 1 or 2");
error("Surface::hLine: bytesPerPixel must be 1, 2, or 4");
}
}

Expand Down Expand Up @@ -122,8 +127,15 @@ void Surface::vLine(int x, int y, int y2, uint32 color) {
*ptr = (uint16)color;
ptr += pitch/2;
}

} else if (format.bytesPerPixel == 4) {
uint32 *ptr = (uint32 *)getBasePtr(x, y);
while (y++ <= y2) {
*ptr = color;
ptr += pitch / 4;

This comment has been minimized.

Copy link
@lordhoto

lordhoto May 20, 2011

Contributor

That reminds me, we should really make our common code not believe that the pitch can be divided through 2 resp. 4 for 2 resp. 4 bpp surfaces.

This comment has been minimized.

Copy link
@wjp

wjp May 20, 2011

Contributor

Why? The two uses of pitch I've seen are increasing the alignment of the starts of pixel rows, and/or creating a subsurface of a surface with longer rows. In both of these cases this assumption is valid.

This comment has been minimized.

Copy link
@lordhoto

lordhoto May 20, 2011

Contributor

That's probably totally correct, sorry my fault.

}
} else {
error("Surface::vLine: bytesPerPixel must be 1 or 2");
error("Surface::vLine: bytesPerPixel must be 1, 2, or 4");
}
}

Expand Down Expand Up @@ -183,8 +195,8 @@ void Surface::move(int dx, int dy, int height) {
if ((dx == 0 && dy == 0) || height <= 0)
return;

if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2)
error("Surface::move: bytesPerPixel must be 1 or 2");
if (format.bytesPerPixel != 1 && format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
error("Surface::move: bytesPerPixel must be 1, 2, or 4");

byte *src, *dst;
int x, y;
Expand Down Expand Up @@ -223,6 +235,10 @@ void Surface::move(int dx, int dy, int height) {
*(uint16 *)dst = *(const uint16 *)src;
src -= 2;
dst -= 2;
} else if (format.bytesPerPixel == 4) {
*(uint32 *)dst = *(const uint32 *)src;
src -= 4;
dst -= 4;
}
}
src += pitch + (pitch - dx * format.bytesPerPixel);
Expand All @@ -240,6 +256,10 @@ void Surface::move(int dx, int dy, int height) {
*(uint16 *)dst = *(const uint16 *)src;
src += 2;
dst += 2;
} else if (format.bytesPerPixel == 4) {
*(uint32 *)dst = *(const uint32 *)src;
src += 4;
dst += 4;
}
}
src += pitch - (pitch + dx * format.bytesPerPixel);
Expand Down

0 comments on commit 1ee5ef9

Please sign in to comment.