clang again
This commit is contained in:
parent
94bbaf973f
commit
04b3d3f7b7
2 changed files with 65 additions and 56 deletions
|
|
@ -73,7 +73,9 @@ Adafruit_Image::Adafruit_Image(void)
|
||||||
@brief Destructor.
|
@brief Destructor.
|
||||||
@return None (void).
|
@return None (void).
|
||||||
*/
|
*/
|
||||||
Adafruit_Image::~Adafruit_Image(void) { dealloc(); }
|
Adafruit_Image::~Adafruit_Image(void) {
|
||||||
|
dealloc();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief Deallocates memory associated with Adafruit_Image object
|
@brief Deallocates memory associated with Adafruit_Image object
|
||||||
|
|
@ -156,14 +158,14 @@ int16_t Adafruit_Image::height(void) const {
|
||||||
via canvas->getBuffer()) to move data in or out. Potential
|
via canvas->getBuffer()) to move data in or out. Potential
|
||||||
for a lot of mayhem here if used wrong.
|
for a lot of mayhem here if used wrong.
|
||||||
*/
|
*/
|
||||||
void *Adafruit_Image::getCanvas(void) const {
|
void* Adafruit_Image::getCanvas(void) const {
|
||||||
if (format != IMAGE_NONE) { // Image allocated?
|
if (format != IMAGE_NONE) { // Image allocated?
|
||||||
if (format == IMAGE_1)
|
if (format == IMAGE_1)
|
||||||
return (void *)canvas.canvas1;
|
return (void*)canvas.canvas1;
|
||||||
else if (format == IMAGE_8)
|
else if (format == IMAGE_8)
|
||||||
return (void *)canvas.canvas8;
|
return (void*)canvas.canvas8;
|
||||||
else if (format == IMAGE_16)
|
else if (format == IMAGE_16)
|
||||||
return (void *)canvas.canvas16;
|
return (void*)canvas.canvas16;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +182,7 @@ void *Adafruit_Image::getCanvas(void) const {
|
||||||
Vertical offset in pixels; top edge = 0, positive = down.
|
Vertical offset in pixels; top edge = 0, positive = down.
|
||||||
@return None (void).
|
@return None (void).
|
||||||
*/
|
*/
|
||||||
void Adafruit_Image::draw(Adafruit_SPITFT &tft, int16_t x, int16_t y) {
|
void Adafruit_Image::draw(Adafruit_SPITFT& tft, int16_t x, int16_t y) {
|
||||||
if (format == IMAGE_1) {
|
if (format == IMAGE_1) {
|
||||||
uint16_t foreground, background;
|
uint16_t foreground, background;
|
||||||
if (palette) {
|
if (palette) {
|
||||||
|
|
@ -214,7 +216,9 @@ void Adafruit_Image::draw(Adafruit_SPITFT &tft, int16_t x, int16_t y) {
|
||||||
often be in pre-setup() declaration, but DOES need initializing
|
often be in pre-setup() declaration, but DOES need initializing
|
||||||
before any of the image loading or size functions are called!
|
before any of the image loading or size functions are called!
|
||||||
*/
|
*/
|
||||||
Adafruit_ImageReader::Adafruit_ImageReader(FatVolume &fs) { filesys = &fs; }
|
Adafruit_ImageReader::Adafruit_ImageReader(FatVolume& fs) {
|
||||||
|
filesys = &fs;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief Destructor.
|
@brief Destructor.
|
||||||
|
|
@ -246,8 +250,8 @@ Adafruit_ImageReader::~Adafruit_ImageReader(void) {
|
||||||
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
||||||
completion, other values on failure).
|
completion, other values on failure).
|
||||||
*/
|
*/
|
||||||
ImageReturnCode Adafruit_ImageReader::drawBMP(const char *filename,
|
ImageReturnCode Adafruit_ImageReader::drawBMP(const char* filename,
|
||||||
Adafruit_SPITFT &tft, int16_t x,
|
Adafruit_SPITFT& tft, int16_t x,
|
||||||
int16_t y, boolean transact) {
|
int16_t y, boolean transact) {
|
||||||
uint16_t tftbuf[BUFPIXELS]; // Temp space for buffering TFT data
|
uint16_t tftbuf[BUFPIXELS]; // Temp space for buffering TFT data
|
||||||
// Call core BMP-reading function, passing address to TFT object,
|
// Call core BMP-reading function, passing address to TFT object,
|
||||||
|
|
@ -270,8 +274,8 @@ ImageReturnCode Adafruit_ImageReader::drawBMP(const char *filename,
|
||||||
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
||||||
completion, other values on failure).
|
completion, other values on failure).
|
||||||
*/
|
*/
|
||||||
ImageReturnCode Adafruit_ImageReader::loadBMP(const char *filename,
|
ImageReturnCode Adafruit_ImageReader::loadBMP(const char* filename,
|
||||||
Adafruit_Image &img) {
|
Adafruit_Image& img) {
|
||||||
// Call core BMP-reading function. TFT and working buffer are NULL
|
// Call core BMP-reading function. TFT and working buffer are NULL
|
||||||
// (unused and allocated in function, respectively), X & Y position are
|
// (unused and allocated in function, respectively), X & Y position are
|
||||||
// always 0 because full image is loaded (RAM permitting). Adafruit_Image
|
// always 0 because full image is loaded (RAM permitting). Adafruit_Image
|
||||||
|
|
@ -308,12 +312,12 @@ ImageReturnCode Adafruit_ImageReader::loadBMP(const char *filename,
|
||||||
completion, other values on failure).
|
completion, other values on failure).
|
||||||
*/
|
*/
|
||||||
ImageReturnCode Adafruit_ImageReader::coreBMP(
|
ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
const char *filename, // SD file to load
|
const char* filename, // SD file to load
|
||||||
Adafruit_SPITFT *tft, // Pointer to TFT object, or NULL if to image
|
Adafruit_SPITFT* tft, // Pointer to TFT object, or NULL if to image
|
||||||
uint16_t *dest, // TFT working buffer, or NULL if to canvas
|
uint16_t* dest, // TFT working buffer, or NULL if to canvas
|
||||||
int16_t x, // Position if loading to TFT (else ignored)
|
int16_t x, // Position if loading to TFT (else ignored)
|
||||||
int16_t y,
|
int16_t y,
|
||||||
Adafruit_Image *img, // NULL if load-to-screen
|
Adafruit_Image* img, // NULL if load-to-screen
|
||||||
boolean transact) { // SD & TFT sharing bus, use transactions
|
boolean transact) { // SD & TFT sharing bus, use transactions
|
||||||
|
|
||||||
ImageReturnCode status = IMAGE_ERR_FORMAT; // IMAGE_SUCCESS on valid file
|
ImageReturnCode status = IMAGE_ERR_FORMAT; // IMAGE_SUCCESS on valid file
|
||||||
|
|
@ -324,7 +328,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
uint8_t depth; // BMP bit depth
|
uint8_t depth; // BMP bit depth
|
||||||
uint32_t compression = 0; // BMP compression mode
|
uint32_t compression = 0; // BMP compression mode
|
||||||
uint32_t colors = 0; // Number of colors in palette
|
uint32_t colors = 0; // Number of colors in palette
|
||||||
uint16_t *quantized = NULL; // 16-bit 5/6/5 color palette
|
uint16_t* quantized = NULL; // 16-bit 5/6/5 color palette
|
||||||
uint32_t rowSize; // >bmpWidth if scanline padding
|
uint32_t rowSize; // >bmpWidth if scanline padding
|
||||||
uint8_t sdbuf[3 * BUFPIXELS]; // BMP read buf (R+G+B/pixel)
|
uint8_t sdbuf[3 * BUFPIXELS]; // BMP read buf (R+G+B/pixel)
|
||||||
#if ((3 * BUFPIXELS) <= 255)
|
#if ((3 * BUFPIXELS) <= 255)
|
||||||
|
|
@ -333,7 +337,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
uint16_t srcidx = sizeof sdbuf;
|
uint16_t srcidx = sizeof sdbuf;
|
||||||
#endif
|
#endif
|
||||||
uint32_t destidx = 0;
|
uint32_t destidx = 0;
|
||||||
uint8_t *dest1 = NULL; // Dest ptr for 1-bit BMPs to img
|
uint8_t* dest1 = NULL; // Dest ptr for 1-bit BMPs to img
|
||||||
boolean flip = true; // BMP is stored bottom-to-top
|
boolean flip = true; // BMP is stored bottom-to-top
|
||||||
uint32_t bmpPos = 0; // Next pixel position in file
|
uint32_t bmpPos = 0; // Next pixel position in file
|
||||||
int loadWidth, loadHeight, // Region being loaded (clipped)
|
int loadWidth, loadHeight, // Region being loaded (clipped)
|
||||||
|
|
@ -450,7 +454,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((depth >= 16) ||
|
if ((depth >= 16) ||
|
||||||
(quantized = (uint16_t *)malloc(colors * sizeof(uint16_t)))) {
|
(quantized = (uint16_t*)malloc(colors * sizeof(uint16_t)))) {
|
||||||
if (depth < 16) {
|
if (depth < 16) {
|
||||||
// Load and quantize color table
|
// Load and quantize color table
|
||||||
for (uint16_t c = 0; c < colors; c++) {
|
for (uint16_t c = 0; c < colors; c++) {
|
||||||
|
|
@ -529,8 +533,8 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
}
|
}
|
||||||
} else { // Canvas is simpler,
|
} else { // Canvas is simpler,
|
||||||
file.read(sdbuf, sizeof sdbuf); // just load sdbuf
|
file.read(sdbuf, sizeof sdbuf); // just load sdbuf
|
||||||
} // (destidx never resets)
|
} // (destidx never resets)
|
||||||
srcidx = 0; // Reset bmp buf index
|
srcidx = 0; // Reset bmp buf index
|
||||||
}
|
}
|
||||||
if (depth == 24) {
|
if (depth == 24) {
|
||||||
// Convert each pixel from BMP to 565 format, save in dest
|
// Convert each pixel from BMP to 565 format, save in dest
|
||||||
|
|
@ -564,7 +568,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end pixel loop
|
} // end pixel loop
|
||||||
if (tft) { // Drawing to TFT?
|
if (tft) { // Drawing to TFT?
|
||||||
if (destidx) { // Any remainders?
|
if (destidx) { // Any remainders?
|
||||||
// See notes above re: DMA
|
// See notes above re: DMA
|
||||||
|
|
@ -584,11 +588,11 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
img->palette = quantized; // Keep palette with img
|
img->palette = quantized; // Keep palette with img
|
||||||
}
|
}
|
||||||
} // end depth>24 or quantized malloc OK
|
} // end depth>24 or quantized malloc OK
|
||||||
} // end top/left clip
|
} // end top/left clip
|
||||||
} // end malloc check
|
} // end malloc check
|
||||||
} // end depth check
|
} // end depth check
|
||||||
} // end planes/compression check
|
} // end planes/compression check
|
||||||
} // end signature
|
} // end signature
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
return status;
|
return status;
|
||||||
|
|
@ -605,10 +609,9 @@ ImageReturnCode Adafruit_ImageReader::coreBMP(
|
||||||
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
@return One of the ImageReturnCode values (IMAGE_SUCCESS on successful
|
||||||
completion, other values on failure).
|
completion, other values on failure).
|
||||||
*/
|
*/
|
||||||
ImageReturnCode Adafruit_ImageReader::bmpDimensions(const char *filename,
|
ImageReturnCode Adafruit_ImageReader::bmpDimensions(const char* filename,
|
||||||
int32_t *width,
|
int32_t* width,
|
||||||
int32_t *height) {
|
int32_t* height) {
|
||||||
|
|
||||||
ImageReturnCode status = IMAGE_ERR_FILE_NOT_FOUND; // Guilty until innocent
|
ImageReturnCode status = IMAGE_ERR_FILE_NOT_FOUND; // Guilty until innocent
|
||||||
|
|
||||||
if ((file = filesys->open(filename, FILE_READ))) { // Open requested file
|
if ((file = filesys->open(filename, FILE_READ))) { // Open requested file
|
||||||
|
|
@ -643,7 +646,7 @@ ImageReturnCode Adafruit_ImageReader::bmpDimensions(const char *filename,
|
||||||
@return Unsigned 16-bit value, native endianism.
|
@return Unsigned 16-bit value, native endianism.
|
||||||
*/
|
*/
|
||||||
uint16_t Adafruit_ImageReader::readLE16(void) {
|
uint16_t Adafruit_ImageReader::readLE16(void) {
|
||||||
#if !defined(ESP32) && !defined(ESP8266) && \
|
#if !defined(ESP32) && !defined(ESP8266) && \
|
||||||
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||||
// Read directly into result -- BMP data and variable both little-endian.
|
// Read directly into result -- BMP data and variable both little-endian.
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
|
|
@ -662,7 +665,7 @@ uint16_t Adafruit_ImageReader::readLE16(void) {
|
||||||
@return Unsigned 32-bit value, native endianism.
|
@return Unsigned 32-bit value, native endianism.
|
||||||
*/
|
*/
|
||||||
uint32_t Adafruit_ImageReader::readLE32(void) {
|
uint32_t Adafruit_ImageReader::readLE32(void) {
|
||||||
#if !defined(ESP32) && !defined(ESP8266) && \
|
#if !defined(ESP32) && !defined(ESP8266) && \
|
||||||
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||||
// Read directly into result -- BMP data and variable both little-endian.
|
// Read directly into result -- BMP data and variable both little-endian.
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
|
|
@ -684,7 +687,7 @@ uint32_t Adafruit_ImageReader::readLE32(void) {
|
||||||
Output stream (Serial default if unspecified).
|
Output stream (Serial default if unspecified).
|
||||||
@return None (void).
|
@return None (void).
|
||||||
*/
|
*/
|
||||||
void Adafruit_ImageReader::printStatus(ImageReturnCode stat, Stream &stream) {
|
void Adafruit_ImageReader::printStatus(ImageReturnCode stat, Stream& stream) {
|
||||||
if (stat == IMAGE_SUCCESS)
|
if (stat == IMAGE_SUCCESS)
|
||||||
stream.println(F("Success!"));
|
stream.println(F("Success!"));
|
||||||
else if (stat == IMAGE_ERR_FILE_NOT_FOUND)
|
else if (stat == IMAGE_ERR_FILE_NOT_FOUND)
|
||||||
|
|
|
||||||
|
|
@ -39,42 +39,48 @@ enum ImageFormat {
|
||||||
ImageReader.loadBMP() and Image.draw(), not ImageReader.drawBMP().
|
ImageReader.loadBMP() and Image.draw(), not ImageReader.drawBMP().
|
||||||
*/
|
*/
|
||||||
class Adafruit_Image {
|
class Adafruit_Image {
|
||||||
public:
|
public:
|
||||||
Adafruit_Image(void);
|
Adafruit_Image(void);
|
||||||
~Adafruit_Image(void);
|
~Adafruit_Image(void);
|
||||||
int16_t width(void) const; // Return image width in pixels
|
int16_t width(void) const; // Return image width in pixels
|
||||||
int16_t height(void) const; // Return image height in pixels
|
int16_t height(void) const; // Return image height in pixels
|
||||||
void draw(Adafruit_SPITFT &tft, int16_t x, int16_t y);
|
void draw(Adafruit_SPITFT& tft, int16_t x, int16_t y);
|
||||||
/*!
|
/*!
|
||||||
@brief Return canvas image format.
|
@brief Return canvas image format.
|
||||||
@return An ImageFormat type: IMAGE_1 for a GFXcanvas1, IMAGE_8 for
|
@return An ImageFormat type: IMAGE_1 for a GFXcanvas1, IMAGE_8 for
|
||||||
a GFXcanvas8, IMAGE_16 for a GFXcanvas16, IMAGE_NONE if no
|
a GFXcanvas8, IMAGE_16 for a GFXcanvas16, IMAGE_NONE if no
|
||||||
canvas currently allocated.
|
canvas currently allocated.
|
||||||
*/
|
*/
|
||||||
ImageFormat getFormat(void) const { return (ImageFormat)format; }
|
ImageFormat getFormat(void) const {
|
||||||
void *getCanvas(void) const;
|
return (ImageFormat)format;
|
||||||
|
}
|
||||||
|
void* getCanvas(void) const;
|
||||||
/*!
|
/*!
|
||||||
@brief Return pointer to color palette.
|
@brief Return pointer to color palette.
|
||||||
@return Pointer to an array of 16-bit color values, or NULL if no
|
@return Pointer to an array of 16-bit color values, or NULL if no
|
||||||
palette associated with image.
|
palette associated with image.
|
||||||
*/
|
*/
|
||||||
uint16_t *getPalette(void) const { return palette; }
|
uint16_t* getPalette(void) const {
|
||||||
|
return palette;
|
||||||
|
}
|
||||||
/*!
|
/*!
|
||||||
@brief Return pointer to 1bpp image mask canvas.
|
@brief Return pointer to 1bpp image mask canvas.
|
||||||
@return GFXcanvas1* pointer (1-bit RAM-resident image) if present,
|
@return GFXcanvas1* pointer (1-bit RAM-resident image) if present,
|
||||||
NULL otherwise.
|
NULL otherwise.
|
||||||
*/
|
*/
|
||||||
GFXcanvas1 *getMask(void) const { return mask; };
|
GFXcanvas1* getMask(void) const {
|
||||||
|
return mask;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// MOST OF THESE ARE NOT SUPPORTED YET -- WIP
|
// MOST OF THESE ARE NOT SUPPORTED YET -- WIP
|
||||||
union { // Single pointer, only one variant is used:
|
union { // Single pointer, only one variant is used:
|
||||||
GFXcanvas1 *canvas1; ///< Canvas object if 1bpp format
|
GFXcanvas1* canvas1; ///< Canvas object if 1bpp format
|
||||||
GFXcanvas8 *canvas8; ///< Canvas object if 8bpp format
|
GFXcanvas8* canvas8; ///< Canvas object if 8bpp format
|
||||||
GFXcanvas16 *canvas16; ///< Canvas object if 16bpp
|
GFXcanvas16* canvas16; ///< Canvas object if 16bpp
|
||||||
} canvas; ///< Union of different GFXcanvas types
|
} canvas; ///< Union of different GFXcanvas types
|
||||||
GFXcanvas1 *mask; ///< 1bpp image mask (or NULL)
|
GFXcanvas1* mask; ///< 1bpp image mask (or NULL)
|
||||||
uint16_t *palette; ///< Color palette for 8bpp image (or NULL)
|
uint16_t* palette; ///< Color palette for 8bpp image (or NULL)
|
||||||
uint8_t format; ///< Canvas bundle type in use
|
uint8_t format; ///< Canvas bundle type in use
|
||||||
void dealloc(void); ///< Free/deinitialize variables
|
void dealloc(void); ///< Free/deinitialize variables
|
||||||
friend class Adafruit_ImageReader; ///< Loading occurs here
|
friend class Adafruit_ImageReader; ///< Loading occurs here
|
||||||
|
|
@ -93,21 +99,21 @@ protected:
|
||||||
for use.
|
for use.
|
||||||
*/
|
*/
|
||||||
class Adafruit_ImageReader {
|
class Adafruit_ImageReader {
|
||||||
public:
|
public:
|
||||||
Adafruit_ImageReader(FatVolume &fs);
|
Adafruit_ImageReader(FatVolume& fs);
|
||||||
~Adafruit_ImageReader(void);
|
~Adafruit_ImageReader(void);
|
||||||
ImageReturnCode drawBMP(const char *filename, Adafruit_SPITFT &tft, int16_t x,
|
ImageReturnCode drawBMP(const char* filename, Adafruit_SPITFT& tft, int16_t x,
|
||||||
int16_t y, boolean transact = true);
|
int16_t y, boolean transact = true);
|
||||||
ImageReturnCode loadBMP(const char *filename, Adafruit_Image &img);
|
ImageReturnCode loadBMP(const char* filename, Adafruit_Image& img);
|
||||||
ImageReturnCode bmpDimensions(const char *filename, int32_t *w, int32_t *h);
|
ImageReturnCode bmpDimensions(const char* filename, int32_t* w, int32_t* h);
|
||||||
void printStatus(ImageReturnCode stat, Stream &stream = Serial);
|
void printStatus(ImageReturnCode stat, Stream& stream = Serial);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
FatVolume *filesys; ///< FAT FileSystem Object
|
FatVolume* filesys; ///< FAT FileSystem Object
|
||||||
File32 file; ///< Current Open file
|
File32 file; ///< Current Open file
|
||||||
ImageReturnCode coreBMP(const char *filename, Adafruit_SPITFT *tft,
|
ImageReturnCode coreBMP(const char* filename, Adafruit_SPITFT* tft,
|
||||||
uint16_t *dest, int16_t x, int16_t y,
|
uint16_t* dest, int16_t x, int16_t y,
|
||||||
Adafruit_Image *img, boolean transact);
|
Adafruit_Image* img, boolean transact);
|
||||||
uint16_t readLE16(void);
|
uint16_t readLE16(void);
|
||||||
uint32_t readLE32(void);
|
uint32_t readLE32(void);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue