Framebuffer vertices, draw lines, draw polygon, draw circles, and draw parabolic Functions

Source: Internet
Author: User
Framebuffer draws points, draw lines, draw polygon, draw circles, and draw parabolic functions-Linux general technology-Linux programming and kernel information. For more information, see the following. # Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Define TRUE 1
# Define FALSE 0
# Define MIN (x, y) (x)> (y )? (Y) :( x ))
# Define MAX (x, y) (x)> (y )? (X) :( y ))
Typedef struct fbdev {
Int fb;
Unsigned long fb_mem_offset;
Unsigned long fb_mem;
Struct fb_fix_screeninfo fb_fix;
Struct fb_var_screeninfo fb_var;
Char dev [20];
} FBDEV, * PFBDEV;
Typedef struct point {
Int x;
Int y;
Int z;
} POINT, * PPOINT;
/* These math function Writed
* Kf701
* HeFei
*/
Void draw_dot (PFBDEV pFbdev, POINT p, uint8_t r, uint8_t g, uint8_t B );
Void draw_line (PFBDEV pFbdev, POINT p1, POINT p2, uint8_t r, uint8_t g, uint8_t B );
Void draw_polygon (PFBDEV pFbdev, uint32_t num, PPOINT array, uint8_t r, uint8_t g, uint8_t B );
Void draw_triangle (PFBDEV pFbdev, POINT p1, POINT p2, POINT p3, uint8_t r, uint8_t g, uint8_t B );
Void draw_circle (PFBDEV pFbdev, POINT center, uint32_t radius, uint8_t r, uint8_t g, uint8_t B );
Void draw_parabla_x (PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t B );
Void draw_parabla_y (PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t B );
Int fb_open (PFBDEV pFbdev)
{
PFbdev-> fb = open (pFbdev-> dev, O_RDWR );
If (pFbdev-> fb dev );
Return FALSE;
}
If (-1 = ioctl (pFbdev-> fb, FBIOGET_VSCREENINFO, & (pFbdev-> fb_var )))
{
Printf ("ioctl FBIOGET_VSCREENINFO \ n ");
Return FALSE;
}
If (-1 = ioctl (pFbdev-> fb, FBIOGET_FSCREENINFO, & (pFbdev-> fb_fix )))
{
Printf ("ioctl FBIOGET_FSCREENINFO \ n ");
Return FALSE;
}
PFbdev-> fb_mem_offset = (unsigned long) (pFbdev-> fb_fix.smem_start )&(~ PAGE_MASK );
PFbdev-> fb_mem = (unsigned long int) mmap (NULL, pFbdev-> fb_fix.smem_len +
PFbdev-> fb_mem_offset,
PROT_READ | PROT_WRITE, MAP_SHARED, pFbdev-> fb, 0 );
If (-1L = (long) pFbdev-> fb_mem)
{
Printf ("mmap error! Mem: % ld offset: % ld \ n ", pFbdev-> fb_mem,
PFbdev-> fb_mem_offset );
Return FALSE;
}
/*
Printf ("depth (bits per pixel) = % d \ n", fb. fb_var.bits_per_pixel );
Printf ("smemlen = % d \ n", fb. fb_fix.smem_len );
Printf ("fix_line (in byte) = % d \ n", fb. fb_fix.line_length );
*/
Return TRUE;
}
Void fb_close (PFBDEV pFbdev)
{
Close (pFbdev-> fb );
PFbdev-> fb =-1;
}
Void fb_memcpy (void * addr, void * color, size_t len)
{
Memcpy (addr, color, len );
}
Void draw_dot (PFBDEV pFbdev, POINT p, uint8_t r, uint8_t g, uint8_t B)
{
Uint32_t offset;
Uint8_t color [4];
Color [0] = B;
Color [1] = g;
Color [2] = r;
Color [3] = 0x0;
Offset = p. y * pFbdev-> fb_fix.line_length + 4 * p. x;
Fb_memcpy (void *) (pFbdev-> fb_mem + pFbdev-> fb_mem_offset + offset), color, 4 );
}
Void draw_line (PFBDEV pFbdev, POINT p1, POINT p2, uint8_t r, uint8_t g, uint8_t B)
{
POINT p;
Int x, y;
For (x = MIN (p1.x, p2.x); x = 0; I --)
{
Draw_circle (& fb, center, I, 0xff, 0xff, 0x0 );
}
*/
Center. x = 700;
Center. y = 250;
Int a =-100;
Draw_parabla_x (& fb, center, a, 0x0, 0xff, 0x0 );
Draw_parabla_x (& fb, center,-a, 0x0, 0xff, 0x0 );
Draw_parabla_y (& fb, center, a, 0x0, 0xff, 0x0 );
Draw_parabla_y (& fb, center,-a, 0x0, 0xff, 0x0 );
Fb_close (& fb );
Return 0;
}

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.