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
|
// ==========================================================
// 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.3 $
// $Date: 2008/06/16 15:16:07 $
// $Id: BITMAPINFO.cs,v 1.3 2008/06/16 15:16:07 cklein05 Exp $
// ==========================================================
using System;
using System.Runtime.InteropServices;
namespace FreeImageAPI
{
/// <summary>
/// The <b>BITMAPINFO</b> structure defines the dimensions and color information for a DIB.
/// </summary>
/// <remarks>
/// A DIB consists of two distinct parts: a <b>BITMAPINFO</b> structure describing the dimensions
/// and colors of the bitmap, and an array of bytes defining the pixels of the bitmap. The bits in
/// the array are packed together, but each scan line must be padded with zeroes to end on a
/// <b>LONG</b> data-type boundary. If the height of the bitmap is positive, the bitmap is a
/// bottom-up DIB and its origin is the lower-left corner. If the height is negative, the bitmap is
/// a top-down DIB and its origin is the upper left corner.
/// <para/>
/// A bitmap is packed when the bitmap array immediately follows the <b>BITMAPINFO</b> header.
/// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the <b>biClrUsed</b>
/// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap
/// array starts on a <b>DWORD</b> boundary.
/// <para/>
/// <b>Note</b> The <b>bmiColors</b> member should not contain palette indexes if the bitmap is to
/// be stored in a file or transferred to another application.
/// <para/>
/// Unless the application has exclusive use and control of the bitmap, the bitmap color table
/// should contain explicit RGB values.
/// </remarks>
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFO : IEquatable<BITMAPINFO>
{
/// <summary>
/// Specifies a <see cref="FreeImageAPI.BITMAPINFOHEADER"/> structure that contains information
/// about the dimensions of color format.
/// </summary>
public BITMAPINFOHEADER bmiHeader;
/// <summary>
/// The <b>bmiColors</b> member contains one of the following:
/// <list type="bullets">
///
/// <item>
/// <term>
/// An array of <see cref="FreeImageAPI.RGBQUAD"/>. The elements of the array that make up the
/// color table.
/// </term>
/// </item>
///
/// <item>
/// <term>
/// An array of 16-bit unsigned integers that specifies indexes into the currently realized
/// logical palette. This use of <b>bmiColors</b> is allowed for functions that use DIBs.
/// When <b>bmiColors</b> elements contain indexes to a realized logical palette, they must
/// also call the following bitmap functions:
/// </term>
/// </item>
///
/// </list>
/// <b>CreateDIBitmap</b>
/// <para/>
/// <b>CreateDIBPatternBrush</b>
/// <para/>
/// <b>CreateDIBSection</b>
/// <para/>
/// The <i>iUsage</i> parameter of CreateDIBSection must be set to DIB_PAL_COLORS.
/// <para/>
/// The number of entries in the array depends on the values of the <b>biBitCount</b> and
/// <b>biClrUsed</b> members of the <see cref="FreeImageAPI.BITMAPINFOHEADER"/> structure.
/// <para/>
/// The colors in the <b>bmiColors</b> table appear in order of importance. For more information,
/// see the Remarks section.
/// </summary>
public RGBQUAD[] bmiColors;
/// <summary>
/// Tests whether two specified <see cref="BITMAPINFO"/> structures are equivalent.
/// </summary>
/// <param name="left">The <see cref="BITMAPINFO"/> that is to the left of the equality operator.</param>
/// <param name="right">The <see cref="BITMAPINFO"/> that is to the right of the equality operator.</param>
/// <returns>
/// <b>true</b> if the two <see cref="BITMAPINFO"/> structures are equal; otherwise, <b>false</b>.
/// </returns>
public static bool operator ==(BITMAPINFO left, BITMAPINFO right)
{
if (left.bmiHeader != right.bmiHeader)
{
return false;
}
if ((left.bmiColors == null) && (right.bmiColors == null))
{
return true;
}
if ((left.bmiColors == null) || (right.bmiColors == null))
{
return false;
}
if (left.bmiColors.Length != right.bmiColors.Length)
{
return false;
}
for (int i = 0; i < left.bmiColors.Length; i++)
{
if (left.bmiColors[i] != right.bmiColors[i])
{
return false;
}
}
return true;
}
/// <summary>
/// Tests whether two specified <see cref="BITMAPINFO"/> structures are different.
/// </summary>
/// <param name="left">The <see cref="BITMAPINFO"/> that is to the left of the inequality operator.</param>
/// <param name="right">The <see cref="BITMAPINFO"/> that is to the right of the inequality operator.</param>
/// <returns>
/// <b>true</b> if the two <see cref="BITMAPINFO"/> structures are different; otherwise, <b>false</b>.
/// </returns>
public static bool operator !=(BITMAPINFO left, BITMAPINFO right)
{
return !(left == right);
}
/// <summary>
/// Tests whether the specified <see cref="BITMAPINFO"/> structure is equivalent to this <see cref="BITMAPINFO"/> structure.
/// </summary>
/// <param name="other">A <see cref="BITMAPINFO"/> structure to compare to this instance.</param>
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFO"/> structure
/// equivalent to this <see cref="BITMAPINFO"/> structure; otherwise, <b>false</b>.</returns>
public bool Equals(BITMAPINFO other)
{
return (this == other);
}
/// <summary>
/// Tests whether the specified object is a <see cref="BITMAPINFO"/> structure
/// and is equivalent to this <see cref="BITMAPINFO"/> structure.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="BITMAPINFO"/> structure
/// equivalent to this <see cref="BITMAPINFO"/> structure; otherwise, <b>false</b>.</returns>
public override bool Equals(object obj)
{
return ((obj is BITMAPINFO) && (this == ((BITMAPINFO)obj)));
}
/// <summary>
/// Returns a hash code for this <see cref="BITMAPINFO"/> structure.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="BITMAPINFO"/>.</returns>
public override int GetHashCode()
{
int hash = bmiHeader.GetHashCode();
if (bmiColors != null)
{
for (int c = 0; c < bmiColors.Length; c++)
{
hash ^= bmiColors[c].GetHashCode();
hash <<= 1;
}
hash <<= 1;
}
else
{
hash >>= 1;
}
return hash;
}
}
}
|