// -------------------------------------------------------------------------------------------------------------------- // // Copyright © James South and contributors. // Licensed under the Apache License, Version 2.0. // // // Encoder for generating an image out of a gif encoded stream. // // -------------------------------------------------------------------------------------------------------------------- namespace ImageProcessor.Formats { using System; using System.IO; /// /// Encoder for generating an image out of a gif encoded stream. /// public class GifDecoder : IImageDecoder { /// /// Gets the size of the header for this image type. /// /// The size of the header. public int HeaderSize { get { return 6; } } /// /// Returns a value indicating whether the supports the specified /// file header. /// /// The containing the file extension. /// /// True if the decoder supports the file extension; otherwise, false. /// public bool IsSupportedFileExtension(string extension) { Guard.NotNullOrEmpty(extension, "extension"); extension = extension.StartsWith(".") ? extension.Substring(1) : extension; return extension.Equals("GIF", StringComparison.OrdinalIgnoreCase); } /// /// Returns a value indicating whether the supports the specified /// file header. /// /// The containing the file header. /// /// True if the decoder supports the file header; otherwise, false. /// public bool IsSupportedFileFormat(byte[] header) { return header.Length >= 6 && header[0] == 0x47 && // G header[1] == 0x49 && // I header[2] == 0x46 && // F header[3] == 0x38 && // 8 (header[4] == 0x39 || header[4] == 0x37) && // 9 or 7 header[5] == 0x61; // a } /// /// Decodes the image from the specified stream to the . /// /// The to decode to. /// The containing image data. public void Decode(Image image, Stream stream) { new GifDecoderCore().Decode(image, stream); } } }