1 // ==========================================================
2 // FreeImage 3 .NET wrapper
3 // Original FreeImage 3 functions and .NET compatible derived functions
4 //
5 // Design and implementation by
6 // - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
7 // - Carsten Klein (cklein05@users.sourceforge.net)
8 //
9 // Contributors:
10 // - David Boland (davidboland@vodafone.ie)
11 //
12 // Main reference : MSDN Knowlede Base
13 //
14 // This file is part of FreeImage 3
15 //
16 // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
17 // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
18 // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
19 // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
20 // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
21 // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
22 // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
23 // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
24 // THIS DISCLAIMER.
25 //
26 // Use at your own risk!
27 // ==========================================================
28 
29 // ==========================================================
30 // CVS
31 // $Revision: 1.4 $
32 // $Date: 2008/06/16 15:17:37 $
33 // $Id: BITMAPINFOHEADER.cs,v 1.4 2008/06/16 15:17:37 cklein05 Exp $
34 // ==========================================================
35 
36 using System;
37 using System.Runtime.InteropServices;
38 
39 namespace FreeImageAPI
40 {
41 	/// <summary>
42 	/// This structure contains information about the dimensions and color format
43 	/// of a device-independent bitmap (DIB).
44 	/// </summary>
45 	/// <remarks>
46 	/// The <see cref="FreeImageAPI.BITMAPINFO"/> structure combines the
47 	/// <b>BITMAPINFOHEADER</b> structure and a color table to provide a complete
48 	/// definition of the dimensions and colors of a DIB.
49 	/// </remarks>
50 	[Serializable, StructLayout(LayoutKind.Sequential)]
51 	public struct BITMAPINFOHEADER : IEquatable<BITMAPINFOHEADER>
52 	{
53 		/// <summary>
54 		/// Specifies the size of the structure, in bytes.
55 		/// </summary>
56 		public uint biSize;
57 		/// <summary>
58 		/// Specifies the width of the bitmap, in pixels.
59 		/// <para/>
60 		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
61 		/// the <b>biWidth</b> member specifies the width of the decompressed JPEG or PNG image file,
62 		/// respectively.
63 		/// </summary>
64 		public int biWidth;
65 		/// <summary>
66 		/// Specifies the height of the bitmap, in pixels. If <b>biHeight</b> is positive, the bitmap
67 		/// is a bottom-up DIB and its origin is the lower-left corner. If <b>biHeight</b> is negative,
68 		/// the bitmap is a top-down DIB and its origin is the upper-left corner.
69 		/// <para/>
70 		/// If <b>biHeight</b> is negative, indicating a top-down DIB, <b>biCompression</b> must be
71 		/// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
72 		/// <para/>
73 		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
74 		/// the <b>biHeight</b> member specifies the height of the decompressed JPEG or PNG image file,
75 		/// respectively.
76 		/// </summary>
77 		public int biHeight;
78 		/// <summary>
79 		/// Specifies the number of planes for the target device. This value must be set to 1.
80 		/// </summary>
81 		public ushort biPlanes;
82 		/// <summary>
83 		/// Specifies the number of bits per pixel.The biBitCount member of the <b>BITMAPINFOHEADER</b>
84 		/// structure determines the number of bits that define each pixel and the maximum number of
85 		/// colors in the bitmap. This member must be one of the following values.
86 		/// <para/>
87 		///
88 		/// <list type="table">
89 		/// <listheader>
90 		/// <term>Value</term>
91 		/// <description>Meaning</description>
92 		/// </listheader>
93 		///
94 		/// <item>
95 		/// <term>0</term>
96 		/// <description>
97 		/// <b>Windows 98/Me, Windows 2000/XP:</b> The number of bits-per-pixel is specified
98 		/// or is implied by the JPEG or PNG format.
99 		/// </description>
100 		/// </item>
101 		///
102 		/// <item>
103 		/// <term>1</term>
104 		/// <description>
105 		/// The bitmap is monochrome, and the bmiColors member of <see cref="FreeImageAPI.BITMAPINFO"/>
106 		/// contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear,
107 		/// the pixel is displayed with the color of the first entry in the bmiColors table; if the bit
108 		/// is set, the pixel has the color of the second entry in the table.
109 		/// </description>
110 		/// </item>
111 		///
112 		/// <item>
113 		/// <term>4</term>
114 		/// <description>
115 		/// The bitmap has a maximum of 16 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
116 		/// contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the
117 		/// color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two
118 		/// pixels. The first pixel contains the color in the second table entry, and the second pixel
119 		/// contains the color in the sixteenth table entry.</description>
120 		/// </item>
121 		///
122 		/// <item>
123 		/// <term>8</term>
124 		/// <description>
125 		/// The bitmap has a maximum of 256 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
126 		/// contains up to 256 entries. In this case, each byte in the array represents a single pixel.
127 		/// </description>
128 		/// </item>
129 		///
130 		/// <item>
131 		/// <term>16</term>
132 		/// <description>
133 		/// The bitmap has a maximum of 2^16 colors. If the <b>biCompression</b> member of the
134 		/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
135 		/// Each <b>WORD</b> in the bitmap array represents a single pixel. The relative intensities
136 		/// of red, green, and blue are represented with five bits for each color component.
137 		/// The value for blue is in the least significant five bits, followed by five bits each for
138 		/// green and red. The most significant bit is not used. The <b>bmiColors</b> color table is used
139 		/// for optimizing colors used on palette-based devices, and must contain the number of entries
140 		/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
141 		/// <para/>
142 		/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS, the
143 		/// <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
144 		/// and blue components, respectively, of each pixel. Each <b>WORD</b> in the bitmap array represents
145 		/// a single pixel.
146 		/// <para/>
147 		/// <b>Windows NT/Windows 2000/XP:</b> When the <b>biCompression</b> member is BI_BITFIELDS,
148 		/// bits set in each <b>DWORD</b> mask must be contiguous and should not overlap the bits
149 		/// of another mask. All the bits in the pixel do not have to be used.
150 		/// <para/>
151 		/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> member is BI_BITFIELDS, the system
152 		/// supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is
153 		/// 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image,
154 		/// where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800.
155 		/// </description>
156 		/// </item>
157 		///
158 		/// <item>
159 		/// <term>24</term>
160 		/// <description>
161 		/// The bitmap has a maximum of 2^24 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
162 		/// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue,
163 		/// green, and red, respectively, for a pixel. The <b>bmiColors</b> color table is used for
164 		/// optimizing colors used on palette-based devices, and must contain the number of entries
165 		/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
166 		/// </description>
167 		/// </item>
168 		///
169 		/// <item>
170 		/// <term>32</term>
171 		/// <description>
172 		/// The bitmap has a maximum of 2^32 colors. If the <b>biCompression</b> member of the
173 		/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
174 		/// Each <b>DWORD</b> in the bitmap array represents the relative intensities of blue, green, and red,
175 		/// respectively, for a pixel. The high byte in each <b>DWORD</b> is not used. The <b>bmiColors</b>
176 		/// color table is used for optimizing colors used on palette-based devices, and must contain the
177 		/// number of entries specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
178 		/// <para/>
179 		/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS,
180 		/// the <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
181 		/// and blue components, respectively, of each pixel. Each <b>DWORD</b> in the bitmap array represents
182 		/// a single pixel.
183 		/// <para/>
184 		/// <b>Windows NT/ 2000:</b> When the <b>biCompression</b> member is BI_BITFIELDS, bits set in each
185 		/// <b>DWORD</b> mask must be contiguous and should not overlap the bits of another mask. All the
186 		/// bits in the pixel do not need to be used.
187 		/// <para/>
188 		/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> member is BI_BITFIELDS, the system
189 		/// supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is
190 		/// 0x0000FF00, and the red mask is 0x00FF0000.
191 		/// </description>
192 		/// </item>
193 		/// </list>
194 		/// </summary>
195 		public ushort biBitCount;
196 		/// <summary>
197 		/// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be
198 		/// compressed).
199 		/// <list type="table">
200 		/// <listheader>
201 		/// <term>Value</term>
202 		/// <description>Meaning</description>
203 		/// </listheader>
204 		///
205 		/// <item>
206 		/// <term>BI_RGB</term>
207 		/// <description>An uncompressed format.</description>
208 		/// </item>
209 		///
210 		/// <item>
211 		/// <term>BI_RLE8</term>
212 		/// <description>A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format
213 		/// is a 2-byte format consisting of a count byte followed by a byte containing a color index.
214 		/// </description>
215 		/// </item>
216 		///
217 		/// <item>
218 		/// <term>BI_RLE4</term>
219 		/// <description>An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format
220 		/// consisting of a count byte followed by two word-length color indexes.</description>
221 		/// </item>
222 		///
223 		/// <item>
224 		/// <term>BI_BITFIELDS</term>
225 		/// <description>Specifies that the bitmap is not compressed and that the color table consists
226 		/// of three <b>DWORD</b> color masks that specify the red, green, and blue components, respectively,
227 		/// of each pixel. This is valid when used with 16- and 32-bpp bitmaps.</description>
228 		/// </item>
229 		///
230 		/// <item>
231 		/// <term>BI_JPEG</term>
232 		/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a JPEG image.
233 		/// </description>
234 		/// </item>
235 		///
236 		/// <item>
237 		/// <term>BI_PNG</term>
238 		/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a PNG image.
239 		/// </description>
240 		/// </item>
241 		///
242 		/// </list>
243 		/// </summary>
244 		public uint biCompression;
245 		/// <summary>
246 		/// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
247 		/// <para/>
248 		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
249 		/// <b>biSizeImage</b> indicates the size of the JPEG or PNG image buffer, respectively.
250 		/// </summary>
251 		public uint biSizeImage;
252 		/// <summary>
253 		/// Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap.
254 		/// An application can use this value to select a bitmap from a resource group that best matches
255 		/// the characteristics of the current device.
256 		/// </summary>
257 		public int biXPelsPerMeter;
258 		/// <summary>
259 		/// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
260 		/// </summary>
261 		public int biYPelsPerMeter;
262 		/// <summary>
263 		/// Specifies the number of color indexes in the color table that are actually used by the bitmap.
264 		/// If this value is zero, the bitmap uses the maximum number of colors corresponding to the value
265 		/// of the biBitCount member for the compression mode specified by <b>biCompression</b>.
266 		/// <para/>
267 		/// If <b>iClrUsed</b> is nonzero and the <b>biBitCount</b> member is less than 16, the <b>biClrUsed</b>
268 		/// member specifies the actual number of colors the graphics engine or device driver accesses.
269 		/// If <b>biBitCount</b> is 16 or greater, the <b>biClrUsed</b> member specifies the size of the color
270 		/// table used to optimize performance of the system color palettes. If <b>biBitCount</b> equals 16 or 32,
271 		/// the optimal color palette starts immediately following the three <b>DWORD</b> masks.
272 		/// <para/>
273 		/// When the bitmap array immediately follows the <see cref="BITMAPINFO"/> structure, it is a packed bitmap.
274 		/// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the
275 		/// <b>biClrUsed</b> member must be either zero or the actual size of the color table.
276 		/// </summary>
277 		public uint biClrUsed;
278 		/// <summary>
279 		/// Specifies the number of color indexes that are required for displaying the bitmap. If this value
280 		/// is zero, all colors are required.
281 		/// </summary>
282 		public uint biClrImportant;
283 
284 		/// <summary>
285 		/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are equivalent.
286 		/// </summary>
287 		/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the equality operator.</param>
288 		/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the equality operator.</param>
289 		/// <returns>
290 		/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are equal; otherwise, <b>false</b>.
291 		/// </returns>
operator ==FreeImageAPI.BITMAPINFOHEADER292 		public static bool operator ==(BITMAPINFOHEADER left, BITMAPINFOHEADER right)
293 		{
294 			return ((left.biSize == right.biSize) &&
295 					(left.biWidth == right.biWidth) &&
296 					(left.biHeight == right.biHeight) &&
297 					(left.biPlanes == right.biPlanes) &&
298 					(left.biBitCount == right.biBitCount) &&
299 					(left.biCompression == right.biCompression) &&
300 					(left.biSizeImage == right.biSizeImage) &&
301 					(left.biXPelsPerMeter == right.biXPelsPerMeter) &&
302 					(left.biYPelsPerMeter == right.biYPelsPerMeter) &&
303 					(left.biClrUsed == right.biClrUsed) &&
304 					(left.biClrImportant == right.biClrImportant));
305 		}
306 
307 		/// <summary>
308 		/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are different.
309 		/// </summary>
310 		/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the inequality operator.</param>
311 		/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the inequality operator.</param>
312 		/// <returns>
313 		/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are different; otherwise, <b>false</b>.
314 		/// </returns>
operator !=FreeImageAPI.BITMAPINFOHEADER315 		public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right)
316 		{
317 			return !(left == right);
318 		}
319 
320 		/// <summary>
321 		/// Tests whether the specified <see cref="BITMAPINFOHEADER"/> structure is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
322 		/// </summary>
323 		/// <param name="other">A <see cref="BITMAPINFOHEADER"/> structure to compare to this instance.</param>
324 		/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
325 		/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
EqualsFreeImageAPI.BITMAPINFOHEADER326 		public bool Equals(BITMAPINFOHEADER other)
327 		{
328 			return (this == other);
329 		}
330 
331 		/// <summary>
332 		/// Tests whether the specified object is a <see cref="BITMAPINFOHEADER"/> structure
333 		/// and is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
334 		/// </summary>
335 		/// <param name="obj">The object to test.</param>
336 		/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
337 		/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
EqualsFreeImageAPI.BITMAPINFOHEADER338 		public override bool Equals(object obj)
339 		{
340 			return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj));
341 		}
342 
343 		/// <summary>
344 		/// Returns a hash code for this <see cref="BITMAPINFOHEADER"/> structure.
345 		/// </summary>
346 		/// <returns>An integer value that specifies the hash code for this <see cref="BITMAPINFOHEADER"/>.</returns>
GetHashCodeFreeImageAPI.BITMAPINFOHEADER347 		public override int GetHashCode()
348 		{
349 			return base.GetHashCode();
350 		}
351 	}
352 }