コード例 #1
0
        public void ConversionToBytesSetsColorIndexes()
        {
            byte expectedIndexes0 = "11 10 01 00".AsByte(); // d c b a
            byte expectedIndexes1 = "00 11 10 01".AsByte(); // h g f e
            byte expectedIndexes2 = "01 00 11 10".AsByte(); // l k j i
            byte expectedIndexes3 = "10 01 00 11".AsByte(); // p o n m

            var block = new BC3BlockData();

            // pixel    value    byte
            block.ColorIndexes[0]  = 0;     // a(0,3)   00       indexes0
            block.ColorIndexes[1]  = 1;     // b(1,3)   01
            block.ColorIndexes[2]  = 2;     // c(2,3)   10
            block.ColorIndexes[3]  = 3;     // d(3,3)   11
            block.ColorIndexes[4]  = 1;     // e(0,2)   01       indexes1
            block.ColorIndexes[5]  = 2;     // f(1,2)   10
            block.ColorIndexes[6]  = 3;     // g(2,2)   11
            block.ColorIndexes[7]  = 0;     // h(3,2)   00
            block.ColorIndexes[8]  = 2;     // i(0,1)   10       indexes2
            block.ColorIndexes[9]  = 3;     // j(1,1)   11
            block.ColorIndexes[10] = 0;     // k(2,1)   00
            block.ColorIndexes[11] = 1;     // l(3,1)   01
            block.ColorIndexes[12] = 3;     // m(0,0)   11       indexes3
            block.ColorIndexes[13] = 0;     // n(1,0)   00
            block.ColorIndexes[14] = 1;     // o(2,0)   01
            block.ColorIndexes[15] = 2;     // p(3,0)   10

            var buffer = block.ToBytes();

            byte indexes0 = buffer[12];
            byte indexes1 = buffer[13];
            byte indexes2 = buffer[14];
            byte indexes3 = buffer[15];

            Assert.AreEqual(expectedIndexes0, indexes0);
            Assert.AreEqual(expectedIndexes1, indexes1);
            Assert.AreEqual(expectedIndexes2, indexes2);
            Assert.AreEqual(expectedIndexes3, indexes3);
        }
コード例 #2
0
        public void ConstructionFromBytesSetsAlphaIndexes()
        {
            // Increment until max value, then decrement
            byte alphas0 = "10  001 000".AsByte(); // c b a
            byte alphas1 = "1 100 011 0".AsByte(); // f e d c
            byte alphas2 = "111 110  10".AsByte(); // h g f
            byte alphas3 = "01  110 111".AsByte(); // k j i
            byte alphas4 = "0 011 100 1".AsByte(); // n m l k
            byte alphas5 = "000 001  01".AsByte(); // p o n

            var bytes = new byte[BlockFormat.BC3ByteSize];

            bytes[2] = alphas2;
            bytes[3] = alphas1;
            bytes[4] = alphas0;
            bytes[5] = alphas5;
            bytes[6] = alphas4;
            bytes[7] = alphas3;

            var block = BC3BlockData.FromBytes(bytes);

            Assert.AreEqual(0, block.AlphaIndexes[0]);  // a    000
            Assert.AreEqual(1, block.AlphaIndexes[1]);  // b    001
            Assert.AreEqual(2, block.AlphaIndexes[2]);  // c    010
            Assert.AreEqual(3, block.AlphaIndexes[3]);  // d    011
            Assert.AreEqual(4, block.AlphaIndexes[4]);  // e    100
            Assert.AreEqual(5, block.AlphaIndexes[5]);  // f    101
            Assert.AreEqual(6, block.AlphaIndexes[6]);  // g    110
            Assert.AreEqual(7, block.AlphaIndexes[7]);  // h    111
            Assert.AreEqual(7, block.AlphaIndexes[8]);  // i    111
            Assert.AreEqual(6, block.AlphaIndexes[9]);  // j    110
            Assert.AreEqual(5, block.AlphaIndexes[10]); // k    101
            Assert.AreEqual(4, block.AlphaIndexes[11]); // l    100
            Assert.AreEqual(3, block.AlphaIndexes[12]); // m    011
            Assert.AreEqual(2, block.AlphaIndexes[13]); // n    010
            Assert.AreEqual(1, block.AlphaIndexes[14]); // o    001
            Assert.AreEqual(0, block.AlphaIndexes[15]); // p    000
        }