Content originally posted in LPCWare by Ex-Zero on Sun Jan 01 06:16:19 MST 2012 Playing with SWIM I was trying to load a simple 480x272 Windows BMP file from SD. Wasn't too difficult (with EA SD sample) to load a 24bpp file to SDRAM. But SWIM is expecting 16bpp, so a conversion is needed. Picture data (width, height, picture data offset) are stored in BMP file and can be read there via offset as shown below:
<code> //DRAM 2M Words x 32 Bits x 4 Banks (256-MBIT) //at 0xA000 0000 - 0xA1FF FFFF range = 0x0200 0000 #define SDRAM_FRAME (SDRAM_BASE+0x10000) #define SDRAM_PIC (SDRAM_BASE+0x800000) #define SDRAM_RAW (SDRAM_BASE+0x1000000)
/*********************************************************************** * Function: draw_picture * * Purpose: read Windows BMP (24bpp GBR) from SD and draw it (480x272) * * Parameters: * win : Window identifier * filename : filename * * Outputs: None * * Returns: Nothing * * Notes: this function is reading original 24bpp GBR files (Windows) * **********************************************************************/ static int draw_picture(SWIM_WINDOW_T *win, const char * filename) { uint8_t *raw24_ptr;//pointer to reading 24bpp BGR COLOR_T *pic_ptr;//pointer to writing 16bpp RGB565 uint16_t p_col;//color bits uint32_t p_off;//data offset uint32_t p_w;//picture width uint32_t p_h;//picture height
//set picture pointer pointer pic_ptr = (COLOR_T *)SDRAM_PIC; raw24_ptr = (uint8_t *)SDRAM_RAW; swim_set_pen_color(win,BLACK); res = f_open (&file, filename, FA_READ); if (res) { sprintf(buff, "Failed to open ip.txt: %d \n", res); swim_put_text(win,(const char*)&buff); return 0; } //read image res = f_read (&file,(void*)raw24_ptr,Finfo.fsize, &numRead);/* Read data from a file */ if (res || numRead <= 0) { sprintf(buff, "Failed to read file: %d \n", res); swim_put_text(win,(const char*)&buff); return 0; } sprintf(buff, "Read %d bytes\n",numRead); // swim_put_text(win,(const char*)&buff); // swim_put_text(win,(const char*)"Closing file\n"); res = f_close (&file); if (res) { sprintf(buff, "Failed to close new.txt: %d \n", res); swim_put_text(win,(const char*)&buff); return 0; } raw24_ptr =(uint8_t *)SDRAM_RAW; p_off = *(uint16_t*)(raw24_ptr +0x0A); p_w = *(uint32_t*)(raw24_ptr +0x12); p_h = *(uint32_t*)(raw24_ptr +0x16); p_col = *(uint16_t*)(raw24_ptr +0x1C); sprintf(buff, "Offset %d\nWidth %d - Height %d - Color %d\n",p_off,p_w,p_h,p_col); // swim_put_text(win,(const char*)&buff); raw24_ptr += p_off;//set pointer to data offset