From 8a52fdab57338649226fb2f8abd76ef41f0c20a3 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 30 Apr 2015 19:47:29 +0200 Subject: [PATCH] gsdx-ogl: allow to dump texture as png file -- slower (but that a debug feature) ++ smaller (40x-50x) ++ native support of alpha Require libpng++ and the define ENABLE_OGL_PNG Note: depth is not supported yet. --- plugins/GSdx/GSTextureOGL.cpp | 28 ++++++++++++++++++++++++++++ plugins/GSdx/GSTextureOGL.h | 3 +++ plugins/GSdx/config.h | 1 + 3 files changed, 32 insertions(+) diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index f18f0e033b..92388cbb48 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -527,6 +527,30 @@ void GSTextureOGL::Save(const string& fn, const void* image, uint32 pitch) fclose(fp); } +#ifdef ENABLE_OGL_PNG +#include "png++/png.hpp" + +void GSTextureOGL::SavePNG(const string& fn, const void* image, uint32 pitch) { + if (IsDss()) { + // TODO + //png::image img(m_size.x, m_size.y); + } else { + png::image img(m_size.x, m_size.y); + + uint8* data = (uint8*)image; + for(int h = 0; h < m_size.y; h++, data += pitch) { + for (int w = 0; w < m_size.x; w++) { + png::rgba_pixel pixel(data[4*w+0], data[4*w+1], data[4*w+2], data[4*w+3]); + img.set_pixel(w, h, pixel); + } + } + + std::string rename = fn; + img.write(rename.replace(fn.length()-3, 3, "png")); + } +} +#endif + void GSTextureOGL::SaveRaw(const string& fn, const void* image, uint32 pitch) { // Build a raw CSV file @@ -607,7 +631,11 @@ bool GSTextureOGL::Save(const string& fn, bool dds) gl_BindFramebuffer(GL_READ_FRAMEBUFFER, 0); } +#ifdef ENABLE_OGL_PNG + if (status) SavePNG(fn, image, pitch); +#else if (status) Save(fn, image, pitch); +#endif free(image); return status; diff --git a/plugins/GSdx/GSTextureOGL.h b/plugins/GSdx/GSTextureOGL.h index cfd6456780..62f041217e 100644 --- a/plugins/GSdx/GSTextureOGL.h +++ b/plugins/GSdx/GSTextureOGL.h @@ -69,6 +69,9 @@ class GSTextureOGL : public GSTexture void Unmap(); bool Save(const string& fn, bool dds = false); void Save(const string& fn, const void* image, uint32 pitch); +#ifdef ENABLE_OGL_PNG + void SavePNG(const string& fn, const void* image, uint32 pitch); +#endif void SaveRaw(const string& fn, const void* image, uint32 pitch); bool IsBackbuffer() { return (m_type == GSTexture::Backbuffer); } diff --git a/plugins/GSdx/config.h b/plugins/GSdx/config.h index a7d9f4f823..16b3f379f5 100644 --- a/plugins/GSdx/config.h +++ b/plugins/GSdx/config.h @@ -38,6 +38,7 @@ //#define DISABLE_DATE +//#define ENABLE_OGL_PNG #if defined(_DEBUG) || defined(_DEVEL) #define ENABLE_OGL_DEBUG // Create a debug context and check opengl command status. Allow also to dump various textures/states. //#define ENABLE_OGL_DEBUG_FENCE