반응형

  콘솔에서 프레임버퍼에 색깔을 찍어본 예제입니다. X윈도우상에서도 결과를 보고 싶은데 안되네요.


 

  1. #include <stdio.h>  
  2. #include <stdlib.h>  
  3. #include <string.h>  
  4.     
  5. #include <fcntl.h>  
  6. #include <unistd.h>  
  7. #include <linux/fb.h>  
  8. #include <sys/mman.h>  
  9.     
  10.     
  11. int main( int argc, char* argv[] )  
  12. {  
  13.     int framebuffer_fd = 0;  
  14.     struct fb_var_screeninfo framebuffer_variable_screeninfo;  
  15.     struct fb_fix_screeninfo framebuffer_fixed_screeninfo;  
  16.     
  17.     framebuffer_fd = open( "/dev/fb0", O_RDWR );  
  18.     if ( framebuffer_fd <  0 ){  
  19.         perror( "Error: cannot open framebuffer device\n" );  
  20.         exit(1);  
  21.     }  
  22.     
  23.     
  24.     if ( ioctl(framebuffer_fd, FBIOGET_VSCREENINFO,   
  25.             &framebuffer_variable_screeninfo) )  
  26.     {  
  27.         perror( "Error: reading variable screen infomation\n" );  
  28.         exit(1);  
  29.     }  
  30.     framebuffer_variable_screeninfo.bits_per_pixel=32;  
  31.     
  32.     if ( ioctl(framebuffer_fd, FBIOPUT_VSCREENINFO,   
  33.             &framebuffer_variable_screeninfo) )  
  34.     {  
  35.         perror( "Error: reading variable screen infomation\n" );  
  36.         exit(1);  
  37.     }  
  38.     
  39.     
  40.     
  41.     if ( ioctl(framebuffer_fd, FBIOGET_FSCREENINFO,   
  42.             &framebuffer_fixed_screeninfo) )  
  43.     {  
  44.         perror( "Error: reading fixed screen infomation\n" );  
  45.         exit(1);  
  46.     }  
  47.     
  48.     printf( "framebuffer Display information\n" );  
  49.     printf( " %d x %d  %d bpp\n", framebuffer_variable_screeninfo.xres,  
  50.              framebuffer_variable_screeninfo.yres,   
  51.              framebuffer_variable_screeninfo.bits_per_pixel );  
  52.     
  53.     
  54.     int width  = framebuffer_variable_screeninfo.xres;  
  55.     int height = framebuffer_variable_screeninfo.yres;  
  56.     int bpp = framebuffer_variable_screeninfo.bits_per_pixel/8;  
  57.     int xoffset = framebuffer_variable_screeninfo.xoffset;  
  58.     int yoffset = framebuffer_variable_screeninfo.yoffset;  
  59.     
  60.     
  61.     long int screensize = width*height*bpp;  
  62.     
  63.     
  64.     char *framebuffer_pointer = (char*)mmap( 0, screensize,  
  65.                                         PROT_READ|PROT_WRITE,  
  66.                                         MAP_SHARED,  
  67.                                         framebuffer_fd, 0 );  
  68.     
  69.     if ( framebuffer_pointer == MAP_FAILED )  
  70.     {  
  71.         perror( "Error : mmap\n" );  
  72.         exit(1);  
  73.     }  
  74.     else  
  75.         {  
  76.             int x,y;  
  77.             for ( y=0; y<height; y++)  
  78.             for ( x=0; x<width; x++)  
  79.             {  
  80.                 unsigned int pixel_offset = (y+yoffset)*framebuffer_fixed_screeninfo.line_length*2 +(x+xoffset)*bpp;  
  81.         
  82.     
  83.         if (bpp==4){  
  84.             if ( x<=width*1/3){    
  85.                  framebuffer_pointer[pixel_offset]=255;//B  
  86.                  framebuffer_pointer[pixel_offset+1]=0;//G  
  87.                  framebuffer_pointer[pixel_offset+2]=0;//R  
  88.                  framebuffer_pointer[pixel_offset+3]=0;//A  
  89.             }  
  90.             if ( x>width*1/3 && x<=width*2/3){      
  91.                  framebuffer_pointer[pixel_offset]=0;//B  
  92.                  framebuffer_pointer[pixel_offset+1]=255;//G  
  93.                  framebuffer_pointer[pixel_offset+2]=0;//R  
  94.                  framebuffer_pointer[pixel_offset+3]=0;//A  
  95.             }  
  96.             if ( x>width*2/3){     
  97.                  framebuffer_pointer[pixel_offset]=0;//B  
  98.                  framebuffer_pointer[pixel_offset+1]=0;//G  
  99.                  framebuffer_pointer[pixel_offset+2]=255;//R  
  100.                  framebuffer_pointer[pixel_offset+3]=0;//A  
  101.             }  
  102.         }  
  103.     
  104.          }  
  105.     
  106.     }   
  107.     
  108.     munmap( framebuffer_pointer, screensize );   
  109.     close( framebuffer_fd );  
  110. }  
  111.     
  112.     
  113.     
  114.         


반응형

'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

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.
블로그의 문서는 종종 최신 버전으로 업데이트됩니다. 여유 시간이 날때 진행하는 거라 언제 진행될지는 알 수 없습니다.

영화,책, 생각등을 올리는 블로그도 운영하고 있습니다. https://freewriting2024.tistory.com


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts