Re: [whatwg] proposal: Add support for masking to canvas

2013-07-16 Thread Ian Hickson
On Fri, 1 Feb 2013, Cameron McCormack wrote:
> On 30/01/13 6:28 PM, Ian Hickson wrote:
> > That's weird. heycam, can you elaborate on this? The addHitRegion() 
> > case in particular never makes sense to be called without a dictionary 
> > containing at least one member. Do we have to allow it?
> 
> This is to encourage (require, really) API design that allows the 
> dictionary object to be not specified at all.  Remember that all 
> dictionary members can be "not specified" anyway.
> 
> Do you want addHitRegion() to throw just like addHitRegion({}) would 
> throw? That will happen if you already have wording to say that 
> addHitRegion({}) will throw.

Ah, ok. Fixed. Thanks.

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-31 Thread Cameron McCormack

On 30/01/13 6:28 PM, Ian Hickson wrote:

That's weird. heycam, can you elaborate on this? The addHitRegion() case
in particular never makes sense to be called without a dictionary
containing at least one member. Do we have to allow it?


This is to encourage (require, really) API design that allows the 
dictionary object to be not specified at all.  Remember that all 
dictionary members can be "not specified" anyway.


Do you want addHitRegion() to throw just like addHitRegion({}) would 
throw?  That will happen if you already have wording to say that 
addHitRegion({}) will throw.


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Ian Hickson
On Wed, 30 Jan 2013, Boris Zbarsky wrote:
> On 1/30/13 12:55 AM, Rik Cabanier wrote:
> >void maskImage(optional MaskOptions options);
> > 
> > Why is it optional?
> 
> Because http://dev.w3.org/2006/webapi/WebIDL/#idl-operations says (if you
> scroll down a ways):
> 
>   If the type of an argument is a dictionary type or a union type that
>   has a dictionary type as one of its flattened member types, and this
>   argument is either the final argument or is followed by an optional
>   argument, then the argument MUST be specified as optional.  Such
>   arguments are always considered to have a default value of an empty
>   dictionary, unless otherwise specified.

That's weird. heycam, can you elaborate on this? The addHitRegion() case 
in particular never makes sense to be called without a dictionary 
containing at least one member. Do we have to allow it?

(The webidl checker doesn't seem to catch this particular bug, by the way.)

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Boris Zbarsky

On 1/30/13 12:55 AM, Rik Cabanier wrote:

   void maskImage(optional MaskOptions options);

Why is it optional?


Because http://dev.w3.org/2006/webapi/WebIDL/#idl-operations says (if 
you scroll down a ways):


  If the type of an argument is a dictionary type or a union type that
  has a dictionary type as one of its flattened member types, and this
  argument is either the final argument or is followed by an optional
  argument, then the argument MUST be specified as optional.  Such
  arguments are always considered to have a default value of an empty
  dictionary, unless otherwise specified.


It's not optional for 'addHitRegion' in the spec either...


Well, then whenever someone tries to actually parse that IDL with a 
WebIDL parser/validator they'll come filing bugs.  ;)


-Boris


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Ian Hickson
On Wed, 30 Jan 2013, Boris Zbarsky wrote:
> On 1/30/13 12:13 AM, Rik Cabanier wrote:
> > ah, sorry. I looked at the dictionary for hitregions
> 
> Sounds like we should consider fixing this hitregions thing whatever it is.

The HitRegionOptions dictionary has (some) nullable members to allow the 
"missing" value to also be represented as null (as distinct from the empty 
string). For 'id', the missing value is represented by the empty string, 
so it's not nullable. For 'cursor', the missing value is not distinguished 
from the value 'inherit', so it's not nullable either. As you point out, 
all the values are optional; the reason to make something nullable is just 
to allow the "null" value, not to make it optional.

-- 
Ian Hickson   U+1047E)\._.,--,'``.fL
http://ln.hixie.ch/   U+263A/,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
On Tue, Jan 29, 2013 at 9:49 PM, Boris Zbarsky  wrote:

