mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
wasm: optimize TVG saving Logic
Optimized the saving logic for TVG. Copying the picture is unnecessary; the logic now directly utilizes the currently held picture.
This commit is contained in:
parent
06a34a4c65
commit
059939f2ed
1 changed files with 8 additions and 8 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <thorvg.h>
|
||||
#include <emscripten/bind.h>
|
||||
#include "tvgPicture.h"
|
||||
|
||||
using namespace emscripten;
|
||||
using namespace std;
|
||||
|
@ -236,26 +237,25 @@ public:
|
|||
|
||||
if (!animation) return false;
|
||||
|
||||
auto duplicate = cast<Picture>(animation->picture()->duplicate());
|
||||
|
||||
if (!duplicate) {
|
||||
errorMsg = "duplicate(), fail";
|
||||
return false;
|
||||
}
|
||||
|
||||
auto saver = Saver::gen();
|
||||
if (!saver) {
|
||||
errorMsg = "Invalid saver";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (saver->save(std::move(duplicate), "output.tvg") != tvg::Result::Success) {
|
||||
//preserve the picture using the reference counting
|
||||
PP(animation->picture())->ref();
|
||||
|
||||
if (saver->save(tvg::cast<Picture>(animation->picture()), "output.tvg") != tvg::Result::Success) {
|
||||
PP(animation->picture())->unref();
|
||||
errorMsg = "save(), fail";
|
||||
return false;
|
||||
}
|
||||
|
||||
saver->sync();
|
||||
|
||||
PP(animation->picture())->unref();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue