Account for scaleFactor when saving clipped PNG.

This commit is contained in:
Unknown W. Brackets 2016-04-30 20:33:14 -07:00
parent 7a4af06cee
commit e1fd6b6f21
5 changed files with 13 additions and 8 deletions

View File

@ -95,7 +95,7 @@ bool TextureReplacer::LoadIni() {
if (ini.GetKeys("hashes", hashNames)) { if (ini.GetKeys("hashes", hashNames)) {
auto hashes = ini.GetOrCreateSection("hashes"); auto hashes = ini.GetOrCreateSection("hashes");
// Format: hashname = filename.png // Format: hashname = filename.png
for (std::string hashName : hashNames) { for (const std::string &hashName : hashNames) {
hashes->Get(hashName.c_str(), &aliases_[hashName], ""); hashes->Get(hashName.c_str(), &aliases_[hashName], "");
} }
} }
@ -104,7 +104,7 @@ bool TextureReplacer::LoadIni() {
if (ini.GetKeys("hashranges", hashrangeKeys)) { if (ini.GetKeys("hashranges", hashrangeKeys)) {
auto hashranges = ini.GetOrCreateSection("hashranges"); auto hashranges = ini.GetOrCreateSection("hashranges");
// Format: addr,w,h = newW,newH // Format: addr,w,h = newW,newH
for (std::string key : hashrangeKeys) { for (const std::string &key : hashrangeKeys) {
std::string value; std::string value;
if (hashranges->Get(key.c_str(), &value, "")) { if (hashranges->Get(key.c_str(), &value, "")) {
ParseHashRange(key, value); ParseHashRange(key, value);
@ -277,7 +277,7 @@ static bool WriteTextureToPNG(png_imagep image, const std::string &filename, int
} }
#endif #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"); _assert_msg_(G3D, enabled_, "Replacement not enabled");
if (!g_Config.bSaveNewTextures) { if (!g_Config.bSaveNewTextures) {
// Ignore. // Ignore.
@ -308,7 +308,12 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con
} }
// Only save the hashed portion of the PNG. // 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 #ifdef USING_QT_UI
ERROR_LOG(G3D, "Replacement texture saving not implemented for Qt"); ERROR_LOG(G3D, "Replacement texture saving not implemented for Qt");

View File

@ -133,7 +133,7 @@ public:
ReplacedTexture &FindReplacement(u64 cachekey, u32 hash, int w, int h); 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: protected:
bool LoadIni(); bool LoadIni();

View File

@ -1674,7 +1674,7 @@ void TextureCacheDX9::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &re
if (replacer.Enabled()) { if (replacer.Enabled()) {
int bpp = dstFmt == D3DFMT_A8R8G8B8 ? 4 : 2; 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));
} }
} }

View File

@ -1813,7 +1813,7 @@ void TextureCache::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &repla
if (replacer.Enabled()) { if (replacer.Enabled()) {
int bpp = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2; 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));
} }
} }

View File

@ -1348,7 +1348,7 @@ void TextureCacheVulkan::SetTexture(VulkanPushBuffer *uploadBuffer) {
} else { } else {
LoadTextureLevel(*entry, (uint8_t *)data, stride, i, scaleFactor, dstFmt); LoadTextureLevel(*entry, (uint8_t *)data, stride, i, scaleFactor, dstFmt);
if (replacer.Enabled()) { 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); entry->vkTex->texture_->UploadMip(i, mipWidth, mipHeight, texBuf, bufferOffset, stride / bpp);