본문 바로가기
영상처리

YV12toNV21, YV12toNV12, NV12toYV12, NV21toYV12, NV12toNV21, NV21toNV12

by 붕어사랑 티스토리 2022. 6. 8.
반응형

영상처리 하는님들 코드좀 공유 하세요.

 

구글링해서 하나도 안나오는거 졸라 얄밉네

 

 

출저 및 참고 : https://stackoverflow.com/questions/42000543/convert-yv12-to-nv21-yuv-ycrcb-420

 

public static byte[] YV12toNV21(final byte[] input, final byte[] output, final int width, final int height) {

    final int size = width * height;
    final int quarter = size / 4;
    final int vPosition = size; // This is where V starts
    final int uPosition = size + quarter; // This is where U starts

    System.arraycopy(input, 0, output, 0, size); // Y is same

    for (int i = 0; i < quarter; i++) {
        output[size + i*2 ] = input[vPosition + i]; // For NV21, V first
        output[size + i*2 + 1] = input[uPosition + i]; // For Nv21, U second
    }
    return output;
}


public static byte[] YV12toNV12(final byte[] input, final byte[] output, final int width, final int height) {

    final int size = width * height;
    final int quarter = size / 4;
    final int vPosition = size; // This is where V starts
    final int uPosition = size + quarter; // This is where U starts

    System.arraycopy(input, 0, output, 0, size); // Y is same

    for (int i = 0; i < quarter; i++) {
        output[size + i*2 + 1] = input[vPosition + i]; // For NV21, V first
        output[size + i*2 ] = input[uPosition + i]; // For Nv21, U second
    }
    return output;
}

 

public static byte[] NV21toYV12(final byte[] input, final byte[] output, final int width, final int height) {
    final int size = width * height;
    final int quarter = size / 4;
    final int vPosition = size; // This is where V starts
    final int uPosition = size + quarter; // This is where U starts
    System.arraycopy(input, 0, output, 0, size); // Y is same
    for (int i = 0; i < quarter; i++) {
        output[vPosition + i] = input[size + i*2 ];
        output[uPosition + i] = input[size + i*2 + 1];
    }
    return output;
}

public static byte[] NV12toYV12(final byte[] input, final byte[] output, final int width, final int height) {
    final int size = width * height;
    final int quarter = size / 4;
    final int vPosition = size; // This is where V starts
    final int uPosition = size + quarter; // This is where U starts
    System.arraycopy(input, 0, output, 0, size); // Y is same
    for (int i = 0; i < quarter; i++) {
        output[vPosition + i] = input[size + i*2 + 1];
        output[uPosition + i] = input[size + i*2 ];
    }
    return output;
}

 

 

 

 

NV21 to NV12 와 NV12 to NV21은 동일한 함수내용을 같는다.

public static byte[] NV21toNV12(final byte[] input, final byte[] output, final int width, final int height) {

    final int size = width * height;
    final int quarter = size / 4;
    System.arraycopy(input, 0, output, 0, size); // Y is same
    for (int i = 0; i < quarter; i++) {
        output[size + i*2 ] = input[size + i*2 +1];
        output[size + i*2 + 1] = input[size + i*2];
    }
    return output;
}


public static byte[] NV12toNV21(final byte[] input, final byte[] output, final int width, final int height) {

    final int size = width * height;
    final int quarter = size / 4;
    System.arraycopy(input, 0, output, 0, size); // Y is same
    for (int i = 0; i < quarter; i++) {
        output[size + i*2 ] = input[size + i*2 +1];
        output[size + i*2 + 1] = input[size + i*2];
    }
    return output;
}

 

 

 

반응형

'영상처리' 카테고리의 다른 글

HRV 신호 SDNN RMSSD의 차이  (0) 2024.05.22
DSP 옛날기억 끄적끄적  (0) 2024.05.17
DC 성분이란 (DC Component)  (0) 2024.05.14
RGBA to NV21  (0) 2023.06.02
yuv crop, flip, rotate 예제 코드  (0) 2022.06.07

댓글