thorvg icon indicating copy to clipboard operation
thorvg copied to clipboard

Masking display incorrectly

Open JSUYA opened this issue 4 years ago • 8 comments

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;

image

JSUYA avatar Jan 11 '21 03:01 JSUYA

Looks this is correct behavior as masking just doing as its role. masking should not change its target's behavior.

hermet avatar Jan 22 '21 14:01 hermet

Sorry, I misunderstood.

hermet avatar Jan 22 '21 14:01 hermet

#326 should close the subject of the gradient shapes with masks (for now :) )

mgrudzinska avatar Apr 08 '21 16:04 mgrudzinska

@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));
  1. the current result from tvg (inv mask - left, mask - right): inv_pyt

  2. I'd expect this one (inv mask - left, mask - right): inv_pyt_exp

  3. or this one (inv mask - left, mask - right): inv_pyt_exp2

Our current version doesn't seem to be consistent for me. I think the third one is the correct one.

mgrudzinska avatar Apr 08 '21 17:04 mgrudzinska

@JSUYA what do you think? There are my current results, but I still have to improve the code:

left - mask, right - inv mask mask_inv_ok

mgrudzinska avatar Apr 12 '21 01:04 mgrudzinska

#337

mgrudzinska avatar Apr 13 '21 11:04 mgrudzinska

just checked, it's still valid issue.

hermet avatar May 31 '21 08:05 hermet

@JSUYA @hermet please check after #519 and #520 are merged. just to make sure that I understood the problem in this issue correctly

mgrudzinska avatar Jun 26 '21 12:06 mgrudzinska