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:
parent
cce869ae01
commit
33d8166620
|
@ -694,15 +694,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
|
||||||
D3D11_MAPPED_SUBRESOURCE map;
|
D3D11_MAPPED_SUBRESOURCE map;
|
||||||
D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ_WRITE, 0, &map);
|
D3D::context->Map(s_screenshot_texture, 0, D3D11_MAP_READ_WRITE, 0, &map);
|
||||||
|
|
||||||
bool saved_png = false;
|
bool saved_png = TextureToPng((u8*)map.pData, map.RowPitch, filename, rc.GetWidth(), rc.GetHeight(), false);
|
||||||
if (map.pData)
|
|
||||||
{
|
|
||||||
u8* data = new u8[map.RowPitch * rc.GetHeight()];
|
|
||||||
memcpy(data, map.pData, map.RowPitch * rc.GetHeight());
|
|
||||||
|
|
||||||
saved_png = TextureToPng(data, map.RowPitch, filename.c_str(), rc.GetWidth(), rc.GetHeight(), false);
|
|
||||||
delete[] data;
|
|
||||||
}
|
|
||||||
|
|
||||||
D3D::context->Unmap(s_screenshot_texture, 0);
|
D3D::context->Unmap(s_screenshot_texture, 0);
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ void TextureCache::TCacheEntry::Bind(unsigned int stage)
|
||||||
D3D::context->PSSetShaderResources(stage, 1, &texture->GetSRV());
|
D3D::context->PSSetShaderResources(stage, 1, &texture->GetSRV());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
|
bool TextureCache::TCacheEntry::Save(const std::string filename, unsigned int level)
|
||||||
{
|
{
|
||||||
// TODO: Somehow implement this (D3DX11 doesn't support dumping individual LODs)
|
// TODO: Somehow implement this (D3DX11 doesn't support dumping individual LODs)
|
||||||
static bool warn_once = true;
|
static bool warn_once = true;
|
||||||
|
@ -65,14 +65,7 @@ bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
|
||||||
HRESULT hr = D3D::context->Map(pNewTexture, 0, D3D11_MAP_READ_WRITE, 0, &map);
|
HRESULT hr = D3D::context->Map(pNewTexture, 0, D3D11_MAP_READ_WRITE, 0, &map);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
if (map.pData)
|
saved_png = TextureToPng((u8*)map.pData, map.RowPitch, filename, desc.Width, desc.Height);
|
||||||
{
|
|
||||||
u8* data = new u8[map.RowPitch * desc.Height];
|
|
||||||
memcpy(data, map.pData, map.RowPitch * desc.Height);
|
|
||||||
|
|
||||||
saved_png = TextureToPng(data, map.RowPitch, filename, desc.Width, desc.Height);
|
|
||||||
delete[] data;
|
|
||||||
}
|
|
||||||
D3D::context->Unmap(pNewTexture, 0);
|
D3D::context->Unmap(pNewTexture, 0);
|
||||||
}
|
}
|
||||||
SAFE_RELEASE(pNewTexture);
|
SAFE_RELEASE(pNewTexture);
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
const float *colmat);
|
const float *colmat);
|
||||||
|
|
||||||
void Bind(unsigned int stage);
|
void Bind(unsigned int stage);
|
||||||
bool Save(const char filename[], unsigned int level);
|
bool Save(const std::string filename, unsigned int level);
|
||||||
};
|
};
|
||||||
|
|
||||||
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
|
TCacheEntryBase* CreateTexture(unsigned int width, unsigned int height,
|
||||||
|
|
|
@ -1825,7 +1825,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
|
||||||
|
|
||||||
// Turn image upside down
|
// Turn image upside down
|
||||||
FlipImageData(data, W, H, 4);
|
FlipImageData(data, W, H, 4);
|
||||||
bool success = TextureToPng(data, W*4, filename.c_str(), W, H, false);
|
bool success = TextureToPng(data, W*4, filename, W, H, false);
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -59,7 +59,7 @@ struct VBOCache {
|
||||||
};
|
};
|
||||||
static std::map<u64,VBOCache> s_VBO;
|
static std::map<u64,VBOCache> s_VBO;
|
||||||
|
|
||||||
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
|
bool SaveTexture(const std::string filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
|
||||||
{
|
{
|
||||||
#ifndef USE_GLES3
|
#ifndef USE_GLES3
|
||||||
int width = std::max(virtual_width >> level, 1);
|
int width = std::max(virtual_width >> level, 1);
|
||||||
|
@ -127,7 +127,7 @@ void TextureCache::TCacheEntry::Bind(unsigned int stage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
|
bool TextureCache::TCacheEntry::Save(const std::string filename, unsigned int level)
|
||||||
{
|
{
|
||||||
return SaveTexture(filename, GL_TEXTURE_2D, texture, virtual_width, virtual_height, level);
|
return SaveTexture(filename, GL_TEXTURE_2D, texture, virtual_width, virtual_height, level);
|
||||||
}
|
}
|
||||||
|
@ -394,7 +394,7 @@ void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFo
|
||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
SaveTexture(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
SaveTexture(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
||||||
count++).c_str(), GL_TEXTURE_2D, texture, virtual_width, virtual_height, 0);
|
count++), GL_TEXTURE_2D, texture, virtual_width, virtual_height, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_renderer->RestoreAPIState();
|
g_renderer->RestoreAPIState();
|
||||||
|
|
|
@ -53,7 +53,7 @@ private:
|
||||||
const float *colmat) override;
|
const float *colmat) override;
|
||||||
|
|
||||||
void Bind(unsigned int stage) override;
|
void Bind(unsigned int stage) override;
|
||||||
bool Save(const char filename[], unsigned int level);
|
bool Save(const std::string filename, unsigned int level);
|
||||||
};
|
};
|
||||||
|
|
||||||
~TextureCache();
|
~TextureCache();
|
||||||
|
@ -64,7 +64,7 @@ private:
|
||||||
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
|
TCacheEntryBase* CreateRenderTargetTexture(unsigned int scaled_tex_w, unsigned int scaled_tex_h) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level);
|
bool SaveTexture(const std::string filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ void Init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveTexture(const char* filename, u32 texmap, s32 mip)
|
void SaveTexture(const std::string filename, u32 texmap, s32 mip)
|
||||||
{
|
{
|
||||||
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
|
||||||
u8 subTexmap = texmap & 3;
|
u8 subTexmap = texmap & 3;
|
||||||
|
@ -98,7 +98,7 @@ void DumpActiveTextures()
|
||||||
for (s32 mip = 0; mip <= maxLod; ++mip)
|
for (s32 mip = 0; mip <= maxLod; ++mip)
|
||||||
{
|
{
|
||||||
SaveTexture(StringFromFormat("%star%i_ind%i_map%i_mip%i.png",
|
SaveTexture(StringFromFormat("%star%i_ind%i_map%i_mip%i.png",
|
||||||
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
File::GetUserPath(D_DUMPTEXTURES_IDX),
|
||||||
swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
|
swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ void DumpActiveTextures()
|
||||||
for (s32 mip = 0; mip <= maxLod; ++mip)
|
for (s32 mip = 0; mip <= maxLod; ++mip)
|
||||||
{
|
{
|
||||||
SaveTexture(StringFromFormat("%star%i_stage%i_map%i_mip%i.png",
|
SaveTexture(StringFromFormat("%star%i_stage%i_map%i_mip%i.png",
|
||||||
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
File::GetUserPath(D_DUMPTEXTURES_IDX),
|
||||||
swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
|
swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ void OnObjectEnd()
|
||||||
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
|
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
|
||||||
swstats.thisFrame.numDrawnObjects, ObjectBufferName[i], i - BufferBase[i]);
|
swstats.thisFrame.numDrawnObjects, ObjectBufferName[i], i - BufferBase[i]);
|
||||||
|
|
||||||
(void)TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename.c_str(), EFB_WIDTH, EFB_HEIGHT, true);
|
(void)TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
|
||||||
memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i]));
|
memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ void SWRenderer::DrawTexture(u8 *texture, int width, int height)
|
||||||
if (s_bScreenshot)
|
if (s_bScreenshot)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
std::lock_guard<std::mutex> lk(s_criticalScreenshot);
|
||||||
TextureToPng(texture, width*4, s_sScreenshotName.c_str(), width, height, false);
|
TextureToPng(texture, width*4, s_sScreenshotName, width, height, false);
|
||||||
// Reset settings
|
// Reset settings
|
||||||
s_sScreenshotName.clear();
|
s_sScreenshotName.clear();
|
||||||
s_bScreenshot = false;
|
s_bScreenshot = false;
|
||||||
|
|
|
@ -26,7 +26,7 @@ Inputs:
|
||||||
data : This is an array of RGBA with 8 bits per channel. 4 bytes for each pixel.
|
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.
|
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;
|
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[] = "Dolphin Screenshot";
|
||||||
char title_key[] = "Title";
|
char title_key[] = "Title";
|
||||||
FILE *fp = NULL;
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = NULL;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
|
|
||||||
// Open file for writing (binary mode)
|
// Open file for writing (binary mode)
|
||||||
fp = fopen(filename, "wb");
|
File::IOFile fp(filename, "wb");
|
||||||
if (fp == NULL) {
|
if (!fp.IsOpen()) {
|
||||||
PanicAlert("Screenshot failed: Could not open file %s %d\n", filename, errno);
|
PanicAlert("Screenshot failed: Could not open file %s %d\n", filename, errno);
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
|
@ -67,7 +66,7 @@ bool TextureToPng(u8* data, int row_stride, const char* filename, int width, int
|
||||||
goto finalise;
|
goto finalise;
|
||||||
}
|
}
|
||||||
|
|
||||||
png_init_io(png_ptr, fp);
|
png_init_io(png_ptr, fp.GetHandle());
|
||||||
|
|
||||||
// Write header (8 bit colour depth)
|
// Write header (8 bit colour depth)
|
||||||
png_set_IHDR(png_ptr, info_ptr, width, height,
|
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;
|
success = true;
|
||||||
|
|
||||||
finalise:
|
finalise:
|
||||||
|
|
||||||
if (fp != NULL) fclose(fp);
|
|
||||||
if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
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);
|
if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
|
||||||
bool SaveData(const char* filename, const char* pdata);
|
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
|
#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)
|
void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level)
|
||||||
{
|
{
|
||||||
char szTemp[MAX_PATH];
|
std::string filename;
|
||||||
std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) +
|
std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) +
|
||||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID;
|
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? :/
|
// TODO: TLUT format should actually be stored in filename? :/
|
||||||
if (level == 0)
|
if (level == 0)
|
||||||
{
|
{
|
||||||
sprintf(szTemp, "%s/%s_%08x_%i.png", szDir.c_str(),
|
filename = StringFromFormat("%s/%s_%08x_%i.png", szDir.c_str(),
|
||||||
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
||||||
(u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF);
|
(u32)(entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF);
|
||||||
}
|
}
|
||||||
else
|
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(),
|
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(),
|
||||||
(u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF, level);
|
(u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false == File::Exists(szTemp))
|
if (!File::Exists(filename))
|
||||||
entry->Save(szTemp, level);
|
entry->Save(filename, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static u32 CalculateLevelSize(u32 level_0_size, u32 level)
|
static u32 CalculateLevelSize(u32 level_0_size, u32 level)
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
virtual ~TCacheEntryBase();
|
virtual ~TCacheEntryBase();
|
||||||
|
|
||||||
virtual void Bind(unsigned int stage) = 0;
|
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,
|
virtual void Load(unsigned int width, unsigned int height,
|
||||||
unsigned int expanded_width, unsigned int level) = 0;
|
unsigned int expanded_width, unsigned int level) = 0;
|
||||||
|
|
Loading…
Reference in New Issue