OpenTK.Graphics.ColorFormat Struct Reference

Defines the ColorFormat component of a GraphicsMode. More...

List of all members.

Public Member Functions

 ColorFormat (int bpp)
 Constructs a new ColorFormat with the specified aggregate bits per pixel.
 ColorFormat (int red, int green, int blue, int alpha)
 Constructs a new ColorFormat with the specified bits per pixel for the Red, Green, Blue and Alpha color channels.
override bool Equals (object obj)
 Indicates whether this instance and a specified object are equal.
override int GetHashCode ()
 Returns the hash code for this instance.
override string ToString ()
 Returns a System.String that describes this instance.

Static Public Member Functions

static implicit operator ColorFormat (int bpp)
 Converts the specified bpp into a new ColorFormat.
static bool operator== (ColorFormat left, ColorFormat right)
 Compares two instances for equality.
static bool operator!= (ColorFormat left, ColorFormat right)
 Compares two instances for inequality.

Public Attributes

byte red
byte green
byte blue
byte alpha
bool isIndexed
int bitsPerPixel

Properties

int Red [get, set]
 Gets the bits per pixel for the Red channel.
int Green [get, set]
 Gets the bits per pixel for the Green channel.
int Blue [get, set]
 Gets the bits per pixel for the Blue channel.
int Alpha [get, set]
 Gets the bits per pixel for the Alpha channel.
bool IsIndexed [get, set]
 Gets a System.Boolean indicating whether this ColorFormat is indexed.
int BitsPerPixel [get, set]
 Gets the sum of Red, Green, Blue and Alpha bits per pixel.

Detailed Description

Defines the ColorFormat component of a GraphicsMode.

A ColorFormat contains Red, Green, Blue and Alpha components that descibe the allocated bits per pixel for the corresponding color.

Definition at line 20 of file ColorFormat.cs.


Constructor & Destructor Documentation

OpenTK.Graphics.ColorFormat.ColorFormat ( int  bpp  ) 

Constructs a new ColorFormat with the specified aggregate bits per pixel.

Parameters:
bpp The bits per pixel sum for the Red, Green, Blue and Alpha color channels.

Definition at line 32 of file ColorFormat.cs.

00033         {
00034             if (bpp < 0)
00035                 throw new ArgumentOutOfRangeException("bpp", "Must be greater or equal to zero.");
00036             red = green = blue = alpha = 0;
00037             bitsPerPixel = bpp;
00038             isIndexed = false;
00039 
00040             switch (bpp)
00041             {
00042                 case 32:
00043                     Red = Green = Blue = Alpha = 8;
00044                     break;
00045                 case 24:
00046                     Red = Green = Blue = 8;
00047                     break;
00048                 case 16:
00049                     Red = Blue = 5;
00050                     Green = 6;
00051                     break;
00052                 case 15:
00053                     Red = Green = Blue = 5;
00054                     break;
00055                 case 8:
00056                     Red = Green = 3;
00057                     Blue = 2;
00058                     IsIndexed = true;
00059                     break;
00060                 case 4:
00061                     Red = Green = 2;
00062                     Blue = 1;
00063                     IsIndexed = true;
00064                     break;
00065                 case 1:
00066                     IsIndexed = true;
00067                     break;
00068                 default:
00069                     Red = Blue = Alpha = (byte)(bpp / 4);
00070                     Green = (byte)((bpp / 4) + (bpp % 4));
00071                     break;
00072             }
00073         }

OpenTK.Graphics.ColorFormat.ColorFormat ( int  red,
int  green,
int  blue,
int  alpha 
)

Constructs a new ColorFormat with the specified bits per pixel for the Red, Green, Blue and Alpha color channels.

Parameters:
red Bits per pixel for the Red color channel.
green Bits per pixel for the Green color channel.
blue Bits per pixel for the Blue color channel.
alpha Bits per pixel for the Alpha color channel.

Definition at line 83 of file ColorFormat.cs.

00084         {
00085             if (red < 0 || green < 0 || blue < 0 || alpha < 0)
00086                 throw new ArgumentOutOfRangeException("Arguments must be greater or equal to zero.");
00087             this.red = (byte)red;
00088             this.green = (byte)green;
00089             this.blue = (byte)blue;
00090             this.alpha = (byte)alpha;
00091             this.bitsPerPixel = red + green + blue + alpha;
00092             this.isIndexed = false;
00093             if (this.bitsPerPixel < 15 && this.bitsPerPixel != 0)
00094                 this.isIndexed = true;
00095         }


Member Function Documentation

override bool OpenTK.Graphics.ColorFormat.Equals ( object  obj  ) 

Indicates whether this instance and a specified object are equal.

Parameters:
obj Another object to compare to.
Returns:
True if this instance is equal to obj; false otherwise.

Definition at line 142 of file ColorFormat.cs.

00143         {
00144             return (obj is ColorFormat) ? (this == (ColorFormat)obj) : false;
00145         }

override int OpenTK.Graphics.ColorFormat.GetHashCode (  ) 

Returns the hash code for this instance.

Returns:
A System.Int32 with the hash code of this instance.

Definition at line 183 of file ColorFormat.cs.

00184         {
00185             return Red ^ Green ^ Blue ^ Alpha;
00186         }

static implicit OpenTK.Graphics.ColorFormat.operator ColorFormat ( int  bpp  )  [static]

Converts the specified bpp into a new ColorFormat.

Parameters:
bpp The bits per pixel to convert.
Returns:
A ColorFormat with the specified bits per pixel.

Definition at line 123 of file ColorFormat.cs.

00124         {
00125             return new ColorFormat(bpp);
00126         }

static bool OpenTK.Graphics.ColorFormat.operator!= ( ColorFormat  left,
ColorFormat  right 
) [static]

Compares two instances for inequality.

Parameters:
left The left operand.
right The right operand.
Returns:
True if both instances are not equal; false otherwise.

Definition at line 174 of file ColorFormat.cs.

00175         {
00176             return !(left == right);
00177         }

static bool OpenTK.Graphics.ColorFormat.operator== ( ColorFormat  left,
ColorFormat  right 
) [static]

Compares two instances for equality.

Parameters:
left The left operand.
right The right operand.
Returns:
True if both instances are equal; false otherwise.

Definition at line 153 of file ColorFormat.cs.

00154         {
00155             if ((object)left == (object)null && (object)right != (object)null ||
00156                 (object)left != (object)null && (object)right == (object)null)
00157                 return false;
00158 
00159             if ((object)left == (object)null && (object)right == (object)null)
00160                 return true;
00161 
00162             return left.Red == right.Red &&
00163                    left.Green == right.Green &&
00164                    left.Blue == right.Blue &&
00165                    left.Alpha == right.Alpha;
00166         }

override string OpenTK.Graphics.ColorFormat.ToString (  ) 

Returns a System.String that describes this instance.

Returns:
A System.String that describes this instance.

Definition at line 192 of file ColorFormat.cs.

00193         {
00194             return string.Format("{0} ({1})", BitsPerPixel, (IsIndexed ? " indexed" : Red.ToString() + Green.ToString() + Blue.ToString() + Alpha.ToString()));
00195         }


Property Documentation

int OpenTK.Graphics.ColorFormat.Alpha [get, set]

Gets the bits per pixel for the Alpha channel.

Definition at line 108 of file ColorFormat.cs.

int OpenTK.Graphics.ColorFormat.BitsPerPixel [get, set]

Gets the sum of Red, Green, Blue and Alpha bits per pixel.

Definition at line 112 of file ColorFormat.cs.

int OpenTK.Graphics.ColorFormat.Blue [get, set]

Gets the bits per pixel for the Blue channel.

Definition at line 106 of file ColorFormat.cs.

int OpenTK.Graphics.ColorFormat.Green [get, set]

Gets the bits per pixel for the Green channel.

Definition at line 104 of file ColorFormat.cs.

bool OpenTK.Graphics.ColorFormat.IsIndexed [get, set]

Gets a System.Boolean indicating whether this ColorFormat is indexed.

Definition at line 110 of file ColorFormat.cs.

int OpenTK.Graphics.ColorFormat.Red [get, set]

Gets the bits per pixel for the Red channel.

Definition at line 102 of file ColorFormat.cs.

 All Classes Functions Variables Enumerations Properties Events

Generated on Tue Mar 9 14:59:22 2010 for The Open Toolkit library by  doxygen 1.6.1