> On 1/30/13 12:37 AM, Rik Cabanier wrote:
>
>> enum CanvasMaskType { luminosity, alpha};
>>
>
> Last nits.  Need quotes around the enum values.  So:
>
>   enum CanvasMaskType { "luminosity", "alpha" };
>
>  void maskImage(MaskOptions options);
>>
>
> I believe that has to be:
>
>   void maskImage(optional MaskOptions options);
>

Why is it optional?
It's not optional for 'addHitRegion' in the spec either...


>
> to be valid WebIDL.
>
> Apart from that, the IDL parts look fine.  Can't speak to the actual
> graphics bits.  ;)
>
> -Boris
>
>


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Boris Zbarsky

On 1/30/13 12:37 AM, Rik Cabanier wrote:

enum CanvasMaskType { luminosity, alpha};


Last nits.  Need quotes around the enum values.  So:

  enum CanvasMaskType { "luminosity", "alpha" };


void maskImage(MaskOptions options);


I believe that has to be:

  void maskImage(optional MaskOptions options);

to be valid WebIDL.

Apart from that, the IDL parts look fine.  Can't speak to the actual 
graphics bits.  ;)


-Boris



Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
I want to get it right! :-)
After looking at the CG API, maybe imageSmoothing could be a part of the
mask too.

Third try:

enum CanvasMaskType { luminosity, alpha};
dictionary MaskOptions {

CanvasImageSource image;
unrestricted double sx;
unrestricted double sy;
unrestricted double sw;
unrestricted double sh;
unrestricted double dx;
unrestricted double dy;
unrestricted double dw;
unrestricted double dh;
CanvasMaskType maskType = "luminosity";
boolean invert = false;
boolean clipToMask = true;
boolean imageSmoothingEnabled = true;

}

void maskImage(MaskOptions options);
void resetMask();

If not specified, the dw and dh arguments must default to the values of sw
and sh, interpreted such that one CSS pixel in the image is treated as one
unit in thescratch bitmap's coordinate space. If the sx, sy, sw, and sh
arguments are omitted, they must default to 0, 0, the image's intrinsic
width in image pixels, and the image's intrinsic height in image pixels,
respectively.


On Tue, Jan 29, 2013 at 9:23 PM, Boris Zbarsky  wrote:

> On 1/30/13 12:13 AM, Rik Cabanier wrote:
>
>> ah, sorry. I looked at the dictionary for hitregions
>>
>
> Sounds like we should consider fixing this hitregions thing whatever it is.
>
>  optional unrestricted double sx;
>>
>
> That's not actually valid WebIDL, with the "optional".
>
> And that's because all dictionary members in WebIDL are always optional to
> start with.
>
> So just dropping all those "optional" should do the trick.
>
> Note that this does mean that for things you really must have the prose
> needs to specify throwing if they're not present.


I would specify the same language as for drawImage:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-drawimage

Thanks for the help!


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Boris Zbarsky

On 1/30/13 12:13 AM, Rik Cabanier wrote:

ah, sorry. I looked at the dictionary for hitregions


Sounds like we should consider fixing this hitregions thing whatever it is.


optional unrestricted double sx;


That's not actually valid WebIDL, with the "optional".

And that's because all dictionary members in WebIDL are always optional 
to start with.


So just dropping all those "optional" should do the trick.

Note that this does mean that for things you really must have the prose 
needs to specify throwing if they're not present.


-Boris


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
ah, sorry. I looked at the dictionary for hitregions and assumed that's how
you make something optional in a dict [1]

Second try:

enum CanvasMaskType { luminosity, alpha};
dictionary maskOptions {

CanvasImageSource image;
optional unrestricted double sx;
optional unrestricted double sy;
optional unrestricted double sw;
optional unrestricted double sh;
unrestricted double dx;
unrestricted double dy;
optional unrestricted double dw;
optional unrestricted double dh;
optional CanvasMaskType maskType = "luminosity";
optional boolean invert = false;
optional boolean clipToMask = true;

}

void maskImage(maskOptions options);
void resetMask();

If not specified, the dw and dh arguments must default to the values of sw
and sh, interpreted such that one CSS pixel in the image is treated as one
unit in thescratch bitmap's coordinate space. If the sx, sy, sw, and sh
arguments are omitted, they must default to 0, 0, the image's intrinsic
width in image pixels, and the image's intrinsic height in image pixels,
respectively.


1:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#hitregionoptions

On Tue, Jan 29, 2013 at 9:07 PM, Tab Atkins Jr. wrote:

> On Tue, Jan 29, 2013 at 9:04 PM, Boris Zbarsky  wrote:
> > On 1/29/13 11:37 PM, Rik Cabanier wrote:
> >>
> >> So the API could be as follows:
> >
> > ...
> >
> >> unrestricted double? sx;
> >> unrestricted double? sy;
> >
> >
> > Do these actually need to be nullable?  What's the use case for setting
> them
> > to null?
> >
> > Same thing for the rest of this dictionary's members.
>
> Hah, right, I overlooked that.  They don't need to be *nullable*, just
> *optional*.
>
> ~TJ
>


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Tab Atkins Jr.
On Tue, Jan 29, 2013 at 9:04 PM, Boris Zbarsky  wrote:
> On 1/29/13 11:37 PM, Rik Cabanier wrote:
>>
>> So the API could be as follows:
>
> ...
>
>> unrestricted double? sx;
>> unrestricted double? sy;
>
>
> Do these actually need to be nullable?  What's the use case for setting them
> to null?
>
> Same thing for the rest of this dictionary's members.

Hah, right, I overlooked that.  They don't need to be *nullable*, just
*optional*.

~TJ


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Boris Zbarsky

On 1/29/13 11:37 PM, Rik Cabanier wrote:

So the API could be as follows:

...

unrestricted double? sx;
unrestricted double? sy;


Do these actually need to be nullable?  What's the use case for setting 
them to null?


Same thing for the rest of this dictionary's members.

-Boris


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Tab Atkins Jr.
On Tue, Jan 29, 2013 at 8:37 PM, Rik Cabanier  wrote:
> So the API could be as follows:
>
> enum CanvasMaskType { luminosity, alpha};
> dictionary maskOptions {
>
> CanvasImageSource image;
> unrestricted double? sx;
> unrestricted double? sy;
> unrestricted double? sw;
> unrestricted double? sh;
> unrestricted double dx;
> unrestricted double dy;
> unrestricted double? dw;
> unrestricted double? dh;
> CanvasMaskType? maskType = "luminosity";
> boolean? invert = false;
> boolean? clipToMask = true;
>
> }
>
> void maskImage(maskOptions options);
> void resetMask();
>
> If not specified, the dw and dh arguments must default to the values of sw
> and sh, interpreted such that one CSS pixel in the image is treated as one
> unit in thescratch bitmap's coordinate space. If the sx, sy, sw, and sh
> arguments are omitted, they must default to 0, 0, the image's intrinsic
> width in image pixels, and the image's intrinsic height in image pixels,
> respectively.

Yeah, looks good to me.

~TJ


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
Thanks!
I like that better too.

So the API could be as follows:

enum CanvasMaskType { luminosity, alpha};
dictionary maskOptions {

CanvasImageSource image;
unrestricted double? sx;
unrestricted double? sy;
unrestricted double? sw;
unrestricted double? sh;
unrestricted double dx;
unrestricted double dy;
unrestricted double? dw;
unrestricted double? dh;
CanvasMaskType? maskType = "luminosity";
boolean? invert = false;
boolean? clipToMask = true;

}

void maskImage(maskOptions options);
void resetMask();

If not specified, the dw and dh arguments must default to the values of sw
and sh, interpreted such that one CSS pixel in the image is treated as one
unit in thescratch bitmap's coordinate space. If the sx, sy, sw, and sh
arguments are omitted, they must default to 0, 0, the image's intrinsic
width in image pixels, and the image's intrinsic height in image pixels,
respectively.

Rik

On Tue, Jan 29, 2013 at 8:18 PM, Tab Atkins Jr. wrote:

> On Tue, Jan 29, 2013 at 7:30 PM, Rik Cabanier  wrote:
> > Do you believe it's OK to have 12 arguments or would a dictionary be
> better?
>
> No, it's not okay.  ^_^  Particularly when some of the parameters are
> boolean - boolean positional arguments are the devil.  Go with a dict.
>
> ~TJ
>


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Tab Atkins Jr.
On Tue, Jan 29, 2013 at 7:30 PM, Rik Cabanier  wrote:
> Do you believe it's OK to have 12 arguments or would a dictionary be better?

