线性RGB空间中的仿射变换

时间:2023-02-09 09:16:14

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).

如果使用以下Java代码转换线性RGB颜色空间中的源栅格,则应用过滤器时抛出java.awt.image.ImagingOpException:无法转换src图像错误(最后一行)。

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.

当使用ColorSpace.CS_sRGB时,它可以正常工作。

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?

在实际情况下,我用灰色模糊的线操纵图像。转换这样的源只是缺少JDK功能还是根本没有意义?

Anyway, I plan to recalculate pixels to sRGB and make the transformation afterwards.

无论如何,我计划重新计算像素到sRGB并在之后进行转换。

1 个解决方案

#1


2  

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 BufferedImages:

不是解释为什么你的代码不起作用*,但至少你可以轻松解决这个问题。而不是过滤BufferedImages:

op.filter(srcImage, dstImage);

...you could filter the Rasters:

...你可以过滤掉栅格:

op.filter(srcRaster, dstRaster);

Which will produce the same result (as using filter(BufferedImage, BufferedImage) on two images in sRGB color space).

这将产生相同的结果(如在sRGB颜色空间中的两个图像上使用过滤器(BufferedImage,BufferedImage))。

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.

*)我坚信这是一个Java(JRE)错误,应该报告给Oracle / OpenJDK。

#1


2  

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 BufferedImages:

不是解释为什么你的代码不起作用*,但至少你可以轻松解决这个问题。而不是过滤BufferedImages:

op.filter(srcImage, dstImage);

...you could filter the Rasters:

...你可以过滤掉栅格:

op.filter(srcRaster, dstRaster);

Which will produce the same result (as using filter(BufferedImage, BufferedImage) on two images in sRGB color space).

这将产生相同的结果(如在sRGB颜色空间中的两个图像上使用过滤器(BufferedImage,BufferedImage))。

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.

*)我坚信这是一个Java(JRE)错误,应该报告给Oracle / OpenJDK。