Tentative patch for downscaling in Cairo
Hello
I had a look at how complex would it be to add correct downscaling to Cairo now that Pixman supports convolution filters. It turns out it this is rather easy. Here is an initial, minimal attempt. It uses convolution filters only if the image is being downscaled by more than half a pixel in at least one dimension.
Some discussion:
1. The sampling and reconstruction kernels are picked in a way that gives comparable quality when upscaling and downscaling. I paired box sampling with bilinear reconstruction and impulse (point) sampling with box reconstruction. This gives the expected result for NEAREST filter. BEST filter uses Lanczos3 for both kernels.
2. Subsampling bits are always set to 1, since this doesn't seem to affect quality at all.
3. I am not sure whether this code works correctly for matrices with a skew component. It should be OK for any combination of scale, rotation and translation.
4. This patch causes new failures in the test suite: - recording-surface*: possibly an effect of improved quality. - surface-pattern-scale-down*, surface-pattern-big-scale-down: the reference images should be updated. - pthread-same-source: I have no idea why this is failing, since this test shouldn't even trigger the new code. - large-source-roi: this test attempts to downscale an image which is 30000 pixels wide down to 7 pixels. The filter parameters seem to be created correctly, but they might trigger an overflow somewhere in the convolution code; the output rectangle is white instead of red, as if nothing was drawn. - device-offset-scale: there are subtle differences which look like convolution-related smoothing; I'm not sure whether this is OK or not.
Note that master currently fails many more tests, I only listed new failures cause by this patch.
Regards, Krzysztof Kosiński
On 31-3-2013 5:03, Krzysztof Kosiński wrote:
Hello
I had a look at how complex would it be to add correct downscaling to Cairo now that Pixman supports convolution filters. It turns out it this is rather easy. Here is an initial, minimal attempt. It uses convolution filters only if the image is being downscaled by more than half a pixel in at least one dimension.
Hi all, The current version of Cairo in devlibs is 1.11.2. How much trouble is it to upgrade this to 1.12.x, or do we want to wait for a cairo release with our bugs fixed? Upgrading now would fix a very long standing export bug: https://bugs.launchpad.net/inkscape/+bug/759154.
Thanks, Johan
Hi Inkscapers,
De : Johan Engelen <jbc.engelen@...2592...> The current version of Cairo in devlibs is 1.11.2. How much trouble is it to upgrade this to 1.12.x, or do we want to wait for a cairo release with our bugs fixed? Upgrading now would fix a very long standing export bug: https://bugs.launchpad.net/inkscape/+bug/759154.
I recently managed to build 1.12.8 on Windows XP without any problem, but didn't commit it to the devlibs because I wasn't sure there were no regressions. Tests with 1.12.14 are in progress. If there's no objection, I can commit it when it's done, or wait until the downscaling patch is accepted.
Regards, -- Nicolas
De : Nicolas Dufour <nicoduf@...48...>
De : Johan Engelen <jbc.engelen@...2592...> The current version of Cairo in devlibs is 1.11.2. How much trouble is it to upgrade this to 1.12.x, or do we want to wait for a cairo release with our bugs fixed? Upgrading now would fix a very long standing export bug: https://bugs.launchpad.net/inkscape/+bug/759154.
I recently managed to build 1.12.8 on Windows XP without any problem, but didn't commit it to the devlibs because I wasn't sure there were no regressions. Tests with 1.12.14 are in progress. If there's no objection, I can commit it when it's done, or wait until the downscaling patch is accepted.
Test version for win32 (trunk revision 12262 with Cairo-1.12.14 and Pixmal-0.28.2) available here: ftp://download.tuxfamily.org/inkscape/
Regards, -- Nicolas
On 2-4-2013 16:01, Nicolas Dufour wrote:
De : Nicolas Dufour <nicoduf@...48...>
De : Johan Engelen <jbc.engelen@...2592...> The current version of Cairo in devlibs is 1.11.2. How much trouble is it to upgrade this to 1.12.x, or do we want to wait for a cairo release with our bugs fixed? Upgrading now would fix a very long standing export bug: https://bugs.launchpad.net/inkscape/+bug/759154.
I recently managed to build 1.12.8 on Windows XP without any problem, but didn't commit it to the devlibs because I wasn't sure there were no regressions. Tests with 1.12.14 are in progress. If there's no objection, I can commit it when it's done, or wait until the downscaling patch is accepted.
Test version for win32 (trunk revision 12262 with Cairo-1.12.14 and Pixmal-0.28.2) available here: ftp://download.tuxfamily.org/inkscape/
It works fine for me (not a whole lot of testing). I'm ok with committing it to devlibs. Why not :) worst thing that happens is we have to revert it :)
Thanks for the good work, Cheers, Johan
El 05/04/13 18:45, Johan Engelen escribió:
On 2-4-2013 16:01, Nicolas Dufour wrote:
De : Nicolas Dufour<nicoduf@...48...>
De : Johan Engelen<jbc.engelen@...2592...> The current version of Cairo in devlibs is 1.11.2. How much trouble is it to upgrade this to 1.12.x, or do we want to wait for a cairo release with our bugs fixed? Upgrading now would fix a very long standing export bug: https://bugs.launchpad.net/inkscape/+bug/759154.
I recently managed to build 1.12.8 on Windows XP without any problem, but didn't commit it to the devlibs because I wasn't sure there were no regressions. Tests with 1.12.14 are in progress. If there's no objection, I can commit it when it's done, or wait until the downscaling patch is accepted.
Test version for win32 (trunk revision 12262 with Cairo-1.12.14 and Pixmal-0.28.2) available here: ftp://download.tuxfamily.org/inkscape/
It works fine for me (not a whole lot of testing). I'm ok with committing it to devlibs. Why not :) worst thing that happens is we have to revert it :)
I've been playing with the development version and I noticed that there is some interpolation in downscaling, but it's rather slow and maybe too "smooth" compared to the one in current inkscape stable. Bitmap dowscaling in stable looks sharper and more consistent, downscaling in trunk is too blurry and it seems that it produces different qualities depending on the scaling.
Is that the downscaling patch discussed in this thread? If it is, I'm afraid it's still not acceptable for quality work.
Gez.
2013/6/30 Guillermo Espertino (Gez) <gespertino@...400...>:
I've been playing with the development version and I noticed that there is some interpolation in downscaling, but it's rather slow and maybe too "smooth" compared to the one in current inkscape stable. Bitmap dowscaling in stable looks sharper and more consistent, downscaling in trunk is too blurry and it seems that it produces different qualities depending on the scaling.
Is that the downscaling patch discussed in this thread? If it is, I'm afraid it's still not acceptable for quality work.
No. The patch is about adding scaling directly into Cairo, using convolution filters recently added to Pixman. These filters are correct from the point of view of signal processing and correctly downscale even pathological images, such as zone plates. The dev version of Inkscape uses its own scaling routine before using Cairo to do the non-scaling part - probably it's not good enough.
The stable version does not actually downscale anything at all - it always samples 4 points per pixel. and uses bicubic interpolation. This means that at high downscaling factors most pixels are ignored.
Regards, Krzysztof
El 30/06/13 17:10, Krzysztof Kosiński escribió:
Is that the downscaling patch discussed in this thread? If it is, I'm afraid it's still not acceptable for quality work.
No. The patch is about adding scaling directly into Cairo, using convolution filters recently added to Pixman. These filters are correct from the point of view of signal processing and correctly downscale even pathological images, such as zone plates. The dev version of Inkscape uses its own scaling routine before using Cairo to do the non-scaling part - probably it's not good enough.
Thanks Krzysztof for clarifying this.
The stable version does not actually downscale anything at all - it always samples 4 points per pixel. and uses bicubic interpolation. This means that at high downscaling factors most pixels are ignored.
Well, what stable does looks in my oppinion pretty decent, and it's fast too. I find it adequate for my needs because it produces sharp results and images with logos or text looks crisp when downsized. Some people may argue that the results are too sharp, but I think it's pretty good for most of the common cases (I guess it's not enough for some edge cases, though).
I'm curious about this new downscaling method in cairo and how it compares to the current downscaling method in terms of sharpness and speed. Are there any sample images of the result?
Kind regards, Gez.
2013/6/30 Guillermo Espertino (Gez) <gespertino@...400...>:
El 30/06/13 17:10, Krzysztof Kosiński escribió:
Is that the downscaling patch discussed in this thread? If it is, I'm afraid it's still not acceptable for quality work.
No. The patch is about adding scaling directly into Cairo, using convolution filters recently added to Pixman. These filters are correct from the point of view of signal processing and correctly downscale even pathological images, such as zone plates. The dev version of Inkscape uses its own scaling routine before using Cairo to do the non-scaling part - probably it's not good enough.
Thanks Krzysztof for clarifying this.
The stable version does not actually downscale anything at all - it always samples 4 points per pixel. and uses bicubic interpolation. This means that at high downscaling factors most pixels are ignored.
Well, what stable does looks in my oppinion pretty decent, and it's fast too. I find it adequate for my needs because it produces sharp results and images with logos or text looks crisp when downsized. Some people may argue that the results are too sharp, but I think it's pretty good for most of the common cases (I guess it's not enough for some edge cases, though).
I'm curious about this new downscaling method in cairo and how it compares to the current downscaling method in terms of sharpness and speed. Are there any sample images of the result?
There is a demo called "scale" in Pixman sources where you can load an image file and look at the results of various options. I'm attaching a screenshot of a zone plate downscaled with the best-performing filter. Note that this filter is likely not suitable for Inkscape except perhaps for export, because it's rather slow to compute.
Regards, Krzysztof
2013/6/30 Krzysztof Kosiński <tweenk.pl@...400...>:
There is a demo called "scale" in Pixman sources where you can load an image file and look at the results of various options. I'm attaching a screenshot of a zone plate downscaled with the best-performing filter. Note that this filter is likely not suitable for Inkscape except perhaps for export, because it's rather slow to compute.
Of course, I forgot the file :) Regards, Krzysztof
Seems like the screenshot is too big. Here's an uploaded copy: http://osch.chem.uw.edu.pl/scale-test.png
Regards, Krzysztof
participants (4)
-
Guillermo Espertino (Gez)
-
Johan Engelen
-
Krzysztof Kosiński
-
Nicolas Dufour