Use ARGB when on/off colors are not opaque

This commit is contained in:
Sean Owen 2014-06-25 08:49:23 +01:00
parent 17da7bbe4c
commit 15b4dedb98

View file

@ -55,8 +55,20 @@ public final class MatrixToImageConfig {
}
int getBufferedImageColorModel() {
// Use faster BINARY if colors match default
return onColor == BLACK && offColor == WHITE ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_INT_ARGB;
if (onColor == BLACK && offColor == WHITE) {
// Use faster BINARY if colors match default
return BufferedImage.TYPE_BYTE_BINARY;
}
if (hasTransparency(onColor) || hasTransparency(offColor)) {
// Use ARGB representation if colors specify non-opaque alpha
return BufferedImage.TYPE_INT_ARGB;
}
// Default otherwise to RGB representation with ignored alpha channel
return BufferedImage.TYPE_INT_RGB;
}
private static boolean hasTransparency(int argb) {
return (argb & 0xFF000000) != 0xFF000000;
}
}