Adafruit ImageReader Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Adafruit_ImageReader Class Reference

An optional adjunct to Adafruit_SPITFT that reads RGB BMP images (maybe others in the future) from a flash filesystem (SD card or SPI/QSPI flash). It's purposefully been made an entirely separate class (rather than part of SPITFT or GFX classes) so that Arduino code that uses GFX or SPITFT without image loading does not need to incur the RAM overhead and additional dependencies of the Adafruit_SPIFlash library by its mere inclusion. The syntaxes can therefore be a bit bizarre (passing display object as an argument), see examples for use. More...

#include <Adafruit_ImageReader.h>

Inheritance diagram for Adafruit_ImageReader:
Adafruit_ImageReader_EPD

Public Member Functions

 Adafruit_ImageReader (FatVolume &fs)
 Constructor. More...
 
 ~Adafruit_ImageReader (void)
 Destructor. More...
 
ImageReturnCode drawBMP (const char *filename, Adafruit_SPITFT &tft, int16_t x, int16_t y, boolean transact=true)
 Loads BMP image file from SD card directly to SPITFT screen. More...
 
ImageReturnCode loadBMP (const char *filename, Adafruit_Image &img)
 Loads BMP image file from SD card into RAM (as one of the GFX canvas object types) for use with the bitmap-drawing functions. Not practical for most AVR microcontrollers, but some of the more capable 32-bit micros can afford some RAM for this. More...
 
ImageReturnCode bmpDimensions (const char *filename, int32_t *w, int32_t *h)
 Query pixel dimensions of BMP image file on SD card. More...
 
void printStatus (ImageReturnCode stat, Stream &stream=Serial)
 Print human-readable status message corresponding to an ImageReturnCode type. More...
 

Protected Member Functions

ImageReturnCode coreBMP (const char *filename, Adafruit_SPITFT *tft, uint16_t *dest, int16_t x, int16_t y, Adafruit_Image *img, boolean transact)
 BMP-reading function common both to the draw function (to TFT) and load function (to canvas object in RAM). BMP code has been centralized here so if/when more BMP format variants are added in the future, it doesn't need to be implemented, debugged and kept in sync in two places. More...
 
uint16_t readLE16 (void)
 Reads a little-endian 16-bit unsigned value from currently- open File, converting if necessary to the microcontroller's native endianism. (BMP files use little-endian values.) More...
 
uint32_t readLE32 (void)
 Reads a little-endian 32-bit unsigned value from currently- open File, converting if necessary to the microcontroller's native endianism. (BMP files use little-endian values.) More...
 

Protected Attributes

FatVolume * filesys
 FAT FileSystem Object.
 
File32 file
 Current Open file.
 

Detailed Description

An optional adjunct to Adafruit_SPITFT that reads RGB BMP images (maybe others in the future) from a flash filesystem (SD card or SPI/QSPI flash). It's purposefully been made an entirely separate class (rather than part of SPITFT or GFX classes) so that Arduino code that uses GFX or SPITFT without image loading does not need to incur the RAM overhead and additional dependencies of the Adafruit_SPIFlash library by its mere inclusion. The syntaxes can therefore be a bit bizarre (passing display object as an argument), see examples for use.

Constructor & Destructor Documentation

◆ Adafruit_ImageReader()

Adafruit_ImageReader::Adafruit_ImageReader ( FatVolume &  fs)

Constructor.

