From cfacdd705fe2cef8aeb5de5353818f4799dee253 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Wed, 22 Sep 2021 01:01:49 +0200 Subject: [PATCH] example: refactoring --- src/examples/GradientMasking.cpp | 12 ++++-------- src/examples/InvMasking.cpp | 8 +++----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/examples/GradientMasking.cpp b/src/examples/GradientMasking.cpp index 151bb837..381c3ecf 100644 --- a/src/examples/GradientMasking.cpp +++ b/src/examples/GradientMasking.cpp @@ -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; } diff --git a/src/examples/InvMasking.cpp b/src/examples/InvMasking.cpp index 04f7c2f0..042e0773 100644 --- a/src/examples/InvMasking.cpp +++ b/src/examples/InvMasking.cpp @@ -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(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; }