Updated NeoBuffer object (markdown)

Michael Miller
2016-04-20 11:06:38 -07:00
parent 4d9d3f4a7f
commit 5df0c16df6

@@ -4,7 +4,7 @@
The NeoBuffer is basic image storage object. Based upon the "method" object it is defined with, it can store the image data in RAM or reference image data stored in PROGMEM.
It provides direct x,y access to get and set pixels along with a render method Blt() that will copy bits to the NeoPixelBus or other Raster objects.
It provides direct x,y access to get and set pixels along with a render method `Blt()` that will copy bits to the NeoPixelBus or other Raster objects.
## How to construct one
The important part of creating one is to match the "ColorFeature" between your NeoPixelBus and the buffer since the buffer will store/reference data in the same format as the bus.
@@ -16,7 +16,7 @@ NeoBuffer<NeoBufferMethod<NeoGrbwFeature>> image(myImageWidth, myImageHeight, NU
```
You also need to decide how you are going to store the image data. Images take a lot of memory, and some consideration needs to be taken when making this decision.
If you plan to dynamically modify the image through source code, then you have to use define it to use RAM. You can still initialize the RAM stored image from PROGMEM.
If you plan to dynamically modify the image through source code, then you have to define it to use RAM. You can still initialize the RAM stored image from PROGMEM.
If you plan to just consume the image and never modify it, your best approach is to use PROGMEM as it will store in flash like source code and save precious RAM for your sketch.
```
// stored in RAM, but initialized by the "myImage" from PROGMEM
@@ -29,15 +29,16 @@ NeoBuffer<NeoBufferProgmemMethod<NeoGrbwFeature>> image(myImageWidth, myImageHei
To render the buffer image you use one of the BLT (block transfer) methods. They will copy the image data from the buffer to the target.
### Targets of Rendering
The BLT method all take a generic target for the first parameter of a `NeoBufferContext<>`. This buffer context is a mechanism to allow for different types of targets all can be used. You can pass the NeoPixelBus directly for this. You may also pass any of the other Raster objects that allow for writing to.
The BLT methods all take a generic target for the first parameter as a `NeoBufferContext<>`. This buffer context is a mechanism to allow for different types of targets to be used. You can pass the NeoPixelBus directly for this. You may also pass any of the other Raster objects that allow writing to.
### Rendering to a string of pixels
If you have both an image that is one pixel high, and you have just a string of pixels on your NeoPixelBus, and you want speed, then you can use `Blt(dest, destIndex)` method. This method is limited but is very quick.
If you have both an image that is one pixel high, and you have just a string of pixels on your NeoPixelBus, and you want speed; then you can use `Blt(dest, destIndex)` method. This method is limited but is very quick.
### Rendering to a matrix of pixels
If your image has more than one row or column of pixels and/or your pixels are arranged in a matrix, then can use `Blt(dest, xDest, yDest, xSrc, ySrc, wSrc, hSrc, layoutMap)`. This is the most common way to render.
The complexity with this method is that the target buffer doesn't explicitly know how you have them laid out. Are you using NeoTopology or NeoMosaic? So you need to pass a callback as the "layoutMap" that will be called so you can provide the mapping. Inside this you can provide your custom layout mapping or you can use the `MapProbe()` method of any of the matrix panel support objects like NeoTopology, NeoTiles, or NeoMosaic.
The complexity with this method is that the target buffer doesn't explicitly know how you have them laid out. You maybe using NeoTopology or maybe NeoMosaic. To solve this you need to pass a callback as the "layoutMap" that will be called so you can provide the mapping. Inside this you can provide your custom layout mapping or you can use the `MapProbe()` method of any of the matrix panel support objects like NeoTopology, NeoTiles, or NeoMosaic.
If you are providing your own mapping; you must return `PixelIndex_OutOfBounds` if the coordinate is outside the range you support.
```
NeoTopology<RowMajorLayout> topo(16,16);