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

Tilman Hausherr edited comment on PDFBOX-3854 at 7/5/17 6:55 PM:
-----------------------------------------------------------------

It is really just that method. I am testing copying the image the hard way 
(without ColorConvertOp) and that works fast too, but I need to rerun all tests 
again.

{code}
    public BufferedImage toRGBImage(WritableRaster raster) throws IOException
    {
        init();
        ColorModel colorModel = new ComponentColorModel(awtColorSpace,
                false, false, Transparency.OPAQUE, 
raster.getDataBuffer().getDataType());

        BufferedImage image = new BufferedImage(colorModel, raster, false, 
null);

        BufferedImage dest = new BufferedImage(image.getWidth(), 
image.getHeight(), BufferedImage.TYPE_INT_RGB);
        int width = image.getWidth();
        int height = image.getHeight();
        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                dest.setRGB(x, y, image.getRGB(x, y));
            }
        }
        return dest;
    }
{code}

What I am wondering about: in my 1000 PDF test I didn't notice any improvement, 
maybe this is because they are very different. Is your project something where 
all PDF files are always with RGB colorspaces?


was (Author: tilman):
It is really just that method. I am testing copying the image the hard way 
(without ColorConvertOp) and that works fast too, but I need to rerun all tests 
again.

What I am wondering about: in my 1000 PDF test I didn't notice any improvement, 
maybe this is because they are very different. Is your project something where 
all PDF files are always with RGB colorspaces?

> PDDeviceRGB.toRGBImage does not return a RGB-Typed-Image
> --------------------------------------------------------
>
>                 Key: PDFBOX-3854
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3854
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.6
>            Reporter: Yannick Haser
>         Attachments: rgbImageExample0.pdf, rgbImageSecondExample.pdf, 
> Starter2.java, Starter.java
>
>
> While converting a PDPage to a BufferedImage (using the PDFRenderer) 
> Images-Resources located in the PDPage gets loaded in a WriteableRaster and a 
> given Colorspace.
> These get converted to a BufferedImage (with PDDeviceRGB.toRGBImage()). But 
> the Type of the returing BufferedImage is with the given Raster and 
> Colorspace always from Type "BufferedImage.TYPE_CUSTOM" instead of the 
> expected "BufferedImage.TYPE_INT_RGB" for example.
> Consequences:
> Image-Processing-Operations with/on BufferedImages with TYPE_CUSTOM are not 
> optimized in Java (slower) and partialy runs through "Synchronized" Blocks.
> ==> Converting different Documents in different Threads are blocking each 
> other.
> "Quick"-Fix for seeing a Performance-Improvement in a Multithreading 
> Environment:
> {code:title=PDDeviceRGB.java|borderStyle=solid}
> @Override
> public BufferedImage toRGBImage(WritableRaster raster) throws IOException {
>       init();
>       ColorModel colorModel = new ComponentColorModel(awtColorSpace, false, 
> false, Transparency.OPAQUE,
>                       raster.getDataBuffer().getDataType());
>       BufferedImage image = new BufferedImage(colorModel, raster, false, 
> null);
>       BufferedImage dest = new BufferedImage(image.getWidth(), 
> image.getHeight(), BufferedImage.TYPE_INT_RGB);
>       ColorConvertOp op = new 
> ColorConvertOp(dest.getColorModel().getColorSpace(), null);
>       return op.filter(image, dest);
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to