Created
August 7, 2014 01:26
-
-
Save iwilbert/da3752677be59a63da20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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