This commit is contained in:
Lioncash 2013-11-16 16:53:22 -05:00
commit c46aabc853
7 changed files with 15 additions and 11 deletions

View File

@ -701,6 +701,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
memcpy(data, map.pData, 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); 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);

View File

@ -71,6 +71,7 @@ bool TextureCache::TCacheEntry::Save(const char filename[], unsigned int level)
memcpy(data, map.pData, map.RowPitch * desc.Height); memcpy(data, map.pData, map.RowPitch * desc.Height);
saved_png = TextureToPng(data, map.RowPitch, filename, desc.Width, 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);
} }

View File

@ -1825,7 +1825,11 @@ 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);
return TextureToPng(data, W*4, filename.c_str(), W, H, false); bool success = TextureToPng(data, W*4, filename.c_str(), W, H, false);
delete[] data;
return success;
} }
} }

View File

@ -78,8 +78,9 @@ bool SaveTexture(const char* filename, u32 textarget, u32 tex, int virtual_width
delete[] data; delete[] data;
return false; return false;
} }
bool success = TextureToPng(data, width * 4, filename, width, height, true);
return TextureToPng(data, width*4, filename, width, height, true); delete[] data;
return success;
#else #else
return false; return false;
#endif #endif

View File

@ -57,6 +57,7 @@ void SaveTexture(const char* filename, u32 texmap, s32 mip)
GetTextureRGBA(data, texmap, mip, width, height); GetTextureRGBA(data, texmap, mip, width, height);
(void)TextureToPng(data, width*4, filename, width, height, true); (void)TextureToPng(data, width*4, filename, width, height, true);
delete[] data;
} }
@ -140,6 +141,7 @@ void DumpEfb(const char* filename)
} }
(void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true); (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
delete[] data;
} }
void DumpDepth(const char* filename) void DumpDepth(const char* filename)
@ -161,6 +163,7 @@ void DumpDepth(const char* filename)
} }
(void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true); (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
delete[] data;
} }
void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name) void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name)
@ -241,6 +244,7 @@ void OnObjectEnd()
(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.c_str(), EFB_WIDTH, EFB_HEIGHT, true);
memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i])); memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i]));
} }
} }

View File

@ -142,9 +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);
u8 *data = new u8[width * 4 * height]; TextureToPng(texture, width*4, s_sScreenshotName.c_str(), width, height, false);
memcpy(data, texture, sizeof(u8) * 4 * width * height);
TextureToPng(data, width*4, s_sScreenshotName.c_str(), width, height, false);
// Reset settings // Reset settings
s_sScreenshotName.clear(); s_sScreenshotName.clear();
s_bScreenshot = false; s_bScreenshot = false;

View File

@ -24,8 +24,6 @@ TextureToPng
Inputs: 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.
data is a newly allocated memory and must have delete[] run on it before returning.
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 char* filename, int width, int height, bool saveAlpha)
@ -109,8 +107,5 @@ finalise:
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);
// Our duty to delete the inputted data.
delete[] data;
return success; return success;
} }