Читать BMP с SD-карты быстрее
Я работаю над Cy8CKIT -050 Cypress Kit, флеш-чипом W25Q128FV,SD-картой и TFT-дисплеем https://www.buydisplay.com/default/lcd-5-ssd1963-tft-module-touch-screen-display-800x480-mcu-arduino
у меня есть интерфейс, флэш-чип с использованием SPIFFS и SD-карты с использованием FATFS с Cy8CKIT - 050
но скорость загрузки изображения BMP с SD-карты очень медленная, сейчас размер изображения составляет 150*90, и он занимает 635 мс
как я могу улучшить это? Также я хочу записать образ BMP с SD-карты на Flash-чип и загрузить изображение с Flash-чипа, чтобы показать, как я могу это сделать
я прилагаю код для справки
`void DrawImage(UG_S16 x1, UG_S16 y1, UG_S16 x2, UG_S16 y2, const TCHAR* имя файла) {
FATFS fatFs;
FIL fileO;
uint16_t buffimg,buffimg1;
uint16_t buffer[1];
UINT br,br1;
FRESULT pt;
char read[50];
uint32_t bmpWidth = 0;
uint32_t bmpHeight = 0;
uint16_t bmpImageoffset;
uint16_t rowSize;
uint8_t rdBuf[60];
uint8_t header_buff[60];
uint16_t position = 0;
uint8_t numberOfPixels = 0;
uint32_t commpression = 0;
uint32_t imageSize = 0;
unsigned int byte_read;
uint16_t bmpSig;
uint8_t row_buff[rowSize]; // only read 1 row at a time
uint8_t cc,R,G,B;
uint16_t pixel;
uint16_t color;
uint32 i,j, count=0;
uint8_t pColorData[DISPLAY_WIDTH*3];
uint8_t pColorData_flash[DISPLAY_WIDTH*3];
uint8_t pColorData_flash1[DISPLAY_WIDTH*3];
uint32_t pos;
int row =0 ;
if((x1 < 0) ||(x1 >= DISPLAY_WIDTH) || (y1 < 0) || (y1 >= DISPLAY_HEIGHT)) return;
if((x2 < 0) ||(x2 >= DISPLAY_WIDTH) || (y2 < 0) || (y2 >= DISPLAY_HEIGHT)) return;
/* Mount drive */
pt = f_mount(&fatFs, "", 1);
if(pt != FR_OK) return;
/* open file */
pt = f_open(&fileO, namefile, FA_READ);
if(pt != FR_OK) return;
/* read bmp header */
pt = f_read(&fileO, header_buff, sizeof header_buff, &byte_read);
if(pt != FR_OK){
return;
}
//my_spiffs_mount();
//spiffs_file fd = SPIFFS_open(&fs, "bmpFile", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
//if (SPIFFS_write(&fs, fd,header_buff, sizeof(header_buff)) < 0) sprintf(bufferOut,"wr errno %i\n", SPIFFS_errno(&fs));
//SPIFFS_close(&fs, fd);
//UG_PutString(1,200,bufferOut);
//fd = SPIFFS_open(&fs, "bmpFile", SPIFFS_RDWR, 0);
//if (SPIFFS_read(&fs, fd, rdBuf, sizeof(rdBuf)) < 0) sprintf(bufferOut,"rd errno %i\n", SPIFFS_errno(&fs));
//SPIFFS_close(&fs, fd);
//UG_PutString(1,220,bufferOut);
bmpSig = (header_buff[1] << 8) | header_buff [0];
sprintf(bufferOut,"Signature:\t0x%X\n", bmpSig);
UG_PutString(1,160,bufferOut);
if(bmpSig != 0x4D42){
UG_PutString(1,180,"not a bmp");
return; // not a bmp
}
bmpImageoffset = header_buff [7] * 256 + header_buff [6];
bmpHeight = (header_buff [25] << 24) | (header_buff [24] << 16) | (header_buff [23] << 8) | header_buff [22];
bmpWidth = (header_buff [21] << 24) | (header_buff [20] << 16) | (header_buff [19] << 8) | header_buff [18];
position = header_buff [10]; // starting point in file
numberOfPixels = header_buff [29] * 256 + header_buff [28];
commpression = (header_buff [30] << 24) | (header_buff [31] << 16) | (header_buff [32] << 8) | header_buff [33];
imageSize = (header_buff [37] << 24) | (header_buff [36] << 16) | (header_buff [35] << 8) | header_buff [34];
rowSize = ((numberOfPixels * bmpWidth + 31) /32 ) * 4;
sprintf(read ,"Offset:\t%d\n", bmpImageoffset);
UG_PutString(1,1,read);
sprintf(read ,"Height:\t%u\n", bmpHeight);
UG_PutString(1,20,read);
sprintf(read ,"Width:\t\t%u\n", bmpWidth);
UG_PutString(1,40,read);
sprintf(read ,"Row Size:\t%d\n", rowSize);
UG_PutString(1,60,read);
sprintf(read ,"Start Index:\t%d\n", position);
UG_PutString(1,80,read);
sprintf(read ,"# of Pixels:\t%d\n", numberOfPixels);
UG_PutString(1,100,read);
sprintf(read ,"Compression:\t%u\n", commpression);
UG_PutString(1,120,read);
sprintf(read ,"Image Size:\t%u\n", imageSize);
UG_PutString(1,140,read);
Display_WindowSet (x1, x2, y1, y2);
/ * Запись в LCD-GRAM * / Display_WriteCommand (0x2c);
/ * получить текущий счетчик миллисекунд * / unsigned long nCurrentMillis = nmillis;
for(i=0;i<bmpHeight; i++)
{
for(j=0; j<rowSize; j++)
{
count++;
LED3_Write(1);
f_read(&fileO,pColorData+j,1,&byte_read);
//fd = SPIFFS_open(&fs, "bmpFile", SPIFFS_RDWR , 0);
//if (SPIFFS_write(&fs, fd,pColorData+j, 1) < 0) sprintf(bufferOut,"wr errno %i\n", SPIFFS_errno(&fs));
//SPIFFS_close(&fs, fd);
//fd = SPIFFS_open(&fs, "bmpFile", SPIFFS_RDWR, 0);
//if (SPIFFS_read(&fs, fd, pColorData_flash+j, 1) < 0) sprintf(bufferOut,"rd errno %i\n", SPIFFS_errno(&fs));
//SPIFFS_close(&fs, fd);
//sprintf(bufferOut," row %lu",j);
//UG_PutString(1,360,bufferOut);
//CyDelay(1);
LED3_Write(0);
}
for(j=0;j<bmpWidth;j++)
{
//fd = SPIFFS_open(&fs, "bmpFile", SPIFFS_RDWR, 0);
//if (SPIFFS_read(&fs, fd, pColorData_flash,rowSize) < 0) sprintf(bufferOut,"rd errno %i\n", SPIFFS_errno(&fs));
//SPIFFS_close(&fs, fd);
uint32_t k = j*3;
R = pColorData[k+2];
G = pColorData[k+1];
B = pColorData[k];
color = color565(R,G,B);
Display_WriteData (color);
//sprintf(bufferOut," width %lu",j);
//UG_PutString(1,380,bufferOut);
}
//sprintf(bufferOut," height %lu",i);
//UG_PutString(1,400,bufferOut);
}
unsigned long nTime = nmillis-nCurrentMillis;
sprintf(bufferOut,"time taken for load : %lu ms",nTime);
UG_PutString(1,320,bufferOut);
sprintf(bufferOut,"%lu",count);
UG_PutString(1,340,bufferOut);
f_close(&fileO);
} `