[aseprite] 102/250: Use RAII helper to avoid calling WebPPictureFree for each return in WebPFormat::onSave()
Tobias Hansen
thansen at moszumanska.debian.org
Sun Dec 20 15:27:17 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit a5bdf461f44190bfedec9bc30d270b84450635b7
Author: David Capello <davidcapello at gmail.com>
Date: Tue Sep 29 12:06:33 2015 -0300
Use RAII helper to avoid calling WebPPictureFree for each return in WebPFormat::onSave()
---
src/app/file/webp_format.cpp | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/app/file/webp_format.cpp b/src/app/file/webp_format.cpp
index c48ff0c..b843c27 100644
--- a/src/app/file/webp_format.cpp
+++ b/src/app/file/webp_format.cpp
@@ -170,6 +170,17 @@ struct WriterData {
FileOp* fop;
};
+class ScopedWebPPicture {
+public:
+ ScopedWebPPicture(WebPPicture& pic) : m_pic(pic) {
+ }
+ ~ScopedWebPPicture() {
+ WebPPictureFree(&m_pic);
+ }
+private:
+ WebPPicture& m_pic;
+};
+
const char* getEncoderErrorMessage(WebPEncodingError errorCode) {
switch (errorCode) {
case VP8_ENC_OK: return ""; break;
@@ -280,9 +291,10 @@ bool WebPFormat::onSave(FileOp* fop)
return false;
}
+ ScopedWebPPicture scopedPic(pic); // Calls WebPPictureFree automatically
+
if (!WebPPictureImportRGBA(&pic, (uint8_t*)image->getPixelAddress(0, 0), image->width() * sizeof(uint32_t))) {
fop->setError("Error converting RGBA data into a WebP picture\n");
- WebPPictureFree(&pic);
return false;
}
@@ -293,11 +305,9 @@ bool WebPFormat::onSave(FileOp* fop)
if (!WebPEncode(&config, &pic)) {
fop->setError("Error encoding image into WebP: %s\n",
getEncoderErrorMessage(pic.error_code));
- WebPPictureFree(&pic);
return false;
}
- WebPPictureFree(&pic);
return true;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list