[136] | 1 |
|
---|
| 2 |
|
---|
| 3 | #ifndef _PIMAGE_H
|
---|
| 4 | #define _PIMAGE_H
|
---|
| 5 |
|
---|
| 6 | class Adafruit_GFX;
|
---|
| 7 |
|
---|
| 8 | #if defined(__SD_H__) // Arduino SD library
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | /// This class mimics Processing's PImage, but with fewer
|
---|
| 12 | /// capabilities. It allows an image stored in the SD card to be
|
---|
| 13 | /// drawn to the display.
|
---|
| 14 | /// @author Enrico Gueli <enrico.gueli@gmail.com>
|
---|
| 15 | class PImage {
|
---|
| 16 | public:
|
---|
| 17 | PImage() :
|
---|
| 18 | _valid(false),
|
---|
| 19 | _bmpWidth(0),
|
---|
| 20 | _bmpHeight(0) { }
|
---|
| 21 |
|
---|
| 22 | void draw(Adafruit_GFX & glcd, int16_t x, int16_t y);
|
---|
| 23 |
|
---|
| 24 | static PImage loadImage(const char * fileName);
|
---|
| 25 |
|
---|
| 26 | void close() { _bmpFile.close(); }
|
---|
| 27 |
|
---|
| 28 | bool isValid() { return _valid; }
|
---|
| 29 |
|
---|
| 30 | int width() { return _bmpWidth; }
|
---|
| 31 | int height() { return _bmpHeight; }
|
---|
| 32 |
|
---|
| 33 | private:
|
---|
| 34 | friend class Adafruit_GFX;
|
---|
| 35 |
|
---|
| 36 | File _bmpFile;
|
---|
| 37 | int _bmpWidth, _bmpHeight; // W+H in pixels
|
---|
| 38 | uint8_t _bmpDepth; // Bit depth (currently must be 24)
|
---|
| 39 | uint32_t _bmpImageoffset; // Start of image data in file
|
---|
| 40 | uint32_t _rowSize; // Not always = bmpWidth; may have padding
|
---|
| 41 | bool _flip;
|
---|
| 42 |
|
---|
| 43 | bool _valid;
|
---|
| 44 |
|
---|
| 45 | PImage(File & bmpFile, int bmpWidth, int bmpHeight, uint8_t bmpDepth, uint32_t bmpImageoffset, uint32_t rowSize, bool flip) :
|
---|
| 46 | _bmpFile(bmpFile),
|
---|
| 47 | _bmpWidth(bmpWidth),
|
---|
| 48 | _bmpHeight(bmpHeight),
|
---|
| 49 | _bmpDepth(bmpDepth),
|
---|
| 50 | _bmpImageoffset(bmpImageoffset),
|
---|
| 51 | _rowSize(rowSize),
|
---|
| 52 | _flip(flip),
|
---|
| 53 | _valid(true) // since Adafruit_GFX is friend, we could just let it write the variables and save some CPU cycles
|
---|
| 54 | { }
|
---|
| 55 |
|
---|
| 56 | static uint16_t read16(File f);
|
---|
| 57 | static uint32_t read32(File f);
|
---|
| 58 |
|
---|
| 59 | // TODO close the file in ~PImage and PImage(const PImage&)
|
---|
| 60 |
|
---|
| 61 | };
|
---|
| 62 |
|
---|
| 63 | #endif
|
---|
| 64 |
|
---|
| 65 | #endif // _PIMAGE_H
|
---|