美文网首页
Android基于JAVA的YUV图片叠加算法

Android基于JAVA的YUV图片叠加算法

作者: 懒瓜籽 | 来源:发表于2018-03-09 18:03 被阅读0次
    //YUV420P图片叠加算法
    public static void mergeYUV420P(byte[] yuv420P_A, byte[] yuv420P_B, int offset_x, int offset_y,
                                    int a_width, int a_height, int b_width, int b_height) {
    
        //y
        for (int i = 0; i < b_height; i++) {
            for (int j = 0; j < b_width; j++) {
                yuv420P_A[i * a_width + offset_y * a_width + j + offset_x] = yuv420P_B[i * b_width + j];
            }
        }
    
        //uv
        for (int i = 0; i < b_height / 4; i++) {
            for (int j = 0; j < b_width; j++) {
                if (j < b_width / 2) {
                    yuv420P_A[i * a_width + offset_y / 4 * a_width + j + offset_x / 2 + a_width * a_height] = yuv420P_B[i * b_width + j + b_width * b_height];
    
                    yuv420P_A[i * a_width + offset_y / 4 * a_width + j + offset_x / 2 + a_width * a_height + a_width * a_height / 4] =
                            yuv420P_B[i * b_width + j + b_width * b_height + b_width * b_height / 4];
                } else {
                    yuv420P_A[i * a_width + offset_y / 4 * a_width + j + (a_width / 2 - b_width / 2) + offset_x / 2 + a_width * a_height] =
                            yuv420P_B[i * b_width + j + b_width * b_height];
    
                    yuv420P_A[i * a_width + offset_y / 4 * a_width + j + (a_width / 2 - b_width / 2) + offset_x / 2 + a_width * a_height + a_width * a_height / 4] =
                            yuv420P_B[i * b_width + j + b_width * b_height + b_width * b_height / 4];
                }
            }
        }
    }
    
    //YUV420SP_NV12图片叠加算法
    public static void mergeNV12(byte[] nv12_A, byte[] nv12_B, int offset_x, int offset_y, int a_width, int a_height, int b_width, int b_height) {
    
        //y
        for (int i = 0; i < b_height; i++) {
            for (int j = 0; j < b_width; j++) {
                nv12_A[i * a_width + offset_y * a_width + j + offset_x] = nv12_B[i * b_width + j];
            }
        }
    
        //uv
        for (int i = 0; i < b_height / 2; i++) {
            for (int j = 0; j < b_width; j++) {
                nv12_A[i * a_width + offset_y / 2 * a_width + j + offset_x + a_width * a_height] = nv12_B[i * b_width + j + b_width * b_height];
            }
        }
    }

    相关文章

      网友评论

          本文标题:Android基于JAVA的YUV图片叠加算法

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