Bug 22138 - [PATCH] Image quality worse compared to Adobe Reader
Summary: [PATCH] Image quality worse compared to Adobe Reader
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: splash backend (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
: 48513 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-06-07 09:21 UTC by Bernd Buschinski
Modified: 2013-03-17 09:20 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
above okular, under Adobe Reader image (54.80 KB, image/png)
2009-06-07 09:21 UTC, Bernd Buschinski
Details
pdf with formular, on page2 bottom (408.38 KB, application/pdf)
2009-06-07 09:24 UTC, Bernd Buschinski
Details
description of poppler (cairo)'s pitiful image rendering (107.15 KB, image/jpeg)
2009-11-10 08:17 UTC, Jud Craft
Details
Hotfix for Okular low-resolution image rendering problems (1.57 KB, application/octet-stream)
2012-04-11 20:39 UTC, Ulrich Lukas
Details
imagemagick patch (16.64 KB, patch)
2012-08-22 14:28 UTC, Stefan Talpalaru
Details | Splinter Review
the imagemagick rendering of Buschinski and Lukas' example pdfs (246.38 KB, image/png)
2012-08-22 14:30 UTC, Stefan Talpalaru
Details
imagemagick patch without gamma errors (21.56 KB, patch)
2012-08-27 21:45 UTC, Stefan Talpalaru
Details | Splinter Review
side by side comparison with gamma error example (701.39 KB, image/png)
2012-08-27 21:48 UTC, Stefan Talpalaru
Details
imagemagick patch without gamma errors (22.23 KB, patch)
2012-08-28 20:11 UTC, Stefan Talpalaru
Details | Splinter Review
Implement bilinear scaling (7.80 KB, patch)
2012-11-19 14:34 UTC, Adrian Johnson
Details | Splinter Review
Implement bilinear scaling (8.45 KB, patch)
2012-11-20 09:31 UTC, Adrian Johnson
Details | Splinter Review
Implement bilinear scaling using fixed point (8.71 KB, patch)
2012-11-20 09:38 UTC, Adrian Johnson
Details | Splinter Review
Page 7 of the file i wanted to attach since the whole file was too big (289.95 KB, application/pdf)
2012-11-21 21:39 UTC, Albert Astals Cid
Details
Implement bilinear image scaling in splash (13.97 KB, patch)
2012-11-22 12:31 UTC, Adrian Johnson
Details | Splinter Review

Description Bernd Buschinski 2009-06-07 09:21:11 UTC
Created attachment 26509 [details]
above okular, under Adobe Reader image

The Image quality is unreadable worse compared to Adobe Reader in some images

poppler-0.10.7
poppler-qt4-0.10.7

Image shows a formular as Image in pdf
Comment 1 Bernd Buschinski 2009-06-07 09:24:31 UTC
Created attachment 26510 [details]
pdf with formular, on page2 bottom
Comment 2 Ulrich Lukas 2009-06-12 15:54:56 UTC
Quoting the e-Mail I posted yesterday on poppler@lists.freedesktop.org:

I have several PDFs which consist of low-resolution scanned images.

These PDFs are rendered better and /much/ more readable in Adobe Reader
(e.g. Version 8.1.3) than in Okular or in other applications using
libpoppler version 0.10.5.

The reason appears to me to be a much better antialiasing technique in
Adobe Reader.


Once again, this report does NOT concern the rendering of fonts, but the
rendering of images!

I've uploaded an example file and a screenshot with explanations for you:

http://datenparkplatz.de/DiesUndDas/poppler.adobe.comparison.jpg
http://datenparkplatz.de/DiesUndDas/af2.pdf


I'm using Ubuntu Jaunty 9.04 AMD64.
Comment 3 Jud Craft 2009-11-10 08:15:19 UTC
This bug is genuinely a problem.  Tossing in my two cents.

Note that this is not anything special in Adobe - cairo just isn't doing any basic antialiasing at all.

Compare the image from Poppler-Evince to the same image (extracted from Evince's PDF) in the GNOME Image Viewer.
Comment 4 Jud Craft 2009-11-10 08:17:53 UTC
Created attachment 31093 [details]
description of poppler (cairo)'s pitiful image rendering

I apologize for using slides from class, but you can clearly see the image difference, even in JPG format - cairo's rendering is absolutely pitiful.

The lack of antialiasing means that many images aren't recognizable at all, even in fullscreen.
Comment 5 Albert Astals Cid 2009-11-10 11:46:16 UTC
Congratulatios Jud, you totally hijacked a but not related to your problem, do you feel a better person now?

If you are not absolutely sure the problem is the same always open a different bug, and yours is obviously a different problem since Bernd is complaining about the Splash backend output and you are complaining about the Cairo backend output.
Comment 6 Jud Craft 2009-11-18 19:22:01 UTC
I did not realize.  I truly apologize.

Please forgive me.  The bug description looked nearly exact; I assumed Okular and Evince ran on the same engine; I missed the "component" line above.  A newbie mistake.
Comment 7 Albert Astals Cid 2012-04-11 13:43:15 UTC
*** Bug 48513 has been marked as a duplicate of this bug. ***
Comment 8 Yuri 2012-04-11 13:46:57 UTC
https://bugs.freedesktop.org/show_bug.cgi?id=48513 has the testcase showing how text-as-image image quality in evince is worse compared to okular, even though both of them use poppler. Adobe actually produces even worse quality compared to okular/evince on this testcase.
Comment 9 Ulrich Lukas 2012-04-11 20:39:56 UTC
Created attachment 59827 [details]
Hotfix for Okular low-resolution image rendering problems
Comment 10 Albert Astals Cid 2012-04-12 00:07:51 UTC
Mr Lukas stop being useless.
Comment 11 Stefan Talpalaru 2012-08-17 18:27:03 UTC
How about switching from Bresenham to Lanczos for upscaling in splash/Splash.cc ?
scaleImageYdXu(), scaleImageYuXd() and scaleImageYuXu() could be replaced by a new scaleImageLanczos() function.
Comment 12 Albert Astals Cid 2012-08-17 22:55:11 UTC
Stefan: are you volunteering to do so?
Comment 13 Stefan Talpalaru 2012-08-22 14:28:09 UTC
Created attachment 65962 [details] [review]
imagemagick patch
Comment 14 Stefan Talpalaru 2012-08-22 14:30:22 UTC
Created attachment 65963 [details]
the imagemagick rendering of Buschinski and Lukas' example pdfs
Comment 15 Stefan Talpalaru 2012-08-22 14:46:17 UTC
My approach was to use imagemagick (actually Magick++, the C++ wrapper) to scale all the bitmaps.

the good:
- optional dependency
- popular library, usually installed by default
- good resizing for soft masked images (using the "sample" method that doesn't introduce new colors in order to avoid a black halo)
- excellent resizing for the rest of the images (using the "resize" method that defaults to the Lanczos filter for upsizing). Now it's finally possible to read PDFs with scanned book pages and comics in okular.

the bad:
- we're adding a new dependency
- the rendering is slower. 1.42 times slower in pdftoppm for Buschinski's Uebung_DBV_Bildverbesserung_090320.pdf on my machine.

the ugly:
- I'm using a PNG intermediary when converting from SplashBitmap to Magick::Image instead of a more straightforward conversion.
Comment 16 Albert Astals Cid 2012-08-22 21:04:10 UTC
Hmmm, i am not sure we want to add a dependency on ImageMagick in Splash

What do others think?
Comment 17 Thomas Freitag 2012-08-23 07:00:32 UTC
I personally don't like a dependency to imagemagick. But propably I don't have an open mind for imagemagick, I had some bad experiences with it a couple of years ago (nothing to do with raster image operations). But if it stays configurable and the default is "no", why not?
On the other hand I would prefer a splash internal solution. I.e. using nearest neighbour resampling for downscaling (I could provide that) and use a Lanczos filter for upsizing (I know the theory but have no clue how difficult it is to implement a performant algorithm). But because this hasn't a high priority for me and so I don't know when and if I have the time to do it, the imagemagick solution could be the way for those who look for a better quality right now.
Comment 18 Christoph 2012-08-27 17:59:10 UTC
Can you check if http://kdepepo.wordpress.com/2012/08/15/reverse-antialiasing-for-image-scaling/ is an option for upscaling? There is a test program linked from one of the comments. It can currently only double pixel size, but for any scaling factors != 2.0 it could be combined with bilinear interpolation.
Comment 19 Stefan Talpalaru 2012-08-27 21:45:05 UTC
Created attachment 66192 [details] [review]
imagemagick patch without gamma errors

Changes:
- ImageMagick support now disabled by default
- the gamma error associated with scaling has been corrected by doing the resize in a linear colorspace. Details:
http://www.4p8.com/eric.brasseur/gamma.html
http://www.imagemagick.org/Usage/resize/#resize_colorspace
- the intermediary PNG conversion was removed. SplashBitmap objects are converted to Magick::Image using the ImgWriter mechanism
- speed and memory usage improvements
Comment 20 Stefan Talpalaru 2012-08-27 21:48:44 UTC
Created attachment 66193 [details]
side by side comparison with gamma error example

This is a side by side comparison of the previous soft-masked formula and low-res page scan with an added test image with high contrast to show the effect of gamma errors during resize: http://eoimages.gsfc.nasa.gov/ve//1438/earth_lights_4800.tif
Comment 21 Stefan Talpalaru 2012-08-28 20:11:39 UTC
Created attachment 66245 [details] [review]
imagemagick patch without gamma errors

added the ImageMagick include dir to poppler.pc so cups-filters (which includes Splash.h) can be built against poppler with IM enabled
Comment 22 Albert Astals Cid 2012-11-18 23:30:03 UTC
I'm a bit confused by your implementation of MagickWriter::init, why aren't you using the FILE * anywhere?
Comment 23 Stefan Talpalaru 2012-11-18 23:51:16 UTC
Even though it inherits from ImgWriter, MagickWriter does not write to a file. Its only purpose is to facilitate the conversion to ImageMagick's data type for use in Splash::bitmapToMagickImage() :

  writer = new MagickWriter();
  src->writeImgFile(writer, NULL, 0, 0);
  *dst = ((MagickWriter*)writer)->image;

This is how I was able to use writeImgFile() instead of duplicating the bitmap type dependent logic for reading. The result is retrieved from the custom "image" member of the MagickWriter object.
Comment 24 Albert Astals Cid 2012-11-18 23:59:00 UTC
It is not acceptable to provide a class that doesn't do what it is expected to do. Please provide an alternate way of doing that.
Comment 25 Stefan Talpalaru 2012-11-19 00:04:29 UTC
It is not acceptable that you maintain code you don't understand. I give up trying to submit this patch.
Comment 26 Albert Astals Cid 2012-11-19 08:13:34 UTC
Really? Why? Because i told you your code needs to be improved? That's a really low threshold of collaboration and commenting you're taking, can you explain why so low?
Comment 27 Stefan Talpalaru 2012-11-19 12:34:41 UTC
Sure, Albert, I'll explain it. You need 3 months to start reading my patch. When you start reading it, you start asking questions that show you can't be bothered to finish reading or that you don't understand what you read.

That's OK, questions are not a problem, but you go on asking for modifications that further show your incompetence. At this point you destroy the fine balance between feeling good for contributing to the community and feeling frustrated because my effort is met with hostility and ignorance.

So no, I don't have any more time and patience to take shit from you. Keep your line algorithm for bitmap scaling, I already run patched versions of poppler on my computers.

For the future, please refrain from asking other potential contributors for patches when you obviously don't want them. You'd save everybody precious time with an honest "go away".
Comment 28 Albert Astals Cid 2012-11-19 13:51:37 UTC
This is simply (In reply to comment #27)
> Sure, Albert, I'll explain it. You need 3 months to start reading my patch.

Yes, and I am sorry that no one else takes responsability in the poppler community to review other people patches, given I do this on my free time I do stuff on an as fast as I can basis, that obviously is not enough, but unless we find the magial 30 hours a day it's the best I can do

> When you start reading it, you start asking questions that show you can't be
> bothered to finish reading or that you don't understand what you read.

I do understand what i read, i understand that you have implemented an ImgWriter that does not work as an ImgWriter and that's simply wrong.

And I won't bother answering the rest of personal insults.
Comment 29 Albert Astals Cid 2012-11-19 13:57:32 UTC
FWIW this was planned to be included in next poppler release as you can see in http://freedesktop.org/wiki/Software/poppler?rev=52 (by mistake i wrote the name of the guy that created the bug instead of yours) but since you are not interested in helping anymore I've removed it from the list freedesktop.org/wiki/Software/poppler
Comment 30 Adrian Johnson 2012-11-19 14:34:30 UTC
Created attachment 70258 [details] [review]
Implement bilinear scaling

Here's a proof of concept of implementing bilinear scaling in Splash::scaleImageYuXu. Testing with the two pdfs test cases in this bug shows a big improvement. The quality is about the same as the cairo output (which also uses bilinear scaling). Performance is slightly slower than before but the patch has plenty of scope for optimizing (such as moving the SplashMode switch to work on the source row).

If you are interested in this I can continue to work on it.
Comment 31 Albert Astals Cid 2012-11-19 21:18:02 UTC
Thanks for the patch Adrian, i'll try to have a look to squeeze it in before the 0.22 beta 2 this thursday.

Thomas, as Splash guru, can you give it a quick look too?
Comment 32 Adrian Johnson 2012-11-20 09:31:52 UTC
Created attachment 70301 [details] [review]
Implement bilinear scaling

Updated to fix a bug.
Comment 33 Adrian Johnson 2012-11-20 09:38:04 UTC
Created attachment 70302 [details] [review]
Implement bilinear scaling using fixed point

This version has been changed to used fixed point integers to see if I can make it faster. It barely made any difference. So take your pick on which version you prefer.
Comment 34 Thomas Freitag 2012-11-20 14:31:45 UTC
(In reply to comment #31)
> Thanks for the patch Adrian, i'll try to have a look to squeeze it in before
> the 0.22 beta 2 this thursday.
> 
> Thomas, as Splash guru, can you give it a quick look too?

I hadn't a look the algorithm itself and I didn't test the patch. You should see in Your regtest if it has the desired result. But what I can say is that it replaces the correct function: it is called only when there is an upscale in both dimensions (x and y), and hopefully here we get a better quality. So one hint for Your tests: You should render some PDF with images at least with 300 dpi. With 150 dpi this function in splash is seldom called, because most images inside Your PDF Suite have at least 150 dpi (as far as I remember).
And just to be complete: for downscaling an image it isn't necessary, there the Bresenham algorithm is well enough, so the patch should do what is expected.
So in my eyes the patch is okay!
Comment 35 Albert Astals Cid 2012-11-21 21:34:49 UTC
Had a look at a lot of files on the regtest and while most look better there are at least 3 that look much worse when rendered with -r200 on pdftoppm than without the patch, listing them here

altona_technical_1v2_x3.pdf columns 4 and 5 get all blurry, this does not happen in acroread neither in the cairo outputdev

http://bugsfiles.kde.org/attachment.cgi?id=12083 page 12, there is a blocky graph that also gets all blurry, this does not happen in acroread neither in the cairo outputdev

File_that_i_will_attach page 7 bottom left image gets "destroyed", this happpens a bit on both acroread and cairooutputdev, but not as massive

I'm concerned about them all, but http://bugsfiles.kde.org/attachment.cgi?id=12083 seems like the most important one since the clear data shown by the graph is lost.

Any idea how to fix this?
Comment 36 Albert Astals Cid 2012-11-21 21:39:27 UTC
Created attachment 70393 [details]
Page 7 of the file i wanted to attach since the whole file was too big
Comment 37 Adrian Johnson 2012-11-21 22:49:02 UTC
In cairo the function CairoOutputDev::getFilterForSurface selects between bilinear or nearest neighbour scaling depending on the interpolation flag and the scaling factor.

Fixing this should just be a case of putting the original spash code back (for nearest neighbour scaling) and adding a similar function to splash to switch select between my bilinear code or the splash nearest neighbour code.

Do you prefer using my floating point or fixed point patch?
Comment 38 Albert Astals Cid 2012-11-21 23:19:52 UTC
Floating point.

Fabio was having some problem with the fixed point (he told me gave him some glitches in a file)
Comment 39 Adrian Johnson 2012-11-22 12:31:21 UTC
Created attachment 70423 [details] [review]
Implement bilinear image scaling in splash

Here's the updated patch that switches between bilinear and nearest depending on the interpolate flag and scale factor.

This fixes the regression in altona_technical_1v2_x3.pdf and  http://bugsfiles.kde.org/attachment.cgi?id=12083.

I have not been able to figure out how to fix https://bugs.freedesktop.org/attachment.cgi?id=70393. It seems to be caused by an smask with a transfer function. The transfer function messes up the smooth interpolation introduced by the bilinear scaling. The output is very similar to acroread so I'm not really sure what else I can do.
Comment 40 William Bader 2012-11-23 01:59:15 UTC
re floating vs. fixed point, there might be a bigger difference on a tablet or netbook than on a laptop.
Comment 41 Albert Astals Cid 2012-11-30 20:32:24 UTC
Pushed!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.