Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <linux/fb.h>
- #include <sys/mman.h>
- #include <sys/ioctl.h>
- #include "graphic.h"
- #include "common.h"
- static int fbfd = 0;
- static struct fb_var_screeninfo vinfo;
- static struct fb_fix_screeninfo finfo;
- static long int screensize = 0;
- static char *fbp = 0;
- static void openfb()
- {
- fbfd = open("/dev/fb0", O_RDWR);
- if (fbfd == -1) {
- perror("Error: cannot open framebuffer device");
- exit(1);
- }
- printf("The framebuffer device was opened successfully.\n");
- if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
- perror("Error reading fixed information");
- exit(2);
- }
- if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
- perror("Error reading variable information");
- exit(3);
- }
- screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
- fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
- }
- static void closefb(){
- munmap(fbp, screensize);
- close(fbfd);
- }
- static void clearScreen(){
- for(int i = 0; i<screensize; i++)
- {
- if (vinfo.bits_per_pixel == 32) {
- *(fbp + i) = 0;
- }
- }
- }
- static void line(int x1, int y1, int x2, int y2) {
- int x_start ,x_end, _y1,_y2, temp ;
- long int location;
- _y1 = min(y1, y2);
- _y2 = max(y1, y2);
- if (_y1 == _y2) _y2++;
- for(int y = _y1; y <= _y2; y++)
- {
- x_start = (y-_y1) * (x2-x1) / (_y2-_y1) + x1;
- x_end = (y+1-_y1) * (x2-x1) / (_y2-_y1) + x1;
- temp = x_start;
- x_start = min(x_start,x_end);
- x_end = max(temp, x_end);
- for (int x = x_start; x <= x_end; x++)
- {
- location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
- (y+vinfo.yoffset) * finfo.line_length;
- if (vinfo.bits_per_pixel == 32) {
- //RGBA
- *(fbp + location) = y; // B
- *(fbp + location + 1) = x; // G
- *(fbp + location + 2) = 200; // R
- *(fbp + location + 3) = 0; // A
- }
- }
- }
- }
- int test(const char * file_name) {
- openfb();
- clearScreen();
- line(5,5,80,100);
- line(80,5,5,100);
- line(100,5,140,50);
- line(180,5,100,100);
- line(200,5,200,100);
- line(280,5,200,100);
- line(280,5,280,100);
- line(220,5,250,10);
- closefb();
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement