Resampling in HTML browsers

Bug 105932: Inline image scaling introduces ugly aliasing

As imaging technologies move from pixel sizing to physical (cm, pt, etc.) sizing, web browsers will need to resample images to the user's display resolution. We can no longer rely on all inline images being created at 96 dpi, stored at 96 dpi, sent over the wire at 96 dpi, and displayed at 96 dpi. We can't rely on Mozilla's current "nearest neighbor" scaling algorithm that introduces horrible aliasing artifacts because the ugly appearance of scaled images will discourage web site designers from using resolution-independent markup and stylesheets.

Steps to Reproduce

These steps always reproduce the problem in Mozilla build 2001101803 on Windows ME:

  1. Download and unzip the attached test case.
  2. From Mozilla, open aliasing.html
  3. Scroll down to the "Actual" images.

Actual results

In both quirks and standard mode, scaled images have ugly aliasing due to nearest-neighbor resampling. (This also happens in MS Internet Explorer 5.0, 5.5, and 6.0.)

Expected results

Scaled images have little aliasing.

Other notes

To reduce aliasing by 6 dB/octave, use bilinear interpolation instead of nearest neighbor resampling. If this poses a performance problem, make it a preference.

Bug 90813 covers the same problem with respect to text rather than inline images.

Scaling methods

This section demonstrates the operation of Mozilla's current image scaler.

This is a Original image at 16x16 pixels
This is a Actual result at 128x128 pixels (HTML)
This is a Approximation of Mozilla 0.9.5 actual result at 128x128 pixels (GIMP nearest-neighbor resampling)
This is a Expected result at 128x128 pixels (GIMP linear interpolation)

Aliasing is ugly

This section demonstrates more typical scaling ratios that occur when an image stored at 96 dpi is displayed at 72 dpi or at 120 dpi.

aliasing is ugly Original image at 64x64 pixels
aliasing is ugly Actual result at 32x32 pixels (HTML)
aliasing is ugly Expected result at 32x32 pixels (GIMP linear interpolation)
aliasing is ugly Actual result at 48x48 pixels (HTML)
aliasing is ugly Expected result at 48x48 pixels (GIMP linear interpolation)
aliasing is ugly Actual result at 80x80 pixels (HTML)
aliasing is ugly Expected result at 80x80 pixels (GIMP linear interpolation)
aliasing is ugly Actual result at 96x96 pixels (HTML)
aliasing is ugly Expected result at 96x96 pixels (GIMP linear interpolation)