Skip to content

Instantly share code, notes, and snippets.

@iwilbert
Created August 7, 2014 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwilbert/da3752677be59a63da20 to your computer and use it in GitHub Desktop.
Save iwilbert/da3752677be59a63da20 to your computer and use it in GitHub Desktop.
public static void drawHorizontalLine(byte[] screen, int width, int x1, int x2, int y) {
int height = screen.length / width;
if (y < 0 || y >= height || x1 < 0 || x1 >= screen.length * 8 || x2 < 0 || x2 >= screen.length * 8)
return;
int base = y * width / 8;
int start = base + x1 / 8;
int end = base + x2 / 8;
byte mask1;
if (x1 % 8 == 0)
mask1 = (byte) ~0;
else
mask1 = (byte) ((byte) (1 << (8 - x1 % 8)) - 1);
byte mask2 = (byte) (~0 << (8 - x2 % 8 - 1));
if (start == end)
screen[start] |= mask1 & mask2;
else {
screen[start] |= mask1;
screen[end] |= mask2;
}
for (int i = start + 1; i < end; i++)
screen[i] |= (byte) ~0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment