diff options
Diffstat (limited to 'src/test')
10 files changed, 906 insertions, 154 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index 8cc676291..780338492 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -29,6 +29,7 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.newt; import java.io.IOException; +import java.net.URLConnection; import com.jogamp.common.util.IOUtil; import com.jogamp.newt.Display; @@ -47,6 +48,7 @@ import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.test.junit.util.QuitAdapter; import com.jogamp.opengl.util.Animator; +import com.jogamp.opengl.util.PNGPixelRect; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import javax.media.nativewindow.NativeWindowFactory; @@ -171,25 +173,55 @@ public class TestGearsES2NEWT extends UITestCase { } }); - final PointerIcon pointerIconOne; + final PointerIcon[] pointerIcons = { null, null, null }; { - PointerIcon _pointerIconOne = null; - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); final Display disp = glWindow.getScreen().getDisplay(); disp.createNative(); - try { - _pointerIconOne = disp.createPointerIcon(res, 32, 0); - } catch (Exception e) { - e.printStackTrace(); + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/crosshair-lumina-trans-32x32.png" } ); + try { + _pointerIcon = disp.createPointerIcon(res, 16, 16); + System.err.println("Create PointerIcon #01: "+_pointerIcon); + } catch (Exception e) { + e.printStackTrace(); + } + pointerIcons[0] = _pointerIcon; + } + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); + try { + _pointerIcon = disp.createPointerIcon(res, 32, 0); + System.err.println("Create PointerIcon #02: "+_pointerIcon); + } catch (Exception e) { + e.printStackTrace(); + } + pointerIcons[1] = _pointerIcon; + } + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "crosshair-lumina-trans-64x64.png" } ); + try { + final URLConnection urlConn = res.resolve(0); + final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + System.err.println("Create PointerIcon #03: "+image); + _pointerIcon = disp.createPointerIcon(image, 32, 32); + System.err.println("Create PointerIcon #03: "+_pointerIcon); + } catch (Exception e) { + e.printStackTrace(); + } + pointerIcons[2] = _pointerIcon; } - pointerIconOne = _pointerIconOne; } if( setPointerIcon ) { - glWindow.setPointerIcon(pointerIconOne); + glWindow.setPointerIcon(pointerIcons[0]); System.err.println("Set PointerIcon: "+glWindow.getPointerIcon()); } glWindow.addKeyListener(new KeyAdapter() { + int pointerIconIdx = 0; + @Override public void keyPressed(final KeyEvent e) { if( e.isAutoRepeat() ) { @@ -246,7 +278,14 @@ public class TestGearsES2NEWT extends UITestCase { final Thread t = glWindow.setExclusiveContextThread(null); System.err.println("[set pointer-icon pre]"); final PointerIcon currentPI = glWindow.getPointerIcon(); - glWindow.setPointerIcon( currentPI == pointerIconOne ? null : pointerIconOne); + final PointerIcon newPI; + if( pointerIconIdx >= pointerIcons.length ) { + newPI=null; + pointerIconIdx=0; + } else { + newPI=pointerIcons[pointerIconIdx++]; + } + glWindow.setPointerIcon( newPI ); System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon()); glWindow.setExclusiveContextThread(t); } }.start(); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java new file mode 100644 index 000000000..bb9bc42a8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/PNGTstFiles.java @@ -0,0 +1,54 @@ +/** + * Copyright 2014 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; + +public class PNGTstFiles { + static public final String[] allBasenames = { + "test-ntscN_3-01-160x90", + "test-ntscN_4-01-160x90", + "test-ntscNG4-01-160x90", + "test-ntscI_3-01-160x90", + "test-ntscI_4-01-160x90", + "test-ntscIG3-01-160x90", + "test-ntscIG4-01-160x90", + "test-ntscP_3-01-160x90", + "test-ntscP_4-01-160x90", + "grayscale_texture", + "bug724-transparent-grey_orig", + "bug724-transparent-grey_gimpexp", + "crosshair-lumina-trans-32x32", + "crosshair-lumina-trans-64x64", + }; + static public final String[] greyBasenames = { + "grayscale_texture", + "bug724-transparent-grey_orig", + "bug724-transparent-grey_gimpexp", + "crosshair-lumina-trans-32x32", + "crosshair-lumina-trans-64x64", + }; +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java deleted file mode 100644 index 3ace5ab6a..000000000 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage00NEWT.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2010 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 java.io.File; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URLConnection; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; - -import com.jogamp.common.util.IOUtil; -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.util.texture.spi.PNGImage; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestPNGImage00NEWT extends UITestCase { - @Test - public void testPNGReadWriteAndCompare() throws InterruptedException, IOException, MalformedURLException { - final File out1_f=new File(getSimpleTestName(".")+"-PNGImageTest1.png"); - final File out2_f=new File(getSimpleTestName(".")+"-PNGImageTest2.png"); - final File out2F_f=new File(getSimpleTestName(".")+"-PNGImageTest2Flipped.png"); - final File out2R_f=new File(getSimpleTestName(".")+"-PNGImageTest2Reversed.png"); - final File out2RF_f=new File(getSimpleTestName(".")+"-PNGImageTest2ReversedFlipped.png"); - final String url_s="jogl/util/data/av/test-ntsc01-57x32.png"; - URLConnection urlConn = IOUtil.getResource(url_s, this.getClass().getClassLoader()); - PNGImage image1 = PNGImage.read(urlConn.getInputStream()); - System.err.println("PNGImage - Orig: "+image1); - image1.write(out1_f, true); - { - Assert.assertEquals(image1.getData(), PNGImage.read(out1_f.toURI().toURL().openStream()).getData()); - } - - final PNGImage image2 = PNGImage.createFromData(image1.getWidth(), image1.getHeight(), - image1.getDpi()[0], image1.getDpi()[1], - image1.getBytesPerPixel(), false /* reverseChannels */, image1.isGLOriented(), image1.getData()); - image2.write(out2_f, true); - { - Assert.assertEquals(image1.getData(), PNGImage.read(out2_f.toURI().toURL().openStream()).getData()); - } - - // flipped - final PNGImage image2F = PNGImage.createFromData(image1.getWidth(), image1.getHeight(), - image1.getDpi()[0], image1.getDpi()[1], - image1.getBytesPerPixel(), false /* reverseChannels */, !image1.isGLOriented(), image1.getData()); - image2F.write(out2F_f, true); - - // reversed channels - final PNGImage image2R = PNGImage.createFromData(image1.getWidth(), image1.getHeight(), - image1.getDpi()[0], image1.getDpi()[1], - image1.getBytesPerPixel(), true /* reverseChannels */, image1.isGLOriented(), image1.getData()); - image2R.write(out2R_f, true); - - // reversed channels and flipped - final PNGImage image2RF = PNGImage.createFromData(image1.getWidth(), image1.getHeight(), - image1.getDpi()[0], image1.getDpi()[1], - image1.getBytesPerPixel(), true /* reverseChannels */, !image1.isGLOriented(), image1.getData()); - image2RF.write(out2RF_f, true); - } - - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestPNGImage00NEWT.class.getName()); - } -} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect00NEWT.java new file mode 100644 index 000000000..fc97c56fa --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect00NEWT.java @@ -0,0 +1,224 @@ +/** + * Copyright 2014 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 java.io.BufferedOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.URLConnection; + +import javax.media.nativewindow.util.PixelFormat; +import javax.media.nativewindow.util.PixelFormatUtil; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.PNGPixelRect; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPNGPixelRect00NEWT extends UITestCase { + @Test + public void testPNGRead01_All() throws InterruptedException, IOException, MalformedURLException { + for(int i=0; i<PNGTstFiles.allBasenames.length; i++) { + final String basename = PNGTstFiles.allBasenames[i]; + final String pathname=""; + testPNG01Impl(pathname, basename, null, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + } + + @Test + public void testPNGRead02_RGB888_to_RGBA8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_3-01-160x90"; + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.RGBA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead03_RGB888_to_RGBA8888_stride1000() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_3-01-160x90"; // 640 bytes = 4 * 160 + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.RGBA8888, 1000 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead04_RGB888_to_RGBA8888_stride999() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_3-01-160x90"; // 640 bytes = 4 * 160 + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.RGBA8888, 999 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead11_RGBA8888_to_LUMINA() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.LUMINANCE, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead12_RGBA8888_to_RGB888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.RGB888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead13_RGBA8888_to_BGR888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.BGR888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + @Test + public void testPNGRead14_RGBA8888_to_BGRA8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.BGRA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testPNGRead15_RGBA8888_to_ARGB8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.ARGB8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testPNGRead16_RGBA8888_to_ABGR8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG02Impl(pathname, basename, PixelFormat.ABGR8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + private void testPNG01Impl(final String pathname, final String basename, + final PixelFormat destFmt, final int destMinStrideInBytes, final boolean destIsGLOriented) + throws InterruptedException, IOException, MalformedURLException + { + System.err.println("Test01: "+pathname+basename+".png, destFmt "+destFmt+", destMinStrideInBytes "+destMinStrideInBytes+", destIsGLOriented "+destIsGLOriented); + + final File out1_f=new File(getSimpleTestName(".")+"-01-"+basename+"-orig.png"); + final File out2F_f=new File(getSimpleTestName(".")+"-02-"+basename+"-flipped.png"); + final File out2R_f=new File(getSimpleTestName(".")+"-03-"+basename+"-reversed.png"); + final File out2RF_f=new File(getSimpleTestName(".")+"-04-"+basename+"-reversed_flipped.png"); + URLConnection urlConn = IOUtil.getResource(this.getClass(), pathname+basename+".png"); + + final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), destFmt, false /* directBuffer */, destMinStrideInBytes, destIsGLOriented); + System.err.println("PNGPixelRect - Orig: "+image1); + { + final OutputStream outs = new BufferedOutputStream(IOUtil.getFileOutputStream(out1_f, true /* allowOverwrite */)); + image1.write(outs, true /* close */); + { + final PNGPixelRect image1_R = PNGPixelRect.read(out1_f.toURI().toURL().openStream(), image1.getPixelformat(), false /* directBuffer */, destMinStrideInBytes, destIsGLOriented); + System.err.println("PNGPixelRect - Orig (Read Back): "+image1_R); + Assert.assertEquals(image1.getPixels(), image1_R.getPixels()); + } + } + + // + // Flipped Orientation + // + { + final PNGPixelRect image2F = new PNGPixelRect(image1.getPixelformat(), image1.getSize(), + image1.getStride(), !image1.isGLOriented(), image1.getPixels(), + image1.getDpi()[0], image1.getDpi()[1]); + System.err.println("PNGPixelRect - Flip : "+image2F); + final OutputStream outs = new BufferedOutputStream(IOUtil.getFileOutputStream(out2F_f, true /* allowOverwrite */)); + image2F.write(outs, true /* close */); + { + // flip again .. to compare w/ original + final PNGPixelRect image2F_R = PNGPixelRect.read(out2F_f.toURI().toURL().openStream(), image1.getPixelformat(), false /* directBuffer */, destMinStrideInBytes, !destIsGLOriented); + System.err.println("PNGPixelRect - Flip (Read Back): "+image2F_R); + Assert.assertEquals(image1.getPixels(), image2F_R.getPixels()); + } + } + + // + // Reversed Components + // + final PixelFormat revFmt = PixelFormatUtil.getReversed(image1.getPixelformat()); + { + final PNGPixelRect image2R = new PNGPixelRect(revFmt, image1.getSize(), + image1.getStride(), image1.isGLOriented(), image1.getPixels(), + image1.getDpi()[0], image1.getDpi()[1]); + System.err.println("PNGPixelRect - Reversed : "+image2R); + final OutputStream outs = new BufferedOutputStream(IOUtil.getFileOutputStream(out2R_f, true /* allowOverwrite */)); + image2R.write(outs, true /* close */); + { + // reverse again .. to compare w/ original + final PNGPixelRect image2R_R = PNGPixelRect.read(out2R_f.toURI().toURL().openStream(), revFmt, false /* directBuffer */, destMinStrideInBytes, destIsGLOriented); + System.err.println("PNGPixelRect - Reversed (Read Back): "+image2R_R); + Assert.assertEquals(image1.getPixels(), image2R_R.getPixels()); + } + } + + // reversed channels and flipped + { + final PNGPixelRect image2RF = new PNGPixelRect(revFmt, image1.getSize(), + image1.getStride(), !image1.isGLOriented(), image1.getPixels(), + image1.getDpi()[0], image1.getDpi()[1]); + System.err.println("PNGPixelRect - Reversed+Flipped : "+image2RF); + final OutputStream outs = new BufferedOutputStream(IOUtil.getFileOutputStream(out2RF_f, true /* allowOverwrite */)); + image2RF.write(outs, true /* close */); + { + // reverse+flip again .. to compare w/ original + final PNGPixelRect image2RF_R = PNGPixelRect.read(out2RF_f.toURI().toURL().openStream(), revFmt, false /* directBuffer */, destMinStrideInBytes, !destIsGLOriented); + System.err.println("PNGPixelRect - Reversed+FLipped (Read Back): "+image2RF_R); + Assert.assertEquals(image1.getPixels(), image2RF_R.getPixels()); + } + } + } + + private void testPNG02Impl(final String pathname, final String basename, + final PixelFormat destFmt, final int destMinStrideInBytes, final boolean destIsGLOriented) + throws InterruptedException, IOException, MalformedURLException + { + System.err.println("Test02: "+pathname+basename+".png, destFmt "+destFmt+", destMinStrideInBytes "+destMinStrideInBytes+", destIsGLOriented "+destIsGLOriented); + + final File out1_f=new File(getSimpleTestName(".")+"-"+basename+"-orig.png"); + URLConnection urlConn = IOUtil.getResource(this.getClass(), pathname+basename+".png"); + + final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), destFmt, false /* directBuffer */, destMinStrideInBytes, destIsGLOriented); + System.err.println("PNGPixelRect - Orig: "+image1); + { + final OutputStream outs = new BufferedOutputStream(IOUtil.getFileOutputStream(out1_f, true /* allowOverwrite */)); + image1.write(outs, true /* close */); + { + final PNGPixelRect image1_R = PNGPixelRect.read(out1_f.toURI().toURL().openStream(), image1.getPixelformat(), false /* directBuffer */, destMinStrideInBytes, destIsGLOriented); + System.err.println("PNGPixelRect - Orig (Read Back): "+image1_R); + Assert.assertEquals(image1.getPixels(), image1_R.getPixels()); + } + } + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestPNGPixelRect00NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java index 29e041908..0e92db48e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGImage01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -32,6 +32,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URLConnection; +import javax.media.nativewindow.util.PixelFormat; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; @@ -52,10 +53,10 @@ 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.PNGPixelRect; import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; -import com.jogamp.opengl.util.texture.spi.PNGImage; /** * Test reading and displaying a PNG image. @@ -64,71 +65,71 @@ import com.jogamp.opengl.util.texture.spi.PNGImage; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestPNGImage01NEWT extends UITestCase { - +public class TestPNGPixelRect01NEWT extends UITestCase { static boolean showFPS = false; static long duration = 200; // ms - - public void testImpl(final InputStream istream) throws InterruptedException, IOException { - final PNGImage image = PNGImage.read(istream); + + public void testImpl(final int num, final String basename, final InputStream istream, final PixelFormat destFmt) throws InterruptedException, IOException { + final GLProfile glp = GLProfile.getGL2ES2(); + final PNGPixelRect image = PNGPixelRect.read(istream, destFmt, true /* directBuffer */, 0 /* destMinStrideInBytes */, true /* destIsGLOriented */); Assert.assertNotNull(image); - final boolean hasAlpha = 4 == image.getBytesPerPixel(); - System.err.println("PNGImage: "+image); - + final GLPixelAttributes glpa = GLPixelAttributes.convert(image.getPixelformat(), glp); + final boolean hasAlpha = 4 == glpa.bytesPerPixel; + System.err.println("PNGPixelRect: "+basename+", "+image+", glpa "+glpa); + final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false); - final GLProfile glp = GLProfile.getGL2ES2(); final GLCapabilities caps = new GLCapabilities(glp); if( hasAlpha ) { caps.setAlphaBits(1); } - + final int internalFormat; if(glp.isGL2ES3()) { internalFormat = hasAlpha ? GL.GL_RGBA8 : GL.GL_RGB8; } else { internalFormat = hasAlpha ? GL.GL_RGBA : GL.GL_RGB; - } + } final TextureData texData = new TextureData(glp, internalFormat, - image.getWidth(), - image.getHeight(), + image.getSize().getWidth(), + image.getSize().getHeight(), 0, - new GLPixelAttributes(image.getGLFormat(), image.getGLType()), + glpa, false /* mipmap */, false /* compressed */, false /* must flip-vert */, - image.getData(), + image.getPixels(), null); - + // final TextureData texData = TextureIO.newTextureData(glp, istream, false /* mipmap */, TextureIO.PNG); - System.err.println("TextureData: "+texData); - + System.err.println("TextureData: "+texData); + final GLWindow glad = GLWindow.create(caps); - glad.setTitle("TestPNGImage01NEWT"); + glad.setTitle(this.getSimpleTestName(".")); // 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 TextureDraw01ES2Listener gle = new TextureDraw01ES2Listener( texData, 0 ) ; // gle.setClearColor(new float[] { 1.0f, 0.0f, 0.0f, 1.0f } ); glad.addGLEventListener(gle); - glad.addGLEventListener(new GLEventListener() { + glad.addGLEventListener(new GLEventListener() { boolean shot = false; - + @Override public void init(GLAutoDrawable drawable) { System.err.println("Chosen Caps: " + drawable.getChosenGLCapabilities()); System.err.println("GL ctx: " + drawable.getGL().getContext()); } - + @Override public void display(GLAutoDrawable drawable) { // 1 snapshot if(null!=((TextureDraw01Accessor)gle).getTexture() && !shot) { shot = true; - snapshot(0, null, drawable.getGL(), screenshot, TextureIO.PNG, null); + snapshot(num, basename, 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) { } }); @@ -144,28 +145,43 @@ public class TestPNGImage01NEWT extends UITestCase { while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) { Thread.sleep(100); } - + animator.stop(); glad.destroy(); } - + @Test - public void testRead01_RGBn_exp() throws InterruptedException, IOException, MalformedURLException { - final String fname = null == _fname ? "bug724-transparent-grey_gimpexp.png" : _fname; - final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); - testImpl(urlConn.getInputStream()); + public void testRead00_Manual() throws InterruptedException, IOException, MalformedURLException { + if( null == _fname ) { + return; + } + final URLConnection urlConn = IOUtil.getResource(this.getClass(), _fname); + testImpl(0, _fname, urlConn.getInputStream(), null); } @Test - public void testRead02_RGBn_orig() throws InterruptedException, IOException, MalformedURLException { + public void testRead01_All() throws InterruptedException, IOException, MalformedURLException { + if( null != _fname ) { + return; + } + for(int i=0; i<PNGTstFiles.allBasenames.length; i++) { + final String basename = PNGTstFiles.allBasenames[i]; + final URLConnection urlConn = IOUtil.getResource(this.getClass(), basename+".png"); + testImpl(i, basename, urlConn.getInputStream(), null); + } + } + @Test + public void testRead02_Gray2RGBA() throws InterruptedException, IOException, MalformedURLException { if( null != _fname ) { return; } - final String fname = "bug724-transparent-grey_orig.png"; - final URLConnection urlConn = IOUtil.getResource(this.getClass(), fname); - testImpl(urlConn.getInputStream()); + for(int i=0; i<PNGTstFiles.greyBasenames.length; i++) { + final String basename = PNGTstFiles.greyBasenames[i]; + final URLConnection urlConn = IOUtil.getResource(this.getClass(), basename+".png"); + testImpl(i, basename, urlConn.getInputStream(), PixelFormat.RGBA8888); + } } - + static String _fname = null; public static void main(String args[]) { for(int i=0; i<args.length; i++) { @@ -177,6 +193,6 @@ public class TestPNGImage01NEWT extends UITestCase { _fname = args[i]; } } - org.junit.runner.JUnitCore.main(TestPNGImage01NEWT.class.getName()); + org.junit.runner.JUnitCore.main(TestPNGPixelRect01NEWT.class.getName()); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil00NEWT.java new file mode 100644 index 000000000..bfcf9c2d7 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil00NEWT.java @@ -0,0 +1,364 @@ +/** + * Copyright 2014 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 java.io.IOException; +import java.net.MalformedURLException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import javax.media.nativewindow.util.Dimension; +import javax.media.nativewindow.util.PixelFormat; +import javax.media.nativewindow.util.PixelFormatUtil; +import javax.media.nativewindow.util.PixelRectangle; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Testing PixelFormatUtil's Conversion using synthetic test data + * including strides, endian-order and all PixelFormat conversions. + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPixelFormatUtil00NEWT extends UITestCase { + @Test + public void testConversion01_srcS000_BE_TL_destS000_TL() throws InterruptedException, IOException, MalformedURLException { + testPNG00Impl(0 /* srcMinStrideInBytes */, ByteOrder.BIG_ENDIAN, false /* srcIsGLOriented */, + 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testConversion02_srcS000_LE_TL_destS000_TL() throws InterruptedException, IOException, MalformedURLException { + testPNG00Impl(0 /* srcMinStrideInBytes */, ByteOrder.LITTLE_ENDIAN, false /* srcIsGLOriented */, + 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testConversion03_srcS000_BE_TL_destS259_TL() throws InterruptedException, IOException, MalformedURLException { + testPNG00Impl(0 /* srcMinStrideInBytes */, ByteOrder.BIG_ENDIAN, false /* srcIsGLOriented */, + 259 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testConversion04_srcS259_BE_TL_destS259_TL() throws InterruptedException, IOException, MalformedURLException { + testPNG00Impl(259 /* srcMinStrideInBytes */, ByteOrder.BIG_ENDIAN, false /* srcIsGLOriented */, + 259 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testConversion05_srcS301_BE_TL_destS259_TL() throws InterruptedException, IOException, MalformedURLException { + testPNG00Impl(301 /* srcMinStrideInBytes */, ByteOrder.BIG_ENDIAN, false /* srcIsGLOriented */, + 259 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + static final byte red___val = (byte)0x01; + static final byte green_val = (byte)0x02; + static final byte blue__val = (byte)0x03; + static final byte alpha_val = (byte)0x04; + static final byte undef_val = (byte)0xff; + + static final void getComponents(final int srcComps, final PixelFormat fmt, final byte[] components) { + final byte b1, b2, b3, b4; + if( 1 == srcComps ) { + // LUM -> Fmt Conversion + switch(fmt) { + case LUMINANCE: + b1 = red___val; + b2 = undef_val; + b3 = undef_val; + b4 = undef_val; + break; + case RGB888: + b1 = red___val; + b2 = red___val; + b3 = red___val; + b4 = undef_val; + break; + case BGR888: + b1 = red___val; + b2 = red___val; + b3 = red___val; + b4 = undef_val; + break; + case RGBA8888: + b1 = red___val; + b2 = red___val; + b3 = red___val; + b4 = undef_val; + break; + case ABGR8888: + b1 = undef_val; + b2 = red___val; + b3 = red___val; + b4 = red___val; + break; + case BGRA8888: + b1 = red___val; + b2 = red___val; + b3 = red___val; + b4 = undef_val; + break; + case ARGB8888: + b1 = undef_val; + b2 = red___val; + b3 = red___val; + b4 = red___val; + break; + default: + throw new InternalError("Unhandled format "+fmt); + } + } else { + // 1:1 values + switch(fmt) { + case LUMINANCE: + if( srcComps > 1 ) { + b1 = ( red___val + green_val+ blue__val ) / 3; + b2 = undef_val; + b3 = undef_val; + b4 = undef_val; + } else { + b1 = red___val; + b2 = undef_val; + b3 = undef_val; + b4 = undef_val; + } + break; + case RGB888: + b1 = red___val; + b2 = green_val; + b3 = blue__val; + b4 = undef_val; + break; + case BGR888: + b1 = blue__val; + b2 = green_val; + b3 = red___val; + b4 = undef_val; + break; + case RGBA8888: + b1 = red___val; + b2 = green_val; + b3 = blue__val; + b4 = srcComps > 3 ? alpha_val : undef_val; + break; + case ABGR8888: + b1 = srcComps > 3 ? alpha_val : undef_val; + b2 = blue__val; + b3 = green_val; + b4 = red___val; + break; + case BGRA8888: + b1 = blue__val; + b2 = green_val; + b3 = red___val; + b4 = srcComps > 3 ? alpha_val : undef_val; + break; + case ARGB8888: + b1 = srcComps > 3 ? alpha_val : undef_val; + b2 = red___val; + b3 = green_val; + b4 = blue__val; + break; + default: + throw new InternalError("Unhandled format "+fmt); + } + } + components[0] = b1; + components[1] = b2; + components[2] = b3; + components[3] = b4; + } + private void testPNG00Impl(final int srcMinStrideInBytes, final ByteOrder srcByteOrder, final boolean srcIsGLOriented, + final int destMinStrideInBytes, final boolean destIsGLOriented) + throws InterruptedException, IOException, MalformedURLException + { + System.err.println("Test00: srcMinStrideInBytes "+srcMinStrideInBytes+", srcByteOrder "+srcByteOrder+", srcIsGLOriented "+srcIsGLOriented+ + ", destMinStrideInBytes "+destMinStrideInBytes+", destIsGLOriented "+destIsGLOriented); + + final PixelFormat[] formats = PixelFormat.values(); + final int width = 64, height = 64; + + for(int i=0; i<formats.length; i++) { + final PixelFormat srcFmt = formats[i]; + final int srcBpp = srcFmt.bytesPerPixel(); + final int srcStrideBytes = Math.max(srcMinStrideInBytes, width*srcBpp); + final ByteBuffer srcPixels = ByteBuffer.allocate(height*srcStrideBytes).order(srcByteOrder); + final byte[] srcComponents = new byte[4]; + getComponents(srcFmt.componentCount, srcFmt, srcComponents); + for(int y=0; y<height; y++) { + int o = y*srcStrideBytes; + for(int x=0; x<width; x++) { + switch(srcFmt) { + case LUMINANCE: + srcPixels.put(o++, srcComponents[0]); + break; + case RGB888: + case BGR888: + srcPixels.put(o++, srcComponents[0]); + srcPixels.put(o++, srcComponents[1]); + srcPixels.put(o++, srcComponents[2]); + break; + case RGBA8888: + case ABGR8888: + case BGRA8888: + case ARGB8888: + srcPixels.put(o++, srcComponents[0]); + srcPixels.put(o++, srcComponents[1]); + srcPixels.put(o++, srcComponents[2]); + srcPixels.put(o++, srcComponents[3]); + break; + default: + throw new InternalError("Unhandled format "+srcFmt); + } + } + } + final PixelRectangle imageSrc = new PixelRectangle.GenericPixelRect(srcFmt, new Dimension(width, height), srcStrideBytes, srcIsGLOriented, srcPixels); + System.err.println("CONVERT["+i+"][*]: Image0 - Orig: "+imageSrc); + testComponents(imageSrc, 0, 0, srcComponents); + testComponents(imageSrc, width-1, height-1, srcComponents); + + for(int j=0; j<formats.length; j++) { + final PixelFormat destFmt = formats[j]; + System.err.println("CONVERT["+i+"]["+j+"]: "+srcFmt+" -> "+destFmt); + + final int destStrideBytes = Math.max(destMinStrideInBytes, width*destFmt.bytesPerPixel()); + final byte[] destComponents = new byte[4]; + getComponents(srcFmt.componentCount, destFmt, destComponents); + final PixelRectangle imageConv1 = PixelFormatUtil.convert32(imageSrc, destFmt, destStrideBytes, destIsGLOriented, false /* nio */); + System.err.println("CONVERT["+i+"]["+j+"]: Conv1: "+imageConv1); + testComponents(imageConv1, 0, 0, destComponents); + testComponents(imageConv1, width-1, height-1, destComponents); + if( PixelFormat.LUMINANCE != srcFmt && PixelFormat.LUMINANCE == destFmt ) { + // Cannot convert: RGB* -> LUM -> RGB* + System.err.println("CONVERT["+i+"]["+j+"]: Conv2: Dropped due to RGB* -> LUM"); + } else if( srcFmt.componentCount > destFmt.componentCount ) { + // Cannot convert back if: src.componentCount > dest.componentCount + System.err.println("CONVERT["+i+"]["+j+"]: Conv2: Dropped due to src.componentCount > dest.componentCount"); + } else { + final PixelRectangle imageConv2 = PixelFormatUtil.convert32(imageConv1, imageSrc.getPixelformat(), imageSrc.getStride(), imageSrc.isGLOriented(), false /* nio */); + System.err.println("CONVERT["+i+"]["+j+"]: Conv2: "+imageConv2); + testComponents(imageConv2, 0, 0, srcComponents); + testComponents(imageConv2, width-1, height-1, srcComponents); + if( imageSrc.getStride() == imageConv1.getStride() ) { + Assert.assertEquals(imageSrc.getPixels(), imageConv2.getPixels()); + } + } + } + } + } + private void dumpComponents(PixelRectangle image, int x1, int y1, int w, int h) { + if( x1 + w >= image.getSize().getWidth() ) { + x1 = image.getSize().getWidth() - w; + } + if( y1 + h >= image.getSize().getHeight() ) { + y1 = image.getSize().getHeight() - h; + } + System.err.print("PixelsBytes "+x1+"/"+y1+" "+w+"x"+h+":"); + final ByteBuffer bb = image.getPixels(); + final int bpp = image.getPixelformat().bytesPerPixel(); + for(int y = y1; y< y1+h; y++) { + System.err.printf("%n[%3d][%3d] ", x1, y); + int o = y * image.getStride()+x1*bpp; + for(int x = x1; x< x1+w; x++) { + switch(bpp) { + case 1: { + final byte a = bb.get(o++); + System.err.printf(" 0x%02X", a); + } + break; + case 2: { + final byte a = bb.get(o++), b = bb.get(o++); + System.err.printf(" 0x%02X%02X", b, a); + } + break; + case 3: { + final byte a = bb.get(o++), b = bb.get(o++), c = bb.get(o++); + System.err.printf(" 0x%02X%02X%02X", c, b, a); + } + break; + case 4: { + final byte a = bb.get(o++), b = bb.get(o++), c = bb.get(o++), d = bb.get(o++); + System.err.printf(" 0x%02X%02X%02X%02X", d, c, b, a); + } + break; + } + } + } + System.err.println(); + } + private void testComponents(PixelRectangle image, int x, int y, byte[] components) { + dumpComponents(image, x, y, 3, 3); + final ByteBuffer bb = image.getPixels(); + final int bpp = image.getPixelformat().bytesPerPixel(); + int o = y * image.getStride()+x*bpp; + switch(bpp) { + case 1: { + final byte c1 = bb.get(o++); + final boolean equal = c1==components[0]; + System.err.printf("Test [%3d][%3d] exp 0x%02X == has 0x%02X : %b%n", + x, y, components[0], c1, equal ); + Assert.assertEquals(components[0], c1); + } + break; + case 2: { + final byte c1 = bb.get(o++), c2 = bb.get(o++); + final boolean equal = c1==components[0] && c2==components[1]; + System.err.printf("Test [%3d][%3d] exp 0x%02X%02X == has 0x%02X%02X : %b%n", + x, components[1], components[0], c2, c1, equal ); + Assert.assertEquals(components[0], c1); + Assert.assertEquals(components[1], c2); + } + break; + case 3: { + final byte c1 = bb.get(o++), c2 = bb.get(o++), c3 = bb.get(o++); + final boolean equal = c1==components[0] && c2==components[1] && c3==components[2]; + System.err.printf("Test [%3d][%3d] exp 0x%02X%02X%02X == has 0x%02X%02X%02X : %b%n", + x, y, components[2], components[1], components[0], c3, c2, c1, equal ); + Assert.assertEquals(components[0], c1); + Assert.assertEquals(components[1], c2); + Assert.assertEquals(components[2], c3); + } + break; + case 4: { + final byte c1 = bb.get(o++), c2 = bb.get(o++), c3 = bb.get(o++), c4 = bb.get(o++); + final boolean equal = c1==components[0] && c2==components[1] && c3==components[2] && c4==components[3]; + System.err.printf("Test [%3d][%3d] exp 0x%02X%02X%02X%02X == has 0x%02X%02X%02X%02X : %b%n", + x, y, components[3], components[2], components[1], components[0], c4, c3, c2, c1, equal ); + Assert.assertEquals(components[0], c1); + Assert.assertEquals(components[1], c2); + Assert.assertEquals(components[2], c3); + Assert.assertEquals(components[3], c4); + } + break; + } + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestPixelFormatUtil00NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil01NEWT.java new file mode 100644 index 000000000..f54861371 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil01NEWT.java @@ -0,0 +1,105 @@ +/** + * Copyright 2014 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 java.io.IOException; +import java.net.MalformedURLException; +import java.net.URLConnection; + +import javax.media.nativewindow.util.PixelFormat; +import javax.media.nativewindow.util.PixelFormatUtil; +import javax.media.nativewindow.util.PixelRectangle; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.PNGPixelRect; + +/** + * Testing PixelFormatUtil's Conversion using PNG test data + * including strides, endian-order and PixelFormat conversions: + * { PixelFormat.RGBA8888, PixelFormat.ABGR8888, PixelFormat.BGRA8888, PixelFormat.ARGB8888 } + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TestPixelFormatUtil01NEWT extends UITestCase { + @Test + public void testPNGRead11_fromRGBA8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.RGBA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testPNGRead12_fromABGR8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.ABGR8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testPNGRead13_fromBGRA8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.BGRA8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + @Test + public void testPNGRead14_fromARGB8888() throws InterruptedException, IOException, MalformedURLException { + final String basename ="test-ntscN_4-01-160x90"; + final String pathname=""; + testPNG01Impl(pathname, basename, PixelFormat.ARGB8888, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + } + + private void testPNG01Impl(final String pathname, final String basename, final PixelFormat srcFmt, + final int destMinStrideInBytes, final boolean destIsGLOriented) + throws InterruptedException, IOException, MalformedURLException + { + System.err.println("Test01: "+pathname+basename+".png, srcFmt "+srcFmt+", destMinStrideInBytes "+destMinStrideInBytes+", destIsGLOriented "+destIsGLOriented); + + URLConnection urlConn = IOUtil.getResource(this.getClass(), pathname+basename+".png"); + + final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), srcFmt, false /* directBuffer */, destMinStrideInBytes, false /* isGLOriented */); + System.err.println("PNGPixelRect - Orig: "+image1); + + final PixelFormat[] formats = new PixelFormat[] { PixelFormat.RGBA8888, PixelFormat.ABGR8888, PixelFormat.BGRA8888, PixelFormat.ARGB8888 }; + for(int i=0; i<formats.length; i++) { + final PixelFormat destFmt = formats[i]; + System.err.println("CONVERT["+i+"]: "+srcFmt+" -> "+destFmt); + final PixelRectangle imageConv1 = PixelFormatUtil.convert32(image1, destFmt, destMinStrideInBytes, destIsGLOriented, false /* nio */); + System.err.println("PNGPixelRect - Conv1: "+imageConv1); + final PixelRectangle imageConv2 = PixelFormatUtil.convert32(imageConv1, image1.getPixelformat(), image1.getStride(), image1.isGLOriented(), false /* nio */); + System.err.println("PNGPixelRect - Conv2: "+imageConv2); + Assert.assertEquals(image1.getPixels(), imageConv2.getPixels()); + } + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestPixelFormatUtil01NEWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png Binary files differnew file mode 100644 index 000000000..92279640b --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-32x32.png diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png Binary files differnew file mode 100644 index 000000000..9be285335 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/crosshair-lumina-trans-64x64.png diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java index 69874df6b..70d01ae66 100644 --- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java +++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/NewtAWTReparentingKeyAdapter.java @@ -28,25 +28,27 @@ package com.jogamp.opengl.test.junit.newt.parenting; import java.awt.Frame; +import java.net.URLConnection; import javax.media.nativewindow.util.InsetsImmutable; import com.jogamp.common.util.IOUtil; import com.jogamp.newt.Display; -import com.jogamp.newt.Window; import com.jogamp.newt.Display.PointerIcon; import com.jogamp.newt.awt.NewtCanvasAWT; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; import com.jogamp.opengl.test.junit.util.QuitAdapter; +import com.jogamp.opengl.util.PNGPixelRect; public class NewtAWTReparentingKeyAdapter extends KeyAdapter { final Frame frame; final NewtCanvasAWT newtCanvasAWT; final GLWindow glWindow; final QuitAdapter quitAdapter; - PointerIcon pointerIconTest = null; + PointerIcon[] pointerIcons = null; + int pointerIconIdx = 0; public NewtAWTReparentingKeyAdapter(Frame frame, NewtCanvasAWT newtCanvasAWT, GLWindow glWindow, QuitAdapter quitAdapter) { this.frame = frame; @@ -144,13 +146,46 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { } } }.start(); } else if(e.getKeySymbol() == KeyEvent.VK_C ) { - if( null == pointerIconTest ) { - final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/jogamp-32x32.png" } ); - final Display disp = glWindow.getScreen().getDisplay(); - try { - pointerIconTest = disp.createPointerIcon(res, 16, 0); - } catch (Exception err) { - err.printStackTrace(); + if( null == pointerIcons ) { + { + pointerIcons = new PointerIcon[3]; + final Display disp = glWindow.getScreen().getDisplay(); + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "newt/data/crosshair-lumina-trans-32x32.png" } ); + try { + _pointerIcon = disp.createPointerIcon(res, 16, 16); + System.err.println("Create PointerIcon #01: "+_pointerIcon); + } catch (Exception ex) { + ex.printStackTrace(); + } + pointerIcons[0] = _pointerIcon; + } + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "jogamp-pointer-64x64.png" } ); + try { + _pointerIcon = disp.createPointerIcon(res, 32, 0); + System.err.println("Create PointerIcon #02: "+_pointerIcon); + } catch (Exception ex) { + ex.printStackTrace(); + } + pointerIcons[1] = _pointerIcon; + } + { + PointerIcon _pointerIcon = null; + final IOUtil.ClassResources res = new IOUtil.ClassResources(glWindow.getClass(), new String[] { "crosshair-lumina-trans-64x64.png" } ); + try { + final URLConnection urlConn = res.resolve(0); + final PNGPixelRect image = PNGPixelRect.read(urlConn.getInputStream(), null, false /* directBuffer */, 0 /* destMinStrideInBytes */, false /* destIsGLOriented */); + System.err.println("Create PointerIcon #03: "+image); + _pointerIcon = disp.createPointerIcon(image, 32, 32); + System.err.println("Create PointerIcon #03: "+_pointerIcon); + } catch (Exception ex) { + ex.printStackTrace(); + } + pointerIcons[2] = _pointerIcon; + } } } new Thread() { @@ -158,7 +193,14 @@ public class NewtAWTReparentingKeyAdapter extends KeyAdapter { final Thread t = glWindow.setExclusiveContextThread(null); System.err.println("[set pointer-icon pre]"); final PointerIcon currentPI = glWindow.getPointerIcon(); - glWindow.setPointerIcon( currentPI == pointerIconTest ? null : pointerIconTest); + final PointerIcon newPI; + if( pointerIconIdx >= pointerIcons.length ) { + newPI=null; + pointerIconIdx=0; + } else { + newPI=pointerIcons[pointerIconIdx++]; + } + glWindow.setPointerIcon( newPI ); System.err.println("[set pointer-icon post] "+currentPI+" -> "+glWindow.getPointerIcon()); glWindow.setExclusiveContextThread(t); } }.start(); |