Image widget callback function for GIF animation.

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

    • Image widget callback function for GIF animation.

      Hello,

      I want to control the no of GIF frames displayed on an image widget so have used a callback for the image widget.

      I use the IMAGE_SetGIFData(hItem, pData, FileSize) to set the GIF to image widget and use WM_SetCallback(hObj, Image_CallbackFunc) to set a callback to image widget.
      The LCD displays blank in this case. When I remove the WM_SetCallback function call then the GIF animation is visible on the LCD. I assume the callback is overwriting the drawing which is done automatically by IMAGE_SetGIFData. So currently I draw a static image in callback function but it is not drawing on LCD.

      My callback function is below,

      static void Image_CallbackFunc(WM_MESSAGE* pMsg) {

      switch (pMsg->MsgId) {
      case WM_PAINT:
      Image_Draw(pMsg);
      break;

      default:
      IMAGE_Callback(pMsg); // The original callback
      break;
      }
      }

      // my callback calls Image_Draw below
      static void Image_Draw(WM_MESSAGE* pMsg){

      GUI_DrawBitmap(&image1, 50, 260);

      }

      The above code does not draw anything on the LCD.

      Am not sure why this is happening.
      Please let me know if this is the right way to use callback with GIF animation on image widget.

      Thanks
      Regards,

      Anuj
    • Hi,

      with your code, the bitmap should be drawn into the IMAGE widget.

      anuj.tanksali wrote:

      GUI_DrawBitmap(&image1, 50, 260);
      What are the dimensions of the IMAGE widget? Note that when drawing inside the WM_PAINT case of a window/widget, relative coordinates have to be used instead of screen coordinates. So for example the top-left position of a window in its relative coordinates is (0,0). Is x: 50, y: 260 still in the visible area of the IMAGE widget?

      Best regards,
      Florian
      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.
    • Hi Florian,

      Thanks,
      The issue was with the coordinates I changed the coordinates to (0,0) then it is working but facing an odd issue.
      This is my code in the image callback function.

      if(gasIconState == GAS_ANIMATION_START){
      gasGifSubImageCntr++;
      if(gasGifSubImageCntr >= gasGifInfo.NumImages){
      gasIconState = GAS_ANIMATION_STOP;
      (void)GUI_GIF_DrawSub(GetGasOnImagePtr(), GetGasOnImageSize(), 0, 0, (gasGifInfo.NumImages - 1));
      }
      else{
      (void)GUI_GIF_DrawSub(GetGasOnImagePtr(), GetGasOnImageSize(), 0, 0, gasGifSubImageCntr);
      }
      }
      else if(gasIconState == GAS_ANIMATION_STANDBY){
      DrawBitmap(uimBitmaps[BITMAP_GAS_STANDBY],0,0);
      }
      else if(gasIconState == GAS_ANIMATION_STOP){
      (void)GUI_GIF_DrawSub(GetGasOnImagePtr(), GetGasOnImageSize(), 0, 0, (gasGifInfo.NumImages - 1));
      }

      I display 7 frames for the GIF then stop i.e. display the last frame only.
      While the GIF is animating from first to last frame the background of GIF is black i.e. transparency is not displayed but when the GIF reaches last frame the last frame is displayed correctly i.e. with Transparency.

      How do I resolve this?

      Thanks
      Regards,
      Anuj
    • Hi,

      I'm not really sure yet what could cause a behavior like this. Is the transparency index of the GIF correct? Does this issue only appear when using emWin and otherwise the transparency is shown correctly?

      Best regards,
      Florian
      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.
    • Hello Florian,

      Thanks for the quick reply.
      Yes the image has transparency and I checked this on my windows computer.

      When I draw the same sub images in my dialog WM_PAINT they display fine i.e. with transparency. Only when I draw sub images in the image callback I get the transparency issue. So I believe the the GIF is fine as drawing in dialog WM_PAINT is working fine.

      I get the issue with Transparency only when drawing is done in image callback.

      Thanks
      Regards,
      Anuj
    • Hi,

      have you set the WM_CF_HASTRANS flag to the IMAGE widget? Without the flag, a window will not be able to display any transparency.

      Best regards,
      Florian
      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.
    • Hi Florian,

      I set the WM_CF_HASTRANS flag to image widget using WM_SetTransState() function in WM_INIT_DIALOG.
      But still facing same issue.

      What I noticed is without the flag if no callback is used then doing only IMAGE_SetGif starts the GIF and it is continuously animating with transparency. So its not the WM_CF_HASTRANS flag issue I think. when I use GUI_GIF_DrawSub with callback I face an issue.

      I need to use the Callback as I want to stop the Animation after last frame is displayed.

      Thanks
      Regards
      Anuj