【转】YUV值对应的颜色
版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎大家积极评论,博主会一一答复!
最近有人在网上问我,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
生成代码:
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- typedef void Void;
- typedef bool Bool;
- typedef int Int;
- typedef unsigned char UChar;
- typedef UChar Pel; ///< 16-bit pixel type
- class TComPicYuv
- {
- private:
- // ------------------------------------------------------------------------------------------------
- // YUV buffer
- // ------------------------------------------------------------------------------------------------
- Pel* m_apiPicBufY; ///< Buffer (including margin)
- Pel* m_apiPicBufU;
- Pel* m_apiPicBufV;
- // ------------------------------------------------------------------------------------------------
- // Parameter for general YUV buffer usage
- // ------------------------------------------------------------------------------------------------
- Int m_iPicWidth; ///< Width of picture
- Int m_iPicHeight; ///< Height of picture
- public:
- TComPicYuv ();
- virtual ~TComPicYuv();
- // ------------------------------------------------------------------------------------------------
- // Memory management
- // ------------------------------------------------------------------------------------------------
- Bool create ( Int iPicWidth, Int iPicHeight );
- Void destroy ();
- Void setYuv (Pel pixelY,Pel pixelU,Pel pixelV);
- Void setPixel (int posX, int posY, int width, Pel pixelY,Pel pixelU,Pel pixelV);
- // ------------------------------------------------------------------------------------------------
- // Get information of picture
- // ------------------------------------------------------------------------------------------------
- Pel* getPicBufY () { return m_apiPicBufY ; }
- Pel* getPicBufU () { return m_apiPicBufU ; }
- Pel* getPicBufV () { return m_apiPicBufV ; }
- Int getWidth () { return m_iPicWidth; }
- Int getHeight () { return m_iPicHeight; }
- Int getStride () { return m_iPicWidth ; }
- Int getCStride () { return (m_iPicWidth >> 1); }
- };// END CLASS DEFINITION TComPicYuv
- TComPicYuv::TComPicYuv()
- {
- m_apiPicBufY = NULL; // Buffer (including margin)
- m_apiPicBufU = NULL;
- m_apiPicBufV = NULL;
- }
- TComPicYuv::~TComPicYuv()
- {
- }
- Bool TComPicYuv::create( Int iPicWidth, Int iPicHeight )
- {
- m_iPicWidth = iPicWidth;
- m_iPicHeight = iPicHeight;
- m_apiPicBufY = (Pel*)malloc(m_iPicWidth * m_iPicHeight * sizeof(Pel));
- m_apiPicBufU = (Pel*)malloc((m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel));
- m_apiPicBufV = (Pel*)malloc((m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel));
- return true;
- }
- Void TComPicYuv::destroy()
- {
- if( m_apiPicBufY ){ free( m_apiPicBufY ); m_apiPicBufY = NULL; }
- if( m_apiPicBufU ){ free( m_apiPicBufU ); m_apiPicBufU = NULL; }
- if( m_apiPicBufV ){ free( m_apiPicBufV ); m_apiPicBufV = NULL; }
- }
- Void TComPicYuv::setYuv(Pel pixelY,Pel pixelU,Pel pixelV)
- {
- if( m_apiPicBufY ){ memset(m_apiPicBufY, pixelY,m_iPicWidth * m_iPicHeight * sizeof(Pel)) ; }
- if( m_apiPicBufU ){ memset(m_apiPicBufU, pixelU,(m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel)) ; }
- if( m_apiPicBufV ){ memset(m_apiPicBufV, pixelV,(m_iPicWidth >>1) * (m_iPicHeight>>1) * sizeof(Pel)) ; }
- }
- Void TComPicYuv::setPixel(int posX, int posY, int width, Pel pixelY,Pel pixelU,Pel pixelV)
- {
- Pel *Y = m_apiPicBufY + posY*m_iPicWidth+posX;
- for(int h = 0; h<width; h++)
- {
- for(int w = 0; w<width;w++)
- {
- Y[h*m_iPicWidth + w] = pixelY;
- }
- }
- Pel *U = m_apiPicBufU + (posY>>1)*(m_iPicWidth>>1)+(posX>>1);
- Pel *V = m_apiPicBufV + (posY>>1)*(m_iPicWidth>>1)+(posX>>1);
- for(int h = 0; h<(width>>1); h++)
- {
- for(int w = 0; w<(width>>1);w++)
- {
- U[h*(m_iPicWidth>>1) + w] = pixelU;
- V[h*(m_iPicWidth>>1) + w] = pixelV;
- }
- }
- }
- int main()
- {
- TComPicYuv *frame = new TComPicYuv;
- TComPicYuv *clourMap = new TComPicYuv;
- frame->create(8,8);
- clourMap->create(512,512);
- FILE *FrameFile = fopen("D:\\clourFrame_8x8.yuv","wb");
- FILE *clourFile = fopen("D:\\clourMap_512x512.yuv","wb");
- for(int Y = 0; Y<256; Y++)
- {
- for(int U = 0; U<256; U++)
- {
- for(int V = 0; V<256; V++)
- {
- frame->setYuv((Pel)Y,(Pel)U,(Pel)V);
- fwrite(frame->getPicBufY(),1,frame->getWidth()*frame->getHeight(),FrameFile);
- fwrite(frame->getPicBufU(),1,(frame->getWidth()*frame->getHeight())>>2,FrameFile);
- fwrite(frame->getPicBufV(),1,(frame->getWidth()*frame->getHeight())>>2,FrameFile);
- int count = Y*256*256 + U*256 + V;
- if(count%1000000==0)
- {
- printf("=");
- }
- }
- }
- }
- for(int Y = 0; Y<256; Y++)
- {
- for(int U = 0; U<256; U++)
- {
- for(int V = 0; V<256; V++)
- {
- clourMap->setPixel(U*2,V*2,2,Y,U,V);
- }
- }
- fwrite(clourMap->getPicBufY(),1,clourMap->getWidth()*clourMap->getHeight(),clourFile);
- fwrite(clourMap->getPicBufU(),1,(clourMap->getWidth()*clourMap->getHeight())>>2,clourFile);
- fwrite(clourMap->getPicBufV(),1,(clourMap->getWidth()*clourMap->getHeight())>>2,clourFile);
- printf("*");
- }
- fclose(clourFile);
- fclose(FrameFile);
- frame->destroy();
- clourMap->destroy();
- }
转载:http://blog.csdn.net/cabbage2008/article/details/50117671
【转】YUV值对应的颜色的更多相关文章
- 常用icon以及color颜色RGB值和对应颜色效果图
Android谷歌官方扁平化设计常用icon集合 Android谷歌官方扁平化设计color颜色RGB值和对应颜色效果图.
- html根据下拉框选中的值修改背景颜色
错误的写法 <!doctype html><html><head><meta charset="utf-8"><title&g ...
- .NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度
.NET C#生成随机颜色,可以控制亮度,生成暗色或者亮色 基于YUV模式判断颜色明亮度 随机颜色在日常开发中很常用到,有时候要控制颜色明亮度,比如在白色背景网页上的随机颜色,一般要求颜色稍微暗一 ...
- 颜色的RGB值表示法
颜色的RGB值表示法 从物理光学试验中得出:红.绿.蓝三种色光是其他色光所混合不出来的.而这三种色光以不同比例的混合几乎可以得出自然界所有的颜色. 如红光与不同比例的绿光混合可以得出橙.黄.黄绿等色: ...
- YUV格式介绍
原文链接:http://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html YUV格式有两大类:planar和packed.对于plana ...
- 关于yuv格式
首先,内存分布 1:YUV420 (1):I420: YYYYYYYY UU VV =>YUV420P (2): ...
- 多媒体编程基础之RGB和YUV
一.概念 1.什么是RGB? 对一种颜色进行编码的方法统称为“颜色空间”或“色域”.用最简单的话说,世界上任何一种颜色的“颜色空间”都可定义成一个固定的数字或变量.RGB(红.绿.蓝)只是众多颜色空间 ...
- iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像
iOS面向编码|iOSVideoToolbox:读写解码回调函数CVImageBufferRef的YUV图像 本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImag ...
- Video Toolbox:读写解码回调函数CVImageBufferRef的YUV图像
本文档基于H.264的解码,介绍读写Video Toolbox解码回调函数参数CVImageBufferRef中的YUV或RGB数据的方法,并给出CVImageBufferRef生成灰度图代码.方便调 ...
随机推荐
- Java基础知识强化83:System类之gc()方法(垃圾回收)以及和finalize()区别
1. System概述: System类包含一些有用的类字段和方法.它不能被实例化. 2. gc()方法:垃圾回收器 public static void gc() 调用gc方法暗示着Ja ...
- 与useradd命令相关的两个默认配置文件
Configuration Files for User Management Defaults When working with tools as useradd, some defaul ...
- 图解JavaScript知识点
- String[]和ArrayList和LinkedList区别
String[]和ArrayList和LinkedList区别 参考文档如下: http://www.blogjava.net/flysky19/articles/92775.html http:// ...
- mysql的distinct理解
select distinct id,name from route where update_time>=''; 上面的sql语句的逻辑是两条记录的id,name只要有一个不一样,就算不一样. ...
- 一个打砖块的小游戏1.0 KILL THE BLOCKS !
/******************************************** * 程序名称:MR.DUAN 的打砖块(KILL THE BLOCKS !) * 作 者:WindAutum ...
- expr的简单应用
expr命令 是一个手工命令行计数器,用于在UNIX/LINUX下求表达式变量的值,一般用于整数值,也可用于字符串. –格式为: expr expression_r(命令读入Expression 参数 ...
- java加载配置文件
有时候一些变量可能会变,但直接写在程序代码中不好,因为有时候需要改的时候要改动源代码,这时候可以使用配置文件来管理.比如数据库中的端口和密码. 1. 把.properties配置文件放在src目录下. ...
- if exists用法
1 判断数据库是否存在Sql代码 if exists (select * from sys.databases where name = ’数据库名’) drop database [数据库名] ...
- python爬虫程序
http://blog.csdn.net/pleasecallmewhy/article/details/8922826 此人的博客关于python爬虫程序分析得很好!