美文网首页
Android YUV

Android YUV

作者: Frank_Kivi | 来源:发表于2019-01-18 14:10 被阅读7次
  1. yuv编码简介



    在YUV420中,一个像素点对应一个Y,一个2X2的小方块对应一个U和V。对于所有YUV420图像,它们的Y值排列是完全相同的,因为只有Y的图像就是灰度图像。YUV420sp与YUV420p的数据格式它们的UV排列在原理上是完全不同的。420p它是先把U存放完后,再存放V,也就是说UV它们是连续的。而420sp它是UV、UV这样交替存放的。

  2. yuv流的各种操作。



    代码:

public static byte[] flip(byte[] src, int width, int height) {
        for (int i = 0; i < height; i++) {
            int left = 0;
            int right = width - 1;
            while (left < right) {
                byte b = src[i * width + right];
                src[i * width + right] = src[i * width + left];
                src[i * width + left] = b;
                left++;
                right--;
            }
        }
        int uHeader = width * height;
        int uHeight = height / 2;
        for (int i = 0; i < uHeight; i++) {
            int left = 0;
            int right = width - 2;
            while (left < right) {
                byte b = src[uHeader + i * width + right];
                src[uHeader + i * width + right] = src[uHeader + i * width + left];
                src[uHeader + i * width + left] = b;
                b = src[uHeader + i * width + right + 1];
                src[uHeader + i * width + right + 1] = src[uHeader + i * width + left + 1];
                src[uHeader + i * width + left + 1] = b;
                left += 2;
                right -= 2;
            }
        }
        return src;

    }

    public static byte[] rotate270(byte[] src, int width, int height) {
        byte[] dest = new byte[src.length];
        int index = 0;
        for (int i = width - 1; i >= 0; i--) {
            for (int j = 0; j < height; j++) {
                dest[index++] = src[j * width + i];
            }
        }
        int uHeader = index;
        int uHeight = height / 2;
        for (int i = width - 2; i >= 0; i -= 2) {
            for (int j = 0; j < uHeight; j++) {
                dest[index++] = src[uHeader + j * width + i];
                dest[index++] = src[uHeader + j * width + i + 1];
            }
        }
        return dest;
    }


    public static byte[] rotate90(byte[] src, int width, int height) {
        byte[] dest = new byte[src.length];
        int index = 0;
        for (int i = 0; i < width; i++) {
            for (int j = height - 1; j >= 0; j--) {
                dest[index++] = src[j * width + i];
            }
        }
        int uHeader = index;
        int uHeight = height / 2;
        for (int i = 0; i < width; i += 2) {
            for (int j = uHeight - 1; j >= 0; j--) {
                dest[index++] = src[uHeader + j * width + i];
                dest[index++] = src[uHeader + j * width + i + 1];
            }
        }
        return dest;
    }

    public static byte[] rotate180(byte[] src, int width, int height) {
        int top = 0;
        int bottom = height - 1;
        while (top < bottom) {
            for (int i = 0; i < width; i++) {
                byte b = src[bottom * width + width - 1 - i];
                src[bottom * width + width - 1 - i] = src[top * width + i];
                src[top * width + i] = b;
            }
            top++;
            bottom--;
        }
        int uHeader = width * height;
        top = 0;
        bottom = height / 2 - 1;
        while (top < bottom) {
            for (int i = 0; i < width; i += 2) {
                byte b = src[uHeader + bottom * width + width - 2 - i];
                src[uHeader + bottom * width + width - 2 - i] = src[uHeader + top * width + i];
                src[uHeader + top * width + i] = b;

                b = src[uHeader + bottom * width + width - 1 - i];
                src[uHeader + bottom * width + width - 1 - i] = src[uHeader + top * width + i + 1];
                src[uHeader + top * width + i + 1] = b;
            }
            top++;
            bottom--;
        }
        return src;
    }

相关文章

  • YVU格式Y分量存储为灰度

    Android: Image类浅析(结合YUV_420_888) Image Image为Android 5.0以...

  • Android YUV

    yuv编码简介在YUV420中,一个像素点对应一个Y,一个2X2的小方块对应一个U和V。对于所有YUV420图像,...

  • Android使用surfaceView显示解码数据

    在上一篇文章《Android使用ffmpeg解码视频为YUV》中我们已经使用ffmpeg解码视频为yuv数据文件了...

  • JNI——RTMP推流

    视频: android相机的预览画面格式是NV21,直播播放的格式是YUV,所以首先要把相机预览的画面转成YUV然...

  • Android YUV旋转

    1、旋转算法

  • YUV数据格式与YUV_420_888

    最近在准备做Android Camera2相关应用,刚好也碰上了YUV格式相关的问题,所以还是写一篇博客理解YUV...

  • YUV格式初探

    目录 一、 YUV起源 二、 YUV的类型 三、 YUV的采样和存储格式 四、 YUV的相关Enum 五、 YUV...

  • YUV数据格式

    目录 YUV的原理 YUV的取值范围 YUV的存储格式 YUV的采样格式 存储方式 10bit YUV数据的存储 ...

  • 【嵌入式】关于YUV

    文章参考自YUV图解 (YUV444, YUV422, YUV420, YV12, NV12, NV21) YUV...

  • 音视频相关问题

    视频相关的问与答: 一、YUV的内存存储格式YUV格式有很多种,比如YUV420,YUV422,YUV444等。比...

网友评论

      本文标题:Android YUV

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