From 25997647f241cb04b93dd64d9674fe3b47f7e081 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 30 Apr 2015 23:06:54 +0200 Subject: [PATCH] gsdx-ogl: add ENABLE_OGL_PNG_OPAQUE to dump texture without alpha Alpha is nice but fully transparent texture suck The best will be an image viewer that can toggle the alpha channel --- plugins/GSdx/GSTextureOGL.cpp | 16 +++++++++++++--- plugins/GSdx/GSTextureSW.cpp | 16 +++++++++++++--- plugins/GSdx/config.h | 6 ++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index 92388cbb48..c56b616aa9 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -536,17 +536,27 @@ void GSTextureOGL::SavePNG(const string& fn, const void* image, uint32 pitch) { //png::image img(m_size.x, m_size.y); } else { png::image img(m_size.x, m_size.y); + png::image img_opaque(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); + png::rgba_pixel pa(data[4*w+0], data[4*w+1], data[4*w+2], data[4*w+3]); + img.set_pixel(w, h, pa); + +#ifdef ENABLE_OGL_PNG_OPAQUE + png::rgb_pixel p(data[4*w+0], data[4*w+1], data[4*w+2]); + img_opaque.set_pixel(w, h, p); +#endif } } std::string rename = fn; - img.write(rename.replace(fn.length()-3, 3, "png")); + img.write(rename.replace(fn.length()-4, 4, "_full.png")); +#ifdef ENABLE_OGL_PNG_OPAQUE + rename = fn; + img_opaque.write(rename.replace(fn.length()-4, 4, "_opaque.png")); +#endif } } #endif diff --git a/plugins/GSdx/GSTextureSW.cpp b/plugins/GSdx/GSTextureSW.cpp index 1f514038fa..173fa958c5 100644 --- a/plugins/GSdx/GSTextureSW.cpp +++ b/plugins/GSdx/GSTextureSW.cpp @@ -123,17 +123,27 @@ struct BITMAPINFOHEADER void GSTextureSW::SavePNG(const string& fn) { png::image img(m_size.x, m_size.y); + png::image img_opaque(m_size.x, m_size.y); uint8* data = (uint8*)m_data; for(int h = 0; h < m_size.y; h++, data += m_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); + png::rgba_pixel pa(data[4*w+0], data[4*w+1], data[4*w+2], data[4*w+3]); + img.set_pixel(w, h, pa); + +#ifdef ENABLE_OGL_PNG_OPAQUE + png::rgb_pixel p(data[4*w+0], data[4*w+1], data[4*w+2]); + img_opaque.set_pixel(w, h, p); +#endif } } std::string rename = fn; - img.write(rename.replace(fn.length()-3, 3, "png")); + img.write(rename.replace(fn.length()-4, 4, "_full.png")); +#ifdef ENABLE_OGL_PNG_OPAQUE + rename = fn; + img_opaque.write(rename.replace(fn.length()-4, 4, "_opaque.png")); +#endif } #endif diff --git a/plugins/GSdx/config.h b/plugins/GSdx/config.h index 7a0440d4c0..f65c192687 100644 --- a/plugins/GSdx/config.h +++ b/plugins/GSdx/config.h @@ -38,7 +38,13 @@ //#define DISABLE_DATE +// Allow to dump texture as PNG (require libpng++). It reduces the size of the dump +// and alpha is well supported //#define ENABLE_OGL_PNG +// Extension of the previous define to also dump texture without alpha (hard to see anything +// when the texture is fully transparent) +//#define ENABLE_OGL_PNG_OPAQUE + #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