[SOLVED] Problem displaying 320*240 image from SD card

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

  • [SOLVED] Problem displaying 320*240 image from SD card

    Hi,

    I am working on displaying images from external memory. I am having problems displaying the complete picture. I can display image up until 170*240, after which when I try to expand x value I see white background and nothing else on the LCD.
    Please see the below code and image attached with this thread.
    Could someone tell me what I could be doing wrong?

    P.S: I have tried displaying images on buttons using the same functions and it works.


    C Source Code

    1. /*********************************************************************
    2. * *
    3. * SEGGER Microcontroller GmbH *
    4. * Solutions for real time microcontroller applications *
    5. * *
    6. **********************************************************************
    7. * *
    8. * C-file generated by: *
    9. * *
    10. * GUI_Builder for emWin version 5.48 *
    11. * Compiled Jun 13 2018, 10:51:02 *
    12. * (c) 2018 Segger Microcontroller GmbH *
    13. * *
    14. **********************************************************************
    15. * *
    16. * Internet: www.segger.com Support: support@segger.com *
    17. * *
    18. **********************************************************************
    19. */
    20. // USER START (Optionally insert additional includes)
    21. // USER END
    22. #include "project.h"
    23. #include <stddef.h>
    24. #include <string.h>
    25. #include "WIDGET.h"
    26. #include "WM.h"
    27. #include "BUTTON.h"
    28. #include "DIALOG.h"
    29. #include "FS.h"
    30. /*********************************************************************
    31. *
    32. * Defines
    33. *
    34. **********************************************************************
    35. */
    36. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    37. #define RECOMMENDED_MEMORY (1024L * 5)
    38. //extern void _OnPaint();
    39. //extern void DrawDTA();
    40. // USER START (Optionally insert additional defines)
    41. // USER END
    42. /*********************************************************************
    43. *
    44. * Static data
    45. *
    46. **********************************************************************
    47. */
    48. // USER START (Optionally insert additional static data)
    49. // USER END
    50. /*********************************************************************
    51. *
    52. * _aDialogCreate
    53. */
    54. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    55. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
    56. { IMAGE_CreateIndirect, "SplashScreen", GUI_ID_IMAGE0, 0, 0, 320, 240, 0, 0x0, 0 },
    57. // USER START (Optionally insert additional widgets)
    58. // USER END
    59. };
    60. /*********************************************************************
    61. *
    62. * Static code
    63. *
    64. **********************************************************************
    65. */
    66. int APP_GetDataBMP(void * p, const U8 ** ppData, unsigned NumBytes, U32 Off)
    67. {
    68. static U8 acBuffer[512];
    69. FS_FILE * pFile;
    70. int NumBytesRead;
    71. pFile = (FS_FILE *)p;
    72. //
    73. // Check buffer size
    74. //
    75. if (NumBytes > sizeof(acBuffer))
    76. {
    77. NumBytes = sizeof(acBuffer);
    78. }
    79. //
    80. // Set file pointer to the required position
    81. //
    82. FS_SetFilePos(pFile, Off, FS_FILE_BEGIN);
    83. //
    84. // Read data into buffer
    85. //
    86. NumBytesRead = FS_FRead(acBuffer, 1, NumBytes, pFile);
    87. //
    88. // Set data pointer to the beginning of the buffer
    89. //
    90. *ppData = (const U8 *)acBuffer;
    91. //
    92. // Return number of available bytes
    93. //
    94. return NumBytesRead;
    95. }
    96. /*********************************************************************
    97. *
    98. * MainTask
    99. */
    100. void _OnPaint(const char * filename)
    101. {
    102. FS_FILE * pFile;
    103. char acVolumeName[10];
    104. //
    105. // Enable long file name support
    106. //
    107. FS_FAT_SupportLFN();
    108. //
    109. // Mount volume
    110. //
    111. FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName));
    112. if (FS_Mount(acVolumeName) > 0)
    113. {
    114. //
    115. // Open file
    116. //
    117. pFile = FS_FOpen(filename, "rb");
    118. }
    119. //
    120. // Draw the bmp image by passing a pointer to the file handle and the GetData function
    121. //
    122. GUI_BMP_DrawEx(APP_GetDataBMP, pFile,0, 0);
    123. //
    124. // Close file
    125. //
    126. FS_FClose(pFile);
    127. }
    128. static void _cbDrawSplashScreen(WM_MESSAGE * pMsg)
    129. {
    130. switch (pMsg->MsgId)
    131. {
    132. case WM_PAINT:
    133. _OnPaint("Tree.dta");
    134. // USER START (Optionally insert additional message handling)
    135. // USER END
    136. break;
    137. default:
    138. IMAGE_Callback(pMsg);
    139. break;
    140. }
    141. }
    142. // USER START (Optionally insert additional static code)
    143. // USER END
    144. /*********************************************************************
    145. *
    146. * _cbDialog
    147. */
    148. static void _cbDialog(WM_MESSAGE * pMsg)
    149. {
    150. WM_HWIN hItem;
    151. IMAGE_Handle hImage;
    152. hItem = pMsg -> hWin;
    153. switch (pMsg->MsgId)
    154. {
    155. case WM_INIT_DIALOG:
    156. hImage = WM_GetDialogItem(pMsg -> hWin,GUI_ID_IMAGE0);
    157. WM_SetCallback(hImage, _cbDrawSplashScreen);
    158. // USER START (Optionally insert additional message handling)
    159. // USER END
    160. break;
    161. default:
    162. WM_DefaultProc(pMsg);
    163. }
    164. }
    165. /*********************************************************************
    166. *
    167. * Public code
    168. *
    169. **********************************************************************
    170. */
    171. /*********************************************************************
    172. *
    173. * CreateWindow
    174. */
    175. void CreateSplashScreen(void)
    176. {
    177. //
    178. // Check if recommended memory for the sample is available
    179. //
    180. if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY)
    181. {
    182. GUI_ErrorOut("Not enough memory available.");
    183. return;
    184. }
    185. //
    186. // Use memory devices for all windows
    187. //
    188. #if GUI_SUPPORT_MEMDEV
    189. WM_SetCreateFlags(WM_CF_MEMDEV);
    190. WM_EnableMemdev(WM_HBKWIN);
    191. #endif
    192. WM_SetDesktopColor(GUI_BLACK);
    193. while(1)
    194. {
    195. GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbDialog, 0, 0, 0);
    196. GUI_Delay(10);
    197. }
    198. }
    199. // USER START (Optionally insert additional public code)
    200. // USER END
    201. /*************************** End of file ****************************/
    Display All
    Thanks and regards,
    BMD
    Files
    • Tree.bmp

      (230.45 kB, downloaded 345 times, last: )
  • Florian/Sven,

    Could you please help me understand this behavior? I tried different things but nothing seems to work.
    I am trying to display 320x240 Image from SD card on the 320x240 LCD and I can see Image only when the x value is <= 170 and y = 240. Any value above 170 shows blank screen.
    I have been using the same code to display images on buttons and it works well but those are very small images. If you could please check/ help me understand where I could be going wrong, that would really help me a lot.

    Looking forward to hear from you.

    Best regards,
    BMD
  • Okay, so I just found out that images of larger sizes are the problem. I am compressing the images before i convert them using bitmap converter but no matter how small the image size is before conversion to .bmp/.dta, at the end of conversion the sizes of images are more than 200kB. Is there a way to convert images to lower size using bitmap converter?

    Regards,
    BMD
  • I finally figured it out. The problem was I wasn't allocating enough memory.
    Solution:

    1. Increased the memory allocation in GUIConf.c - #define GUI_NUMBYTES 0x4000 ( i increased it from 2000 to 4000).
    2. Increased the buffer size in Getdata function.


    Best regards,
    BMD