码迷,mamicode.com
首页 > 其他好文 > 详细

YUV420sp与YUV420p互转

时间:2020-04-22 10:21:15      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:env   sig   yuv42   tmp   byte   width   jin   exp   code   

JNIEXPORT jbyteArray JNICALL
Java_com_uestc_smileteeth_view_recordvideo_RecordVideoLib_YUV420spToYUV420p(JNIEnv *env,
                                                                            jclass type,
                                                                            jbyteArray yuv420sp_,
                                                                            jint width,
                                                                            jint height) {
    jbyte *yuv420sp = (*env)->GetByteArrayElements(env, yuv420sp_, NULL);

    jbyteArray yuv420pRet = (*env)->NewByteArray(env, (*env)->GetArrayLength(env, yuv420sp_));
    jbyte *yuv420p = (*env)->GetByteArrayElements(env, yuv420pRet, NULL);
    int i, j;
    int y_size = width * height;

    unsigned char *y = yuv420sp;
    unsigned char *vu = yuv420sp + y_size;

    unsigned char *y_tmp = yuv420p;
    unsigned char *u_tmp = yuv420p + y_size;
    unsigned char *v_tmp = yuv420p + y_size * 5 / 4;

    // y
    memcpy(y_tmp, y, y_size);

    // v,u
    for (j = 0, i = 0; j < y_size / 2; j += 2, i++) {
        v_tmp[i] = vu[j];
        u_tmp[i] = vu[j + 1];
    }

    (*env)->ReleaseByteArrayElements(env, yuv420sp_, yuv420sp, 0);
    (*env)->ReleaseByteArrayElements(env, yuv420pRet, yuv420p, 0);
    return yuv420pRet;
}

yuv420p转yuv420sp

JNIEXPORT jbyteArray JNICALL
Java_com_uestc_smileteeth_view_recordvideo_RecordVideoLib_YUV420pToYUV420sp(JNIEnv *env,
                                                                            jclass type,
                                                                            jbyteArray yuv420p_,
                                                                            jint width,
                                                                            jint height) {
    jbyte *yuv420p = (*env)->GetByteArrayElements(env, yuv420p_, NULL);

    jbyteArray yuv420spRet = (*env)->NewByteArray(env, (*env)->GetArrayLength(env, yuv420p_));
    jbyte *yuv420sp = (*env)->GetByteArrayElements(env, yuv420spRet, NULL);
    int i, j;
    int y_size = width * height;

    unsigned char *y = yuv420sp;
    unsigned char *vu = yuv420sp + y_size;

    unsigned char *y_tmp = yuv420p;
    unsigned char *u_tmp = yuv420p + y_size;
    unsigned char *v_tmp = yuv420p + y_size * 5 / 4;

    // y
    memcpy(y, y_tmp, y_size);

    // v,u
    for (j = 0, i = 0; j < y_size / 2; j += 2, i++) {
        vu[j] = v_tmp[i];
        vu[j + 1] = u_tmp[i];
    }

    (*env)->ReleaseByteArrayElements(env, yuv420p_, yuv420p, 0);
    (*env)->ReleaseByteArrayElements(env, yuv420spRet, yuv420sp, 0);
    return yuv420spRet;
}

原文链接:https://blog.csdn.net/Emily2015/article/details/79271199

YUV420sp与YUV420p互转

标签:env   sig   yuv42   tmp   byte   width   jin   exp   code   

原文地址:https://www.cnblogs.com/yanwei-wang/p/12749641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!