aboutsummaryrefslogtreecommitdiff
path: root/libraries/TFT/utility/PImage.h
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
committerCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
commit177ad96f866714a4962be57f69cd3d5a6334cde1 (patch)
tree1072239986340d6a239adac924eddf2e1d1ca566 /libraries/TFT/utility/PImage.h
parent6cff36ac5e85c74bcb45cc53491ad69d64520b36 (diff)
parentd90fcca5839d13d57ed527d4009b78d22dafbde7 (diff)
Merge branch 'merge-1.0.5' into ide-1.5.x-discovery
Diffstat (limited to 'libraries/TFT/utility/PImage.h')
-rw-r--r--libraries/TFT/utility/PImage.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/libraries/TFT/utility/PImage.h b/libraries/TFT/utility/PImage.h
new file mode 100644
index 0000000..d37bf71
--- /dev/null
+++ b/libraries/TFT/utility/PImage.h
@@ -0,0 +1,64 @@
+
+
+#ifndef _PIMAGE_H
+#define _PIMAGE_H
+
+class Adafruit_GFX;
+
+#if defined(__SD_H__) // Arduino SD library
+
+
+/// This class mimics Processing's PImage, but with fewer
+/// capabilities. It allows an image stored in the SD card to be
+/// drawn to the display.
+/// @author Enrico Gueli <enrico.gueli@gmail.com>
+class PImage {
+public:
+ PImage() :
+ _valid(false),
+ _bmpWidth(0),
+ _bmpHeight(0) { }
+
+ void draw(Adafruit_GFX & glcd, int16_t x, int16_t y);
+
+ static PImage loadImage(const char * fileName);
+
+
+ bool isValid() { return _valid; }
+
+ int width() { return _bmpWidth; }
+ int height() { return _bmpHeight; }
+
+private:
+ friend class Adafruit_GFX;
+
+ File _bmpFile;
+ int _bmpWidth, _bmpHeight; // W+H in pixels
+ uint8_t _bmpDepth; // Bit depth (currently must be 24)
+ uint32_t _bmpImageoffset; // Start of image data in file
+ uint32_t _rowSize; // Not always = bmpWidth; may have padding
+ bool _flip;
+
+ bool _valid;
+
+ PImage(File & bmpFile, int bmpWidth, int bmpHeight, uint8_t bmpDepth, uint32_t bmpImageoffset, uint32_t rowSize, bool flip) :
+ _bmpFile(bmpFile),
+ _bmpWidth(bmpWidth),
+ _bmpHeight(bmpHeight),
+ _bmpDepth(bmpDepth),
+ _bmpImageoffset(bmpImageoffset),
+ _rowSize(rowSize),
+ _flip(flip),
+ _valid(true) // since Adafruit_GFX is friend, we could just let it write the variables and save some CPU cycles
+ { }
+
+ static uint16_t read16(File f);
+ static uint32_t read32(File f);
+
+ // TODO close the file in ~PImage and PImage(const PImage&)
+
+};
+
+#endif
+
+#endif // _PIMAGE_H