pixelated bitmaps on canvas and export with Cairo rendering

Bug #804162 reported by Guillermo Espertino (Gez) on 2011-07-01
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Krzysztof Kosinski
Fix Released

Bug Description

I just exported some artwork with several bitmap images and noticed that all of them ended up badly pixelated. It looks like the bitmap oversampling value set in preferences is being ignored completely, both for on-canvas rendering and exporting.
The interpolation quality used instead is so bad that makes it almost impossible to work with bitmap images at all.
This behavior started since the switch to Cairo rendering.

Inkscape 0.48+devel r10387
Ubuntu 11.04, 64 bit.

tags: added: bitmap cairo
removed: cairo-renderer
su_v (suv-lp) on 2011-07-01
tags: added: renderer-cairo
removed: cairo
su_v (suv-lp) wrote :

@Gez - I have added 'renderer-cairo' to the official tag list, based on the proposal here:

(most of the 'cairo' tagged reports are those actually invalid in Inkscape due to an upstream bug in cairo, or at least closely related to cairo itself - maybe requiring a code change in Inkscape to adapt to changes upstream).

su_v (suv-lp) on 2011-07-01
tags: added: regression
su_v (suv-lp) wrote :

> the bitmap oversampling value set in preferences is being ignored completely

Reproduced with Inkscape 0.48+devel r10392/10393 on Mac OS X 10.5.8 (i386)
Tested with both cairo 1.10.2 (GTK+/X11) and cairo 1.11.2 (GTK+/Quartz)

Changed in inkscape:
status: New → Confirmed
Krzysztof Kosinski (tweenk) wrote :

This problem is caused by the fact that Cairo does not include any real downscaling routines. Downscaling uses the interpolation routines for upscaling, which means that at most 4 pixels are considered regardless of the scale. I made an attempt to fix this some time ago, but my patch did not make it into the trunk.

I found lots of discussion, and many proposed solutions, and patches to this problem. It seems that many (mozilla, poppler, others?) using cairo (or pixman) is maintaing some patch that fixes the ugly downscaling output.

Related information for reference:

Confirmed on Inkscape r9886 (Ubuntu 12.04 using distribution's standard package

I just made a test case with a SVG including a 1920x1080 white & and black checkerboard pattern and attached it to this report.

To trigger the bug, export it to a 240x135 pixels bitmap and check output.
Correct : grey. Incorrect : white.

You can adjust bitmap oversample in settings, though it will also apply on-screen which may or may not be what you want.
In this exact case, setting it to 8x8 or 16x16 works around the problem.
See https://bugs.launchpad.net/inkscape/+bug/270909 which is related.

You have a workaround : export at high enough DPI and downsample afterwards using an external tool lile ImageMagick's convert (explained there), see bug 270909.

@gouri: The problem you're describing is a different one and it has nothing to do with this regression.
This bug affects only the current development versoin which uses cairo rendering.

I'm not sure if your bug is really a bug or a limitation of inkscape's oversampling with a small amount of samples (although my gut says that pixels aligned perfectly to the pixel grid shouldn't get blurred at all). Anyway, that report is about a different issue.
This is just about bitmap downscaling in Cairo.

@gouri: Now that I think about it, if you're exporting to any resolution except 90 dpi or one of its multiples, it's to be expected that oversampling will blur those pixels. And 2x2 and 4x4 could be insufficient for low resolutions.
If you didn't use 90 dpi or a multiple, it is NOT a bug.

To the rest, sorry for the noise.

ScislaC (scislac) on 2012-08-29
Changed in inkscape:
milestone: none → 0.49
jazzynico (jazzynico) on 2012-09-05
Changed in inkscape:
status: Confirmed → Triaged
ScislaC (scislac) on 2012-11-20
tags: added: blocker
Changed in cairo:
importance: Unknown → Medium
status: Unknown → Confirmed
Jaspervdg (jaspervdg) wrote :

Revision 12227 includes a "hack" that makes Inkscape handle downsampling of bitmaps, leaving all other transformations to Cairo. This is probably the best we can do for now. (Although the downsampling routine itself could be improved somewhat.) Note that this hack is only used for displaying "image" tags (at least, anything that is handled by src/display/drawing-image).

Tom Fields (udzelem) wrote :

Hi, Guys!

the upstream mozilla bug #486918 is marked "VERIFIED FIXED" now.

Is the upstream fix not applicable to this issue?

Krzysztof Kosinski (tweenk) wrote :

I sent an initial patch for Cairo to their mailing list.

Tavmjong Bah (tavmjong-free) wrote :

Jasper's hack and the proposed Cairo patch both seem to do the trick. There are, however, two issues with the results:

1. Up scaling results in blurred bitmaps. This seems to be what is required by the SVG 1.1 spec but is different from Inkscape 0.48 behavior. There is a proposal in CSS to add a flag to control how up scaling is done.

2. There is a question of what color space the filtering is being done in. Take the test file in #5 and display it at a scale of 100% and then compare the result when it is down scaled or up scaled. There is a definite perceived color shift.

Created attachment 78522
Downscaling patch

Pixman now implements convolutions, so this bug should be rather easy to fix. Here is an example patch.

su_v (suv-lp) wrote :

Follow-up reports (based by changes in r12227):
- Bug #1163449 “Imported bitmap appear blurry when zoomed in”
- Bug #1217752 "Extension Raster--> Wave is not working”

Krzysztof Kosinski (tweenk) wrote :

The Cairo fix is now in the trunk and will be part of the 1.14 release, due in October.

This patch has landed in trunk, and will be part of the next release.

Changed in cairo:
status: Confirmed → Fix Released
Martin Owens (doctormo) wrote :

I'm setting this to Fixed Committed, it's in trunk and in the trunk repository. Future builds and releases will be fixed.

Changed in inkscape:
status: Triaged → Fix Committed
Krzysztof Kosinski (tweenk) wrote :

Fix committed so removing blocker tag.

tags: removed: blocker
su_v (suv-lp) wrote :

Reopening for project 'Inkscape': upstream commit in cairo git master has been reverted.

See also:

Changed in inkscape:
status: Fix Committed → Triaged
tags: added: blocker

The patch had to be reverted.
See http://thread.gmane.org/gmane.comp.lib.cairo/24825/focus=24856

Another patch has been proposed and is under consideration:

Changed in cairo:
status: Fix Released → Confirmed

The aforementioned patch has landed; please re-test and share feedback here or on the mailing list.

I'm going to close this bug as fixed, assuming the new downscaling patch does the trick. If it does not, or if there are any concerns, please reopen this patch so further investigation can be done.

Changed in cairo:
status: Confirmed → Fix Released
ScislaC (scislac) on 2014-11-20
tags: removed: blocker
su_v (suv-lp) on 2015-02-23
Changed in inkscape:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.