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
Conversation
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
@@ -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; |
There was a problem hiding this comment.
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';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed.
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> |
There was a problem hiding this comment.
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>
.
This is a great start! Just a few things to sort out. :-) For the record: this fixes #765. |
@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 :) |
done. ----- Original Message ----- @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: |
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 ----- @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: |
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
Sorry, just caught one more thing. Otherwise looking good. |
I've fixed that assert, btw: 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) { |
There was a problem hiding this comment.
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)
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 I don't see any reason why the tests are failing, so I restarted them to see if it was just random. |
It was caused by taking out the explicity default setting for compositeOperation in openseadragon.js ----- Original Message ----- 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 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: |
@meihuisu That makes sense. It's coming together nicely! |
I am done. |
Awesome...thank you for getting all the details sorted out; it's a lovely patch! |
adding setting of globalCompositeOperation for tiledImage
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