diff options
author | Sven Gothel <[email protected]> | 2013-09-27 01:53:18 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-27 01:53:18 +0200 |
commit | 7ec812589190c0fbc6916cc22d9b74f009244f5c (patch) | |
tree | cbf5a32430efe1e576322732089aa4b5faafd6a2 | |
parent | 6fbf6de172f50dce7f65790460458238bf780902 (diff) |
DirectDataBufferInt: createBufferedImage(..) use BufferedImage type value instead of component-count, support all int types ; Add type 'BufferedImageInt' preserving the custom image-type, add note about TYPE_CUSTOM
- createBufferedImage(..) use BufferedImage type value instead of component-count, support all int types
- Support all integer data image-type, hence we need to pass image-type instead of component count (collision).
- Also pass 'properties' to allow configuring all BufferedImage parameters (just in case)
- Return BufferedImageInt to allow user to query the used image-type, see below.
- Add type 'BufferedImageInt' preserving the custom image-type, add note about TYPE_CUSTOM
- Simply extends BufferedImage w/ custom image-type, since BufferedImage's type is TYPE_CUSTOM
due to our custom storage type (see API doc comment).
Unit tests:
- Testing all integer image-type's in
- TestTiledPrintingGearsSwingAWT
- TestTiledPrintingNIOImageSwingAWT
- Disable all AA print-hints, all AWT text visible on X11.
Probably has a regression on Windows / OSX .. TBD.
10 files changed, 176 insertions, 77 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 8c58efb3f..442b12672 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -332,7 +332,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.tile.TestRandomTiledRendering2GL2NEWT $* #testawt com.jogamp.opengl.test.junit.jogl.tile.TestRandomTiledRendering3GL2AWT $* #testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsAWT $* -#testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT $* +testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT $* #testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsSwingAWT2 $* #testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingGearsNewtAWT $* #testawt com.jogamp.opengl.test.junit.jogl.tile.TestTiledPrintingNIOImageSwingAWT $* @@ -454,7 +454,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.jogl.acore.TestPBufferDeadlockAWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteAWT $* #testawt com.jogamp.opengl.test.junit.jogl.acore.x11.TestGLXCallsOnAWT $* -testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPosAWT $* +#testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug816OSXCALayerPosAWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug675BeansInDesignTimeAWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug551AWT $* #testawt com.jogamp.opengl.test.junit.jogl.awt.TestBug572AWT $* diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java index d9c3c3791..1d66d67e7 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/DirectDataBufferInt.java @@ -28,6 +28,7 @@ package com.jogamp.nativewindow.awt; import java.awt.Point; +import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorModel; import java.awt.image.DataBuffer; @@ -36,6 +37,7 @@ import java.awt.image.SampleModel; import java.awt.image.SinglePixelPackedSampleModel; import java.awt.image.WritableRaster; import java.nio.IntBuffer; +import java.util.Hashtable; import com.jogamp.common.nio.Buffers; @@ -50,40 +52,97 @@ public final class DirectDataBufferInt extends DataBuffer { } } + public static class BufferedImageInt extends BufferedImage { + final int customImageType; + public BufferedImageInt (int customImageType, ColorModel cm, WritableRaster raster, Hashtable<?,?> properties) { + super(cm, raster, false /* isRasterPremultiplied */, properties); + this.customImageType = customImageType; + } + + /** + * @return one of the custom image-type values {@link BufferedImage#TYPE_INT_ARGB TYPE_INT_ARGB}, + * {@link BufferedImage#TYPE_INT_ARGB_PRE TYPE_INT_ARGB_PRE}, + * {@link BufferedImage#TYPE_INT_RGB TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_BGR TYPE_INT_BGR}. + */ + public int getCustomType() { + return customImageType; + } + + @Override + public String toString() { + return new String("BufferedImageInt@"+Integer.toHexString(hashCode()) + +": custum/internal type = "+customImageType+"/"+getType() + +" "+getColorModel()+" "+getRaster()); + } + } + /** - * Creates a {@link BufferedImage} using an RGB[A] {@link DirectColorModel} - * with an {@link DirectWritableRaster} utilizing a {@link DirectDataBufferInt} as storage. + * Creates a {@link BufferedImageInt} using a {@link DirectColorModel direct color model} in {@link ColorSpace#CS_sRGB sRGB color space}.<br> + * It uses a {@link DirectWritableRaster} utilizing {@link DirectDataBufferInt} storage. + * <p> + * Note that due to using the custom storage type {@link DirectDataBufferInt}, the resulting + * {@link BufferedImage}'s {@link BufferedImage#getType() image-type} is of {@link BufferedImage#TYPE_CUSTOM TYPE_CUSTOM}. + * We are not able to change this detail, since the AWT image implementation associates the {@link BufferedImage#getType() image-type} + * with a build-in storage-type. + * Use {@link BufferedImageInt#getCustomType()} to retrieve the custom image-type, which will return the <code>imageType</code> + * value passed here. + * </p> * * @param width * @param height - * @param numComponents 3 or 4 components, i.e. {@link BufferedImage#TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_RGBA}. + * @param imageType one of {@link BufferedImage#TYPE_INT_ARGB TYPE_INT_ARGB}, {@link BufferedImage#TYPE_INT_ARGB_PRE TYPE_INT_ARGB_PRE}, + * {@link BufferedImage#TYPE_INT_RGB TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_BGR TYPE_INT_BGR}. * @param location origin, if <code>null</code> 0/0 is assumed. + * @param properties <code>Hashtable</code> of + * <code>String</code>/<code>Object</code> pairs. Used for {@link BufferedImage#getProperty(String)} etc. * @return */ - public static BufferedImage createBufferedImage(int width, int height, int numComponents, Point location) { - final int[] bandOffsets = new int[numComponents]; - for (int i=0; i < numComponents; i++) { + public static BufferedImageInt createBufferedImage(int width, int height, int imageType, Point location, Hashtable<?,?> properties) { + final int[] bandOffsets = new int[imageType]; + for (int i=0; i < imageType; i++) { bandOffsets[i] = i; } + final ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB); + final int transferType = DataBuffer.TYPE_INT; final int bpp, rmask, gmask, bmask, amask; - final ColorModel cm; - if( 4 == numComponents ) { - bpp = 32; - rmask = 0x00ff0000; - gmask = 0x0000ff00; - bmask = 0x000000ff; - amask = 0xff000000; - cm = ColorModel.getRGBdefault(); - } else if( 3 == numComponents ) { - bpp = 24; - rmask = 0x00ff0000; - gmask = 0x0000ff00; - bmask = 0x000000ff; - amask = 0x0; - cm = new DirectColorModel(bpp, rmask, gmask, bmask, amask); - } else { - throw new IllegalArgumentException("numComponents must be [3..4], has "+numComponents); + final boolean alphaPreMul; + switch( imageType ) { + case BufferedImage.TYPE_INT_ARGB: + bpp = 32; + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0xff000000; + alphaPreMul = false; + break; + case BufferedImage.TYPE_INT_ARGB_PRE: + bpp = 32; + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0xff000000; + alphaPreMul = true; + break; + case BufferedImage.TYPE_INT_RGB: + bpp = 24; + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0x0; + alphaPreMul = false; + break; + case BufferedImage.TYPE_INT_BGR: + bpp = 24; + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0x0; + alphaPreMul = false; + break; + default: + throw new IllegalArgumentException("Unsupported imageType, must be [INT_ARGB, INT_ARGB_PRE, INT_RGB, INT_BGR], has "+imageType); } + final ColorModel colorModel = new DirectColorModel(colorSpace, bpp, rmask, gmask, bmask, amask, alphaPreMul, transferType); final int[] bandMasks; if ( 0 != amask ) { bandMasks = new int[4]; @@ -108,7 +167,7 @@ public final class DirectDataBufferInt extends DataBuffer { // final WritableRaster raster = new SunWritableRaster(sppsm, dataBuffer, location); final WritableRaster raster = new DirectWritableRaster(sppsm, dataBuffer, location); - return new BufferedImage (cm, raster, false /* isRasterPremultiplied */, null /* properties */); + return new BufferedImageInt(imageType, colorModel, raster, properties); } /** Default data bank. */ diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java index 1517e0bd1..37ad8c361 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OffscreenPrintable.java @@ -31,7 +31,6 @@ import java.awt.Container; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; -import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.awt.print.Paper; @@ -55,6 +54,7 @@ import com.jogamp.nativewindow.awt.DirectDataBufferInt; */ public class OffscreenPrintable extends PrintableBase implements Printable { + public final int imageType; public final String pngFilename; /** @@ -62,11 +62,13 @@ public class OffscreenPrintable extends PrintableBase implements Printable { * @param job * @param printContainer * @param printDPI - * @param numSamples multisampling value: < 0 turns off, == 0 leaves as-is, > 0 enables using given num samples + * @param numSamples multisampling value: < 0 turns off, == 0 leaves as-is, > 0 enables using given num samples + * @param imageType AWT BufferedImage type (must be one of the integer types) * @param pngFilename TODO */ - public OffscreenPrintable(PrinterJob job, Container printContainer, int printDPI, int numSamples, String pngFilename) { + public OffscreenPrintable(PrinterJob job, Container printContainer, int printDPI, int numSamples, int imageType, String pngFilename) { super(job, printContainer, printDPI, numSamples); + this.imageType = imageType; this.pngFilename = pngFilename; } @@ -141,13 +143,14 @@ public class OffscreenPrintable extends PrintableBase implements Printable { " -> total "+frameWidthT+ "x" + frameHeightT+ " -> scaled "+frameSWidthT+ "x" + frameSHeightT); - final BufferedImage image = DirectDataBufferInt.createBufferedImage(frameSWidthT, frameSHeightT, 4, null /* location */); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frameSWidthT, frameSHeightT, imageType, null /* location */, null /* properties */); { + System.err.println("PRINT.offscrn image "+image); final Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.setClip(0, 0, frameSWidthT, frameSHeightT); g2d.scale(scaleGraphics, scaleGraphics); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { cont.printAll(g2d); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java index 273da5c76..a23f7f8c3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/OnscreenPrintable.java @@ -145,8 +145,8 @@ public class OnscreenPrintable extends PrintableBase implements Printable { System.err.println("PRINT at.pre: "+g2d.getTransform()); g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.scale(scaleComp72, scaleComp72); // WARNING: Produces rounding artifacts due to diff scale-factor of AWT/GL comps !!! - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AWTEDTExecutor.singleton.invoke(true, new Runnable() { public void run() { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java index 5c200a076..af4b41af2 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsAWT.java @@ -36,6 +36,7 @@ import java.awt.Label; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.io.BufferedReader; import java.io.IOException; @@ -177,26 +178,26 @@ public class TestTiledPrintingGearsAWT extends TiledPrintingAWTBase { if( !printDone ) { printDone = true; { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 0); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 0); waitUntilPrintJobsIdle(p); } { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 8); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 8); waitUntilPrintJobsIdle(p); } { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 300, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 300, -1); waitUntilPrintJobsIdle(p); } { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, true, 300, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 300, -1); waitUntilPrintJobsIdle(p); } if( allow600dpi ) { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 600, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 600, -1); waitUntilPrintJobsIdle(p); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsNewtAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsNewtAWT.java index 1a5f8b922..d600c95a8 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsNewtAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsNewtAWT.java @@ -36,6 +36,7 @@ import java.awt.Label; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.io.BufferedReader; import java.io.IOException; @@ -182,26 +183,26 @@ public class TestTiledPrintingGearsNewtAWT extends TiledPrintingAWTBase { if( !printDone ) { printDone = true; { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 0); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 0); waitUntilPrintJobsIdle(p); } { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 8); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 8); waitUntilPrintJobsIdle(p); } { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 300, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 300, -1); waitUntilPrintJobsIdle(p); } { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, true, 300, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 300, -1); waitUntilPrintJobsIdle(p); } if( allow600dpi ) { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 600, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 600, -1); waitUntilPrintJobsIdle(p); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java index b4f5ad988..cd1ae8657 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT.java @@ -36,6 +36,7 @@ import java.awt.Frame; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; import java.awt.print.PageFormat; import java.io.BufferedReader; import java.io.IOException; @@ -216,26 +217,41 @@ public class TestTiledPrintingGearsSwingAWT extends TiledPrintingAWTBase { if( !printDone ) { printDone = true; { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 0); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 0); waitUntilPrintJobsIdle(p); } { - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 72, 8); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 72, 8); waitUntilPrintJobsIdle(p); } { - // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 300, -1); + // No AA needed for 150 dpi and greater :) + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 150, -1); waitUntilPrintJobsIdle(p); } { - // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, true, 300, -1); + // No AA needed for 150 dpi and greater :) + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB_PRE /* offscreen-type */, 150, -1); + waitUntilPrintJobsIdle(p); + } + { + // No AA needed for 150 dpi and greater :) + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_ARGB /* offscreen-type */, 150, -1); + waitUntilPrintJobsIdle(p); + } + { + // No AA needed for 150 dpi and greater :) + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_RGB /* offscreen-type */, 150, -1); + waitUntilPrintJobsIdle(p); + } + { + // No AA needed for 150 dpi and greater :) + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, BufferedImage.TYPE_INT_BGR /* offscreen-type */, 150, -1); waitUntilPrintJobsIdle(p); } if( allow600dpi ) { // No AA needed for 300 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, false, 600, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.LANDSCAPE, null, -1 /* offscreen-type */, 600, -1); waitUntilPrintJobsIdle(p); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java index f619ec9a1..a89f4dd6e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingGearsSwingAWT2.java @@ -220,7 +220,7 @@ public class TestTiledPrintingGearsSwingAWT2 extends TiledPrintingAWTBase { printDone = true; { // No AA needed for 150 dpi and greater :) - final PrintableBase p = doPrintAuto(frame, PageFormat.PORTRAIT, null, false, 150, -1); + final PrintableBase p = doPrintAuto(frame, PageFormat.PORTRAIT, null, -1 /* offscreen-type */, 150, -1); waitUntilPrintJobsIdle(p); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java index a0c50ac4b..3198212b5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledPrintingNIOImageSwingAWT.java @@ -36,7 +36,6 @@ import java.awt.Frame; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Label; -import java.awt.RenderingHints; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; @@ -125,8 +124,8 @@ public class TestTiledPrintingNIOImageSwingAWT extends UITestCase { final Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.setClip(0, 0, image.getWidth(), image.getHeight()); g2d.scale(scaleComp72, scaleComp72); - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + // g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // frame.paintAll(g2d); final AWTPrintLifecycle.Context ctx = AWTPrintLifecycle.Context.setupPrint(frame, 1.0/scaleComp72, 1.0/scaleComp72, 0); @@ -230,21 +229,39 @@ public class TestTiledPrintingNIOImageSwingAWT extends UITestCase { Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel1, true)); Assert.assertEquals(true, AWTRobotUtil.waitForRealized(glJPanel2, true)); - // paint offscreen: array 72dpi + // paint offscreen: array 72dpi ARGB { final BufferedImage image = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_ARGB); - printOffscreenToFile(image, frame, caps, 0, "array_072dpi"); + printOffscreenToFile(image, frame, caps, 0, "array_072dpi_argb"); } - // paint offscreen: NIO 72dpi + // paint offscreen: NIO 72dpi ARGB { - final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth(), frame.getHeight(), 4, null /* location */); - printOffscreenToFile(image, frame, caps, 1, "newio_072dpi"); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_ARGB, null /* location */, null /* properties */); + printOffscreenToFile(image, frame, caps, 1, "newio_072dpi_argb"); } - // paint offscreen: NIO 300dpi + // paint offscreen: NIO 150dpi ARGB { - final int scale = (int) ( 300.0 / 72.0 + 0.5 ); - final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth()*scale, frame.getHeight()*scale, 4, null /* location */); - printOffscreenToFile(image, frame, caps, 2, "newio_300dpi"); + final int scale = (int) ( 150.0 / 72.0 + 0.5 ); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth()*scale, frame.getHeight()*scale, BufferedImage.TYPE_INT_ARGB, null /* location */, null /* properties */); + printOffscreenToFile(image, frame, caps, 2, "newio_150dpi_argb"); + } + // paint offscreen: NIO 150dpi ARGB_PRE + { + final int scale = (int) ( 150.0 / 72.0 + 0.5 ); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth()*scale, frame.getHeight()*scale, BufferedImage.TYPE_INT_ARGB_PRE, null /* location */, null /* properties */); + printOffscreenToFile(image, frame, caps, 2, "newio_150dpi_argbp"); + } + // paint offscreen: NIO 150dpi RGB + { + final int scale = (int) ( 150.0 / 72.0 + 0.5 ); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth()*scale, frame.getHeight()*scale, BufferedImage.TYPE_INT_RGB, null /* location */, null /* properties */); + printOffscreenToFile(image, frame, caps, 2, "newio_150dpi_rgb"); + } + // paint offscreen: NIO 150dpi BGR + { + final int scale = (int) ( 150.0 / 72.0 + 0.5 ); + final BufferedImage image = DirectDataBufferInt.createBufferedImage(frame.getWidth()*scale, frame.getHeight()*scale, BufferedImage.TYPE_INT_BGR, null /* location */, null /* properties */); + printOffscreenToFile(image, frame, caps, 2, "newio_150dpi_bgr"); } Assert.assertNotNull(frame); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java index 199a667a1..8393cf978 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TiledPrintingAWTBase.java @@ -70,11 +70,11 @@ public abstract class TiledPrintingAWTBase extends UITestCase { * @param cont * @param pOrientation * @param paper - * @param offscrn TODO + * @param offscrnImageType if < 0 onscreen, otherwise integer BufferedImage type * @param dpi * @param numSamples multisampling value: < 0 turns off, == 0 leaves as-is, > 0 enables using given num samples */ - public PrintableBase doPrintAuto(Container cont, int pOrientation, Paper paper, boolean offscrn, int dpi, int numSamples) { + public PrintableBase doPrintAuto(Container cont, int pOrientation, Paper paper, int offscrnImageType, int dpi, int numSamples) { lock.lock(); try { final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); @@ -91,31 +91,29 @@ public abstract class TiledPrintingAWTBase extends UITestCase { StreamPrintServiceFactory[] factories = PrinterJob.lookupStreamPrintServices(pdfMimeType); if (factories.length > 0) { - final String fname = getPrintFilename(offscrn, dpi, numSamples, "pdf"); + final String fname = getPrintFilename(offscrnImageType, dpi, numSamples, "pdf"); System.err.println("doPrint: dpi "+dpi+", "+fname); FileOutputStream outstream; try { outstream = new FileOutputStream(fname); - return doPrintAutoImpl(cont, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscrn, dpi, numSamples); + return doPrintAutoImpl(cont, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscrnImageType, dpi, numSamples); } catch (FileNotFoundException e) { Assert.assertNull("Unexpected exception", e); } - return null; } System.err.println("No PDF"); factories = PrinterJob.lookupStreamPrintServices(psMimeType); if (factories.length > 0) { - final String fname = getPrintFilename(offscrn, dpi, numSamples, "ps"); + final String fname = getPrintFilename(offscrnImageType, dpi, numSamples, "ps"); System.err.println("doPrint: dpi "+dpi+", "+fname); FileOutputStream outstream; try { outstream = new FileOutputStream(fname); - return doPrintAutoImpl(cont, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscrn, dpi, numSamples); + return doPrintAutoImpl(cont, pj, factories[0].getPrintService(outstream), pOrientation, paper, offscrnImageType, dpi, numSamples); } catch (FileNotFoundException e) { Assert.assertNull("Unexpected exception", e); } - return null; } System.err.println("No PS"); return null; @@ -123,15 +121,15 @@ public abstract class TiledPrintingAWTBase extends UITestCase { lock.unlock(); } } - private String getPrintFilename(boolean offscrn, int dpi, int numSamples, String suffix) { + private String getPrintFilename(int offscrnImageType, int dpi, int numSamples, String suffix) { final int maxSimpleTestNameLen = getMaxTestNameLen()+getClass().getSimpleName().length()+1; final String simpleTestName = getSimpleTestName("."); - final String onoffscrn = offscrn ? "offscrn" : "on_scrn"; + final String onoffscrn = 0 > offscrnImageType ? "on_screen" : "offscrn_"+offscrnImageType; return String.format("%-"+maxSimpleTestNameLen+"s-n%04d-%s-dpi%03d-aa%d.%s", simpleTestName, printCount, onoffscrn, dpi, numSamples, suffix).replace(' ', '_'); } private PrintableBase doPrintAutoImpl(Container cont, PrinterJob job, StreamPrintService ps, int pOrientation, Paper paper, - boolean offscrn, int dpi, int numSamples) { + int offscrnImageType, int dpi, int numSamples) { try { PageFormat pageFormat = job.defaultPage(); if( null != paper ) { @@ -143,8 +141,12 @@ public abstract class TiledPrintingAWTBase extends UITestCase { } pageFormat.setOrientation(pOrientation); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT job.setPrintService(ps); - final PrintableBase printable = offscrn ? new OffscreenPrintable(job, cont, dpi, numSamples, getPrintFilename(offscrn, dpi, numSamples, "png")) : - new OnscreenPrintable(job, cont, dpi, numSamples); + final PrintableBase printable; + if( 0 < offscrnImageType ) { + printable = new OffscreenPrintable(job, cont, dpi, numSamples, offscrnImageType, getPrintFilename(offscrnImageType, dpi, numSamples, "png")); + } else { + printable = new OnscreenPrintable(job, cont, dpi, numSamples); + } printable.job.setPrintable(printable, pageFormat); doPrintImpl(printable); return printable; |