Skip to main content

Class PixelBufferBase

Represents a pixel buffer

Assembly: MicroGraphics.dll
View Source
Declaration
public abstract class PixelBufferBase : IPixelBuffer, IDisposable

Derived:

Expand

Implements:
Meadow.Peripherals.Displays.IPixelBuffer, System.IDisposable

Properties

Width

Width of buffer in pixels

View Source
Declaration
public int Width { get; protected set; }

Height

Height of buffer in pixels

View Source
Declaration
public int Height { get; protected set; }

ColorMode

Color mode of the buffer

View Source
Declaration
public virtual ColorMode ColorMode { get; protected set; }

BitDepth

Bit depth of display as an integer

View Source
Declaration
public int BitDepth { get; }

ByteCount

Number of bytes in buffer

View Source
Declaration
public int ByteCount { get; }

Buffer

The buffer that holds the pixel data The packing structure in buffer-specific

View Source
Declaration
public byte[] Buffer { get; protected set; }

Methods

InitializeBuffer(bool)

Initialize the pixel buffer based on the current width, height and color depth

View Source
Declaration
public void InitializeBuffer(bool replaceIfExists = false)
Parameters
TypeNameDescription
System.BooleanreplaceIfExistsIf true, will recreates the buffer if it already exists

Clear()

Clear the array that stores the pixel buffer

View Source
Declaration
public virtual void Clear()

Fill(Color)

Fill the entire pixel buffer with a color

View Source
Declaration
public abstract void Fill(Color color)
Parameters
TypeNameDescription
Meadow.ColorcolorFill color

Fill(int, int, int, int, Color)

Fill a region of the pixel buffer with a color

View Source
Declaration
public abstract void Fill(int originX, int originY, int width, int height, Color color)
Parameters
TypeNameDescription
System.Int32originXX pixel to start fill
System.Int32originYY pixel to start fill
System.Int32widthWidth to fill
System.Int32heightheight to fill
Meadow.ColorcolorFill color

GetPixel(int, int)

Get pixel at location

View Source
Declaration
public abstract Color GetPixel(int x, int y)
Returns

Meadow.Color

Parameters
TypeNameDescription
System.Int32xX pixel location
System.Int32yY pixel location

SetPixel(int, int, Color)

Set pixel at location to a color

View Source
Declaration
public abstract void SetPixel(int x, int y, Color color)
Parameters
TypeNameDescription
System.Int32xX pixel location
System.Int32yY pixel location
Meadow.ColorcolorPixel color

InvertPixel(int, int)

Invert pixel color at location

View Source
Declaration
public abstract void InvertPixel(int x, int y)
Parameters
TypeNameDescription
System.Int32xX pixel location
System.Int32yY pixel location

WriteBuffer(int, int, IPixelBuffer)

Default way to write a buffer into this buffer.

This is very slow and should be avoided if possible. It loops through every pixel. If the buffer bit depths match there should be faster ways to write using Array.Copy.

View Source
Declaration
public virtual void WriteBuffer(int originX, int originY, IPixelBuffer buffer)
Parameters
TypeNameDescription
System.Int32originXThe X coord to start writing
System.Int32originYThe Y coord to start writing
Meadow.Peripherals.Displays.IPixelBufferbufferThe buffer to copy into this buffer

WriteBufferSlow(int, int, IPixelBuffer)

A slow buffer write operation that writes pixel-by-pixel using the Color struct to scale color based on bit depth.

This method can handle buffers with mismatched bit depths.

View Source
Declaration
protected void WriteBufferSlow(int originX, int originY, IPixelBuffer buffer)
Parameters
TypeNameDescription
System.Int32originXThe X coord to start writing the buffer
System.Int32originYThe Y coord to start writing the buffer
Meadow.Peripherals.Displays.IPixelBufferbufferThe buffer to write

RotateAndConvert<T>(RotationType)

Create a new buffer from the existing buffer with a new rotation

View Source
Declaration
public T RotateAndConvert<T>(RotationType rotation) where T : PixelBufferBase, new()
Returns

<T>: The new buffer

Parameters
TypeNameDescription
Meadow.Peripherals.Displays.RotationTyperotationRotation
Type Parameters
NameDescription
TBuffer type

ScaleUp<T>(int)

Create a new buffer scaled up from the existing buffer

View Source
Declaration
public T ScaleUp<T>(int scaleFactor) where T : PixelBufferBase, new()
Returns

<T>: The new buffer

Parameters
TypeNameDescription
System.Int32scaleFactorInteger scale ratio
Type Parameters
NameDescription
TBuffer type

ConvertPixelBuffer<T>()

Create a new pixel buffer and copy/convert pixel data from existing buffer

View Source
Declaration
public T ConvertPixelBuffer<T>() where T : PixelBufferBase, new()
Returns

<T>: A pixel buffer derived from PixelBufferBase##### Type Parameters | Name | Description | |:--- |:--- | | T | The buffer type to convert to |

GetColorDistance(Color, Color)

Calculate the uncorrected distance between two colors using bytes for red, green, blue

View Source
Declaration
public double GetColorDistance(Color color1, Color color2)
Returns

System.Double: The distance as a double

Parameters
TypeName
Meadow.Colorcolor1
Meadow.Colorcolor2

Dispose(bool)

Dispose of the object

View Source
Declaration
protected virtual void Dispose(bool disposing)
Parameters
TypeNameDescription
System.BooleandisposingIs disposing

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

View Source
Declaration
public void Dispose()

Implements

  • Meadow.Peripherals.Displays.IPixelBuffer
  • System.IDisposable