Skip to content

NeoBitmapFile object

Michael Miller edited this page Nov 7, 2019 · 4 revisions

NeoBitmapFile object API

NOTE: Parts of the description below are out of date, specifically around using BLT and rendering. Please refer to the API and examples for exactness until this area is updated.

The NeoBitmapFile is image file reference object. As pixels are rendered it will retrieve them from the file thus saving memory.

It provides direct x,y access to get 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.

Here you can see that they both are defined with NeoGrbwFeature.

NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
NeoBitmapFile<NeoGrbwFeature, File> image;

The other template class is the class type used by your library to represent a file. It must follow standard Arduino File API. Generally, just passing File like above is normal. For Esp8266, you may pass a SPIFFS File type allowing this to read from SPIFFs library.

How to render the image

To render the bitmap image you use one of the BLT (block transfer) methods. They will copy the image data from the file to the target.

Targets of Rendering

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 a "sprite" 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, xSrc, ySrc, wSrc) method. The image can contain multiple rows, but only the row at ySrc will be used in the render. This method is very quick and is primarily slowed down by the speed of the File class.

Rendering to a matrix of pixels

If your bitmap has more than one row or column of pixels and your NeoPixels are arranged in a matrix, then can use Blt(dest, xDest, yDest, xSrc, ySrc, wSrc, hSrc, layoutMap) to render a 2D image.

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);

uint16_t LayoutMap(int16_t x, int16_t y)
{
  return topo.MapProbe(x, y);
}

Once of you have defined this callback, then you can use to render parts of the image.

image.Blt(strip, 4, 4, 0, 0, 4, 4, LayoutMap);

This will render the first 4x4 block of pixels to the strip at location (4,4).

Clone this wiki locally