Chinaunix首页 | 论坛 | 博客
  • 博客访问: 827716
  • 博文数量: 54
  • 博客积分: 8076
  • 博客等级: 中将
  • 技术积分: 648
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-01 15:11
文章分类

全部博文(54)

分类: C/C++

2011-08-29 12:00:17

从现在起,整理一些自己常用的库函数。

  1. //File : img.h
  2. //Author : Loonzhong <sepnic@gmail.com>

  3. #ifndef __IMG_H
  4. #define __IMG_H


  5. class img {
  6. public:
  7.     img() {};
  8.     ~img() {};
  9.     
  10.     void yuv_to_rgb16(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb);
  11.     void yuv_to_rgb32(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb);

  12. private:
  13.     
  14. };


  15. #endif /* __IMG_H */
  1. //File : img.cpp
  2. //Author : Loonzhong <sepnic@gmail.com>

  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <fcntl.h>
  7. #include <sys/ioctl.h>
  8. #include <string.h>
  9. #include <errno.h>

  10. #include "img.h"

  11. void img::yuv_to_rgb16(unsigned char y,
  12.                        unsigned char u,
  13.                        unsigned char v,
  14.                        unsigned char *rgb)
  15. {
  16.     register int r, g, b;
  17.     int rgb16;

  18.     r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
  19.     g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u -128) ) >> 10;
  20.     b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;

  21.     r = r > 255 ? 255 : r < 0 ? 0 : r;
  22.     g = g > 255 ? 255 : g < 0 ? 0 : g;
  23.     b = b > 255 ? 255 : b < 0 ? 0 : b;

  24.     rgb16 = (int)(((r >> 3)<<11) | ((g >> 2) << 5)| ((b >> 3) << 0));

  25.     *(rgb++) = (unsigned char)(rgb16 & 0xFF);
  26.     *(rgb++) = (unsigned char)((rgb16 & 0xFF00) >> 8);
  27. }

  28. void img::yuv_to_rgb32(unsigned char y,
  29.                        unsigned char u,
  30.                        unsigned char v,
  31.                        unsigned char *rgb)
  32. {
  33.     register int r, g, b;

  34.         r = (y + (359 * v)) >> 8;
  35.         g = (y - (88 * u) - (183 * v)) >> 8;
  36.         b = (y + (454 * u)) >> 8;
  37.         
  38.         b = (b > 255) ? 255 : ((b < 0) ? 0 : b);
  39.         g = (g > 255) ? 255 : ((g < 0) ? 0 : g);
  40.         r = (r > 255) ? 255 : ((r < 0) ? 0 : r);
  41.         
  42.         *(rgb++) = b;
  43.         *(rgb++) = g;
  44.         *(rgb++) = r;
  45.         *(rgb++) = 0x0;
  46. }

阅读(5151) | 评论(0) | 转发(0) |
0

上一篇:u-boot for s3c44b0x 移植心得

下一篇:Prayer

给主人留下些什么吧!~~