mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Use IOFile for TextureToPng to support non-ascii
Changed save texture/screenshot uses to std::string Removed unneeded new/delete calls when dealing with temp data.
This commit is contained in:
@ -26,7 +26,7 @@ Inputs:
|
||||
data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel.
|
||||
row_stride: Determines the amount of bytes per row of pixels.
|
||||
*/
|
||||
bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int height, bool saveAlpha)
|
||||
bool TextureToPng(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@ -35,13 +35,12 @@ bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int
|
||||
|
||||
char title[] = "Dolphin Screenshot";
|
||||
char title_key[] = "Title";
|
||||
FILE *fp = NULL;
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
|
||||
// Open file for writing (binary mode)
|
||||
fp = fopen(filename, "wb");
|
||||
if (fp == NULL) {
|
||||
File::IOFile fp(filename, "wb");
|
||||
if (!fp.IsOpen()) {
|
||||
PanicAlert("Screenshot failed: Could not open file %s %d\n", filename, errno);
|
||||
goto finalise;
|
||||
}
|
||||
@ -67,7 +66,7 @@ bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int
|
||||
goto finalise;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
png_init_io(png_ptr, fp.GetHandle());
|
||||
|
||||
// Write header (8 bit colour depth)
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height,
|
||||
@ -102,8 +101,6 @@ bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int
|
||||
success = true;
|
||||
|
||||
finalise:
|
||||
|
||||
if (fp != NULL) fclose(fp);
|
||||
if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||
if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "Common.h"
|
||||
|
||||
bool SaveData(const char* filename, const char* pdata);
|
||||
bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int height, bool saveAlpha = true);
|
||||
bool TextureToPng(u8* data, int row_stride, const std::string filename, int width, int height, bool saveAlpha = true);
|
||||
|
||||
#endif // _IMAGEWRITE_H
|
||||
|
||||
|
@ -283,7 +283,7 @@ PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsign
|
||||
|
||||
void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level)
|
||||
{
|
||||
char szTemp[MAX_PATH];
|
||||
std::string filename;
|
||||
std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) +
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID;
|
||||
|
||||
@ -295,19 +295,19 @@ void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level)
|
||||
// TODO: TLUT format should actually be stored in filename? :/
|
||||
if (level == 0)
|
||||
{
|
||||
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir.c_str(),
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
||||
(u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF);
|
||||
filename = StringFromFormat("%s/%s_%08x_%i.png", szDir.c_str(),
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
||||
(u32)(entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(szTemp, "%s/%s_%08x_%i_mip%i.png", szDir.c_str(),
|
||||
filename = StringFromFormat("%s/%s_%08x_%i_mip%i.png", szDir.c_str(),
|
||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
||||
(u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF, level);
|
||||
}
|
||||
|
||||
if (false == File::Exists(szTemp))
|
||||
entry->Save(szTemp, level);
|
||||
if (!File::Exists(filename))
|
||||
entry->Save(filename, level);
|
||||
}
|
||||
|
||||
static u32 CalculateLevelSize(u32 level_0_size, u32 level)
|
||||
|
@ -73,7 +73,7 @@ public:
|
||||
virtual ~TCacheEntryBase();
|
||||
|
||||
virtual void Bind(unsigned int stage) = 0;
|
||||
virtual bool Save(const char filename[], unsigned int level) = 0;
|
||||
virtual bool Save(const std::string filename, unsigned int level) = 0;
|
||||
|
||||
virtual void Load(unsigned int width, unsigned int height,
|
||||
unsigned int expanded_width, unsigned int level) = 0;
|
||||
|
Reference in New Issue
Block a user