Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/GlRectDrawerTest.java

Issue 1367923002: Android GlRectDrawer: Add test for RGB rendering (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove unused variable Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 final float MAX_DIFF = 1.0f; 46 final float MAX_DIFF = 1.0f;
47 47
48 private static float normalizedByte(byte b) { 48 private static float normalizedByte(byte b) {
49 return (b & 0xFF) / 255.0f; 49 return (b & 0xFF) / 255.0f;
50 } 50 }
51 51
52 private static float saturatedConvert(float c) { 52 private static float saturatedConvert(float c) {
53 return 255.0f * Math.max(0, Math.min(c, 1)); 53 return 255.0f * Math.max(0, Math.min(c, 1));
54 } 54 }
55 55
56 // Assert RGB ByteBuffers are pixel perfect identical.
57 private static void assertEquals(int width, int height, ByteBuffer actual, Byt eBuffer expected) {
58 actual.rewind();
59 expected.rewind();
60 assertEquals(actual.capacity(), width * height * 3);
61 assertEquals(expected.capacity(), width * height * 3);
62 for (int y = 0; y < HEIGHT; ++y) {
63 for (int x = 0; x < WIDTH; ++x) {
64 final int actualR = actual.get() & 0xFF;
65 final int actualG = actual.get() & 0xFF;
66 final int actualB = actual.get() & 0xFF;
67 final int expectedR = expected.get() & 0xFF;
68 final int expectedG = expected.get() & 0xFF;
69 final int expectedB = expected.get() & 0xFF;
70 if (actualR != expectedR || actualG != expectedG || actualB != expectedB ) {
71 fail("ByteBuffers of size " + width + "x" + height + " not equal at po sition "
72 + "(" + x + ", " + y + "). Expected color (R,G,B): "
73 + "(" + expectedR + ", " + expectedG + ", " + expectedB + ")"
74 + " but was: " + "(" + actualR + ", " + actualG + ", " + actualB + ").");
75 }
76 }
77 }
78 }
79
80 @SmallTest
81 public void testRgbRendering() throws Exception {
82 // Create EGL base with a pixel buffer as display output.
83 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType .PIXEL_BUFFER);
84 eglBase.createPbufferSurface(WIDTH, HEIGHT);
85 eglBase.makeCurrent();
86
87 // Create RGB byte buffer plane with random content.
88 final ByteBuffer rgbPlane = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);
89 final Random random = new Random(SEED);
90 random.nextBytes(rgbPlane.array());
91
92 // Upload the RGB byte buffer data as a texture.
93 final int rgbTexture = GlUtil.generateTexture(GLES20.GL_TEXTURE_2D);
94 GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
95 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, rgbTexture);
96 GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGB, WIDTH,
97 HEIGHT, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, rgbPlane);
98
99 // Draw the RGB frame onto the pixel buffer.
100 final GlRectDrawer drawer = new GlRectDrawer();
101 final float[] identityMatrix = new float[16];
102 Matrix.setIdentityM(identityMatrix, 0);
103 drawer.drawRgb(rgbTexture, identityMatrix);
104
105 // Download the pixels in the pixel buffer as RGB.
106 final ByteBuffer data = ByteBuffer.allocateDirect(WIDTH * HEIGHT * 3);
107 GLES20.glReadPixels(0, 0, WIDTH, HEIGHT, GLES20.GL_RGB, GLES20.GL_UNSIGNED_B YTE, data);
108
109 // Assert rendered image is pixel perfect to source RGB.
110 assertEquals(WIDTH, HEIGHT, data, rgbPlane);
111
112 drawer.release();
113 GLES20.glDeleteTextures(1, new int[] {rgbTexture}, 0);
114 eglBase.release();
115 }
116
56 @SmallTest 117 @SmallTest
57 public void testYuvRendering() throws Exception { 118 public void testYuvRendering() throws Exception {
58 // Create EGL base with a pixel buffer as display output. 119 // Create EGL base with a pixel buffer as display output.
59 EglBase eglBase = eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.Config Type.PIXEL_BUFFER); 120 EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL _BUFFER);
60 eglBase.createPbufferSurface(WIDTH, HEIGHT); 121 eglBase.createPbufferSurface(WIDTH, HEIGHT);
61 eglBase.makeCurrent(); 122 eglBase.makeCurrent();
62 123
63 // Create YUV byte buffer planes with random content. 124 // Create YUV byte buffer planes with random content.
64 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; 125 final ByteBuffer[] yuvPlanes = new ByteBuffer[3];
65 final Random random = new Random(SEED); 126 final Random random = new Random(SEED);
66 for (int i = 0; i < 3; ++i) { 127 for (int i = 0; i < 3; ++i) {
67 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); 128 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT);
68 random.nextBytes(yuvPlanes[i].array()); 129 random.nextBytes(yuvPlanes[i].array());
69 } 130 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF); 179 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF);
119 assertEquals(actualAlpha, 255); 180 assertEquals(actualAlpha, 255);
120 } 181 }
121 } 182 }
122 183
123 drawer.release(); 184 drawer.release();
124 GLES20.glDeleteTextures(3, yuvTextures, 0); 185 GLES20.glDeleteTextures(3, yuvTextures, 0);
125 eglBase.release(); 186 eglBase.release();
126 } 187 }
127 } 188 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698