Created
July 29, 2014 22:35
-
-
Save jyhjuzi/9588ff61cd446a9761a3 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
package Chapter5; | |
public class Q5_8{ | |
static void drawHorizontalLine(byte[] screen, int width, int x1, int x2, int y){ | |
int height = screen.length/width/8; | |
int startOffset = x1%8; | |
int firstFullByte = x1/8; | |
if(startOffset!=0) | |
firstFullByte ++; | |
int endOffset = x2%8; | |
int lastFullByte = x2/8; | |
if(endOffset !=7) | |
lastFullByte --; | |
for(int i = firstFullByte; i <= lastFullByte; i++){ | |
screen[y*width/8+i]=(byte) 0xff; | |
} | |
byte startMask = (byte) (0xff >> startOffset); | |
byte endMask = (byte) ~(0xff>>(endOffset+1)); | |
if(x1/8 == x2/8){ | |
byte wholeMask = (byte) (startMask & endMask); | |
screen[y*width/8+x1/8]|=wholeMask; | |
} | |
else if(startOffset!=0){ | |
screen[y*width/8+firstFullByte-1] |= startMask; | |
} | |
else if(endOffset!=7) | |
screen[y*width/8+lastFullByte+1] |= endMask; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment