File: BITMAPINFOHEADER.cs

package info (click to toggle)
freeimage 3.18.0%2Bds2-11
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,824 kB
  • sloc: cpp: 42,339; cs: 36,178; pascal: 4,629; ansic: 1,294; makefile: 101; sh: 84
file content (352 lines) | stat: -rw-r--r-- 16,794 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// ==========================================================
// 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
{
	/// <summary>
	/// This structure contains information about the dimensions and color format
	/// of a device-independent bitmap (DIB).
	/// </summary>
	/// <remarks>
	/// The <see cref="FreeImageAPI.BITMAPINFO"/> structure combines the
	/// <b>BITMAPINFOHEADER</b> structure and a color table to provide a complete
	/// definition of the dimensions and colors of a DIB.
	/// </remarks>
	[Serializable, StructLayout(LayoutKind.Sequential)]
	public struct BITMAPINFOHEADER : IEquatable<BITMAPINFOHEADER>
	{
		/// <summary>
		/// Specifies the size of the structure, in bytes.
		/// </summary>
		public uint biSize;
		/// <summary>
		/// Specifies the width of the bitmap, in pixels.
		/// <para/>
		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
		/// the <b>biWidth</b> member specifies the width of the decompressed JPEG or PNG image file,
		/// respectively.
		/// </summary>
		public int biWidth;
		/// <summary>
		/// Specifies the height of the bitmap, in pixels. If <b>biHeight</b> is positive, the bitmap
		/// is a bottom-up DIB and its origin is the lower-left corner. If <b>biHeight</b> is negative,
		/// the bitmap is a top-down DIB and its origin is the upper-left corner. 
		/// <para/>
		/// If <b>biHeight</b> is negative, indicating a top-down DIB, <b>biCompression</b> must be
		/// either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.
		/// <para/>
		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
		/// the <b>biHeight</b> member specifies the height of the decompressed JPEG or PNG image file,
		/// respectively.
		/// </summary>
		public int biHeight;
		/// <summary>
		/// Specifies the number of planes for the target device. This value must be set to 1.
		/// </summary>
		public ushort biPlanes;
		/// <summary>
		/// Specifies the number of bits per pixel.The biBitCount member of the <b>BITMAPINFOHEADER</b>
		/// 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.
		/// <para/>
		/// 
		/// <list type="table">
		/// <listheader>
		/// <term>Value</term>
		/// <description>Meaning</description>
		/// </listheader>
		/// 
		/// <item>
		/// <term>0</term>
		/// <description>
		/// <b>Windows 98/Me, Windows 2000/XP:</b> The number of bits-per-pixel is specified
		/// or is implied by the JPEG or PNG format.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>1</term>
		/// <description>
		/// The bitmap is monochrome, and the bmiColors member of <see cref="FreeImageAPI.BITMAPINFO"/>
		/// 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.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>4</term>
		/// <description>
		/// The bitmap has a maximum of 16 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
		/// 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.</description>
		/// </item>
		/// 
		/// <item>
		/// <term>8</term>
		/// <description>
		/// The bitmap has a maximum of 256 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
		/// contains up to 256 entries. In this case, each byte in the array represents a single pixel.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>16</term>
		/// <description>
		/// The bitmap has a maximum of 2^16 colors. If the <b>biCompression</b> member of the
		/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
		/// Each <b>WORD</b> 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 <b>bmiColors</b> color table is used
		/// for optimizing colors used on palette-based devices, and must contain the number of entries
		/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
		/// <para/>
		/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS, the
		/// <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
		/// and blue components, respectively, of each pixel. Each <b>WORD</b> in the bitmap array represents
		/// a single pixel.
		/// <para/>
		/// <b>Windows NT/Windows 2000/XP:</b> When the <b>biCompression</b> member is BI_BITFIELDS,
		/// bits set in each <b>DWORD</b> 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.
		/// <para/>
		/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> 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.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>24</term>
		/// <description>
		/// The bitmap has a maximum of 2^24 colors, and the <b>bmiColors</b> member of <b>BITMAPINFO</b>
		/// is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue,
		/// green, and red, respectively, for a pixel. The <b>bmiColors</b> color table is used for
		/// optimizing colors used on palette-based devices, and must contain the number of entries
		/// specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>32</term>
		/// <description>
		/// The bitmap has a maximum of 2^32 colors. If the <b>biCompression</b> member of the
		/// <b>BITMAPINFOHEADER</b> is BI_RGB, the <b>bmiColors</b> member of <b>BITMAPINFO</b> is NULL.
		/// Each <b>DWORD</b> in the bitmap array represents the relative intensities of blue, green, and red,
		/// respectively, for a pixel. The high byte in each <b>DWORD</b> is not used. The <b>bmiColors</b>
		/// color table is used for optimizing colors used on palette-based devices, and must contain the 
		/// number of entries specified by the <b>biClrUsed</b> member of the <b>BITMAPINFOHEADER</b>.
		/// <para/>
		/// If the <b>biCompression</b> member of the <b>BITMAPINFOHEADER</b> is BI_BITFIELDS,
		/// the <b>bmiColors</b> member contains three <b>DWORD</b> color masks that specify the red, green,
		/// and blue components, respectively, of each pixel. Each <b>DWORD</b> in the bitmap array represents
		/// a single pixel.
		/// <para/>
		/// <b>Windows NT/ 2000:</b> When the <b>biCompression</b> member is BI_BITFIELDS, bits set in each
		/// <b>DWORD</b> 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.
		/// <para/>
		/// <b>Windows 95/98/Me:</b> When the <b>biCompression</b> 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.
		/// </description>
		/// </item>
		/// </list>
		/// </summary>
		public ushort biBitCount;
		/// <summary>
		/// Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be
		/// compressed).
		/// <list type="table">
		/// <listheader>
		/// <term>Value</term>
		/// <description>Meaning</description>
		/// </listheader>
		/// 
		/// <item>
		/// <term>BI_RGB</term>
		/// <description>An uncompressed format.</description>
		/// </item>
		/// 
		/// <item>
		/// <term>BI_RLE8</term>
		/// <description>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.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>BI_RLE4</term>
		/// <description>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.</description>
		/// </item>
		/// 
		/// <item>
		/// <term>BI_BITFIELDS</term>
		/// <description>Specifies that the bitmap is not compressed and that the color table consists
		/// of three <b>DWORD</b> 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.</description>
		/// </item>
		/// 
		/// <item>
		/// <term>BI_JPEG</term>
		/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a JPEG image.
		/// </description>
		/// </item>
		/// 
		/// <item>
		/// <term>BI_PNG</term>
		/// <description><b>Windows 98/Me, Windows 2000/XP:</b> Indicates that the image is a PNG image.
		/// </description>
		/// </item>
		/// 
		/// </list>
		/// </summary>
		public uint biCompression;
		/// <summary>
		/// Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
		/// <para/>
		/// <b>Windows 98/Me, Windows 2000/XP:</b> If <b>biCompression</b> is BI_JPEG or BI_PNG,
		/// <b>biSizeImage</b> indicates the size of the JPEG or PNG image buffer, respectively.
		/// </summary>
		public uint biSizeImage;
		/// <summary>
		/// 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.
		/// </summary>
		public int biXPelsPerMeter;
		/// <summary>
		/// Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap.
		/// </summary>
		public int biYPelsPerMeter;
		/// <summary>
		/// 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 <b>biCompression</b>.
		/// <para/>
		/// If <b>iClrUsed</b> is nonzero and the <b>biBitCount</b> member is less than 16, the <b>biClrUsed</b>
		/// member specifies the actual number of colors the graphics engine or device driver accesses.
		/// If <b>biBitCount</b> is 16 or greater, the <b>biClrUsed</b> member specifies the size of the color
		/// table used to optimize performance of the system color palettes. If <b>biBitCount</b> equals 16 or 32,
		/// the optimal color palette starts immediately following the three <b>DWORD</b> masks.
		/// <para/>
		/// When the bitmap array immediately follows the <see cref="BITMAPINFO"/> structure, it is a packed bitmap.
		/// Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the
		/// <b>biClrUsed</b> member must be either zero or the actual size of the color table.
		/// </summary>
		public uint biClrUsed;
		/// <summary>
		/// Specifies the number of color indexes that are required for displaying the bitmap. If this value
		/// is zero, all colors are required.
		/// </summary>
		public uint biClrImportant;

		/// <summary>
		/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are equivalent.
		/// </summary>
		/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the equality operator.</param>
		/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the equality operator.</param>
		/// <returns>
		/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are equal; otherwise, <b>false</b>.
		/// </returns>
		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));
		}

		/// <summary>
		/// Tests whether two specified <see cref="BITMAPINFOHEADER"/> structures are different.
		/// </summary>
		/// <param name="left">The <see cref="BITMAPINFOHEADER"/> that is to the left of the inequality operator.</param>
		/// <param name="right">The <see cref="BITMAPINFOHEADER"/> that is to the right of the inequality operator.</param>
		/// <returns>
		/// <b>true</b> if the two <see cref="BITMAPINFOHEADER"/> structures are different; otherwise, <b>false</b>.
		/// </returns>
		public static bool operator !=(BITMAPINFOHEADER left, BITMAPINFOHEADER right)
		{
			return !(left == right);
		}

		/// <summary>
		/// Tests whether the specified <see cref="BITMAPINFOHEADER"/> structure is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
		/// </summary>
		/// <param name="other">A <see cref="BITMAPINFOHEADER"/> structure to compare to this instance.</param>
		/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
		/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
		public bool Equals(BITMAPINFOHEADER other)
		{
			return (this == other);
		}

		/// <summary>
		/// Tests whether the specified object is a <see cref="BITMAPINFOHEADER"/> structure
		/// and is equivalent to this <see cref="BITMAPINFOHEADER"/> structure.
		/// </summary>
		/// <param name="obj">The object to test.</param>
		/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFOHEADER"/> structure
		/// equivalent to this <see cref="BITMAPINFOHEADER"/> structure; otherwise, <b>false</b>.</returns>
		public override bool Equals(object obj)
		{
			return ((obj is BITMAPINFOHEADER) && (this == (BITMAPINFOHEADER)obj));
		}

		/// <summary>
		/// Returns a hash code for this <see cref="BITMAPINFOHEADER"/> structure.
		/// </summary>
		/// <returns>An integer value that specifies the hash code for this <see cref="BITMAPINFOHEADER"/>.</returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
	}
}