/**
  * @brief  draw the image after scaling it
  * @param  hFile: pointer to the image file
  * @param  Enlarge: 0 = window mode
  *                  1 = full screen mode
  * @param  type:    specify the image type
  *                  this parameter can be:
  *                  - IMAGE_TYPE_JPG
  *                  - IMAGE_TYPE_BMP
  * @retval None
  */
static int _DrawImage(FIL *hFile, uint8_t Enlarge, uint8_t type)
{
  int XPos, YPos, XSize, YSize, nx, ny, n;
  GUI_JPEG_INFO Info;

  if(type == IMAGE_TYPE_BMP)
  {
    Info.XSize = GUI_BMP_GetXSizeEx(_GetData, hFile);
    Info.YSize = GUI_BMP_GetYSizeEx(_GetData, hFile);
  }
  else if (type == IMAGE_TYPE_JPG)
  {
    GUI_JPEG_GetInfoEx(_GetData, hFile, &Info);
  }

  if((Info.XSize == 0) || (Info.YSize == 0) ||
     (Info.XSize > 1024) || (Info.YSize > 768))
  {
    return 1;
  }
  if(Enlarge == 0)
  {
    nx = 220000 / Info.XSize;
    ny = 134000 / Info.YSize;
  }
  else
  {
    nx = 320000 / Info.XSize;
    ny = 240000 / Info.YSize;
  }

  if (nx < ny) {
    n = nx;
  } else {
    n = ny;
  }

  XSize = Info.XSize * n / 1000;
  YSize = Info.YSize * n / 1000;
  if(Enlarge == 0)
  {
    XPos = (220 - XSize) / 2;
    YPos = (134 - YSize) / 2;
  }
  else
  {
    XPos = (320 - XSize) / 2;
    YPos = (240 - YSize) / 2;
  }
  if(type == IMAGE_TYPE_BMP)
  {
    return GUI_BMP_DrawScaledEx(_GetData, hFile, XPos, YPos, n, 1000);
  }
  else if (type == IMAGE_TYPE_JPG)
  {
    return GUI_JPEG_DrawScaledEx(_GetData, hFile, XPos, YPos, n, 1000);
  }

  return 0;
}
/*******************************************************************
*
*       _ShowBMP
*
* Function description
*   Shows the contents of a bitmap file
*/
static void _ShowBMP(const char * sFilename) {
  HANDLE hFile;
  int    XSize;
  int    YSize;
  int    XPos;
  int    YPos;

  hFile = CreateFile(sFilename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  GUI_ClearRect(0, 60, 319, 239);
  XSize = GUI_BMP_GetXSizeEx(_GetData, &hFile);
  YSize = GUI_BMP_GetYSizeEx(_GetData, &hFile);
  XPos  = (XSize > 320) ?  0 : 160 - (XSize / 2);
  YPos  = (YSize > 180) ? 60 : 150 - (YSize / 2);
  if (!GUI_BMP_DrawEx(_GetData, &hFile, XPos, YPos)) {
    GUI_Delay(2000);
  }
  CloseHandle(hFile);
}