public static DecompressColour ( byte block, int blockOffset, bool isDxt1 ) : byte[] | ||
block | byte | |
blockOffset | int | |
isDxt1 | bool | |
Résultat | byte[] |
public static byte[] DecompressColour(byte[] block, int blockOffset, bool isDxt1)
{
// Unpack the endpoints
var codes = new byte[16];
var a = Unpack565(block, blockOffset + 0, codes, 0);
var b = Unpack565(block, blockOffset + 2, codes, 4);
// Generate the midpoints.
for (int i = 0; i < 3; ++i)
{
var c = codes[i];
var d = codes[4 + i];
if (isDxt1 && a <= b)
{
codes[8 + i] = (byte)((c + d) / 2);
codes[12 + i] = 0;
}
else
{
codes[8 + i] = (byte)(((2 * c) + d) / 3);
codes[12 + i] = (byte)((c + (2 * d)) / 3);
}
}
// Fill in alpha for the intermediate values.
codes[8 + 3] = 255;
codes[12 + 3] = (byte)((isDxt1 && a <= b) ? 0 : 255);
// Unpack the indices
var indices = new byte[16];
for (int i = 0; i < 4; i++)
{
var packed = block[blockOffset + 4 + i];
indices[4 * i + 0] = (byte)(packed & 0x3);
indices[4 * i + 1] = (byte)((packed >> 2) & 0x3);
indices[4 * i + 2] = (byte)((packed >> 4) & 0x3);
indices[4 * i + 3] = (byte)((packed >> 6) & 0x3);
}
// Store the colours
var rgba = new byte[4 * 16];
for (int i = 0; i < 16; ++i)
{
var offset = 4 * indices[i];
for (int j = 0; j < 4; ++j)
{
rgba[4 * i + j] = codes[offset + j];
}
}
return rgba;
}
public static byte[] DecompressBlock(byte[] block, int blockOffset, SquishOptions flags) { // Get the block locations var colOff = blockOffset; var alphaOff = blockOffset; if ((flags & (SquishOptions.DXT3 | SquishOptions.DXT5)) != 0) { colOff += 8; } // Decompress colour. var rgba = ColourBlock.DecompressColour(block, colOff, flags.HasFlag(SquishOptions.DXT1)); // Decompress alpha seperately if necessary. if (flags.HasFlag(SquishOptions.DXT3)) { Alpha.DecompressAlphaDxt3(block, alphaOff, rgba, 0); } else if (flags.HasFlag(SquishOptions.DXT5)) { Alpha.DecompressAlphaDxt5(block, alphaOff, rgba, 0); } return(rgba); }