SlideShare a Scribd company logo
#include <SD.h>
#include "TFTLCD.h"
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
//Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt
conflict with the library)
// our TFT wiring
TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// the file itself
File bmpFile;
// information we extract about the bitmap file
int bmpWidth, bmpHeight;
uint8_t bmpDepth, bmpImageoffset;
//int loads = 0;
#define ROTATION 3
#define BUFFPIXEL 60
#define BYTES_PER_PIXEL 3
uint8_t picBuffer[BYTES_PER_PIXEL * BUFFPIXEL]; // 3 * pixels to buffer
int bufferIndex = BYTES_PER_PIXEL * BUFFPIXEL;
void setup()
{
Serial.begin(9600);
tft.reset();
tft.initDisplay();
tft.setRotation(ROTATION);
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
tft.setRotation(ROTATION);
if (!SD.begin(10)) {
Serial.println("failed!");
while(1);
}
Serial.println("SD OK!");
}
/*
Callback for displayBitmap function to load data into buffer
*/
unsigned int loadBitmapData(void *data)
{
File *sdFile = (File *) data;
int bytesRead = sdFile->read(picBuffer, 2 * BUFFPIXEL);
return bytesRead / 2;
}
/*
Loads a raw 16-bit bitmap with the format
4-byte width
4-byte height
raw 16-bit pixel data in R5G6B5 format
*/
void displayBitmap(const char *name, int x, int y)
{
File sdFile = SD.open(name);
if( ! sdFile )
{
Serial.println("Error opening file.");
return;
}
uint32_t width = read32( sdFile );
uint32_t height = read32( sdFile );
Serial.print("Width: ");
Serial.println(width, DEC);
uint32_t time = millis();
uint16_t bx, ex, by, ey;
tft.setViewport(x, y, x + width - 1, y + height - 1);
tft.goTo(x, y);
int bytesRead = ( loadBitmapData(&sdFile) );
tft.bulkWrite( (uint16_t *) picBuffer, bytesRead, loadBitmapData, &sdFile);
// tft.setViewport(bx, ex, by, ey);
tft.setDefaultViewport();
Serial.print(millis() - time, DEC);
Serial.println(" ms");
sdFile.close();
}
/*
Slightly modified routine for drawing bitmaps (From original samples).
Watch out, as this one uses some global variables
*/
void bmpdraw(const char *name, int x, int y) {
File sdFile = SD.open(name);
if( ! sdFile )
{
Serial.println("Error opening file.");
return;
}
if( ! bmpReadHeader(sdFile) )
{
Serial.println("Error reading header.");
return;
}
sdFile.seek(bmpImageoffset);
uint32_t diskTime = 0;
uint32_t tempTime;
uint32_t time = millis();
uint16_t p;
uint8_t g, b;
int i, j;
Serial.print("rotation = "); Serial.println(tft.getRotation(), DEC);
tft.goTo(0,0);
for (i=0; i< bmpHeight; i++) {
// bitmaps are stored with the BOTTOM line first so we have to move 'up'
tft.goTo(0, bmpHeight - i - 1);
for (j=0; j<bmpWidth; j++) {
// read more pixels
if (bufferIndex >= BYTES_PER_PIXEL * BUFFPIXEL) {
tempTime = millis();
sdFile.read(picBuffer, BYTES_PER_PIXEL * BUFFPIXEL);
diskTime += millis() - tempTime;
bufferIndex= 0;
}
p = tft.Color565( picBuffer[bufferIndex+2], picBuffer[bufferIndex+1],
picBuffer[bufferIndex]);
bufferIndex += 3;
tft.writeData(p);
}
}
uint32_t totalTime = millis();
Serial.print("Total time: ");
Serial.println(totalTime - time, DEC);
Serial.print("Disk Time: ");
Serial.println(diskTime, DEC);
sdFile.close();
}
/*
From example code. Reads bitmap header. Uses global variables.
*/
boolean bmpReadHeader(File f) {
// read header
uint32_t tmp;
if (read16(f) != 0x4D42) {
// magic bytes missing
return false;
}
// read file size
tmp = read32(f);
Serial.print("size 0x"); Serial.println(tmp, HEX);
// read and ignore creator bytes
read32(f);
bmpImageoffset = read32(f);
Serial.print("offset "); Serial.println(bmpImageoffset, DEC);
// read DIB header
tmp = read32(f);
Serial.print("header size "); Serial.println(tmp, DEC);
bmpWidth = read32(f);
bmpHeight = read32(f);
if (read16(f) != 1)
return false;
bmpDepth = read16(f);
Serial.print("bitdepth "); Serial.println(bmpDepth, DEC);
Serial.print("compression "); Serial.println(tmp, DEC);
return true;
}
/*********************************************/
// These read data from the SD card file and convert them to big endian
// (the data is stored in little endian format!)
// LITTLE ENDIAN!
uint16_t read16(File &f) {
uint16_t d;
uint8_t b;
b = f.read();
d = f.read();
d <<= 8;
d |= b;
return d;
}
// LITTLE ENDIAN!
uint32_t read32(File &f) {
uint32_t d;
uint16_t b;
b = read16(f);
d = read16(f);
d <<= 16;
d |= b;
return d;
}
void loop()
{
// 16-bit top-down display
displayBitmap("out.lcd", 0, 0);
delay(3000);
tft.fillScreen(BLACK);
delay(1000);
// 24-bit bottom-up display
bmpdraw("sunset.bmp", 0, 0);
delay(3000);
tft.fillScreen(WHITE);
delay(1000);
// 16-bit top-down display
displayBitmap("sunset.lcd", 0, 0);
delay(3000);
}
return d;
}
void loop()
{
// 16-bit top-down display
displayBitmap("out.lcd", 0, 0);
delay(3000);
tft.fillScreen(BLACK);
delay(1000);
// 24-bit bottom-up display
bmpdraw("sunset.bmp", 0, 0);
delay(3000);
tft.fillScreen(WHITE);
delay(1000);
// 16-bit top-down display
displayBitmap("sunset.lcd", 0, 0);
delay(3000);
}

