리눅스 프레임버퍼 예제 1OpenCV/미분류2015. 1. 27. 10:27
Table of Contents
반응형
콘솔에서 프레임버퍼에 색깔을 찍어본 예제입니다. X윈도우상에서도 결과를 보고 싶은데 안되네요.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <linux/fb.h>
- #include <sys/mman.h>
- int main( int argc, char* argv[] )
- {
- int framebuffer_fd = 0;
- struct fb_var_screeninfo framebuffer_variable_screeninfo;
- struct fb_fix_screeninfo framebuffer_fixed_screeninfo;
- framebuffer_fd = open( "/dev/fb0", O_RDWR );
- if ( framebuffer_fd < 0 ){
- perror( "Error: cannot open framebuffer device\n" );
- exit(1);
- }
- if ( ioctl(framebuffer_fd, FBIOGET_VSCREENINFO,
- &framebuffer_variable_screeninfo) )
- {
- perror( "Error: reading variable screen infomation\n" );
- exit(1);
- }
- framebuffer_variable_screeninfo.bits_per_pixel=32;
- if ( ioctl(framebuffer_fd, FBIOPUT_VSCREENINFO,
- &framebuffer_variable_screeninfo) )
- {
- perror( "Error: reading variable screen infomation\n" );
- exit(1);
- }
- if ( ioctl(framebuffer_fd, FBIOGET_FSCREENINFO,
- &framebuffer_fixed_screeninfo) )
- {
- perror( "Error: reading fixed screen infomation\n" );
- exit(1);
- }
- printf( "framebuffer Display information\n" );
- printf( " %d x %d %d bpp\n", framebuffer_variable_screeninfo.xres,
- framebuffer_variable_screeninfo.yres,
- framebuffer_variable_screeninfo.bits_per_pixel );
- int width = framebuffer_variable_screeninfo.xres;
- int height = framebuffer_variable_screeninfo.yres;
- int bpp = framebuffer_variable_screeninfo.bits_per_pixel/8;
- int xoffset = framebuffer_variable_screeninfo.xoffset;
- int yoffset = framebuffer_variable_screeninfo.yoffset;
- long int screensize = width*height*bpp;
- char *framebuffer_pointer = (char*)mmap( 0, screensize,
- PROT_READ|PROT_WRITE,
- MAP_SHARED,
- framebuffer_fd, 0 );
- if ( framebuffer_pointer == MAP_FAILED )
- {
- perror( "Error : mmap\n" );
- exit(1);
- }
- else
- {
- int x,y;
- for ( y=0; y<height; y++)
- for ( x=0; x<width; x++)
- {
- unsigned int pixel_offset = (y+yoffset)*framebuffer_fixed_screeninfo.line_length*2 +(x+xoffset)*bpp;
- if (bpp==4){
- if ( x<=width*1/3){
- framebuffer_pointer[pixel_offset]=255;//B
- framebuffer_pointer[pixel_offset+1]=0;//G
- framebuffer_pointer[pixel_offset+2]=0;//R
- framebuffer_pointer[pixel_offset+3]=0;//A
- }
- if ( x>width*1/3 && x<=width*2/3){
- framebuffer_pointer[pixel_offset]=0;//B
- framebuffer_pointer[pixel_offset+1]=255;//G
- framebuffer_pointer[pixel_offset+2]=0;//R
- framebuffer_pointer[pixel_offset+3]=0;//A
- }
- if ( x>width*2/3){
- framebuffer_pointer[pixel_offset]=0;//B
- framebuffer_pointer[pixel_offset+1]=0;//G
- framebuffer_pointer[pixel_offset+2]=255;//R
- framebuffer_pointer[pixel_offset+3]=0;//A
- }
- }
- }
- }
- munmap( framebuffer_pointer, screensize );
- close( framebuffer_fd );
- }
반응형
'OpenCV > 미분류' 카테고리의 다른 글
QT와 OpenCV 같이 사용시 pro 파일 설정 방법 (0) | 2023.10.08 |
---|---|
Video for Linux Two & YUV422 to BGR888 (0) | 2010.08.24 |
atan2 함수 (0) | 2010.06.29 |
Bitmap file 분석 (0) | 2009.08.14 |