public void CompressNotPowTexture() { var width = 7; var height = 5; var sourcePixels = new Color32[height * width]; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { Color32 c; if (x == width - 1 && y == height - 1) { c = new Color32(0xD8, 0xF8, 0x08, 0xD0); } else if (x == 0) { c = new Color32(0x88, 0xE0, 0x70, 0x30); } else if (y == 0) { c = new Color32(0x40, 0x48, 0x70, 0xF8); } else if (x == width - 1) { c = new Color32(0x78, 0xF8, 0x00, 0xA0); } else if (y == height - 1) { c = new Color32(0xF8, 0xA8, 0x50, 0xD8); } else { c = new Color32(0xD0, 0xC0, 0x88, 0xB8); } sourcePixels[y * width + x] = c; } } var compressed = DDS.Compress(width, height, sourcePixels, false, false); var compressedWithAlpha = DDS.Compress(width, height, sourcePixels, true, false); //Debug.Log(string.Join(", ", compressed.Select(_=>string.Format("0x{0:X2}", _)))); //Debug.Log(string.Join(", ", compressedWithAlpha.Select(_ => string.Format("0x{0:X2}", _)))); Assert.AreEqual(new byte[] { 0x6E, 0xF5, 0x0F, 0x87, 0x01, 0xA9, 0xA9, 0xA9, 0xCF, 0xDD, 0xC0, 0x87, 0xF0, 0x50, 0x50, 0x50, 0xEE, 0x8E, 0x4E, 0x42, 0x54, 0x54, 0x54, 0x54, 0x8F, 0x4A, 0xCB, 0x29, 0xAA, 0xAA, 0xAA, 0xAA }, compressed); Assert.AreEqual(new byte[] { 0xD8, 0x30, 0x01, 0x10, 0x49, 0x91, 0x14, 0x49, 0x6E, 0xF5, 0x0F, 0x87, 0x01, 0xA9, 0xA9, 0xA9, 0xD8, 0xA0, 0x80, 0xD4, 0x26, 0x6D, 0xD2, 0x26, 0xCF, 0xDD, 0xC0, 0x87, 0xF0, 0x50, 0x50, 0x50, 0xF8, 0x30, 0x01, 0x10, 0x00, 0x01, 0x10, 0x00, 0xEE, 0x8E, 0x4E, 0x42, 0x54, 0x54, 0x54, 0x54, 0xF8, 0xF8, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x8F, 0x4A, 0xCB, 0x29, 0xAA, 0xAA, 0xAA, 0xAA }, compressedWithAlpha); compressed = DDS.Compress(width, height, sourcePixels, false, true); compressedWithAlpha = DDS.Compress(width, height, sourcePixels, true, true); Assert.AreEqual(new byte[] { 0x2D, 0xED, 0xCF, 0x8E, 0x01, 0xA9, 0xA9, 0xA9, 0xAE, 0xDD, 0xA0, 0x7F, 0xF0, 0x50, 0x50, 0x50, 0xCD, 0x86, 0x2D, 0x3A, 0x54, 0x54, 0x54, 0x54, 0x8F, 0x4A, 0xCB, 0x29, 0xAA, 0xAA, 0xAA, 0xAA }, compressed); Assert.AreEqual(new byte[] { 0xD8, 0x30, 0x01, 0x10, 0x49, 0x91, 0x14, 0x49, 0x2D, 0xED, 0xCF, 0x8E, 0x01, 0xA9, 0xA9, 0xA9, 0xD8, 0xA0, 0x80, 0xD4, 0x26, 0x6D, 0xD2, 0x26, 0xAE, 0xDD, 0xA0, 0x7F, 0xF0, 0x50, 0x50, 0x50, 0xF8, 0x30, 0x01, 0x10, 0x00, 0x01, 0x10, 0x00, 0xCD, 0x86, 0x2D, 0x3A, 0x54, 0x54, 0x54, 0x54, 0xF8, 0xF8, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x8F, 0x4A, 0xCB, 0x29, 0xAA, 0xAA, 0xAA, 0xAA }, compressedWithAlpha); }
public void CompressSingleColorTexture_MatchRepeatedBlocks(int width, int height) { var res = DDS.Compress(width, height, GenArray(width, height, new Color32(0xB8, 0xD0, 0xC0, 0xFF)), false); var block = DDS.Compress(4, 4, GenArray(4, 4, new Color32(0xB8, 0xD0, 0xC0, 0xFF)), false); Assert.AreEqual(res.Length, block.Length * ((width + 3) / 4) * ((height + 3) / 4)); for (int i = 0; i < res.Length; i += block.Length) { for (int j = 0; j < block.Length; ++j) { Assert.AreEqual(res[i + j], block[j]); } } }