Common and VideoCommon: Change texture data from std::vector to Common::UniqueBuffer.

This commit is contained in:
Jordan Woyak
2025-05-03 17:36:22 -05:00
parent a736d2ed5f
commit 5a80105555
8 changed files with 36 additions and 33 deletions

View File

@ -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;
}
}