static void fillScreen(byte[] buf, pBGRA color, int pixelWidth) { int stride = (pixelWidth * 32) / 8; int pixelHeight = buf.Length / stride; for (int y = 0; y < pixelHeight; y++) { for (int x = 0; x < pixelWidth; x++) { printPixel(buf, x, y, color, pixelWidth); } } }
static void printPixel(byte[] buf, int x, int y, pBGRA color, int pixelWidth) { int blue = color.blue; int green = color.green; int red = color.red; int alpha = color.alpha; int pixelOffset = (x + y * pixelWidth) * 32 / 8; buf[pixelOffset] = (byte)blue; buf[pixelOffset + 1] = (byte)green; buf[pixelOffset + 2] = (byte)red; buf[pixelOffset + 3] = (byte)alpha; }
static void printLine(byte[] buf, pLine lineCoords, pBGRA color, int pixelWidth) { int stride = (pixelWidth * 32) / 8; int pixelHeight = buf.Length / stride; int x0 = lineCoords.x0; int y0 = lineCoords.y0; int x1 = lineCoords.x1; int y1 = lineCoords.y1; int dx = Math.Abs(x1 - x0); int sx = x0 < x1 ? 1 : -1; int dy = Math.Abs(y1 - y0); int sy = y0 < y1 ? 1 : -1; int err = (dx > dy ? dx : -dy) / 2; int e2; for (; ;) { if (!(x0 >= pixelWidth || y0 >= pixelHeight || x0 < 0 || y0 < 0)) { printPixel(buf, x0, y0, color, pixelWidth); } if (x0 == x1 && y0 == y1) { break; } e2 = err; if (e2 > -dx) { err -= dy; x0 += sx; } if (e2 < dy) { err += dx; y0 += sy; } } }
static void lmoveScreen(byte[] buf, pBGRA fillColor, int moveAmt, int pixelWidth) { int stride = (pixelWidth * 32) / 8; int pixelHeight = buf.Length / stride; for (int y = 0; y < pixelHeight; y++) { for (int x = 0; x < pixelWidth; x++) { int nextPixel = x + moveAmt; if (nextPixel < pixelWidth) { int pixelOffset = (nextPixel + y * pixelWidth) * 32 / 8; printPixel(buf, x, y, new pBGRA(buf[pixelOffset], buf[pixelOffset + 1], buf[pixelOffset + 2], buf[pixelOffset + 3]), pixelWidth); } else { printPixel(buf, x, y, fillColor, pixelWidth); } } } }