diff --git a/Minecraft.Client/BufferedImage.cpp b/Minecraft.Client/BufferedImage.cpp index aa214e15..d28aacb6 100644 --- a/Minecraft.Client/BufferedImage.cpp +++ b/Minecraft.Client/BufferedImage.cpp @@ -54,6 +54,8 @@ BufferedImage::BufferedImage(const wstring& File, bool filenameHasExtension /*=f wstring filePath; filePath = File; + const bool isTerrainAtlas = filePath.find(L"terrain.png") != wstring::npos; + wDrive = drive; if(wDrive.empty()) { @@ -181,6 +183,13 @@ BufferedImage::BufferedImage(const wstring& File, bool filenameHasExtension /*=f return; } + if (isTerrainAtlas && l > 0) + { + delete[] data[l]; + data[l] = nullptr; + continue; + } + if( l == 0 ) { width=ImageInfo.Width; diff --git a/Minecraft.Client/Texture.cpp b/Minecraft.Client/Texture.cpp index cc1b3122..2896c6ff 100644 --- a/Minecraft.Client/Texture.cpp +++ b/Minecraft.Client/Texture.cpp @@ -698,7 +698,7 @@ 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)); + int col = averageMipColors(c0, c1, c2, c3); // 4J - and back from ARGB -> RGBA //col = ( col << 8 ) | (( col >> 24 ) & 0xff); //tempData[x + y * ww] = col; @@ -743,6 +743,15 @@ 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::averageMipColors(int c0, int c1, int c2, int c3) +{ + const int a = (((c0 >> 24) & 0xff) + ((c1 >> 24) & 0xff) + ((c2 >> 24) & 0xff) + ((c3 >> 24) & 0xff)) >> 2; + const int r = (((c0 >> 16) & 0xff) + ((c1 >> 16) & 0xff) + ((c2 >> 16) & 0xff) + ((c3 >> 16) & 0xff)) >> 2; + const int g = (((c0 >> 8) & 0xff) + ((c1 >> 8) & 0xff) + ((c2 >> 8) & 0xff) + ((c3 >> 8) & 0xff)) >> 2; + const int b = ((c0 & 0xff) + (c1 & 0xff) + (c2 & 0xff) + (c3 & 0xff)) >> 2; + return (a << 24) | (r << 16) | (g << 8) | b; +} + int Texture::crispBlend(int c0, int c1) { int a0 = static_cast(((c0 & 0xff000000) >> 24)) & 0xff; diff --git a/Minecraft.Client/Texture.h b/Minecraft.Client/Texture.h index c6f30aaf..9d3329c9 100644 --- a/Minecraft.Client/Texture.h +++ b/Minecraft.Client/Texture.h @@ -96,4 +96,5 @@ public: ByteBuffer *getData(unsigned int level = 0); static int crispBlend(int c0, int c1); + static int averageMipColors(int c0, int c1, int c2, int c3); }; \ No newline at end of file diff --git a/Minecraft.Client/Textures.cpp b/Minecraft.Client/Textures.cpp index 24c88b1a..6c8a1fd4 100644 --- a/Minecraft.Client/Textures.cpp +++ b/Minecraft.Client/Textures.cpp @@ -856,7 +856,7 @@ void Textures::loadTexture(BufferedImage *img, int id, bool blur, bool clamp) c2 = ( ( c2 >> 8 ) & 0x00ffffff ) | ( c2 << 24 ); c3 = ( ( c3 >> 8 ) & 0x00ffffff ) | ( c3 << 24 ); #endif - int col = Texture::crispBlend(Texture::crispBlend(c0, c1), Texture::crispBlend(c2, c3)); + int col = Texture::averageMipColors(c0, c1, c2, c3); #ifndef _XBOX // 4J - and back from ARGB -> RGBA col = ( col << 8 ) | (( col >> 24 ) & 0xff);