using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace FreeImageAPI { /// /// Provides methods for working with generic bitmap scanlines. /// /// Type of the bitmaps' scanlines. public sealed class Scanline : MemoryArray where T : struct { /// /// Initializes a new instance based on the specified FreeImage bitmap. /// /// Handle to a FreeImage bitmap. public Scanline(FIBITMAP dib) : this(dib, 0) { } /// /// Initializes a new instance based on the specified FreeImage bitmap. /// /// Handle to a FreeImage bitmap. /// Index of the zero based scanline. public Scanline(FIBITMAP dib, int scanline) : this(dib, scanline, (int)(typeof(T) == typeof(FI1BIT) ? FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) : typeof(T) == typeof(FI4BIT) ? FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib) / 4 : (FreeImage.GetBPP(dib) * FreeImage.GetWidth(dib)) / (Marshal.SizeOf(typeof(T)) * 8))) { } internal Scanline(FIBITMAP dib, int scanline, int length) : base(FreeImage.GetScanLine(dib, scanline), length) { if (dib.IsNull) { throw new ArgumentNullException("dib"); } if ((scanline < 0) || (scanline >= FreeImage.GetHeight(dib))) { throw new ArgumentOutOfRangeException("scanline"); } } } }