NV21数据的旋转

简介: NV21数据的旋转

镜像之后,果然要旋转。于是从网上搜索了几个算法,并进行了验证、优化。分享给大家。


 需要提醒的是,如果进行编码,注意90、270时,宽高要进行对换。


public static byte[] NV21_rotate_to_270(byte[] nv21_data, byte[] nv21_rotated, int width, int height)
    {
        int y_size = width * height;
        int i = 0;
        // Rotate the Y luma
        for (int x = width - 1; x >= 0; x--)
        {
            int offset = 0;
            for (int y = 0; y < height; y++)
            {
                nv21_rotated[i] = nv21_data[offset + x];
                i++;
                offset += width;
            }
        }
        // Rotate the U and V color components
        i = y_size;
        for (int x = width - 1; x > 0; x = x - 2)
        {
            int offset = y_size;
            for (int y = 0; y < height / 2; y++)
            {
                nv21_rotated[i] = nv21_data[offset + (x - 1)];
                i++;
                nv21_rotated[i] = nv21_data[offset + x];
                i++;
                offset += width;
            }
        }
        return nv21_rotated;
    }
    public static byte[] NV21_rotate_to_180(byte[] nv21_data, byte[] nv21_rotated, int width, int height)
    {
        int y_size = width * height;
        int buffser_size = y_size * 3 / 2;
        int i = 0;
        int count = 0;
        for (i = y_size - 1; i >= 0; i--)
        {
            nv21_rotated[count] = nv21_data[i];
            count++;
        }
        for (i = buffser_size - 1; i >= y_size; i -= 2)
        {
            nv21_rotated[count++] = nv21_data[i - 1];
            nv21_rotated[count++] = nv21_data[i];
        }
        return nv21_rotated;
    }
    public static byte[] NV21_rotate_to_90(byte[] nv21_data, byte[] nv21_rotated, int width, int height)
    {
        int y_size = width * height;
        int buffser_size = y_size * 3 / 2;
        // Rotate the Y luma
        int i = 0;
        int startPos = (height - 1)*width;
        for (int x = 0; x < width; x++)
        {
            int offset = startPos;
            for (int y = height - 1; y >= 0; y--)
            {
                nv21_rotated[i] = nv21_data[offset + x];
                i++;
                offset -= width;
            }
        }
        // Rotate the U and V color components
        i = buffser_size - 1;
        for (int x = width - 1; x > 0; x = x - 2)
        {
            int offset = y_size;
            for (int y = 0; y < height / 2; y++)
            {
                nv21_rotated[i] = nv21_data[offset + x];
                i--;
                nv21_rotated[i] = nv21_data[offset + (x - 1)];
                i--;
                offset += width;
            }
        }
        return nv21_rotated;
    }
目录
相关文章
|
8月前
|
存储 编解码 Android开发
NV21、NV12、YV12、RGB、YUV、RGBA、RGBX8888等图像色彩编码格式区别
NV21、NV12、YV12、RGB、YUV、RGBA、RGBX8888都是常见的图像颜色编码格式,它们之间的主要区别在于色彩空间和数据排列方式。
135 0
|
8月前
|
编解码 API 开发工具
NV21、NV12、YV12、RGB565、YUV等颜色编码格式区别和接口设计探讨
NV21、NV12、YV12、RGB565、YUV分别是不同的颜色编码格式,这些颜色编码格式各有特点,适用于不同的应用场景。选择合适的颜色编码格式取决于具体的需求和环境:
150 1
|
9月前
旋转的沙漏-[ Qt绘制旋转图像]
旋转的沙漏-[ Qt绘制旋转图像]
99 0
|
10月前
|
算法
DX 纹理像素格式转换算法 R10G10B10A2 转 R8G8B8A8
DX 纹理像素格式转换算法 R10G10B10A2 转 R8G8B8A8
90 0
|
人工智能
【数据增强】90°、180°和270°翻转图片(*4)
【数据增强】90°、180°和270°翻转图片(*4)
【数据增强】90°、180°和270°翻转图片(*4)
|
算法
NV21数据的旋转
NV21数据的旋转
146 0
|
Linux C语言
RGB源数据操作:图片顺时针90°旋转
RGB源数据操作:图片顺时针90°旋转
131 0
RGB源数据操作:图片顺时针90°旋转
RGB源数据操作:图片顺时针180°镜像、顺时针180°旋转
RGB源数据操作:图片顺时针180°镜像、顺时针180°旋转
119 0
RGB源数据操作:图片顺时针180°镜像、顺时针180°旋转
|
Python
Halcon读取dxf文件生成xld,然后实现点坐标遍历/缩放/镜像/求最大面积等操作(★firecat推荐★)
Halcon读取dxf文件生成xld,然后实现点坐标遍历/缩放/镜像/求最大面积等操作(★firecat推荐★)
558 0