fix stbi_shiftsigned to be shifting a value that's unsigned

This commit is contained in:
Sean Barrett 2017-04-28 23:35:37 -07:00
parent f1417efd36
commit 84e42c2e8d
2 changed files with 10 additions and 4 deletions

View File

@ -4960,7 +4960,7 @@ static int stbi__bitcount(unsigned int a)
return a & 0xff;
}
static int stbi__shiftsigned(int v, int shift, int bits)
static unsigned int stbi__shiftsigned(unsigned int v, int shift, int bits)
{
int result;
int z=0;
@ -4969,6 +4969,7 @@ static int stbi__shiftsigned(int v, int shift, int bits)
else v >>= shift;
result = v;
// replicate the high bits to the low bits
z = bits;
while (z < 8) {
result += v >> z;
@ -5185,7 +5186,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
int bpp = info.bpp;
for (i=0; i < (int) s->img_x; ++i) {
stbi__uint32 v = (bpp == 16 ? (stbi__uint32) stbi__get16le(s) : stbi__get32le(s));
int a;
unsigned int a;
out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mr, rshift, rcount));
out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mg, gshift, gcount));
out[z++] = STBI__BYTECAST(stbi__shiftsigned(v & mb, bshift, bcount));

View File

@ -37,7 +37,8 @@ extern void ods(char *fmt, ...);
#define FAST_CHUNK
#define IN_PLACE
#define SKIP_TERRAIN 48 // use to avoid building underground stuff
#define SKIP_TERRAIN 0
//#define SKIP_TERRAIN 48 // use to avoid building underground stuff
// allows you to see what perf would be like if underground was efficiently culled,
// or if you were making a game without underground
@ -131,7 +132,8 @@ unsigned char minecraft_info[256][7] =
{ C_solid, 35,35,35,35,4,4, },
// 48
{ C_solid, 36,36,36,36,36,36 },
//{ C_solid, 36,36,36,36,36,36 },
{ C_force, 36,36,36,36,36,36 },
{ C_solid, 37,37,37,37,37,37 },
{ C_cross, 80,80,80,80,80,80 }, // torch
{ C_empty }, // fire
@ -142,6 +144,7 @@ unsigned char minecraft_info[256][7] =
// 56
{ C_solid, 50,50,50,50,50,50 },
//{ C_force, 50,50,50,50,50,50 },
{ C_solid, 26,26,26,26,26,26 },
{ C_solid, 60,59,59,59,43,43 },
{ C_cross, 95,95,95,95 },
@ -831,6 +834,8 @@ void mesh_init(void)
minecraft_color_for_blocktype[161][i] = 37 | 64; // green
minecraft_color_for_blocktype[10][i] = 63; // emissive lava
minecraft_color_for_blocktype[11][i] = 63; // emissive
//minecraft_color_for_blocktype[56][i] = 63; // emissive diamond
minecraft_color_for_blocktype[48][i] = 63; // emissive dungeon
}
#ifdef VHEIGHT_TEST