2007-07-23 02:15:18 +02:00
|
|
|
#region --- License ---
|
|
|
|
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
|
|
|
* See license.txt for license info
|
|
|
|
*/
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Globalization;
|
|
|
|
|
2007-09-02 02:04:34 +02:00
|
|
|
namespace OpenTK
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
2007-09-02 02:04:34 +02:00
|
|
|
public class ColorMode
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
public byte Red, Green, Blue, Alpha;
|
|
|
|
public bool IsIndexed = false;
|
|
|
|
public int BitsPerPixel;
|
|
|
|
|
2007-09-02 02:04:34 +02:00
|
|
|
public ColorMode(int bpp)
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
Red = Green = Blue = Alpha = 0;
|
|
|
|
BitsPerPixel = bpp;
|
|
|
|
|
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
Red = Green = Blue = Alpha = 8;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
Red = Green = Blue = 8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
Red = Blue = 5;
|
|
|
|
Green = 6;
|
|
|
|
break;
|
|
|
|
case 15:
|
|
|
|
Red = Green = Blue = 5;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
IsIndexed = true;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
IsIndexed = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-02 02:04:34 +02:00
|
|
|
public ColorMode(int red, int green, int blue, int alpha)
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
Red = (byte)red;
|
|
|
|
Green = (byte)green;
|
|
|
|
Blue = (byte)blue;
|
|
|
|
Alpha = (byte)alpha;
|
|
|
|
BitsPerPixel = red + green + blue + alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
{
|
2007-09-02 02:04:34 +02:00
|
|
|
return (obj is ColorMode) ? (this == (ColorMode)obj) : false;
|
2007-07-23 02:15:18 +02:00
|
|
|
}
|
|
|
|
|
2007-09-02 02:04:34 +02:00
|
|
|
public static bool operator ==(ColorMode left, ColorMode right)
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
if ((object)left == (object)null && (object)right != (object)null ||
|
|
|
|
(object)left != (object)null && (object)right == (object)null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((object)left == (object)null && (object)right == (object)null)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return left.Red == right.Red &&
|
|
|
|
left.Green == right.Green &&
|
|
|
|
left.Blue == right.Blue &&
|
|
|
|
left.Alpha == right.Alpha;
|
|
|
|
}
|
|
|
|
|
2007-09-02 02:04:34 +02:00
|
|
|
public static bool operator !=(ColorMode left, ColorMode right)
|
2007-07-23 02:15:18 +02:00
|
|
|
{
|
|
|
|
return !(left == right);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
return Red ^ Green ^ Blue ^ Alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
{
|
2007-08-07 20:08:06 +02:00
|
|
|
return string.Format("{0} ({1})", BitsPerPixel, (IsIndexed ? " indexed" : Red.ToString() + Green.ToString() + Blue.ToString() + Alpha.ToString()));
|
2007-07-23 02:15:18 +02:00
|
|
|
}
|
|
|
|
}
|
2007-08-20 12:46:37 +02:00
|
|
|
}
|