版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎大家积极评论,博主会一一答复!

最近有人在网上问我,YUV的值对应的颜色是如何的

下面给出YUV值对应的颜色关系

256张图512x512,每张对应的Y为0~255   每4x4对应的是同一颜色区域  横坐标 U  纵坐标V

yuv下载地址

http://download.csdn.net/detail/cabbage2008/9314683

这里截取了Y=0,10,20,60,128,250,255几张

Y=0

Y=10

Y=20

Y=60

Y=128

Y=250

Y=255

生成代码:

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. typedef       void                Void;
  5. typedef       bool                Bool;
  6. typedef       int                 Int;
  7. typedef       unsigned char       UChar;
  8. typedef       UChar               Pel;        ///< 16-bit pixel type
  9. class TComPicYuv
  10. {
  11. private:
  12. // ------------------------------------------------------------------------------------------------
  13. //  YUV buffer
  14. // ------------------------------------------------------------------------------------------------
  15. Pel*  m_apiPicBufY;           ///< Buffer (including margin)
  16. Pel*  m_apiPicBufU;
  17. Pel*  m_apiPicBufV;
  18. // ------------------------------------------------------------------------------------------------
  19. //  Parameter for general YUV buffer usage
  20. // ------------------------------------------------------------------------------------------------
  21. Int   m_iPicWidth;            ///< Width of picture
  22. Int   m_iPicHeight;           ///< Height of picture
  23. public:
  24. TComPicYuv         ();
  25. virtual ~TComPicYuv();
  26. // ------------------------------------------------------------------------------------------------
  27. //  Memory management
  28. // ------------------------------------------------------------------------------------------------
  29. Bool  create      ( Int iPicWidth, Int iPicHeight );
  30. Void  destroy     ();
  31. Void  setYuv      (Pel pixelY,Pel pixelU,Pel pixelV);
  32. Void  setPixel    (int posX, int posY, int width, Pel pixelY,Pel pixelU,Pel pixelV);
  33. // ------------------------------------------------------------------------------------------------
  34. //  Get information of picture
  35. // ------------------------------------------------------------------------------------------------
  36. Pel*  getPicBufY  ()     { return m_apiPicBufY ; }
  37. Pel*  getPicBufU  ()     { return m_apiPicBufU ; }
  38. Pel*  getPicBufV  ()     { return m_apiPicBufV ; }
  39. Int   getWidth    ()     { return  m_iPicWidth;    }
  40. Int   getHeight   ()     { return  m_iPicHeight;   }
  41. Int   getStride   ()     { return  m_iPicWidth ;    }
  42. Int   getCStride  ()     { return  (m_iPicWidth >> 1); }
  43. };// END CLASS DEFINITION TComPicYuv
  44. TComPicYuv::TComPicYuv()
  45. {
  46. m_apiPicBufY      = NULL;   // Buffer (including margin)
  47. m_apiPicBufU      = NULL;
  48. m_apiPicBufV      = NULL;
  49. }
  50. TComPicYuv::~TComPicYuv()
  51. {
  52. }
  53. Bool TComPicYuv::create( Int iPicWidth, Int iPicHeight )
  54. {
  55. m_iPicWidth       = iPicWidth;
  56. m_iPicHeight      = iPicHeight;
  57. m_apiPicBufY      = (Pel*)malloc(m_iPicWidth * m_iPicHeight * sizeof(Pel));
  58. m_apiPicBufU      = (Pel*)malloc((m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel));
  59. m_apiPicBufV      = (Pel*)malloc((m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel));
  60. return true;
  61. }
  62. Void TComPicYuv::destroy()
  63. {
  64. if( m_apiPicBufY ){ free( m_apiPicBufY );    m_apiPicBufY = NULL; }
  65. if( m_apiPicBufU ){ free( m_apiPicBufU );    m_apiPicBufU = NULL; }
  66. if( m_apiPicBufV ){ free( m_apiPicBufV );    m_apiPicBufV = NULL; }
  67. }
  68. Void TComPicYuv::setYuv(Pel pixelY,Pel pixelU,Pel pixelV)
  69. {
  70. if( m_apiPicBufY ){ memset(m_apiPicBufY, pixelY,m_iPicWidth * m_iPicHeight * sizeof(Pel)) ; }
  71. if( m_apiPicBufU ){ memset(m_apiPicBufU, pixelU,(m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel)) ; }
  72. if( m_apiPicBufV ){ memset(m_apiPicBufV, pixelV,(m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel)) ; }
  73. }
  74. Void TComPicYuv::setPixel(int posX, int posY, int width, Pel pixelY,Pel pixelU,Pel pixelV)
  75. {
  76. Pel *Y = m_apiPicBufY + posY*m_iPicWidth+posX;
  77. for(int h = 0; h<width; h++)
  78. {
  79. for(int w = 0; w<width;w++)
  80. {
  81. Y[h*m_iPicWidth + w] = pixelY;
  82. }
  83. }
  84. Pel *U = m_apiPicBufU + (posY>>1)*(m_iPicWidth>>1)+(posX>>1);
  85. Pel *V = m_apiPicBufV + (posY>>1)*(m_iPicWidth>>1)+(posX>>1);
  86. for(int h = 0; h<(width>>1); h++)
  87. {
  88. for(int w = 0; w<(width>>1);w++)
  89. {
  90. U[h*(m_iPicWidth>>1) + w] = pixelU;
  91. V[h*(m_iPicWidth>>1) + w] = pixelV;
  92. }
  93. }
  94. }
  95. int main()
  96. {
  97. TComPicYuv *frame = new TComPicYuv;
  98. TComPicYuv *clourMap = new TComPicYuv;
  99. frame->create(8,8);
  100. clourMap->create(512,512);
  101. FILE *FrameFile = fopen("D:\\clourFrame_8x8.yuv","wb");
  102. FILE *clourFile = fopen("D:\\clourMap_512x512.yuv","wb");
  103. for(int Y = 0; Y<256; Y++)
  104. {
  105. for(int U = 0; U<256; U++)
  106. {
  107. for(int V = 0; V<256; V++)
  108. {
  109. frame->setYuv((Pel)Y,(Pel)U,(Pel)V);
  110. fwrite(frame->getPicBufY(),1,frame->getWidth()*frame->getHeight(),FrameFile);
  111. fwrite(frame->getPicBufU(),1,(frame->getWidth()*frame->getHeight())>>2,FrameFile);
  112. fwrite(frame->getPicBufV(),1,(frame->getWidth()*frame->getHeight())>>2,FrameFile);
  113. int  count = Y*256*256 + U*256 + V;
  114. if(count%1000000==0)
  115. {
  116. printf("=");
  117. }
  118. }
  119. }
  120. }
  121. for(int Y = 0; Y<256; Y++)
  122. {
  123. for(int U = 0; U<256; U++)
  124. {
  125. for(int V = 0; V<256; V++)
  126. {
  127. clourMap->setPixel(U*2,V*2,2,Y,U,V);
  128. }
  129. }
  130. fwrite(clourMap->getPicBufY(),1,clourMap->getWidth()*clourMap->getHeight(),clourFile);
  131. fwrite(clourMap->getPicBufU(),1,(clourMap->getWidth()*clourMap->getHeight())>>2,clourFile);
  132. fwrite(clourMap->getPicBufV(),1,(clourMap->getWidth()*clourMap->getHeight())>>2,clourFile);
  133. printf("*");
  134. }
  135. fclose(clourFile);
  136. fclose(FrameFile);
  137. frame->destroy();
  138. clourMap->destroy();
  139. }

