mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-15 16:59:18 +01:00
Common: Add SavePNG() function that writes PNGs using the simplified libpng API.
This commit is contained in:
parent
4c9ffb58fa
commit
2de3b12e9d
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Common/Image.h"
|
#include "Common/Image.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <png.h>
|
#include <png.h>
|
||||||
@ -37,4 +38,31 @@ bool LoadPNG(const std::vector<u8>& input, std::vector<u8>* data_out, u32* width
|
|||||||
|
|
||||||
return true;
|
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
|
} // namespace Common
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
@ -12,4 +13,13 @@ namespace Common
|
|||||||
{
|
{
|
||||||
bool LoadPNG(const std::vector<u8>& input, std::vector<u8>* data_out, u32* width_out,
|
bool LoadPNG(const std::vector<u8>& input, std::vector<u8>* data_out, u32* width_out,
|
||||||
u32* height_out);
|
u32* height_out);
|
||||||
}
|
|
||||||
|
enum class ImageByteFormat
|
||||||
|
{
|
||||||
|
RGB,
|
||||||
|
RGBA,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool SavePNG(const std::string& path, const u8* input, ImageByteFormat format, u32 width,
|
||||||
|
u32 height, int stride = 0);
|
||||||
|
} // namespace Common
|
||||||
|
Loading…
x
Reference in New Issue
Block a user