[Bug 10799] drawImage/pattern filters underspecified

http://www.w3.org/Bugs/Public/show_bug.cgi?id=10799

--- Comment #2 from Philip Taylor <excors@gmail.com> 2010-09-30 22:32:57 UTC ---
Hmm, I'm assuming this is something that can resolved without having to change
the spec's basic assumption that it's drawing to an infinitely precise buffer
(which is why it doesn't talk about antialiasing or rounding etc). Even with
infinitely precise output, it matters how you compute each point from the
low-resolution input image, so it seems a useful thing to specify.

It sounds like perhaps the desired behaviour is for the computation of the
sampled colour at (possibly non-integer) position (x, y) on a w*h bitmap image
to be something like (in random pseudocode since it helps me think about this):

  filtered(x, y, clamped) =
    if not (0.0 <= x <= w and 0.0 <= y <= h)
      return transparent black
    else
      compute filtered value at (x, y) (using standard bilinear interpolation
or nearest neighbour or whatever), such that whenever the filtering algorithm
chooses to sample the image at pixel index (ix, iy):

        if clamped: clamp ix to (0 .. w-1), iy to (0 .. h-1);
    else: wrap ix to (0 .. w-1), iy to (0 .. h-1);

        then return the pixel at the new (ix, iy).

  drawimage(x, y) =
    if not (sx <= x <= sx+sw and sy <= y <= sy+sh)
      return transparent black
    else
      filtered(x, y, true)

  pattern_norepeat(x, y) = filtered(x, y, false)

  pattern_repeatx(x, y) = filtered(x % w, y, false)

  pattern_repeaty(x, y) = filtered(x, y % h, false)

  pattern_repeat(x, y) = filtered(x % w, y % h, false)

The relevant points are:

* drawImage clamps to the edge pixels when doing bilinear interpolation,
instead of wrapping or padding with transparency outside the image.

* All patterns wrap instead of clamping (even no-repeat).

* drawImage clamps to the edge pixels of the whole image, not to the edges of
the source rectangle segment of the image.

* Areas of patterns outside the image region are transparent black.

It looks like this is what IE9 does. Opera mostly does this, except patterns
get clamped in their non-repeating directions (e.g. repeat-x wraps on
left/right edges and clamps on top/bottom; no-repeat clamps on both) (and
there's the weird offset thing). Firefox interpolates with transparency around
the edges (instead of wrapping/clamping), except in repeating patterns where it
wraps. Chrome is nothing like this and all its scaling looks terrible if you go
above 16x.

-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Thursday, 30 September 2010 22:32:59 UTC