Linux: framebuffer Test Program

Source: Internet
Author: User

Set FB to 24-Bit mode:

Fbset-FB/dev/fb0-G 800 600 800 24-n

Fill FB with r g B:

Use-FB 255 0 0 // red

Use-FB 0 255 0 // green

...

 

Use-fb.c code:

/* Use-fb.c */

# Include <stdio. h>
# Include <fcntl. h>
# Include <Linux/FB. h>
# Include <sys/Mman. h>
# Include <stdlib. h>

Struct fb_var_screeninfo vinfo;

Int
Main (INT argc, char * argv [])
{
Int fbfd, fbsize, I;
Int red, green, blue;
Unsigned char * fbbuf;

If (argc! = 4 ){
Printf ("Usage: Use-FB red green blue/N ");
Exit (0 );
}
Red = atoi (argv [1]);
Green = atoi (argv [2]);
Blue = atoi (argv [3]);
 
/* Open video memory */
If (fbfd = open ("/dev/fb0", o_rdwr) <0 ){
Exit (1 );
}
/* Get variable display parameters */
If (IOCTL (fbfd, fbioget_vscreeninfo, & vinfo )){
Printf ("Bad vscreeninfo IOCTL/N ");
Exit (2 );
}
/* Size of Frame Buffer */
Fbsize = vinfo. xres * vinfo. yres * (vinfo. bits_per_pixel/8 );
/* Map video memory */
If (fbbuf = MMAP (0, fbsize, prot_read | prot_write,
Map_shared, fbfd, 0) = (void *)-1 ){
Exit (3 );
}
/* Clear the screen */
For (I = 0; I <fbsize; I ++ ){
* (Fbbuf + I ++) = red;
* (Fbbuf + I ++) = green;
* (Fbbuf + I) = blue;
}

Printf ("clear screen with RGB: % S % s/n", argv [1], argv [2], argv [3]);
Munmap (fbbuf, fbsize );
Close (fbfd );
}

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.