Hi,
your message caught my attention, so I could not resist to try and
investigate it a little. I did not get too far and do not have the time to
do any tests, but maybe at least a small hint. To at least have a chance
that the sun java2d machinery draws the image without converting it first,
BufferedImage.getType() must return something else than TYPE_CUSTOM. (At
least I think so) For IndexColorModel, the raster has to be either
BytePackedRaster or ByteComponentRaster. ByteComponentRaster resulting in
BufferedImage type TYPE_BYTE_INDEXED is a safer bet.
I might be talking rubbish, but maybe it is worth trying.
Best regards,
Petr.
-----Původní zpráva-----
From: Tilman Hausherr
Sent: Tuesday, April 25, 2017 6:50 PM
To: [email protected]
Subject: Optimizing SampledImageReader.from1Bit
I tried optimize SampledImageReader.from1Bit() not just for stencils but
for all 1 bit images by using the raster to create smaller
BufferedImages. Instead of calling
"colorSpace.toRGBImage(raster);" where the raster would be copied into
an RGB image, I did this:
byte[] indexedValues = new byte[] { 0, (byte)0xFF };
ColorModel colorModel = new IndexColorModel(1, 2, indexedValues,
indexedValues, indexedValues);
return new BufferedImage(colorModel, raster, false, null);
Sadly, this resulted in a bigger memory footprint.
Lowest possible -Xmx setting to convert a file with 300dpi A4 scans: 76m
With the optimization: 123m
The stack trace suggests that java copies the image to an RGB image:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown
Source)
at java.awt.image.BufferedImage.<init>(Unknown Source)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown Source)
at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown Source)
at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.ValidatePipe.copyImage(Unknown Source)
at sun.java2d.SunGraphics2D.copyImage(Unknown Source)
at sun.java2d.pipe.DrawImage.makeBufferedImage(Unknown Source)
at sun.java2d.pipe.DrawImage.renderImageXform(Unknown Source)
at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
at sun.java2d.pipe.ValidatePipe.transformImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at
org.apache.pdfbox.rendering.PageDrawer.drawBufferedImage(PageDrawer.java:1007)
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]