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

Tilman Hausherr commented on PDFBOX-5464:
-----------------------------------------

I suspect that something is wrong in PDSeparation.toRGBImage(WritableRaster 
raster). The JPEG image itself is OK, it is a grey jpeg with a separation 
colorspace.
The separation colorspace seems OK when displayed in PDFDebugger (blue). That 
separation colorspace has a an ICC colorspace as alternate colorspace, but that 
ICC colorspace is a LAB space.
Some of the values returned by tintTransform() are negative, and/or larger than 
255, which is unusual, and I don't know if these values are properly stored in 
"altRaster".

I was able to get it to work by using toRGB(). But this is only a proof of 
concept, I don't know what's wrong.
{code}
    public BufferedImage toRGBImage(WritableRaster raster) throws IOException
    {
        if (alternateColorSpace instanceof PDLab)
        {
            // PDFBOX-3622 - regular converter fails for Lab colorspaces
            return toRGBImage2(raster);
        }
        
        int width = raster.getWidth();
        int height = raster.getHeight();
        float[] samples = new float[1];
        
        BufferedImage bim = new BufferedImage(raster.getWidth(), 
raster.getHeight(), BufferedImage.TYPE_INT_RGB);
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                raster.getPixel(x, y, samples);
                samples[0] /= 255.0;
                float[] toRGB = toRGB(samples);
                bim.setRGB(x, y, ((int) (toRGB[0] * 255)) << 16 | ((int) 
(toRGB[1] * 255)) << 8 | ((int) (toRGB[2] * 255)));
            }
        }
        
        return bim;
    }
{code}


> White areas are rendered red when converting a pdf to png with pdfbox
> ---------------------------------------------------------------------
>
>                 Key: PDFBOX-5464
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5464
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.26, 3.0.0 PDFBox
>            Reporter: Kirovj
>            Priority: Major
>         Attachments: err1-1.png, err1-2.png, err1-3.png, err1.pdf
>
>
> hi
> This may be a problem similar to PDFBOX-4470 Red areas around text when 
> converting a pdf to png with pdfbox - ASF JIRA (apache.org)
> When I convert a pdf to png files with pdfbox, I find that the backgroud 
> White color was rendered as Red. And this is unusual, I have only one pdf 
> rendered like this. But in this pdf, almost all pages are rendered as Red 
> color.
> Here's some of the code that I'm using:
> {code:java}
> try (PDDocument document = PDDocument.load(new File("example/" + file + 
> ".pdf"))) {
>     int numberOfPages = document.getNumberOfPages();
>     PDFRenderer renderer = new PDFRenderer(document);
>     for (int i = 0; i < numberOfPages; i++) {
>         System.out.println("render " + i);
>         BufferedImage bufferedImage = renderer.renderImage(i, 2, 
> ImageType.RGB);
>         ImageIO.write(bufferedImage, "png", new File("example/" + file + "-" 
> + i + ".png"));
>     }
> } {code}
> I also tried pdfbox 3.0.0-RC1, but result is the same.
> The red png files start at pdf page 3.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

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

Reply via email to