No, it's not okay.  ^_^  Particularly when some of the parameters are
boolean - boolean positional arguments are the devil.  Go with a dict.

~TJ


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
Jatinder,

I forgot to ask what you think of the API itself.
Do you believe it's OK to have 12 arguments or would a dictionary be better?

Rik

On Tue, Jan 29, 2013 at 5:34 PM, Jatinder Mann  wrote:

>  Seeing that alpha and luminance masking is definitely useful, I would
> like to see them added to the spec.
>
> ** **
>
> We may want to ensure that the spec provides a very clear mathematical
> definition of luma. Luma, luminance, and luminosity are technically
> different things. One specific feedback is whether the spec will be
> specifying if user agents should assume linear gamma space or 2.2 gamma
> space. Basically all images are natively stored in 2.2. gamma space, but
> luminance is typically calculated assuming linear gamma. I believe 2.2
> gamma would be faster, as there is no need for the conversion. 
>
> ** **
>
> Thanks,
>
> Jatinder
>
> ** **
>
> *From:* Rik Cabanier [mailto:caban...@gmail.com]
> *Sent:* Thursday, January 24, 2013 1:42 PM
> *To:* public-canvas-...@w3.org; wha...@whatwg.org
> *Subject:* proposal: Add support for masking to canvas
>
> ** **
>
> All, 
>
> ** **
>
> the canvas API does not have a convenient way of supporting masking today.
> 
>
> There is some support with the compositing operators but it requires quite
> a bit of work on the author's part as well as a temporary canvas. In
> addition, there is no way to implement a luminosity mask without reading
> the pixels and doing the math yourself.
>
> ** **
>
> I was thinking of proposing the following new API calls for the 2d canvas
> context:
>
> enum CanvasMaskType { luminosity, alpha};
> void maskImage(image, sx, sy, sw, sh, dx, dy, dw, dh, maskType, invert,
> clipToMask);
> void resetMask();
>
>  ** **
>
> 'maskImage' will set the mask in the current graphics state which makes it
> subject to save/restore. parameters:
>
> image = HTMLImageElement or HTMLCanvasElement or HTMLVideoElement. 
>
>  Points to set of pixels that will be used as the mask source 
>
>  ** **
>
> sx, sy, etc = describes what portions of the source and destination canvas
> to target. (This is similar to drawImage [1])
>
> ** **
>
> maskType = sets what type of mask.
>
> luminosity = (default) use the luma value of the pixel
>
>   alpha = just look at the alpha channel. ignore the color channel 
>
> invert = boolean. (default = false) invert the mask values 
>
> ** **
>
> clipToMask = boolean (default = true) the area outside of the mask pixels
> clipped away. If false, that area is not affected by the mask.
>
> ** **
>
> 'maskImage' will set the mask in the current graphics state which makes it
> subject to save/restore.
>
>  ** **
>
>  'resetMask' will remove the mask from the current graphics state.
>
> ** **
>
> Some people told me that maskImage is taking too many parameters and that
> a dictionary would be better.
>
> ** **
>
> What do people think? Is this useful enough to add to the API?
>
> ** **
>
> Rik
>
> ** **
>
> 1:
> http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dom-context-2d-drawimage
> 
>


Re: [whatwg] proposal: Add support for masking to canvas

2013-01-29 Thread Rik Cabanier
luminance would be calculated the same as for compositing and blending:

https://dvcs.w3.org/hg/FXTF/rawfile/tip/compositing/index.html#blendingnonseparable

This is done with no adjustment for gamma.

Maybe we can add real ICC color management later so you can blend/mask in
other RGB colorspaces or Lab.

Rik

On Tue, Jan 29, 2013 at 5:34 PM, Jatinder Mann  wrote:

