Android OpenGL es GPUImage convert YUV to RGB

Android OpenGL es GPUImage convert YUV to RGB

Android OpenGL-ES GPUImage


1,YUV转RGB

andorid 的camera数据是YUV数据,需要转换成rgb,但是普通的转换效率不高,即使使用GPU转换也是

修改fragment shader脚本如下:

    varying highp vec2 textureCoordinate;
    uniform sampler2D inputImageTexture;
    uniform sampler2D uvTexture;
    precision mediump float;
    void main(){
         vec4 y = vec4((texture2D(inputImageTexture, textureCoordinate).r - 16./255.) * 1.164);  
         vec4 u = vec4(texture2D(uvTexture, textureCoordinate).a - 128./255.);  
        vec4 v = vec4(texture2D(uvTexture, textureCoordinate).r - 128./255.);  
        y += v * vec4(1.596, -0.813, 0, 0);
        y += u * vec4(0, -0.392, 2.017, 0); 
        y.a = 1.0;
        gl_FragColor = y;//texture2D(inputImageTexture, textureCoordinate);
               }

这是是关键杜爱民 uvy相关的转换成rab

2,坐标转换

坐标转换 例如平移缩放旋转等
坐标脚本

    VERTEX_SHADER = "uniform mat4 uMVPMatrix;\n"
                + "attribute vec4 position;\n" + "attribute vec4 inputTextureCoordinate;\n" + " \n"
                + "varying vec2 textureCoordinate;\n" + " \n" + "void main()\n" + "{\n"
                + "    gl_Position = uMVPMatrix * position; \n"
                + "    textureCoordinate = inputTextureCoordinate.xy;\n" + "}";

多添加了uMVPMatrix

Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 1, 2);

    Matrix.setLookAtM(mVMatrix, 0,//
            0, 0, cameraId == Camera.CameraInfo.CAMERA_FACING_FRONT ? -1 : 1, //eye
            0f, 0f, 0f,//center
            0f, 1f, 0f//up
    );
    //eye 坐标的eyez 正值时候看到的景物是折叠的

    float y = ((maxHeight - height) / 1f / maxHeight);
    Matrix.translateM(mVMatrix, 0,//
            0, y, 0f//x,y,z
    );

    Matrix.rotateM(mVMatrix, 0, mRotation.asInt(), 0, 0, -1);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值