diff options
author | Sven Gothel <[email protected]> | 2013-04-01 05:16:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-04-01 05:16:35 +0200 |
commit | a54bd3e963a7be320dee0c9692d237607fcd0f96 (patch) | |
tree | e365b6baeda020429355f9a7a98a7c3e65da713b /src/test/com/jogamp | |
parent | 00c65b4a34445d140ca9e6ee531dfa4278b8e770 (diff) |
Fix Bug 671: Add JPEG Decoder w/o AWT Dependencies
Original JavaScript code from <https://github.com/notmasteryet/jpgjs/blob/master/jpg.js>,
author 'notmasteryet' <async.processingjs at yahoo.com>.
Ported to Java.
Enhancements:
* InputStream instead of memory buffer
* User provided memory handler
* Fixed JPEG Component ID/Index mapping
* Color space conversion (YCCK, CMYK -> RGB)
* More error tolerant
+++
Features:
JOGL AWT
RGB ok ok
YCCK ok Exception
CMYK ok Exception
YUV Store ok n/a
Need Y-Flip no yes
+++
Benchmark: TestJPEGJoglAWTBenchmarkNewtAWT
JOGL.RGB Loops 100, dt 1199 ms, 11.99 ms/l
JOGL.YUV Loops 100, dt 351 ms, 3.51 ms/l
AWT..... Loops 100, dt 2144 ms, 21.44 ms/l
File: jogl/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j1-baseline.jpg
Machine: GNU/Linux PC (AMD 8 core), JavaSE 6 (1.6.0_38)
.++++ UITestCase.setUp: com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGJoglAWTBenchmarkNewtAWT - benchmark
libEGL warning: DRI2: failed to authenticate
0: JPEGImage[261x202, bytesPerPixel 3, reversedChannels false, JPEGPixels[261x202, sourceComp 3, sourceCS YCbCr, storageCS RGB, storageComp 3], java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]]
0: TextureData[261x202, y-flip false, internFormat 0x1907, pixelFormat 0x1907, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 0, buffer java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]
JOGL.RGB Loops 100, dt 1199 ms, 11.99 ms/l
0: JPEGImage[261x202, bytesPerPixel 3, reversedChannels false, JPEGPixels[261x202, sourceComp 3, sourceCS YCbCr, storageCS YCbCr, storageComp 3], java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]]
0: TextureData[261x202, y-flip false, internFormat 0x1907, pixelFormat 0x1907, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 0, buffer java.nio.DirectByteBuffer[pos=0 lim=158166 cap=158166]
JOGL.YUV Loops 100, dt 351 ms, 3.51 ms/l
0: TextureData[261x202, y-flip true, internFormat 0x1907, pixelFormat 0x80e0, pixelType 0x1401, border 0, estSize 158166, alignment 1, rowlen 261, buffer java.nio.HeapByteBuffer[pos=0 lim=158166 cap=158166]
AWT..... Loops 100, dt 2144 ms, 21.44 ms/l
++++ UITestCase.tearDown: com.jogamp.opengl.test.junit.jogl.util.texture.TestJPEGJoglAWTBenchmarkNewtAWT - benchmark
Diffstat (limited to 'src/test/com/jogamp')
13 files changed, 807 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java new file mode 100644 index 000000000..37054afe6 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGImage01NEWT.java @@ -0,0 +1,124 @@ +package com.jogamp.opengl.test.junit.jogl.util.texture; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URLConnection; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.Test; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.spi.JPEGImage; +import javax.media.opengl.GL; + +public class TestJPEGImage01NEWT extends UITestCase { + + static boolean showFPS = false; + static long duration = 100; // ms + + public void testImpl(final boolean withAlpha, final InputStream istream) throws InterruptedException, IOException { + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + final GLProfile glp = GLProfile.getGL2ES2(); + final GLCapabilities caps = new GLCapabilities(glp); + if( withAlpha ) { + caps.setAlphaBits(1); + } + + final JPEGImage image = JPEGImage.read(istream); + Assert.assertNotNull(image); + System.err.println("JPEGImage: "+image); + + final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + final TextureData texData = new TextureData(glp, internalFormat, + image.getWidth(), + image.getHeight(), + 0, + image.getGLFormat(), + image.getGLType(), + false /* mipmap */, + false /* compressed */, + false /* must flip-vert */, + image.getData(), + null); + // final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.JPG); + System.err.println("TextureData: "+texData); + + final GLWindow glad = GLWindow.create(caps); + glad.setTitle("TestJPEGImage01NEWT"); + // Size OpenGL to Video Surface + glad.setSize(texData.getWidth(), texData.getHeight()); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + final GLEventListener gle = new TextureDraw01ES2Listener( texData ) ; + glad.addGLEventListener(gle); + glad.addGLEventListener(new GLEventListener() { + boolean shot = false; + + @Override public void init(GLAutoDrawable drawable) {} + + public void display(GLAutoDrawable drawable) { + // 1 snapshot + if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { + shot = true; + snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null); + } + } + + @Override public void dispose(GLAutoDrawable drawable) { } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + }); + + Animator animator = new Animator(glad); + animator.setUpdateFPSFrames(60, showFPS ? System.err : null); + QuitAdapter quitAdapter = new QuitAdapter(); + glad.addKeyListener(quitAdapter); + glad.addWindowListener(quitAdapter); + glad.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glad.destroy(); + } + + @Test + public void testReadES2_RGB() throws InterruptedException, IOException, MalformedURLException { + final String fname = null == _fname ? "test-ntscN_3-01-160x90-90pct-yuv444-base.jpg" : _fname; + final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); + testImpl(false, urlConn.getInputStream()); + } + + static String _fname = null; + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } else if(args[i].equals("-file")) { + i++; + _fname = args[i]; + } + } + org.junit.runner.JUnitCore.main(TestJPEGImage01NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java new file mode 100644 index 000000000..de8a4e2b5 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTBenchmarkNewtAWT.java @@ -0,0 +1,152 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.util.texture; + + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.imageio.ImageIO; +import javax.media.opengl.GL; +import javax.media.opengl.GLProfile; + +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.awt.AWTTextureData; +import com.jogamp.opengl.util.texture.spi.JPEGImage; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLConnection; +import java.nio.Buffer; + +import org.junit.Test; + +public class TestJPEGJoglAWTBenchmarkNewtAWT extends UITestCase { + static boolean showFPS = false; + static String fname = "j1-baseline.jpg"; + + @Test + public void benchmark() throws IOException { + benchmarkImpl(100, fname); + } + void benchmarkImpl(int loops, String fname) throws IOException { + { + final long t0 = System.currentTimeMillis(); + for(int i = 0; i< loops; i++ ) { + final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); + final InputStream istream = urlConn.getInputStream(); + final JPEGImage image = JPEGImage.read(istream); // parsing & completion done !!! + final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + final TextureData texData = new TextureData(GLProfile.getGL2ES2(), internalFormat, + image.getWidth(), + image.getHeight(), + 0, + image.getGLFormat(), + image.getGLType(), + false /* mipmap */, + false /* compressed */, + false /* must flip-vert */, + image.getData(), + null); + if(0==i || loops-1==i) { + System.err.println(i+": "+image.toString()); + System.err.println(i+": "+texData+", buffer "+texData.getBuffer()); + } + istream.close(); + } + final long t1 = System.currentTimeMillis(); + final long dt = t1 - t0; + final float msPl = (float)dt / (float)loops ; + System.err.println("JOGL.RGB Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l"); + } + { + final long t0 = System.currentTimeMillis(); + for(int i = 0; i< loops; i++ ) { + final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); + final InputStream istream = urlConn.getInputStream(); + final JPEGImage image = JPEGImage.read(istream, TextureData.ColorSpace.YCbCr); // parsing & completion done !!! + final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + final TextureData texData = new TextureData(GLProfile.getGL2ES2(), internalFormat, + image.getWidth(), + image.getHeight(), + 0, + image.getGLFormat(), + image.getGLType(), + false /* mipmap */, + false /* compressed */, + false /* must flip-vert */, + image.getData(), + null); + if(0==i || loops-1==i) { + System.err.println(i+": "+image.toString()); + System.err.println(i+": "+texData+", buffer "+texData.getBuffer()); + } + istream.close(); + } + final long t1 = System.currentTimeMillis(); + final long dt = t1 - t0; + final float msPl = (float)dt / (float)loops ; + System.err.println("JOGL.YUV Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l"); + } + { + final long t0 = System.currentTimeMillis(); + for(int i = 0; i< loops; i++ ) { + final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); + final InputStream istream = urlConn.getInputStream(); + Buffer data = null; + try { + BufferedImage img = ImageIO.read(istream); + AWTTextureData texData = new AWTTextureData(GLProfile.getGL2ES2(), 0, 0, false, img); + data = texData.getBuffer(); // completes data conversion !!! + if(0==i || loops-1==i) { + System.err.println(i+": "+texData+", buffer "+data); + } + } catch (Exception e) { + System.err.println("AWT ImageIO failure w/ file "+fname+": "+e.getMessage()); + } + istream.close(); + } + final long t1 = System.currentTimeMillis(); + final long dt = t1 - t0; + final float msPl = (float)dt / (float)loops ; + System.err.println("AWT..... Loops "+loops+", dt "+dt+" ms, "+msPl+" ms/l"); + } + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-file")) { + i++; + fname = args[i]; + } + } + org.junit.runner.JUnitCore.main(TestJPEGJoglAWTBenchmarkNewtAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java new file mode 100644 index 000000000..c85aa55b8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGJoglAWTCompareNewtAWT.java @@ -0,0 +1,267 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.util.texture; + + +import com.jogamp.common.util.IOUtil; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.imageio.ImageIO; +import javax.media.opengl.GL; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; + +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.texture.awt.AWTTextureData; +import com.jogamp.opengl.util.texture.spi.JPEGImage; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.net.URLConnection; + +import org.junit.Assert; +import org.junit.Test; + +public class TestJPEGJoglAWTCompareNewtAWT extends UITestCase { + static boolean showFPS = false; + static long duration = 100; // ms + + String[] files = { "test-ntscN_3-01-160x90-90pct-yuv444-base.jpg", // 0 + "test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg", // 1 + "test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg", // 2 + "test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg", // 3 + "j1-baseline.jpg", // 4 + "j2-progressive.jpg", // 5 + "j3-baseline_gray.jpg", // 6 + "test-cmyk-01.jpg", // 7 + "test-ycck-01.jpg" }; // 8 + + void testImpl(final String fname) throws InterruptedException, IOException { + final Animator animator = new Animator(); + + final GLWindow w1 = testJOGLJpeg(fname); + final GLWindow w2 = testAWTJpeg(fname, w1.getWidth() + 50); + + animator.add(w1); + animator.add(w2); + animator.setUpdateFPSFrames(60, showFPS ? System.err : null); + QuitAdapter quitAdapter = new QuitAdapter(); + w1.setVisible(true); + w2.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + w1.destroy(); + w2.destroy(); + } + + GLWindow testJOGLJpeg(final String fname) throws InterruptedException, IOException { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), fname); + Assert.assertNotNull(testTextureUrlConn); + InputStream istream = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(istream); + + final JPEGImage image = JPEGImage.read(istream); + Assert.assertNotNull(image); + System.err.println("JPEGImage: "+image); + + GLProfile glp = GLProfile.getGL2ES2(); + final int internalFormat = (image.getBytesPerPixel()==4)?GL.GL_RGBA:GL.GL_RGB; + final TextureData texData = new TextureData(glp, internalFormat, + image.getWidth(), + image.getHeight(), + 0, + image.getGLFormat(), + image.getGLType(), + false /* mipmap */, + false /* compressed */, + false /* must flip-vert */, + image.getData(), + null); + // final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.JPG); + System.err.println("TextureData: "+texData); + + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + final GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(1); + + final GLWindow glad1 = GLWindow.create(caps); + glad1.setTitle("JPEG JOGL"); + // Size OpenGL to Video Surface + glad1.setSize(texData.getWidth(), texData.getHeight()); + glad1.setPosition(0, 0); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + final GLEventListener gle = new TextureDraw01ES2Listener( texData ) ; + glad1.addGLEventListener(gle); + glad1.addGLEventListener(new GLEventListener() { + boolean shot = false; + + @Override public void init(GLAutoDrawable drawable) {} + + public void display(GLAutoDrawable drawable) { + // 1 snapshot + if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { + shot = true; + snapshot(0, "JoglJPEG", drawable.getGL(), screenshot, TextureIO.PNG, null); + } + } + + @Override public void dispose(GLAutoDrawable drawable) { } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + }); + + return glad1; + } + + GLWindow testAWTJpeg(final String fname, int xpos) throws InterruptedException, IOException { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), fname); + Assert.assertNotNull(testTextureUrlConn); + InputStream istream = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(istream); + + GLProfile glp = GLProfile.getGL2ES2(); + TextureData texData = null; + int w = 300, h = 300; + try { + BufferedImage img = ImageIO.read(istream); + texData = new AWTTextureData(glp, 0, 0, false, img); + System.err.println("TextureData: "+texData); + w = texData.getWidth(); + h = texData.getHeight(); + } catch (Exception e) { + System.err.println("AWT ImageIO failure w/ file "+fname+": "+e.getMessage()); + // e.printStackTrace(); // : CMYK, YCCK -> com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source) + } + + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + final GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(1); + + final GLWindow glad1 = GLWindow.create(caps); + glad1.setTitle("JPEG AWT"); + // Size OpenGL to Video Surface + glad1.setSize(w, h); + glad1.setPosition(xpos, 0); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + final GLEventListener gle; + if( texData != null ) { + gle = new TextureDraw01ES2Listener( texData ) ; + glad1.addGLEventListener(gle); + } else { + gle = null; + } + glad1.addGLEventListener(new GLEventListener() { + boolean shot = false; + + @Override public void init(GLAutoDrawable drawable) {} + + public void display(GLAutoDrawable drawable) { + // 1 snapshot + if( null!=gle && null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { + shot = true; + snapshot(0, "AWTJPEG", drawable.getGL(), screenshot, TextureIO.PNG, null); + } + } + + @Override public void dispose(GLAutoDrawable drawable) { } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + }); + + return glad1; + } + + @Test + public void test01YUV444Base__ES2() throws InterruptedException, IOException { + testImpl(files[0]); + } + @Test + public void test01YUV444Prog__ES2() throws InterruptedException, IOException { + testImpl(files[1]); + } + + @Test + public void test01YUV422hBase__ES2() throws InterruptedException, IOException { + testImpl(files[2]); + } + @Test + public void test01YUV422hProg_ES2() throws InterruptedException, IOException { + testImpl(files[3]); + } + + @Test + public void test02YUV420Base__ES2() throws InterruptedException, IOException { + testImpl(files[4]); + } + @Test + public void test02YUV420Prog_ES2() throws InterruptedException, IOException { + testImpl(files[5]); + } + @Test + public void test02YUV420BaseGray_ES2() throws InterruptedException, IOException { + testImpl(files[6]); + } + + @Test + public void test03CMYK_01_ES2() throws InterruptedException, IOException { + testImpl(files[7]); + } + @Test + public void test03YCCK_01_ES2() throws InterruptedException, IOException { + testImpl(files[8]); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } + } + org.junit.runner.JUnitCore.main(TestJPEGJoglAWTCompareNewtAWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGTextureFromFileNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGTextureFromFileNEWT.java new file mode 100644 index 000000000..55e8152ae --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestJPEGTextureFromFileNEWT.java @@ -0,0 +1,264 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.util.texture; + + +import com.jogamp.common.util.IOUtil; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.TextureDraw01Accessor; +import com.jogamp.opengl.test.junit.jogl.demos.es2.TextureDraw01ES2Listener; +import com.jogamp.opengl.test.junit.jogl.demos.gl2.TextureDraw01GL2Listener; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; + +import com.jogamp.opengl.util.texture.TextureData; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.GLReadBufferUtil; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URLConnection; + +import org.junit.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class TestJPEGTextureFromFileNEWT extends UITestCase { + static boolean showFPS = false; + static long duration = 100; // ms + + InputStream testTextureStream01YUV444_Base; + InputStream testTextureStream01YUV444_Prog; + + InputStream testTextureStream01YUV422h_Base; + InputStream testTextureStream01YUV422h_Prog; + + InputStream testTextureStream02YUV420_Base; + InputStream testTextureStream02YUV420_Prog; + InputStream testTextureStream02YUV420_BaseGray; + + InputStream testTextureStream03CMYK_01; + InputStream testTextureStream03YCCK_01; + + @Before + public void initTest() throws IOException { + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-ntscN_3-01-160x90-90pct-yuv444-base.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream01YUV444_Base = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream01YUV444_Base); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream01YUV444_Prog = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream01YUV444_Prog); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream01YUV422h_Base = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream01YUV422h_Base); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream01YUV422h_Prog = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream01YUV422h_Prog); + } + + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "j1-baseline.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream02YUV420_Base = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream02YUV420_Base); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "j2-progressive.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream02YUV420_Prog = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream02YUV420_Prog); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "j3-baseline_gray.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream02YUV420_BaseGray = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream02YUV420_BaseGray); + } + + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-cmyk-01.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream03CMYK_01 = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream03CMYK_01); + } + { + URLConnection testTextureUrlConn = IOUtil.getResource(this.getClass(), "test-ycck-01.jpg"); + Assert.assertNotNull(testTextureUrlConn); + testTextureStream03YCCK_01 = testTextureUrlConn.getInputStream(); + Assert.assertNotNull(testTextureStream03YCCK_01); + } + } + + @After + public void cleanupTest() { + testTextureStream01YUV444_Base = null; + testTextureStream01YUV444_Prog = null; + testTextureStream01YUV422h_Base = null; + testTextureStream01YUV422h_Prog = null; + testTextureStream02YUV420_Base = null; + testTextureStream02YUV420_Prog = null; + testTextureStream02YUV420_BaseGray = null; + } + + public void testImpl(boolean useFFP, final InputStream istream) throws InterruptedException, IOException { + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); + GLProfile glp; + if(useFFP && GLProfile.isAvailable(GLProfile.GL2GL3)) { + glp = GLProfile.getGL2GL3(); + } else if(!useFFP && GLProfile.isAvailable(GLProfile.GL2ES2)) { + glp = GLProfile.getGL2ES2(); + } else { + System.err.println(getSimpleTestName(".")+": GLProfile n/a, useFFP: "+useFFP); + return; + } + final GLCapabilities caps = new GLCapabilities(glp); + caps.setAlphaBits(1); + + final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.JPG); + System.err.println("TextureData: "+texData); + + final GLWindow glad = GLWindow.create(caps); + glad.setTitle("TestPNGTextureGL2FromFileNEWT"); + // Size OpenGL to Video Surface + glad.setSize(texData.getWidth(), texData.getHeight()); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + final GLEventListener gle = useFFP ? new TextureDraw01GL2Listener( texData ) : new TextureDraw01ES2Listener( texData ) ; + glad.addGLEventListener(gle); + glad.addGLEventListener(new GLEventListener() { + boolean shot = false; + + @Override public void init(GLAutoDrawable drawable) {} + + public void display(GLAutoDrawable drawable) { + // 1 snapshot + if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { + shot = true; + snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null); + } + } + + @Override public void dispose(GLAutoDrawable drawable) { } + @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } + }); + + Animator animator = new Animator(glad); + animator.setUpdateFPSFrames(60, showFPS ? System.err : null); + QuitAdapter quitAdapter = new QuitAdapter(); + glad.addKeyListener(quitAdapter); + glad.addWindowListener(quitAdapter); + glad.setVisible(true); + animator.start(); + + while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { + Thread.sleep(100); + } + + animator.stop(); + glad.destroy(); + } + + @Test + public void test01YUV444Base__GL2() throws InterruptedException, IOException { + testImpl(true, testTextureStream01YUV444_Base); + } + @Test + public void test01YUV444Base__ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream01YUV444_Base); + } + @Test + public void test01YUV444Prog__GL2() throws InterruptedException, IOException { + testImpl(true, testTextureStream01YUV444_Prog); + } + @Test + public void test01YUV444Prog__ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream01YUV444_Prog); + } + + @Test + public void test01YUV422hBase__ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream01YUV422h_Base); + } + @Test + public void test01YUV422hProg_ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream01YUV422h_Prog); + } + + @Test + public void test02YUV420Base__ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream02YUV420_Base); + } + @Test + public void test02YUV420Prog_ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream02YUV420_Prog); + } + @Test + public void test02YUV420BaseGray_ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream02YUV420_BaseGray); + } + + @Test + public void test03CMYK_01_ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream03CMYK_01); + } + @Test + public void test03YCCK_01_ES2() throws InterruptedException, IOException { + testImpl(false, testTextureStream03YCCK_01); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + duration = MiscUtils.atol(args[i], duration); + } + } + org.junit.runner.JUnitCore.main(TestJPEGTextureFromFileNEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j1-baseline.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j1-baseline.jpg Binary files differnew file mode 100644 index 000000000..8efe6af1f --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j1-baseline.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j2-progressive.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j2-progressive.jpg Binary files differnew file mode 100644 index 000000000..aa5fbd0d9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j2-progressive.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j3-baseline_gray.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j3-baseline_gray.jpg Binary files differnew file mode 100644 index 000000000..048eb791b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/j3-baseline_gray.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-cmyk-01.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-cmyk-01.jpg Binary files differnew file mode 100644 index 000000000..40a300f2d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-cmyk-01.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg Binary files differnew file mode 100644 index 000000000..8e4fe9a09 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-base.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg Binary files differnew file mode 100644 index 000000000..35556f90b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-60pct-yuv422h-prog.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg Binary files differnew file mode 100644 index 000000000..051a166cd --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-base.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg Binary files differnew file mode 100644 index 000000000..40b0fc8c2 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ntscN_3-01-160x90-90pct-yuv444-prog.jpg diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ycck-01.jpg b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ycck-01.jpg Binary files differnew file mode 100644 index 000000000..84c1984f9 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/test-ycck-01.jpg |