<div dir="ltr">If you convert any RGB format to YUV420 you will lose data. If you want to just change the format to YCbCr without losing data.. you can try YUV444 format... its 3 bytes per pixel, just like RGB, so you will not lose any data.</div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-27 9:25 GMT-03:00 Jasleen Kaur <span dir="ltr"><<a href="mailto:Jasleen@beesys.com" target="_blank">Jasleen@beesys.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt">
<div>We have ARGB buffer to be compressed and then decoded also.</div>
<div>But for encoding the data the input as ARGB wasnt accepted.</div>
<div>The data was converted to YUV and then compressed, and on the receive side decoded and then converted back to ARGB.</div>
<div><br>
</div>
<div><b>The problem is that, While this conversion happens colours change.</b></div>
<div><br>
</div>
<div>Following is the code used to convert from ARGB to YUV and YUV to ARGB respectively.</div>
<div><br>
</div>
<div><br>
</div>
<div>
<div>void <b>ConvertToYUV</b>(int iWidth, int iHeight, BYTE* pARGBBuff)</div>
<div>{<span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"></span>#define RNDTO2(X) ( ( (X) & 0xFFFFFFFE )</div>
<div><span style="white-space:pre-wrap"></span>#define RNDTO32(X) ( ( (X) % 32 ) ? ( ( (X) + 32 ) & 0xFFFFFFE0 ) : (X) )</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>//int ystride  = RNDTO32 ( iWidth );</div>
<div>    //int uvstride = RNDTO32 ( iWidth / 2 );</div>
<div><span style="white-space:pre-wrap"></span>int ystride  = iWidth;</div>
<div>    int uvstride = iWidth / 2;</div>
<div>    int ysize    = ystride * iHeight;</div>
<div>    int vusize   = uvstride * ( iHeight / 2 );</div>
<div>    int size     = ysize + ( 2 * vusize );</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>if(m_sws_ctx == NULL)</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>//SwsFilter</div>
<div><span style="white-space:pre-wrap"></span>m_sws_ctx = sws_getContext(iWidth, </div>
<div><span style="white-space:pre-wrap"></span>iHeight,</div>
<div><span style="white-space:pre-wrap"></span>AV_PIX_FMT_BGRA, </div>
<div><span style="white-space:pre-wrap"></span>iWidth, iHeight,</div>
<div><span style="white-space:pre-wrap"></span>AV_PIX_FMT_YUV420P, </div>
<div><span style="white-space:pre-wrap"></span>SWS_FAST_BILINEAR, 0, 0, 0);</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>m_picture_buf = (uint8_t*)malloc(size);</div>
<div><span style="white-space:pre-wrap"></span>}<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span></div>
<div>    //uint8_t *plane[] = { m_picture_buf, m_picture_buf + ysize, m_picture_buf + ysize + vusize};</div>
<div><span style="white-space:pre-wrap"></span>uint8_t *plane[] = { m_picture_buf, m_picture_buf + ysize + vusize, m_picture_buf + ysize};</div>
<div>    int stride[] = { ystride, uvstride, uvstride};</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>uint8_t *inData[1] = { pARGBBuff };</div>
<div>    int inLinesize[1] = { 4 * iWidth}; </div>
<div><br>
</div>
<div>    sws_scale(m_sws_ctx, inData, inLinesize, 0, iHeight, plane, stride);<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span></div>
<div>}</div>
</div>
<br>
<div>
<div>
<div>void <b>ConvertToARGB</b>(int iWidth, int iHeight)</div>
<div>{<span style="white-space:pre-wrap"> </span></div>
<div><span style="white-space:pre-wrap"></span>#define RNDTO2(X) ( ( (X) & 0xFFFFFFFE )</div>
<div><span style="white-space:pre-wrap"></span>#define RNDTO32(X) ( ( (X) % 32 ) ? ( ( (X) + 32 ) & 0xFFFFFFE0 ) : (X) )</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>int iSize = iWidth * iHeight * 4;</div>
<div><span style="white-space:pre-wrap"></span>int ystride  = RNDTO32 ( iWidth );</div>
<div>    int uvstride = RNDTO32 ( iWidth / 2 );<span style="white-space:pre-wrap">
</span></div>
<div>    int ysize    = ystride * iHeight;</div>
<div>    int vusize   = uvstride * ( iHeight / 2 );</div>
<div> </div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>if(m_sws_ctx == NULL)</div>
<div><span style="white-space:pre-wrap"></span>{</div>
<div><span style="white-space:pre-wrap"></span>//SwsFilter</div>
<div><span style="white-space:pre-wrap"></span>m_sws_ctx = sws_getContext(iWidth, </div>
<div><span style="white-space:pre-wrap"></span>iHeight,</div>
<div><span style="white-space:pre-wrap"></span>AV_PIX_FMT_YUV420P, </div>
<div><span style="white-space:pre-wrap"></span>iWidth, iHeight,</div>
<div><span style="white-space:pre-wrap"></span>AV_PIX_FMT_BGRA, </div>
<div><span style="white-space:pre-wrap"></span>SWS_FAST_BILINEAR, 0, 0, 0);</div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>m_picture_buf = (uint8_t*)malloc(iSize);</div>
<div><span style="white-space:pre-wrap"></span>}<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span></div>
<div><span style="white-space:pre-wrap"></span>// src<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span>int srcstride[] = {ystride, uvstride, uvstride};   </div>
<div><br>
</div>
<div><span style="white-space:pre-wrap"></span>// dest</div>
<div><span style="white-space:pre-wrap"></span>uint8_t *destplane[] = {m_picture_buf};</div>
<div>    int stride[] = { iWidth * 4};<span style="white-space:pre-wrap">
</span></div>
<div><span style="white-space:pre-wrap"></span></div>
<div>    int iHeightReturned = sws_scale(m_sws_ctx, m_picture->data, srcstride, 0, iHeight, destplane, stride);<span style="white-space:pre-wrap">
</span><span style="font-size:10pt;white-space:pre-wrap"></span></div>
<div>  </div>
<div><b>  <span style="font-size:13.3333330154419px">m_picture is the output of </span><span style="font-size:10pt">avcodec_decode_video2.</span></b><span style="font-size:10pt;white-space:pre-wrap">
</span></div>
<div>}</div>
<div><br>
</div>
<div><br>
</div>
<div>What correction needs to be done in the code, so that colours remain intact.</div>
<div><br>
</div>
<div>Thanks and regards</div><span class="HOEnZb"><font color="#888888">
<div>Jasleen</div>
</font></span></div>
</div>
</div>
</div>

