OLD | NEW |
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 Loading... |
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 | |
117 @SmallTest | 56 @SmallTest |
118 public void testYuvRendering() throws Exception { | 57 public void testYuvRendering() throws Exception { |
119 // Create EGL base with a pixel buffer as display output. | 58 // Create EGL base with a pixel buffer as display output. |
120 EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType.PIXEL
_BUFFER); | 59 EglBase eglBase = eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.Config
Type.PIXEL_BUFFER); |
121 eglBase.createPbufferSurface(WIDTH, HEIGHT); | 60 eglBase.createPbufferSurface(WIDTH, HEIGHT); |
122 eglBase.makeCurrent(); | 61 eglBase.makeCurrent(); |
123 | 62 |
124 // Create YUV byte buffer planes with random content. | 63 // Create YUV byte buffer planes with random content. |
125 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | 64 final ByteBuffer[] yuvPlanes = new ByteBuffer[3]; |
126 final Random random = new Random(SEED); | 65 final Random random = new Random(SEED); |
127 for (int i = 0; i < 3; ++i) { | 66 for (int i = 0; i < 3; ++i) { |
128 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); | 67 yuvPlanes[i] = ByteBuffer.allocateDirect(WIDTH * HEIGHT); |
129 random.nextBytes(yuvPlanes[i].array()); | 68 random.nextBytes(yuvPlanes[i].array()); |
130 } | 69 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF); | 118 assertTrue(Math.abs(actualBlue - expectedBlue) < MAX_DIFF); |
180 assertEquals(actualAlpha, 255); | 119 assertEquals(actualAlpha, 255); |
181 } | 120 } |
182 } | 121 } |
183 | 122 |
184 drawer.release(); | 123 drawer.release(); |
185 GLES20.glDeleteTextures(3, yuvTextures, 0); | 124 GLES20.glDeleteTextures(3, yuvTextures, 0); |
186 eglBase.release(); | 125 eglBase.release(); |
187 } | 126 } |
188 } | 127 } |
OLD | NEW |