美文网首页
Android YUV旋转

Android YUV旋转

作者: 倬倬爸 | 来源:发表于2018-06-27 14:51 被阅读0次

1、旋转算法

void    rotateYUV420Degree270(char* src, char* dest, int m_nWidth, int m_nHeight) {
//    H264LOG("H264Encoder::rotateYUV420Degree270 enter m_nWidth = ", m_nWidth);
    int srcImageWidth = m_nHeight;
    int srcImageHeight = m_nWidth;
    int imageSize = m_nWidth*m_nHeight;
    // Rotate the Y luma
    int i = 0;
    for(int x = srcImageWidth-1;x >= 0;x--)
    {
        for(int y = 0;y < srcImageHeight;y++)
        {
            dest[i] = src[y*srcImageWidth+x];
            i++;
        }
    }
//     H264LOG("H264Encoder::rotateYUV420Degree270 rotate Y.");
    // Rotate the U and V color components
    i = imageSize;
    for(int x = srcImageWidth-1;x > 0;x=x-2)
    {
        for(int y = 0;y < srcImageHeight/2;y++)
        {
            dest[i] = src[imageSize+(y*srcImageWidth)+(x-1)];
            i++;
            dest[i] = src[imageSize+(y*srcImageWidth)+x];
            i++;
        }
    }
//    H264LOG("H264Encoder::rotateYUV420Degree270 exit.");
}

void    rotateYUV420Degree90(char *src, char *des, int m_nWidth, int m_nHeight)
{
    int width = m_nHeight;
    int height = m_nWidth;
    int wh = width * height;
    //旋转Y
    int k = 0;
    for(int i = 0; i < width; i++) {
        for(int j = 0; j < height; j++)
        {
            des[k] = src[width * j + i];
            k++;
        }
    }

    for(int i = 0; i < width; i += 2) {
        for(int j = 0; j < height / 2; j++)
        {
            des[k] = src[wh+ width * j + i];
            des[k+1] = src[wh + width * j + i + 1];
            k+=2;
        }
    }
}

相关文章

网友评论

      本文标题:Android YUV旋转

      本文链接:https://www.haomeiwen.com/subject/eewbyftx.html