- 浏览: 444534 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
zjhgx:
多谢,多谢。多谢
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
37du:
受教了,对于理解运行过程有很好的效果
ActionMapper---webwork 2.1到2.2 的变化 -
chxiaowu:
非常好,谢谢!
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
euii:
谢谢,这样的总结。
Ubuntu 中软件的安装、卸载以及查看的方法总结 -
xiaoyao3857:
谢谢,正需要这样的汇总型字典!
Ubuntu 中软件的安装、卸载以及查看的方法总结
This is a quick document I produced while figuring out how to use the framebuf
fer device to produce graphics on the Linux console. I don't claim to be an ex
pert in this area, but when I looked for a general guide to doing this, I foun
d absolutely nothing, except the header file <linux/fb.h>
Therefore, this is meant to be a jump-start guide for those who want to begin
using graphics in the linux console. Hopefully someone out there will write a
decent graphical browser, so I don't have to start up X every time I want to s
urf!
As always, no warranty, express or implied...etc. Give me a break, I took my f
irst look at this device less than 24 hours ago! Any corrections, money, gifts
, etc. (I wish!), just contact me
You may freely distribute this document, as long as you do not change it in an
y way, and credit me as author. In particular, I encourage Linux distributions
to include this in their packages, as I feel there isn't half as much program
ming information in most distributions as there ought to be. Copyright James D
abell, May 1999.
This document was last updated June 11th, 1999. (Corrections from Joerg Beyer
& Ian Thompson-Bell)
Part One:
First of all, configure your system for the framebuffer console device. It may
come in handy. Note that the device is only available for graphics cards that
implement VESA 2.0. Fortunately, virtually all recent cards out there do this
.
When you have got high-res textmodes, then you can start experimenting. You wi
ll have a device /dev/fb0 that you can look at like any normal file. To take a
screenshot, all you have to do is
cat /dev/fb0 > ~/sshot
And you will have a pretty big file with the contents of your graphics card's
memory inside. Now, if you clear the screen, and type
cat ~/sshot > /dev/fb0
You should have a display that looks exactly like before. Of course, the secon
d you start typing the display reverts to normal.
Part Two:
So now, we can move on to using the device in a C program. Take a look at the
following code:
#include <unistd.h> #include <stdio.h> #include <fcntl.h> int main() { int fbfd = 0; fbfd = open("/dev/fb0", O_RDWR); if (!fbfd) { printf("Error: cannot open framebuffer device.\n"); exit(1); } printf("The framebuffer device was opened successfully.\n"); close(fbfd); return 0; }
All in all, a pretty simple program. We open the framebuffer device file using
the low-level open(), because the buffered, higher level fopen() is unsuitabl
e for our needs.
Next, we test the file descriptor to make sure that we were successful, and pr
int a message out that tells the user what happened.
Note that if you #include <errno.h>, then you will be able to find out exactly
why the open() call fails. Check the man page for open() for more information
on this
Finally, we clean up by closing the file descriptor and returning.
Part Three:
Using the newly created file descriptor, we can perform operations on the fram
ebuffer with the ioctl() function. This function is used to talk to special de
vice files in ways that are particular to that device. In this case, we can us
e it to obtain information on the video card. We can also use the file descrip
tor to map the file into memory, and use a pointer to access it, which is more
efficient and easier on us. This is done using the mmap() function. If you ha
ven't used this before, here is some sample code:
#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h> int main() { int fbfd = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screensize = 0; char *fbp = 0; fbfd = open("/dev/fb0", O_RDWR); if (!fbfd) { printf("Error: cannot open framebuffer device.\n"); exit(1); } printf("The framebuffer device was opened successfully.\n"); if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { printf("Error reading fixed information.\n"); exit(2); } if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error reading variable information.\n"); 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); if ((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory.\n") ; exit(4); } printf("The framebuffer device was mapped to memory successfully.\n"); munmap(fbp, screensize); close(fbfd); return 0; }
As you can see, we have to #include an extra header file to deal with mmap().
We use the information returned by the ioctl()s to figure out how much memory
to map. The members of fb_var_screeninfo that are used are xres, yres, and bit
s_per_pixel.
Note that there is also what is known as the virtual screen size, which can be
utilised for scrolling, etc, but that is beyond the scope of this document. H
owever, if you are planning on using scrolling, you will probably want to use
xres_virtual and yres_virtual to calculate how much memory to map.
Finally, remember to munmap() the memory you have mapped for use with the fram
ebuffer.
Part Four:
In this section we finally get to plot a pixel on the screen. First of all, we
need to know in what format we should put the data. As it is the most common,
and also the only type I have access to, I will be talking about the type of
framebuffer that utilises packed pixels. All that is necessary to put a pixel
on the screen, is to put bytes corresponding to the colours blue, green, red a
nd transparency, in that order, at the correct location in memory, starting at
0 for x = 0, y = 0, and increasing by four bytes for every x, and y * the len
gth of the line in bytes for every y. Standard graphics stuff; people used to
the good ol' days back in mode 13h programming in DOS will catch on quickly. A
nyway, here's the code:
#include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <linux/fb.h> #include <sys/mman.h> int main() { int fbfd = 0; struct fb_var_screeninfo vinfo; struct fb_fix_screeninfo finfo; long int screensize = 0; char *fbp = 0; int x = 0, y = 0; long int location = 0; /* Open the file for reading and writing */ fbfd = open("/dev/fb0", O_RDWR); if (!fbfd) { printf("Error: cannot open framebuffer device.\n"); exit(1); } printf("The framebuffer device was opened successfully.\n"); /* Get fixed screen information */ if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) { printf("Error reading fixed information.\n"); exit(2); } /* Get variable screen information */ if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) { printf("Error reading variable information.\n"); exit(3); } /* Figure out the size of the screen in bytes */ screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8; /* Map the device to memory */ fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0); if ((int)fbp == -1) { printf("Error: failed to map framebuffer device to memory.\n"); exit(4); } printf("The framebuffer device was mapped to memory successfully.\n"); x = 100; y = 100; /* Where we are going to put the pixel */ /* Figure out where in memory to put the pixel */ location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length; *(fbp + location) = 100; /* Some blue */ *(fbp + location + 1) = 15; /* A little green */ *(fbp + location + 2) = 200; /* A lot of red */ *(fbp + location + 3) = 0; /* No transparency */ munmap(fbp, screensize); close(fbfd); return 0; }
Now that you know how to plot a pixel, it becomes a trivial matter to write fu
nctions to draw lines, boxes, windows, etc. Hopefully, by now you are well on
your way to writing that web browser for me - consider it payment for this tut
orial ;).
<SHAMELESS_MODE>
Talking of payment, I get paid every time somebody buys a book this way. Sorry
, but I'm a poor student, and let's face it, if you are reading this page, the
n you will probably be interested in them, if you don't have them already. I h
ave personally read each of these, and can say with all honesty that they are
great books.
Beginning Linux Programming:
This book really has it all for getting to grips with Linux programming. If yo
u can already program in C, and want to know how to use some of the more speci
fic Linux stuff, then get this book. It covers all sorts, from shell programmi
ng, through socket programming in C, to X programming using tcl/tk.
C: The Complete Reference:
This is the only book you should consider getting if you want to learn C. This
was all I needed to get programming in C, and since it also doubles as a refe
rence book, you will keep coming back to it again and again. It's by Herbert S
childt, one of the best authors on the planet when it comes to C. Forget the "
learn C in 14 days" cons, get this. Now.
Genetic Algorithms in C++:
This is all you need to understand the theory behind, and implement Genetic Al
gorithms. Genetic Algorithms model themselves on nature, by "evolving" solutio
ns based upon how well they perform in an environment (your program). It sound
s complex, but I assure you that it is *really* easy to get into.
One thing though. All of the sample code is targetted at MS Windows, so if you
are the kind of person who relies on the code in a book to get through it, an
d you are developing for Linux, then this book may not be for you. Personally,
I didn't even need to look at the code before implementing my own stuff, the
text is more than sufficient.
Internet Programming With Python
This book is co-authored by Guido Van Rossum, the guy who wrote the Python lan
guage. It also comes with a CD containing Python for many different platforms,
as well as sample code. It covers CGI programs written in Python, and also a
couple of subjects not usually mentioned in books of this kind, namely generat
ing HTML (in a *very* nice way) and extending the language. It also covers the
basics in a way that makes this book also good for learning the language from
scratch.<!-- / message --><!-- edit note -->
Another : http://www.linuxsir.org/bbs/showthread.php?t=241071
发表评论
-
htonl(),htons(),ntohl(),ntons()--大小端模式转换函数
2010-12-16 16:51 4045不同机器内部对变量的字节存储顺序不同,有的采用大端模式(big ... -
关于Linux静态库和动态库的分析
2010-09-28 10:29 16111.什么是库在windows平台和linux平台下都大量存在着 ... -
Heartbeat
2010-09-01 19:31 1377Heartbeat 项目是 Linux-HA ... -
linux下更改共享内存的最大值
2010-07-26 13:22 6028System V IPC 参数 名字 ... -
环境变量相关
2010-06-10 15:03 978系统环境变量: /etc/profile:此文件 ... -
linux中的信号处理(signal与alarm)
2010-05-12 15:25 1768简单处理程序: ... -
LINUX 时间和日期
2010-04-01 19:09 2546时间与日期 通常对于 一个程序来说可以确定时间与日期是十分 ... -
IPC之消息队列
2010-03-13 12:05 1406消息队列缺点: 1. 如果进程创建了一个消息队列,在该队 ... -
如何让errno多线程/进程安全
2010-03-13 11:35 1753在 linux 或者 unix 环境中, errno ... -
Linux下库相关的概略介绍及动态库的搜索路径优先级
2010-03-13 11:29 1623(本文主要针对动态连接 ... -
ftok函数
2010-03-13 11:01 1744系统建立IPC通讯(如消 ... -
About pci.ids
2009-12-23 21:01 1725pci.ids - This is a public r ... -
port I/O
2009-12-21 15:27 1153Name outb, outw, outl, outsb ... -
udev相关
2009-12-11 20:22 1164udev 是Linux kernel 2.6系 ... -
SMP(Symmetrical Multi-Processing)
2009-12-11 15:22 1731对称多处理" ... -
功能强大的sed命令
2009-11-27 21:55 2002vim不太熟练,发现shell的sed命令很强大。 1. S ... -
/etc/sudoers配置文件的格式
2009-11-25 20:56 1612-------下面文章转载自网 ... -
/etc/sudoers中的含义
2009-11-25 20:55 2483Sudo 是允许系统管理员让普通用户执行一些或者全部的roo ... -
linux下如何模拟按键输入和模拟鼠标
2009-11-14 10:06 2812查看/dev/input/eventX是什么类型的事件, ca ... -
Linux root file system
2009-11-05 20:03 10551. Linux for PowerPC Embedded S ...
相关推荐
linux frame buffer 相关的资料。相关framebuffer 的学习还可以参考Linux 2.2 Framebuffer Device Programming Tutorial
linux framebuffer编程,显示BMP图片
qvfb是QT virtualframebuffer的缩写,是QT在X11下的一个framebuffer仿真器,有了它我们就可以利用X11下众多便利的工具来开发基于framebuffer的应用程序了。qvfb的原理很简单,它建立了一个systemV共享内存,用户只需...
Linux下FrameBuffer直接写屏
嵌入式linux基于framebuffer的截图工具。
Linux Framebuffer应用编程——jpeg显示在RGB888 Lcd显示屏 包含源代码.c文件,运行在Arm9开发板的可执行文件,一张jpg图像(分辨率800*533) 相关原理详见【正点原子文档】I.MX6U嵌入式Linux C应用编程指南V1.4 ...
在LINUX framebuffer 显示汉字
在linux下,实现将ramdisk中的图片以文件流的形式打开并通过fframbuffer输出到屏幕。
linux从framebuffer获取image源码
linux下用framebuffer显示BMP文件的C源代码,我曾经在ARM2440上运行成功这个程序,我用的是240*320 16位的BMP图片
把framebuffer的数据转换为bmp图片,超高清,windows可以直接查看图片
QT使用 Linux framebuffer时候 支持QT本身不支持的其他格式(例如支持argb4444)的一种取巧方法
基于Linux内核framebuffer的图像采集与显示系统设计.pdf
linux基于framebuffer的简单程序,可以根据不同的输入显示红,绿,黑,白等颜色,分辨率可以在程序中调整,现在是640x480的。 是framebuffer编程很好的参考程序 这个程序是我在别的程序基础上改的。
在Linux内核中,Framebuffer(帖缓冲)驱动是显示驱动的标准,Framebuffer将显示设备抽象为帖缓冲区,用户通过内存映射到进程地址空间之后,就可以直接进行读写操作,且写操作可以立即在屏幕上进行显示,在Linux内核/...
Linux设备驱动之Framebuffer分析[归纳].pdf
本代码是linux下的FrameBuffer驱动,适用于AMCC公司的ppc405ex系列嵌入式CPU
Linux设备驱动之Framebuffer分析.pdf
在Framebuffer上实现的俄罗斯方块,可在嵌入式系统上实现,本人也试验过在Ubuntu虚拟机上实现,同时里面也有在窗口中实现的部分