转载:http://blog.csdn.net/cabbage2008/article/details/50117671

【转】YUV值对应的颜色的更多相关文章

  1. 常用icon以及color颜色RGB值和对应颜色效果图

    Android谷歌官方扁平化设计常用icon集合   Android谷歌官方扁平化设计color颜色RGB值和对应颜色效果图.

  2. html根据下拉框选中的值修改背景颜色

    错误的写法 <!doctype html><html><head><meta charset="utf-8"><title&g ...

  3. .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度

    .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度   随机颜色在日常开发中很常用到,有时候要控制颜色明亮度,比如在白色背景网页上的随机颜色,一般要求颜色稍微暗一 ...

  4. 颜色的RGB值表示法

    颜色的RGB值表示法 从物理光学试验中得出:红.绿.蓝三种色光是其他色光所混合不出来的.而这三种色光以不同比例的混合几乎可以得出自然界所有的颜色. 如红光与不同比例的绿光混合可以得出橙.黄.黄绿等色: ...

  5. YUV格式介绍

    原文链接:http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html YUV格式有两大类:planar和packed.对于plana ...

  6. 关于yuv格式

    首先,内存分布        1:YUV420          (1):I420:              YYYYYYYY UU VV    =>YUV420P          (2): ...

  7. 多媒体编程基础之RGB和YUV

    一.概念 1.什么是RGB? 对一种颜色进行编码的方法统称为“颜色空间”或“色域”.用最简单的话说,世界上任何一种颜色的“颜色空间”都可定义成一个固定的数字或变量.RGB(红.绿.蓝)只是众多颜色空间 ...

  8. iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像

    iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...

  9. Video Toolbox:读写解码回调函数CVImageBufferRef的YUV图像

    本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImageBufferRef中的YUV或RGB数据的方法,并给出CVImageBufferRef生成灰度图代码.方便调 ...

随机推荐

  1. karma、jasmine做angularjs单元测试

    引用文:karma.jasmine做angularjs单元测试 karma和jasmine介绍 <1>技术介绍 karma karma是Testacular的新名字 karma是用来自动化 ...

  2. C++输出hello world 详细注释

    /* #include<iostream> #:预处理标志,后面跟预处理指令,include:预处理指令,包含 <iostream>:c++头文件,输入输出流 这行的作用就是在 ...

  3. java的练习

    import java.awt.GridLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.s ...

  4. jquery.ajax提交多值(数组)

    偶尔会遇到类似复选框的一个属性存在多值情况,若使用ajax提交的化,设置data :{ids:[1,2,3,4]} 提交后,后台无法使用ids获取到数据. 这里可以用到ajax的 traditiona ...

  5. SharePoint中获取当前登录的用户名几种方式

    第一种方法: System.Web.HttpContext.Current.User.Identity.Name.ToString();或者: SPContext.Current.Site.OpenW ...

  6. DNN模块开发之利器篇:七种武器

    我们在进行DNN模块开发时经常需要调用Dotnetnuke.dll中的方法函数,模块开发用到DNN的方法函数会让你的开发更加得心应手,下面我们就来介绍一下.   1) PortalModuleBase ...

  7. ajax+ashx 完美实现input file上传文件

    1.input file 样式不能满足需求 <input type="file" value="浏览" /> IE8效果图:    Firefox效 ...

  8. 华为S5300交换机配置基于接口的本地端口镜像

    配置思路 1.  将Ethernet0/0/20接口配置为观察端口(监控端口) 2.  将Ethernet0/0/1----Ethernet0/0/10接口配置为镜像端口 配置步骤 1.  配置观察端 ...

  9. quartz2.2.1-测试01

    工程列表: (1)web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app versio ...

  10. Practice: Process logs with Apache Hadoop

    http://www.ibm.com/developerworks/library/os-log-process-hadoop/ Analyzing Apache logs with Apache P ...