Bug 690997 - loosing quality of images with ps2pdf
Summary: loosing quality of images with ps2pdf
Status: RESOLVED WORKSFORME
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 7.21
Hardware: PC Linux
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-14 16:34 UTC by Werner Meyer
Modified: 2009-12-16 09:18 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
ps-file (1.21 MB, application/postscript)
2009-12-15 13:28 UTC, Werner Meyer
Details
quality-loss (ps2pdf without options) (291.49 KB, application/pdf)
2009-12-15 13:30 UTC, Werner Meyer
Details
good quality but differences? large file, ps2pdf with many options (4.41 MB, application/pdf)
2009-12-15 13:31 UTC, Werner Meyer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Werner Meyer 2009-12-14 16:34:57 UTC
Please add to the ps2pdf-manpage a hint how to obtain images in the pdf in the
same quality as they were in the ps-file.

I didn't find it out neither in the man-page nor somewhere else (including the
worldwide web!)

Well - maybe I'm to foolish otr my english is to bad, but please just give a
hint (and/or set the default to not loose quality of images converting ps to pdf).

I'm very disappointed about the fact, that the images in the pdf I get via 
# ps2pdf file.ps
in the resulting file.pdf are of bad quality, while they were of good quality
before.
Comment 1 Alex Cherepanov 2009-12-14 16:54:39 UTC
Please try

ps2pdf -dDownsampleColorImages#false -dDownsampleGrayImages#false
-dDownsampleMonoImages#false  FILE.PS FILE.PDF

All these parameters are documented in doc/ps2pdf.htm in your Ghostscript
package.
Comment 2 Hin-Tak Leung 2009-12-14 20:29:28 UTC
According to the documentation, Downsample*Images are false by default... In any
case, I use 
  -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \
 -dPDFsettings=/prepress
where I want to preserve image quality. You may want to add the Gray equivalent
of those two filter options as well. As Alex wrote, all these options are
documented in doc/ps2pdf.htm .
Comment 3 Werner Meyer 2009-12-15 06:35:03 UTC
OK - in /usr/share/doc/packages/ghostscript-library/doc/Ps2pdf.htm there is
written something about it (in the man-page unfortunately not).
But my english is to bad to understand this all.

I tried

ps2pdf -dDownsampleColorImages#false -dDownsampleGrayImages#false
-dDownsampleMonoImages#false

but this was not a solution. Same result as before. The pictures lost much
quality (seems to be strongly compressed jpg). (pdf has a fourth of the size of
the ps)



So I tried 

ps2pdf -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode
-dPDFsettings=/prepress

The pictures are much better, the pdf has three and a half the size of the ps.

But I wonder about the fact, that the images aren't identical. They don't loose
so much of quality, but they differ a little bit.

I don't understand this. 

Isn't it possible, to leave them absolutely as they are?
Comment 4 Hin-Tak Leung 2009-12-15 11:25:51 UTC
Try putting all the options in (and have the prepress switch up front) - "#" is
the same as "=" :

ps2pdf -dPDFsettings=/prepress \
-dDownsampleColorImages#false -dDownsampleGrayImages#false \
-dDownsampleMonoImages#false \
 -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode \
 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode \
file.ps

The difference you see is also likely due to difference in viewer
characteristics, not ps2pdf. Presumably you are using gsview/ghostview/gv/ggv
for ps and acroread/xpdf/evine/okular/kpdf for pdf's. Also, if the version 7.21
is true, you are using a fairly old version of ghostscript.

Feel free to look at Ps2pdf.htm and add more options to experiment. You saw how
the options are used in the above command line.
Comment 5 Hin-Tak Leung 2009-12-15 11:27:02 UTC
If you need any further help, attaching the file you try to process to the bug
report would be a good idea. (you can mark it as private if desired).
Comment 6 Werner Meyer 2009-12-15 13:25:43 UTC
The proposed options seem to take the same effect as the former. 1,2MB ps gets
4,4 MB pdf. 

I followed the differences in appearence in okular for both - ps and pdf (don't
know, what okular uses to show ps).

If the pictures really are the same, only otherwise displayed, its OK.
I'll make attachements.

btw
ps2pdf is maybe 8.64 (comes with opensuse11.2) - the man-page sayd 7.21, the
doc...htm says 8.64
 
Comment 7 Werner Meyer 2009-12-15 13:28:18 UTC
Created attachment 5780 [details]
ps-file
Comment 8 Werner Meyer 2009-12-15 13:30:05 UTC
Created attachment 5781 [details]
quality-loss (ps2pdf without options)
Comment 9 Werner Meyer 2009-12-15 13:31:40 UTC
Created attachment 5782 [details]
good quality but differences? large file, ps2pdf with many options
Comment 10 Hin-Tak Leung 2009-12-15 17:08:12 UTC
(Correct the version - the reporter is using v8.64, not 7.21)

The image processing in the two files are working as by design. The original ps
file has 5 figures, 4 small ones run-length-encoded, and 1 big jpeg at
2048x1536, and scaled and shrinked to embed in the document. The difference in
file size is entirely due to how the large jpeg is treated, whether to
down-sample to match its size on page and/or write it back with a non-lossy
compression. Down-sample + DCTDecode gives 224013 bytes and don't-down-sample +
FlateDecode gives 4482132 bytes.

The man-page contains:

"SEE ALSO
    Ps2pdf.htm in the Ghostscript documentation"

and all the switches/behaviors are as documented in Ps2pdf.htm .
Comment 11 Werner Meyer 2009-12-16 09:05:17 UTC
Only for my interest (I just don't understand it): why is the pdf with
non-loss-compressed image larger than the ps-file, from which its generated?
It cannot contain mor information than the ps...

Thanks for explaining (which not really belongs to a bugzilla...).
Comment 12 Ken Sharp 2009-12-16 09:18:11 UTC
The original image is a JPEG, the final image is a straight bitmap which is
flate (Zip) encoded for compression.

JPEG is a more efficient encoding scheme, so its smaller. 

However because the original JPEG is expanded out to a full resolution image
before being written to a PDF file, if we wrote back a JPEG then the result
would contain obvious JPEG compression artefacts (applying lossy compression to
an image which was the result of decompressing a lossy compression). 

Just like any other time you read/modify/save a JPEG file.

So that's a bad idea, and you should stick with Flate.