﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-x-zone-文章分类-RGB&amp;&amp;YUV</title><link>http://www.cppblog.com/cc1983/category/5450.html</link><description>all about c++</description><language>zh-cn</language><lastBuildDate>Tue, 20 May 2008 02:58:57 GMT</lastBuildDate><pubDate>Tue, 20 May 2008 02:58:57 GMT</pubDate><ttl>60</ttl><item><title>yuv420平面格式转换为rgb24(带跨度,ddraw输出)</title><link>http://www.cppblog.com/cc1983/articles/35096.html</link><dc:creator>刘旭</dc:creator><author>刘旭</author><pubDate>Wed, 24 Oct 2007 15:02:00 GMT</pubDate><guid>http://www.cppblog.com/cc1983/articles/35096.html</guid><wfw:comment>http://www.cppblog.com/cc1983/comments/35096.html</wfw:comment><comments>http://www.cppblog.com/cc1983/articles/35096.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cc1983/comments/commentRss/35096.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cc1983/services/trackbacks/35096.html</trackback:ping><description><![CDATA[<p>void yuv420_to_rgb24(unsigned char *pdata, int stride, int width, int height, unsigned char *pdst)<br>{<br>&nbsp;const unsigned char *Y, *U, *V;<br>&nbsp;unsigned char *RGB;<br>&nbsp;int x, y;</p>
<p>&nbsp;if (stride &lt; 0) {<br>&nbsp;&nbsp;Y = pdata - stride * (height - 1);<br>&nbsp;&nbsp;U = pdata - (stride / 2) * (height * 5 / 2 - 1);<br>&nbsp;&nbsp;V = pdata - (stride / 2) * (height * 3 - 1);<br>&nbsp;} else {<br>&nbsp;&nbsp;Y = pdata;<br>&nbsp;&nbsp;U = pdata + stride * height;<br>&nbsp;&nbsp;V = pdata + stride * height * 5 / 4;<br>&nbsp;}<br>&nbsp;RGB = pdst;<br>&nbsp;for(y=0; y&lt;height/2; y++)<br>&nbsp;{<br>&nbsp;&nbsp;unsigned char *pDst1 = RGB;<br>&nbsp;&nbsp;unsigned char *pDst2 = RGB+width*3;<br>&nbsp;&nbsp;const unsigned char *pYSrc1 = Y;<br>&nbsp;&nbsp;const unsigned char *pYSrc2 = Y + stride;<br>&nbsp;&nbsp;for(x=0; x&lt;width/2; x++)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;const int Uo = U[x]-128;<br>&nbsp;&nbsp;&nbsp;const int Vo = V[x]-128;<br>&nbsp;&nbsp;&nbsp;const int Ro = (91181*Uo)&gt;&gt;16;<br>&nbsp;&nbsp;&nbsp;const int Go = (22553*Vo + 46801*Uo)&gt;&gt;16;<br>&nbsp;&nbsp;&nbsp;const int Bo = (116129*Vo)&gt;&gt;16;</p>
<p>&nbsp;&nbsp;&nbsp;TO_RGB24(pDst1,&nbsp;&nbsp; pYSrc1)<br>&nbsp;&nbsp;&nbsp;&nbsp;pDst1 +=6;<br>&nbsp;&nbsp;&nbsp;pYSrc1+=2;<br>&nbsp;&nbsp;&nbsp;TO_RGB24(pDst2,&nbsp;&nbsp; pYSrc2)<br>&nbsp;&nbsp;&nbsp;&nbsp;pDst2 +=6;<br>&nbsp;&nbsp;&nbsp;pYSrc2+=2;<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;RGB&nbsp; += width*6;<br>&nbsp;&nbsp;Y&nbsp;&nbsp;&nbsp; += 2*stride;<br>&nbsp;&nbsp;U&nbsp;&nbsp;&nbsp; += stride/2;<br>&nbsp;&nbsp;V&nbsp;&nbsp;&nbsp; += stride/2;<br>&nbsp;}<br>}</p>
<img src ="http://www.cppblog.com/cc1983/aggbug/35096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cc1983/" target="_blank">刘旭</a> 2007-10-24 23:02 <a href="http://www.cppblog.com/cc1983/articles/35096.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RGB24到YUV420平面格式</title><link>http://www.cppblog.com/cc1983/articles/35094.html</link><dc:creator>刘旭</dc:creator><author>刘旭</author><pubDate>Wed, 24 Oct 2007 14:58:00 GMT</pubDate><guid>http://www.cppblog.com/cc1983/articles/35094.html</guid><wfw:comment>http://www.cppblog.com/cc1983/comments/35094.html</wfw:comment><comments>http://www.cppblog.com/cc1983/articles/35094.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/cc1983/comments/commentRss/35094.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/cc1983/services/trackbacks/35094.html</trackback:ping><description><![CDATA[#define SCALEBITS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8<br>#define ONE_HALF&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (1 &lt;&lt; (SCALEBITS - 1))<br>#define FIX(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((int) ((x) * (1L&lt;&lt;SCALEBITS) + 0.5))<br>typedef unsigned char&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint8_t;<br>void rgb24_to_yuv420p(uint8_t *lum, uint8_t *cb, uint8_t *cr, uint8_t *src, int width, int height)<br>{<br>&nbsp;&nbsp;&nbsp; int wrap, wrap3, x, y;<br>&nbsp;&nbsp;&nbsp; int r, g, b, r1, g1, b1;<br>&nbsp;&nbsp;&nbsp; uint8_t *p;<br>&nbsp;&nbsp;&nbsp; wrap = width;<br>&nbsp;&nbsp;&nbsp; wrap3 = width * 3;<br>&nbsp;&nbsp;&nbsp; p = src;<br>&nbsp;&nbsp;&nbsp; for (y = 0; y &lt; height; y += 2)<br>&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nb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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b1 += b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) &gt;&gt; SCALEBITS;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p += wrap3;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum += wrap;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r = p[0];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g = p[1];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = p[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1 += r;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g1 += g;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b1 += b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) &gt;&gt; SCALEBITS;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r = p[3];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g = p[4];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b = p[5];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; r1 += r;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g1 += g;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; b1 += b;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) &gt;&gt; SCALEBITS;<br>&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb[0] = (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +<br>&nbsp;&nbsp;&nbsp;&nbsp;FIX(0.50000) * b1 + 4 * ONE_HALF - 1) &gt;&gt; (SCALEBITS + 2)) + 128);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cr[0] = (((FIX(0.50000) * r1 - FIX(0.41869) * g1 -<br>&nbsp;&nbsp;&nbsp;&nbsp;FIX(0.08131) * b1 + 4 * ONE_HALF - 1) &gt;&gt; (SCALEBITS + 2)) + 128);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cr++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p += -wrap3+2 * 3;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum += -wrap + 2;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p += wrap3;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lum += wrap;<br>&nbsp;&nbsp;&nbsp; }<br>} 
<img src ="http://www.cppblog.com/cc1983/aggbug/35094.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/cc1983/" target="_blank">刘旭</a> 2007-10-24 22:58 <a href="http://www.cppblog.com/cc1983/articles/35094.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>