Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding setting of globalCompositeOperation for tiledImage #814

Merged
merged 11 commits into from Jan 21, 2016

Conversation

meihuisu
Copy link

@meihuisu meihuisu commented Jan 6, 2016

globalCompositeOperation for tag is used to allow
multiple tiledImage be blended in a specific way.
(special handling,
when compositeOperation is 'source-over' and opacity is 1,
useSketch is false, otherwise useSketch is true
)
Valid values are 'source-atop', 'source-in', 'source-out',
'destination-over', 'destination-atop', 'destination-in',
'destination-out', 'lighter', 'copy' or 'xor'
http://www.w3schools.com/tags/canvas_globalcompositeoperation.asp

html <canvas> is used to process multiple tiledImages to blend
is a specific way.
(special handling,
   when compositeOperation is 'source-over' and opacity is 1,
   useSketch is false, otherwise useSketch is true
)
Valid values are 'source-atop', 'source-in', 'source-out',
  'destination-over', 'destination-atop', 'destination-in',
  'destination-out', 'lighter', 'copy' or 'xor'
http://www.w3schools.com/tags/canvas_globalcompositeoperation.asp
@meihuisu meihuisu changed the title adding setting of globalCompositeOperation for tiledImagesUpdate to allow setting of globalCompositeOperation when adding setting of globalCompositeOperation for tiledImage Jan 6, 2016
@@ -1301,7 +1317,8 @@ function drawTiles( tiledImage, lastDrawn ) {
drawDebugInfo( tiledImage, lastDrawn );
return;
}
var useSketch = tiledImage.opacity < 1;
var useSketch = (tiledImage.compositeOperation == 'source-over') ? (tiledImage.opacity < 1):true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more readable to me:

var useSketch = tiledImage.opacity < 1 || tiledImage.compositeOperation !== 'source-over';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@avandecreme
Copy link
Member

This looks good to me. Note that you need to do a manual merge because #764 modified the same part of the code.

* @property {String} [compositeOperation='source-over']
* Valid values are 'source-atop', 'source-in', 'source-out',
* 'destination-over', 'destination-atop', 'destination-in',
* 'destination-out', 'lighter', 'copy' or 'xor'.<br>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need the <br>.

@iangilman
Copy link
Member

This is a great start! Just a few things to sort out. :-)

For the record: this fixes #765.

@iangilman
Copy link
Member

@meihuisu Sorry, didn't see you had updated the pull request! Your changes look good; you just need to merge in the latest from master and we should be good to go :)

@meihuisu
Copy link
Author

done.

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Thursday, January 14, 2016 9:41:20 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@meihuisu Sorry, didn't see you had updated the pull request! Your changes look good; you just need to merge in the latest from master and we should be good to go :)


Reply to this email directly or view it on GitHub:
#814 (comment)

@meihuisu
Copy link
Author

while testing with our code, we are seeing this message on console with latest master..

[OpenSeadragon.Spring] options.animationTime must be a non-zero number openseadragon.js:14938:1

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Thursday, January 14, 2016 9:41:20 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@meihuisu Sorry, didn't see you had updated the pull request! Your changes look good; you just need to merge in the latest from master and we should be good to go :)


Reply to this email directly or view it on GitHub:
#814 (comment)

@avandecreme
Copy link
Member