>  Seeing that alpha and luminance masking is definitely useful, I would
> like to see them added to the spec.
>
> ** **
>
> We may want to ensure that the spec provides a very clear mathematical
> definition of luma. Luma, luminance, and luminosity are technically
> different things. One specific feedback is whether the spec will be
> specifying if user agents should assume linear gamma space or 2.2 gamma
> space. Basically all images are natively stored in 2.2. gamma space, but
> luminance is typically calculated assuming linear gamma. I believe 2.2
> gamma would be faster, as there is no need for the conversion. 
>
> ** **
>
> Thanks,
>
> Jatinder
>
> ** **
>
> *From:* Rik Cabanier [mailto:caban...@gmail.com]
> *Sent:* Thursday, January 24, 2013 1:42 PM
> *To:* public-canvas-...@w3.org; wha...@whatwg.org
> *Subject:* proposal: Add support for masking to canvas
>
> ** **
>
> All, 
>
> ** **
>
> the canvas API does not have a convenient way of supporting masking today.
> 
>
> There is some support with the compositing operators but it requires quite
> a bit of work on the author's part as well as a temporary canvas. In
> addition, there is no way to implement a luminosity mask without reading
> the pixels and doing the math yourself.
>
> ** **
>
> I was thinking of proposing the following new API calls for the 2d canvas
> context:
>
> enum CanvasMaskType { luminosity, alpha};
> void maskImage(image, sx, sy, sw, sh, dx, dy, dw, dh, maskType, invert,
> clipToMask);
> void resetMask();
>
>  ** **
>
> 'maskImage' will set the mask in the current graphics state which makes it
> subject to save/restore. parameters:
>
> image = HTMLImageElement or HTMLCanvasElement or HTMLVideoElement. 
>
>  Points to set of pixels that will be used as the mask source 
>
>  ** **
>
> sx, sy, etc = describes what portions of the source and destination canvas
> to target. (This is similar to drawImage [1])
>
> ** **
>
> maskType = sets what type of mask.
>
> luminosity = (default) use the luma value of the pixel
>
>   alpha = just look at the alpha channel. ignore the color channel 
>
> invert = boolean. (default = false) invert the mask values 
>
> ** **
>
> clipToMask = boolean (default = true) the area outside of the mask pixels
> clipped away. If false, that area is not affected by the mask.
>
> ** **
>
> 'maskImage' will set the mask in the current graphics state which makes it
> subject to save/restore.
>
>  ** **
>
>  'resetMask' will remove the mask from the current graphics state.
>
> ** **
>
> Some people told me that maskImage is taking too many parameters and that
> a dictionary would be better.
>
> ** **
>
> What do people think? Is this useful enough to add to the API?
>
> ** **
>
> Rik
>
> ** **
>
> 1:
> http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dom-context-2d-drawimage
> 
>


[whatwg] proposal: Add support for masking to canvas

2013-01-24 Thread Rik Cabanier
All,

the canvas API does not have a convenient way of supporting masking today.
There is some support with the compositing operators but it requires quite
a bit of work on the author's part as well as a temporary canvas. In
addition, there is no way to implement a luminosity mask without reading
the pixels and doing the math yourself.

I was thinking of proposing the following new API calls for the 2d canvas
context:

enum CanvasMaskType { luminosity, alpha};
void maskImage(image, sx, sy, sw, sh, dx, dy, dw, dh, maskType, invert,
clipToMask);
void resetMask();


'maskImage' will set the mask in the current graphics state which makes it
subject to save/restore. parameters:

image = HTMLImageElement or HTMLCanvasElement or HTMLVideoElement.

Points to set of pixels that will be used as the mask source


sx, sy, etc = describes what portions of the source and destination canvas
to target. (This is similar to drawImage [1])

maskType = sets what type of mask.

luminosity = (default) use the luma value of the pixel

alpha = just look at the alpha channel. ignore the color channel

invert = boolean. (default = false) invert the mask values

clipToMask = boolean (default = true) the area outside of the mask pixels
clipped away. If false, that area is not affected by the mask.

'maskImage' will set the mask in the current graphics state which makes it
subject to save/restore.


'resetMask' will remove the mask from the current graphics state.

Some people told me that maskImage is taking too many parameters and that a
dictionary would be better.

What do people think? Is this useful enough to add to the API?

Rik

1:
http://www.w3.org/html/wg/drafts/2dcontext/html5_canvas/#dom-context-2d-drawimage