Skip to main content

Class PixelBufferBase

Represents a pixel buffer

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

Derived:

Expand

Meadow.Foundation.Graphics.Buffers.Buffer1bpp, Meadow.Foundation.Graphics.Buffers.BufferGray4, Meadow.Foundation.Graphics.Buffers.BufferGray8, Meadow.Foundation.Graphics.Buffers.BufferIndexed4, Meadow.Foundation.Graphics.Buffers.BufferRgb332, Meadow.Foundation.Graphics.Buffers.BufferRgb444, Meadow.Foundation.Graphics.Buffers.BufferRgb565, Meadow.Foundation.Graphics.Buffers.BufferRgb888, Meadow.Foundation.Graphics.Buffers.BufferRgba8888

Implements:
Meadow.Foundation.Graphics.Buffers.IPixelBuffer, System.IDisposable

Properties

Width

Width of buffer in pixels

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

Height

Height of buffer in pixels

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

ColorMode

Color mode of the buffer

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

BitDepth

Bit depth of display as an integer

View Source
public int BitDepth { get; }

ByteCount

Number of bytes in buffer

View Source
public int ByteCount { get; }

Buffer

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

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

Methods

InitializeBuffer(bool)

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

View Source
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
public virtual void Clear()

Fill(Color)

Fill the entire pixel buffer with a color

View Source
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
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
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
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
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
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.Foundation.Graphics.Buffers.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
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.Foundation.Graphics.Buffers.IPixelBufferbufferThe buffer to write

RotateAndConvert<T>(RotationType)

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

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

<T>: The new buffer

Parameters
TypeNameDescription
Meadow.Foundation.Graphics.RotationTyperotationRotation
Type Parameters
NameDescription
TBuffer type

ScaleUp<T>(int)

Create a new buffer scaled up from the existing buffer

View Source
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
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
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
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
public void Dispose()

Implements