diff options
Diffstat (limited to 'Source/Core/InputCommon/ImageOperations.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ImageOperations.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Source/Core/InputCommon/ImageOperations.cpp b/Source/Core/InputCommon/ImageOperations.cpp index 04293c9183..907cb52b8d 100644 --- a/Source/Core/InputCommon/ImageOperations.cpp +++ b/Source/Core/InputCommon/ImageOperations.cpp @@ -5,12 +5,9 @@ #include <algorithm> #include <cmath> -#include <limits> -#include <stack> #include <string> #include <vector> -#include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Common/Image.h" @@ -49,11 +46,11 @@ std::optional<ImagePixelData> LoadImage(const std::string& path) { File::IOFile file; file.Open(path, "rb"); - std::vector<u8> buffer(file.GetSize()); + Common::UniqueBuffer<u8> buffer(file.GetSize()); file.ReadBytes(buffer.data(), file.GetSize()); ImagePixelData image; - std::vector<u8> data; + Common::UniqueBuffer<u8> data; if (!Common::LoadPNG(buffer, &data, &image.width, &image.height)) return std::nullopt; @@ -74,19 +71,20 @@ std::optional<ImagePixelData> LoadImage(const std::string& path) bool WriteImage(const std::string& path, const ImagePixelData& image) { - std::vector<u8> buffer; - buffer.reserve(image.width * image.height * 4); + Common::UniqueBuffer<u8> buffer; + buffer.reset(image.width * image.height * 4); + std::size_t buffer_index = 0; for (u32 y = 0; y < image.height; ++y) { for (u32 x = 0; x < image.width; ++x) { const auto index = x + y * image.width; const auto pixel = image.pixels[index]; - buffer.push_back(pixel.r); - buffer.push_back(pixel.g); - buffer.push_back(pixel.b); - buffer.push_back(pixel.a); + buffer[buffer_index++] = pixel.r; + buffer[buffer_index++] = pixel.g; + buffer[buffer_index++] = pixel.b; + buffer[buffer_index++] = pixel.a; } } |
