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

Oliver Schmidtmer commented on PDFBOX-5171:
-------------------------------------------

I suppose you are refering to PDFBOX-5051?

I have to confess that the file there, slowpdfbox.pdf, seems to be also created 
by our PDF Printer. So that is exactly the same issue.

> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to