/*** Function: A monochrome screen is stored in a one-dimensional byte array, allowing 8 consecutive pixels to be stored in one byte. Screen width bit W,* and W can be divisible by 8 (that is, one byte is not spread over two lines) and the screen height can be inferred from the length of the array and the width of the screen. * Implementation Method Drawhorizontalline (byte[] screen,
intwidth,
intx1,
int x2,
inty), draw from Point (x1,y) * The horizontal line to the point (x2,y). */
<pre name= "code" class= "java" >/** * idea: Use SCREEN[BYTE_POS]=0XFF to set an entire byte at a time. The bit of the beginning and end of the remainder, using the mask setting. * @param screen * @param width * @param x1 * @param x2 * @param y */public static void Drawhorizontalline (byte[] Screen,in T width,int x1,int x2,int y) {int startoffset=x1%8;int firstfullbyte=x1/8;if (startoffset!=0) firstFullByte++;int Endoffset=x2%8;int lastfullbyte=x2/8;if (endoffset!=7) lastfullbyte--;//set the full byte for (int i=firstfullbyte;i<= lastfullbyte;i++) {screen[(WIDTH/8) *y+i]= (byte) 0xFF;} Creates a mask for the start and end of the line byte startmask= (byte) (1>>startoffset); byte endmask= (byte) ~ (1>> (endoffset+1));// Sets the start and end point of the line if ((X1/8) = = (X2/8)) {byte mask= (byte) (startmask&endmask); screen[(WIDTH/8) *y+ (X1/8)]|=mask;} Else{if (startoffset!=0) {int bytenumber= (WIDTH/8) *y+firstfullbyte-1;screen[bytenumber]|=startmask;} if (endoffset!=0) {int bytenumber= (WIDTH/8) *y+lastfullbyte+1;screen[bytenumber]|=endmask;}}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
9.5-bit operation (eight)--monochrome screen draw horizontal line