- 浏览: 236149 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
wahahachuang8:
GoEasy 实时推送支持IE6-IE11及大多数主流浏览器的 ...
服务器推送技术 java -
mahuanjian:
[flash=200,200][/flash]
服务器推送技术 java -
wenjundiandian:
下面有网页编辑器的话还是会被隐藏.
ext中消息框、提示框、确认框显示在最前面的解决方法 -
天塔上的猫:
/**
* JAVA常见的权限控制算法的实现
*
* ...
JAVA常见的权限控制算法的实现
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <asm/page.h>
#include <linux/fb.h>
#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 by
* kf701 <kf701.ye@gmail.com>
* 2007-04-05 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_parabola_x(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b);
void draw_parabola_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 < 0)
{
printf("Error opening %s: %m. Check kernel config\n", pFbdev->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<=MAX(p1.x,p2.x); x++ )
{
y = (p2.y-p1.y)*(x-p1.x)/(p2.x-p1.x) + p1.y;
p.x = x;
p.y = y;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_triangle(PFBDEV pFbdev, POINT p1, POINT p2, POINT p3, uint8_t r, uint8_t g, uint8_t b)
{
POINT p[3];
p[0] = p1;
p[1] = p2;
p[2] = p3;
draw_polygon(pFbdev, 3, p, r, g, b);
}
void draw_polygon(PFBDEV pFbdev, uint32_t num, PPOINT array, uint8_t r, uint8_t g, uint8_t b)
{
int i;
for(i=0; i<num; i++)
{
draw_line(pFbdev, array[i], array[(i+1)%num], r, g, b);
}
}
void draw_circle(PFBDEV pFbdev, POINT center, uint32_t radius, uint8_t r, uint8_t g, uint8_t b)
{
POINT p;
int x,y,tmp;
for(x=center.x-radius; x<=center.x+radius; x++)
{
p.x = x;
tmp = sqrt(radius*radius -(x-center.x)*(x-center.x));
p.y = center.y + tmp;
draw_dot(pFbdev, p, r, g, b);
p.y = center.y - tmp;
draw_dot(pFbdev, p, r, g, b);
}
for(y=center.y-radius; y<=center.y+radius; y++)
{
p.y = y;
tmp = sqrt(radius*radius - (y-center.y)*(y-center.y));
p.x = center.x + tmp;
draw_dot(pFbdev, p, r, g, b);
p.x = center.x - tmp;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_parabola_x(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b)
{
int x;
POINT p;
for(x=center.x-100; x<center.x+100; x++)
{
p.x = x;
p.y = (x-center.x)*(x-center.x)/a + center.y;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_parabola_y(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b)
{
int y;
POINT p;
for(y=center.y-100; y<center.y+100; y++)
{
p.y = y;
p.x = (y-center.y)*(y-center.y)/a + center.x;
draw_dot(pFbdev, p, r, g, b);
}
}
int main(void)
{
FBDEV fb;
memset(&fb, 0, sizeof(FBDEV));
strcpy(fb.dev, "/dev/fb0");
if(fb_open(&fb)==FALSE)
{
printf("open frame buffer error\n");
return 0;
}
POINT p1, p2, p3;
p1.x = 300;
p1.y = 450;
p2.x = 500;
p2.y = 300;
draw_line( &fb, p1, p2, 0x0, 0xff, 0x0 );
p1.x = 200;
p1.y = 200;
p2.x = 300;
p2.y = 400;
p3.x = 500;
p3.y = 250;
draw_triangle(&fb, p1, p2, p3, 0x0, 0xff, 0x0);
POINT center = { 600, 500, 0 };
int radius = 100;
draw_circle(&fb, center, radius, 0x0, 0xff, 0x0);
/*
int i;
for(i=radius-2; i>=0; i--)
{
draw_circle(&fb, center, i, 0xff, 0xff, 0x0);
}
*/
center.x = 700;
center.y = 250;
int a = -100;
draw_parabola_x(&fb, center, a, 0x0, 0xff, 0x0);
draw_parabola_x(&fb, center, -a, 0x0, 0xff, 0x0);
draw_parabola_y(&fb, center, a, 0x0, 0xff, 0x0);
draw_parabola_y(&fb, center, -a, 0x0, 0xff, 0x0);
fb_close(&fb);
return 0;
}
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <asm/page.h>
#include <linux/fb.h>
#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 by
* kf701 <kf701.ye@gmail.com>
* 2007-04-05 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_parabola_x(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b);
void draw_parabola_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 < 0)
{
printf("Error opening %s: %m. Check kernel config\n", pFbdev->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<=MAX(p1.x,p2.x); x++ )
{
y = (p2.y-p1.y)*(x-p1.x)/(p2.x-p1.x) + p1.y;
p.x = x;
p.y = y;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_triangle(PFBDEV pFbdev, POINT p1, POINT p2, POINT p3, uint8_t r, uint8_t g, uint8_t b)
{
POINT p[3];
p[0] = p1;
p[1] = p2;
p[2] = p3;
draw_polygon(pFbdev, 3, p, r, g, b);
}
void draw_polygon(PFBDEV pFbdev, uint32_t num, PPOINT array, uint8_t r, uint8_t g, uint8_t b)
{
int i;
for(i=0; i<num; i++)
{
draw_line(pFbdev, array[i], array[(i+1)%num], r, g, b);
}
}
void draw_circle(PFBDEV pFbdev, POINT center, uint32_t radius, uint8_t r, uint8_t g, uint8_t b)
{
POINT p;
int x,y,tmp;
for(x=center.x-radius; x<=center.x+radius; x++)
{
p.x = x;
tmp = sqrt(radius*radius -(x-center.x)*(x-center.x));
p.y = center.y + tmp;
draw_dot(pFbdev, p, r, g, b);
p.y = center.y - tmp;
draw_dot(pFbdev, p, r, g, b);
}
for(y=center.y-radius; y<=center.y+radius; y++)
{
p.y = y;
tmp = sqrt(radius*radius - (y-center.y)*(y-center.y));
p.x = center.x + tmp;
draw_dot(pFbdev, p, r, g, b);
p.x = center.x - tmp;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_parabola_x(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b)
{
int x;
POINT p;
for(x=center.x-100; x<center.x+100; x++)
{
p.x = x;
p.y = (x-center.x)*(x-center.x)/a + center.y;
draw_dot(pFbdev, p, r, g, b);
}
}
void draw_parabola_y(PFBDEV pFbdev, POINT center, int a, uint8_t r, uint8_t g, uint8_t b)
{
int y;
POINT p;
for(y=center.y-100; y<center.y+100; y++)
{
p.y = y;
p.x = (y-center.y)*(y-center.y)/a + center.x;
draw_dot(pFbdev, p, r, g, b);
}
}
int main(void)
{
FBDEV fb;
memset(&fb, 0, sizeof(FBDEV));
strcpy(fb.dev, "/dev/fb0");
if(fb_open(&fb)==FALSE)
{
printf("open frame buffer error\n");
return 0;
}
POINT p1, p2, p3;
p1.x = 300;
p1.y = 450;
p2.x = 500;
p2.y = 300;
draw_line( &fb, p1, p2, 0x0, 0xff, 0x0 );
p1.x = 200;
p1.y = 200;
p2.x = 300;
p2.y = 400;
p3.x = 500;
p3.y = 250;
draw_triangle(&fb, p1, p2, p3, 0x0, 0xff, 0x0);
POINT center = { 600, 500, 0 };
int radius = 100;
draw_circle(&fb, center, radius, 0x0, 0xff, 0x0);
/*
int i;
for(i=radius-2; i>=0; i--)
{
draw_circle(&fb, center, i, 0xff, 0xff, 0x0);
}
*/
center.x = 700;
center.y = 250;
int a = -100;
draw_parabola_x(&fb, center, a, 0x0, 0xff, 0x0);
draw_parabola_x(&fb, center, -a, 0x0, 0xff, 0x0);
draw_parabola_y(&fb, center, a, 0x0, 0xff, 0x0);
draw_parabola_y(&fb, center, -a, 0x0, 0xff, 0x0);
fb_close(&fb);
return 0;
}
来源:http://hi.baidu.com/mikenoodle/blog/item/f0317ff0739d2cc57831aa55.html
发表评论
-
Linux下获取IP、MAC、网关、掩码的shell脚本
2012-07-05 13:45 1924Mask:ifconfig |grep inet| sed - ... -
输入法
2012-01-04 18:00 0http://civilnet.cn/syszux/syszu ... -
tar压缩解压
2012-01-01 11:04 1048tar -c: 建立压缩档案-x ... -
Linux GUI 技术网
2012-01-01 10:32 729http://www.linuxgraphics.cn/hom ... -
Linux常用命令大全
2012-01-01 10:27 647http://www.emlinix.com/linux-zh ... -
嵌入式Linux应用程序自动载入驱动模块方法
2012-01-01 10:22 1292英利公司推出的嵌入式L ... -
MP4音频解码信息
2011-12-31 11:48 0http://blog.chinaunix.net/space ... -
ffmpeg库音频解码示例
2011-12-31 11:45 0一个英文版的例子(有讲解)ffmpeg的一些使用例子mpeg ... -
基于Bootloader的可靠嵌入式软件远程更新机制
2011-12-31 11:42 0嵌入式软件的远程自动 ... -
Double转STRING
2011-12-31 11:40 0double x=1.23456789; ch ... -
linux下检测网卡与网线连通状态
2011-12-31 11:32 0Linux下检测网卡与网线连接状态,使用ioctl向socke ... -
去除10分钟左右自动关闭LCD显示
2012-01-04 09:50 552注释掉drivers\char\vt.c的blank_scre ... -
linux logo 左上角有黑块解决办法
2012-01-04 09:50 942http://www.unixresources.net/li ... -
linux下gprs ppp 拨号的注意事项
2011-12-31 11:21 0折腾了几天,终于在linux下拨号成功了! 注意事项: 1 ... -
GPRS模块在Linux平台上ppp拨号上网总结与心得
2011-12-31 11:09 0由于一个嵌入式平台 ... -
Linux下检测U盘是否插入
2011-12-31 11:07 0Linux下检测U盘是否插入Linux的文件系统是异步的,也就 ... -
Linux下应用程序如何取得U盘插拔消息
2011-12-31 11:06 0Linux 2.6内核版本以后,对于/dev目录的管理采用了新 ... -
在嵌入式Linux下GPRS上网方案
2011-12-31 11:02 0在嵌入式Linux下GPRS上网方案 硬/软件环境 ... -
FFMpeg框架代码阅读
2011-12-31 10:50 01. 简介FFmpeg是一个集录制、转换、音/视频编码解码 ... -
关于ffmpeg的安装及其编译
2011-12-31 10:48 0所需软件包:nasm-0.98.39-1.i386.r ...
相关推荐
本教程将详细讲解如何利用framebuffer在Linux屏幕上画点、线、矩形、矩形波以及打印字符。 首先,你需要知道如何打开和配置framebuffer设备。在Linux中,framebuffer通常位于`/dev/fb0`(对于第一个framebuffer设备...
3. **myoled_fb_user.c**:这个文件可能包含了用户级的函数,用于与framebuffer驱动交互,例如设置屏幕颜色、画点、画线或者显示图像。 为了将framebuffer与SPI驱动结合,首先需要配置好树莓派的SPI接口,确保OLED...
`fbdev-helpers`提供了一些实用函数,便于在C语言中处理framebuffer设备,而`fbset`则是一个命令行工具,可以用来配置framebuffer的参数。 在嵌入式系统开发中,framebuffer尤为重要,因为它允许开发者在资源有限的...
标签 "framebuffer" 明确指出了文档内容的核心技术点。framebuffer是一种直接与显示硬件交互的技术,通常被用在嵌入式系统或在服务器没有图形界面的环境下。这种技术可以提供一种高效地进行图像显示的方法,尤其是在...
通过打开这个设备文件,程序可以获取到显示器的相关信息,并进行画点、画线、画圆等基本的图形操作。这些功能在开发操作系统内核模块、嵌入式系统界面或者需要高效图形渲染的场景中非常有用。 压缩包中的"fb"文件很...
2. **图形绘制**:在Framebuffer上实现俄罗斯方块,需要编写低级别的图形绘制函数,包括画线、填充矩形等。这些函数可能使用C语言或汇编语言编写,直接操作内存来实现像素的设置。 3. **事件处理**:为了响应用户的...
首先,我们需要包含必要的头文件,如`<fcntl.h>`、`<sys/ioctl.h>`、`<linux/fb.h>`等,以便使用Framebuffer的相关函数和常量。在`framebuffer_dot.c`源代码中,你会看到这些头文件的引用。 接着,程序会打开...
2. **获取Framebuffer信息**:使用`ioctl()`函数获取Framebuffer设备的配置信息,如屏幕分辨率、颜色深度等,这些信息存储在`struct fb_var_screeninfo`和`struct fb_fix_screeninfo`结构体中。 ```c struct fb_var_...
在Linux内核中,Framebuffer设备模型提供了一系列特定的函数和数据结构,以支持显卡驱动的编写。开发Framebuffer驱动时,开发者应参考内核源码中的`Documentation/fb`目录下的文档,如`00-INDEX`、`framebuffer.txt`...
### FrameBuffer图形用户接口 #### 一、简介 在计算机科学领域中,FrameBuffer(帧缓冲)技术是一种用于渲染图像到显示器的技术。它提供了一种简单而直接的方式,通过将图像数据存储在一个内存区域(即帧缓冲区)...
要实现Android下读取framebuffer的内容,我们需要了解以下几个关键知识点: 1. **权限**:由于framebuffer是系统级别的资源,因此访问它需要特定的权限。在AndroidManifest.xml中,你需要添加`...
framebuffer编程,在linux系统下实现对显示屏的控制
5. **framebuff.c** 和 **fbtools.c**:这两个文件可能是通用的Framebuffer工具函数集合,包含了初始化Framebuffer设备、设置颜色模式、刷新屏幕等常用操作。它们是其他示例程序的基础支持。 6. **test.cpp**:这是...
最后,完成显示后,别忘了同步framebuffer的内容到屏幕上,这通常通过调用`msync()`函数来实现。 综上所述,操作framebuffer显示BMP图像涉及到了对BMP文件格式的理解、framebuffer设备的访问、内存映射、像素数据的...
这个过程涉及到的知识点包括:嵌入式Linux系统开发、ARM处理器架构、framebuffer驱动编程、C语言文件I/O、内存映射、BMP图片格式解析以及设备控制I/O (`ioctl`)。通过这个程序,开发者可以理解如何在没有图形库支持...
FrameBuffer设备还提供了一系列ioctl命令,可以用来获取显示设备的固定信息(如显示内存大小)、可变信息(如分辨率、像素结构、每扫描线的字节宽度)以及伪彩色模式下的调色板信息等。 除了基础的显示功能,...
`fb.h`和`fb.cpp`可能包含了与framebuffer操作相关的类和函数,比如创建QFBO和进行像素读写。 `app_main.h`、`app_main.c`、`main.cpp`则是应用程序的入口点和主循环,它们负责初始化Qt环境,创建窗口,并且可能...
3. **映射内存**:通过`mmap()`函数将显卡的物理内存空间映射到用户空间,这使得用户可以直接读写显存,从而实现画点、画线、填充等图形操作。 4. **直接写内存**:一旦显存被映射,就可以通过指针直接操作内存,...
在这种场景下,"基于framebuffer的摄像程序"是一个关键解决方案。本项目通过修改luvcview源代码,实现了在framebuffer设备上直接显示摄像头捕获的图像,从而为无图形系统的嵌入式环境提供了照相和录像的能力。 首先...