// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
//
//
// Contains the component parts that make up a single pixel.
//
// --------------------------------------------------------------------------------------------------------------------
namespace ImageProcessor.Imaging
{
using System.Runtime.InteropServices;
///
/// Contains the component parts that make up a single pixel.
///
[StructLayout(LayoutKind.Explicit)]
public struct PixelData
{
///
/// The blue component.
///
[FieldOffset(0)]
public byte B;
///
/// The green component.
///
[FieldOffset(1)]
public byte G;
///
/// The red component.
///
[FieldOffset(2)]
public byte R;
///
/// The alpha component.
///
[FieldOffset(3)]
public byte A;
///
/// Indicates whether this instance and a specified object are equal.
///
///
/// true if and this instance are the same type and represent the same value; otherwise, false.
///
/// Another object to compare to.
public override bool Equals(object obj)
{
if (obj is PixelData)
{
PixelData pixelData = (PixelData)obj;
return this.B == pixelData.B && this.G == pixelData.G & this.R == pixelData.R & this.A == pixelData.A;
}
return false;
}
///
/// Returns the hash code for this instance.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
public override int GetHashCode()
{
return this.GetHashCode(this);
}
///
/// Returns the hash code for the given instance.
///
///
/// The instance of to return the hash code for.
///
///
/// A 32-bit signed integer that is the hash code for this instance.
///
private int GetHashCode(PixelData obj)
{
unchecked
{
int hashCode = obj.B.GetHashCode();
hashCode = (hashCode * 397) ^ obj.G.GetHashCode();
hashCode = (hashCode * 397) ^ obj.R.GetHashCode();
hashCode = (hashCode * 397) ^ obj.A.GetHashCode();
return hashCode;
}
}
}
}