More Related Content

Similar to My bitmap

Arduino
ArduinoArduino
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
footstatus
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
Teddy Hsiung
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
anithareadymade
 
Roll your own toy unix clone os
Roll your own toy unix clone osRoll your own toy unix clone os
Roll your own toy unix clone os
eramax
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
Miller Lee
 
Uclinux
UclinuxUclinux
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
SANTIAGO PABLO ALBERTO
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
Ahmed Mekkawy
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
Syed Ghufran Hassan
 
Sysprog 12
Sysprog 12Sysprog 12
Sysprog 12
Ahmed Mekkawy
 
Sysprog 12
Sysprog 12Sysprog 12
Sysprog 12
Ahmed Mekkawy
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
Jens Siebert
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
PVS-Studio
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
Andrey Karpov
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
hairilfaiz86
 
Vcs24
Vcs24Vcs24
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
艾鍗科技
 
CUDA Deep Dive
CUDA Deep DiveCUDA Deep Dive
CUDA Deep Dive
krasul
 
Mango64 u boot 업데이트 하기
Mango64 u boot 업데이트 하기Mango64 u boot 업데이트 하기
Mango64 u boot 업데이트 하기
종인 전
 

Similar to My bitmap (20)

Arduino
ArduinoArduino
Arduino
 
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdfHow do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
How do I draw the Labview code for pneumatic cylinder(air pistion). .pdf
 
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
ExperiencesSharingOnEmbeddedSystemDevelopment_20160321
 
Following are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdfFollowing are the changes mentioned in bold in order to obtain the r.pdf
Following are the changes mentioned in bold in order to obtain the r.pdf
 
Roll your own toy unix clone os
Roll your own toy unix clone osRoll your own toy unix clone os
Roll your own toy unix clone os
 
GPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMPGPU Programming on CPU - Using C++AMP
GPU Programming on CPU - Using C++AMP
 
Uclinux
UclinuxUclinux
Uclinux
 
Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
codings related to avr micro controller
codings related to avr micro controllercodings related to avr micro controller
codings related to avr micro controller
 
Sysprog 12
Sysprog 12Sysprog 12
Sysprog 12
 
Sysprog 12
Sysprog 12Sysprog 12
Sysprog 12
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Vcs24
Vcs24Vcs24
Vcs24
 
