summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Image.cpp
diff options
context:
space:
mode:
authorLC <mathew1800@gmail.com>2020-12-19 21:45:21 -0500
committerGitHub <noreply@github.com>2020-12-19 21:45:21 -0500
commit0315ca5e37f0f240e1fb7df72e1bb3bc3f7222eb (patch)
tree5af5f79f322b98aaae41f2986e0dc3c0b9399141 /Source/Core/Common/Image.cpp
parent2097de603c1e225dd4fb8118d7c1cfd3f5162471 (diff)
parent0ad2f3da454feca1fc9ba9c3f8592e104028b936 (diff)
Merge pull request #9332 from leoetlino/warning-fixes
Core: Fix various warnings
Diffstat (limited to 'Source/Core/Common/Image.cpp')
-rw-r--r--Source/Core/Common/Image.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/Core/Common/Image.cpp b/Source/Core/Common/Image.cpp
index 478d4b42ab..0621eb64d4 100644
--- a/Source/Core/Common/Image.cpp
+++ b/Source/Core/Common/Image.cpp
@@ -83,4 +83,29 @@ bool SavePNG(const std::string& path, const u8* input, ImageByteFormat format, u
return false;
return outfile.WriteBytes(buffer.data(), size);
}
+
+bool ConvertRGBAToRGBAndSavePNG(const std::string& path, const u8* input, u32 width, u32 height,
+ int stride)
+{
+ const std::vector<u8> data = RGBAToRGB(input, width, height, stride);
+ return SavePNG(path, data.data(), ImageByteFormat::RGB, width, height);
+}
+
+std::vector<u8> RGBAToRGB(const u8* input, u32 width, u32 height, int row_stride)
+{
+ std::vector<u8> buffer;
+ buffer.reserve(width * height * 3);
+
+ for (u32 y = 0; y < height; ++y)
+ {
+ const u8* pos = input + y * row_stride;
+ for (u32 x = 0; x < width; ++x)
+ {
+ buffer.push_back(pos[x * 4]);
+ buffer.push_back(pos[x * 4 + 1]);
+ buffer.push_back(pos[x * 4 + 2]);
+ }
+ }
+ return buffer;
+}
} // namespace Common