<br>_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="http://ffmpeg.org/mailman/listinfo/libav-user" target="_blank">http://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><table border="0" width="440px" cellpadding="0" cellspacing="0" style="font-size:12.8000001907349px"><tbody><tr><td align="left" width="99%"><span style="color:rgb(10,76,160);font-size:15px"><img src="cid:ii_i1b2qszh0_149154ae60de1073" align="absmiddle" height="28" width="28"> ​ <font size="4">Rafael Lúcio</font></span><font size="1" color="#888888"><span style="color:rgb(0,0,153)"><br>INOVA COMUNICAÇÕES INTELIGENTES  </span><br></font><font color="#888888"><div><a value="+556191657397" style="color:rgb(34,34,34);font-size:x-small"><font color="#000099">+55 61 9996 5587</font></a><br></div><div><font style="color:rgb(51,51,255)"><a value="+556132745459" style="color:rgb(34,34,34)"><font size="1" color="#000099">+55 61 3574- 7100</font></a></font></div><div><font style="color:rgb(51,51,255)"><a value="+556132745459" style="color:rgb(34,34,34)"><font size="1" color="#000099">Fax +55 61 3574 7024</font></a></font></div><div><font size="1"><a href="http://www.inova.in/" style="color:rgb(17,85,204)" target="_blank">http://www.inova.in/</a></font></div></font></td><td align="right" nowrap width="1px"><img src="http://www.inova.in/tmp/inova/selo-iso.png" style="font-size:12.7272720336914px;text-align:start;color:rgb(136,136,136)"><br></td></tr><tr><td colspan="2" nowrap><span style="color:rgb(0,102,0)"><br>Antes de imprimir, pense em sua responsabilidade com o MEIO AMBIENTE<br><br></span></td></tr></tbody></table></div><div dir="ltr"><div><font size="1" color="#666666">---- BEGIN SSH2 PUBLIC KEY ----<br></font></div><div><div><font size="1" color="#666666">AAAAB3NzaC1yc2EAAAABJQAAAQEAmEyriiqf7mtO/4kLHp2pbbJ1ScVD73z8RqEK<br></font></div><div><font size="1" color="#666666">evHWx1tPEIv749EnghOFVvg7xYdyE0sfk6UT8EAVznsOmzU96F+ENdsRGFZhDIk6</font></div><div><font size="1" color="#666666">kjL9ZabmLMzIlRqh6naB6aJl7/sut7SGwxV1CIr0DPWXtTIr+pSkBzKfPmR6dZ4o</font></div><div><font size="1" color="#666666">OIcPsSY3hFaq7zTPLWm/IOnZO/9NWvI7d+v0ULfj3pslHeVkUlaqD8D/sm/A+qar</font></div><div><font size="1" color="#666666">DXd/3eVaPLE8FyVGqLhLgoqoDRdqL6KCX9kdiigStuXJ6ZxjXeqWUzHbSiHn0YMy</font></div><div><font size="1" color="#666666">LHtUmcYPnYuEx3dEhPqMLSr/m+RSMHUQBW6umlhyejN2AfeB/w==</font></div><div><font size="1" color="#666666">---- END SSH2 PUBLIC KEY ----</font></div></div><div><br></div></div></div></div></div></div>
</div>