Permalink
Browse files

Tests: GraphicsUtils.usesAlpha() returns false for image without tran…

…sparent pixels.
  • Loading branch information...
eseifert committed Aug 18, 2017
1 parent 73dc579 commit 903899bce0f1360988d9e7c499975b8c7ddba5c7
@@ -116,8 +116,11 @@ public static boolean usesAlpha(Image image) {
return false;
}
DataBuffer dataBuffer = alphaRaster.getDataBuffer();
final int elemBits = DataBuffer.getDataTypeSize(dataBuffer.getDataType());
final int alphaBits = elemBits/bimage.getRaster().getNumBands();
final int alphaShift = (elemBits - alphaBits);
for (int i = 0; i < dataBuffer.getSize(); i++) {
int alpha = dataBuffer.getElem(i);
int alpha = dataBuffer.getElem(i) >>> alphaShift;
if (alpha < 255) {
return true;
}
@@ -31,7 +31,9 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Polygon;
@@ -366,7 +368,7 @@ public void usesAlphaReturnsFalseForNullImage() {
@Test
public void usesAlphaReturnsFalseForImageWithoutAlphaChannel() {
Image image = new BufferedImage(320, 240, BufferedImage.TYPE_INT_RGB);
Image image = new BufferedImage(3, 3, BufferedImage.TYPE_INT_RGB);
boolean result = GraphicsUtils.usesAlpha(image);
@@ -375,10 +377,22 @@ public void usesAlphaReturnsFalseForImageWithoutAlphaChannel() {
@Test
public void usesAlphaReturnsTrueForImageWithTransparentPixels() {
Image image = new BufferedImage(320, 240, BufferedImage.TYPE_INT_ARGB);
Image image = new BufferedImage(3, 3, BufferedImage.TYPE_INT_ARGB);
boolean result = GraphicsUtils.usesAlpha(image);
assertTrue(result);
}
@Test
public void usesAlphaReturnsFalseForImageWithoutTransparentPixels() {
BufferedImage image = new BufferedImage(3, 3, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
g.setColor(Color.BLACK);
g.fillRect(image.getMinX(), image.getMinY(), image.getWidth(), image.getHeight());
boolean result = GraphicsUtils.usesAlpha(image);
assertFalse(result);
}
}

0 comments on commit 903899b

Please sign in to comment.