mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Common and VideoCommon: Change texture data from std::vector to Common::UniqueBuffer.
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user