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

Tilman Hausherr commented on PDFBOX-4831:
-----------------------------------------

Please change the segment in PageDrawer.java to this:
{code}
            Matrix xformMatrix = new Matrix(xform);
            boolean isScaledUp = bim.getWidth() <= 
Math.round(ctm.getScalingFactorX() * xformMatrix.getScalingFactorX()) ||
                                 bim.getHeight() <= 
Math.round(ctm.getScalingFactorY() * xformMatrix.getScalingFactorY());
{code}
This takes two of your suggestions and also considers rotations.

When rendering your file at 300 dpi {{isScaledUp}} is now true, and the number 
of unique colors changes from 4 to 2, and the rendering gets faster, so I guess 
that's what you wanted.

However the rendering of a lot of files changes, sometimes worse. But it looks 
closer to Adobe Reader. A good example is gs-bugzilla688728.pdf, where the new 
rendering is now the same as in Adobe. An example for "worse" is 
K_UPMEYER_SPRING10.pdf, the image at the lower right of page 1, or 
outside-in.pdf the "MARKET NOTE" top right. (But Adobe is also bad there).

(Files mentioned are available by googling, if not, mention them and I'll 
upload them)

> Rounding errors when rendering non-interleaved binary CCITT image at 1:1 
> scale cause gray pixels in output
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4831
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4831
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.19
>            Reporter: Gábor Stefanik
>            Priority: Major
>         Attachments: 13._Korona_szallo_vegzes_13.09.26.eredeti-1.png, 
> 13._Korona_szallo_vegzes_13.09.26.eredeti.pdf
>
>
> I have a 300dpi scanned PDF file with a single CCITT-encoded black-and-white 
> image in each page, spanning the whole page. The images all have a resolution 
> of 2480x3504.
>  
> When I try to render a page from this PDF into a PNG at 300DPI, the resulting 
> PNG has some pixels with colors #010101 and #fefefe. The PNG has the same 
> 2480x3504 dimensions as the embedded CCITT images, but stepping through the 
> PDFBox code reveals it's trying to downscale the image by a tiny fraction of 
> a pixel (e.g. to 2479.999964573x3503.9999537378) using bicubic interpolation, 
> introducing these "near-black" and "near-white" pixels due to rounding 
> errors. Additionally, the actual image conversion code goes to a slow path 
> intended for "proper" interpolated scaling, rather than hitting the fast path 
> for copying 1:1-scale images.
>  
> For now, we worked around this by treating images containing only #000000, 
> #010101, #fefefe and #ffffff as binary, but the performance hit from the slow 
> path is still there.



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