Dependencies:   mbed FATFileSystem

Revision:
21:f3b0ce18b44f
Parent:
18:14e5391beccf
Child:
26:716bcd47f3ca
--- a/N5110_Modded/Bitmap.cpp	Wed May 08 15:48:44 2019 +0000
+++ b/N5110_Modded/Bitmap.cpp	Thu May 09 06:22:53 2019 +0000
@@ -1,4 +1,5 @@
 #include "Bitmap.h"
+Serial d(USBTX,USBRX);
 
 //Total New Process time = 0.04 Seconds (still a bit long)
 //Image data is Stored in DWORDS (32-bits) not Bytes (8-bits)
@@ -14,8 +15,11 @@
 
 void Bitmap::renderBMP(const char *path, unsigned int const x, unsigned int const y) {
     FILE *bmp = fopen(path,"r");
+    if (bmp == NULL) {
+        d.printf("fail");
+    }
     unsigned char *buffer = (unsigned char*)std::malloc(4 * sizeof(unsigned char));
-    this->readDIB(bmp); //Reading DIB header
+    this->readDIB(bmp);  //Reading DIB header
     unsigned short int dcount = (width / 32) + 1;   //Counting DWORDS required per Row of Image
     fseek(bmp,offbits,SEEK_SET);
     std::bitset<32> bits;
@@ -31,26 +35,16 @@
         }
     }
     std::fclose(bmp);
+    free(buffer);
 }
 
 void Bitmap::readDIB(FILE *bmp) {
     std::fseek(bmp,10,SEEK_SET);
-    std::fread(&offbits,4,1,bmp);
+    std::fread(&offbits,4,1,bmp);  //Bytes to skip to get to data block
     std::fseek(bmp,18,SEEK_SET);
-    std::fread(&width,4,1,bmp);
+    std::fread(&width,4,1,bmp);    //Width of Image
     std::fseek(bmp,22,SEEK_SET);
-    std::fread(&height,4,1,bmp);
-}
-
-void Bitmap::renderDWORD(std::bitset<32> bits, unsigned int const x, unsigned int const y) {
-    bool state;
-    if (bits[31 - offbits] == 1) {
-        state = false;
-    } else {
-        state = true;
-    }
-    this->setPixel((colomn + x) ,(row + y),state);
-    colomn++;
+    std::fread(&height,4,1,bmp);   //Height of image
 }
 
 void Bitmap::swapEndian(FILE *bmp, unsigned char *buffer, std::bitset<32> &bits) {
@@ -77,4 +71,16 @@
     for (offbits = 0; offbits < 32; offbits++) {
         this->renderDWORD(bits,x,y);
     }
+}
+
+//Aiding Funtion for fullloop and halfloop
+void Bitmap::renderDWORD(std::bitset<32> bits, unsigned int const x, unsigned int const y) {
+    bool state;
+    if (bits[31 - offbits] == 1) {
+        state = false;
+    } else {
+        state = true;
+    }
+    this->setPixel((colomn + x) ,(row + y),state);
+    colomn++;
 }
\ No newline at end of file