From e1fd6b6f21dca0d1d1ac8b73153cd0cee6490162 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 30 Apr 2016 20:33:14 -0700 Subject: [PATCH] Account for scaleFactor when saving clipped PNG. --- Core/TextureReplacer.cpp | 13 +++++++++---- Core/TextureReplacer.h | 2 +- GPU/Directx9/TextureCacheDX9.cpp | 2 +- GPU/GLES/TextureCache.cpp | 2 +- GPU/Vulkan/TextureCacheVulkan.cpp | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index 866131592..51e08cb22 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -95,7 +95,7 @@ bool TextureReplacer::LoadIni() { if (ini.GetKeys("hashes", hashNames)) { auto hashes = ini.GetOrCreateSection("hashes"); // Format: hashname = filename.png - for (std::string hashName : hashNames) { + for (const std::string &hashName : hashNames) { hashes->Get(hashName.c_str(), &aliases_[hashName], ""); } } @@ -104,7 +104,7 @@ bool TextureReplacer::LoadIni() { if (ini.GetKeys("hashranges", hashrangeKeys)) { auto hashranges = ini.GetOrCreateSection("hashranges"); // Format: addr,w,h = newW,newH - for (std::string key : hashrangeKeys) { + for (const std::string &key : hashrangeKeys) { std::string value; if (hashranges->Get(key.c_str(), &value, "")) { ParseHashRange(key, value); @@ -277,7 +277,7 @@ static bool WriteTextureToPNG(png_imagep image, const std::string &filename, int } #endif -void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, ReplacedTextureFormat fmt) { +void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, int scaleFactor, ReplacedTextureFormat fmt) { _assert_msg_(G3D, enabled_, "Replacement not enabled"); if (!g_Config.bSaveNewTextures) { // Ignore. @@ -308,7 +308,12 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con } // Only save the hashed portion of the PNG. - LookupHashRange(addr, w, h); + int lookupW = w / scaleFactor; + int lookupH = h / scaleFactor; + if (LookupHashRange(addr, lookupW, lookupH)) { + w = lookupW * scaleFactor; + h = lookupH * scaleFactor; + } #ifdef USING_QT_UI ERROR_LOG(G3D, "Replacement texture saving not implemented for Qt"); diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index f9cc69dd3..13d16bc87 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -133,7 +133,7 @@ public: ReplacedTexture &FindReplacement(u64 cachekey, u32 hash, int w, int h); - void NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, ReplacedTextureFormat fmt); + void NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, const void *data, int pitch, int level, int w, int h, int scaleFactor, ReplacedTextureFormat fmt); protected: bool LoadIni(); diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index 8133b508a..9b5f5cde0 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -1674,7 +1674,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &re if (replacer.Enabled()) { int bpp = dstFmt == D3DFMT_A8R8G8B8 ? 4 : 2; - replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash, entry.addr, pixelData, w * bpp, level, w, h, FromD3D9Format(dstFmt)); + replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash, entry.addr, pixelData, w * bpp, level, w, h, scaleFactor, FromD3D9Format(dstFmt)); } } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index d177a4f15..a1dcd4fed 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -1813,7 +1813,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &repla if (replacer.Enabled()) { int bpp = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; - replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash,entry.addr, pixelData, (useUnpack ? bufw : w) * bpp, level, w, h, FromGLESFormat(dstFmt, useBGRA)); + replacer.NotifyTextureDecoded(entry.CacheKey(), entry.fullhash,entry.addr, pixelData, (useUnpack ? bufw : w) * bpp, level, w, h, scaleFactor, FromGLESFormat(dstFmt, useBGRA)); } } diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index a1418201f..3e25e66cf 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -1348,7 +1348,7 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) { } else { LoadTextureLevel(*entry, (uint8_t *)data, stride, i, scaleFactor, dstFmt); if (replacer.Enabled()) { - replacer.NotifyTextureDecoded(cachekey, entry->fullhash, texaddr, data, stride, i, mipWidth, mipHeight, FromVulkanFormat(actualFmt)); + replacer.NotifyTextureDecoded(cachekey, entry->fullhash, texaddr, data, stride, i, mipWidth, mipHeight, scaleFactor, FromVulkanFormat(actualFmt)); } } entry->vkTex->texture_->UploadMip(i, mipWidth, mipHeight, texBuf, bufferOffset, stride / bpp);