mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
example: refactoring
This commit is contained in:
parent
702f452c6c
commit
cfacdd705f
2 changed files with 7 additions and 13 deletions
|
@ -5,8 +5,6 @@
|
|||
/* Drawing Commands */
|
||||
/************************************************************************/
|
||||
|
||||
uint32_t *data = nullptr;
|
||||
|
||||
void tvgDrawCmds(tvg::Canvas* canvas)
|
||||
{
|
||||
if (!canvas) return;
|
||||
|
@ -27,7 +25,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
colorStops[1] = {1,255,255,255,255};
|
||||
fill->colorStops(colorStops,2);
|
||||
shape->fill(move(fill));
|
||||
|
||||
|
||||
shape->composite(move(mask), tvg::CompositeMethod::AlphaMask);
|
||||
canvas->push(move(shape));
|
||||
|
||||
|
@ -59,7 +57,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
colorStops1[1] = {1,1,255,255,255};
|
||||
fill1->colorStops(colorStops1,2);
|
||||
shape1->fill(move(fill1));
|
||||
|
||||
|
||||
shape1->composite(move(mask1), tvg::CompositeMethod::AlphaMask);
|
||||
canvas->push(move(shape1));
|
||||
|
||||
|
@ -81,7 +79,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
colorStops2[1] = {1,255,255,255,255};
|
||||
fill2->colorStops(colorStops2,2);
|
||||
shape2->fill(move(fill2));
|
||||
|
||||
|
||||
shape2->composite(move(mask2), tvg::CompositeMethod::InvAlphaMask);
|
||||
canvas->push(move(shape2));
|
||||
|
||||
|
@ -113,7 +111,7 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
colorStops3[1] = {1,1,255,255,255};
|
||||
fill3->colorStops(colorStops3,2);
|
||||
shape3->fill(move(fill3));
|
||||
|
||||
|
||||
shape3->composite(move(mask3), tvg::CompositeMethod::InvAlphaMask);
|
||||
canvas->push(move(shape3));
|
||||
|
||||
|
@ -219,8 +217,6 @@ int main(int argc, char **argv)
|
|||
//Terminate ThorVG Engine
|
||||
tvg::Initializer::term(tvg::CanvasEngine::Sw);
|
||||
|
||||
if (data) free(data);
|
||||
|
||||
} else {
|
||||
cout << "engine is not supported" << endl;
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
/* Drawing Commands */
|
||||
/************************************************************************/
|
||||
|
||||
uint32_t *data = nullptr;
|
||||
|
||||
void tvgDrawCmds(tvg::Canvas* canvas)
|
||||
{
|
||||
if (!canvas) return;
|
||||
|
@ -87,13 +85,15 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
//Image
|
||||
ifstream file(EXAMPLE_DIR"/rawimage_200x300.raw");
|
||||
if (!file.is_open()) return;
|
||||
data = (uint32_t*) malloc(sizeof(uint32_t) * (200 * 300));
|
||||
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 (image->load(data, 200, 300, true) != tvg::Result::Success) return;
|
||||
image->translate(500, 400);
|
||||
free(data);
|
||||
|
||||
|
||||
//Mask4
|
||||
auto mask4 = tvg::Shape::gen();
|
||||
|
@ -214,8 +214,6 @@ int main(int argc, char **argv)
|
|||
//Terminate ThorVG Engine
|
||||
tvg::Initializer::term(tvg::CanvasEngine::Sw);
|
||||
|
||||
if (data) free(data);
|
||||
|
||||
} else {
|
||||
cout << "engine is not supported" << endl;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue