示例#1
0
        static void ComputeEndpoints(
            ASTCPixel[] EndPoints,
            int[]       ColorValues,
            uint ColorEndpointMode,
            ref int ColorValuesPosition)
        {
            switch (ColorEndpointMode)
            {
            case 0:
            {
                uint[] Val = ReadUintColorValues(2, ColorValues, ref ColorValuesPosition);

                EndPoints[0] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[0], (short)Val[0]);
                EndPoints[1] = new ASTCPixel(0xFF, (short)Val[1], (short)Val[1], (short)Val[1]);

                break;
            }


            case 1:
            {
                uint[] Val = ReadUintColorValues(2, ColorValues, ref ColorValuesPosition);
                int    L0  = (int)((Val[0] >> 2) | (Val[1] & 0xC0));
                int    L1  = (int)Math.Max(L0 + (Val[1] & 0x3F), 0xFFU);

                EndPoints[0] = new ASTCPixel(0xFF, (short)L0, (short)L0, (short)L0);
                EndPoints[1] = new ASTCPixel(0xFF, (short)L1, (short)L1, (short)L1);

                break;
            }

            case 4:
            {
                uint[] Val = ReadUintColorValues(4, ColorValues, ref ColorValuesPosition);

                EndPoints[0] = new ASTCPixel((short)Val[2], (short)Val[0], (short)Val[0], (short)Val[0]);
                EndPoints[1] = new ASTCPixel((short)Val[3], (short)Val[1], (short)Val[1], (short)Val[1]);

                break;
            }

            case 5:
            {
                int[] Val = ReadIntColorValues(4, ColorValues, ref ColorValuesPosition);

                BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]);
                BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]);

                EndPoints[0] = new ASTCPixel((short)Val[2], (short)Val[0], (short)Val[0], (short)Val[0]);
                EndPoints[1] = new ASTCPixel((short)(Val[2] + Val[3]), (short)(Val[0] + Val[1]), (short)(Val[0] + Val[1]), (short)(Val[0] + Val[1]));

                EndPoints[0].ClampByte();
                EndPoints[1].ClampByte();

                break;
            }

            case 6:
            {
                uint[] Val = ReadUintColorValues(4, ColorValues, ref ColorValuesPosition);

                EndPoints[0] = new ASTCPixel(0xFF, (short)(Val[0] * Val[3] >> 8), (short)(Val[1] * Val[3] >> 8), (short)(Val[2] * Val[3] >> 8));
                EndPoints[1] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[1], (short)Val[2]);

                break;
            }

            case 8:
            {
                uint[] Val = ReadUintColorValues(6, ColorValues, ref ColorValuesPosition);

                if (Val[1] + Val[3] + Val[5] >= Val[0] + Val[2] + Val[4])
                {
                    EndPoints[0] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[2], (short)Val[4]);
                    EndPoints[1] = new ASTCPixel(0xFF, (short)Val[1], (short)Val[3], (short)Val[5]);
                }
                else
                {
                    EndPoints[0] = ASTCPixel.BlueContract(0xFF, (short)Val[1], (short)Val[3], (short)Val[5]);
                    EndPoints[1] = ASTCPixel.BlueContract(0xFF, (short)Val[0], (short)Val[2], (short)Val[4]);
                }

                break;
            }

            case 9:
            {
                int[] Val = ReadIntColorValues(6, ColorValues, ref ColorValuesPosition);

                BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]);
                BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]);
                BitArrayStream.BitTransferSigned(ref Val[5], ref Val[4]);

                if (Val[1] + Val[3] + Val[5] >= 0)
                {
                    EndPoints[0] = new ASTCPixel(0xFF, (short)Val[0], (short)Val[2], (short)Val[4]);
                    EndPoints[1] = new ASTCPixel(0xFF, (short)(Val[0] + Val[1]), (short)(Val[2] + Val[3]), (short)(Val[4] + Val[5]));
                }
                else
                {
                    EndPoints[0] = ASTCPixel.BlueContract(0xFF, Val[0] + Val[1], Val[2] + Val[3], Val[4] + Val[5]);
                    EndPoints[1] = ASTCPixel.BlueContract(0xFF, Val[0], Val[2], Val[4]);
                }

                EndPoints[0].ClampByte();
                EndPoints[1].ClampByte();

                break;
            }

            case 10:
            {
                uint[] Val = ReadUintColorValues(6, ColorValues, ref ColorValuesPosition);

                EndPoints[0] = new ASTCPixel((short)Val[4], (short)(Val[0] * Val[3] >> 8), (short)(Val[1] * Val[3] >> 8), (short)(Val[2] * Val[3] >> 8));
                EndPoints[1] = new ASTCPixel((short)Val[5], (short)Val[0], (short)Val[1], (short)Val[2]);

                break;
            }

            case 12:
            {
                uint[] Val = ReadUintColorValues(8, ColorValues, ref ColorValuesPosition);

                if (Val[1] + Val[3] + Val[5] >= Val[0] + Val[2] + Val[4])
                {
                    EndPoints[0] = new ASTCPixel((short)Val[6], (short)Val[0], (short)Val[2], (short)Val[4]);
                    EndPoints[1] = new ASTCPixel((short)Val[7], (short)Val[1], (short)Val[3], (short)Val[5]);
                }
                else
                {
                    EndPoints[0] = ASTCPixel.BlueContract((short)Val[7], (short)Val[1], (short)Val[3], (short)Val[5]);
                    EndPoints[1] = ASTCPixel.BlueContract((short)Val[6], (short)Val[0], (short)Val[2], (short)Val[4]);
                }

                break;
            }

            case 13:
            {
                int[] Val = ReadIntColorValues(8, ColorValues, ref ColorValuesPosition);

                BitArrayStream.BitTransferSigned(ref Val[1], ref Val[0]);
                BitArrayStream.BitTransferSigned(ref Val[3], ref Val[2]);
                BitArrayStream.BitTransferSigned(ref Val[5], ref Val[4]);
                BitArrayStream.BitTransferSigned(ref Val[7], ref Val[6]);

                if (Val[1] + Val[3] + Val[5] >= 0)
                {
                    EndPoints[0] = new ASTCPixel((short)Val[6], (short)Val[0], (short)Val[2], (short)Val[4]);
                    EndPoints[1] = new ASTCPixel((short)(Val[7] + Val[6]), (short)(Val[0] + Val[1]), (short)(Val[2] + Val[3]), (short)(Val[4] + Val[5]));
                }
                else
                {
                    EndPoints[0] = ASTCPixel.BlueContract(Val[6] + Val[7], Val[0] + Val[1], Val[2] + Val[3], Val[4] + Val[5]);
                    EndPoints[1] = ASTCPixel.BlueContract(Val[6], Val[0], Val[2], Val[4]);
                }

                EndPoints[0].ClampByte();
                EndPoints[1].ClampByte();

                break;
            }

            default:
                throw new ASTCDecoderException("Unsupported color endpoint mode (is it HDR?)");
            }
        }
