pixelated bitmaps on canvas and export with Cairo rendering

Bug #804162 reported by Guillermo Espertino (Gez)
18
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Inkscape
Fix Released
High
Krzysztof Kosinski
cairo
Fix Released
Medium

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.

Revision history for this message
Guillermo Espertino (Gez) (gespertino-gmail) wrote :
tags: added: bitmap cairo
removed: cairo-renderer
su_v (suv-lp)
tags: added: renderer-cairo
removed: cairo
Revision history for this message
su_v (suv-lp) wrote :

@Gez - I have added 'renderer-cairo' to the official tag list, based on the proposal here:
<http://article.gmane.org/gmane.comp.graphics.inkscape.devel/36697>

(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)
tags: added: regression
Revision history for this message
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
Revision history for this message
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.

Revision history for this message
In , Dusan Maliarik (dusan-maliarik) wrote :

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:
https://bugzilla.mozilla.org/show_bug.cgi?id=486918
http://lists.cairographics.org/archives/cairo/2009-July/017637.html
http://lists.cairographics.org/archives/cairo/2009-November/018561.html
http://lists.freedesktop.org/archives/cairo/2011-July/022142.html

Revision history for this message
Stéphane Gourichon (stephane-gourichon-lpad) wrote :

Confirmed on Inkscape 0.48.3.1 r9886 (Ubuntu 12.04 using distribution's standard package 0.48.3.1-1ubuntu1).

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.

Revision history for this message
Guillermo Espertino (Gez) (gespertino-gmail) wrote :

@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.

Revision history for this message
Guillermo Espertino (Gez) (gespertino-gmail) wrote :

@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)
Changed in inkscape:
milestone: none → 0.49
jazzynico (jazzynico)
Changed in inkscape:
status: Confirmed → Triaged
ScislaC (scislac)
tags: added: blocker
Changed in cairo:
importance: Unknown → Medium
status: Unknown → Confirmed
Revision history for this message
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).

Revision history for this message
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?

Revision history for this message
Krzysztof Kosinski (tweenk) wrote :

I sent an initial patch for Cairo to their mailing list.
http://lists.cairographics.org/archives/cairo/2013-March/024196.html

Revision history for this message
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.

Revision history for this message
Tavmjong Bah (tavmjong-free) wrote :
Revision history for this message
In , Krzysztof Kosinski (tweenk) wrote :

Created attachment 78522
Downscaling patch

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

Revision history for this message
su_v (suv-lp) wrote :

Follow-up reports (based by changes in r12227):
- Bug #1163449 “Imported bitmap appear blurry when zoomed in”
  <https://bugs.launchpad.net/inkscape/+bug/1163449>
- Bug #1217752 "Extension Raster--> Wave is not working”
  <https://bugs.launchpad.net/inkscape/+bug/1217752>

Revision history for this message
Krzysztof Kosinski (tweenk) wrote :

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

Revision history for this message
In , B-harrington (b-harrington) wrote :

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

Changed in cairo:
status: Confirmed → Fix Released
Revision history for this message
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
Revision history for this message
Krzysztof Kosinski (tweenk) wrote :

Fix committed so removing blocker tag.

tags: removed: blocker
Revision history for this message
su_v (suv-lp) wrote :

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

See also:
<http://thread.gmane.org/gmane.comp.lib.cairo/24825/focus=24856>
<http://cgit.freedesktop.org/cairo/commit/?id=3d94269bd427304af70ae681d5533b572d19ec3c>

Changed in inkscape:
status: Fix Committed → Triaged
tags: added: blocker
Revision history for this message
In , B-harrington (b-harrington) wrote :

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:
http://thread.gmane.org/gmane.comp.lib.cairo/24870

Changed in cairo:
status: Fix Released → Confirmed
Revision history for this message
In , B-harrington (b-harrington) wrote :

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

Revision history for this message
In , B-harrington (b-harrington) wrote :

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)
tags: removed: blocker
su_v (suv-lp)
Changed in inkscape:
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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