Linux Serial Driver
Linux Serial DriverLinux Serial Driver
Linux Serial Driver
 
CUDA Deep Dive
CUDA Deep DiveCUDA Deep Dive
CUDA Deep Dive
 
Mango64 u boot 업데이트 하기
Mango64 u boot 업데이트 하기Mango64 u boot 업데이트 하기
Mango64 u boot 업데이트 하기
 

Recently uploaded

Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
q30122000
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
PreethaV16
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
nikshimanasa
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
pvpriya2
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Massimo Talia
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
paraasingh12 #V08
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Digital Image Processing Unit -2 Notes complete
Digital Image Processing Unit -2 Notes completeDigital Image Processing Unit -2 Notes complete
Digital Image Processing Unit -2 Notes complete
shubhamsaraswat8740
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
MuhammadJazib15
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
PriyankaKilaniya
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
mahaffeycheryld
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
Seetal Daas
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
DharmaBanothu
 

Recently uploaded (20)

Height and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdfHeight and depth gauge linear metrology.pdf
Height and depth gauge linear metrology.pdf
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
FULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back EndFULL STACK PROGRAMMING - Both Front End and Back End
FULL STACK PROGRAMMING - Both Front End and Back End
 
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptxEV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
EV BMS WITH CHARGE MONITOR AND FIRE DETECTION.pptx
 
Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...Determination of Equivalent Circuit parameters and performance characteristic...
Determination of Equivalent Circuit parameters and performance characteristic...
 
Levelised Cost of Hydrogen (LCOH) Calculator Manual
Levelised Cost of Hydrogen  (LCOH) Calculator ManualLevelised Cost of Hydrogen  (LCOH) Calculator Manual
Levelised Cost of Hydrogen (LCOH) Calculator Manual
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls ChennaiCall Girls Chennai +91-8824825030 Vip Call Girls Chennai
Call Girls Chennai +91-8824825030 Vip Call Girls Chennai
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Digital Image Processing Unit -2 Notes complete
Digital Image Processing Unit -2 Notes completeDigital Image Processing Unit -2 Notes complete
Digital Image Processing Unit -2 Notes complete
 
Impartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 StandardImpartiality as per ISO /IEC 17025:2017 Standard
Impartiality as per ISO /IEC 17025:2017 Standard
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
Prediction of Electrical Energy Efficiency Using Information on Consumer's Ac...
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
AI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdfAI in customer support Use cases solutions development and implementation.pdf
AI in customer support Use cases solutions development and implementation.pdf
 
Assistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdfAssistant Engineer (Chemical) Interview Questions.pdf
Assistant Engineer (Chemical) Interview Questions.pdf
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
A high-Speed Communication System is based on the Design of a Bi-NoC Router, ...
 

