Bug 46378 - Poor Resampling Image quality
Summary: Poor Resampling Image quality
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Printing and PDF export (show other bugs)
(earliest affected)
3.5.0 release
Hardware: Other All
: medium normal
Assignee: Not Assigned
QA Contact:
Whiteboard: target:3.6.0 SkillCG
Keywords: difficultyInteresting, easyHack, skillCpp
Depends on:
Reported: 2012-02-21 01:43 CET by Fernand
Modified: 2015-12-15 23:31 CET (History)
4 users (show)

See Also:
Crash report or crash signature:

Image resampled using Irfanview and Lanczos Filter (76.97 KB, image/pjpeg)
2012-02-21 01:43 CET, Fernand
Image resampled during the PDF export (92.65 KB, image/pjpeg)
2012-02-21 01:44 CET, Fernand
Full backtrace for vcl::PDFWriterImpl::implWriteBitmapEx (33.73 KB, text/plain)
2012-05-24 04:18 CEST, Gökçen Eraslan
Image to test the downsampling (2.06 MB, image/pjpeg)
2012-05-29 01:22 CEST, Fernand
Lanczos3 resampling of images added to Bitmap and enabled in PDF export (12.52 KB, patch)
2012-06-02 11:47 CEST, Tomaz Vajngerl

Note You need to log in before you can comment on or make changes to this bug.
Description Fernand 2012-02-21 01:43:28 CET
Created attachment 57380 [details]
Image resampled using Irfanview and Lanczos Filter

To reduce a important fatening size-factor ( images zoomed in by the user) We can use the max DPI settings. It works well, the images are reduced to the wanted pixels but we find  a poor resampling quality. To proof mi point is joined 2 images.
The LOresampling is the image we find  in the PDF when the origial image is resampled by 50%.. 
The LanczosResampling is  a resampling done, using Irfanview and the LanczosFilter who gives a far  better quality and a small reduction in file size.
I do not know what Resampling filter is uses by LO , in general all parts of LO , Writer and Draw are suffering the same quality loss due to the used Resampling Filter.
I do not know if Lanczos( who gives in general the best results) is confirm the LO lincencing ?
Thorsten told me that LibO uses bilinear interpolation, *without*
any band limiting beforehand.
Comment 1 Fernand 2012-02-21 01:44:49 CET
Created attachment 57381 [details]
Image resampled during the PDF export
Comment 2 Thorsten Behrens (CIB) 2012-02-22 01:10:45 CET
I think that's a nice localized change that suits as an EasyHack for someone with image processing know-how: downsampling code is in vcl/source/gdi/pdfwriter_impl2.cxx, method PDFWriterImpl::implWriteBitmapEx().
Comment 3 Gökçen Eraslan 2012-05-24 04:18:54 CEST
Created attachment 62054 [details]
Full backtrace for vcl::PDFWriterImpl::implWriteBitmapEx
Comment 4 Not Assigned 2012-05-28 00:02:02 CEST
Gökçen Eraslan committed a patch related to this issue.
It has been pushed to "master":


fdo#46378: Prefer interpolation-based image rescaling in PDF export.
Comment 5 Gökçen Eraslan 2012-05-28 00:38:19 CEST
Hi Fernand,

I and kendy changed the resampling method preferred in PDF export. Can you also send the document you've used to take the screenshots?
Comment 6 Jan Holesovsky 2012-05-28 00:54:01 CEST
Actually - enough when you test this yourself with tomorrows daily build from


Please reopen if it is still there, and in that case, please provide the source document as Gokcen indicated.
Comment 7 Fernand 2012-05-28 07:29:19 CEST

Thanks, i am not on the office , vacation in Belgium :-)

i sea if i can find the image tomorow, and post it here


Comment 8 Fernand 2012-05-29 01:22:17 CEST
Created attachment 62196 [details]
Image to test the downsampling

downsampkle this image to 99 ppi abnd compare the results with the Lancos filter
in Irfanview who gives good quality
Comment 9 Tomaz Vajngerl 2012-05-29 02:26:42 CEST

As I would like to start hacking in LibreOffice and I need to get familiar with the code I would like to implement Lanczos Resampling (BMP_SCALE_LANCZOS) in addition to BMP_SCALE_INTERPOLATE and BMP_SCALE_FAST. Lanczos resampling is currently the overall best choice for downsampling of images. 

I also found out that bad quality resampling is not only limited to PDF export but   also if you put a image in a LibreOffice Draw document and export as a PNG or JPEG so it also needs to be changed there. Maybe there are other cases that need to be addressed.

Best regards,
Comment 10 Fernand 2012-05-31 05:03:22 CEST
I tested on the latest LOdev 3.6.

There is no better quality, still comparable with the posted examples

Lanczos produces still far better quality !
Comment 11 Jan Holesovsky 2012-05-31 13:51:12 CEST
Fernand: The best if you can provide directly a .odf + what exactly one should provide in the PDF Export dialog to see the wrong downsampling, that would be best.  Thank you!

