【转】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生成灰度图代码.方便调 ...
随机推荐
- UVA 12378 Ball Blasting Game 【Manacher回文串】
Ball Blasting Game Morteza is playing a ball blasting game. In this game there is a chain of differe ...
- Linux LVM 扩展磁盘分区
系统:centos 6.3--新建分区 fdisk -l /dev/sdc # 查看分区 fdisk /dev/sdc # 创建分区 :n ...
- 启动android程序报错
提示错误如下: The connection to adb is down, and a severe error has occured. [2010-03-11 09:36:56 - HelloO ...
- Asp.Net WebApi 启用CORS跨域访问指定多个域名
1.后台action指定 EnableCors指定可访问的域名多个,使用逗号隔开 //支持客户端凭据提交,指定多个域名,使用逗号隔开 [EnableCors("http://localhos ...
- WPF 打开文件 打开路径对话框
WPF调用WinForm中的 OpenFileDialog 和 FolderBrowserDialog 来实现响应的功能 对应的引用程序集: using System.Windows.Forms; O ...
- Nagios监控memcached
下载地址: http://search.cpan.org/CPAN/authors/id/Z/ZI/ZIGOROU/Nagios-Plugins-Memcached-0.02.tar.gz http: ...
- 【转】解析JDK 7的动态类型语言支持
http://www.infoq.com/cn/articles/jdk-dynamically-typed-language Java虚拟机的字节码指令集的数量自从Sun公司的第一款Java虚拟机问 ...
- Java中如何判断当前环境是大端字节顺序还是小端字节顺序
Java非字节类型的基本类型,除了布尔型都是由组合在一起的几个字节组成的.这些数据类 型及其大小总结在表 2-1 中. 表:基本数据类型及其大小 数据类型 大小(以字节表示) Byte 1 Char ...
- 武汉科技大学ACM:1007: 陶陶摘苹果
Problem Description 厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试. 个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹 ...
- php中curl、fsockopen的应用
最近要用到通过post上传文件,网上盛传的有curl的post提交和fsockopen,其中curl最简单,于是从最简单的说起. 这是简单的将一个变量post到另外一个页面 $url = ''; $d ...