summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Image.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-12-11 10:24:16 +0100
committerGitHub <noreply@github.com>2020-12-11 10:24:16 +0100
commitfd5c69deca4aa988a445b29c6c2292d586c0bf45 (patch)
tree38cac804ecaa164de1961eb2f8abe7139a26b105 /Source/Core/Common/Image.cpp
parent2e63cc8313f01b7720f555ba72219f134eb298fa (diff)
parent324de7fa02f101ee7031ec20fe628dbc28f04c71 (diff)
Merge pull request #9289 from AdmiralCurtiss/simple-png-api-write
Use Simplified libpng API for writing PNGs.
Diffstat (limited to 'Source/Core/Common/Image.cpp')
-rw-r--r--Source/Core/Common/Image.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/Source/Core/Common/Image.cpp b/Source/Core/Common/Image.cpp
index 91d1bc68e0..678a64db8c 100644
--- a/Source/Core/Common/Image.cpp
+++ b/Source/Core/Common/Image.cpp
@@ -4,6 +4,7 @@
#include "Common/Image.h"
+#include <string>
#include <vector>
#include <png.h>
@@ -37,4 +38,31 @@ bool LoadPNG(const std::vector<u8>& input, std::vector<u8>* data_out, u32* width
return true;
}
+
+bool SavePNG(const std::string& path, const u8* input, ImageByteFormat format, u32 width,
+ u32 height, int stride)
+{
+ png_image png = {};
+ png.version = PNG_IMAGE_VERSION;
+ png.width = width;
+ png.height = height;
+
+ switch (format)
+ {
+ case ImageByteFormat::RGB:
+ png.format = PNG_FORMAT_RGB;
+ break;
+ case ImageByteFormat::RGBA:
+ png.format = PNG_FORMAT_RGBA;
+ break;
+ default:
+ return false;
+ }
+
+ png_image_write_to_file(&png, path.c_str(), 0, input, stride, nullptr);
+ if (png.warning_or_error & PNG_IMAGE_ERROR)
+ return false;
+
+ return true;
+}
} // namespace Common