Yep, see 28d49df#commitcomment-15429375

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{

this.context.save();
this.context.globalAlpha = opacity;
this.context.globalCompositeOperation = compositeOperation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compositeOperation is optional, so we should only set it to the context if it exists.

Also, please add compositeOperation to the doc comment here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to explicitly have compositionOperation to default to 'source-over' and
so the use of it does not need to be checked? Or else, the setting of useSketch would
also need to have a check before its use.

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Friday, January 15, 2016 9:16:07 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @Lends OpenSeadragon.Drawer.prototype */{

     this.context.save();
     this.context.globalAlpha = opacity;
  •    this.context.globalCompositeOperation = compositeOperation;
    

compositeOperation is optional, so we should only set it to the context if it exists.

Also, please add compositeOperation to the doc comment here.


Reply to this email directly or view it on GitHub:
https://github.com/openseadragon/openseadragon/pull/814/files#r49878837

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is set to default in openseadragon.js

1073 // APPEARANCE
1074 opacity: 1,
1075 compositeOperation: 'source-over',
1076 placeholderFillStyle: null,

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Friday, January 15, 2016 9:16:07 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @Lends OpenSeadragon.Drawer.prototype */{

     this.context.save();
     this.context.globalAlpha = opacity;
  •    this.context.globalCompositeOperation = compositeOperation;
    

compositeOperation is optional, so we should only set it to the context if it exists.

Also, please add compositeOperation to the doc comment here.


Reply to this email directly or view it on GitHub:
https://github.com/openseadragon/openseadragon/pull/814/files#r49878837

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs to be optional to this function, because arguments in front of it are optional. Even though this function is currently only used in one place, and all argument are passed in that one place, we need to think of the possibility someone else might call it and not pass in all the arguments.

If it's not passed into this function, I would prefer not to set it at all, rather than setting it to a default value. Depending on the canvas implementation, setting it when we don't need to may have a performance impact. Nothing else in OSD changes the globalCompositeOperation, and this function wraps the change in a context.save context.restore pair, so the change won't ever bleed out past this call, so we can be confident that it'll always be already set to the default when this function starts.

Does that make sense?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.
----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Monday, January 18, 2016 9:18:32 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @Lends OpenSeadragon.Drawer.prototype */{

     this.context.save();
     this.context.globalAlpha = opacity;
  •    this.context.globalCompositeOperation = compositeOperation;
    

It needs to be optional to this function, because arguments in front of it are optional. Even though this function is currently only used in one place, and all argument are passed in that one place, we need to think of the possibility someone else might call it and not pass in all the arguments.

If it's not passed into this function, I would prefer not to set it at all, rather than setting it to a default value. Depending on the canvas implementation, setting it when we don't need to may have a performance impact. Nothing else in OSD changes the globalCompositeOperation, and this function wraps the change in a context.save context.restore pair, so the change won't ever bleed out past this call, so we can be confident that it'll always be already set to the default when this function starts.

Does that make sense?


Reply to this email directly or view it on GitHub:
https://github.com/openseadragon/openseadragon/pull/814/files#r50023838

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed the default option value to null in openseadragon.js.

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Monday, January 18, 2016 9:18:32 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @Lends OpenSeadragon.Drawer.prototype */{

     this.context.save();
     this.context.globalAlpha = opacity;
  •    this.context.globalCompositeOperation = compositeOperation;
    

It needs to be optional to this function, because arguments in front of it are optional. Even though this function is currently only used in one place, and all argument are passed in that one place, we need to think of the possibility someone else might call it and not pass in all the arguments.

If it's not passed into this function, I would prefer not to set it at all, rather than setting it to a default value. Depending on the canvas implementation, setting it when we don't need to may have a performance impact. Nothing else in OSD changes the globalCompositeOperation, and this function wraps the change in a context.save context.restore pair, so the change won't ever bleed out past this call, so we can be confident that it'll always be already set to the default when this function starts.

Does that make sense?


Reply to this email directly or view it on GitHub:
https://github.com/openseadragon/openseadragon/pull/814/files#r50023838

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iangilman, I am sorry, I think I committed something bad. can you revert it? thanks.

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Monday, January 18, 2016 9:18:32 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

@@ -383,6 +383,7 @@ $.Drawer.prototype = /** @Lends OpenSeadragon.Drawer.prototype */{

     this.context.save();
     this.context.globalAlpha = opacity;
  •    this.context.globalCompositeOperation = compositeOperation;
    

It needs to be optional to this function, because arguments in front of it are optional. Even though this function is currently only used in one place, and all argument are passed in that one place, we need to think of the possibility someone else might call it and not pass in all the arguments.

If it's not passed into this function, I would prefer not to set it at all, rather than setting it to a default value. Depending on the canvas implementation, setting it when we don't need to may have a performance impact. Nothing else in OSD changes the globalCompositeOperation, and this function wraps the change in a context.save context.restore pair, so the change won't ever bleed out past this call, so we can be confident that it'll always be already set to the default when this function starts.

Does that make sense?


Reply to this email directly or view it on GitHub:
https://github.com/openseadragon/openseadragon/pull/814/files#r50023838

@iangilman
Copy link
Member

Sorry, just caught one more thing. Otherwise looking good.

@iangilman
Copy link
Member

I've fixed that assert, btw:

#820

Thanks for mentioning it :)

@@ -383,6 +384,9 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{

this.context.save();
this.context.globalAlpha = opacity;
if (compositeOperation !== undefined && compositeOperation !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just check to see if it's truthy: if (compositeOperation)

@iangilman
Copy link
Member

Great minds think alike! Looks like you fixed the thing I was commenting on. :)

I do think the test should be truthy/falsy rather than explicitly for null.

I don't see any reason why the tests are failing, so I restarted them to see if it was just random.

@meihuisu
Copy link
Author

It was caused by taking out the explicity default setting for compositeOperation in openseadragon.js
to 'source-over' yesterday and everything spiraled down. My first time with outside opensource and
github. I will switch to truthy/falsy after test it out with my viewer.

----- Original Message -----
From: "Ian Gilman" notifications@github.com
To: "openseadragon/openseadragon" openseadragon@noreply.github.com
Cc: "meihuisu" mei@isi.edu
Sent: Wednesday, January 20, 2016 9:21:29 AM
Subject: Re: [openseadragon] adding setting of globalCompositeOperation for tiledImage (#814)

Great minds think alike! Looks like you fixed the thing I was commenting on. :)

I do think the test should be truthy/falsy rather than explicitly for null.

I don't see any reason why the tests are failing, so I restarted them to see if it was just random.


Reply to this email directly or view it on GitHub:
#814 (comment)

@iangilman
Copy link
Member

@meihuisu That makes sense. It's coming together nicely!

@meihuisu
Copy link
Author

I am done.

@iangilman
Copy link
Member

Awesome...thank you for getting all the details sorted out; it's a lovely patch!

iangilman added a commit that referenced this pull request Jan 21, 2016
adding setting of globalCompositeOperation for tiledImage
@iangilman iangilman merged commit 0a61e16 into openseadragon:master Jan 21, 2016
iangilman added a commit that referenced this pull request Jan 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants