<div dir="ltr"><div class="gmail_quote">On Tue, Jun 5, 2012 at 5:16 AM, Sampath Subasinghe <span dir="ltr"><<a href="mailto:susiriss@gmail.com" target="_blank">susiriss@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
          I am using libswscale to do some YUV - RGB conversion back and forth. There are 2 steps performed on an image.<br>
<br>
1. RGB - YUV conversion<br>
2. YUV - RGB conversion<br>
<br>
Issue is that in the image output from step 2, the right edge of the image is missing, means the pixels are black. The rest of the image seems ok compared to original image. This black edge is roughly 5-10 pixels wide and varies depending on the size of the image. This issue happens for images with certain dimensions. For some images this issue does not appear. So I guess this is due to libswscale issue or the way i'm using it is wrong. Also I get a libswscale warning on this conversion.<br>

<br>
[swscaler @ 0x1768020] Warning: data is not aligned! This can lead to a speedloss<br>
<br>
If I analyze the Y values along the right edge, I can see that they have valid values, so I deduce this is an issue arising from step 2 (YUV to RGB). My code (truncated for clarity) looks like follows for each step.<br>
<br>
Step 1. RGB- YUV conversion.-------------------<u></u>---------<br>
<br>
// Create YUV buffer<br>
    m_bufferSize = avpicture_get_size(PIX_FMT_<u></u>YUV420P, width, height);<br>
    avPictureInfo_ = avcodec_alloc_frame();<br>
    m_buffer = (uint8_t *)av_malloc(m_bufferSize);<br>
<br>
    avpicture_fill((AVPicture*)<u></u>avPictureInfo_, m_buffer, PIX_FMT_YUV420P,<br>
                   width, height);<br>
<br>
// Then fill it with  RGB data<br>
struct SwsContext *img_convert_ctx = sws_getContext(m_width, m_height, PIX_FMT_RGB24,<br>
                                                        m_width, m_height, PIX_FMT_YUV420P, SWS_BICUBIC,<br>
                                                        NULL, NULL, NULL);<br>
<br>
    if (img_convert_ctx == NULL) {<br>
        return NULL;<br>
    }<br>
<br>
        uint8_t * srcData[4] = {m_buffer, 0, 0, 0};<br>
    int srcLineSize[4] = {m_width * 3 * sizeof(uint8_t), 0, 0, 0};<br>
    sws_scale(img_convert_ctx, srcData, srcLineSize, 0,<br>
              m_height, yuvImage->avPictureInfo_-><u></u>data, yuvImage->avPictureInfo_-><u></u>linesize);<br>
<br>
    free(img_convert_ctx);<br>
<br>
Step 2: YUV - RGB conversion ------------------------------<u></u>--------------------<br>
<br>
    m_bufferSize = avpicture_get_size(PIX_FMT_<u></u>RGB24, width, height);<br>
    m_buffer = (uint8_t *)av_malloc(m_bufferSize);<br>
<br>
struct SwsContext *img_convert_ctx = sws_getContext(m_width, m_height, PIX_FMT_YUV420P,<br>
                                                        m_width, m_height, PIX_FMT_RGB24, SWS_BICUBIC,<br>
                                                        NULL, NULL, NULL);<br>
<br>
    if (img_convert_ctx == NULL) {<br>
        return NULL;<br>
    }<br>
<br>
<br>
    AVFrame * rgbPictInfo = avcodec_alloc_frame();<br>
    avpicture_fill((AVPicture*)<u></u>rgbPictInfo, rgbImage->m_buffer, PIX_FMT_RGB24,<br>
                   m_width, m_height);<br>
    sws_scale(img_convert_ctx, avPictureInfo_->data, avPictureInfo_->linesize, 0,<br>
              m_height, rgbPictInfo->data, rgbPictInfo->linesize);<br>
<br>
------------------------------<u></u>-----------------<br>
<br>
I am using libav functions to allocate memory etc, so they should take care of alignment. So why does libswscale complain about not aligned data? Why are pixels missing along in the right edge of the image? I'm also attaching two images from step 1 and 2.<br>

<br>
Please help!<span class="HOEnZb"><font color="#888888"><br>
-Sampath</font></span></blockquote><div><br>Your example is 45 pixel wide.<br><br>It is a natural limitation of YUV_420P images that the dimensions should divide 2, or even 4. You also have SWS_BICUBIC that requires more alignment on the edges.<br>
<br>Sincerely,<br>Alex Cohn<br></div></div></div>