9.5-bit operation (eight)--monochrome screen draw horizontal line

Source: Internet
Author: User

/*** 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.