Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Flyinghead
47349595fd special build to convert custom texture packs ids 2020-04-02 12:24:55 +02:00
3 changed files with 54 additions and 1 deletions

View file

@ -20,6 +20,7 @@
#include "cfg/cfg.h"
#include <algorithm>
#include <set>
#include <dirent.h>
#include <png.h>
#include <sstream>
@ -28,6 +29,9 @@
u8* loadPNGData(const std::string& subpath, int &width, int &height);
CustomTexture custom_texture;
static std::set<u32> loadedTexs;
static FILE *fp;
void CustomTexture::LoaderThread()
{
while (initialized)
@ -61,6 +65,18 @@ void CustomTexture::LoaderThread()
{
image_data = LoadCustomTexture(texture->old_texture_hash, width, height);
}
if (image_data == NULL)
{
image_data = LoadCustomTexture(texture->old_texture_hash2, width, height);
if (image_data != NULL && loadedTexs.insert(texture->old_texture_hash2).second)
{
if (fp == NULL)
fp = fopen("convert.txt", "a");
std::stringstream path;
path << "mv " << std::hex << texture->old_texture_hash2 << ".png ../new/" << texture->texture_hash << ".png";
fprintf(fp, "%s\n", path.str().c_str());
}
}
if (image_data != NULL)
{
texture->custom_width = width;
@ -127,6 +143,8 @@ void CustomTexture::Terminate()
loader_thread.WaitToEnd();
#endif
}
if (fp)
fclose(fp);
}
u8* CustomTexture::LoadCustomTexture(u32 hash, int& width, int& height)

View file

@ -22,6 +22,8 @@ u32 palette16_ram[1024];
u32 palette32_ram[1024];
u32 pal_hash_256[4];
u32 pal_hash_16[64];
u32 old_pal_hash_256[4];
u32 old_pal_hash_16[64];
// Rough approximation of LoD bias from D adjust param, only used to increase LoD
const std::array<f32, 16> D_Adjust_LoD_Bias = {
@ -89,6 +91,7 @@ void palette_update()
return;
pal_needs_update=false;
u32 old_palette_ram[1024];
switch(PAL_RAM_CTRL&3)
{
@ -97,6 +100,7 @@ void palette_update()
{
palette16_ram[i] = ARGB1555(PALETTE_RAM[i]);
palette32_ram[i] = ARGB1555_32(PALETTE_RAM[i]);
old_palette_ram[i] = OLD_ARGB1555_32(PALETTE_RAM[i]);
}
break;
@ -105,6 +109,7 @@ void palette_update()
{
palette16_ram[i] = ARGB565(PALETTE_RAM[i]);
palette32_ram[i] = ARGB565_32(PALETTE_RAM[i]);
old_palette_ram[i] = OLD_ARGB565_32(PALETTE_RAM[i]);
}
break;
@ -113,6 +118,7 @@ void palette_update()
{
palette16_ram[i] = ARGB4444(PALETTE_RAM[i]);
palette32_ram[i] = ARGB4444_32(PALETTE_RAM[i]);
old_palette_ram[i] = OLD_ARGB4444_32(PALETTE_RAM[i]);
}
break;
@ -121,13 +127,20 @@ void palette_update()
{
palette16_ram[i] = ARGB8888(PALETTE_RAM[i]);
palette32_ram[i] = ARGB8888_32(PALETTE_RAM[i]);
old_palette_ram[i] = OLD_ARGB8888_32(PALETTE_RAM[i]);
}
break;
}
for (int i = 0; i < 64; i++)
{
pal_hash_16[i] = XXH32(&PALETTE_RAM[i << 4], 16 * 4, 7);
old_pal_hash_16[i] = XXH32(&old_palette_ram[i << 4], 16 * 4, 7);
}
for (int i = 0; i < 4; i++)
{
pal_hash_256[i] = XXH32(&PALETTE_RAM[i << 8], 256 * 4, 7);
old_pal_hash_256[i] = XXH32(&old_palette_ram[i << 8], 256 * 4, 7);
}
}
std::vector<vram_block*> VramLocks[VRAM_SIZE_MAX / PAGE_SIZE];
@ -559,9 +572,14 @@ void BaseTextureCacheData::Create()
void BaseTextureCacheData::ComputeHash()
{
texture_hash = XXH32(&vram[sa], size, 7);
old_texture_hash2 = texture_hash;
if (IsPaletted())
{
texture_hash ^= palette_hash;
old_texture_hash2 ^= old_palette_hash;
}
old_texture_hash = texture_hash;
old_texture_hash2 ^= tcw.full;
texture_hash ^= tcw.full & 0xFC000000; // everything but texaddr, reserved and stride
}
@ -582,9 +600,15 @@ void BaseTextureCacheData::Update()
// Get the palette hash to check for future updates
if (tcw.PixelFmt == PixelPal4)
{
palette_hash = pal_hash_16[tcw.PalSelect];
old_palette_hash = old_pal_hash_16[tcw.PalSelect];
}
else
{
palette_hash = pal_hash_256[tcw.PalSelect >> 4];
old_palette_hash = old_pal_hash_256[tcw.PalSelect >> 4];
}
}
::palette_index = this->palette_index; // might be used if pal. tex

View file

@ -120,7 +120,7 @@ public:
void palette_update();
#define clamp(minv, maxv, x) (x < minv ? minv : x > maxv ? maxv : x)
#define clamp(minv, maxv, x) ((x) < (minv) ? (minv) : (x) > (maxv) ? (maxv) : (x))
// Unpack to 16-bit word
@ -151,6 +151,15 @@ void palette_update();
#define ARGB8888_32( word ) ( ((word >> 0) & 0xFF000000) | (((word >> 16) & 0xFF) << 0) | (((word >> 8) & 0xFF) << 8) | ((word & 0xFF) << 16) )
// previous conversion used with uint8888 (lr)
#define OLD_ARGB1555_32( word ) ( ((word & 0x8000) ? 0xFF : 0) | (((word>>10) & 0x1F)<<27) | (((word>>5) & 0x1F)<<19) | (((word>>0) & 0x1F)<<11) )
#define OLD_ARGB565_32( word ) ( (((word>>11)&0x1F)<<27) | (((word>>5)&0x3F)<<18) | (((word>>0)&0x1F)<<11) | 0xFF )
#define OLD_ARGB4444_32( word ) ( (((word>>12)&0xF)<<4) | (((word>>8)&0xF)<<28) | (((word>>4)&0xF)<<20) | (((word>>0)&0xF)<<12) )
#define OLD_ARGB8888_32( word ) ( ((word >> 24) & 0xFF) | (((word >> 16) & 0xFF) << 24) | (((word >> 8) & 0xFF) << 16) | ((word & 0xFF) << 8) )
template<class PixelPacker>
__forceinline u32 YUV422(s32 Y,s32 Yu,s32 Yv)
{
@ -672,9 +681,11 @@ public:
u32 palette_index;
//used for palette updates
u32 palette_hash; // Palette hash at time of last update
u32 old_palette_hash;
u32 vq_codebook; // VQ quantizers table for compressed textures
u32 texture_hash; // xxhash of texture data, used for custom textures
u32 old_texture_hash; // legacy hash
u32 old_texture_hash2; // v2 hash
u8* custom_image_data; // loaded custom image data
u32 custom_width;
u32 custom_height;