Commit 11bdbd06 authored by zhaozl's avatar zhaozl

feature: 添加使用ImageReader读取RGBA to NV21图片并保存

parent b0bdf319
......@@ -196,10 +196,14 @@ public class ImageRenderer implements GLSurfaceView.Renderer {
int pixelStride = planes[0].getPixelStride();
int rowStride = planes[0].getRowStride();
int rowPadding = rowStride - pixelStride * mWidth;
buffer.position(RGBA_SIZE * 5 / 8);
Log.v(TAG, "acquire image size: " + buffer.capacity());
// buffer.position(Y_SIZE / 2);
// buffer.get(mImageBytes, 0, Y_SIZE);
// buffer.position(0);
// buffer.get(mImageBytes, Y_SIZE, Y_SIZE / 2);
buffer.position(NV21_OFFSET);
buffer.get(mImageBytes);
// 读取Y数据
// int yOffset = (int)(mHeight * 0.625f);
// int yHeight = (int)(mHeight * 0.25f);
......@@ -315,7 +319,8 @@ public class ImageRenderer implements GLSurfaceView.Renderer {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
checkGlError("glBindFramebuffer 0");
renderTexture(mNV21ToRGBAProgram, mFrameTextureID, false); // 使用NV21ToRGBA的shader
// renderTexture(mNV21ToRGBAProgram, mFrameTextureID, false); // 使用NV21ToRGBA的shader
renderTexture(mProgram, mTextureID, true);
}
private void renderTexture(int program, int textureId, boolean toNv21) {
......@@ -514,22 +519,22 @@ public class ImageRenderer implements GLSurfaceView.Renderer {
private static final int VERTICES_DATA_POS_OFFSET = 0;
private static final int VERTICES_DATA_UV_OFFSET = 3;
private final float[] mVerticesData = {
// X, Y, Z, U, V
-1.0f, -1.0f, 0, 0.f, 0.f, // 左下
1.0f, -1.0f, 0, 1.f, 0.f, // 右下
-1.0f, 1.0f, 0, 0.f, 1.f, // 左上
1.0f, 1.0f, 0, 1.f, 1.f // 右上
};
// private final float[] mVerticesData = {
// // X, Y, Z, U, V
// -1.0f, -1.0f, 0 /* 左下 */, 0.f, 1.f, /* 左上 */
// 1.0f, -1.0f, 0 /* 右下 */, 1.f, 1.f, /* 右上 */
// -1.0f, 1.0f, 0 /* 左上 */, 0.f, 0.f, /* 左下 */
// 1.0f, 1.0f, 0 /* 右上 */, 1.f, 0.f, /* 右下 */
// -1.0f, -1.0f, 0, 0.f, 0.f, // 左下
// 1.0f, -1.0f, 0, 1.f, 0.f, // 右下
// -1.0f, 1.0f, 0, 0.f, 1.f, // 左上
// 1.0f, 1.0f, 0, 1.f, 1.f // 右上
// };
private final float[] mVerticesData = {
// X, Y, Z, U, V
-1.0f, -1.0f, 0 /* 左下 */, 0.f, 1.f, /* 左上 */
1.0f, -1.0f, 0 /* 右下 */, 1.f, 1.f, /* 右上 */
-1.0f, 1.0f, 0 /* 左上 */, 0.f, 0.f, /* 左下 */
1.0f, 1.0f, 0 /* 右上 */, 1.f, 0.f, /* 右下 */
};
private FloatBuffer mVertices;
private final String mVertexShader =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment