aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/com/jogamp/opengl')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java61
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java6
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java7
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormat00NEWT.java61
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil00NEWT.java597
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormatUtil01NEWT.java11
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java5
13 files changed, 605 insertions, 171 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
index d3cdf5e95..95bec26fa 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestSharedContextNewtAWTBug523.java
@@ -72,6 +72,7 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.ExceptionUtils;
import com.jogamp.common.nio.Buffers;
import com.jogamp.newt.awt.NewtCanvasAWT;
import com.jogamp.newt.opengl.GLWindow;
@@ -476,7 +477,7 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase {
final String errStr = "GL-Error: "+prefix + " on obj 0x"+Integer.toHexString(obj.hashCode())+", OpenGL error: 0x" + Integer.toHexString(glError);
if( errorSet.add(errStr) ) {
System.err.println(errStr);
- Thread.dumpStack();
+ ExceptionUtils.dumpStack(System.err);
}
}
final int status = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
@@ -484,7 +485,7 @@ public class TestSharedContextNewtAWTBug523 extends UITestCase {
final String errStr = "GL-Error: "+prefix + " on obj 0x"+Integer.toHexString(obj.hashCode())+", glCheckFramebufferStatus: 0x" + Integer.toHexString(status);
if( errorSet.add(errStr) ) {
System.err.println(errStr);
- Thread.dumpStack();
+ ExceptionUtils.dumpStack(System.err);
}
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
index ae11c9d54..340816a13 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
@@ -31,11 +31,16 @@ package com.jogamp.opengl.test.junit.jogl.demos.es2.awt;
import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Dimension;
+import java.awt.DisplayMode;
+import java.awt.GraphicsDevice;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.lang.reflect.InvocationTargetException;
+import javax.media.nativewindow.NativeSurface;
import javax.media.nativewindow.ScalableSurface;
+import javax.media.nativewindow.util.Rectangle;
+import javax.media.nativewindow.util.RectangleImmutable;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
@@ -45,6 +50,8 @@ import javax.media.opengl.awt.GLJPanel;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
+import jogamp.common.os.PlatformPropsImpl;
+
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
@@ -53,6 +60,7 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.os.Platform;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.event.TraceKeyAdapter;
import com.jogamp.newt.event.TraceWindowAdapter;
@@ -70,11 +78,13 @@ import com.jogamp.opengl.util.FPSAnimator;
public class TestGearsES2GLJPanelAWT extends UITestCase {
static Dimension wsize, rwsize=null;
static boolean forceES2 = false;
+ static boolean forceES3 = false;
static boolean forceGL3 = false;
static boolean forceGLFFP = false;
static boolean shallUsePBuffer = false;
static boolean shallUseBitmap = false;
static boolean useMSAA = false;
+ static int msaaNumSamples = 4;
static int swapInterval = 0;
static boolean useAnimator = true;
static boolean manualTest = false;
@@ -117,6 +127,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
protected void runTestGL(final GLCapabilities caps)
throws AWTException, InterruptedException, InvocationTargetException
{
+ System.err.println("Requesting: "+caps);
+
final JFrame frame = new JFrame("Swing GLJPanel");
Assert.assertNotNull(frame);
@@ -209,7 +221,23 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
if( e.isAutoRepeat() ) {
return;
}
- if(e.getKeyChar()=='x') {
+ if(e.getKeyChar()=='p') {
+ System.err.println();
+ final java.awt.Point los = glJPanel.getLocationOnScreen();
+ final RectangleImmutable r = new Rectangle(los.x, los.y, glJPanel.getWidth(), glJPanel.getHeight());
+ final GraphicsDevice gd = glJPanel.getGraphicsConfiguration().getDevice();
+ final DisplayMode dm = gd.getDisplayMode();
+ System.err.printf("GetPixelScale: AWT DisplayMode %d x %d pixel-units%n", dm.getWidth(), dm.getHeight());
+ System.err.printf("GetPixelScale: NW Screen: %s%n", glJPanel.getNativeSurface().getGraphicsConfiguration().getScreen());
+ System.err.printf("GetPixelScale: Panel Bounds: %s window-units%n", r.toString());
+ System.err.printf("GetPixelScale: Panel Resolution: %d x %d pixel-units%n", glJPanel.getSurfaceWidth(), glJPanel.getSurfaceHeight());
+ if( Platform.OSType.MACOS == PlatformPropsImpl.OS_TYPE ) {
+ final int[] screenIndexOut = { 0 };
+ final double pixelScale = jogamp.nativewindow.macosx.OSXUtil.GetPixelScale(r, screenIndexOut);
+ System.err.printf("GetPixelScale: PixelScale %f on screen-idx %d%n", pixelScale, screenIndexOut[0]);
+ }
+ System.err.println();
+ } else if(e.getKeyChar()=='x') {
final int[] hadSurfacePixelScale = glJPanel.getCurrentSurfaceScale(new int[2]);
final int[] reqSurfacePixelScale;
if( hadSurfacePixelScale[0] == ScalableSurface.IDENTITY_PIXELSCALE ) {
@@ -302,16 +330,18 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
final GLProfile glp;
if(forceGL3) {
glp = GLProfile.get(GLProfile.GL3);
+ } else if(forceES3) {
+ glp = GLProfile.get(GLProfile.GLES3);
} else if(forceES2) {
glp = GLProfile.get(GLProfile.GLES2);
} else if(forceGLFFP) {
glp = GLProfile.getMaxFixedFunc(true);
} else {
- glp = GLProfile.getGL2ES2();
+ glp = GLProfile.getDefault();
}
final GLCapabilities caps = new GLCapabilities( glp );
if(useMSAA) {
- caps.setNumSamples(4);
+ caps.setNumSamples(msaaNumSamples);
caps.setSampleBuffers(true);
}
if(shallUsePBuffer) {
@@ -406,7 +436,24 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
}
@Test
- public void test30_GL3()
+ public void test30_GLES3()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+
+ if( !GLProfile.isAvailable(GLProfile.GLES3) ) {
+ System.err.println("GLES3 n/a");
+ return;
+ }
+ final GLProfile glp = GLProfile.get(GLProfile.GLES3);
+ final GLCapabilities caps = new GLCapabilities( glp );
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test40_GL3()
throws AWTException, InterruptedException, InvocationTargetException
{
if( manualTest ) {
@@ -447,6 +494,8 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
duration = MiscUtils.atol(args[i], duration);
} else if(args[i].equals("-es2")) {
forceES2 = true;
+ } else if(args[i].equals("-es3")) {
+ forceES3 = true;
} else if(args[i].equals("-gl3")) {
forceGL3 = true;
} else if(args[i].equals("-glFFP")) {
@@ -480,7 +529,9 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
i++;
swapInterval = MiscUtils.atoi(args[i], swapInterval);
} else if(args[i].equals("-msaa")) {
+ i++;
useMSAA = true;
+ msaaNumSamples = MiscUtils.atoi(args[i], msaaNumSamples);
} else if(args[i].equals("-noanim")) {
useAnimator = false;
} else if(args[i].equals("-pbuffer")) {
@@ -503,7 +554,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
System.err.println("forceES2 "+forceES2);
System.err.println("forceGL3 "+forceGL3);
System.err.println("forceGLFFP "+forceGLFFP);
- System.err.println("useMSAA "+useMSAA);
+ System.err.println("useMSAA "+useMSAA+", msaaNumSamples "+msaaNumSamples);
System.err.println("useAnimator "+useAnimator);
System.err.println("shallUsePBuffer "+shallUsePBuffer);
System.err.println("shallUseBitmap "+shallUseBitmap);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java
index 11d9da780..c22a6fdf8 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java
@@ -99,7 +99,7 @@ public class TestGearsES2GLJPanelsAWT extends UITestCase {
if( initSingleBuffer ) {
singleAWTGLPixelBufferProvider = new SingleAWTGLPixelBufferProvider( glp.isGL2ES3() /* allowRowStride */);
- singleAWTGLPixelBufferProvider.initSingleton(4, 600, 600, 1, true);
+ singleAWTGLPixelBufferProvider.initSingleton(null, 4, true, 600, 600, 1);
} else {
singleAWTGLPixelBufferProvider = null;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
index 546420057..ed20ccd97 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
@@ -40,6 +40,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import javax.media.nativewindow.util.PixelFormat;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
@@ -117,8 +118,9 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase {
@Override
public void init(final GLAutoDrawable drawable) {
final GL gl = drawable.getGL();
- final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
- final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
+ final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.getGLProfile(), 3);
+ final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3, true);
+ final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs, true, imageWidth, imageHeight, 1, 0);
renderer.setImageBuffer(pixelBuffer);
if( drawable.isGLOriented() ) {
flipVertically[0] = false;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
index b128f8691..a9d159684 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
@@ -48,6 +48,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
+import javax.media.nativewindow.util.PixelFormat;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
@@ -136,8 +137,9 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase {
@Override
public void init(final GLAutoDrawable drawable) {
final GL gl = drawable.getGL();
- final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
- final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
+ final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.getGLProfile(), 3);
+ final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3, true);
+ final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs, true, imageWidth, imageHeight, 1, 0);
renderer.setImageBuffer(pixelBuffer);
if( drawable.isGLOriented() ) {
flipVertically[0] = false;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
index 9dee67e5e..1f7016b7c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
@@ -39,6 +39,7 @@ import com.jogamp.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
+import javax.media.nativewindow.util.PixelFormat;
import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
@@ -121,8 +122,9 @@ public class TestTiledRendering1GL2NEWT extends UITestCase {
final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider = GLPixelBuffer.defaultProviderWithRowStride;
final boolean[] flipVertically = { false };
- final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
- final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
+ final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.getGLProfile(), 3);
+ final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3, true);
+ final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs, true, imageWidth, imageHeight, 1, 0);
renderer.setImageBuffer(pixelBuffer);
flipVertically[0] = false;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java
index e979ac966..e792ecaa2 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java
@@ -40,6 +40,8 @@ import com.jogamp.opengl.util.texture.TextureIO;
import java.io.File;
import java.io.IOException;
+
+import javax.media.nativewindow.util.PixelFormat;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
@@ -197,8 +199,9 @@ public class TestTiledRendering2NEWT extends UITestCase {
@Override
public void init(final GLAutoDrawable drawable) {
final GL gl = drawable.getGL();
- final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
- final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
+ final PixelFormat.Composition hostPixelComp = pixelBufferProvider.getHostPixelComp(gl.getGLProfile(), 3);
+ final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3, true);
+ final GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, hostPixelComp, pixelAttribs, true, imageWidth, imageHeight, 1, 0);
renderer.setImageBuffer(pixelBuffer);
if( drawable.isGLOriented() ) {
flipVertically[0] = false;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java
index 2eb8b45c3..1a146adb6 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT.java
@@ -112,7 +112,7 @@ public class TestBug817GLReadBufferUtilGLCTXDefFormatTypeES2NEWT extends UITestC
public void dispose(final GLAutoDrawable drawable) {}
public void display(final GLAutoDrawable drawable) {
final GLPixelBufferProvider pixelBufferProvider = screenshot.getPixelBufferProvider();
- final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(drawable.getGL(), readAlpha ? 4 : 3);
+ final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(drawable.getGL(), readAlpha ? 4 : 3, true);
System.err.println("GLPixelAttributes: "+pixelAttribs);
snapshot(displayCount++, null, drawable.getGL(), screenshot, TextureIO.PNG, null);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java
index 4a324f594..3f910ed36 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPNGPixelRect01NEWT.java
@@ -73,9 +73,10 @@ public class TestPNGPixelRect01NEWT extends UITestCase {
final GLProfile glp = GLProfile.getGL2ES2();
final PNGPixelRect image = PNGPixelRect.read(istream, destFmt, true /* directBuffer */, 0 /* destMinStrideInBytes */, true /* destIsGLOriented */);
Assert.assertNotNull(image);
- final GLPixelAttributes glpa = GLPixelAttributes.convert(image.getPixelformat(), glp);
- final boolean hasAlpha = 4 == glpa.bytesPerPixel;
- System.err.println("PNGPixelRect: "+basename+", "+image+", glpa "+glpa);
+ System.err.println("PNGPixelRect: "+basename+", "+image);
+ final GLPixelAttributes glpa = new GLPixelAttributes(glp, image.getPixelformat(), false /* pack */);
+ final boolean hasAlpha = 4 == glpa.pfmt.comp.bytesPerPixel();
+ System.err.println("GLPixelAttributes: "+glpa);
final GLReadBufferUtil screenshot = new GLReadBufferUtil(true, false);
final GLCapabilities caps = new GLCapabilities(glp);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormat00NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormat00NEWT.java
new file mode 100644
index 000000000..5550cfcd2
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/TestPixelFormat00NEWT.java
@@ -0,0 +1,61 @@
+/**
+ * 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 javax.media.nativewindow.util.PixelFormat;
+
+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 PixelFormat integrity
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestPixelFormat00NEWT extends UITestCase {
+ @Test
+ public void test00() throws InterruptedException, IOException, MalformedURLException {
+ final PixelFormat[] formats = PixelFormat.values();
+
+ for(int i=0; i<formats.length; i++) {
+ final PixelFormat pf = formats[i];
+ System.err.printf("%02d: %s, %s%n", i, pf, pf.comp);
+ final PixelFormat pf2 = PixelFormat.valueOf(pf.comp);
+ Assert.assertEquals(pf, pf2);
+ }
+ }
+ public static void main(final String args[]) {
+ org.junit.runner.JUnitCore.main(TestPixelFormat00NEWT.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
index 1b549fa96..6193ad1a7 100644
--- 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
@@ -36,12 +36,14 @@ 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 javax.media.nativewindow.util.PixelFormat.CType;
import org.junit.Assert;
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.util.Bitstream;
import com.jogamp.opengl.test.junit.util.UITestCase;
/**
@@ -50,142 +52,401 @@ import com.jogamp.opengl.test.junit.util.UITestCase;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestPixelFormatUtil00NEWT extends UITestCase {
+ static final byte undef_val = (byte)0xFF;
+ static final PixelFormat.Composition comp_val = PixelFormat.RGBA8888.comp;
+ static final float red___valF;
+ static final float green_valF;
+ static final float blue__valF;
+ static final float alpha_valF;
+ static final float lum___valF;
+ static {
+ // Using am equal stepping of 0x30 = 48 between each RGBA and undefined values,
+ // dividing 0xff equally by 5 excluding zero.
+ final byte red___val = (byte)0x30;
+ final byte green_val = (byte)0x60;
+ final byte blue__val = (byte)0x90;
+ final byte alpha_val = (byte)0xC0;
+ red___valF = comp_val.toFloat(red___val, 0, false);
+ green_valF = comp_val.toFloat(green_val, 1, false);
+ blue__valF = comp_val.toFloat(blue__val, 2, false);
+ alpha_valF = comp_val.toFloat(alpha_val, 3, false);
+ lum___valF = ( red___valF + green_valF + blue__valF ) / 3f;
+ }
+
+ @Test
+ public void testConversion00() throws InterruptedException, IOException, MalformedURLException {
+ {
+ final PixelFormat fmt = PixelFormat.RGBA5551;
+ final PixelFormat.Composition comp = fmt.comp;
+ System.err.printf("%s, %s:%n", fmt, comp);
+ final int u16_alpha = comp.encode4CompI8((byte)comp.fromFloat(red___valF, 0, false),
+ (byte)comp.fromFloat(green_valF, 0, false),
+ (byte)comp.fromFloat(blue__valF, 0, false),
+ (byte)comp.fromFloat(alpha_valF, 0, false));
+ final int u16_undef = comp.encode4CompI8((byte)comp.fromFloat(red___valF, 0, false),
+ (byte)comp.fromFloat(green_valF, 0, false),
+ (byte)comp.fromFloat(blue__valF, 0, false),
+ undef_val);
+ System.err.printf(" u16_alpha %s%n", Bitstream.toHexBinString(true, u16_alpha, comp.bitsPerPixel()));
+ System.err.printf(" u16_undef %s%n", Bitstream.toHexBinString(true, u16_undef, comp.bitsPerPixel()));
+ {
+ final byte c4NormI8_alpha = (byte)comp.fromFloat(alpha_valF, 0, false);
+ final byte c4NormI8_undef = undef_val;
+ final int compBitShift = 15;
+ final int compMask = 0x1;
+ final int v_alpha = ( c4NormI8_alpha & compMask ) << compBitShift ;
+ final int v_undef = ( c4NormI8_undef & compMask ) << compBitShift ;
+ System.err.printf(" xx_alpha %s%n", Bitstream.toHexBinString(true, v_alpha, comp.bitsPerPixel()));
+ System.err.printf(" xx_undef %s%n", Bitstream.toHexBinString(true, v_undef, comp.bitsPerPixel()));
+ }
+ }
+ {
+ final int r8 = 0x30;
+ final int g8 = 0x60;
+ final int b8 = 0x90;
+ final int a8 = 0xC0;
+
+ final int l1 = 0x1;
+ final int r5 = 0x6;
+ final int g6 = 0xC;
+ final int b5 = 0x6;
+
+ final PixelFormat rgba8888Fmt = PixelFormat.RGBA8888;
+ final PixelFormat.Composition rgba8888Comp = rgba8888Fmt.comp;
+ final PixelFormat rgb565Fmt = PixelFormat.RGB565;
+ final PixelFormat.Composition rgb565Comp = rgb565Fmt.comp;
+ final PixelFormat lumFmt = PixelFormat.LUMINANCE;
+ final PixelFormat.Composition lumComp = lumFmt.comp;
+ System.err.printf("%s, %s -> %s %s%n", rgb565Fmt, rgb565Comp, lumFmt, lumComp);
+
+ {
+ final float r8f = rgba8888Comp.toFloat(r8, 0, false);
+ final int r8fi = rgba8888Comp.fromFloat(r8f, 0, false);
+ final float g8f = rgba8888Comp.toFloat(g8, 1, false);
+ final int g8fi = rgba8888Comp.fromFloat(g8f, 1, false);
+ final float b8f = rgba8888Comp.toFloat(b8, 2, false);
+ final int b8fi = rgba8888Comp.fromFloat(b8f, 2, false);
+ final float a8f = rgba8888Comp.toFloat(a8, 3, false);
+ final int a8fi = rgba8888Comp.fromFloat(a8f, 3, false);
+
+ System.err.printf("res00.0.r %s -> %f -> %s%n", Bitstream.toHexBinString(true, r8, 8), r8f, Bitstream.toHexBinString(true, r8fi, 8));
+ System.err.printf("res00.0.g %s -> %f -> %s%n", Bitstream.toHexBinString(true, g8, 8), g8f, Bitstream.toHexBinString(true, g8fi, 8));
+ System.err.printf("res00.0.b %s -> %f -> %s%n", Bitstream.toHexBinString(true, b8, 8), b8f, Bitstream.toHexBinString(true, b8fi, 8));
+ System.err.printf("res00.0.a %s -> %f -> %s%n", Bitstream.toHexBinString(true, a8, 8), a8f, Bitstream.toHexBinString(true, a8fi, 8));
+ }
+ {
+ final float res00_0 = ( red___valF + green_valF + blue__valF ) / 3f;
+ final int res00 = rgba8888Comp.fromFloat(res00_0, 0, false);
+ System.err.printf("res01.0 ( %f + %f + %f ) / 3f = %f -> %s%n",
+ red___valF, green_valF, blue__valF, res00_0, Bitstream.toHexBinString(true, res00, 8));
+ }
+ {
+ final float res00_0 = ( red___valF + green_valF + blue__valF ) / 3f;
+ final int res00 = lumComp.fromFloat(res00_0, 0, false);
+ System.err.printf("res02.1 ( %f + %f + %f ) / 3f = %f -> %s%n",
+ red___valF, green_valF, blue__valF, res00_0, Bitstream.toHexBinString(true, res00, 8));
+ }
+ {
+ // sourceNorm static -> lum
+ final int rl1 = lumComp.fromFloat(red___valF, 0, false);
+ final int gl1 = lumComp.fromFloat(green_valF, 0, false);
+ final int bl1 = lumComp.fromFloat(blue__valF, 0, false);
+ final float rl2 = lumComp.toFloat(rl1, 0, false);
+ final float gl2 = lumComp.toFloat(gl1, 0, false);
+ final float bl2 = lumComp.toFloat(bl1, 0, false);
+ System.err.printf("res20.l1 ( %s + %s + %s )%n",
+ Bitstream.toHexBinString(true, rl1, 8),
+ Bitstream.toHexBinString(true, gl1, 8),
+ Bitstream.toHexBinString(true, bl1, 8));
+ System.err.printf("res20.l2 ( %f + %f + %f )%n", rl2, gl2, bl2);
+ final float res02_l2_0 = ( rl2 + gl2 + bl2 ) / 3f;
+ final int res02_l2_x = lumComp.fromFloat(res02_l2_0, 0, false);
+ System.err.printf("res20.l3 ( %f + %f + %f ) / 3f = %f -> %s%n",
+ rl2, gl2, bl2, res02_l2_0, Bitstream.toHexBinString(true, res02_l2_x, 8));
+
+ // rescale lum -> rgb565
+ final int r_1 = rgb565Comp.fromFloat(rl2, 0, false);
+ final int g_1 = rgb565Comp.fromFloat(gl2, 1, false);
+ final int b_1 = rgb565Comp.fromFloat(bl2, 2, false);
+ final float r_2 = rgb565Comp.toFloat(r_1, 0, false);
+ final float g_2 = rgb565Comp.toFloat(g_1, 1, false);
+ final float b_2 = rgb565Comp.toFloat(b_1, 2, false);
+ System.err.printf("res20._1 ( %s + %s + %s )%n",
+ Bitstream.toHexBinString(true, r_1, 8),
+ Bitstream.toHexBinString(true, g_1, 8),
+ Bitstream.toHexBinString(true, b_1, 8));
+ System.err.printf("res20._2 ( %f + %f + %f )%n", r_2, g_2, b_2);
+ final float res02__3_0 = ( r_2 + g_2 + b_2 ) / 3f;
+ final int res02__3_x = lumComp.fromFloat(res02__3_0, 0, false);
+ System.err.printf("res20._3 ( %f + %f + %f ) / 3f = %f -> %s%n",
+ r_2, g_2, b_2, res02__3_0, Bitstream.toHexBinString(true, res02__3_x, 8));
+ }
+ {
+ // sourceNorm static -> lum
+ // rescale lum -> rgb565
+ final float rF = rgb565Comp.toFloat(rescaleComp(lumComp, 0, rgb565Comp, 0, red___valF), 0, false);
+ final float gF = rgb565Comp.toFloat(rescaleComp(lumComp, 0, rgb565Comp, 1, green_valF), 1, false);
+ final float bF = rgb565Comp.toFloat(rescaleComp(lumComp, 0, rgb565Comp, 2, blue__valF), 2, false);
+ final float res01_0 = ( rF + gF + bF ) / 3f;
+ final int res01 = lumComp.fromFloat(res01_0, 0, false);
+ System.err.printf("res30.xx ( %f + %f + %f ) / 3f = %f -> %s%n",
+ rF, gF, bF, res01_0, Bitstream.toHexBinString(true, res01, 8));
+ }
+ {
+ final float rF = rgb565Comp.toFloat(r5, 0, false);
+ final float gF = rgb565Comp.toFloat(g6, 1, false);
+ final float bF = rgb565Comp.toFloat(b5, 2, false);
+
+ final float lF = ( rF + gF + bF ) / 3f;
+ final int res00 = lumComp.fromFloat(lF, 0, false);
+
+ System.err.printf("res40 ( %f + %f + %f ) / 3f = %s%n",
+ rF, gF, bF, Bitstream.toHexBinString(true, res00, 8));
+ }
+ }
+
+ }
+
@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 */);
+ testConversionImpl(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 */);
+ testConversionImpl(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 */);
+ testConversionImpl(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 */);
+ testConversionImpl(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 */);
+ testConversionImpl(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) {
+ /**
+ * Note: Fixes bit-rounding errors, i.e. RGBA5551: A 0.6f -> 0x01 -> 1f ... -> RGBA8888: A 0xff
+ */
+ static final float sourceNorm(final PixelFormat.Composition srcComp, final int sIdx, final float f) {
+ if( sIdx >= 0 && sIdx < srcComp.componenCount() ) {
+ return srcComp.toFloat(srcComp.fromFloat(f, sIdx, false), sIdx, false);
+ } else {
+ return 0f;
+ }
+ }
+ static final byte rescaleComp(final PixelFormat.Composition srcComp, final int sIdx,
+ final PixelFormat.Composition dstComp, final int dIdx, final float f) {
+ if( dIdx >= 0 && dIdx < dstComp.componenCount() ) {
+ return (byte)dstComp.fromFloat(sourceNorm(srcComp, sIdx, f), dIdx, false);
+ } else {
+ return (byte)0;
+ }
+ }
+ static final void getComponentData(final PixelFormat srcFmt, final PixelFormat dstFmt, final byte[] components) {
+ final PixelFormat.Composition srcComp = srcFmt.comp;
+ final PixelFormat.Composition dstComp = dstFmt.comp;
final byte b1, b2, b3, b4;
- if( 1 == srcComps ) {
+ int u16;
+ if( PixelFormat.LUMINANCE == srcFmt ) {
// LUM -> Fmt Conversion
- switch(fmt) {
+ switch(dstFmt) {
case LUMINANCE:
- b1 = red___val;
+ b1 = rescaleComp(srcComp, 0, dstComp, 0, lum___valF);
b2 = undef_val;
b3 = undef_val;
b4 = undef_val;
break;
- case RGB888:
- b1 = red___val;
- b2 = red___val;
- b3 = red___val;
+ case RGB565:
+ case BGR565:
+ u16 = dstComp.encode3CompI8(
+ rescaleComp(srcComp, 0, dstComp, 0, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 1, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 2, lum___valF));
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
b4 = undef_val;
break;
- case BGR888:
- b1 = red___val;
- b2 = red___val;
- b3 = red___val;
+ case RGBA5551:
+ u16 = dstComp.encode4CompI8(
+ rescaleComp(srcComp, 0, dstComp, 0, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 1, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 2, lum___valF),
+ undef_val);
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
b4 = undef_val;
break;
+ case ABGR1555:
+ u16 = dstComp.encode4CompI8(
+ undef_val,
+ rescaleComp(srcComp, 0, dstComp, 0, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 1, lum___valF),
+ rescaleComp(srcComp, 0, dstComp, 2, lum___valF) );
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
+ b4 = undef_val;
+ break;
+ case BGRx8888:
+ case RGBx8888:
+ case RGB888:
+ case BGR888:
case RGBA8888:
- b1 = red___val;
- b2 = red___val;
- b3 = red___val;
+ b1 = rescaleComp(srcComp, 0, dstComp, 0, lum___valF);
+ b2 = rescaleComp(srcComp, 0, dstComp, 1, lum___valF);
+ b3 = rescaleComp(srcComp, 0, dstComp, 2, lum___valF);
b4 = undef_val;
break;
case ABGR8888:
+ case ARGB8888:
b1 = undef_val;
- b2 = red___val;
- b3 = red___val;
- b4 = red___val;
+ b2 = rescaleComp(srcComp, 0, dstComp, 1, lum___valF);
+ b3 = rescaleComp(srcComp, 0, dstComp, 2, lum___valF);
+ b4 = rescaleComp(srcComp, 0, dstComp, 3, lum___valF);
break;
case BGRA8888:
- b1 = red___val;
- b2 = red___val;
- b3 = red___val;
+ b1 = rescaleComp(srcComp, 0, dstComp, 0, lum___valF);
+ b2 = rescaleComp(srcComp, 0, dstComp, 1, lum___valF);
+ b3 = rescaleComp(srcComp, 0, dstComp, 2, lum___valF);
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);
+ throw new InternalError("Unhandled format "+dstFmt);
}
} else {
+ final int srcIdxR = srcComp.find(CType.R);
+ final int srcIdxG = srcComp.find(CType.G);
+ final int srcIdxB = srcComp.find(CType.B);
+ final int srcIdxA = srcComp.find(CType.A);
+ final boolean srcHasAlpha = 0 <= srcIdxA;
+ final boolean srcHasRGB = 0 <= srcIdxR && 0 <= srcIdxG && 0 <= srcIdxB;
// 1:1 values
- switch(fmt) {
+ switch(dstFmt) {
case LUMINANCE:
- if( srcComps > 1 ) {
- b1 = ( red___val + green_val+ blue__val ) / 3;
+ if( srcHasRGB ) {
+ final float rF = sourceNorm(srcComp, srcIdxR, red___valF);
+ final float gF = sourceNorm(srcComp, srcIdxG, green_valF);
+ final float bF = sourceNorm(srcComp, srcIdxB, blue__valF);
+ b1 = (byte)dstComp.fromFloat( ( rF + gF + bF ) / 3f, 0, false);
b2 = undef_val;
b3 = undef_val;
b4 = undef_val;
} else {
- b1 = red___val;
+ b1 = rescaleComp(srcComp, 0, dstComp, 0, red___valF);
b2 = undef_val;
b3 = undef_val;
b4 = undef_val;
}
break;
+ case RGB565:
+ u16 = dstComp.encode3CompI8(
+ rescaleComp(srcComp, srcIdxR, dstComp, 0, red___valF),
+ rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF),
+ rescaleComp(srcComp, srcIdxB, dstComp, 2, blue__valF));
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
+ b4 = undef_val;
+ break;
+ case BGR565:
+ u16 = dstComp.encode3CompI8(
+ rescaleComp(srcComp, srcIdxB, dstComp, 0, blue__valF),
+ rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF),
+ rescaleComp(srcComp, srcIdxR, dstComp, 2, red___valF));
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
+ b4 = undef_val;
+ break;
+ case RGBA5551:
+ u16 = dstComp.encode4CompI8(
+ rescaleComp(srcComp, srcIdxR, dstComp, 0, red___valF),
+ rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF),
+ rescaleComp(srcComp, srcIdxB, dstComp, 2, blue__valF),
+ srcHasAlpha ? rescaleComp(srcComp, srcIdxA, dstComp, 3, alpha_valF) : undef_val);
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
+ b4 = undef_val;
+ break;
+ case ABGR1555:
+ u16 = dstComp.encode4CompI8(
+ srcHasAlpha ? rescaleComp(srcComp, srcIdxA, dstComp, 0, alpha_valF) : undef_val,
+ rescaleComp(srcComp, srcIdxB, dstComp, 1, blue__valF),
+ rescaleComp(srcComp, srcIdxG, dstComp, 2, green_valF),
+ rescaleComp(srcComp, srcIdxR, dstComp, 3, red___valF) );
+ b1 = (byte)( u16 & 0xff );
+ b2 = (byte)( ( u16 >>> 8 ) & 0xff );
+ b3 = undef_val;
+ b4 = undef_val;
+ break;
+ case RGBx8888:
case RGB888:
- b1 = red___val;
- b2 = green_val;
- b3 = blue__val;
+ b1 = rescaleComp(srcComp, srcIdxR, dstComp, 0, red___valF);
+ b2 = rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF);
+ b3 = rescaleComp(srcComp, srcIdxB, dstComp, 2, blue__valF);
b4 = undef_val;
break;
+ case BGRx8888:
case BGR888:
- b1 = blue__val;
- b2 = green_val;
- b3 = red___val;
+ b1 = rescaleComp(srcComp, srcIdxB, dstComp, 0, blue__valF);
+ b2 = rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF);
+ b3 = rescaleComp(srcComp, srcIdxR, dstComp, 2, red___valF);
b4 = undef_val;
break;
case RGBA8888:
- b1 = red___val;
- b2 = green_val;
- b3 = blue__val;
- b4 = srcComps > 3 ? alpha_val : undef_val;
+ b1 = rescaleComp(srcComp, srcIdxR, dstComp, 0, red___valF);
+ b2 = rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF);
+ b3 = rescaleComp(srcComp, srcIdxB, dstComp, 2, blue__valF);
+ if( srcHasAlpha ) {
+ b4 = rescaleComp(srcComp, srcIdxA, dstComp, 3, alpha_valF);
+ } else {
+ b4 = undef_val;
+ }
break;
case ABGR8888:
- b1 = srcComps > 3 ? alpha_val : undef_val;
- b2 = blue__val;
- b3 = green_val;
- b4 = red___val;
+ if( srcHasAlpha ) {
+ b1 = rescaleComp(srcComp, srcIdxA, dstComp, 0, alpha_valF);
+ } else {
+ b1 = undef_val;
+ }
+ b2 = rescaleComp(srcComp, srcIdxB, dstComp, 1, blue__valF);
+ b3 = rescaleComp(srcComp, srcIdxG, dstComp, 2, green_valF);
+ b4 = rescaleComp(srcComp, srcIdxR, dstComp, 3, red___valF);
break;
case BGRA8888:
- b1 = blue__val;
- b2 = green_val;
- b3 = red___val;
- b4 = srcComps > 3 ? alpha_val : undef_val;
+ b1 = rescaleComp(srcComp, srcIdxB, dstComp, 0, blue__valF);
+ b2 = rescaleComp(srcComp, srcIdxG, dstComp, 1, green_valF);
+ b3 = rescaleComp(srcComp, srcIdxR, dstComp, 2, red___valF);
+ if( srcHasAlpha ) {
+ b4 = rescaleComp(srcComp, srcIdxA, dstComp, 3, alpha_valF);
+ } else {
+ b4 = undef_val;
+ }
break;
case ARGB8888:
- b1 = srcComps > 3 ? alpha_val : undef_val;
- b2 = red___val;
- b3 = green_val;
- b4 = blue__val;
+ if( srcHasAlpha ) {
+ b1 = rescaleComp(srcComp, srcIdxA, dstComp, 0, alpha_valF);
+ } else {
+ b1 = undef_val;
+ }
+ b2 = rescaleComp(srcComp, srcIdxR, dstComp, 1, red___valF);
+ b3 = rescaleComp(srcComp, srcIdxG, dstComp, 2, green_valF);
+ b4 = rescaleComp(srcComp, srcIdxB, dstComp, 3, blue__valF);
break;
default:
- throw new InternalError("Unhandled format "+fmt);
+ throw new InternalError("Unhandled format "+dstFmt);
}
}
components[0] = b1;
@@ -193,85 +454,120 @@ public class TestPixelFormatUtil00NEWT extends UITestCase {
components[2] = b3;
components[3] = b4;
}
- private void testPNG00Impl(final int srcMinStrideInBytes, final ByteOrder srcByteOrder, final boolean srcIsGLOriented,
+ private void testConversionImpl(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 PixelFormat[] srcFormats = { PixelFormat.LUMINANCE };
+ // final PixelFormat[] dstFormats = { PixelFormat.RGBx8888 };
+ // final PixelFormat[] dstFormats = { PixelFormat.RGB5551 };
+ // final PixelFormat[] dstFormats = { PixelFormat.RGB888 };
+ // final PixelFormat[] srcFormats = { PixelFormat.RGB888 };
+ // final PixelFormat[] dstFormats = { PixelFormat.RGB565 };
+ final PixelFormat[] srcFormats = PixelFormat.values();
+ final PixelFormat[] dstFormats = 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();
+ for(int i=0; i<srcFormats.length; i++) {
+ final PixelFormat srcFmt = srcFormats[i];
+ final int srcBpp = srcFmt.comp.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);
+ final byte[] srcData = new byte[4];
+ getComponentData(srcFmt, srcFmt, srcData);
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]);
+ srcPixels.put(o++, srcData[0]);
+ break;
+ case BGR565:
+ case RGB565:
+ case ABGR1555:
+ case RGBA5551:
+ srcPixels.put(o++, srcData[0]);
+ srcPixels.put(o++, srcData[1]);
break;
case RGB888:
case BGR888:
- srcPixels.put(o++, srcComponents[0]);
- srcPixels.put(o++, srcComponents[1]);
- srcPixels.put(o++, srcComponents[2]);
+ srcPixels.put(o++, srcData[0]);
+ srcPixels.put(o++, srcData[1]);
+ srcPixels.put(o++, srcData[2]);
break;
+ case RGBx8888:
+ case BGRx8888:
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]);
+ srcPixels.put(o++, srcData[0]);
+ srcPixels.put(o++, srcData[1]);
+ srcPixels.put(o++, srcData[2]);
+ srcPixels.put(o++, srcData[3]);
break;
default:
throw new InternalError("Unhandled format "+srcFmt);
}
}
}
- final PixelRectangle imageSrc = new PixelRectangle.GenericPixelRect(srcFmt, new Dimension(width, height), srcStrideBytes, srcIsGLOriented, srcPixels);
+ 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);
+ System.err.printf("Source %s, %s%n", srcFmt, srcFmt.comp);
+ System.err.printf("Source Data: %s%n", Bitstream.toHexBinString(true, srcData, 0, srcFmt.comp.bytesPerPixel()));
+ testComponents(imageSrc, 0, 0, srcData, 0);
+ testComponents(imageSrc, width-1, height-1, srcData, 0);
- for(int j=0; j<formats.length; j++) {
- final PixelFormat destFmt = formats[j];
- System.err.println("CONVERT["+i+"]["+j+"]: "+srcFmt+" -> "+destFmt);
+ final int maxDelta = 12;
- final int destStrideBytes = Math.max(destMinStrideInBytes, width*destFmt.bytesPerPixel());
+ for(int j=0; j<dstFormats.length; j++) {
+ final PixelFormat destFmt = dstFormats[j];
+ System.err.println("CONVERT["+i+"]["+j+"]: "+srcFmt+" -> "+destFmt);
+ final int destStrideBytes = Math.max(destMinStrideInBytes, width*destFmt.comp.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);
+ getComponentData(srcFmt, destFmt, destComponents);
+ System.err.printf("Source %s, %s%n", srcFmt, srcFmt.comp);
+ System.err.printf("Source Data: %s%n", Bitstream.toHexBinString(true, srcData, 0, srcFmt.comp.bytesPerPixel()));
+ System.err.printf("Dest %s, %s%n", destFmt, destFmt.comp);
+ System.err.printf("Dest Data: %s%n", Bitstream.toHexBinString(true, destComponents, 0, destFmt.comp.bytesPerPixel()));
+ final PixelRectangle imageConv1 = PixelFormatUtil.convert(imageSrc, destFmt, destStrideBytes, destIsGLOriented, false /* nio */);
+ System.err.println("CONVERT["+i+"]["+j+"]: Conv1: "+imageConv1+", maxDelta "+maxDelta);
+ System.err.printf("Conv1 Data: %s%n", Bitstream.toHexBinString(true, imageConv1.getPixels(), 0, destFmt.comp.bytesPerPixel()));
+ testComponents(imageConv1, 0, 0, destComponents, maxDelta);
+ testComponents(imageConv1, width-1, height-1, destComponents, maxDelta);
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 ) {
+ } else if( srcFmt.comp.componenCount() > destFmt.comp.componenCount() ) {
// 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);
+ final PixelRectangle imageConv2 = PixelFormatUtil.convert(imageConv1, imageSrc.getPixelformat(), imageSrc.getStride(), imageSrc.isGLOriented(), false /* nio */);
+ System.err.println("CONVERT["+i+"]["+j+"]: Conv2: "+imageConv2+", maxDelta "+maxDelta);
+ System.err.printf("Conv2 Data: %s%n", Bitstream.toHexBinString(true, imageConv2.getPixels(), 0, srcFmt.comp.bytesPerPixel()));
+ final byte[] destReComponents = new byte[4];
+ getComponentData(destFmt, srcFmt, destReComponents);
+ System.err.printf("DestRe Data: %s%n", Bitstream.toHexBinString(true, destReComponents, 0, srcFmt.comp.bytesPerPixel()));
+ testComponents(imageConv2, 0, 0, destReComponents, maxDelta);
+ testComponents(imageConv2, width-1, height-1, destReComponents, maxDelta);
+ /**
+ * Due to 'dead' components or value range re-scale,
+ * identity comparison on byte level is not correct.
+ *
if( imageSrc.getStride() == imageConv1.getStride() ) {
Assert.assertEquals(imageSrc.getPixels(), imageConv2.getPixels());
}
+ */
}
}
}
}
- private void dumpComponents(final PixelRectangle image, int x1, int y1, final int w, final int h) {
+ static void dumpComponents(final PixelRectangle image, int x1, int y1, final int w, final int h) {
if( x1 + w >= image.getSize().getWidth() ) {
x1 = image.getSize().getWidth() - w;
}
@@ -280,7 +576,7 @@ public class TestPixelFormatUtil00NEWT extends UITestCase {
}
System.err.print("PixelsBytes "+x1+"/"+y1+" "+w+"x"+h+":");
final ByteBuffer bb = image.getPixels();
- final int bpp = image.getPixelformat().bytesPerPixel();
+ final int bpp = image.getPixelformat().comp.bytesPerPixel();
for(int y = y1; y< y1+h; y++) {
System.err.printf("%n[%3d][%3d] ", x1, y);
int o = y * image.getStride()+x1*bpp;
@@ -311,51 +607,58 @@ public class TestPixelFormatUtil00NEWT extends UITestCase {
}
System.err.println();
}
- private void testComponents(final PixelRectangle image, final int x, final int y, final byte[] components) {
+
+ static final void assertEquals(final int a, final int b, final int maxDelta) {
+ final int d = Math.abs( a - b );
+ Assert.assertTrue(String.format("Not equal: abs(%s - %s) = %d, > %d maxDelta",
+ Bitstream.toHexBinString(true, a, 8), Bitstream.toHexBinString(true, b, 8), d, maxDelta),
+ d <= maxDelta);
+ }
+ static final boolean equals(final int a, final int b, final int maxDelta) {
+ final int d = Math.abs( a - b );
+ return d <= maxDelta;
+ }
+
+ /**
+ *
+ * @param image actual data
+ * @param x position in actual data
+ * @param y position in actual data
+ * @param expData expected data
+ * @param maxDelta the maximum delta between expected {@code components} and actual {@code image} data
+ */
+ static void testComponents(final PixelRectangle image, final int x, final int y, final byte[] expData, final int maxDelta) {
dumpComponents(image, x, y, 3, 3);
+ final PixelFormat.Composition imgComp = image.getPixelformat().comp;
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, y, 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;
+ final int bytesPerPixel = imgComp.bytesPerPixel();
+ final int compCount = imgComp.componenCount();
+ final int[] compBitCount = imgComp.componentBitCount();
+
+ final int srcPixOffset = y * image.getStride()+x*bytesPerPixel;
+ final int bbPos = bb.position();
+ bb.position(bbPos+srcPixOffset);
+
+ final long srcPix64 = PixelFormatUtil.getShiftedI64(imgComp.bytesPerPixel(), bb, true);
+ final int[] srcComponents = new int[compCount];
+ final long expPix64 = PixelFormatUtil.getShiftedI64(imgComp.bytesPerPixel(), expData, 0);
+ final int[] expComponents = new int[compCount];
+ boolean equal = true;
+ for(int i=0; i<compCount; i++) {
+ srcComponents[i] = imgComp.decodeSingleI64(srcPix64, i);
+ expComponents[i] = imgComp.decodeSingleI64(expPix64, i);
+ equal = equal && equals(srcComponents[i], expComponents[i], maxDelta);
}
+ System.err.printf("Test [%3d][%3d] exp ", x, y);
+ for(int i=0; i<compCount; i++) { System.err.printf("%s ", Bitstream.toHexBinString(true, expComponents[i], compBitCount[i])); }
+ System.err.printf("==%nTest [%3d][%3d] has ", x, y);
+ for(int i=0; i<compCount; i++) { System.err.printf("%s ", Bitstream.toHexBinString(true, srcComponents[i], compBitCount[i])); }
+ System.err.printf(": equal %b%n%n", equal);
+ for(int i=0; i<compCount; i++) {
+ assertEquals(srcComponents[i], expComponents[i], maxDelta);
+ }
+
+ bb.position(bbPos);
}
public static void main(final String args[]) {
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
index eba920032..37c8c4494 100644
--- 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
@@ -40,6 +40,7 @@ import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
+import com.jogamp.common.util.Bitstream;
import com.jogamp.common.util.IOUtil;
import com.jogamp.opengl.test.junit.util.UITestCase;
import com.jogamp.opengl.util.PNGPixelRect;
@@ -86,15 +87,21 @@ public class TestPixelFormatUtil01NEWT extends UITestCase {
final PNGPixelRect image1 = PNGPixelRect.read(urlConn.getInputStream(), srcFmt, false /* directBuffer */, destMinStrideInBytes, false /* isGLOriented */);
System.err.println("PNGPixelRect - Orig: "+image1);
+ System.err.printf("Image Data: %s%n", Bitstream.toHexBinString(true, image1.getPixels(), 0, image1.getPixelformat().comp.bytesPerPixel()));
+ TestPixelFormatUtil00NEWT.dumpComponents(image1, 0, 0, 3, 3);
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 */);
+ final PixelRectangle imageConv1 = PixelFormatUtil.convert(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.printf("Conv1 Data: %s%n", Bitstream.toHexBinString(true, imageConv1.getPixels(), 0, imageConv1.getPixelformat().comp.bytesPerPixel()));
+ TestPixelFormatUtil00NEWT.dumpComponents(imageConv1, 0, 0, 3, 3);
+ final PixelRectangle imageConv2 = PixelFormatUtil.convert(imageConv1, image1.getPixelformat(), image1.getStride(), image1.isGLOriented(), false /* nio */);
System.err.println("PNGPixelRect - Conv2: "+imageConv2);
+ System.err.printf("Conv2 Data: %s%n", Bitstream.toHexBinString(true, imageConv2.getPixels(), 0, imageConv2.getPixelformat().comp.bytesPerPixel()));
+ TestPixelFormatUtil00NEWT.dumpComponents(imageConv2, 0, 0, 3, 3);
Assert.assertEquals(image1.getPixels(), imageConv2.getPixels());
}
}
diff --git a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
index 31d6b887d..c6ceab34e 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/AWTRobotUtil.java
@@ -46,6 +46,7 @@ import javax.media.opengl.GLDrawable;
import org.junit.Assert;
+import com.jogamp.common.ExceptionUtils;
import com.jogamp.common.util.awt.AWTEDTExecutor;
import com.jogamp.newt.event.WindowEvent;
@@ -229,7 +230,7 @@ public class AWTRobotUtil {
System.err.println("*** AWTRobotUtil.toFrontAndRequestFocus() UI failure");
System.err.println("*** window: "+window);
System.err.println("*** window.hasFocus(): "+window.hasFocus());
- Thread.dumpStack();
+ ExceptionUtils.dumpStack(System.err);
}
return success;
}
@@ -442,7 +443,7 @@ public class AWTRobotUtil {
}
System.err.println("*** gain: "+gain);
System.err.println("*** lost: "+lost);
- Thread.dumpStack();
+ ExceptionUtils.dumpStack(System.err);
}
Assert.assertTrue("Did not gain focus", hasFocus);
}