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/25 15:03:00 UTC

[jira] [Closed] (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:all-tabpanel ]

Tilman Hausherr closed PDFBOX-5171.
-----------------------------------
    Resolution: Duplicate

Closing as duplicate of PDFBOX-5051. I've added you as a watcher there, and will probably use your 2nd solution.

> 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