Example #1
0
        public override int Read(string directoryname)
        {
            var stringList = new List <string>();
            var int32_1    = BigEndianBitConverter.ToInt32(fileData, iPos);

            ColoredConsole.WriteLine("{0:x8}  Number of File Names: {1:x8}", (object)iPos, (object)int32_1);
            iPos += 4;
            for (var index = 0; index < int32_1; ++index)
            {
                var int32_2 = BigEndianBitConverter.ToInt32(fileData, iPos);
                iPos += 4;
                var str = readString(int32_2);
                stringList.Add(str);
                ColoredConsole.WriteLine("{0:x8}    Name: {1}", (object)iPos, (object)str);
            }
            iPos += 5;
            for (var index = 0; index < stringList.Count; ++index)
            {
                var ddsFileSize = DdsHelper.CalculateDdsFileSize(iPos, fileData);
                ColoredConsole.WriteLine("{0:x8}    Size: {1:x8}", (object)iPos, (object)ddsFileSize);
                var fileStream = File.OpenWrite(directoryname + "\\" + $"{(object)index:0000}_" + Path.GetFileNameWithoutExtension(stringList[index]) + ".dds");
                fileStream.Write(fileData, iPos, ddsFileSize);
                fileStream.Close();
                iPos += ddsFileSize;
            }
            return(iPos);
        }
Example #2
0
        public static Texture2D LoadTexture(IGraphicsService graphicsService, string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (fileName.Length == 0)
            {
                throw new ArgumentException("The file name must not be empty.", nameof(fileName));
            }

            // Load API-independent texture.
            Texture texture = null;

            using (var stream = File.OpenRead(fileName))
            {
                string extension = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(extension))
                {
                    extension = extension.ToUpperInvariant();
                    if (extension == ".DDS")
                    {
                        texture = DdsHelper.Load(stream, DdsFlags.ForceRgb | DdsFlags.ExpandLuminance);
                    }
                    else if (extension == ".TGA")
                    {
                        texture = TgaHelper.Load(stream);
                    }
                }

                if (texture == null)
                {
                    // TODO: Register ImagingFactory as service.
                    using (var imagingFactory = new ImagingFactory())
                        texture = WicHelper.Load(imagingFactory, stream, WicFlags.ForceRgb | WicFlags.No16Bpp);
                }
            }

            //Tests(texture);

            // Convert to XNA texture.
            var description = texture.Description;

            if (description.Dimension == TextureDimension.TextureCube)
            {
                var texture2D = new Texture2D(graphicsService.GraphicsDevice, description.Width, description.Height, false, description.Format.ToSurfaceFormat());
                texture2D.SetData(texture.Images[0].Data);
                return(texture2D);
            }
            else
            {
                var texture2D = new Texture2D(graphicsService.GraphicsDevice, description.Width, description.Height, description.MipLevels > 1, description.Format.ToSurfaceFormat());
                for (int i = 0; i < texture.Description.MipLevels; i++)
                {
                    texture2D.SetData(i, null, texture.Images[i].Data, 0, texture.Images[i].Data.Length);
                }

                return(texture2D);
            }
        }
        /// <summary>
        /// Called by the XNA Framework when importing an texture file to be used as a game asset. This
        /// is the method called by the XNA Framework when an asset is to be imported into an object
        /// that can be recognized by the Content Pipeline.
        /// </summary>
        /// <param name="filename">Name of a game asset file.</param>
        /// <param name="context">
        /// Contains information for importing a game asset, such as a logger interface.
        /// </param>
        /// <returns>Resulting game asset.</returns>
        public override TextureContent Import(string filename, ContentImporterContext context)
        {
            string extension = Path.GetExtension(filename);

            if (extension != null)
            {
                Texture texture = null;
                if (extension.Equals(".DDS", StringComparison.OrdinalIgnoreCase))
                {
                    using (var stream = File.OpenRead(filename))
                        texture = DdsHelper.Load(stream, DdsFlags.ForceRgb | DdsFlags.ExpandLuminance);
                }
                else if (extension.Equals(".TGA", StringComparison.OrdinalIgnoreCase))
                {
                    using (var stream = File.OpenRead(filename))
                        texture = TgaHelper.Load(stream);
                }

                if (texture != null)
                {
#if !MONOGAME
                    // When using the XNA content pipeline, check for MonoGame content.
                    if (!string.IsNullOrEmpty(ContentHelper.GetMonoGamePlatform()))
#endif
                    {
                        // These formats are not (yet) available in MonoGame.
                        switch (texture.Description.Format)
                        {
                        case DataFormat.B5G5R5A1_UNORM: // (16-bit TGA files.)
                        case DataFormat.R8_UNORM:
                        case DataFormat.A8_UNORM:
                            texture = texture.ConvertTo(DataFormat.R8G8B8A8_UNORM);
                            break;
                        }
                    }

                    // Convert DigitalRune Texture to XNA TextureContent.
                    var identity = new ContentIdentity(filename, "DigitalRune");
                    return(TextureHelper.ToContent(texture, identity));
                }
            }

            return(base.Import(filename, context));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="filePath"></param>
 public void OpenImage(string filePath)
 {
     _skImage = DdsHelper.Load(filePath);
     RaiseChanged();
 }