Framebuffer display principle, image RGB Data Processing

Source: Internet
Author: User

Framebuffer is the device driver that outputs video data in the memory. framebuffer in Linux is an independent hardware abstraction layer that abstracts display devices into frame buffers, as an image showing the memory, the developer can map the image to the process address space and perform read/write operations directly. Simply put, it abstracts the hardware, so that the upper layer no longer cares about how the hardware is operated, but only completes the image display function, the device files of the driver are generally/dev/fb0,/dev/Fb1, and framebuffer supports up to 32 devices. It illustrates the position of framebuffer in the Linux system. It is higher than the general driver and shields the underlying driver function in the middle.

However, for programmers and Linux systems, there is no difference between the framebuffer device and other files. You can configure the parameter settings for the hardware by configuring the framebuffer device file. The framebuffer ing can be done through read () read data with write (), or map internal data to the application space through the MMAP () function, perform other operations or set its parameters through IOCTL (), and use MMAP () the function maps the image data in the memory directly to framebuffer and shows that the time is short and the efficiency is high. The image data in the memory can be mapped through MMAP.

Position of framebuffer in Linux

Image Display Process

The screen display calls framebuffer. First, an fb_dev struct contains device pointers, memory space pointers, number of horizontal and vertical records, and number of color digits:

Struct fb_dev

{

Int FB;

Void * fb_mem;

Int fb_width, fb_height, fb_line_len, fb_size;

Int fb_bpp;

} Fbdev;

 

Initialize the framebuffer device and perform memory address ing. You can directly map the processed data to the cache of framebuffer for display:

Int FB;

If (Fb = open ("/dev/fb0", o_rdwr) <0)

{

Perror (_ FUNC __);

Return (-1 );

}

Fb_stat (FB );

Fbdev. fb_mem = MMAP (null, fbdev. fb_size,

Prot_read | prot_write, map_shared, FB, 0 );

Fbdev. Fb = FB;

 

The fb_stat (FB) function is defined as follows. To obtain the length, width, and Bit Width of framebuffer, 0 is returned for success and-1 is returned for failure:

Int fb_stat (int fd)

{

Struct fb_fix_screeninfo fb_finfo;

Struct fb_var_screeninfo fb_vinfo;

If (IOCTL (FD, fbioget_fscreeninfo, & fb_finfo ))

{

Perror (_ FUNC __);

Return (-1 );

}

If (IOCTL (FD, fbioget_vscreeninfo, & fb_vinfo ))

{

Perror (_ FUNC __);

Return (-1 );

}

Fbdev. fb_width = fb_vinfo.xres;

Fbdev. fb_height = fb_vinfo.yres;

Fbdev. fb_bpp = fb_vinfo.bits_per_pixel;

Bdev. fb_line_len = fb_finfo.line_length;

Fbdev. fb_size = fb_finfo.smem_len;

Return (0 );

}

 

To display data on the screen, you need to directly display the pixel color on the pixel, because the original decoded data is 24-bit RGB data, and the screen color is 16-bit, you need to convert rgb888 to rgb565 data: Mainly shift the number of digits without color.

The Code is as follows:

Color = (unsigned short) (buffer [x3s] <8) & 0xf800) | (buffer [x3s + 1] <3) & 0x07e0) | (buffer [x3s + 2]> 3) & 0x001f ));

 

Because the resolution of the NEC 3.5-inch LCD screen that comes with the Development Board is 240 × 320, and the output data of the camera is 320 × 240, Matrix Rotation is required for display, determined by the fbmem base address + x * width + Y:

 

If (x> width) | (Y> height)

Return (-1 );

Unsigned short * DST = (unsigned short *) fbmem + x * width + y );

* DST = color;

 

At the end of the program, remove the memory ing and disable the device:

Munmap (fbdev. fb_mem, fbdev. fb_size );

Close (FB );

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.