thorvg
thorvg copied to clipboard
Masking display incorrectly
In Masking.cpp example. When mask object has transparency, the result wrong display. Alpha is applied to the stroke and fill of the target.
Test code
diff --git a/src/examples/Masking.cpp b/src/examples/Masking.cpp
index 8d517ef..fc942d7 100644
--- a/src/examples/Masking.cpp
+++ b/src/examples/Masking.cpp
@@ -52,13 +52,14 @@ void tvgDrawCmds(tvg::Canvas* canvas)
star->lineTo(426, 161);
star->lineTo(546, 143);
star->close();
- star->stroke(10);
+ star->stroke(30);
star->stroke(255, 255, 255, 255);
//Mask3
auto mask3 = tvg::Shape::gen();
mask3->appendCircle(600, 200, 125, 125);
- mask3->fill(255, 255, 255, 255);
+ mask3->fill(255, 255, 255, 125);
+ //or mask3->opacity(125);
star->composite(move(mask3), tvg::CompositeMethod::AlphaMask);
if (canvas->push(move(star)) != tvg::Result::Success) return;
Looks this is correct behavior as masking just doing as its role. masking should not change its target's behavior.
Sorry, I misunderstood.
#326 should close the subject of the gradient shapes with masks (for now :) )
@hermet @JSUYA @patrykka
I have a question - how should the expected result of the following code look like?
//-------------------------------------------
auto shape1 = tvg::Shape::gen();
shape1->appendRect(400, 0, 400, 400, 0, 0);
shape1->fill(255, 0, 0, 255);
//Alpha Mask
auto mask1 = tvg::Shape::gen();
mask1->appendCircle(600, 200, 180, 180);
mask1->fill(0, 0, 0, 127);
shape1->composite(move(mask1), tvg::CompositeMethod::AlphaMask);
canvas->push(move(shape1));
//-------------------------------------------
auto shape2 = tvg::Shape::gen();
shape2->appendRect(0, 0, 400, 400, 0, 0);
shape2->fill(255, 0, 0, 255);
//Inv Alpha Mask
auto mask2 = tvg::Shape::gen();
mask2->appendCircle(200, 200, 180, 180);
mask2->fill(0, 0, 0, 127);
shape2->composite(move(mask2), tvg::CompositeMethod::InvAlphaMask);
canvas->push(move(shape2));
-
the current result from tvg (inv mask - left, mask - right):
-
I'd expect this one (inv mask - left, mask - right):
-
or this one (inv mask - left, mask - right):
Our current version doesn't seem to be consistent for me. I think the third one is the correct one.
@JSUYA what do you think? There are my current results, but I still have to improve the code:
left - mask, right - inv mask
#337
just checked, it's still valid issue.
@JSUYA @hermet please check after #519 and #520 are merged. just to make sure that I understood the problem in this issue correctly