JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
TestJPEGTextureFromFileNEWT.java
Go to the documentation of this file.
1/**
2 * Copyright 2012 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opengl.test.junit.jogl.util.texture;
30
31
32import com.jogamp.common.util.IOUtil;
33import com.jogamp.newt.opengl.GLWindow;
34import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor;
35import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener;
36import com.jogamp.opengl.test.junit.jogl.demos.gl2.TextureDraw01GL2Listener;
37import com.jogamp.opengl.test.junit.util.MiscUtils;
38import com.jogamp.opengl.test.junit.util.QuitAdapter;
39import com.jogamp.opengl.test.junit.util.UITestCase;
40
41import com.jogamp.opengl.GLAutoDrawable;
42import com.jogamp.opengl.GLEventListener;
43import com.jogamp.opengl.GLProfile;
44import com.jogamp.opengl.GLCapabilities;
45
46import com.jogamp.opengl.util.texture.TextureData;
47import com.jogamp.opengl.util.texture.TextureIO;
48import com.jogamp.opengl.util.Animator;
49import com.jogamp.opengl.util.GLReadBufferUtil;
50
51import java.io.IOException;
52import java.io.InputStream;
53import java.net.URLConnection;
54
55import org.junit.Assert;
56import org.junit.After;
57import org.junit.Before;
58import org.junit.Test;
59import org.junit.FixMethodOrder;
60import org.junit.runners.MethodSorters;
61
62@FixMethodOrder(MethodSorters.NAME_ASCENDING)
64 static boolean showFPS = false;
65 static long duration = 100; // ms
66
67 InputStream testTextureStream01YUV444_Base;
68 InputStream testTextureStream01YUV444_Prog;
69
70 InputStream testTextureStream01YUV422h_Base;
71 InputStream testTextureStream01YUV422h_Prog;
72
73 InputStream testTextureStream02YUV420_Base;
74 InputStream testTextureStream02YUV420_Prog;
75 InputStream testTextureStream02YUV420_BaseGray;
76
77 InputStream testTextureStream03CMYK_01;
78 InputStream testTextureStream03YCCK_01;
79
80 InputStream testTextureStream04QTTDefPostFrame;
81
82 @Before
83 public void initTest() throws IOException {
84 {
85 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ntscN_3-01-160x90-90pct-yuv444-base.jpg", this.getClass().getClassLoader(), this.getClass());
86 Assert.assertNotNull(testTextureUrlConn);
87 testTextureStream01YUV444_Base = testTextureUrlConn.getInputStream();
88 Assert.assertNotNull(testTextureStream01YUV444_Base);
89 }
90 {
91 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg", this.getClass().getClassLoader(), this.getClass());
92 Assert.assertNotNull(testTextureUrlConn);
93 testTextureStream01YUV444_Prog = testTextureUrlConn.getInputStream();
94 Assert.assertNotNull(testTextureStream01YUV444_Prog);
95 }
96 {
97 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg", this.getClass().getClassLoader(), this.getClass());
98 Assert.assertNotNull(testTextureUrlConn);
99 testTextureStream01YUV422h_Base = testTextureUrlConn.getInputStream();
100 Assert.assertNotNull(testTextureStream01YUV422h_Base);
101 }
102 {
103 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg", this.getClass().getClassLoader(), this.getClass());
104 Assert.assertNotNull(testTextureUrlConn);
105 testTextureStream01YUV422h_Prog = testTextureUrlConn.getInputStream();
106 Assert.assertNotNull(testTextureStream01YUV422h_Prog);
107 }
108
109 {
110 final URLConnection testTextureUrlConn = IOUtil.getResource("j1-baseline.jpg", this.getClass().getClassLoader(), this.getClass());
111 Assert.assertNotNull(testTextureUrlConn);
112 testTextureStream02YUV420_Base = testTextureUrlConn.getInputStream();
113 Assert.assertNotNull(testTextureStream02YUV420_Base);
114 }
115 {
116 final URLConnection testTextureUrlConn = IOUtil.getResource("j2-progressive.jpg", this.getClass().getClassLoader(), this.getClass());
117 Assert.assertNotNull(testTextureUrlConn);
118 testTextureStream02YUV420_Prog = testTextureUrlConn.getInputStream();
119 Assert.assertNotNull(testTextureStream02YUV420_Prog);
120 }
121 {
122 final URLConnection testTextureUrlConn = IOUtil.getResource("j3-baseline_gray.jpg", this.getClass().getClassLoader(), this.getClass());
123 Assert.assertNotNull(testTextureUrlConn);
124 testTextureStream02YUV420_BaseGray = testTextureUrlConn.getInputStream();
125 Assert.assertNotNull(testTextureStream02YUV420_BaseGray);
126 }
127
128 {
129 final URLConnection testTextureUrlConn = IOUtil.getResource("test-cmyk-01.jpg", this.getClass().getClassLoader(), this.getClass());
130 Assert.assertNotNull(testTextureUrlConn);
131 testTextureStream03CMYK_01 = testTextureUrlConn.getInputStream();
132 Assert.assertNotNull(testTextureStream03CMYK_01);
133 }
134 {
135 final URLConnection testTextureUrlConn = IOUtil.getResource("test-ycck-01.jpg", this.getClass().getClassLoader(), this.getClass());
136 Assert.assertNotNull(testTextureUrlConn);
137 testTextureStream03YCCK_01 = testTextureUrlConn.getInputStream();
138 Assert.assertNotNull(testTextureStream03YCCK_01);
139 }
140 {
141 final URLConnection testTextureUrlConn = IOUtil.getResource("bug745_qttdef_post_frame.jpg", this.getClass().getClassLoader(), this.getClass());
142 Assert.assertNotNull(testTextureUrlConn);
143 testTextureStream04QTTDefPostFrame = testTextureUrlConn.getInputStream();
144 Assert.assertNotNull(testTextureStream04QTTDefPostFrame);
145 }
146
147 }
148
149 @After
150 public void cleanupTest() {
151 testTextureStream01YUV444_Base = null;
152 testTextureStream01YUV444_Prog = null;
153 testTextureStream01YUV422h_Base = null;
154 testTextureStream01YUV422h_Prog = null;
155 testTextureStream02YUV420_Base = null;
156 testTextureStream02YUV420_Prog = null;
157 testTextureStream02YUV420_BaseGray = null;
158 testTextureStream03CMYK_01 = null;
159 testTextureStream03YCCK_01 = null;
160 testTextureStream04QTTDefPostFrame = null;
161 }
162
163 public void testImpl(final boolean useFFP, final InputStream istream) throws InterruptedException, IOException {
164 final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
165 GLProfile glp;
166 if(useFFP && GLProfile.isAvailable(GLProfile.GL2)) {
167 glp = GLProfile.getMaxFixedFunc(true);
168 } else if(!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) {
169 glp = GLProfile.getGL2ES2();
170 } else {
171 System.err.println(getSimpleTestName(".")+": GLProfile n/a, useFFP: "+useFFP);
172 return;
173 }
174 final GLCapabilities caps = new GLCapabilities(glp);
175 caps.setAlphaBits(1);
176
177 final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.JPG);
178 System.err.println("TextureData: "+texData);
179
180 final GLWindow glad = GLWindow.create(caps);
181 glad.setTitle("TestPNGTextureGL2FromFileNEWT");
182 // Size OpenGL to Video Surface
183 glad.setSize(texData.getWidth(), texData.getHeight());
184
185 // load texture from file inside current GL context to match the way
186 // the bug submitter was doing it
187 final GLEventListener gle = useFFP ? new TextureDraw01GL2Listener( texData ) : new TextureDraw01ES2Listener( texData, 0 ) ;
188 glad.addGLEventListener(gle);
190 boolean shot = false;
191
192 @Override public void init(final GLAutoDrawable drawable) {}
193
194 public void display(final GLAutoDrawable drawable) {
195 // 1 snapshot
196 if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) {
197 shot = true;
198 snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
199 }
200 }
201
202 @Override public void dispose(final GLAutoDrawable drawable) { }
203 @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { }
204 });
205
206 final Animator animator = new Animator(glad);
207 animator.setUpdateFPSFrames(60, showFPS ? System.err : null);
208 final QuitAdapter quitAdapter = new QuitAdapter();
209 glad.addKeyListener(quitAdapter);
210 glad.addWindowListener(quitAdapter);
211 glad.setVisible(true);
212 animator.start();
213
214 while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
215 Thread.sleep(100);
216 }
217
218 animator.stop();
219 glad.destroy();
220 }
221
222 @Test
223 public void test01YUV444Base__GL2() throws InterruptedException, IOException {
224 testImpl(true, testTextureStream01YUV444_Base);
225 }
226 @Test
227 public void test01YUV444Base__ES2() throws InterruptedException, IOException {
228 testImpl(false, testTextureStream01YUV444_Base);
229 }
230 @Test
231 public void test01YUV444Prog__GL2() throws InterruptedException, IOException {
232 testImpl(true, testTextureStream01YUV444_Prog);
233 }
234 @Test
235 public void test01YUV444Prog__ES2() throws InterruptedException, IOException {
236 testImpl(false, testTextureStream01YUV444_Prog);
237 }
238
239 @Test
240 public void test01YUV422hBase__ES2() throws InterruptedException, IOException {
241 testImpl(false, testTextureStream01YUV422h_Base);
242 }
243 @Test
244 public void test01YUV422hProg_ES2() throws InterruptedException, IOException {
245 testImpl(false, testTextureStream01YUV422h_Prog);
246 }
247
248 @Test
249 public void test02YUV420Base__ES2() throws InterruptedException, IOException {
250 testImpl(false, testTextureStream02YUV420_Base);
251 }
252 @Test
253 public void test02YUV420Prog_ES2() throws InterruptedException, IOException {
254 testImpl(false, testTextureStream02YUV420_Prog);
255 }
256 @Test
257 public void test02YUV420BaseGray_ES2() throws InterruptedException, IOException {
258 testImpl(false, testTextureStream02YUV420_BaseGray);
259 }
260
261 @Test
262 public void test03CMYK_01_ES2() throws InterruptedException, IOException {
263 testImpl(false, testTextureStream03CMYK_01);
264 }
265 @Test
266 public void test03YCCK_01_ES2() throws InterruptedException, IOException {
267 testImpl(false, testTextureStream03YCCK_01);
268 }
269
270 @Test
271 public void test04QTTDefPostFrame_ES2() throws InterruptedException, IOException {
272 testImpl(false, testTextureStream04QTTDefPostFrame);
273 }
274
275 public static void main(final String args[]) throws IOException {
276 for(int i=0; i<args.length; i++) {
277 if(args[i].equals("-time")) {
278 i++;
279 duration = MiscUtils.atol(args[i], duration);
280 }
281 }
282 org.junit.runner.JUnitCore.main(TestJPEGTextureFromFileNEWT.class.getName());
283 }
284}
void setAlphaBits(final int alphaBits)
Sets the number of bits requested for the color buffer's alpha component.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void setTitle(final String title)
Definition: GLWindow.java:297
final void addKeyListener(final KeyListener l)
Appends the given com.jogamp.newt.event.KeyListener to the end of the list.
Definition: GLWindow.java:902
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
final void addWindowListener(final WindowListener l)
Appends the given com.jogamp.newt.event.WindowListener to the end of the list.
Definition: GLWindow.java:882
final void destroy()
Destroys all resources associated with this GLAutoDrawable, inclusive the GLContext.
Definition: GLWindow.java:605
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
Specifies a set of OpenGL capabilities.
Specifies the the OpenGL profile.
Definition: GLProfile.java:77
static boolean isAvailable(final AbstractGraphicsDevice device, final String profile)
Returns the availability of a profile on a device.
Definition: GLProfile.java:305
static GLProfile getMaxFixedFunc(final AbstractGraphicsDevice device, final boolean favorHardwareRasterizer)
Returns the highest profile, implementing the fixed function pipeline.
Definition: GLProfile.java:808
static final String GL2ES2
The intersection of the desktop GL3, GL2 and embedded ES2 profile.
Definition: GLProfile.java:594
static final String GL2
The desktop OpenGL profile 1.x up to 3.0.
Definition: GLProfile.java:579
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
static long atol(final String str, final long def)
Definition: MiscUtils.java:66
final void setUpdateFPSFrames(final int frames, final PrintStream out)
final synchronized boolean start()
Starts this animator, if not running.
Definition: Animator.java:344
final synchronized boolean stop()
Stops this animator.
Definition: Animator.java:368
Utility to read out the current FB to TextureData, optionally writing the data back to a texture obje...
Represents the data for an OpenGL texture.
int getHeight()
Returns the height in pixels of the texture data.
int getWidth()
Returns the width in pixels of the texture data.
static final String PNG
Constant which can be used as a file suffix to indicate a PNG file, value {@value}.
Definition: TextureIO.java:171
static TextureData newTextureData(final GLProfile glp, final File file, final boolean mipmap, String fileSuffix)
Creates a TextureData from the given file.
Definition: TextureIO.java:233
static final String JPG
Constant which can be used as a file suffix to indicate a JPEG file, value {@value}.
Definition: TextureIO.java:166
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
GL getGL()
Returns the GL pipeline object this GLAutoDrawable uses.
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
Declares events which client code can use to manage OpenGL rendering into a GLAutoDrawable.