-
Bug
-
Resolution: Unresolved
-
P3
-
8, 11, 17, 20, 21
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Bug is present in at least Java 11 and 17
A DESCRIPTION OF THE PROBLEM :
When a ColorConvertOp initialised using `new ColorConvertOp(RenderingHints)` is used with a destination image uses that IndexColorModel (eg. black-white image created with `new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)`) the `ColorConvertOp.filter(BufferedImage, BufferedImage)` call will fail by throwing IllegalArgumentException.
The `new ColorConvertOp(RenderingHints)` constructor says it works for converting BufferedImages, and has no "except when the destination uses IndexColorModel" clause. Neither does `ColorConvertOp.filter(BufferedImage, BufferedImage)` have caveats about IndexColorModel images.
This is either a documentation bug, where it should be clearly stated that this special case is intended to not work. Or a code bug in the IndexColorModel special case code in `ColorConvertOp.filter(BufferedImage, BufferedImage)`.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Source ARGB converted to destination BW.
ACTUAL -
Exception in thread "main" java.lang.IllegalArgumentException: Destination ColorSpace is undefined
at java.desktop/java.awt.image.ColorConvertOp.ICCBIFilter(ColorConvertOp.java:305)
at java.desktop/java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:277)
at ColorConvertOpBug.main(ColorConvertOpBug.java:13)
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
public class ColorConvertOpBug
{
public static void main(String[] args)
{
BufferedImage src = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
BufferedImage dst = new BufferedImage(1,1,BufferedImage.TYPE_BYTE_BINARY);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src,dst);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create the ColorConvertOp using `new ColorConvertOp(ColorSpace, ColorSpace, RenderingHints)` constructor instead. This does mean the ColorConvertOp can't be created before source and destination images are known.
FREQUENCY : always
Bug is present in at least Java 11 and 17
A DESCRIPTION OF THE PROBLEM :
When a ColorConvertOp initialised using `new ColorConvertOp(RenderingHints)` is used with a destination image uses that IndexColorModel (eg. black-white image created with `new BufferedImage(w, h, BufferedImage.TYPE_BYTE_BINARY)`) the `ColorConvertOp.filter(BufferedImage, BufferedImage)` call will fail by throwing IllegalArgumentException.
The `new ColorConvertOp(RenderingHints)` constructor says it works for converting BufferedImages, and has no "except when the destination uses IndexColorModel" clause. Neither does `ColorConvertOp.filter(BufferedImage, BufferedImage)` have caveats about IndexColorModel images.
This is either a documentation bug, where it should be clearly stated that this special case is intended to not work. Or a code bug in the IndexColorModel special case code in `ColorConvertOp.filter(BufferedImage, BufferedImage)`.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Source ARGB converted to destination BW.
ACTUAL -
Exception in thread "main" java.lang.IllegalArgumentException: Destination ColorSpace is undefined
at java.desktop/java.awt.image.ColorConvertOp.ICCBIFilter(ColorConvertOp.java:305)
at java.desktop/java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:277)
at ColorConvertOpBug.main(ColorConvertOpBug.java:13)
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
public class ColorConvertOpBug
{
public static void main(String[] args)
{
BufferedImage src = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
BufferedImage dst = new BufferedImage(1,1,BufferedImage.TYPE_BYTE_BINARY);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src,dst);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Create the ColorConvertOp using `new ColorConvertOp(ColorSpace, ColorSpace, RenderingHints)` constructor instead. This does mean the ColorConvertOp can't be created before source and destination images are known.
FREQUENCY : always