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.
Created attachment 57381 [details]
Image resampled during the PDF export
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().
Created attachment 62054 [details]
Full backtrace for vcl::PDFWriterImpl::implWriteBitmapEx
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.
I and kendy changed the resampling method preferred in PDF export. Can you also send the document you've used to take the screenshots?
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.
Thanks, i am not on the office , vacation in Belgium :-)
i sea if i can find the image tomorow, and post it here
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
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.
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 !
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.
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ž
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ž
(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 email@example.com, start the subject line with [PATCH], and mentioning this bug and your patch.
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.
Tomaz Vajngerl committed a patch related to this issue.
It has been pushed to "master":
fdo#46378: Lanczos3 resampling of images added to Bitmap.
Marking as fixed now, we default to the Lanczos filter for PDF export now. This should be in the 3.6 Beta.
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)
By the way, there are also a bunch of samplers in GEGL. Gimp will use lohalo (low halo) instead of lanczos in the new GEGL based branch as far as I can see.
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.
maybe this link can help:
Migrating Whiteboard tags to Keywords: (EasyHack DifficultyInteresting SkillCpp )