Bug 694371 - pdfwrite doesn't handle 16 bpc images
Summary: pdfwrite doesn't handle 16 bpc images
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Writer (show other bugs)
Version: master
Hardware: All All
: P4 enhancement
Assignee: Ken Sharp
URL:
Keywords:
: 694964 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-06-24 19:42 UTC by Josh
Modified: 2014-07-23 08:52 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
image.pdf (7.17 KB, application/pdf)
2013-06-25 18:47 UTC, Josh
Details
signature.png (11.77 KB, image/png)
2013-06-25 18:47 UTC, Josh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Josh 2013-06-24 19:42:05 UTC
I'm trying to process a PDF with ghostscript 9.05 that contains an image.  The original PDF displays fine in Adobe Acrobat Reader 9 as well as Ubuntu's built in Document Viewer.

When running the file through Ghostscript I get:

       **** Warning: File encountered 'rangecheck' error while processing an image.
    Loading NimbusSanL-ReguItal font from /usr/share/fonts/type1/gsfonts/n019023l.pfb... 4342240 2931231 2721360 1395616 3 done.
    
       **** This file had errors that were repaired or ignored.
       **** The file was produced by: 
       **** >>>> Prawn <<<<
       **** Please notify the author of the software that produced this
       **** file that it does not conform to Adobe's published PDF
       **** specification.

The image is then removed from the output PDF.

I've tried to recreate this by creating other PDFs with an embedded image using Prawn, but have not been able to reproduce.

Is there some way to get ghostscript to autocorrect or fix issues like these?

The Prawn generated PDF:
https://s3.amazonaws.com/test-filestore/image.pdf

The image that is embedded:
https://s3.amazonaws.com/test-filestore/signature.png
Comment 1 Josh 2013-06-24 19:42:35 UTC
This happens with 9.05 and 9.07.  Same issue.
Comment 2 Hin-Tak Leung 2013-06-24 23:56:06 UTC
The file works fine with gs 9.06 on fedora (64-bit). Evince works too. xpdf shows a black box. The one thing interesting about the pdf seems to be that it has an RGB image with 16-bit per component.
Comment 3 Ken Sharp 2013-06-25 07:24:19 UTC
For future reference, *please* attach specimen files to the bug report rather than supplying a URL. It can sometimes be a while before we get round to looking at a problem, and the URL is often no longer valid. That can't happen if you attach the file.

Like Hin-Tak I am unable to reproduce a problem on Windows or Linux, 32 or 64 bits.

Given that you are working on Linux, and you haven't said where you got Ghostscript from) my suspicion is that your distribution is using shared libraries. This can be a problem as Ghostscript uses patched versions of some 3rd party libraries to fix problems we encounter. (we do supply these upstream but it can take some time for them to be adopted, and be reflected in OS distributions).

I'm assuming above that you didn't get Ghostscript binaries from our site:

http://www.ghostscript.com/download/gsdnld.html

I'd suggest that you download Ghostscript form there or if you are comfortable with building applications I would suggest you download the Ghostscript source code (either the released 9.07 or the current HEAD in Git), build that and try it. That code comes with all the third party libraries ready to build and includes them statically. I expect that will work for you.

Please let us know how you get on.
Comment 4 Josh 2013-06-25 18:46:46 UTC
I downloaded source and built it from http://www.ghostscript.com/download.  Still having the issue on Ubuntu 12.04.  

Here is the exact command I'm issuing:

./gs -o output.pdf -dPDFFitPage -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sDEVICE=pdfwrite image.pdf 

I've uploaded the files from s3 to this ticket directly.
Comment 5 Josh 2013-06-25 18:47:29 UTC
Created attachment 10018 [details]
image.pdf
Comment 6 Josh 2013-06-25 18:47:50 UTC
Created attachment 10019 [details]
signature.png
Comment 7 Hin-Tak Leung 2013-06-25 19:20:34 UTC
(In reply to comment #4)
...
> Here is the exact command I'm issuing:
> 
> ./gs -o output.pdf -dPDFFitPage -dDEVICEWIDTHPOINTS=612
> -dDEVICEHEIGHTPOINTS=792 -sDEVICE=pdfwrite image.pdf 
...

You could have saved us a bit of time if you had written that at the beginning. The problem is not the image, but pdfwrite. With png16m or pxlcolor (as well as x11 I tried, & window display).

The rangecheck is thrown by pdfwrite. This should be reassigned to the 'PDF Writer' component and goes to Ken.
Comment 8 Ken Sharp 2013-06-25 19:35:25 UTC
(In reply to comment #7)

> The rangecheck is thrown by pdfwrite. This should be reassigned to the 'PDF
> Writer' component and goes to Ken.

That's an easy one, pdfwrite doesn't support 16 bpc images at the moment, hence the rangecheck. I am part way through converting 16 to 8 for export, but not completed it yet.
Comment 9 Ken Sharp 2013-06-25 19:38:45 UTC
I thought we had an open bug for this already, but it seems not, so I modified this one to be a placeholder for it.

Eventually it'll get fixed as part of the colour work.
Comment 10 Ken Sharp 2014-01-21 01:33:53 UTC
*** Bug 694964 has been marked as a duplicate of this bug. ***
Comment 11 Ken Sharp 2014-06-10 05:35:17 UTC
commit baecaed381a6799e71c451933c3a1707f5653782 fixes this, provided the ColorConversionStrategy is 'LeaveColorUnchanged'
Comment 12 Josh 2014-07-22 21:22:18 UTC
I'm still having this issue with version 9.10 and 9.14 compiled on amd64 (ubuntu 12.04).  My command:  gs -o output.pdf -dPDFFitPage -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -sColorConversionStrategy='LeaveColorUnchanged' -sDEVICE=pdfwrite image.pdf

What am I doing wrong?  Also, I didn't know how to reopen this ticket, so I marked as awaiting review?

Thanks!
Comment 13 Ken Sharp 2014-07-23 00:12:57 UTC
(In reply to Josh from comment #12)
> I'm still having this issue with version 9.10 and 9.14 compiled on amd64
> (ubuntu 12.04).

Its in the latest code, it was added on June 10th according to the comments. So no, it won't be in 9.14 (or 9.10) because that was released prior to that date. The next release (9.15) is expected in September.


>  My command:  gs -o output.pdf -dPDFFitPage
> -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792
> -sColorConversionStrategy='LeaveColorUnchanged' -sDEVICE=pdfwrite image.pdf

You don't actually need to specify the colour conversion strategy as LeaveColorUnchanged, as that is the default. Using your command line and input file I get a PDF file which can be opened without complaint by Adobe Acrobat X and Ghostscript.

 
> What am I doing wrong?  

Did you recompile form the current source ? Are you sure you used the correct recompiled binary (I know, its obvious, but....) ? What is the SHA of the source you used ?
Comment 14 Josh 2014-07-23 08:52:55 UTC
Yes, you are correct.  I'll build from source and try again.

Thanks!