Loading from External SD card

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

  • Loading from External SD card

    Hi ,

    I'm using GUI_DrawBitmap API in my project currently. Bitmaps are created by using BitmapConverter. Now i've to move images to SD card. How i can use GUI_DrawBitmap in this case ? I did not find any API which i can use at the place of GUI_DrawBitmap.

    Please guide!
  • Hi,

    the only bitmaps converted with the BitmapConverter are .dta files. Those ae almost the same as the c-files, just in a binary form.

    Take a look at functions like GUI_DrawStreamedBitmapExAuto() and at chapter 8.1.5 'Drawing streamed bitmaps'. To use them you have to set a get data function which reads the data from the .dta file.

    Besides of the .dta files you can also draw BMP, JPEG, or PNG files. But those have the disadvantage that they need to be decoded which is slower than using the .dta files.

    Here is a short example on how to draw a .dta file. This is for windows filesystem but it should be easy to adapt for any other filesystem.

    Of course you need a .dta file and set the proper path in MainTask.

    C Source Code

    1. #include <windows.h>
    2. #include "GUI.h"
    3. /*********************************************************************
    4. *
    5. * _GetData
    6. */
    7. static int _GetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off) {
    8. HANDLE * phFile;
    9. DWORD NumBytesRead;
    10. U8 * pData;
    11. pData = (U8 *)*ppData;
    12. phFile = (HANDLE *)p;
    13. //
    14. // Set file pointer to the required position
    15. //
    16. SetFilePointer(*phFile, Off, 0, FILE_BEGIN);
    17. //
    18. // Read data into buffer
    19. //
    20. ReadFile(*phFile, pData, NumBytesReq, &NumBytesRead, NULL);
    21. //
    22. // Return number of available bytes
    23. //
    24. return NumBytesRead;
    25. }
    26. /*********************************************************************
    27. *
    28. * Public code
    29. *
    30. **********************************************************************
    31. */
    32. /*********************************************************************
    33. *
    34. * MainTask
    35. */
    36. void MainTask(void) {
    37. HANDLE hFile;
    38. char acPath[] = "Path to .dta file";
    39. GUI_Init();
    40. hFile = CreateFile(acPath, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    41. GUI_DrawStreamedBitmapExAuto(_GetData, (void *)&hFile, 0, 0);
    42. CloseHandle(hFile);
    43. while (1) {
    44. GUI_Delay(100);
    45. }
    46. }
    Display All


    Regards,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • (Solved) Loading from External SD card

    Hello Sven,

    Thank you so much for guiding. I have read this chapter. The code snippet provided by you is working great. Thanks for that. It solved my confusions.
    Only 1 problem i found that while saving a .dta file if i choose "True Color with alpha , r/b swapped, alpha inverted" then i'm not able to see the image on display. What could be the problem ?

    I was using this option as i have understanding that this option will take less time with GUI_DrawBitmap ();

    Can you please tell me which option out of these will be the best if i want to draw image with "good quality" in "less time" with GUI_DrawStreamedBitmapExAuto ?
  • Hi,

    It depends on how your GUI library is compiled. In GUIConf.h you can set a define (GUI_USE_ARGB) to tell emWin the order of the color channels of a 32bit color.

    If the define is set to one the color format looks like this:

    ARGB - Where A (alpha) is inverted (0x00 fully transparent - 0xff is opaque) and R (red) and B (blue) swapped. The color conversio to used is GUICC_M8888I (in LCDConf.c)

    If the define is not present or set to 0:

    ABGR - Where A is not inverted (0xff fully transparent - 0x00 is opaque) and R and B are not swapped. Here the proper color conversion GUICC_8888.

    Unfortunately it is not possible to change this setting with a precompiled library.

    To get the best performance (and a visible image) you have to choose the proper mehtod while saving.

    Take a look into your GUIConf.h if the define is set. If that is the case choose "True Color with alpha , r/b swapped, alpha inverted" while saving.
    If it is not set, choose
    "True Color with alpha".

    The best format to save a bitmap is always if the bitmap uses the same color conversion as the hardware.

    Some examples:

    GUICC_M8888I -
    "True Color with alpha , r/b swapped, alpha inverted"
    GUICC_8888
    - "True Color with alpha"
    GUICC_M565 - "High color (565), red and blue swapped"
    GUICC_565 - "High color (565)"

    Regads,
    Sven
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.