Read BMP file from SD card, and display it

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • Read BMP file from SD card, and display it

    Hello!

    I have an SD-card attached to the SDIO pins of the STM43F4 board. I'm using this library for reading the files on the card which is working well. Now I want to use the GUI_BMP_DrawEx function to display the bmp. It is clear that I have to implement the _GetData function, but in the SD card library there is no function for eg. to set the file pointer. I have a ReadBlock function and that's all.
    Could you help me what kind of function would i need in the _GetData func?
    Or could you recommend an SD card reading library which is capable with Stemwin?

    Thanks for your furher answer!
  • This was solved with the current used setup.
    My getData function looks like this:

    C Source Code

    1. static int _GetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off)
    2. {
    3. DWORD NumBytesRead;
    4. FIL * phFile;
    5. FATFS_t readState = FATFS_DISK_FULL;
    6. phFile = (FIL *)p;
    7. static unsigned char _acBuffer[512];
    8. /*
    9. * Check buffer size
    10. */
    11. if (NumBytesReq > sizeof(_acBuffer))
    12. {
    13. NumBytesReq = sizeof(_acBuffer);
    14. }
    15. /*
    16. * Set file pointer to the required position
    17. */
    18. f_lseek(phFile, Off);
    19. /*
    20. * Read data into buffer
    21. */
    22. readState = UB_Fatfs_ReadBlock(phFile, _acBuffer, NumBytesReq, &NumBytesRead);
    23. /*
    24. * Set data pointer to the beginning of the buffer
    25. */
    26. *ppData = _acBuffer;
    27. /*
    28. * Return number of available bytes
    29. */
    30. return NumBytesRead;
    31. }
    Display All
  • Hello,

    Please note that emWin might stop displaying an image in case the return value does not equal NumBytesReq. I would recommend you to check the return value of the GUI_BMP_DrawEx() function.

    Also I would recommend you to use the DTA format for displaying images from external memory. DTA images can be created using the Bitmap Converter. Details can be found in the chapter "Bitmap Converter" in the emWin user manual.

    Best regards,
    Adrian
  • Adrian,


    could you please provide further information about the 'GetData' function and the situation when less than requested number of bytes are read. Mainly in respect to the comment "It is recommended to make sure that the ’GetData’-function is able to fetch at least one pixel line of the biggest image used by the application." and to the example provided by SEGGER with exactly the same condition:
    segger.com/cms/admin/uploads/u…src/2DGL_DrawJPEGScaled.c



    Thanks,
    Roman
  • Hello Roman,

    This depends on the function calling the GetData() function. Usually the current drawing process is aborted once the GetData() function does not return the requested number of bytes.

    Please find a detailed description of the GetData() function in the section 9.5 "Displaying bitmap files" -> "Gettind data with the ...Ex() functions" in the emWin user manual.

    Best regards,
    Adrian

    The post was edited 1 time, last by SEGGER - Adrian ().