コード例 #1
0
ファイル: Texture.cs プロジェクト: klightspeed/RS5-Extractor
        protected static Color[,] GetDXT1ColourBlock(SubStream data, int offset, bool IsDXT3)
        {
            ushort c0v = data.GetUInt16(offset);
            ushort c1v = data.GetUInt16(offset + 2);

            Color[] c = new Color[4];

            c[0] = Color.FromArgb(0xFF, (c0v >> 8) & 0xF8, (c0v >> 3) & 0xFC, (c0v << 3) & 0xF8);
            c[1] = Color.FromArgb(0xFF, (c1v >> 8) & 0xF8, (c1v >> 3) & 0xFC, (c1v << 3) & 0xF8);

            if (c0v > c1v || IsDXT3)
            {
                c[2] = Color.FromArgb(0xFF, ((int)c[0].R * 2 + c[1].R + 1) / 3, ((int)c[0].G * 2 + c[1].G + 1) / 3, ((int)c[0].B * 2 + c[1].B + 1) / 3);
                c[3] = Color.FromArgb(0xFF, ((int)c[1].R * 2 + c[0].R + 1) / 3, ((int)c[1].G * 2 + c[0].G + 1) / 3, ((int)c[1].B * 2 + c[0].B + 1) / 3);
            }
            else
            {
                c[2] = Color.FromArgb(0xFF, ((int)c[0].R + c[1].R) / 2, ((int)c[0].G + c[1].G) / 2, ((int)c[0].B + c[1].B) / 2);
                c[3] = Color.FromArgb(0, 0, 0, 0);
            }

            ulong lookup = data.GetUInt32(offset + 4);

            Color[,] output = new Color[4, 4];

            for (int i = 0; i < 16; i++)
            {
                output[i % 4, i / 4] = c[(lookup >> (i * 2)) & 3];
            }

            return(output);
        }
コード例 #2
0
ファイル: Texture.cs プロジェクト: klightspeed/RS5-Extractor
        protected static Color[,] GetDXT1ColourBlock(SubStream data, int offset, bool IsDXT3)
        {
            ushort c0v = data.GetUInt16(offset);
            ushort c1v = data.GetUInt16(offset + 2);
            Color[] c = new Color[4];

            c[0] = Color.FromArgb(0xFF, (c0v >> 8) & 0xF8, (c0v >> 3) & 0xFC, (c0v << 3) & 0xF8);
            c[1] = Color.FromArgb(0xFF, (c1v >> 8) & 0xF8, (c1v >> 3) & 0xFC, (c1v << 3) & 0xF8);

            if (c0v > c1v || IsDXT3)
            {
                c[2] = Color.FromArgb(0xFF, ((int)c[0].R * 2 + c[1].R + 1) / 3, ((int)c[0].G * 2 + c[1].G + 1) / 3, ((int)c[0].B * 2 + c[1].B + 1) / 3);
                c[3] = Color.FromArgb(0xFF, ((int)c[1].R * 2 + c[0].R + 1) / 3, ((int)c[1].G * 2 + c[0].G + 1) / 3, ((int)c[1].B * 2 + c[0].B + 1) / 3);
            }
            else
            {
                c[2] = Color.FromArgb(0xFF, ((int)c[0].R + c[1].R) / 2, ((int)c[0].G + c[1].G) / 2, ((int)c[0].B + c[1].B) / 2);
                c[3] = Color.FromArgb(0, 0, 0, 0);
            }

            ulong lookup = data.GetUInt32(offset + 4);
            Color[,] output = new Color[4, 4];

            for (int i = 0; i < 16; i++)
            {
                output[i % 4, i / 4] = c[(lookup >> (i * 2)) & 3];
            }

            return output;
        }
コード例 #3
0
ファイル: Texture.cs プロジェクト: klightspeed/RS5-Extractor
        public DDSImage(SubStream data)
        {
            if (data.GetByte(0) == 'D' && data.GetByte(1) == 'D' && data.GetByte(2) == 'S' && data.GetByte(3) == ' ')
            {
                Height = data.GetInt32(12);
                Width = data.GetInt32(16);
                Depth = data.GetInt32(24);
                Flags = data.GetUInt32(8);
                Pitch = data.GetInt32(20);
                FourCC = Encoding.ASCII.GetString(data.GetBytes(84, 4));
                RGBBitCount = data.GetInt32(88);
                RedMask = data.GetUInt32(92);
                GreenMask = data.GetUInt32(96);
                BlueMask = data.GetUInt32(100);
                AlphaMask = data.GetUInt32(104);
                Data = data;
                ImageOffset = 128;

                if (Depth == 0)
                {
                    Depth = 1;
                }

                if ((Flags & 8) == 0)
                {
                    Pitch = Width * RGBBitCount / 8;
                }

                IsARGB32 = (FourCC == "DXT1" || FourCC == "DXT2" || FourCC == "DXT3" || FourCC == "DXT4" || FourCC == "DXT5" || FourCC == "\0\0\0\0");
                IntensityFactor = 1.0;

                try
                {
                    FailureReason = null;
                    switch (FourCC)
                    {
                        case "DXT1":
                            Bitmap = GetBitmapFromDDS_DXT1(Data, ImageOffset, Width, Height, out HasAlpha);
                            break;
                        case "DXT2":
                            Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, true, out HasAlpha);
                            break;
                        case "DXT3":
                            Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, false, out HasAlpha);
                            break;
                        case "DXT4":
                            Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, true, out HasAlpha);
                            break;
                        case "DXT5":
                            Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, false, out HasAlpha);
                            break;
                        case "\0\0\0\0":
                            Bitmap = GetBitmapFromDDS_RAW(Data, ImageOffset, Width, Height, Pitch, RGBBitCount, RedMask, GreenMask, BlueMask, AlphaMask, out HasAlpha, out IsARGB32);
                            break;
                        case "q\0\0\0":
                            Bitmap = GetBitmapFromDDS_ARGB16F(Data, ImageOffset, Width, Height, out HasAlpha, out IntensityFactor);
                            break;
                        default:
                            Bitmap = null;
                            FailureReason = String.Format("Unknown DDS FourCC {0:X2}:{1:X2}:{2:X2}:{3:X2}", Data.GetByte(84), Data.GetByte(85), Data.GetByte(86), Data.GetByte(87));
                            break;
                    }
                }
                catch (Exception ex)
                {
                    Bitmap = null;
                    FailureReason = ex.Message;
                }
            }
            else
            {
                throw new NotImplementedException(String.Format("Unknown file format {0:X2}:{1:X2}:{2:X2}:{3:X2}", data.GetByte(0), data.GetByte(1), data.GetByte(2), data.GetByte(3)));
            }
        }
コード例 #4
0
ファイル: Texture.cs プロジェクト: klightspeed/RS5-Extractor
        public DDSImage(SubStream data)
        {
            if (data.GetByte(0) == 'D' && data.GetByte(1) == 'D' && data.GetByte(2) == 'S' && data.GetByte(3) == ' ')
            {
                Height      = data.GetInt32(12);
                Width       = data.GetInt32(16);
                Depth       = data.GetInt32(24);
                Flags       = data.GetUInt32(8);
                Pitch       = data.GetInt32(20);
                FourCC      = Encoding.ASCII.GetString(data.GetBytes(84, 4));
                RGBBitCount = data.GetInt32(88);
                RedMask     = data.GetUInt32(92);
                GreenMask   = data.GetUInt32(96);
                BlueMask    = data.GetUInt32(100);
                AlphaMask   = data.GetUInt32(104);
                Data        = data;
                ImageOffset = 128;

                if (Depth == 0)
                {
                    Depth = 1;
                }

                if ((Flags & 8) == 0)
                {
                    Pitch = Width * RGBBitCount / 8;
                }

                IsARGB32        = (FourCC == "DXT1" || FourCC == "DXT2" || FourCC == "DXT3" || FourCC == "DXT4" || FourCC == "DXT5" || FourCC == "\0\0\0\0");
                IntensityFactor = 1.0;

                try
                {
                    FailureReason = null;
                    switch (FourCC)
                    {
                    case "DXT1":
                        Bitmap = GetBitmapFromDDS_DXT1(Data, ImageOffset, Width, Height, out HasAlpha);
                        break;

                    case "DXT2":
                        Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, true, out HasAlpha);
                        break;

                    case "DXT3":
                        Bitmap = GetBitmapFromDDS_DXT3(Data, ImageOffset, Width, Height, false, out HasAlpha);
                        break;

                    case "DXT4":
                        Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, true, out HasAlpha);
                        break;

                    case "DXT5":
                        Bitmap = GetBitmapFromDDS_DXT5(Data, ImageOffset, Width, Height, false, out HasAlpha);
                        break;

                    case "\0\0\0\0":
                        Bitmap = GetBitmapFromDDS_RAW(Data, ImageOffset, Width, Height, Pitch, RGBBitCount, RedMask, GreenMask, BlueMask, AlphaMask, out HasAlpha, out IsARGB32);
                        break;

                    case "q\0\0\0":
                        Bitmap = GetBitmapFromDDS_ARGB16F(Data, ImageOffset, Width, Height, out HasAlpha, out IntensityFactor);
                        break;

                    default:
                        Bitmap        = null;
                        FailureReason = String.Format("Unknown DDS FourCC {0:X2}:{1:X2}:{2:X2}:{3:X2}", Data.GetByte(84), Data.GetByte(85), Data.GetByte(86), Data.GetByte(87));
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Bitmap        = null;
                    FailureReason = ex.Message;
                }
            }
            else
            {
                throw new NotImplementedException(String.Format("Unknown file format {0:X2}:{1:X2}:{2:X2}:{3:X2}", data.GetByte(0), data.GetByte(1), data.GetByte(2), data.GetByte(3)));
            }
        }