Merge pull request #6543 from lioncash/cast

HiresTextures: Remove unnecessary pointer casts in GenBaseName() + minor associated cleanup
This commit is contained in:
Léo Lam
2018-03-27 21:45:56 +02:00
committed by GitHub

View File

@ -12,6 +12,7 @@
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <thread> #include <thread>
#include <tuple>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -229,24 +230,23 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co
case 16 * 2: case 16 * 2:
for (size_t i = 0; i < texture_size; i++) for (size_t i = 0; i < texture_size; i++)
{ {
min = std::min<u32>(min, texture[i] & 0xf); const u32 low_nibble = texture[i] & 0xf;
min = std::min<u32>(min, texture[i] >> 4); const u32 high_nibble = texture[i] >> 4;
max = std::max<u32>(max, texture[i] & 0xf); std::tie(min, max) = std::minmax({min, max, low_nibble, high_nibble});
max = std::max<u32>(max, texture[i] >> 4);
} }
break; break;
case 256 * 2: case 256 * 2:
for (size_t i = 0; i < texture_size; i++)
{ {
min = std::min<u32>(min, texture[i]); const auto minmax = std::minmax_element(texture, texture + texture_size);
max = std::max<u32>(max, texture[i]); min = *minmax.first;
} max = *minmax.second;
break; break;
}
case 16384 * 2: case 16384 * 2:
for (size_t i = 0; i < texture_size / 2; i++) for (size_t i = 0; i < texture_size; i += sizeof(u16))
{ {
min = std::min<u32>(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); const u32 texture_halfword = Common::swap16(texture[i]) & 0x3fff;
max = std::max<u32>(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); std::tie(min, max) = std::minmax({min, max, texture_halfword});
} }
break; break;
} }