Пример #1
0
            protected static XElement GetHEADData(SubStream data, string name)
            {
                int   v1           = data.GetInt32(0);
                float v2           = data.GetSingle(4);
                float v3           = data.GetSingle(8);
                float v4           = data.GetSingle(12);
                float v5           = data.GetSingle(16);
                float v6           = data.GetSingle(20);
                float v7           = data.GetSingle(24);
                float v8           = data.GetSingle(28);
                float lodhimindist = data.GetSingle(32);
                float lodhimaxdist = data.GetSingle(36);
                float lodlomindist = data.GetSingle(40);
                float lodlomaxdist = data.GetSingle(44);
                int   v13          = data.GetInt32(48);

                return(new XElement("IMDL_HEAD",
                                    new XElement("v1", v1),
                                    new XElement("vf", String.Format("{0,12:F6} {1,12:F6} {2,12:F6} {3,12:F6} {4,12:F6} {5,12:F6} {6,12:F6}", v2, v3, v4, v5, v6, v7, v8)),
                                    new XElement("LOD",
                                                 new XAttribute("level", "high"),
                                                 new XAttribute("mindist", lodhimindist),
                                                 new XAttribute("maxdist", lodhimaxdist)
                                                 ),
                                    new XElement("LOD",
                                                 new XAttribute("level", "low"),
                                                 new XAttribute("mindist", lodlomindist),
                                                 new XAttribute("maxdist", lodlomaxdist)
                                                 ),
                                    new XElement("Flags", v13)
                                    ));
            }
Пример #2
0
 protected static XElement GetBBHData(SubStream data)
 {
     return(new XElement("IMDL_BBH",
                         new XAttribute("count", data.Length / 4),
                         String.Join(" ", Enumerable.Range(0, (int)(data.Length / 4)).Select(i => data.GetInt32(i * 4)))
                         ));
 }
Пример #3
0
 private static SubStream GetChunkData(SubStream data, long offset)
 {
     int totalsize = (((12 + (int)data.GetByte(offset + 6) + 7) & -8) + data.GetInt32(offset + 8) + 7) & -8;
     return new SubStream(data, offset, totalsize);
 }
Пример #4
0
        private static SubStream GetChunkData(SubStream data, long offset)
        {
            int totalsize = (((12 + (int)data.GetByte(offset + 6) + 7) & -8) + data.GetInt32(offset + 8) + 7) & -8;

            return(new SubStream(data, offset, totalsize));
        }
Пример #5
0
        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)));
            }
        }
Пример #6
0
        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)));
            }
        }