Draw jpeg over widgets

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

    • Draw jpeg over widgets

      HI,

      We have used PIC32 with segger emwin. PIC32MZ2025DAG176 controller is having 256KB of RAM. when we are trying to draw jpeg images over abutton or image widget, sometimes its failing and image is not getting overlaid on the widget. we could see the free memory is below 33KB when these apis are not able to draw the image. we have allocated 170000 bytes for emwin lib.
      can you please suggest that this memory is enough for our requirement. we have 28 screens and images are saved in jpeg format in program flash.
    • Hi,

      As stated in the emWin user manual the approximate RAM requirement for displaying a JPEG is calculated as follows:

      App. RAM requirement = X-Size of image * 80 bytes + 33 Kbytes

      This depends on the compression type of the JPEG. Please refer to the emWin user manual for more information.


      sanjeev majumdar wrote:

      sometimes its failing and image is not getting overlaid on the widget.
      This sounds a bit like you have a bunch of widgets and trying to draw a JPEG over it. Please note that when using the Window Manager you should only draw within WM_PAINT events. Instead of simply calling GUI_JPEG_Draw() you should set up a dedicated window (WM_CreateWindow()) which overlaps the widgets. Inside of the callback of this window you can react on WM_PAINT and draw the JPEG. Otherwise the Window Manager does "know" about the JPEG to be drawn and it might happen that widgets are getting redrawn over the image (which would explain the behavior).

      Does it really fail?
      If the function GUI_JPEG_Draw() returns 1 it has failed. If it returns 0 the drawing operation was successful.

      Regards
      Sven
    • Thanks for the reply Sven.

      GUI_JPEG_Draw() does really fail sometimes and returns 1 but there is no error code defined in emwin manual for this api. For example, when we are trying to overlay a jpeg on a button, we have registered a callback to the button where we call GUI_JPEG_Draw() in WM_PAINT events. Please refer the attachment shared by you earlier which we have used as reference to implement the same.

      We also keep observing the memory parameters using GUI_ALLOC_GetMemInfo() while we move back and forth from one window to other where widgets have jpeg image to be overlaid and we could find the free memory bytes are keep decreasing. We have taken care to delete the window when we move from one window to other in order to free the emwin memory to be used for future draw purpose. So if this is the case as per observation, we believe that how much ever we give memory to emwin library, at some point we will be out of memory and the jpeg image will not get overlaid on the widgets showing us blank screen.

      kindly assist us in this matter to solve the issue.

      thank u
      Files
    • Hi,

      If you change the MainTask() in the example you have posted to something like below, do the NumFreeBytes decrease further and further or do they stay at one level?

      C Source Code

      1. void MainTask(void) {
      2. WM_HWIN hButton0;
      3. WM_HWIN hButton1;
      4. GUI_Init();
      5. WM_SetCallback(WM_HBKWIN, _cbBk);
      6. while (1) {
      7. hButton0 = BUTTON_CreateEx(10, 10, 80, 80, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON0);
      8. WM_SetCallback(hButton0, _cbButton);
      9. hButton1 = BUTTON_CreateEx(100, 10, 80, 80, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_BUTTON1);
      10. WM_SetCallback(hButton1, _cbButton);
      11. GUI_Delay(100);
      12. WM_DeleteWindow(hButton0);
      13. WM_DeleteWindow(hButton1);
      14. }
      15. }
      Display All
      You can simply watch the variable GUI_ALLOC__Context. Their member describe the current memory managed by emWin.

      The maximum number of bytes used is about 40KB.

      On my end everything is working as expected.

      Regards,
      Sven