Tomaž: Oh - that would be great.  Please look into vcl/source/gdi/bitmap3.cxx, and take Bitmap::ImplScaleInterpolate() as an example to implement the Lanczos filter.  You'll also need to modify the related header, that is vcl/inc/vcl/bitmap.hxx.

As to where exactly to address the PNG / JPEG problem, I am not exactly sure; but probably best to run LO in debugger, and Ctrl+C during the export, and go up in the stack a bit to see where / what is happening there.
Comment 12 Tomaz Vajngerl 2012-06-01 03:16:58 CEST

I have already implemented Lanczos resampling but I need to test that the result is comparable to IrfanView. I will create a patch during weekend - with the resampling enabled only for PDF Export.

Lanczos resampling uses separable convolution which has many other uses like alternative methods of resampling like BiCubic, Mitchell, ... but differ only on the kernel function. In the second step I will also implement those resampling methods. 

With separable convolution it is also possible to implement filters like Gaussian blur (smooth filter) and unsharpen masking,... Because the processing is separable (horizontal and vertical 1D convolution), it is also faster than currently implemented Gaussian Blur which uses 2D convolution. So in the third step I will replace Gaussian Blur with separable Gaussian Blur and implement some additional filters.

Is it better to have for step 2 and 3 a new bugzilla entry or I should do everything under this bugzilla or what is your suggestion?

I was searching the source code and did not find where resampling is done in Export function. Looks like I will have to debug like you suggested to find the correct place. 

Best Regards, Tomaž
Comment 13 Tomaz Vajngerl 2012-06-02 11:47:25 CEST
Created attachment 62428 [details]
Lanczos3 resampling of images added to Bitmap and enabled in PDF export


I finished the implementation of Lanczos resampling. The patch is attached.
Currently the resampling is enabled only for PDF export.

Best regards, Tomaž
Comment 14 Korrawit Pruegsanusak 2012-06-03 10:46:18 CEST
(In reply to comment #13)
> The patch is attached.

Tomaz, thanks for the patch! but it is recommended [a little essential ;)] to write a mail to libreoffice@lists.freedesktop.org, start the subject line with [PATCH], and mentioning this bug and your patch.
Comment 15 Jan Holesovsky 2012-06-03 13:46:38 CEST
Tomaž: Great work, thank you so much! :-)  I (or somebody) will review your patch tomorrow, hopefully it will still make the feature freeze.

No need to create bug reports for things you implement, just send the patch to the mailing list as Korrawit indicated.  But if you prefer to have a tracking bug, do a separate entry for additional stuff.

Would be also great to see you on the IRC - irc.freenode.net, channel #libreoffice-dev [and sorry if you are already there, and I just missed you :-)] - I am 'kendy' there, please do ping me if the debugging method to find the export resampling does not work for you.
Comment 16 Not Assigned 2012-06-04 07:14:55 CEST
Tomaz Vajngerl committed a patch related to this issue.
It has been pushed to "master":


fdo#46378: Lanczos3 resampling of images added to Bitmap.
Comment 17 Jan Holesovsky 2012-06-05 08:34:10 CEST
Marking as fixed now, we default to the Lanczos filter for PDF export now.  This should be in the 3.6 Beta.
Comment 18 Fernand 2012-06-08 05:07:56 CEST
I tested with today's LOdev 7
Fine results compared to before, but when compared to Irfanview, there is still a small diference in overall quality Irfan is a bit more sharp, (maybe they do a sharpening in the same run) or Lancsoz can been tweeked to have this sharpness ?
Sharpess can also harm the quality, so its kind of a choise to make.
The number off unique colors can also been seen as a quality factor, here Irfan is also a bit better (9% more original colors) (85000-93000)
Hope it helps 

Test is made with the attached image, no tweeks on Irfan, just standard resampling (Lancsoz)
Comment 19 Gökçen Eraslan 2012-06-08 05:46:55 CEST
By the way, there are also a bunch of samplers in GEGL[1]. Gimp will use lohalo (low halo)[2] instead of lanczos in the new GEGL based branch as far as I can see[3].

[1] http://www.gegl.org/
[2] http://git.gnome.org/browse/gegl/tree/gegl/buffer/gegl-sampler-lohalo.c
[3] https://mail.gnome.org/archives/commits-list/2012-March/msg13995.html
Comment 20 Tomaz Vajngerl 2012-06-10 05:09:08 CEST
I know the image is not the same as in Irfanview. This is why I checked other programs: Imagemagick is very near to Irfanview, but with Gimp the image is even more sharp. I will try to find why I get a more blurred image but it may take some time, because there are other things I want to do - like speed up resampling so it can be used in the user interface.

lohalo is interesting - maybe if I find more about it I will try to implement it or even better to use GEGL (or any alternative) for Bitmap operations inside of LibreOffice instead.
Comment 21 Fernand 2012-06-11 01:05:05 CEST
maybe this link can help:

Comment 22 Robinson Tryon (qubit) 2015-12-15 23:31:01 CET
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyInteresting SkillCpp  )