Code cleanup

This commit is contained in:
GabsPuNs
2026-04-04 17:36:02 -04:00
parent 451ced38b7
commit 9b2fe6d136
7 changed files with 48 additions and 83 deletions

View File

@@ -656,10 +656,10 @@ void Texture::transferFromImage(BufferedImage *image)
for (int x = 0; x < ww; x++)
for (int y = 0; y < hh; y++)
{
int c0 = data[level - 1]->getInt(((x * 2 + 0) + (y * 2 + 0) * ow) * 4);
int c1 = data[level - 1]->getInt(((x * 2 + 1) + (y * 2 + 0) * ow) * 4);
int c2 = data[level - 1]->getInt(((x * 2 + 1) + (y * 2 + 1) * ow) * 4);
int c3 = data[level - 1]->getInt(((x * 2 + 0) + (y * 2 + 1) * ow) * 4);
unsigned int c0 = data[level - 1]->getInt(((x * 2 + 0) + (y * 2 + 0) * ow) * 4);
unsigned int c1 = data[level - 1]->getInt(((x * 2 + 1) + (y * 2 + 0) * ow) * 4);
unsigned int c2 = data[level - 1]->getInt(((x * 2 + 1) + (y * 2 + 1) * ow) * 4);
unsigned int c3 = data[level - 1]->getInt(((x * 2 + 0) + (y * 2 + 1) * ow) * 4);
#ifndef _XBOX
// 4J - convert our RGBA texels to ARGB that crispBlend is expecting
c0 = ( ( c0 >> 8 ) & 0x00ffffff ) | ( c0 << 24 );
@@ -667,13 +667,13 @@ void Texture::transferFromImage(BufferedImage *image)
c2 = ( ( c2 >> 8 ) & 0x00ffffff ) | ( c2 << 24 );
c3 = ( ( c3 >> 8 ) & 0x00ffffff ) | ( c3 << 24 );
#endif
int col = crispBlend(crispBlend(c0, c1), crispBlend(c2, c3));
unsigned int col = crispBlend(crispBlend(c0, c1), crispBlend(c2, c3));
// 4J - and back from ARGB -> RGBA
//col = ( col << 8 ) | (( col >> 24 ) & 0xff);
//tempData[x + y * ww] = col;
int intIndex = y * ww + x;
int byteIndex = intIndex * 4;
unsigned int intIndex = y * ww + x;
unsigned int byteIndex = intIndex * 4;
// Pull ARGB bytes into either RGBA or BGRA depending on format
@@ -711,53 +711,49 @@ void Texture::transferFromImage(BufferedImage *image)
}
}
// 4J Kept from older versions for where we create mip-maps for levels that do not have pre-made graphics
int Texture::crispBlend(int c0, int c1)
unsigned int Texture::crispBlend(unsigned int c0, unsigned int c1)
{
int a0 = static_cast<int>(((c0 & 0xff000000) >> 24)) & 0xff;
int a1 = static_cast<int>(((c1 & 0xff000000) >> 24)) & 0xff;
unsigned int a0 = (c0 >> 24) & 0xFF;
unsigned int a1 = (c1 >> 24) & 0xFF;
// continue with crisp blend if it's likely to be an opaque/cutout tile in the atlas
if (a0 >= 0xfa || a1 >= 0xfa || !Minecraft::GetInstance()->options->mipmapsBlend)
{
int a = 255;
if ((a0 + a1) < 255)
{
unsigned int r = (((c0 >> 16) & 0xFF) + ((c1 >> 16) & 0xFF)) / 2;
unsigned int g = (((c0 >> 8) & 0xFF) + ((c1 >> 8) & 0xFF)) / 2;
unsigned int b = ((c0 & 0xFF) + (c1 & 0xFF)) / 2;
return (r << 16) | (g << 8) | b;
}
if (a0 + a1 < 255)
{
a = 0;
a0 = 1;
a1 = 1;
}
else if (a0 > a1)
{
a0 = 255;
a1 = 1;
}
else
{
a0 = 1;
a1 = 255;
unsigned int r0 = (c0 >> 16) & 0xFF;
unsigned int g0 = (c0 >> 8) & 0xFF;
unsigned int b0 = c0 & 0xFF;
}
unsigned int r1 = (c1 >> 16) & 0xFF;
unsigned int g1 = (c1 >> 8) & 0xFF;
unsigned int b1 = c1 & 0xFF;
int r0 = ((c0 >> 16) & 0xff) * a0;
int g0 = ((c0 >> 8) & 0xff) * a0;
int b0 = ((c0) & 0xff) * a0;
unsigned int r, g, b;
int r1 = ((c1 >> 16) & 0xff) * a1;
int g1 = ((c1 >> 8) & 0xff) * a1;
int b1 = ((c1) & 0xff) * a1;
if (a0 <= a1)
{
r = (r0 + 255 * r1) / 256;
g = (g0 + 255 * g1) / 256;
b = (b0 + 255 * b1) / 256;
}
else
{
r = (255 * r0 + r1) / 256;
g = (255 * g0 + g1) / 256;
b = (255 * b0 + b1) / 256;
}
int r = (r0 + r1) / (a0 + a1);
int g = (g0 + g1) / (a0 + a1);
int b = (b0 + b1) / (a0 + a1);
return (a << 24) | (r << 16) | (g << 8) | b;
return 0xFF000000 | (r << 16) | (g << 8) | b;
}
else // smoothblend if it's transparent
{
return (((a0 + a1) >> 1) << 24) | (((c0 & 0xfefefe) + (c1 & 0xfefefe)) >> 1);
}
}
int Texture::getManagerId()