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

Emmeran Seehuber commented on PDFBOX-4205:
------------------------------------------

[~cdokolas] I see, LosslessFactory.createFromGrayImage() does not care about 
the color profile of the gray image at all. PDDeviceGray.INSTANCE more or less 
means "whatever the PDF Reader likes as a Grayscale-Colorspace", as 
PDDeviceGray for a printer means "use the color values as the exact values for 
the amount of color to apply on the paper without transforming it future". And 
this is 100% device depending ...

As sRGB is/was the default for many monitors for a long time, this might not 
been seen as a problem. But nowadays most (better) monitors do some kind of 
color management and have colorspaces bigger than sRGB, and then you will also 
get this distortion on a monitor.

So it is no surprise that the gamut curve is wrong... (i.e. the different gray 
tones).

So there are two problems:
 * getRGB() is used to get the color values in sRGB. which causes color 
transformation to sRGB and some potential color loss.
 * PDDeviceGray is used as profile. If getRGB() is used it should be exported 
as sRGB with embedded sRGB Profile - which also means that you need all three 
color channels... Using sRGB but exporting as PDDeviceGray is more or less a 
doomed to shift the gamut curve, i.e. making wrong gray tones.

So getting this right is not so easy. I already struggled with this while 
implementing PDFBOX-4341.

> LosslessFactory alters image
> ----------------------------
>
>                 Key: PDFBOX-4205
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4205
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.7, 2.0.8, 2.0.9
>         Environment: Ubuntu 16.04
>            Reporter: Harry Dent
>            Priority: Minor
>         Attachments: image-2020-02-24-17-59-08-300.png, lossy.png, 
> picture_of_text.png
>
>
> The attached grayscale png becomes lighter when run through the following 
> code snippet: 
> {code:java}
> BufferedImage image = ImageIO.read(new File("picture_of_text.png"));
> PDImageXObject xObject = LosslessFactory.createFromImage(new PDDocument(), 
> image);
> BufferedImage lossy = xObject.getImage();
> ImageIO.write(lossy, "png", new File("lossy.png"));
> {code}
> The difference is easiest to spot by looking at the "S" in "41st". The loss 
> in quality occurs in {{createFromImage()}} (rather than {{getImage()}}), 
> which can be shown by embedding the {{PDImageXObject}} into a {{PDDocument}} 
> and then saving this document to a file. 
>  
>  



--
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