mirror of
https://github.com/Makuna/NeoPixelBus.git
synced 2025-08-06 12:24:27 +02:00
Created NeoBuffer object API (markdown)
75
NeoBuffer-object-API.md
Normal file
75
NeoBuffer-object-API.md
Normal file
@@ -0,0 +1,75 @@
|
||||
NeoBuffer represents a image container object that stores the data in a NeoPixel native format for faster rendering. The primary use of this class is to contain an image and have it rendered to a NeoPixelBus.
|
||||
|
||||
## Constructors
|
||||
|
||||
### NeoBuffer\<METHOD\>(uint16_t width, uint16_t height, PGM_VOID_P pixels)
|
||||
This will define the object with the given Method, and construct it to the width and height.
|
||||
Valid Method objects are the NeoBufferMethod and NeoBufferProgmemMethod.
|
||||
The optional pixels will either be copied into the Ram buffer (for NeoBufferMethod) or become the referenced data (NeoBufferProgmemMethod).
|
||||
|
||||
```
|
||||
NeoPixelBuffer<NeoPixelBufferProgmemMethod<NeoGrbFeature>> image(myImageWidth, myImageHeight, myImage);
|
||||
|
||||
```
|
||||
|
||||
## Methods
|
||||
### uint16_t PixelCount() const
|
||||
This will return the number of pixels in the buffer.
|
||||
|
||||
### uint16_t Width() const
|
||||
This will return the width in pixels of the buffer.
|
||||
|
||||
### uint16_t Height() const
|
||||
This will return the height in pixels of the buffer.
|
||||
|
||||
### void SetPixelColor(int16_t x, int16_t y, ColorObject color)
|
||||
This will set the color to the given pixel.
|
||||
x - the horizontal pixel position
|
||||
y - the vertical pixel position
|
||||
color - a color object to use, RgbColor, HslColor, and HsbColor will all work and if the NeoPixelBus object was created with the NeoRgbwFeature the RgbwColor will also work.
|
||||
|
||||
### ColorObject GetPixelColor(int16_t x, int16_t y)
|
||||
This will return the color of the given pixel.
|
||||
x - the horizontal pixel position
|
||||
y - the vertical pixel position
|
||||
\<return\>, a color object, RgbColor or RgbwColor.
|
||||
|
||||
### void ClearTo(ColorObject color)
|
||||
This will clear all pixels to the given color.
|
||||
color - a color object to use, RgbColor, HslColor, and HsbColor will all work and if the NeoPixelBus object was created with the NeoRgbwFeature the RgbwColor will also work.
|
||||
|
||||
### void Blt(NeoBufferContext destBuffer, uint16_t indexPixel)
|
||||
This will render this image to the destBuffer at indexPixel. This is a linear rendering, not a 2D image rendering.
|
||||
destBuffer - Another NeoBuffer or NeoPixelBus.
|
||||
indexPixel - the location to start the render at
|
||||
|
||||
### void Blt(NeoBufferContext destBuffer, int16_t xDest, int16_t yDest, int16_t xSrc, int16_t ySrc, int16_t wSrc, int16_t hSrc, LayoutMapCallback layoutMap)
|
||||
This will render part of this image to the destBuffer at given location. This is a 2d image rendering.
|
||||
destBuffer - Another NeoBuffer or NeoPixelBus.
|
||||
xDest - the upper left location in the destination to render to
|
||||
yDest - the upper left location in the destination to render to
|
||||
xSrc - the upper left location in the source to render from
|
||||
ySrc - the upper left location in the source to render from
|
||||
wSrc - the width to render
|
||||
hSrc - the height to render
|
||||
layoutMap - a layoutMap callback that implements the destinations mapping routine (see below)
|
||||
|
||||
### void Blt(NeoBufferContext destBuffer, int16_t xDest, int16_t yDest, LayoutMapCallback layoutMap)
|
||||
This will render all of this image to the destBuffer at given location. This is a 2d image rendering.
|
||||
destBuffer - Another NeoBuffer or NeoPixelBus.
|
||||
xDest - the upper left location in the destination to render to
|
||||
yDest - the upper left location in the destination to render to
|
||||
layoutMap - a layoutMap callback that implements the destinations mapping routine (see Matrix Panel support)
|
||||
|
||||
## Callbacks
|
||||
### uint16_t LayoutMapCallback(int16_t x, int16_t y)
|
||||
As the consumer of certain methods, you will need to implement this and pass it into those methods. You are expected to translate the x,y location of the destination to a linear index value. If you have implemented NeoTopology, NeoTiles, or NeoMosaic; you can just call the `MapProbe()` method on them and return what they provide.
|
||||
```
|
||||
NeoTopology<RowMajorLayout> topo(16,16); // 16x16 matrix panel
|
||||
|
||||
uint16_t MyLayoutMap(int16_t x, int16_t y)
|
||||
{
|
||||
return topo.MapProbe(x, y);
|
||||
}
|
||||
```
|
||||
If you implement your own, make sure to handle out of range values beyond your edges including negative values and return PixelIndex_OutOfBounds for these cases.
|
Reference in New Issue
Block a user