AgateLib.DisplayLib.PixelBuffer Class Reference

Class which encapsulates raw pixel data. This can be used to construct or modify surface data programmatically. More...

List of all members.

Public Member Functions

 PixelBuffer (PixelFormat format, Size size)
 Constructs a PixelBuffer object.
 PixelBuffer (PixelFormat format, Size size, byte[] data)
 Constructs a PixelBuffer object. Data passed is not copied; it is referenced.
 PixelBuffer (PixelFormat format, Size size, byte[] data, PixelFormat dataFormat)
 Constructs a PixelBuffer object. This overload performs automatic conversion of the data passed to match the format specified for the pixel buffer. The data is always copied in memory, even if it is of the same type as the format parameter.
 PixelBuffer (PixelFormat format, Size size, byte[] data, bool copyData)
 Constructs a PixelBuffer object. This overload allows you to specify whether or not the data parameter should be copied.
 PixelBuffer (PixelFormat format, Size size, IntPtr data, PixelFormat sourceFormat, int srcRowStride)
 Constructs a PixelBuffer object. Copies data from an unmanaged memory location in the specified format.
 PixelBuffer (PixelBuffer buffer, Rectangle srcRect)
 Constructs a PixelBuffer object, taking image data from a preexisting pixel buffer.
bool IsBlank ()
 Checks to see if this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.
bool IsBlank (double alphaTolerance)
 Checks to see if this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.
bool IsRegionBlank (Rectangle rectangle)
 Checks to see if this region of the pixelbuffer only contains transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.
bool IsRegionBlank (Rectangle rectangle, double alphaTolerance)
 Returns true if all pixels within the passed rectangle are below the passed alpha tolerance value.
bool IsRowBlank (int row)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.
bool IsRowBlank (int row, double alphaTolerance)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.
bool IsRowBlank (int row, int left, int width)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels.
bool IsRowBlank (int row, int left, int width, double alphaTolerance)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.
bool IsColumnBlank (int col)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.
bool IsColumnBlank (int col, double alphaTolerance)
 Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.
bool IsColumnBlank (int col, int top, int height)
 Checks to see if a portion of the selected row of this PixelBuffer contains only transparent pixels.
bool IsColumnBlank (int col, int top, int height, double alphaTolerance)
 Checks to see if a portion of the selected row of this PixelBuffer contains only transparent pixels.
void CopyFrom (PixelBuffer buffer, Rectangle srcRect, Point destPt, bool clip)
 Copies pixel data from the specified PixelBuffer.
int GetPixelIndex (int x, int y)
 Gets the index of the first byte in the pixel in the Data array at the specified point.
bool IsPointValid (int x, int y)
 Returns true if the specified point is within the pixel buffer.
bool IsPointValid (Point pt)
 Returns true if the specified point is within the pixel buffer.
Color GetPixel (int x, int y)
 Copies pixel data from the specified location to a Color structure.
void SetPixel (int x, int y, Color clr)
 Sets the color at a particular pixel.
void SetData (byte[] srcData, PixelFormat srcFormat)
 Copies the data from the array passed in into the internal pixel buffer array. Automatic conversion is performed if the format the data is in (indicated by format parameter) differs from the format the pixel buffer is in.
void SetData (IntPtr data, PixelFormat srcFormat, int srcRowStride)
 Copies the data from the unmanaged memory pointer passed in into the internal pixel buffer array. Automatic conversion is performed if the format the data is in (indicated by format parameter) differs from the format the pixel buffer is in.
PixelBuffer ConvertTo (PixelFormat pixelFormat)
 Creates a new PixelBuffer and copies the data in this PixelBuffer, performing automatic conversion.
PixelBuffer ConvertTo (PixelFormat pixelFormat, Size mTextureSize)
 Creates a new PixelBuffer of the specified size, with the data in this PixelBuffer copied to the upper left corner.
PixelBuffer ConvertTo (PixelFormat pixelFormat, Size mTextureSize, Point point)
 Creates a new PixelBuffer of the specified size, with the data in this PixelBuffer copied so that the upper left corner is specified by point.
void SaveTo (string filename, ImageFileFormat format)
 Saves the data in the PixelBuffer for to an image file.
void ReplaceColor (Color searchColor, Color newColor)
 Replaces all instances of the specified color.

Static Public Member Functions

static PixelBuffer FromFile (string file)
 Loads image data from a file and returns a PixelBuffer.
static void ConvertPixel (byte[] dest, int destIndex, PixelFormat destFormat, byte[] src, int srcIndex, PixelFormat srcFormat)
 Converts a single pixel in the specified format at the specified location from the source array and writes it to the specified location in the destination array.
static int GetPixelStride (PixelFormat format)
 Returns the number of bytes in memory used by a single pixel in the specified format.
static bool FormatHasAlpha (PixelFormat format)
 Returns true if the specified PixelFormat contains an alpha channel.

Properties

PixelFormat PixelFormat [get]
 Gets the format of the pixel data.
byte[] Data [get, set]
 Gets or sets the raw pixel data, in the format indicated by PixelFormat. An exception is thrown when setting Data if the length of the array passed is not Width * Height * PixelStride.
int PixelStride [get]
 Gets how many bytes each pixel takes up in memory.
int Height [get]
 Returns the height in pixels of the buffer.
int Width [get]
 Returns the width in pixels of the buffer.
Size Size [get]
 Returns the size (width, height) in pixels of the buffer.
int RowStride [get]
 Returns how many bytes a single row takes up. This value can be used to increase an index to go from one line of pixels to the next.


Detailed Description

Class which encapsulates raw pixel data. This can be used to construct or modify surface data programmatically.


Constructor & Destructor Documentation

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelFormat  format,
Size  size 
)

Constructs a PixelBuffer object.

Parameters:
size The size of the image data in pixels.
format The raw data format of the pixels to be contained in the pixel buffer. PixelFormat.Any is not a valid parameter.

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelFormat  format,
Size  size,
byte[]  data 
)

Constructs a PixelBuffer object. Data passed is not copied; it is referenced.

Parameters:
size The size of the image data in pixels.
format The raw data format of the pixels to be contained in the pixel buffer. PixelFormat.Any is not a valid parameter.
data Raw pixel data. It must be the correct size for the format passed. This data will not be copied; it will be referenced.

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelFormat  format,
Size  size,
byte[]  data,
PixelFormat  dataFormat 
)

Constructs a PixelBuffer object. This overload performs automatic conversion of the data passed to match the format specified for the pixel buffer. The data is always copied in memory, even if it is of the same type as the format parameter.

Parameters:
size The size of the image data in pixels.
format The raw data format of the pixels to be contained in the pixel buffer. PixelFormat.Any is not a valid parameter.
data Raw pixel data. It must be the correct size for the format passed.
dataFormat Format of the raw pixel data. This data will be copied into the PixelBuffer.

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelFormat  format,
Size  size,
byte[]  data,
bool  copyData 
)

Constructs a PixelBuffer object. This overload allows you to specify whether or not the data parameter should be copied.

Parameters:
size The size of the image data in pixels.
format The raw data format of the pixels to be contained in the pixel buffer. PixelFormat.Any is not a valid parameter.
data Raw pixel data. It must be the correct size for the format passed.
copyData True if the data should be copied into the pixel buffer.

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelFormat  format,
Size  size,
IntPtr  data,
PixelFormat  sourceFormat,
int  srcRowStride 
)

Constructs a PixelBuffer object. Copies data from an unmanaged memory location in the specified format.

Parameters:
format The format the pixel buffer should be stored in.
size The size (width and height) in pixels the pixel buffer should contain.
data Pointer to an unmanaged memory location which contains the pixel data. This data must be the same size in pixels as the size parameter.
sourceFormat The pixelformat of the source data.
srcRowStride The number of bytes from the beginning of one row to the next.

AgateLib.DisplayLib.PixelBuffer.PixelBuffer ( PixelBuffer  buffer,
Rectangle  srcRect 
)

Constructs a PixelBuffer object, taking image data from a preexisting pixel buffer.

Parameters:
buffer The PixelBuffer object to copy image data from.
srcRect The source rectangle in the buffer to copy image data from.


Member Function Documentation

static void AgateLib.DisplayLib.PixelBuffer.ConvertPixel ( byte[]  dest,
int  destIndex,
PixelFormat  destFormat,
byte[]  src,
int  srcIndex,
PixelFormat  srcFormat 
) [static]

Converts a single pixel in the specified format at the specified location from the source array and writes it to the specified location in the destination array.

Parameters:
dest Destination array to write to.
destIndex Index in destination array to begin writing.
destFormat Pixel format to use when writing to destination array.
src Source array to read pixel data from
srcIndex Index in source array where pixel data should be read from.
srcFormat The format of the pixel data in the source array.

PixelBuffer AgateLib.DisplayLib.PixelBuffer.ConvertTo ( PixelFormat  pixelFormat,
Size  mTextureSize,
Point  point 
)

Creates a new PixelBuffer of the specified size, with the data in this PixelBuffer copied so that the upper left corner is specified by point.

Parameters:
pixelFormat PixelFormat that the newly created PixelBuffer should have.
mTextureSize 
point 
Returns:

PixelBuffer AgateLib.DisplayLib.PixelBuffer.ConvertTo ( PixelFormat  pixelFormat,
Size  mTextureSize 
)

Creates a new PixelBuffer of the specified size, with the data in this PixelBuffer copied to the upper left corner.

Parameters:
pixelFormat PixelFormat that the newly created PixelBuffer should have.
mTextureSize 
Returns:

PixelBuffer AgateLib.DisplayLib.PixelBuffer.ConvertTo ( PixelFormat  pixelFormat  ) 

Creates a new PixelBuffer and copies the data in this PixelBuffer, performing automatic conversion.

Parameters:
pixelFormat PixelFormat that the newly created PixelBuffer should have.
Returns:

void AgateLib.DisplayLib.PixelBuffer.CopyFrom ( PixelBuffer  buffer,
Rectangle  srcRect,
Point  destPt,
bool  clip 
)

Copies pixel data from the specified PixelBuffer.

Parameters:
buffer The pixel buffer to copy from.
srcRect 
destPt 
clip If true, the copied region will automatically be clipped. If false, this method will throw an exception if the area being copied to is out of range.

static bool AgateLib.DisplayLib.PixelBuffer.FormatHasAlpha ( PixelFormat  format  )  [static]

Returns true if the specified PixelFormat contains an alpha channel.

Parameters:
format 
Returns:

static PixelBuffer AgateLib.DisplayLib.PixelBuffer.FromFile ( string  file  )  [static]

Loads image data from a file and returns a PixelBuffer.

Parameters:
file 
Returns:

Color AgateLib.DisplayLib.PixelBuffer.GetPixel ( int  x,
int  y 
)

Copies pixel data from the specified location to a Color structure.

Parameters:
x 
y 
Returns:

int AgateLib.DisplayLib.PixelBuffer.GetPixelIndex ( int  x,
int  y 
)

Gets the index of the first byte in the pixel in the Data array at the specified point.

Parameters:
x 
y 
Returns:

static int AgateLib.DisplayLib.PixelBuffer.GetPixelStride ( PixelFormat  format  )  [static]

Returns the number of bytes in memory used by a single pixel in the specified format.

Parameters:
format Which format to look up.
Returns:
The number of bytes used by the format. This is always either 2 for 15 or 16 bit formats, 3 for 24 bit formats, and 4 for 32 bit formats.

bool AgateLib.DisplayLib.PixelBuffer.IsBlank ( double  alphaTolerance  ) 

Checks to see if this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.

Parameters:
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsBlank (  ) 

Checks to see if this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.

Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsColumnBlank ( int  col,
int  top,
int  height,
double  alphaTolerance 
)

Checks to see if a portion of the selected row of this PixelBuffer contains only transparent pixels.

Parameters:
col 
top 
height 
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsColumnBlank ( int  col,
int  top,
int  height 
)

Checks to see if a portion of the selected row of this PixelBuffer contains only transparent pixels.

Parameters:
col 
top 
height 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsColumnBlank ( int  col,
double  alphaTolerance 
)

Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.

Parameters:
col 
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsColumnBlank ( int  col  ) 

Checks to see if the selected row of this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.

Parameters:
col 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsPointValid ( Point  pt  ) 

Returns true if the specified point is within the pixel buffer.

Parameters:
pt 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsPointValid ( int  x,
int  y 
)

Returns true if the specified point is within the pixel buffer.

Parameters:
x 
y 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRegionBlank ( Rectangle  rectangle,
double  alphaTolerance 
)

Returns true if all pixels within the passed rectangle are below the passed alpha tolerance value.

Parameters:
rectangle 
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRegionBlank ( Rectangle  rectangle  ) 

Checks to see if this region of the pixelbuffer only contains transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.

Parameters:
rectangle 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRowBlank ( int  row,
int  left,
int  width,
double  alphaTolerance 
)

Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.

Parameters:
row 
left 
width 
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRowBlank ( int  row,
int  left,
int  width 
)

Checks to see if the selected row of this PixelBuffer contains only transparent pixels.

Parameters:
row 
left 
width 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRowBlank ( int  row,
double  alphaTolerance 
)

Checks to see if the selected row of this PixelBuffer contains only transparent pixels. This overload allows the alpha tolerance to be specified explicitly.

Parameters:
row 
alphaTolerance 
Returns:

bool AgateLib.DisplayLib.PixelBuffer.IsRowBlank ( int  row  ) 

Checks to see if the selected row of this PixelBuffer contains only transparent pixels. Pixels with an alpha value of less than Display.AlphaThreshold are considered transparent.

Parameters:
row 
Returns:

void AgateLib.DisplayLib.PixelBuffer.ReplaceColor ( Color  searchColor,
Color  newColor 
)

Replaces all instances of the specified color.

Parameters:
searchColor The color to replace.
newColor The new color to overwrite searchColor.

void AgateLib.DisplayLib.PixelBuffer.SaveTo ( string  filename,
ImageFileFormat  format 
)

Saves the data in the PixelBuffer for to an image file.

Parameters:
filename 
format 

void AgateLib.DisplayLib.PixelBuffer.SetData ( IntPtr  data,
PixelFormat  srcFormat,
int  srcRowStride 
)

Copies the data from the unmanaged memory pointer passed in into the internal pixel buffer array. Automatic conversion is performed if the format the data is in (indicated by format parameter) differs from the format the pixel buffer is in.

Parameters:
data 
srcFormat 
srcRowStride 

void AgateLib.DisplayLib.PixelBuffer.SetData ( byte[]  srcData,
PixelFormat  srcFormat 
)

Copies the data from the array passed in into the internal pixel buffer array. Automatic conversion is performed if the format the data is in (indicated by format parameter) differs from the format the pixel buffer is in.

Parameters:
data 
srcFormat 

void AgateLib.DisplayLib.PixelBuffer.SetPixel ( int  x,
int  y,
Color  clr 
)

Sets the color at a particular pixel.

Parameters:
x 
y 
clr 


Property Documentation

byte [] AgateLib.DisplayLib.PixelBuffer.Data [get, set]

Gets or sets the raw pixel data, in the format indicated by PixelFormat. An exception is thrown when setting Data if the length of the array passed is not Width * Height * PixelStride.

The data is not copied when set, it is only referenced, so changes to the array that is passed in will affect the data in the pixel buffer. It is assumed that the data passed in is of the same format as the pixel buffer. If you wish to copy data use the SetData method.

int AgateLib.DisplayLib.PixelBuffer.Height [get]

Returns the height in pixels of the buffer.

PixelFormat AgateLib.DisplayLib.PixelBuffer.PixelFormat [get]

Gets the format of the pixel data.

int AgateLib.DisplayLib.PixelBuffer.PixelStride [get]

Gets how many bytes each pixel takes up in memory.

int AgateLib.DisplayLib.PixelBuffer.RowStride [get]

Returns how many bytes a single row takes up. This value can be used to increase an index to go from one line of pixels to the next.

Size AgateLib.DisplayLib.PixelBuffer.Size [get]

Returns the size (width, height) in pixels of the buffer.

int AgateLib.DisplayLib.PixelBuffer.Width [get]

Returns the width in pixels of the buffer.


The documentation for this class was generated from the following file:
AgateLib
Awesome Game and Tool Engine Library
SourceForge.net Logo