// ========================================================== // FreeImage 3 .NET wrapper // Original FreeImage 3 functions and .NET compatible derived functions // // Design and implementation by // - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net) // - Carsten Klein (cklein05@users.sourceforge.net) // // Contributors: // - David Boland (davidboland@vodafone.ie) // // Main reference : MSDN Knowlede Base // // This file is part of FreeImage 3 // // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER // THIS DISCLAIMER. // // Use at your own risk! // ========================================================== // ========================================================== // CVS // $Revision: 1.4 $ // $Date: 2008/06/16 15:17:37 $ // $Id: BITMAPINFOHEADER.cs,v 1.4 2008/06/16 15:17:37 cklein05 Exp $ // ========================================================== using System; using System.Runtime.InteropServices; namespace FreeImageAPI { /// /// This structure contains information about the dimensions and color format /// of a device-independent bitmap (DIB). /// /// /// The structure combines the /// BITMAPINFOHEADER structure and a color table to provide a complete /// definition of the dimensions and colors of a DIB. /// [Serializable, StructLayout(LayoutKind.Sequential)] public struct BITMAPINFOHEADER : IEquatable { /// /// Specifies the size of the structure, in bytes. /// public uint biSize; /// /// Specifies the width of the bitmap, in pixels. /// /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, /// the biWidth member specifies the width of the decompressed JPEG or PNG image file, /// respectively. /// public int biWidth; /// /// Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap /// is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, /// the bitmap is a top-down DIB and its origin is the upper-left corner. /// /// If biHeight is negative, indicating a top-down DIB, biCompression must be /// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed. /// /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, /// the biHeight member specifies the height of the decompressed JPEG or PNG image file, /// respectively. /// public int biHeight; /// /// Specifies the number of planes for the target device. This value must be set to 1. /// public ushort biPlanes; /// /// Specifies the number of bits per pixel.The biBitCount member of the BITMAPINFOHEADER /// structure determines the number of bits that define each pixel and the maximum number of /// colors in the bitmap. This member must be one of the following values. /// /// /// /// /// Value /// Meaning /// /// /// /// 0 /// /// Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified /// or is implied by the JPEG or PNG format. /// /// /// /// /// 1 /// /// The bitmap is monochrome, and the bmiColors member of /// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, /// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit /// is set, the pixel has the color of the second entry in the table. /// /// /// /// /// 4 /// /// The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO /// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the /// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two /// pixels. The first pixel contains the color in the second table entry, and the second pixel /// contains the color in the sixteenth table entry. /// /// /// /// 8 /// /// The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO /// contains up to 256 entries. In this case, each byte in the array represents a single pixel. /// /// /// /// /// 16 /// /// The bitmap has a maximum of 2^16 colors. If the biCompression member of the /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. /// Each WORD in the bitmap array represents a single pixel. The relative intensities /// of red, green, and blue are represented with five bits for each color component. /// The value for blue is in the least significant five bits, followed by five bits each for /// green and red. The most significant bit is not used. The bmiColors color table is used /// for optimizing colors used on palette-based devices, and must contain the number of entries /// specified by the biClrUsed member of the BITMAPINFOHEADER. /// /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the /// bmiColors member contains three DWORD color masks that specify the red, green, /// and blue components, respectively, of each pixel. Each WORD in the bitmap array represents /// a single pixel. /// /// Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, /// bits set in each DWORD mask must be contiguous and should not overlap the bits /// of another mask. All the bits in the pixel do not have to be used. /// /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system /// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is /// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, /// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800. /// /// /// /// /// 24 /// /// The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO /// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, /// green, and red, respectively, for a pixel. The bmiColors color table is used for /// optimizing colors used on palette-based devices, and must contain the number of entries /// specified by the biClrUsed member of the BITMAPINFOHEADER. /// /// /// /// /// 32 /// /// The bitmap has a maximum of 2^32 colors. If the biCompression member of the /// BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. /// Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, /// respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors /// color table is used for optimizing colors used on palette-based devices, and must contain the /// number of entries specified by the biClrUsed member of the BITMAPINFOHEADER. /// /// If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, /// the bmiColors member contains three DWORD color masks that specify the red, green, /// and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents /// a single pixel. /// /// Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each /// DWORD mask must be contiguous and should not overlap the bits of another mask. All the /// bits in the pixel do not need to be used. /// /// Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system /// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is /// 0x0000FF00, and the red mask is 0x00FF0000. /// /// /// /// public ushort biBitCount; /// /// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be /// compressed). /// /// /// Value /// Meaning /// /// /// /// BI_RGB /// An uncompressed format. /// /// /// /// BI_RLE8 /// A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format /// is a 2-byte format consisting of a count byte followed by a byte containing a color index. /// /// /// /// /// BI_RLE4 /// An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format /// consisting of a count byte followed by two word-length color indexes. /// /// /// /// BI_BITFIELDS /// Specifies that the bitmap is not compressed and that the color table consists /// of three DWORD color masks that specify the red, green, and blue components, respectively, /// of each pixel. This is valid when used with 16- and 32-bpp bitmaps. /// /// /// /// BI_JPEG /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image. /// /// /// /// /// BI_PNG /// Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image. /// /// /// /// /// public uint biCompression; /// /// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps. /// /// Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, /// biSizeImage indicates the size of the JPEG or PNG image buffer, respectively. /// public uint biSizeImage; /// /// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. /// An application can use this value to select a bitmap from a resource group that best matches /// the characteristics of the current device. /// public int biXPelsPerMeter; /// /// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap. /// public int biYPelsPerMeter; /// /// Specifies the number of color indexes in the color table that are actually used by the bitmap. /// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value /// of the biBitCount member for the compression mode specified by biCompression. /// /// If iClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed /// member specifies the actual number of colors the graphics engine or device driver accesses. /// If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color /// table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, /// the optimal color palette starts immediately following the three DWORD masks. /// /// When the bitmap array immediately follows the structure, it is a packed bitmap. /// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the /// biClrUsed member must be either zero or the actual size of the color table. /// public uint biClrUsed; /// /// Specifies the number of color indexes that are required for displaying the bitmap. If this value /// is zero, all colors are required. /// public uint biClrImportant; /// /// Tests whether two specified structures are equivalent. /// /// The that is to the left of the equality operator. /// The that is to the right of the equality operator. /// /// true if the two structures are equal; otherwise, false. /// public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right) { return ((left.biSize == right.biSize) && (left.biWidth == right.biWidth) && (left.biHeight == right.biHeight) && (left.biPlanes == right.biPlanes) && (left.biBitCount == right.biBitCount) && (left.biCompression == right.biCompression) && (left.biSizeImage == right.biSizeImage) && (left.biXPelsPerMeter == right.biXPelsPerMeter) && (left.biYPelsPerMeter == right.biYPelsPerMeter) && (left.biClrUsed == right.biClrUsed) && (left.biClrImportant == right.biClrImportant)); } /// /// Tests whether two specified structures are different. /// /// The that is to the left of the inequality operator. /// The that is to the right of the inequality operator. /// /// true if the two structures are different; otherwise, false. /// public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right) { return !(left == right); } /// /// Tests whether the specified structure is equivalent to this structure. /// /// A structure to compare to this instance. /// true if is a structure /// equivalent to this structure; otherwise, false. public bool Equals(BITMAPINFOHEADER other) { return (this == other); } /// /// Tests whether the specified object is a structure /// and is equivalent to this structure. /// /// The object to test. /// true if is a structure /// equivalent to this structure; otherwise, false. public override bool Equals(object obj) { return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj)); } /// /// Returns a hash code for this structure. /// /// An integer value that specifies the hash code for this . public override int GetHashCode() { return base.GetHashCode(); } } }