示例#2
0
        static void ComputeEndpoints(
            AstcPixel[] endPoints,
            int[]       colorValues,
            uint colorEndpointMode,
            ref int colorValuesPosition)
        {
            switch (colorEndpointMode)
            {
            case 0:
            {
                uint[] val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);

                endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[0], (short)val[0]);
                endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[1], (short)val[1]);

                break;
            }


            case 1:
            {
                uint[] val = ReadUintColorValues(2, colorValues, ref colorValuesPosition);
                int    l0  = (int)((val[0] >> 2) | (val[1] & 0xC0));
                int    l1  = (int)Math.Max(l0 + (val[1] & 0x3F), 0xFFU);

                endPoints[0] = new AstcPixel(0xFF, (short)l0, (short)l0, (short)l0);
                endPoints[1] = new AstcPixel(0xFF, (short)l1, (short)l1, (short)l1);

                break;
            }

            case 4:
            {
                uint[] val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);

                endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
                endPoints[1] = new AstcPixel((short)val[3], (short)val[1], (short)val[1], (short)val[1]);

                break;
            }

            case 5:
            {
                int[] val = ReadIntColorValues(4, colorValues, ref colorValuesPosition);

                BitArrayStream.BitTransferSigned(ref val[1], ref val[0]);
                BitArrayStream.BitTransferSigned(ref val[3], ref val[2]);

                endPoints[0] = new AstcPixel((short)val[2], (short)val[0], (short)val[0], (short)val[0]);
                endPoints[1] = new AstcPixel((short)(val[2] + val[3]), (short)(val[0] + val[1]), (short)(val[0] + val[1]), (short)(val[0] + val[1]));

                endPoints[0].ClampByte();
                endPoints[1].ClampByte();

                break;
            }

            case 6:
            {
                uint[] val = ReadUintColorValues(4, colorValues, ref colorValuesPosition);

                endPoints[0] = new AstcPixel(0xFF, (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
                endPoints[1] = new AstcPixel(0xFF, (short)val[0], (short)val[1], (short)val[2]);

                break;
            }

            case 8:
            {
                uint[] val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);

                if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
                {
                    endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
                    endPoints[1] = new AstcPixel(0xFF, (short)val[1], (short)val[3], (short)val[5]);
                }
                else
                {
                    endPoints[0] = AstcPixel.BlueContract(0xFF, (short)val[1], (short)val[3], (short)val[5]);
                    endPoints[1] = AstcPixel.BlueContract(0xFF, (short)val[0], (short)val[2], (short)val[4]);
                }

                break;
            }

            case 9:
            {
                int[] val = ReadIntColorValues(6, colorValues, ref colorValuesPosition);

                BitArrayStream.BitTransferSigned(ref val[1], ref val[0]);
                BitArrayStream.BitTransferSigned(ref val[3], ref val[2]);
                BitArrayStream.BitTransferSigned(ref val[5], ref val[4]);

                if (val[1] + val[3] + val[5] >= 0)
                {
                    endPoints[0] = new AstcPixel(0xFF, (short)val[0], (short)val[2], (short)val[4]);
                    endPoints[1] = new AstcPixel(0xFF, (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
                }
                else
                {
                    endPoints[0] = AstcPixel.BlueContract(0xFF, val[0] + val[1], val[2] + val[3], val[4] + val[5]);
                    endPoints[1] = AstcPixel.BlueContract(0xFF, val[0], val[2], val[4]);
                }

                endPoints[0].ClampByte();
                endPoints[1].ClampByte();

                break;
            }

            case 10:
            {
                uint[] val = ReadUintColorValues(6, colorValues, ref colorValuesPosition);

                endPoints[0] = new AstcPixel((short)val[4], (short)(val[0] * val[3] >> 8), (short)(val[1] * val[3] >> 8), (short)(val[2] * val[3] >> 8));
                endPoints[1] = new AstcPixel((short)val[5], (short)val[0], (short)val[1], (short)val[2]);

                break;
            }

            case 12:
            {
                uint[] val = ReadUintColorValues(8, colorValues, ref colorValuesPosition);

                if (val[1] + val[3] + val[5] >= val[0] + val[2] + val[4])
                {
                    endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
                    endPoints[1] = new AstcPixel((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
                }
                else
                {
                    endPoints[0] = AstcPixel.BlueContract((short)val[7], (short)val[1], (short)val[3], (short)val[5]);
                    endPoints[1] = AstcPixel.BlueContract((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
                }

                break;
            }

            case 13:
            {
                int[] val = ReadIntColorValues(8, colorValues, ref colorValuesPosition);

                BitArrayStream.BitTransferSigned(ref val[1], ref val[0]);
                BitArrayStream.BitTransferSigned(ref val[3], ref val[2]);
                BitArrayStream.BitTransferSigned(ref val[5], ref val[4]);
                BitArrayStream.BitTransferSigned(ref val[7], ref val[6]);

                if (val[1] + val[3] + val[5] >= 0)
                {
                    endPoints[0] = new AstcPixel((short)val[6], (short)val[0], (short)val[2], (short)val[4]);
                    endPoints[1] = new AstcPixel((short)(val[7] + val[6]), (short)(val[0] + val[1]), (short)(val[2] + val[3]), (short)(val[4] + val[5]));
                }
                else
                {
                    endPoints[0] = AstcPixel.BlueContract(val[6] + val[7], val[0] + val[1], val[2] + val[3], val[4] + val[5]);
                    endPoints[1] = AstcPixel.BlueContract(val[6], val[0], val[2], val[4]);
                }

                endPoints[0].ClampByte();
                endPoints[1].ClampByte();

                break;
            }

            default:
                throw new AstcDecoderException("Unsupported color endpoint mode (is it HDR?)");
            }
        }