In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "embedded Linux Framebuffer how to draw a line", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "embedded Linux Framebuffer how to draw a line" bar!
As the name implies, Frame means frame, and buffer is buffered. The color value of each pixel of each frame of the image is saved in Framebuffer.
The operating principle of LCD
The driver sets the LCD controller
Set the timing and signal polarity of LCD controller according to LCD parameters
BPP allocates Framebuffer based on LCD resolution
APP acquires LCD resolution, BPP and other parameters through ioctl
APP maps Framebuffer through mmap and writes data in Framebuffer. From the image above, you can see that the displayable areas of Framebuffer and LCD correspond one to one. Using Framebuffer display is actually writing color data for each pixel to Framebuffer. The relationship between the pixel coordinates of LCD and the position in Framebuffer is as follows
Give any screen coordinates (xQuery y) and the base address of Framebuffer fb_base. In addition, the resolution of LCD is Xres x Yres, which represents the number of binary digits of a single pixel color bpp. The address of its color data in framebuffer is:
(XQuery y) Pixel starting address = fb_base + (y*Xres+x) * bpp/8
Pixel color representation
Sample code # include # include static int fd_fb;static struct fb_var_screeninfo var; / * Current var * / static int screen_size; / * bytes occupied by a frame of data * / static unsigned char * fb_base; / * Framebuffer first address * / static unsigned int line_width / * number of bytes occupied by a row of data * / static unsigned int pixel_width / * number of bytes occupied by a single pixel * / / * function name: lcd_put_pixel * function description: at the specified location of LCD Output specified color (trace point) * input parameters: X coordinates Y coordinate Color * output parameters: none * returned value: will be * modified date version number modifier content *-* 2020-05-12 V1.0 zh (angenao ) create * * / void lcd_put_pixel (int x Int y, unsigned int color) {unsigned char * pen_8 = fb_base+y*line_width+x*pixel_width Unsigned short * pen_16; unsigned int * pen_32; unsigned int red, green, blue; pen_16 = (unsigned short *) pen_8; pen_32 = (unsigned int *) pen_8; switch (var.bits_per_pixel) {case 8: {* pen_8 = color Break;} case 16: {/ * 565 * / red = (color > > 16) & 0xff; green = (color > > 8) & 0xff; blue = (color > > 0) & 0xff Color = (red > > 3) > 2) > 3); * pen_16 = color; break;} case 32: {* pen_32 = color; break } default: {printf ("can't surport% dbpp\ n", var.bits_per_pixel); break;}} int main (int argc, char * * argv) {int I; fd_fb = open ("/ dev/fb0", O_RDWR) / * * Open fb device * / if (fd_fb < 0) {printf ("can't open / dev/fb0\ n"); return-1;} if (ioctl (fd_fb, FBIOGET_VSCREENINFO, & var)) {/ * * get screen variable information * / printf ("can't get var\ n") Return-1;} printf ("RES:%d x% d\ n", var.xres,var.yres); printf ("one pixel bits:%d\ n", var.bits_per_pixel); line_width = var.xres * var.bits_per_pixel / 8 var.bits_per_pixel / row data occupies bytes printf ("line_width:%d byte\ n", line_width) Pixel_width = var.bits_per_pixel / 8 printf / bytes occupied by a pixel printf ("pixel_width:%d byte\ n", pixel_width); screen_size = var.xres * var.yres * var.bits_per_pixel / 8 bytes occupied by a frame printf ("screen_size:%d byte\ n", screen_size) Fb_base = (unsigned char *) mmap (NULL, screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0); / * * Mapping the first address of framebuffer * / if (fb_base = = (unsigned char *)-1) {printf ("can't mmap\ n"); return-1;} memset (fb_base, 0x00, screen_size) / * clear the screen: all set to black * / / * randomly set 100 red dots as red dots * / const double Tunable 2pm 3.14 bang / cycle const int Aits100 * * / amplitude double x moment sinister cos cosy; the pixel coordinates of the starting point of int start_x,start_y;// drawing start_x=0; start_y = var.yres/2 While (1) {for
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 218
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.