You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2021/04/20 18:19:00 UTC

[jira] [Commented] (PDFBOX-5171) Slow PDColorSpace.toRGBImageAWT when processing many pixel sized chuncks

    [ https://issues.apache.org/jira/browse/PDFBOX-5171?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17326022#comment-17326022 ] 

Tilman Hausherr commented on PDFBOX-5171:
-----------------------------------------

Yeah, ColorConvertOp has a "price" for every call so it costs a lot of time if there are very small images.

I've tried both solutions in the past years and didn't use them, either because of rendering differences or because of slowness for other images. I need to test this again when I have more time, hopefully on the weekend. There's another open issue from not long ago. I remember that I found out that using setRGB(getRGB()) is the "gold standard", but too slow.

> Slow PDColorSpace.toRGBImageAWT when processing many pixel sized chuncks
> ------------------------------------------------------------------------
>
>                 Key: PDFBOX-5171
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5171
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Oliver Schmidtmer
>            Priority: Major
>         Attachments: EloPdfPrint_20210420132413502.pdf
>
>
> The attached PDF has a table which is embedded as an image.
> This image is processed in PDColorSpace.toRGBImageAWT(...) as
>  many little chuncks of mostly 1x1 or 2x1 pixels and takes very long.
>  When changing the function from a ColorConvertOp to drawing this is much faster (~2s vs. ~60s). It seems for many small images the ColorConvertOp has a big overhead.
> So I propose to change the implementation to:
> {code:java}
>     protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
>     {
>         //
>         // WARNING: this method is performance sensitive, modify with care!
>         //
>         // ICC Profile color transforms are only fast when performed using ColorConvertOp
>         ColorModel colorModel = new ComponentColorModel(colorSpace, false, false,
>                 Transparency.OPAQUE, raster.getDataBuffer().getDataType());
>         BufferedImage src = new BufferedImage(colorModel, raster, false, null);
>         BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
>                 BufferedImage.TYPE_INT_RGB);
>         Graphics2D g2d = (Graphics2D) dest.getGraphics();
>         g2d.drawImage(src, 0, 0, null);
>         g2d.dispose();
>         return dest;
>     }
> {code}
> or
> {code:java}
>     protected BufferedImage toRGBImageAWT(WritableRaster raster, ColorSpace colorSpace)
>     {
>         //
>         // WARNING: this method is performance sensitive, modify with care!
>         //
>         // ICC Profile color transforms are only fast when performed using ColorConvertOp
>         ColorModel colorModel = new ComponentColorModel(colorSpace, false, false,
>                 Transparency.OPAQUE, raster.getDataBuffer().getDataType());
>         BufferedImage src = new BufferedImage(colorModel, raster, false, null);
>         BufferedImage dest = new BufferedImage(raster.getWidth(), raster.getHeight(),
>                 BufferedImage.TYPE_INT_RGB);
>         if (src.getWidth() > 1 && src.getHeight() > 1)
>         {
>             ColorConvertOp op = new ColorConvertOp(null);
>             op.filter(src, dest);
>         }
>         else
>         {
>             Graphics2D g2d = (Graphics2D) dest.getGraphics();
>             g2d.drawImage(src, 0, 0, null);
>             g2d.dispose();
>         }
>         return dest;
>     }
> {code}
> if the ColorConvertOp is still faster in the normal case.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org