[whatwg] I believe source rectangles for HTML5 Canvas drawImage are specified incorrectly

Rik Cabanier cabanier at gmail.com
Mon Dec 10 15:53:08 PST 2012


On Mon, Dec 10, 2012 at 1:18 PM, Justin Novosad <junov at chromium.org> wrote:

> On Mon, Dec 10, 2012 at 4:04 PM, Rik Cabanier <cabanier at gmail.com> wrote:
>
>>
>>
>> As Ian said, copying the sprite image to a non-scaled canvas first (which
>> most games probably do anyway) works around the issue.
>> There is no need for padding in that case.
>>
>>
> Yes, I am sure a lot of games do it already to work around the color
> bleeding problem but there is a performance cost to doing that.
>

> Couldn't we just make everyone happy by making the behavior controllable
> through a context attribute or an additional overload of drawImage that
> takes an extra argument?
>

I assume this would only be for the 9 argument version of drawImage?

FWIW
I was curious why this bug doesn't show up in WebKit so I looked at the
implementation.
They actually catch cases where there's scaling of a portion of an image
and special case it by copying the non-scaled image to a temporary canvas
first:
        // When the image is scaled using high-quality interpolation, we
create a temporary CGImage
        // containing only the portion we want to display. We need to do
this because high-quality
        // interpolation smoothes sharp edges, causing pixels from outside
the source rect to bleed
        // into the destination rect. See <rdar://problem/6112909>.

It would be nice to see why the Safari folks added this code since it makes
them inconsistent with the spec.



More information about the whatwg mailing list