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

Rik Cabanier cabanier at gmail.com
Mon Dec 17 11:27:20 PST 2012


On Mon, Dec 17, 2012 at 7:23 AM, Justin Novosad <junov at chromium.org> wrote:

>
>
> On Sun, Dec 16, 2012 at 11:52 PM, Rik Cabanier <cabanier at gmail.com> wrote:
>
>>
>>
>> On Wed, Dec 12, 2012 at 10:24 AM, Justin Novosad <junov at chromium.org>wrote:
>>
>>>
>>>
>>> On Wed, Dec 12, 2012 at 12:39 PM, Rik Cabanier <cabanier at gmail.com>wrote:
>>>
>>>>
>>>> What would be the next step? Should we define a new version of
>>>> drawImage with the extra parameter?
>>>
>>>
>>> That is one option, but I think a context attribute (like
>>> imageSmoothingEnabled) is also worth considering.
>>> Perhaps image smoothing could be an enum rather than boolean with an
>>> additional mode that prevents color bleeding.
>>>
>>
>> It seems a bit too expensive to add a variable to the graphics context
>> that is checked for just this call.
>> Maybe just a new drawImage call (like drawNonSmoothedImage?) is all that
>> is needed.
>>
>
> Yes. That sounds quite reasonable to me, but we can find a better name.
> The name "drawNonSmoothedImage" suggests that the image won't be smoothed
> at all, which is not the case.  It's hard to find a name that correctly
> describes the right behavior without getting too technical.  I am thinking
> "drawSubImage", in the sense that the sub region delimited by the source
> rectangle is treated as if it were a whole image.
>

That sounds reasonable.


> This gives me another idea: we could just have a new Image constructor
> that creates a new image element that is a subregion of another:
> var mySprite = new Image(spriteMap, x, y, w, h);
> This can be implemented in a lightweight way that just references the data
> of the source image.
>

Isn't this the same as what Ian suggested: copy it to a temporary canvas
and use the temporary canvas scales.
It seems that you can optimize that case too.



More information about the whatwg mailing list