Reworked Screenshot saving.
Now OGL doesn't rely on WX for PNG saving. FlipImageData supports (pixel data len > 3) now. TextureToPng is now in ImageWrite.cpp/h Video Common depends on zlib and png. D3D no longer depends on zlib and png.
This commit is contained in:
1 parent
2703cae8d3
commit
033ed9477e
10 files changed
+134
-196
No files matched your search
@@ -5,96 +5,12 @@
|
||||
#include "D3DBase.h"
|
||||
#include "D3DTexture.h"
|
||||
|
||||
#include "png.h"
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
|
||||
namespace D3D
|
||||
{
|
||||
|
||||
bool TextureToPng(D3D11_MAPPED_SUBRESOURCE &map, const char* filename, int width, int height, bool saveAlpha)
|
||||
{
|
||||
bool success = false;
|
||||
if (map.pData != NULL)
|
||||
{
|
||||
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) {
|
||||
PanicAlert("Could not open file %s for writing\n", filename);
|
||||
goto finalise;
|
||||
}
|
||||
|
||||
// Initialize write structure
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (png_ptr == NULL) {
|
||||
PanicAlert("Could not allocate write struct\n");
|
||||
goto finalise;
|
||||
|
||||
}
|
||||
|
||||
// Initialize info structure
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == NULL) {
|
||||
PanicAlert("Could not allocate info struct\n");
|
||||
goto finalise;
|
||||
}
|
||||
|
||||
// Setup Exception handling
|
||||
if (setjmp(png_jmpbuf(png_ptr))) {
|
||||
PanicAlert("Error during png creation\n");
|
||||
goto finalise;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
// Write header (8 bit colour depth)
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height,
|
||||
8, PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
char title[] = "Dolphin Screenshot";
|
||||
png_text title_text;
|
||||
title_text.compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
title_text.key = "Title";
|
||||
title_text.text = title;
|
||||
png_set_text(png_ptr, info_ptr, &title_text, 1);
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
// Write image data
|
||||
for (auto y = 0; y < height; ++y)
|
||||
{
|
||||
u8* row_ptr = (u8*)map.pData + y * map.RowPitch;
|
||||
u8* ptr = row_ptr;
|
||||
for (UINT x = 0; x < map.RowPitch / 4; ++x)
|
||||
{
|
||||
if (!saveAlpha)
|
||||
ptr[3] = 0xff;
|
||||
ptr += 4;
|
||||
}
|
||||
png_write_row(png_ptr, row_ptr);
|
||||
}
|
||||
|
||||
// End write
|
||||
png_write_end(png_ptr, NULL);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ReplaceRGBATexture2D(ID3D11Texture2D* pTexture, const u8* buffer, unsigned int width, unsigned int height, unsigned int pitch, unsigned int level, D3D11_USAGE usage)
|
||||
{
|
||||
if (usage == D3D11_USAGE_DYNAMIC || usage == D3D11_USAGE_STAGING)
|
||||
|
||||
Reference in new issue
Block a user