My bitmap

  • 1. #include <SD.h> #include "TFTLCD.h" #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 //Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller: #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) // our TFT wiring TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // the file itself File bmpFile; // information we extract about the bitmap file int bmpWidth, bmpHeight; uint8_t bmpDepth, bmpImageoffset; //int loads = 0; #define ROTATION 3 #define BUFFPIXEL 60 #define BYTES_PER_PIXEL 3 uint8_t picBuffer[BYTES_PER_PIXEL * BUFFPIXEL]; // 3 * pixels to buffer int bufferIndex = BYTES_PER_PIXEL * BUFFPIXEL; void setup() { Serial.begin(9600); tft.reset(); tft.initDisplay(); tft.setRotation(ROTATION); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); tft.setRotation(ROTATION); if (!SD.begin(10)) { Serial.println("failed!"); while(1); } Serial.println("SD OK!"); }
  • 2. /* Callback for displayBitmap function to load data into buffer */ unsigned int loadBitmapData(void *data) { File *sdFile = (File *) data; int bytesRead = sdFile->read(picBuffer, 2 * BUFFPIXEL); return bytesRead / 2; } /* Loads a raw 16-bit bitmap with the format 4-byte width 4-byte height raw 16-bit pixel data in R5G6B5 format */ void displayBitmap(const char *name, int x, int y) { File sdFile = SD.open(name); if( ! sdFile ) { Serial.println("Error opening file."); return; } uint32_t width = read32( sdFile ); uint32_t height = read32( sdFile ); Serial.print("Width: "); Serial.println(width, DEC); uint32_t time = millis(); uint16_t bx, ex, by, ey; tft.setViewport(x, y, x + width - 1, y + height - 1); tft.goTo(x, y); int bytesRead = ( loadBitmapData(&sdFile) ); tft.bulkWrite( (uint16_t *) picBuffer, bytesRead, loadBitmapData, &sdFile); // tft.setViewport(bx, ex, by, ey); tft.setDefaultViewport(); Serial.print(millis() - time, DEC); Serial.println(" ms"); sdFile.close(); } /* Slightly modified routine for drawing bitmaps (From original samples). Watch out, as this one uses some global variables */ void bmpdraw(const char *name, int x, int y) { File sdFile = SD.open(name);
  • 3. if( ! sdFile ) { Serial.println("Error opening file."); return; } if( ! bmpReadHeader(sdFile) ) { Serial.println("Error reading header."); return; } sdFile.seek(bmpImageoffset); uint32_t diskTime = 0; uint32_t tempTime; uint32_t time = millis(); uint16_t p; uint8_t g, b; int i, j; Serial.print("rotation = "); Serial.println(tft.getRotation(), DEC); tft.goTo(0,0); for (i=0; i< bmpHeight; i++) { // bitmaps are stored with the BOTTOM line first so we have to move 'up' tft.goTo(0, bmpHeight - i - 1); for (j=0; j<bmpWidth; j++) { // read more pixels if (bufferIndex >= BYTES_PER_PIXEL * BUFFPIXEL) { tempTime = millis(); sdFile.read(picBuffer, BYTES_PER_PIXEL * BUFFPIXEL); diskTime += millis() - tempTime; bufferIndex= 0; } p = tft.Color565( picBuffer[bufferIndex+2], picBuffer[bufferIndex+1], picBuffer[bufferIndex]); bufferIndex += 3; tft.writeData(p); } } uint32_t totalTime = millis(); Serial.print("Total time: "); Serial.println(totalTime - time, DEC); Serial.print("Disk Time: "); Serial.println(diskTime, DEC); sdFile.close(); } /* From example code. Reads bitmap header. Uses global variables. */ boolean bmpReadHeader(File f) { // read header uint32_t tmp;
  • 4. if (read16(f) != 0x4D42) { // magic bytes missing return false; } // read file size tmp = read32(f); Serial.print("size 0x"); Serial.println(tmp, HEX); // read and ignore creator bytes read32(f); bmpImageoffset = read32(f); Serial.print("offset "); Serial.println(bmpImageoffset, DEC); // read DIB header tmp = read32(f); Serial.print("header size "); Serial.println(tmp, DEC); bmpWidth = read32(f); bmpHeight = read32(f); if (read16(f) != 1) return false; bmpDepth = read16(f); Serial.print("bitdepth "); Serial.println(bmpDepth, DEC); Serial.print("compression "); Serial.println(tmp, DEC); return true; } /*********************************************/ // These read data from the SD card file and convert them to big endian // (the data is stored in little endian format!) // LITTLE ENDIAN! uint16_t read16(File &f) { uint16_t d; uint8_t b; b = f.read(); d = f.read(); d <<= 8; d |= b; return d; } // LITTLE ENDIAN! uint32_t read32(File &f) { uint32_t d; uint16_t b; b = read16(f); d = read16(f); d <<= 16; d |= b;
  • 5. return d; } void loop() { // 16-bit top-down display displayBitmap("out.lcd", 0, 0); delay(3000); tft.fillScreen(BLACK); delay(1000); // 24-bit bottom-up display bmpdraw("sunset.bmp", 0, 0); delay(3000); tft.fillScreen(WHITE); delay(1000); // 16-bit top-down display displayBitmap("sunset.lcd", 0, 0); delay(3000); }
  • 6. return d; } void loop() { // 16-bit top-down display displayBitmap("out.lcd", 0, 0); delay(3000); tft.fillScreen(BLACK); delay(1000); // 24-bit bottom-up display bmpdraw("sunset.bmp", 0, 0); delay(3000); tft.fillScreen(WHITE); delay(1000); // 16-bit top-down display displayBitmap("sunset.lcd", 0, 0); delay(3000); }