public init ( uint w, uint h, |
||
w | uint | |
h | uint | |
data | ||
x | uint | |
y | uint | |
리턴 | void |
public void init(uint w, uint h, Color32[] data, uint x, uint y)
{
uint bw = Math.Min(w - x, 4U);
uint bh = Math.Min(h - y, 4U);
// Blocks that are smaller than 4x4 are handled by repeating the pixels.
// @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :(
// @@ Ideally we should zero the weights of the pixels out of range.
for (uint i = 0; i < 4; i++)
{
uint by = i % bh;
for (uint e = 0; e < 4; e++)
{
uint bx = e % bw;
uint idx = (y + by) * w + x + bx;
m_color[e, i] = data[idx];
}
}
}
public static void GetDXT(Texture2D texture, int i, byte[] bytes, TextureFormat format) { Color32[] colors = texture.GetPixels32(i); uint w = (uint)texture.width >> i; uint h = (uint)texture.height >> i; ColorBlock rgba = new ColorBlock(); BlockDXT1 block1 = new BlockDXT1(); BlockDXT5 block5 = new BlockDXT5(); int blocksize = format == TextureFormat.DXT1 ? 8 : 16; int index = 0; for (uint y = 0; y < h; y += 4) { for (uint x = 0; x < w; x += 4) { rgba.init(w, h, colors, x, y); if (format == TextureFormat.DXT1) { QuickCompress.compressDXT1(rgba, block1); block1.WriteBytes(bytes, index); } else { QuickCompress.compressDXT5(rgba, block5, 0); block5.WriteBytes(bytes, index); } index += blocksize; } } }