// ==========================================================
// 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
{
///
/// The BITMAPINFO structure defines the dimensions and color information for a DIB.
///
///
/// A DIB consists of two distinct parts: a BITMAPINFO 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
/// LONG 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.
///
/// A bitmap is packed when the bitmap array immediately follows the BITMAPINFO header.
/// Packed bitmaps are referenced by a single pointer. For packed bitmaps, the biClrUsed
/// member must be set to an even number when using the DIB_PAL_COLORS mode so that the DIB bitmap
/// array starts on a DWORD boundary.
///
/// Note The bmiColors member should not contain palette indexes if the bitmap is to
/// be stored in a file or transferred to another application.
///
/// Unless the application has exclusive use and control of the bitmap, the bitmap color table
/// should contain explicit RGB values.
///
[Serializable, StructLayout(LayoutKind.Sequential)]
public struct BITMAPINFO : IEquatable
{
///
/// Specifies a structure that contains information
/// about the dimensions of color format.
///
public BITMAPINFOHEADER bmiHeader;
///
/// The bmiColors member contains one of the following:
///
///
/// -
///
/// An array of . The elements of the array that make up the
/// color table.
///
///
///
/// -
///
/// An array of 16-bit unsigned integers that specifies indexes into the currently realized
/// logical palette. This use of bmiColors is allowed for functions that use DIBs.
/// When bmiColors elements contain indexes to a realized logical palette, they must
/// also call the following bitmap functions:
///
///
///
///
/// CreateDIBitmap
///
/// CreateDIBPatternBrush
///
/// CreateDIBSection
///
/// The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS.
///
/// The number of entries in the array depends on the values of the biBitCount and
/// biClrUsed members of the structure.
///
/// The colors in the bmiColors table appear in order of importance. For more information,
/// see the Remarks section.
///
public RGBQUAD[] bmiColors;
///
/// 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 ==(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;
}
///
/// 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 !=(BITMAPINFO left, BITMAPINFO 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(BITMAPINFO 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 BITMAPINFO) && (this == ((BITMAPINFO)obj)));
}
///
/// Returns a hash code for this structure.
///
/// An integer value that specifies the hash code for this .
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;
}
}
}