Permalink
Browse files

Tests: Fixed GraphicsUtils.getAlphaImage() tests for headless systems.

  • Loading branch information...
eseifert committed Aug 19, 2017
1 parent 0d55723 commit 3915cc0fa4f956a2a1318ec3a82088cdb50adb3e
Showing with 16 additions and 12 deletions.
  1. +16 −12 src/test/java/de/erichseifert/vectorgraphics2d/util/GraphicsUtilsTest.java
@@ -34,15 +34,14 @@
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.geom.Arc2D;
import java.awt.geom.CubicCurve2D;
import java.awt.geom.Ellipse2D;
@@ -54,6 +53,7 @@
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.FilteredImageSource;
import java.awt.image.RGBImageFilter;
@@ -468,11 +468,13 @@ public void getAlphaImageReturnsBlackImageForTransparentInput() {
@Test
public void getAlphaImageReturnsBlackImageForTransparentInputWithBitmaskAlpha() {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
BufferedImage image = config.createCompatibleImage(
TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, Transparency.BITMASK);
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel = new ComponentColorModel(
colorSpace, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(
DataBuffer.TYPE_BYTE, TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH, 4, null);
BufferedImage image = new BufferedImage(
colorModel, raster, colorModel.isAlphaPremultiplied(), null);
BufferedImage result = GraphicsUtils.getAlphaImage(image);
@@ -481,11 +483,13 @@ public void getAlphaImageReturnsBlackImageForTransparentInputWithBitmaskAlpha()
@Test
public void getAlphaImageReturnsWhiteImageForOpaqueInputWithBitmaskAlpha() {
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = environment.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
BufferedImage image = config.createCompatibleImage(
TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, Transparency.BITMASK);
ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel = new ComponentColorModel(
colorSpace, true, false, Transparency.BITMASK, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(
DataBuffer.TYPE_BYTE, TEST_IMAGE_WIDTH, TEST_IMAGE_WIDTH, 4, null);
BufferedImage image = new BufferedImage(
colorModel, raster, colorModel.isAlphaPremultiplied(), null);
Graphics g = image.getGraphics();
g.setColor(Color.RED);
g.fillRect(0, 0, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT);

0 comments on commit 3915cc0

Please sign in to comment.