示例#1
0
 /// <summary>
 /// Create a new instance of the <see cref="Texture"/> class from the given file.
 /// </summary>
 /// <param name="config">The Configuration.</param>
 /// <param name="path">The file path to the image.</param>
 /// <param name="decoder">The decoder.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <returns>The <see cref="Texture"/>.</returns>
 public static Texture Load(Configuration config, string path, ITextureDecoder decoder)
 {
     using (Stream stream = config.FileSystem.OpenRead(path))
     {
         return(Load(config, stream, decoder));
     }
 }
示例#2
0
 /// <summary>
 /// Sets a specific image decoder as the decoder for a specific image format.
 /// </summary>
 /// <param name="imageFormat">The image format to register the encoder for.</param>
 /// <param name="decoder">The decoder to use,</param>
 public void SetDecoder(ITextureFormat imageFormat, ITextureDecoder decoder)
 {
     Guard.NotNull(imageFormat, nameof(imageFormat));
     Guard.NotNull(decoder, nameof(decoder));
     this.AddImageFormat(imageFormat);
     this.mimeTypeDecoders.AddOrUpdate(imageFormat, decoder, (s, e) => decoder);
 }
        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);
        }
示例#6
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));
示例#7
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="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>The <see cref="Texture"/>.</returns>
 public static Texture Load(Stream stream, ITextureDecoder decoder) => Load(Configuration.Default, stream, decoder);
示例#8
0
 /// <summary>
 /// Create a new instance of the <see cref="Texture"/> class from the given file.
 /// </summary>
 /// <param name="path">The file path to the image.</param>
 /// <param name="decoder">The decoder.</param>
 /// <exception cref="NotSupportedException">
 /// Thrown if the stream is not readable nor seekable.
 /// </exception>
 /// <returns>The <see cref="Texture"/>.</returns>
 public static Texture Load(string path, ITextureDecoder decoder) => Load(Configuration.Default, path, decoder);