From 3f7ea1fda990ce1d9809db7d32c23a6dda1a2820 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Fri, 7 Feb 2020 20:41:59 +0100 Subject: [PATCH] fix crash for 1x1 TW textures --- core/rend/TexCache.cpp | 6 +++--- core/rend/TexCache.h | 42 ++++++++++++++++++------------------------ 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/core/rend/TexCache.cpp b/core/rend/TexCache.cpp index f2ec61df2..d611e6092 100644 --- a/core/rend/TexCache.cpp +++ b/core/rend/TexCache.cpp @@ -23,7 +23,7 @@ u32 palette32_ram[1024]; u32 pal_hash_256[4]; u32 pal_hash_16[64]; -u32 detwiddle[2][10][1024]; +u32 detwiddle[2][11][1024]; //input : address in the yyyyyxxxxx format //output : address in the xyxyxyxy format //U : x resolution , V : y resolution @@ -64,10 +64,10 @@ static u32 twiddle_slow(u32 x,u32 y,u32 x_sz,u32 y_sz) static void BuildTwiddleTables() { - for (u32 s = 0; s < 10; s++) + for (u32 s = 0; s < 11; s++) { u32 x_sz = 1024; - u32 y_sz = 2 << s; + u32 y_sz = 1 << s; for (u32 i = 0; i < x_sz; i++) { detwiddle[0][s][i] = twiddle_slow(i, 0, x_sz, y_sz); diff --git a/core/rend/TexCache.h b/core/rend/TexCache.h index 0a0b8f728..b74091b63 100644 --- a/core/rend/TexCache.h +++ b/core/rend/TexCache.h @@ -17,7 +17,7 @@ extern u32 pal_hash_256[4]; extern u32 pal_hash_16[64]; extern bool KillTex; -extern u32 detwiddle[2][10][1024]; +extern u32 detwiddle[2][11][1024]; template class PixelBuffer @@ -522,22 +522,19 @@ void texture_PL(PixelBuffer* pb,u8* p_in,u32 Width,u32 Height) template void texture_TW(PixelBuffer* pb,u8* p_in,u32 Width,u32 Height) { - pb->amove(0,0); + pb->amove(0, 0); - const u32 divider=PixelConvertor::xpp*PixelConvertor::ypp; + const u32 divider = PixelConvertor::xpp * PixelConvertor::ypp; - unsigned long bcx_,bcy_; - bcx_=bitscanrev(Width); - bcy_=bitscanrev(Height); - const u32 bcx=bcx_-1; - const u32 bcy=bcy_-1; + const u32 bcx = bitscanrev(Width); + const u32 bcy = bitscanrev(Height); - for (u32 y=0;yrmovex(PixelConvertor::xpp); } @@ -548,22 +545,19 @@ void texture_TW(PixelBuffer* pb,u8* p_in,u32 Width,u32 Height) template void texture_VQ(PixelBuffer* pb,u8* p_in,u32 Width,u32 Height) { - p_in+=256*4*2; - pb->amove(0,0); + p_in += 256 * 4 * 2; // Skip VQ codebook + pb->amove(0, 0); - const u32 divider=PixelConvertor::xpp*PixelConvertor::ypp; - unsigned long bcx_,bcy_; - bcx_=bitscanrev(Width); - bcy_=bitscanrev(Height); - const u32 bcx=bcx_-1; - const u32 bcy=bcy_-1; + const u32 divider = PixelConvertor::xpp * PixelConvertor::ypp; + const u32 bcx = bitscanrev(Width); + const u32 bcy = bitscanrev(Height); - for (u32 y=0;yrmovex(PixelConvertor::xpp); }