Android YUV渲染openGL,Android OpenGL ES process yuv preview as RGBA

I want to use OpenGL to process the data from camera which format is NV21 on Android platform.

My code was below:

vertex shader:

attribute vec4 position;

attribute vec2 inputTextureCoordinate;

varying vec2 v_texCoord;

void main()

{

gl_Position = position;

v_texCoord = inputTextureCoordinate;

}

fragment shader:

precision mediump float;

varying vec2 v_texCoord;

uniform sampler2D yTexture;

uniform sampler2D uvTexture;

const mat3 yuv2rgb = mat3(

1, 0, 1.2802,

1, -0.214821, -0.380589,

1, 2.127982, 0

);

void main() {

vec3 yuv = vec3(

1.1643 * (texture2D(yTexture, v_texCoord).r - 0.0627),

texture2D(uvTexture, v_texCoord).a - 0.5,

texture2D(uvTexture, v_texCoord).r - 0.5

);

vec3 rgb = yuv * yuv2rgb;

gl_FragColor = vec4(rgb, 1.0);

}

I send yTexture:

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE, w, h, 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(data));

where data was the nv21 format byte array of camera preview

And I send uvTexture:

byte[] luminanceAlpha = new byte[w * h / 2];

System.arraycopy(data, w * h, luminanceAlpha, 0, w * h / 2);

GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE_ALPHA, w / 2, h / 2, 0, GLES20.GL_LUMINANCE_ALPHA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(luminanceAlpha));

That's all the code which I thought was important. But when I run the program, I found the result in GLSurfaceView looks more bluer. Is there any wrong with my code. I was very trouble.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值