Android常见的几种YUV格式包括NV21、NV12、YV12和YUV420P等

NV21转NV12

public static void NV21ToNV12(byte[] nv21, byte[] nv12, int width, int height) {
    System.arraycopy(nv21, 0, nv12, 0, width * height);
    for (int i = width * height; i < nv21.length; i += 2) {
        nv12[i] = nv21[i + 1];
        nv12[i + 1] = nv21[i];
    }
}

NV12转NV21

public static void NV12ToNV21(byte[] nv12, byte[] nv21, int width, int height) {
    System.arraycopy(nv12, 0, nv21, 0, width * height);
    for (int i = width * height; i < nv12.length; i += 2) {
        nv21[i] = nv12[i + 1];
        nv21[i + 1] = nv12[i];
    }
}

YV12转I420

public static void YV12ToI420(byte[] yv12, byte[] i420, int width, int height) {
    System.arraycopy(yv12, 0, i420, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        i420[offset + i] = yv12[offset + i + width * height / 4];
        i420[offset + i + width * height / 4] = yv12[offset + i];
    }
}

I420转YV12

public static void I420ToYV12(byte[] i420, byte[] yv12, int width, int height) {
    System.arraycopy(i420, 0, yv12, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        yv12[offset + i] = i420[offset + i + width * height / 4];
        yv12[offset + i + width * height / 4] = i420[offset + i];
    }
}

NV21/NV12/YV12转I420

public static void NV21ToI420(byte[] nv21, byte[] i420, int width, int height) {
    System.arraycopy(nv21, 0, i420, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        i420[offset + i] = nv21[offset + 2 * i + 1];
        i420[offset + i + width * height / 4] = nv21[offset + 2 * i];
    }
}

public static void NV12ToI420(byte[] nv12, byte[] i420, int width, int height) {
    System.arraycopy(nv12, 0, i420, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        i420[offset + i] = nv12[offset + 2 * i + 1];
        i420[offset + i + width * height / 4] = nv12[offset + 2 * i];
    }
}

public static void YV12ToI420(byte[] yv12, byte[] i420, int width, int height) {
    System.arraycopy(yv12, 0, i420, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        i420[offset + i] = yv12[offset + i];
        i420[offset + i + width * height / 4] = yv12[offset + i + width * height / 4];
    }
}

public static void I420ToNV21(byte[] i420, byte[] nv21, int width, int height) {
    System.arraycopy(i420, 0, nv21, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height/4; i++) {
        nv21[offset + 2 * i] = i420[offset + i + width * height / 4];
        nv21[offset + 2 * i + 1] = i420[offset + i];
    }
}

public static void I420ToNV12(byte[] i420, byte[] nv12, int width, int height) {
    System.arraycopy(i420, 0, nv12, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        nv12[offset + 2 * i] = i420[offset + i];
        nv12[offset + 2 * i + 1] = i420[offset + i + width * height / 4];
    }
}

public static void I420ToYV12(byte[] i420, byte[] yv12, int width, int height) {
    System.arraycopy(i420, 0, yv12, 0, width * height);
    int offset = width * height;
    for (int i = 0; i < width * height / 4; i++) {
        yv12[offset + i] = i420[offset + i + width * height / 4];
        yv12[offset + i + width * height / 4] = i420[offset + i];
    }
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值