public virtual Texture GetTexture(ITextureDecoder decoder)
        {
            using FileStream fileStream = File.OpenRead(this.InputFile);

            Texture result = decoder.DecodeTexture(Configuration.Default, fileStream);

            Assert.Equal(fileStream.Length, fileStream.Position);

            return(result);
        }
        public virtual Texture GetTexture(ITextureDecoder decoder)
        {
            using FileStream fileStream = File.OpenRead(this.InputFile);

            Texture result = decoder.DecodeTexture(Configuration.Default, fileStream);

            Assert.True(fileStream.Length == fileStream.Position, "The texture file stream was not read to the end");

            return(result);
        }
        /// <summary>
        /// Decodes the image stream to the current image.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="config">the configuration.</param>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <returns>
        /// A new <see cref="Texture{TPixel}"/>.
        /// </returns>
        private static (Texture texture, ITextureFormat format) DecodeTexture(Stream stream, Configuration config)
        {
            ITextureDecoder decoder = DiscoverDecoder(stream, config, out ITextureFormat format);

            if (decoder is null)
            {
                return(null, null);
            }

            Texture texture = decoder.DecodeTexture(config, stream);

            return(texture, format);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Decode a new instance of the <see cref="Texture"/> class from the given stream.
 /// The pixel format is selected by the decoder.
 /// </summary>
 /// <param name="config">The config for the decoder.</param>
 /// <param name="stream">The stream containing image information.</param>
 /// <param name="decoder">The decoder.</param>
 /// <exception cref="NotSupportedException">Thrown if the stream is not readable.</exception>
 /// <exception cref="UnknownTextureFormatException">Image cannot be loaded.</exception>
 /// <returns>A new <see cref="Texture"/>.</returns>>
 public static Texture Load(Configuration config, Stream stream, ITextureDecoder decoder) =>
 WithSeekableStream(config, stream, s => decoder.DecodeTexture(config, s));