Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2346719
  • 博文数量: 141
  • 博客积分: 3552
  • 博客等级: 中校
  • 技术积分: 4148
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-15 14:39
个人简介

熟悉Linux下程序设计及各种应用程序 熟悉C Language 熟悉Glusterfs、FFmpeg、CDN 系统设计,计算机图形系统设计、分布式程序设计 目前主要研究方向:流媒体

文章分类

全部博文(141)

分类: LINUX

2014-08-07 19:50:39


点击(此处)折叠或打开

  1. /**************************************************
  2.  * example5.c
  3.  * Author: T-bagwell
  4.  *
  5.  * Compile:gcc -Wall example5.c -o example5
  6.  *************************************************/
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. #include <sys/types.h>
  10. #include <sys/stat.h>
  11. #include <fcntl.h>
  12. #include <linux/fb.h>
  13. #include <errno.h>
  14. #include <sys/mman.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <sys/ioctl.h>
  18. #include <jpeglib.h>
  19. #include <jerror.h>


  20. int print_screen(short *buf,int width,int height);
  21. void draw_hline(short *buffer,int x,int y,int maxy,int maxx);

  22. char *fb_addr;
  23. unsigned int fb_width;
  24. unsigned int fb_height;
  25. unsigned int fb_depth;
  26. unsigned fb_size;

  27. unsigned short PIXELRGB888TO565(unsigned char red, unsigned char green, unsigned char blue)
  28. {
  29.         unsigned short B = (blue >> 3) & 0x001F;
  30.         unsigned short G = ((green >> 3) << 5) & 0x07E0;
  31.         unsigned short R = ((red >> 3) << 11) & 0xF800;

  32.         return (unsigned short) (R | G | B);
  33. }

  34. int draw_pixel(void *fbmem, int width, int height, int x, int y, unsigned short color)
  35. {
  36.         if ((x > width) || (y > height))
  37.                 return -1;

  38.         unsigned short *dst = ((unsigned short *) fbmem + y * width + x);

  39.         *dst = color;
  40.         return (0);
  41. }


  42. int main(int argc, char *argv[])
  43. {
  44.         int screen_fbd=0;
  45.         struct jpeg_decompress_struct cinfo;
  46.         struct jpeg_error_mgr jerr;
  47.         FILE *infile;
  48.         struct fb_fix_screeninfo fb_fix;
  49.         struct fb_var_screeninfo fb_var;
  50.         char *env=NULL;
  51.         unsigned char *buffer;
  52.         unsigned char *fbmem;
  53.         short *color_white;
  54.         unsigned short color;
  55.         unsigned int x;
  56.         unsigned int y;
  57.         if ((infile = fopen(argv[1], "rb")) == NULL)
  58.         {
  59.                 fprintf(stderr, "open bbs.chinaffmpeg.com 孙悟空提醒您 %s failed\n", argv[1]);
  60.                 exit(-1);
  61.         }

  62.         if(!(env = getenv("FRAMEBUFFER")))
  63.         {
  64.                 env = "/dev/fb0";
  65.         }

  66.         screen_fbd = open(env, O_RDWR);

  67.         if(screen_fbd < 0)
  68.         {
  69.                 return 0;
  70.         }

  71.         if(ioctl(screen_fbd, FBIOGET_VSCREENINFO, &fb_var) == -1)
  72.         {
  73.                 close(screen_fbd);
  74.                 return 0;
  75.         }
  76.         fb_width = fb_var.xres;
  77.         fb_height = fb_var.yres;
  78.         fb_depth = fb_var.bits_per_pixel;

  79.         cinfo.err = jpeg_std_error(&jerr);
  80.         jpeg_create_decompress(&cinfo);

  81.         jpeg_stdio_src(&cinfo, infile);
  82.         jpeg_read_header(&cinfo, TRUE);
  83.         jpeg_start_decompress(&cinfo);
  84.         if ((cinfo.output_width > fb_width) ||(cinfo.output_height > fb_height))
  85.         {
  86.                 return (-1);
  87.         }

  88.         fbmem = mmap(0, fb_width * fb_height, PROT_READ | PROT_WRITE, MAP_SHARED, screen_fbd, 0);
  89.         buffer = (unsigned char *) malloc(cinfo.output_width * cinfo.output_components);
  90.         y = 0;

  91.         while (cinfo.output_scanline < cinfo.output_height)
  92.         {
  93.                 jpeg_read_scanlines(&cinfo, &buffer, 1);
  94.                 if (fb_depth == 16)
  95.                 {
  96.                         for (x = 0; x < cinfo.output_width; x++)
  97.                         {
  98.                                 color = PIXELRGB888TO565(buffer[x * 3], buffer[x * 3 + 1], buffer[x * 3 + 2]);
  99.                                 draw_pixel(fbmem, fb_width, fb_height, x, y, color);
  100.                         }
  101.                 }
  102.         y++;
  103.         }
  104.         jpeg_finish_decompress(&cinfo);
  105.         jpeg_destroy_decompress(&cinfo);

  106.         free(buffer);
  107.         return 0;
  108. }

QQ群里突然有人问了这个问题,希望得到开源的程序,正好以前写过一个,找的挺费劲的,就贴到这里吧


阅读(8363) | 评论(1) | 转发(4) |
给主人留下些什么吧!~~

超少5212016-09-02 15:21:59

if (fb_depth == 16)
                {
                        for (x = 0; x < cinfo.output_width; x++)
                        {