YUV to RGB conversion by fragment shader

后端 未结 5 1709
悲哀的现实
悲哀的现实 2020-11-30 01:10

I\'ve a problem with convertion of camera preview in Android from YUV format to RGB. The purpose of conversion is to apply some effects. I try to convert by fragment shader

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 01:20

    For the fastest and most optimized way, just use the common GL Extention

    //Fragment Shader
    #extension GL_OES_EGL_image_external : require
    uniform samplerExternalOES u_Texture;
    

    Than in Java

    surfaceTexture = new SurfaceTexture(textureIDs[0]);
    try {
       someCamera.setPreviewTexture(surfaceTexture);
    } catch (IOException t) {
       Log.e(TAG, "Cannot set preview texture target!");
    }
    
    someCamera.startPreview();
    
    private static final int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
    

    In Java GL Thread

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureIDs[0]);
    GLES20.glUniform1i(uTextureHandle, 0);
    

    The color conversion is already done for you. You can do what ever you want right in the Fragment shader.

    Hope that saves you some time in your research.

提交回复
热议问题