private static byte[] ConvertBlockToCmpr(byte[] block)
        {
            byte[] numArray = new byte[32];
            byte[] block1   = new byte[64];
            int    num1     = 0;
            int    num2     = 0;
            int    num3     = 0;

            for (; num1 < block.Length / 64; ++num1)
            {
                Array.Copy((Array)block, num2 + num3, (Array)block1, 0, 16);
                Array.Copy((Array)block, num2 + num3 + 32, (Array)block1, 16, 16);
                Array.Copy((Array)block, num2 + num3 + 64, (Array)block1, 32, 16);
                Array.Copy((Array)block, num2 + num3 + 96, (Array)block1, 48, 16);
                num2 = 16 - num2;
                if (num2 == 0)
                {
                    num3 = 128;
                }
                ImageDataFormat.ConvertBlockToQuaterCmpr(block1).CopyTo((Array)numArray, num1 << 3);
            }
            return(numArray);
        }
        private static byte[] ConvertBlockFromCmpr(byte[] block)
        {
            byte[]   numArray1 = new byte[256];
            byte[][] numArray2 = new byte[4][];
            int      index     = 0;
            int      num1      = 0;
            int      num2      = 0;

            for (; index < block.Length / 8; ++index)
            {
                numArray2[index] = ImageDataFormat.ConvertBlockFromQuaterCmpr(block, index << 3);
                Array.Copy((Array)numArray2[index], 0, (Array)numArray1, num1 + num2, 16);
                Array.Copy((Array)numArray2[index], 16, (Array)numArray1, num1 + num2 + 32, 16);
                Array.Copy((Array)numArray2[index], 32, (Array)numArray1, num1 + num2 + 64, 16);
                Array.Copy((Array)numArray2[index], 48, (Array)numArray1, num1 + num2 + 96, 16);
                num1 = 16 - num1;
                if (num1 == 0)
                {
                    num2 = 128;
                }
            }
            return(numArray1);
        }
        private static int LeastDistance(byte[][] palette, byte[] colour, int offset)
        {
            if (colour[offset + 3] < (byte)8)
            {
                return(3);
            }
            int num1 = int.MaxValue;
            int num2 = 0;

            for (int index = 0; index < palette.Length && palette[index][3] == byte.MaxValue; ++index)
            {
                int num3 = ImageDataFormat.Distance(palette[index], 0, colour, offset);
                if (num3 < num1)
                {
                    if (num3 == 0)
                    {
                        return(index);
                    }
                    num1 = num3;
                    num2 = index;
                }
            }
            return(num2);
        }
        private static byte[] ConvertBlockToQuaterCmpr(byte[] block)
        {
            int  num1;
            int  num2 = num1 = -1;
            int  num3 = num1;
            int  num4 = num1;
            bool flag = false;

            byte[] numArray = new byte[8];
            for (int index1 = 0; index1 < 15; ++index1)
            {
                if (block[index1 * 4 + 3] < (byte)16)
                {
                    flag = true;
                }
                else
                {
                    for (int index2 = index1 + 1; index2 < 16; ++index2)
                    {
                        int num5 = ImageDataFormat.Distance(block, index1 * 4, block, index2 * 4);
                        if (num5 > num4)
                        {
                            num4 = num5;
                            num3 = index1;
                            num2 = index2;
                        }
                    }
                }
            }
            byte[][] palette;
            if (num4 == -1)
            {
                palette = new byte[4][]
                {
                    new byte[4] {
                        (byte)0, (byte)0, (byte)0, byte.MaxValue
                    },
                    new byte[4]
                    {
                        byte.MaxValue,
                        byte.MaxValue,
                        byte.MaxValue,
                        byte.MaxValue
                    },
                    null,
                    null
                };
            }
            else
            {
                palette = new byte[4][]
                {
                    new byte[4],
                    new byte[4],
                    null,
                    null
                };
                Array.Copy((Array)block, num3 * 4, (Array)palette[0], 0, 3);
                palette[0][3] = byte.MaxValue;
                Array.Copy((Array)block, num2 * 4, (Array)palette[1], 0, 3);
                palette[1][3] = byte.MaxValue;
                if ((int)palette[0][0] >> 3 == (int)palette[1][0] >> 3 && (int)palette[0][1] >> 2 == (int)palette[1][1] >> 2 && (int)palette[0][2] >> 3 == (int)palette[1][2] >> 3)
                {
                    int num5 = (int)palette[0][0] >> 3 != 0 || (int)palette[0][1] >> 2 != 0 ? 1 : ((int)palette[0][2] >> 3 != 0 ? 1 : 0);
                    palette[1][0] = num5 != 0 ? (palette[1][1] = palette[1][2] = (byte)0) : (palette[1][1] = palette[1][2] = byte.MaxValue);
                }
            }
            numArray[0] = (byte)((int)palette[0][2] & 248 | (int)palette[0][1] >> 5);
            numArray[1] = (byte)((int)palette[0][1] << 3 & 224 | (int)palette[0][0] >> 3);
            numArray[2] = (byte)((int)palette[1][2] & 248 | (int)palette[1][1] >> 5);
            numArray[3] = (byte)((int)palette[1][1] << 3 & 224 | (int)palette[1][0] >> 3);
            if (((int)numArray[0] > (int)numArray[2] ? 1 : ((int)numArray[0] != (int)numArray[2] ? 0 : ((int)numArray[1] >= (int)numArray[3] ? 1 : 0))) == (flag ? 1 : 0))
            {
                Array.Copy((Array)numArray, 0, (Array)numArray, 4, 2);
                Array.Copy((Array)numArray, 2, (Array)numArray, 0, 2);
                Array.Copy((Array)numArray, 4, (Array)numArray, 2, 2);
                palette[2] = palette[0];
                palette[0] = palette[1];
                palette[1] = palette[2];
            }
            if (!flag)
            {
                palette[2] = new byte[4]
                {
                    (byte)((((int)palette[0][0] << 1) + (int)palette[1][0]) / 3),
                    (byte)((((int)palette[0][1] << 1) + (int)palette[1][1]) / 3),
                    (byte)((((int)palette[0][2] << 1) + (int)palette[1][2]) / 3),
                    byte.MaxValue
                };
                palette[3] = new byte[4]
                {
                    (byte)(((int)palette[0][0] + ((int)palette[1][0] << 1)) / 3),
                    (byte)(((int)palette[0][1] + ((int)palette[1][1] << 1)) / 3),
                    (byte)(((int)palette[0][2] + ((int)palette[1][2] << 1)) / 3),
                    byte.MaxValue
                };
            }
            else
            {
                palette[2] = new byte[4]
                {
                    (byte)((int)palette[0][0] + (int)palette[1][0] >> 1),
                    (byte)((int)palette[0][1] + (int)palette[1][1] >> 1),
                    (byte)((int)palette[0][2] + (int)palette[1][2] >> 1),
                    byte.MaxValue
                };
                palette[3] = new byte[4];
            }
            for (int index = 0; index < block.Length >> 4; ++index)
            {
                numArray[4 + index] = (byte)(ImageDataFormat.LeastDistance(palette, block, index * 16) << 6 | ImageDataFormat.LeastDistance(palette, block, index * 16 + 4) << 4 | ImageDataFormat.LeastDistance(palette, block, index * 16 + 8) << 2 | ImageDataFormat.LeastDistance(palette, block, index * 16 + 12));
            }
            return(numArray);
        }