From 04b3d3f7b750a778bb0b51f9b14d89ab68ade1b6 Mon Sep 17 00:00:00 2001 From: Liz Date: Fri, 1 Aug 2025 09:27:48 -0400 Subject: [PATCH] clang again --- Adafruit_ImageReader.cpp | 69 +++++++++++++++++++++------------------- Adafruit_ImageReader.h | 52 ++++++++++++++++-------------- 2 files changed, 65 insertions(+), 56 deletions(-) diff --git a/Adafruit_ImageReader.cpp b/Adafruit_ImageReader.cpp index a746245..6fba295 100644 --- a/Adafruit_ImageReader.cpp +++ b/Adafruit_ImageReader.cpp @@ -73,7 +73,9 @@ Adafruit_Image::Adafruit_Image(void) @brief Destructor. @return None (void). */ -Adafruit_Image::~Adafruit_Image(void) { dealloc(); } +Adafruit_Image::~Adafruit_Image(void) { + dealloc(); +} /*! @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 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_1) - return (void *)canvas.canvas1; + return (void*)canvas.canvas1; else if (format == IMAGE_8) - return (void *)canvas.canvas8; + return (void*)canvas.canvas8; else if (format == IMAGE_16) - return (void *)canvas.canvas16; + return (void*)canvas.canvas16; } return NULL; } @@ -180,7 +182,7 @@ void *Adafruit_Image::getCanvas(void) const { Vertical offset in pixels; top edge = 0, positive = down. @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) { uint16_t foreground, background; 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 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. @@ -246,8 +250,8 @@ Adafruit_ImageReader::~Adafruit_ImageReader(void) { @return One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure). */ -ImageReturnCode Adafruit_ImageReader::drawBMP(const char *filename, - Adafruit_SPITFT &tft, int16_t x, +ImageReturnCode Adafruit_ImageReader::drawBMP(const char* filename, + Adafruit_SPITFT& tft, int16_t x, int16_t y, boolean transact) { uint16_t tftbuf[BUFPIXELS]; // Temp space for buffering TFT data // 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 completion, other values on failure). */ -ImageReturnCode Adafruit_ImageReader::loadBMP(const char *filename, - Adafruit_Image &img) { +ImageReturnCode Adafruit_ImageReader::loadBMP(const char* filename, + Adafruit_Image& img) { // Call core BMP-reading function. TFT and working buffer are NULL // (unused and allocated in function, respectively), X & Y position are // 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). */ ImageReturnCode Adafruit_ImageReader::coreBMP( - const char *filename, // SD file to load - Adafruit_SPITFT *tft, // Pointer to TFT object, or NULL if to image - uint16_t *dest, // TFT working buffer, or NULL if to canvas + const char* filename, // SD file to load + Adafruit_SPITFT* tft, // Pointer to TFT object, or NULL if to image + uint16_t* dest, // TFT working buffer, or NULL if to canvas int16_t x, // Position if loading to TFT (else ignored) 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 ImageReturnCode status = IMAGE_ERR_FORMAT; // IMAGE_SUCCESS on valid file @@ -324,7 +328,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( uint8_t depth; // BMP bit depth uint32_t compression = 0; // BMP compression mode 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 uint8_t sdbuf[3 * BUFPIXELS]; // BMP read buf (R+G+B/pixel) #if ((3 * BUFPIXELS) <= 255) @@ -333,7 +337,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( uint16_t srcidx = sizeof sdbuf; #endif 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 uint32_t bmpPos = 0; // Next pixel position in file int loadWidth, loadHeight, // Region being loaded (clipped) @@ -450,7 +454,7 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( } if ((depth >= 16) || - (quantized = (uint16_t *)malloc(colors * sizeof(uint16_t)))) { + (quantized = (uint16_t*)malloc(colors * sizeof(uint16_t)))) { if (depth < 16) { // Load and quantize color table for (uint16_t c = 0; c < colors; c++) { @@ -529,8 +533,8 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( } } else { // Canvas is simpler, file.read(sdbuf, sizeof sdbuf); // just load sdbuf - } // (destidx never resets) - srcidx = 0; // Reset bmp buf index + } // (destidx never resets) + srcidx = 0; // Reset bmp buf index } if (depth == 24) { // 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 (destidx) { // Any remainders? // See notes above re: DMA @@ -584,11 +588,11 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( img->palette = quantized; // Keep palette with img } } // end depth>24 or quantized malloc OK - } // end top/left clip - } // end malloc check - } // end depth check - } // end planes/compression check - } // end signature + } // end top/left clip + } // end malloc check + } // end depth check + } // end planes/compression check + } // end signature file.close(); return status; @@ -605,10 +609,9 @@ ImageReturnCode Adafruit_ImageReader::coreBMP( @return One of the ImageReturnCode values (IMAGE_SUCCESS on successful completion, other values on failure). */ -ImageReturnCode Adafruit_ImageReader::bmpDimensions(const char *filename, - int32_t *width, - int32_t *height) { - +ImageReturnCode Adafruit_ImageReader::bmpDimensions(const char* filename, + int32_t* width, + int32_t* height) { ImageReturnCode status = IMAGE_ERR_FILE_NOT_FOUND; // Guilty until innocent 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. */ uint16_t Adafruit_ImageReader::readLE16(void) { -#if !defined(ESP32) && !defined(ESP8266) && \ +#if !defined(ESP32) && !defined(ESP8266) && \ (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) // Read directly into result -- BMP data and variable both little-endian. uint16_t result; @@ -662,7 +665,7 @@ uint16_t Adafruit_ImageReader::readLE16(void) { @return Unsigned 32-bit value, native endianism. */ uint32_t Adafruit_ImageReader::readLE32(void) { -#if !defined(ESP32) && !defined(ESP8266) && \ +#if !defined(ESP32) && !defined(ESP8266) && \ (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) // Read directly into result -- BMP data and variable both little-endian. uint32_t result; @@ -684,7 +687,7 @@ uint32_t Adafruit_ImageReader::readLE32(void) { Output stream (Serial default if unspecified). @return None (void). */ -void Adafruit_ImageReader::printStatus(ImageReturnCode stat, Stream &stream) { +void Adafruit_ImageReader::printStatus(ImageReturnCode stat, Stream& stream) { if (stat == IMAGE_SUCCESS) stream.println(F("Success!")); else if (stat == IMAGE_ERR_FILE_NOT_FOUND) diff --git a/Adafruit_ImageReader.h b/Adafruit_ImageReader.h index ab5e199..bf90e85 100644 --- a/Adafruit_ImageReader.h +++ b/Adafruit_ImageReader.h @@ -39,42 +39,48 @@ enum ImageFormat { ImageReader.loadBMP() and Image.draw(), not ImageReader.drawBMP(). */ class Adafruit_Image { -public: + public: Adafruit_Image(void); ~Adafruit_Image(void); int16_t width(void) const; // Return image width 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. @return An ImageFormat type: IMAGE_1 for a GFXcanvas1, IMAGE_8 for a GFXcanvas8, IMAGE_16 for a GFXcanvas16, IMAGE_NONE if no canvas currently allocated. */ - ImageFormat getFormat(void) const { return (ImageFormat)format; } - void *getCanvas(void) const; + ImageFormat getFormat(void) const { + return (ImageFormat)format; + } + void* getCanvas(void) const; /*! @brief Return pointer to color palette. @return Pointer to an array of 16-bit color values, or NULL if no 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. @return GFXcanvas1* pointer (1-bit RAM-resident image) if present, NULL otherwise. */ - GFXcanvas1 *getMask(void) const { return mask; }; + GFXcanvas1* getMask(void) const { + return mask; + }; -protected: + protected: // MOST OF THESE ARE NOT SUPPORTED YET -- WIP union { // Single pointer, only one variant is used: - GFXcanvas1 *canvas1; ///< Canvas object if 1bpp format - GFXcanvas8 *canvas8; ///< Canvas object if 8bpp format - GFXcanvas16 *canvas16; ///< Canvas object if 16bpp + GFXcanvas1* canvas1; ///< Canvas object if 1bpp format + GFXcanvas8* canvas8; ///< Canvas object if 8bpp format + GFXcanvas16* canvas16; ///< Canvas object if 16bpp } canvas; ///< Union of different GFXcanvas types - GFXcanvas1 *mask; ///< 1bpp image mask (or NULL) - uint16_t *palette; ///< Color palette for 8bpp image (or NULL) + GFXcanvas1* mask; ///< 1bpp image mask (or NULL) + uint16_t* palette; ///< Color palette for 8bpp image (or NULL) uint8_t format; ///< Canvas bundle type in use void dealloc(void); ///< Free/deinitialize variables friend class Adafruit_ImageReader; ///< Loading occurs here @@ -93,21 +99,21 @@ protected: for use. */ class Adafruit_ImageReader { -public: - Adafruit_ImageReader(FatVolume &fs); + public: + Adafruit_ImageReader(FatVolume& fs); ~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); - ImageReturnCode loadBMP(const char *filename, Adafruit_Image &img); - ImageReturnCode bmpDimensions(const char *filename, int32_t *w, int32_t *h); - void printStatus(ImageReturnCode stat, Stream &stream = Serial); + ImageReturnCode loadBMP(const char* filename, Adafruit_Image& img); + ImageReturnCode bmpDimensions(const char* filename, int32_t* w, int32_t* h); + void printStatus(ImageReturnCode stat, Stream& stream = Serial); -protected: - FatVolume *filesys; ///< FAT FileSystem Object + protected: + FatVolume* filesys; ///< FAT FileSystem Object File32 file; ///< Current Open file - ImageReturnCode coreBMP(const char *filename, Adafruit_SPITFT *tft, - uint16_t *dest, int16_t x, int16_t y, - Adafruit_Image *img, boolean transact); + ImageReturnCode coreBMP(const char* filename, Adafruit_SPITFT* tft, + uint16_t* dest, int16_t x, int16_t y, + Adafruit_Image* img, boolean transact); uint16_t readLE16(void); uint32_t readLE32(void); };