Library for interfacing to Nokia 5110 LCD display with Image Loader (as found on the SparkFun website).

Committer:
rottenegg
Date:
Wed Apr 17 05:11:04 2019 +0000
Revision:
50:c293d29e035a
Parent:
42:596c207519de
Upgraded Bitmap to Have an Image loader

Who changed what in which revision?

UserRevisionLine numberNew contents of line
valavanisalex 38:92fad278c2c3 1 #include "Bitmap.h"
valavanisalex 38:92fad278c2c3 2
rottenegg 50:c293d29e035a 3 void Bitmap::renderBMP(const char *path, N5110 &lcd, unsigned int const x, unsigned int const y) {
rottenegg 50:c293d29e035a 4 FILE *bmp = fopen(path,"r");
rottenegg 50:c293d29e035a 5 if (bmp == NULL) {
rottenegg 50:c293d29e035a 6 std::cerr << "File Not Found" << std::endl;
valavanisalex 38:92fad278c2c3 7 }
rottenegg 50:c293d29e035a 8 unsigned char *buffer = (unsigned char*)std::malloc(4 * sizeof(unsigned char));
rottenegg 50:c293d29e035a 9 unsigned long offbits;
rottenegg 50:c293d29e035a 10 unsigned long height;
rottenegg 50:c293d29e035a 11 unsigned long width;
rottenegg 50:c293d29e035a 12 std::fseek(bmp,10,SEEK_SET);
rottenegg 50:c293d29e035a 13 std::fread(&offbits,4,1,bmp);
rottenegg 50:c293d29e035a 14 std::fseek(bmp,18,SEEK_SET);
rottenegg 50:c293d29e035a 15 std::fread(&width,4,1,bmp);
rottenegg 50:c293d29e035a 16 std::fseek(bmp,22,SEEK_SET);
rottenegg 50:c293d29e035a 17 std::fread(&height,4,1,bmp);
rottenegg 50:c293d29e035a 18 unsigned short int dcount = (width / 32) + 1;
rottenegg 50:c293d29e035a 19 fseek(bmp,offbits,SEEK_SET);
rottenegg 50:c293d29e035a 20 std::bitset<32> bits;
rottenegg 50:c293d29e035a 21 int row = 0;
rottenegg 50:c293d29e035a 22 offbits = 0;
rottenegg 50:c293d29e035a 23 int colomn = 0;
rottenegg 50:c293d29e035a 24 bool state;
rottenegg 50:c293d29e035a 25 //NEW ENGINENE CORE
rottenegg 50:c293d29e035a 26 for (unsigned int dwcount = 1; dwcount < ((dcount*height) + 1); dwcount++) {
rottenegg 50:c293d29e035a 27 std::fread(buffer,1,4,bmp);
rottenegg 50:c293d29e035a 28 //endian swap
rottenegg 50:c293d29e035a 29 bits = buffer[0];
rottenegg 50:c293d29e035a 30 bits = (bits << 8) | (std::bitset<32>)buffer[1];
rottenegg 50:c293d29e035a 31 bits = (bits << 8) | (std::bitset<32>)buffer[2];
rottenegg 50:c293d29e035a 32 bits = (bits << 8) | (std::bitset<32>)buffer[3];
rottenegg 50:c293d29e035a 33 //bit loop adaptive
rottenegg 50:c293d29e035a 34 if (dwcount % dcount == 0) {
rottenegg 50:c293d29e035a 35 for (offbits = 0; offbits < (width % 32); offbits++){
rottenegg 50:c293d29e035a 36 if (bits[31 - offbits] == 1) {
rottenegg 50:c293d29e035a 37 state = false;
rottenegg 50:c293d29e035a 38 } else {
rottenegg 50:c293d29e035a 39 state = true;
rottenegg 50:c293d29e035a 40 }
rottenegg 50:c293d29e035a 41 lcd.setPixel((colomn + x) ,(row + y),state);
rottenegg 50:c293d29e035a 42 colomn++;
rottenegg 50:c293d29e035a 43 }
rottenegg 50:c293d29e035a 44 row++;
rottenegg 50:c293d29e035a 45 colomn = 0;
rottenegg 50:c293d29e035a 46 } else {
rottenegg 50:c293d29e035a 47 for (offbits = 0; offbits < 32; offbits++) {
rottenegg 50:c293d29e035a 48 if (bits[31 - offbits] == 1) {
rottenegg 50:c293d29e035a 49 state = false;
rottenegg 50:c293d29e035a 50 } else {
rottenegg 50:c293d29e035a 51 state = true;
rottenegg 50:c293d29e035a 52 }
rottenegg 50:c293d29e035a 53 lcd.setPixel((colomn + x) ,(row + y),state);
rottenegg 50:c293d29e035a 54 colomn++;
rottenegg 50:c293d29e035a 55 }
valavanisalex 40:c9262294f2e1 56 }
valavanisalex 40:c9262294f2e1 57 }
rottenegg 50:c293d29e035a 58 std::fclose(bmp);
rottenegg 50:c293d29e035a 59 }