Skip to content

Commit

Permalink
Merge pull request #291 from Kopernicus/paletteDDSloader
Browse files Browse the repository at this point in the history
Fix #281
StollD authored May 15, 2018
2 parents 6541833 + 4e870ad commit 8d21173
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/Kopernicus.OnDemand/OnDemandStorage.cs
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ public static Boolean EnableBody(String body)
return true;
}
return false;

}

// Unload all maps of a body
@@ -415,8 +415,55 @@ public static Texture2D LoadTexture(String path, Boolean compress, Boolean uploa
{
Debug.Log("[Kopernicus]: DX10 dds not supported: " + path);
}
else if (dDSHeader.ddspf.dwFourCC == DDSHeaders.DDSValues.uintMagic)
{
Debug.Log("[Kopernicus]: Magic dds not supported: " + path);
}
else if (dDSHeader.ddspf.dwRGBBitCount == 4 || dDSHeader.ddspf.dwRGBBitCount == 8)
{
try
{
byte[] data = LoadRestOfReader(binaryReader);

int bpp = (int)dDSHeader.ddspf.dwRGBBitCount;
int colors = (int)Math.Pow(2, bpp);
int width = (int)dDSHeader.dwWidth;
int height = (int)dDSHeader.dwHeight;

if (data.Length == width * height * bpp / 8 + 4 * colors)
{
Color[] palette = new Color[colors];
Color[] image = new Color[width * height];

for (int i = 0; i < 4 * colors; i = i + 4)
{
palette[i / 4] = new Color32(data[i + 0], data[i + 1], data[i + 2], data[i + 3]);
}

for (int i = 4 * colors; i < data.Length; i++)
{
image[(i - 4 * colors) * 8 / bpp] = palette[data[i] * colors / 256];
if (bpp == 4)
image[(i - 64) * 2 + 1] = palette[data[i] % 16];
}

map = new Texture2D(width, height, TextureFormat.ARGB32, mipmap);
map.SetPixels(image);
}
else
{
fourcc = false;
}
}
catch
{
fourcc = false;
}
}
else
{
fourcc = false;
}
}
if (!fourcc)
{
@@ -451,7 +498,7 @@ public static Texture2D LoadTexture(String path, Boolean compress, Boolean uploa
else
{
ok = false;
Debug.Log("[Kopernicus]: Only DXT1, DXT5, A8, RGB24, RGBA32, RGB565, ARGB4444 and RGBA4444 are supported");
Debug.Log("[Kopernicus]: Only DXT1, DXT5, A8, RGB24, RGBA32, RGB565, ARGB4444, RGBA4444, 4bpp palette and 8bpp palette are supported");
}
if (ok)
{

0 comments on commit 8d21173

Please sign in to comment.