Returns
Adafruit_ImageReader object.
Parameters
fsFAT filesystem associated with this Adafruit_ImageReader instance. Any images to load will come from this filesystem; if multiple filesystems are required, each will require its own Adafruit_ImageReader object. The filesystem does NOT need to be initialized yet when passed in here (since this will often be in pre-setup() declaration, but DOES need initializing before any of the image loading or size functions are called!

◆ ~Adafruit_ImageReader()

Adafruit_ImageReader::~Adafruit_ImageReader ( void  )

Destructor.

Returns
None (void).

Member Function Documentation

◆ drawBMP()

ImageReturnCode Adafruit_ImageReader::drawBMP ( const char *  filename,
Adafruit_SPITFT &  tft,
int16_t  x,
int16_t  y,
boolean  transact = true 
)

Loads BMP image file from SD card directly to SPITFT screen.

Parameters
filenameName of BMP image file to load.
tftAdafruit_SPITFT object (e.g. one of the Adafruit TFT or OLED displays that subclass Adafruit_SPITFT).
xHorizontal offset in pixels; left edge = 0, positive = right. Value is signed, image will be clipped if all or part is off the screen edges. Screen rotation setting is observed.
yVertical offset in pixels; top edge = 0, positive = down.
transactPass 'true' if TFT and SD are on the same SPI bus, in which case SPI transactions are necessary. If separate peripherals, can pass 'false'.
Returns
One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure).

◆ loadBMP()

ImageReturnCode Adafruit_ImageReader::loadBMP ( const char *  filename,
Adafruit_Image img 
)

Loads BMP image file from SD card into RAM (as one of the GFX canvas object types) for use with the bitmap-drawing functions. Not practical for most AVR microcontrollers, but some of the more capable 32-bit micros can afford some RAM for this.

Parameters
filenameName of BMP image file to load.
imgAdafruit_Image object, contents will be initialized, allocated and loaded on success (else cleared).
Returns
One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure).

◆ bmpDimensions()

ImageReturnCode Adafruit_ImageReader::bmpDimensions ( const char *  filename,
int32_t *  width,
int32_t *  height 
)

Query pixel dimensions of BMP image file on SD card.

Parameters
filenameName of BMP image file to query.
widthPointer to int32_t; image width in pixels, returned.
heightPointer to int32_t; image height in pixels, returned.
Returns
One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure).

◆ printStatus()

void Adafruit_ImageReader::printStatus ( ImageReturnCode  stat,
Stream &  stream = Serial 
)

Print human-readable status message corresponding to an ImageReturnCode type.

Parameters
statNumeric ImageReturnCode value.
streamOutput stream (Serial default if unspecified).
Returns
None (void).

◆ coreBMP()

ImageReturnCode Adafruit_ImageReader::coreBMP ( const char *  filename,
Adafruit_SPITFT *  tft,
uint16_t *  dest,
int16_t  x,
int16_t  y,
Adafruit_Image img,
boolean  transact 
)
protected

BMP-reading function common both to the draw function (to TFT) and load function (to canvas object in RAM). BMP code has been centralized here so if/when more BMP format variants are added in the future, it doesn't need to be implemented, debugged and kept in sync in two places.

Parameters
filenameName of BMP image file to load.
tftPointer to TFT object, if loading to screen, else NULL.
destWorking buffer for loading 16-bit TFT pixel data, if loading to screen, else NULL.
xHorizontal offset in pixels (if loading to screen).
yVertical offset in pixels (if loading to screen).
imgPointer to Adafruit_Image object, if loading to RAM (or NULL if loading to screen).
transactUse SPI transactions; 'true' is needed only if loading to screen and it's on the same SPI bus as the SD card. Other situations can use 'false'.
Returns
One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure).

◆ readLE16()

uint16_t Adafruit_ImageReader::readLE16 ( void  )
protected

Reads a little-endian 16-bit unsigned value from currently- open File, converting if necessary to the microcontroller's native endianism. (BMP files use little-endian values.)

Returns
Unsigned 16-bit value, native endianism.

◆ readLE32()

uint32_t Adafruit_ImageReader::readLE32 ( void  )
protected

Reads a little-endian 32-bit unsigned value from currently- open File, converting if necessary to the microcontroller's native endianism. (BMP files use little-endian values.)

Returns
Unsigned 32-bit value, native endianism.

The documentation for this class was generated from the following files: