Shows how to use a display and the onboard SD Card. Requires a display module with an adapter

Dependencies:   DmTftLibrary SDFileSystem mbed

Revision:
3:030be860c83d
Parent:
0:ee27d4c12433
Child:
5:ed6a302e0917
--- a/DmDrawBmpBase.cpp	Mon Jul 07 11:09:03 2014 +0000
+++ b/DmDrawBmpBase.cpp	Mon Jul 07 11:43:35 2014 +0000
@@ -30,25 +30,29 @@
 
 bool DmDrawBmpBase::draw888Bitmap(DmTftBase& tft, uint16_t x, uint16_t y) {
   const uint8_t bytesPerPixel = 3;
-  uint32_t filePosition = _bitmapOffset; 
+  uint32_t _bitmapOffset; 
   uint8_t red, green, blue;
   uint16_t row, column;
   uint16_t bytesPerRow = (bytesPerPixel*_width + 3) & ~3;
   uint8_t buff[20*bytesPerPixel];
   uint8_t buffPos = sizeof(buff);
-  
+  uint16_t clipX = _width;
+  uint16_t clipY = _height;
+
+  //make sure image fits
+  if ((x + clipX) > tft.width()) {
+    clipX = tft.width() - x;
+  }
+  if ((y + clipY) > tft.height()) {
+    clipY = tft.height() - y;
+  }
+    
   tft.select();
-  tft.setAddress(x, y, x+_width-1, y+_height-1);
+  tft.setAddress(x, y, x+clipX-1, y+clipY-1);
   tft.unSelect();
   
   for(row=0; row<_height; row++) {
-    _readPos = filePosition = _bitmapOffset + (_height - 1 -row ) * bytesPerRow;
-//    if(_imageFile.position() != filePosition) {
-//      tft.unSelect();
-//      _imageFile.seek(filePosition);
-//      tft.select();
-//      buffPos = sizeof(buff);
-//    }
+    _readPos = _bitmapOffset + (_height - 1 -row ) * bytesPerRow;
     buffPos = sizeof(buff);
     
     for(column=0; column<_width; column++) { 
@@ -56,7 +60,6 @@
         tft.unSelect();
         _readFunc(_userData, buff, _readPos, sizeof(buff));
         _readPos += sizeof(buff);
-//        _imageFile.read(buff, sizeof(buff));
         tft.select();
         buffPos = 0;
       }
@@ -65,7 +68,9 @@
       green = buff[buffPos++];
       red = buff[buffPos++];
 
-      tft.sendData(Convert888to565(red, green, blue));
+      if (row < clipY && column < clipX) {
+        tft.sendData(Convert888to565(red, green, blue));
+      }
     }
   }
   tft.unSelect();
@@ -81,12 +86,22 @@
   uint16_t height = -_height; // Change if load bottom-top
   uint16_t pixel;
   uint16_t row, column;
+  uint16_t clipX = _width;
+  uint16_t clipY = height;
   _readPos = _bitmapOffset;
   
   //_imageFile.seek(_bitmapOffset);
     
+  //make sure image fits
+  if ((x + clipX) > tft.width()) {
+    clipX = tft.width() - x;
+  }
+  if ((y + clipY) > tft.height()) {
+    clipY = tft.height() - y;
+  }
+    
   tft.select();
-  tft.setAddress(x, y, x+_width-1, y+height-1);
+  tft.setAddress(x, y, x+clipX-1, y+clipY-1);
   tft.unSelect();
 
   for(row=0; row<height; row++) {
@@ -101,7 +116,9 @@
       }
       pixel = buff[buffPos++] & 0xFF;
       pixel |= buff[buffPos++] << 8;
-      tft.sendData(pixel);
+      if (row < clipY && column < clipX) {
+        tft.sendData(pixel);
+      }
     }
 
     if ( paddingSize > 0 ) { // Check if there is padding in the file