Reputation: 532
If the source raster in linear RGB color space is transformed using the following Java code, the java.awt.image.ImagingOpException: Unable to transform src image
error is thrown when the filter is applied (the last line).
ColorModel linearRGBColorModel = new DirectColorModel(
ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), 32,
0xff0000, 0xff00, 0xff, 0xff000000, true, DataBuffer.TYPE_INT);
WritableRaster srcRaster = linearRGBColorModel.createCompatibleWritableRaster(100, 100);
WritableRaster dstRaster = linearRGBColorModel.createCompatibleWritableRaster(200, 200);
BufferedImage srcImage = new BufferedImage(linearRGBColorModel, srcRaster, false, null);
BufferedImage dstImage = new BufferedImage(linearRGBColorModel, dstRaster, false, null);
AffineTransform aff = new AffineTransform();
aff.scale(2.0, 2.0);
AffineTransformOp op = new AffineTransformOp(aff, null);
op.filter(srcImage, dstImage);
When ColorSpace.CS_sRGB
is used instead, it works properly.
In real case I manipulate image with gray blurred line. Is transformation of such source just missing JDK feature or it doesn't make sense at all?
Anyway, I plan to recalculate pixels to sRGB and make the transformation afterwards.
Upvotes: 1
Views: 699
Reputation: 27094
Not really an explanation of why you code doesn't work*, but at least you can easily work around the issue. Instead of filtering the BufferedImage
s:
op.filter(srcImage, dstImage);
...you could filter the Raster
s:
op.filter(srcRaster, dstRaster);
Which will produce the same result (as using filter(BufferedImage, BufferedImage)
on two images in sRGB color space).
As long as the color spaces and raster layouts are the same, the type of color space doesn't really matter.
*) I strongly believe this is a Java (JRE) bug, and should be reported to Oracle/OpenJDK.
Upvotes: 2