mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
examples: unified samples and improved coverages
- Unify samples for simpler testing: - Masking + InvMasking - LumaMasking + InvLumaMasking - Applied Dash for the Stroke Triming
This commit is contained in:
parent
151284c3cc
commit
02678b67f4
6 changed files with 325 additions and 423 deletions
|
@ -1,131 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 - 2025 the ThorVG project. All rights reserved.
|
|
||||||
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Example.h"
|
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* ThorVG Drawing Contents */
|
|
||||||
/************************************************************************/
|
|
||||||
|
|
||||||
struct UserExample : tvgexam::Example
|
|
||||||
{
|
|
||||||
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
|
|
||||||
{
|
|
||||||
if (!canvas) return false;
|
|
||||||
|
|
||||||
//Solid Rectangle
|
|
||||||
auto shape = tvg::Shape::gen();
|
|
||||||
shape->appendRect(0, 0, 400, 400);
|
|
||||||
shape->fill(255, 0, 0);
|
|
||||||
|
|
||||||
//Mask
|
|
||||||
auto mask = tvg::Shape::gen();
|
|
||||||
mask->appendCircle(200, 200, 125, 125);
|
|
||||||
mask->fill(255, 100, 255);
|
|
||||||
|
|
||||||
//Nested Mask
|
|
||||||
auto nMask = tvg::Shape::gen();
|
|
||||||
nMask->appendCircle(220, 220, 125, 125);
|
|
||||||
nMask->fill(255, 200, 255);
|
|
||||||
|
|
||||||
mask->mask(nMask, tvg::MaskMethod::InvLuma);
|
|
||||||
shape->mask(mask, tvg::MaskMethod::InvLuma);
|
|
||||||
canvas->push(shape);
|
|
||||||
|
|
||||||
//SVG
|
|
||||||
auto svg = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
|
||||||
svg->opacity(100);
|
|
||||||
svg->scale(3);
|
|
||||||
svg->translate(50, 400);
|
|
||||||
|
|
||||||
//Mask2
|
|
||||||
auto mask2 = tvg::Shape::gen();
|
|
||||||
mask2->appendCircle(150, 500, 75, 75);
|
|
||||||
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
|
||||||
mask2->fill(255, 255, 255);
|
|
||||||
svg->mask(mask2, tvg::MaskMethod::InvLuma);
|
|
||||||
canvas->push(svg);
|
|
||||||
|
|
||||||
//Star
|
|
||||||
auto star = tvg::Shape::gen();
|
|
||||||
star->fill(80, 80, 80);
|
|
||||||
star->moveTo(599, 34);
|
|
||||||
star->lineTo(653, 143);
|
|
||||||
star->lineTo(774, 160);
|
|
||||||
star->lineTo(687, 244);
|
|
||||||
star->lineTo(707, 365);
|
|
||||||
star->lineTo(599, 309);
|
|
||||||
star->lineTo(497, 365);
|
|
||||||
star->lineTo(512, 245);
|
|
||||||
star->lineTo(426, 161);
|
|
||||||
star->lineTo(546, 143);
|
|
||||||
star->close();
|
|
||||||
star->strokeWidth(10);
|
|
||||||
star->strokeFill(255, 255, 255);
|
|
||||||
|
|
||||||
//Mask3
|
|
||||||
auto mask3 = tvg::Shape::gen();
|
|
||||||
mask3->appendCircle(600, 200, 125, 125);
|
|
||||||
mask3->fill(0, 255, 255);
|
|
||||||
star->mask(mask3, tvg::MaskMethod::InvLuma);
|
|
||||||
canvas->push(star);
|
|
||||||
|
|
||||||
//Image
|
|
||||||
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
|
||||||
if (!file.is_open()) return false;
|
|
||||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
|
||||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
auto image = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
|
||||||
image->translate(500, 400);
|
|
||||||
|
|
||||||
//Mask4
|
|
||||||
auto mask4 = tvg::Scene::gen();
|
|
||||||
auto mask4_rect = tvg::Shape::gen();
|
|
||||||
mask4_rect->appendRect(500, 400, 200, 300);
|
|
||||||
mask4_rect->fill(255, 255, 255);
|
|
||||||
auto mask4_circle = tvg::Shape::gen();
|
|
||||||
mask4_circle->appendCircle(600, 550, 125, 125);
|
|
||||||
mask4_circle->fill(128, 0, 128);
|
|
||||||
mask4->push(mask4_rect);
|
|
||||||
mask4->push(mask4_circle);
|
|
||||||
image->mask(mask4, tvg::MaskMethod::InvLuma);
|
|
||||||
canvas->push(image);
|
|
||||||
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* Entry Point */
|
|
||||||
/************************************************************************/
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
return tvgexam::main(new UserExample, argc, argv);
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020 - 2025 the ThorVG project. All rights reserved.
|
|
||||||
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Example.h"
|
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* ThorVG Drawing Contents */
|
|
||||||
/************************************************************************/
|
|
||||||
|
|
||||||
struct UserExample : tvgexam::Example
|
|
||||||
{
|
|
||||||
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
|
|
||||||
{
|
|
||||||
if (!canvas) return false;
|
|
||||||
|
|
||||||
//Solid Rectangle
|
|
||||||
auto shape = tvg::Shape::gen();
|
|
||||||
shape->appendRect(0, 0, 400, 400);
|
|
||||||
shape->fill(0, 0, 255);
|
|
||||||
|
|
||||||
//Mask
|
|
||||||
auto mask = tvg::Shape::gen();
|
|
||||||
mask->appendCircle(200, 200, 125, 125);
|
|
||||||
mask->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
|
||||||
|
|
||||||
//Nested Mask
|
|
||||||
auto nMask = tvg::Shape::gen();
|
|
||||||
nMask->appendCircle(220, 220, 125, 125);
|
|
||||||
nMask->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
|
||||||
|
|
||||||
mask->mask(nMask, tvg::MaskMethod::InvAlpha);
|
|
||||||
shape->mask(mask, tvg::MaskMethod::InvAlpha);
|
|
||||||
canvas->push(shape);
|
|
||||||
|
|
||||||
//SVG
|
|
||||||
auto svg = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
|
||||||
svg->opacity(100);
|
|
||||||
svg->scale(3);
|
|
||||||
svg->translate(50, 400);
|
|
||||||
|
|
||||||
//Mask2
|
|
||||||
auto mask2 = tvg::Shape::gen();
|
|
||||||
mask2->appendCircle(150, 500, 75, 75);
|
|
||||||
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
|
||||||
mask2->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
|
||||||
svg->mask(mask2, tvg::MaskMethod::InvAlpha);
|
|
||||||
canvas->push(svg);
|
|
||||||
|
|
||||||
//Star
|
|
||||||
auto star = tvg::Shape::gen();
|
|
||||||
star->fill(80, 80, 80);
|
|
||||||
star->moveTo(599, 34);
|
|
||||||
star->lineTo(653, 143);
|
|
||||||
star->lineTo(774, 160);
|
|
||||||
star->lineTo(687, 244);
|
|
||||||
star->lineTo(707, 365);
|
|
||||||
star->lineTo(599, 309);
|
|
||||||
star->lineTo(497, 365);
|
|
||||||
star->lineTo(512, 245);
|
|
||||||
star->lineTo(426, 161);
|
|
||||||
star->lineTo(546, 143);
|
|
||||||
star->close();
|
|
||||||
star->strokeWidth(10);
|
|
||||||
star->strokeFill(255, 255, 255);
|
|
||||||
|
|
||||||
//Mask3
|
|
||||||
auto mask3 = tvg::Shape::gen();
|
|
||||||
mask3->appendCircle(600, 200, 125, 125);
|
|
||||||
mask3->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
|
||||||
star->mask(mask3, tvg::MaskMethod::InvAlpha);
|
|
||||||
canvas->push(star);
|
|
||||||
|
|
||||||
//Image
|
|
||||||
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
|
||||||
if (!file.is_open()) return false;
|
|
||||||
auto data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
|
||||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
auto image = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ABGR8888, true))) return false;
|
|
||||||
image->translate(500, 400);
|
|
||||||
free(data);
|
|
||||||
|
|
||||||
//Mask4
|
|
||||||
auto mask4 = tvg::Shape::gen();
|
|
||||||
mask4->moveTo(599, 384);
|
|
||||||
mask4->lineTo(653, 493);
|
|
||||||
mask4->lineTo(774, 510);
|
|
||||||
mask4->lineTo(687, 594);
|
|
||||||
mask4->lineTo(707, 715);
|
|
||||||
mask4->lineTo(599, 659);
|
|
||||||
mask4->lineTo(497, 715);
|
|
||||||
mask4->lineTo(512, 595);
|
|
||||||
mask4->lineTo(426, 511);
|
|
||||||
mask4->lineTo(546, 493);
|
|
||||||
mask4->close();
|
|
||||||
mask4->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
|
||||||
mask4->opacity(70);
|
|
||||||
image->mask(mask4, tvg::MaskMethod::InvAlpha);
|
|
||||||
canvas->push(image);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* Entry Point */
|
|
||||||
/************************************************************************/
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
return tvgexam::main(new UserExample, argc, argv);
|
|
||||||
}
|
|
|
@ -32,64 +32,6 @@ struct UserExample : tvgexam::Example
|
||||||
{
|
{
|
||||||
if (!canvas) return false;
|
if (!canvas) return false;
|
||||||
|
|
||||||
//Solid Rectangle
|
|
||||||
auto shape = tvg::Shape::gen();
|
|
||||||
shape->appendRect(0, 0, 400, 400);
|
|
||||||
shape->fill(255, 0, 0);
|
|
||||||
|
|
||||||
//Mask
|
|
||||||
auto mask = tvg::Shape::gen();
|
|
||||||
mask->appendCircle(200, 200, 125, 125);
|
|
||||||
mask->fill(255, 100, 255);
|
|
||||||
|
|
||||||
//Nested Mask
|
|
||||||
auto nMask = tvg::Shape::gen();
|
|
||||||
nMask->appendCircle(220, 220, 125, 125);
|
|
||||||
nMask->fill(255, 200, 255);
|
|
||||||
|
|
||||||
mask->mask(nMask, tvg::MaskMethod::Luma);
|
|
||||||
shape->mask(mask, tvg::MaskMethod::Luma);
|
|
||||||
canvas->push(shape);
|
|
||||||
|
|
||||||
//SVG
|
|
||||||
auto svg = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
|
||||||
svg->opacity(100);
|
|
||||||
svg->scale(3);
|
|
||||||
svg->translate(50, 400);
|
|
||||||
|
|
||||||
//Mask2
|
|
||||||
auto mask2 = tvg::Shape::gen();
|
|
||||||
mask2->appendCircle(150, 500, 75, 75);
|
|
||||||
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
|
||||||
mask2->fill(255, 255, 255);
|
|
||||||
svg->mask(mask2, tvg::MaskMethod::Luma);
|
|
||||||
canvas->push(svg);
|
|
||||||
|
|
||||||
//Star
|
|
||||||
auto star = tvg::Shape::gen();
|
|
||||||
star->fill(80, 80, 80);
|
|
||||||
star->moveTo(599, 34);
|
|
||||||
star->lineTo(653, 143);
|
|
||||||
star->lineTo(774, 160);
|
|
||||||
star->lineTo(687, 244);
|
|
||||||
star->lineTo(707, 365);
|
|
||||||
star->lineTo(599, 309);
|
|
||||||
star->lineTo(497, 365);
|
|
||||||
star->lineTo(512, 245);
|
|
||||||
star->lineTo(426, 161);
|
|
||||||
star->lineTo(546, 143);
|
|
||||||
star->close();
|
|
||||||
star->strokeWidth(10);
|
|
||||||
star->strokeFill(255, 255, 255);
|
|
||||||
|
|
||||||
//Mask3
|
|
||||||
auto mask3 = tvg::Shape::gen();
|
|
||||||
mask3->appendCircle(600, 200, 125, 125);
|
|
||||||
mask3->fill(0, 255, 255);
|
|
||||||
star->mask(mask3, tvg::MaskMethod::Luma);
|
|
||||||
canvas->push(star);
|
|
||||||
|
|
||||||
//Image
|
//Image
|
||||||
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
||||||
if (!file.is_open()) return false;
|
if (!file.is_open()) return false;
|
||||||
|
@ -97,22 +39,161 @@ struct UserExample : tvgexam::Example
|
||||||
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
file.read(reinterpret_cast<char *>(data), sizeof (uint32_t) * 200 * 300);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
auto image = tvg::Picture::gen();
|
//Luma Masking
|
||||||
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
{
|
||||||
image->translate(500, 400);
|
//Solid Rectangle
|
||||||
|
auto shape = tvg::Shape::gen();
|
||||||
|
shape->appendRect(0, 0, 400, 400);
|
||||||
|
shape->fill(255, 0, 0);
|
||||||
|
|
||||||
//Mask4
|
//Mask
|
||||||
auto mask4 = tvg::Scene::gen();
|
auto mask = tvg::Shape::gen();
|
||||||
auto mask4_rect = tvg::Shape::gen();
|
mask->appendCircle(200, 200, 125, 125);
|
||||||
mask4_rect->appendRect(500, 400, 200, 300);
|
mask->fill(255, 100, 255);
|
||||||
mask4_rect->fill(255, 255, 255);
|
|
||||||
auto mask4_circle = tvg::Shape::gen();
|
//Nested Mask
|
||||||
mask4_circle->appendCircle(600, 550, 125, 125);
|
auto nMask = tvg::Shape::gen();
|
||||||
mask4_circle->fill(128, 0, 128);
|
nMask->appendCircle(220, 220, 125, 125);
|
||||||
mask4->push(mask4_rect);
|
nMask->fill(255, 200, 255);
|
||||||
mask4->push(mask4_circle);
|
|
||||||
image->mask(mask4, tvg::MaskMethod::Luma);
|
mask->mask(nMask, tvg::MaskMethod::Luma);
|
||||||
canvas->push(image);
|
shape->mask(mask, tvg::MaskMethod::Luma);
|
||||||
|
canvas->push(shape);
|
||||||
|
|
||||||
|
//SVG
|
||||||
|
auto svg = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
||||||
|
svg->opacity(100);
|
||||||
|
svg->scale(3);
|
||||||
|
svg->translate(50, 400);
|
||||||
|
|
||||||
|
//Mask2
|
||||||
|
auto mask2 = tvg::Shape::gen();
|
||||||
|
mask2->appendCircle(150, 500, 75, 75);
|
||||||
|
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
||||||
|
mask2->fill(255, 255, 255);
|
||||||
|
svg->mask(mask2, tvg::MaskMethod::Luma);
|
||||||
|
canvas->push(svg);
|
||||||
|
|
||||||
|
//Star
|
||||||
|
auto star = tvg::Shape::gen();
|
||||||
|
star->fill(80, 80, 80);
|
||||||
|
star->moveTo(599, 34);
|
||||||
|
star->lineTo(653, 143);
|
||||||
|
star->lineTo(774, 160);
|
||||||
|
star->lineTo(687, 244);
|
||||||
|
star->lineTo(707, 365);
|
||||||
|
star->lineTo(599, 309);
|
||||||
|
star->lineTo(497, 365);
|
||||||
|
star->lineTo(512, 245);
|
||||||
|
star->lineTo(426, 161);
|
||||||
|
star->lineTo(546, 143);
|
||||||
|
star->close();
|
||||||
|
star->strokeWidth(10);
|
||||||
|
star->strokeFill(255, 255, 255);
|
||||||
|
|
||||||
|
//Mask3
|
||||||
|
auto mask3 = tvg::Shape::gen();
|
||||||
|
mask3->appendCircle(600, 200, 125, 125);
|
||||||
|
mask3->fill(0, 255, 255);
|
||||||
|
star->mask(mask3, tvg::MaskMethod::Luma);
|
||||||
|
canvas->push(star);
|
||||||
|
|
||||||
|
auto image = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
||||||
|
image->translate(500, 400);
|
||||||
|
|
||||||
|
//Mask4
|
||||||
|
auto mask4 = tvg::Scene::gen();
|
||||||
|
auto mask4_rect = tvg::Shape::gen();
|
||||||
|
mask4_rect->appendRect(500, 400, 200, 300);
|
||||||
|
mask4_rect->fill(255, 255, 255);
|
||||||
|
auto mask4_circle = tvg::Shape::gen();
|
||||||
|
mask4_circle->appendCircle(600, 550, 125, 125);
|
||||||
|
mask4_circle->fill(128, 0, 128);
|
||||||
|
mask4->push(mask4_rect);
|
||||||
|
mask4->push(mask4_circle);
|
||||||
|
image->mask(mask4, tvg::MaskMethod::Luma);
|
||||||
|
canvas->push(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Inverse Luma Masking
|
||||||
|
{
|
||||||
|
//Solid Rectangle
|
||||||
|
auto shape = tvg::Shape::gen();
|
||||||
|
shape->appendRect(800, 0, 400, 400);
|
||||||
|
shape->fill(255, 0, 0);
|
||||||
|
|
||||||
|
//Mask
|
||||||
|
auto mask = tvg::Shape::gen();
|
||||||
|
mask->appendCircle(1000, 200, 125, 125);
|
||||||
|
mask->fill(255, 100, 255);
|
||||||
|
|
||||||
|
//Nested Mask
|
||||||
|
auto nMask = tvg::Shape::gen();
|
||||||
|
nMask->appendCircle(1020, 220, 125, 125);
|
||||||
|
nMask->fill(255, 200, 255);
|
||||||
|
|
||||||
|
mask->mask(nMask, tvg::MaskMethod::InvLuma);
|
||||||
|
shape->mask(mask, tvg::MaskMethod::InvLuma);
|
||||||
|
canvas->push(shape);
|
||||||
|
|
||||||
|
//SVG
|
||||||
|
auto svg = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
||||||
|
svg->opacity(100);
|
||||||
|
svg->scale(3);
|
||||||
|
svg->translate(850, 400);
|
||||||
|
|
||||||
|
//Mask2
|
||||||
|
auto mask2 = tvg::Shape::gen();
|
||||||
|
mask2->appendCircle(950, 500, 75, 75);
|
||||||
|
mask2->appendRect(950, 500, 200, 200, 30, 30);
|
||||||
|
mask2->fill(255, 255, 255);
|
||||||
|
svg->mask(mask2, tvg::MaskMethod::InvLuma);
|
||||||
|
canvas->push(svg);
|
||||||
|
|
||||||
|
//Star
|
||||||
|
auto star = tvg::Shape::gen();
|
||||||
|
star->fill(80, 80, 80);
|
||||||
|
star->moveTo(1399, 34);
|
||||||
|
star->lineTo(1453, 143);
|
||||||
|
star->lineTo(1574, 160);
|
||||||
|
star->lineTo(1487, 244);
|
||||||
|
star->lineTo(1507, 365);
|
||||||
|
star->lineTo(1399, 309);
|
||||||
|
star->lineTo(1297, 365);
|
||||||
|
star->lineTo(1312, 245);
|
||||||
|
star->lineTo(1226, 161);
|
||||||
|
star->lineTo(1346, 143);
|
||||||
|
star->close();
|
||||||
|
star->strokeWidth(10);
|
||||||
|
star->strokeFill(255, 255, 255);
|
||||||
|
|
||||||
|
//Mask3
|
||||||
|
auto mask3 = tvg::Shape::gen();
|
||||||
|
mask3->appendCircle(1400, 200, 125, 125);
|
||||||
|
mask3->fill(0, 255, 255);
|
||||||
|
star->mask(mask3, tvg::MaskMethod::InvLuma);
|
||||||
|
canvas->push(star);
|
||||||
|
|
||||||
|
auto image = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
||||||
|
image->translate(1300, 400);
|
||||||
|
|
||||||
|
//Mask4
|
||||||
|
auto mask4 = tvg::Scene::gen();
|
||||||
|
auto mask4_rect = tvg::Shape::gen();
|
||||||
|
mask4_rect->appendRect(1300, 400, 200, 300);
|
||||||
|
mask4_rect->fill(255, 255, 255);
|
||||||
|
auto mask4_circle = tvg::Shape::gen();
|
||||||
|
mask4_circle->appendCircle(1400, 550, 125, 125);
|
||||||
|
mask4_circle->fill(128, 0, 128);
|
||||||
|
mask4->push(mask4_rect);
|
||||||
|
mask4->push(mask4_circle);
|
||||||
|
image->mask(mask4, tvg::MaskMethod::InvLuma);
|
||||||
|
canvas->push(image);
|
||||||
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
|
@ -127,5 +208,5 @@ struct UserExample : tvgexam::Example
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return tvgexam::main(new UserExample, argc, argv);
|
return tvgexam::main(new UserExample, argc, argv, false, 1600, 800);
|
||||||
}
|
}
|
|
@ -32,66 +32,6 @@ struct UserExample : tvgexam::Example
|
||||||
{
|
{
|
||||||
if (!canvas) return false;
|
if (!canvas) return false;
|
||||||
|
|
||||||
//Solid Rectangle
|
|
||||||
auto shape = tvg::Shape::gen();
|
|
||||||
shape->appendRect(0, 0, 400, 400);
|
|
||||||
shape->fill(0, 0, 255);
|
|
||||||
|
|
||||||
//Mask
|
|
||||||
auto mask = tvg::Shape::gen();
|
|
||||||
mask->appendCircle(200, 200, 125, 125);
|
|
||||||
mask->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
|
||||||
|
|
||||||
//Nested Mask
|
|
||||||
auto nMask = tvg::Shape::gen();
|
|
||||||
nMask->appendCircle(220, 220, 125, 125);
|
|
||||||
nMask->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
|
||||||
|
|
||||||
mask->mask(nMask, tvg::MaskMethod::Alpha);
|
|
||||||
shape->mask(mask, tvg::MaskMethod::Alpha);
|
|
||||||
canvas->push(shape);
|
|
||||||
|
|
||||||
//SVG
|
|
||||||
auto svg = tvg::Picture::gen();
|
|
||||||
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
|
||||||
svg->opacity(100);
|
|
||||||
svg->scale(3);
|
|
||||||
svg->translate(50, 400);
|
|
||||||
|
|
||||||
//Mask2
|
|
||||||
auto mask2 = tvg::Shape::gen();
|
|
||||||
mask2->appendCircle(150, 500, 75, 75);
|
|
||||||
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
|
||||||
mask2->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
|
||||||
svg->mask(mask2, tvg::MaskMethod::Alpha);
|
|
||||||
canvas->push(svg);
|
|
||||||
|
|
||||||
//Star
|
|
||||||
auto star = tvg::Shape::gen();
|
|
||||||
star->fill(80, 80, 80);
|
|
||||||
star->moveTo(599, 34);
|
|
||||||
star->lineTo(653, 143);
|
|
||||||
star->lineTo(774, 160);
|
|
||||||
star->lineTo(687, 244);
|
|
||||||
star->lineTo(707, 365);
|
|
||||||
star->lineTo(599, 309);
|
|
||||||
star->lineTo(497, 365);
|
|
||||||
star->lineTo(512, 245);
|
|
||||||
star->lineTo(426, 161);
|
|
||||||
star->lineTo(546, 143);
|
|
||||||
star->close();
|
|
||||||
star->strokeWidth(30);
|
|
||||||
star->strokeJoin(tvg::StrokeJoin::Miter);
|
|
||||||
star->strokeFill(255, 255, 255);
|
|
||||||
|
|
||||||
//Mask3
|
|
||||||
auto mask3 = tvg::Shape::gen();
|
|
||||||
mask3->appendCircle(600, 200, 125, 125);
|
|
||||||
mask3->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
|
||||||
mask3->opacity(200);
|
|
||||||
star->mask(mask3, tvg::MaskMethod::Alpha);
|
|
||||||
canvas->push(star);
|
|
||||||
|
|
||||||
//Image
|
//Image
|
||||||
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
ifstream file(EXAMPLE_DIR"/image/rawimage_200x300.raw", ios::binary);
|
||||||
if (!file.is_open()) return false;
|
if (!file.is_open()) return false;
|
||||||
|
@ -99,27 +39,173 @@ struct UserExample : tvgexam::Example
|
||||||
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);
|
file.read(reinterpret_cast<char*>(data), sizeof (uint32_t) * 200 * 300);
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
auto image = tvg::Picture::gen();
|
//Masking
|
||||||
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
{
|
||||||
image->translate(500, 400);
|
//Solid Rectangle
|
||||||
|
auto shape = tvg::Shape::gen();
|
||||||
|
shape->appendRect(0, 0, 400, 400);
|
||||||
|
shape->fill(0, 0, 255);
|
||||||
|
|
||||||
//Mask4
|
//Mask
|
||||||
auto mask4 = tvg::Shape::gen();
|
auto mask = tvg::Shape::gen();
|
||||||
mask4->moveTo(599, 384);
|
mask->appendCircle(200, 200, 125, 125);
|
||||||
mask4->lineTo(653, 493);
|
mask->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
||||||
mask4->lineTo(774, 510);
|
|
||||||
mask4->lineTo(687, 594);
|
//Nested Mask
|
||||||
mask4->lineTo(707, 715);
|
auto nMask = tvg::Shape::gen();
|
||||||
mask4->lineTo(599, 659);
|
nMask->appendCircle(220, 220, 125, 125);
|
||||||
mask4->lineTo(497, 715);
|
nMask->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
||||||
mask4->lineTo(512, 595);
|
|
||||||
mask4->lineTo(426, 511);
|
mask->mask(nMask, tvg::MaskMethod::Alpha);
|
||||||
mask4->lineTo(546, 493);
|
shape->mask(mask, tvg::MaskMethod::Alpha);
|
||||||
mask4->close();
|
canvas->push(shape);
|
||||||
mask4->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
|
||||||
mask4->opacity(70);
|
//SVG
|
||||||
image->mask(mask4, tvg::MaskMethod::Alpha);
|
auto svg = tvg::Picture::gen();
|
||||||
canvas->push(image);
|
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
||||||
|
svg->opacity(100);
|
||||||
|
svg->scale(3);
|
||||||
|
svg->translate(50, 400);
|
||||||
|
|
||||||
|
//Mask2
|
||||||
|
auto mask2 = tvg::Shape::gen();
|
||||||
|
mask2->appendCircle(150, 500, 75, 75);
|
||||||
|
mask2->appendRect(150, 500, 200, 200, 30, 30);
|
||||||
|
mask2->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
||||||
|
svg->mask(mask2, tvg::MaskMethod::Alpha);
|
||||||
|
canvas->push(svg);
|
||||||
|
|
||||||
|
//Star
|
||||||
|
auto star = tvg::Shape::gen();
|
||||||
|
star->fill(80, 80, 80);
|
||||||
|
star->moveTo(599, 34);
|
||||||
|
star->lineTo(653, 143);
|
||||||
|
star->lineTo(774, 160);
|
||||||
|
star->lineTo(687, 244);
|
||||||
|
star->lineTo(707, 365);
|
||||||
|
star->lineTo(599, 309);
|
||||||
|
star->lineTo(497, 365);
|
||||||
|
star->lineTo(512, 245);
|
||||||
|
star->lineTo(426, 161);
|
||||||
|
star->lineTo(546, 143);
|
||||||
|
star->close();
|
||||||
|
star->strokeWidth(30);
|
||||||
|
star->strokeJoin(tvg::StrokeJoin::Miter);
|
||||||
|
star->strokeFill(255, 255, 255);
|
||||||
|
|
||||||
|
//Mask3
|
||||||
|
auto mask3 = tvg::Shape::gen();
|
||||||
|
mask3->appendCircle(600, 200, 125, 125);
|
||||||
|
mask3->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
||||||
|
mask3->opacity(200);
|
||||||
|
star->mask(mask3, tvg::MaskMethod::Alpha);
|
||||||
|
canvas->push(star);
|
||||||
|
|
||||||
|
auto image = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ARGB8888, true))) return false;
|
||||||
|
image->translate(500, 400);
|
||||||
|
|
||||||
|
//Mask4
|
||||||
|
auto mask4 = tvg::Shape::gen();
|
||||||
|
mask4->moveTo(599, 384);
|
||||||
|
mask4->lineTo(653, 493);
|
||||||
|
mask4->lineTo(774, 510);
|
||||||
|
mask4->lineTo(687, 594);
|
||||||
|
mask4->lineTo(707, 715);
|
||||||
|
mask4->lineTo(599, 659);
|
||||||
|
mask4->lineTo(497, 715);
|
||||||
|
mask4->lineTo(512, 595);
|
||||||
|
mask4->lineTo(426, 511);
|
||||||
|
mask4->lineTo(546, 493);
|
||||||
|
mask4->close();
|
||||||
|
mask4->fill(255, 255, 255); //AlphaMask RGB channels are unused.
|
||||||
|
mask4->opacity(70);
|
||||||
|
image->mask(mask4, tvg::MaskMethod::Alpha);
|
||||||
|
canvas->push(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Inverse Masking
|
||||||
|
{
|
||||||
|
//Solid Rectangle
|
||||||
|
auto shape = tvg::Shape::gen();
|
||||||
|
shape->appendRect(800, 0, 400, 400);
|
||||||
|
shape->fill(0, 0, 255);
|
||||||
|
|
||||||
|
//Mask
|
||||||
|
auto mask = tvg::Shape::gen();
|
||||||
|
mask->appendCircle(1000, 200, 125, 125);
|
||||||
|
mask->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
||||||
|
|
||||||
|
//Nested Mask
|
||||||
|
auto nMask = tvg::Shape::gen();
|
||||||
|
nMask->appendCircle(1020, 220, 125, 125);
|
||||||
|
nMask->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
||||||
|
|
||||||
|
mask->mask(nMask, tvg::MaskMethod::InvAlpha);
|
||||||
|
shape->mask(mask, tvg::MaskMethod::InvAlpha);
|
||||||
|
canvas->push(shape);
|
||||||
|
|
||||||
|
//SVG
|
||||||
|
auto svg = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(svg->load(EXAMPLE_DIR"/svg/cartman.svg"))) return false;
|
||||||
|
svg->opacity(100);
|
||||||
|
svg->scale(3);
|
||||||
|
svg->translate(850, 400);
|
||||||
|
|
||||||
|
//Mask2
|
||||||
|
auto mask2 = tvg::Shape::gen();
|
||||||
|
mask2->appendCircle(950, 500, 75, 75);
|
||||||
|
mask2->appendRect(950, 500, 200, 200, 30, 30);
|
||||||
|
mask2->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
||||||
|
svg->mask(mask2, tvg::MaskMethod::InvAlpha);
|
||||||
|
canvas->push(svg);
|
||||||
|
|
||||||
|
//Star
|
||||||
|
auto star = tvg::Shape::gen();
|
||||||
|
star->fill(80, 80, 80);
|
||||||
|
star->moveTo(1399, 34);
|
||||||
|
star->lineTo(1453, 143);
|
||||||
|
star->lineTo(1574, 160);
|
||||||
|
star->lineTo(1487, 244);
|
||||||
|
star->lineTo(1507, 365);
|
||||||
|
star->lineTo(1399, 309);
|
||||||
|
star->lineTo(1297, 365);
|
||||||
|
star->lineTo(1312, 245);
|
||||||
|
star->lineTo(1226, 161);
|
||||||
|
star->lineTo(1346, 143);
|
||||||
|
star->close();
|
||||||
|
star->strokeWidth(10);
|
||||||
|
star->strokeFill(255, 255, 255);
|
||||||
|
|
||||||
|
//Mask3
|
||||||
|
auto mask3 = tvg::Shape::gen();
|
||||||
|
mask3->appendCircle(1400, 200, 125, 125);
|
||||||
|
mask3->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
||||||
|
star->mask(mask3, tvg::MaskMethod::InvAlpha);
|
||||||
|
canvas->push(star);
|
||||||
|
|
||||||
|
auto image = tvg::Picture::gen();
|
||||||
|
if (!tvgexam::verify(image->load(data, 200, 300, tvg::ColorSpace::ABGR8888, true))) return false;
|
||||||
|
image->translate(1300, 400);
|
||||||
|
|
||||||
|
//Mask4
|
||||||
|
auto mask4 = tvg::Shape::gen();
|
||||||
|
mask4->moveTo(1399, 384);
|
||||||
|
mask4->lineTo(1453, 493);
|
||||||
|
mask4->lineTo(1574, 510);
|
||||||
|
mask4->lineTo(1487, 594);
|
||||||
|
mask4->lineTo(1507, 715);
|
||||||
|
mask4->lineTo(1399, 659);
|
||||||
|
mask4->lineTo(1297, 715);
|
||||||
|
mask4->lineTo(1312, 595);
|
||||||
|
mask4->lineTo(1226, 511);
|
||||||
|
mask4->lineTo(1346, 493);
|
||||||
|
mask4->close();
|
||||||
|
mask4->fill(255, 255, 255); //InvAlphaMask RGB channels are unused.
|
||||||
|
mask4->opacity(70);
|
||||||
|
image->mask(mask4, tvg::MaskMethod::InvAlpha);
|
||||||
|
canvas->push(image);
|
||||||
|
}
|
||||||
|
|
||||||
free(data);
|
free(data);
|
||||||
|
|
||||||
|
@ -134,5 +220,5 @@ struct UserExample : tvgexam::Example
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return tvgexam::main(new UserExample, argc, argv);
|
return tvgexam::main(new UserExample, argc, argv, false, 1600, 800);
|
||||||
}
|
}
|
|
@ -49,6 +49,9 @@ struct UserExample : tvgexam::Example
|
||||||
shape2->translate(300, 300);
|
shape2->translate(300, 300);
|
||||||
shape2->fill(0, 155, 50, 100);
|
shape2->fill(0, 155, 50, 100);
|
||||||
shape2->strokeFill(0, 255, 0);
|
shape2->strokeFill(0, 255, 0);
|
||||||
|
|
||||||
|
float dashPatterns[] = {10, 20};
|
||||||
|
shape2->strokeDash(dashPatterns, 2, 10);
|
||||||
shape2->strokeTrim(0.25f, 0.75f, true);
|
shape2->strokeTrim(0.25f, 0.75f, true);
|
||||||
|
|
||||||
canvas->push(shape1);
|
canvas->push(shape1);
|
||||||
|
|
|
@ -40,8 +40,6 @@ source_file = [
|
||||||
'ImageRotation.cpp',
|
'ImageRotation.cpp',
|
||||||
'ImageScaleDown.cpp',
|
'ImageScaleDown.cpp',
|
||||||
'ImageScaleUp.cpp',
|
'ImageScaleUp.cpp',
|
||||||
'InvLumaMasking.cpp',
|
|
||||||
'InvMasking.cpp',
|
|
||||||
'LinearGradient.cpp',
|
'LinearGradient.cpp',
|
||||||
'Lottie.cpp',
|
'Lottie.cpp',
|
||||||
'LumaMasking.cpp',
|
'LumaMasking.cpp',
|
||||||
|
|
Loading…
Add table
Reference in a new issue