Example #1
0
EMSTATUS GLIB_drawRectFilled(const GLIB_Context *pContext,
                             GLIB_Rectangle *pRect)
{
  EMSTATUS status;
  GLIB_normalizeRect(pRect);

  GLIB_Rectangle tmpRectangle;
  tmpRectangle = *pRect;

  /* Clip rectangle if necessary */
  if (tmpRectangle.xMin < pContext->clippingRegion.xMin)
  {
    tmpRectangle.xMin = pContext->clippingRegion.xMin;
  }
  if (tmpRectangle.xMax > pContext->clippingRegion.xMax)
  {
    tmpRectangle.xMax = pContext->clippingRegion.xMax;
  }

  if (tmpRectangle.yMin < pContext->clippingRegion.yMin)
  {
    tmpRectangle.yMin = pContext->clippingRegion.yMin;
  }
  if (tmpRectangle.yMax > pContext->clippingRegion.yMax)
  {
    tmpRectangle.yMax = pContext->clippingRegion.yMax;
  }

  /* Draw filled rectangle */
  uint8_t red;
  uint8_t green;
  uint8_t blue;
  GLIB_colorTranslate24bpp(pContext->foregroundColor, &red, &green, &blue);

  uint16_t width;
  uint16_t height;
  width  = tmpRectangle.xMax - tmpRectangle.xMin + 1;
  height = tmpRectangle.yMax - tmpRectangle.yMin + 1;

  status = DMD_setClippingArea(tmpRectangle.xMin, tmpRectangle.yMin, width, height);
  if (status != 0) return status;

  status = DMD_writeColor(0, 0, red, green, blue, width * height);
  if (status != 0) return status;

  status = GLIB_resetDisplayClippingArea(pContext);
  if (status != 0) return status;

  return GLIB_OK;
}
Example #2
0
EMSTATUS GLIB_drawBitmap(const GLIB_Context *pContext, uint16_t x, uint16_t y,
                         uint16_t width, uint16_t height, uint8_t *picData)
{
  EMSTATUS status;

  /* Set display clipping area for bitmap */
  status = DMD_setClippingArea(x, y, width, height);
  if (status != DMD_OK) return status;

  /* Write bitmap to display */
  status = DMD_writeData(0, 0, picData, width * height);
  if (status != DMD_OK) return status;

  /* Reset display clipping area to the whole display */
  GLIB_resetDisplayClippingArea(pContext);
  if (status != GLIB_OK) return status;

  return GLIB_OK;
}
Example #3
0
/**************************************************************************//**
 * @brief Clears/updates entire background ready to be drawn
 *****************************************************************************/
void SLIDES_showBMP(char *fileName)
{
  int32_t  xCursor;
  int32_t  yCursor;
  uint32_t pixelsRead;
  uint32_t nPixelsPerRow;
  uint32_t nRows;

  EMSTATUS status;

  /* Open file */
  if (f_open(&BMPfile, fileName, FA_READ) != FR_OK)
  {
    SLIDES_showError(true, "Fatal:\n  Failed to open file:\n  %s", fileName);
  }

  /* Initialize BMP decoder */
  if (BMP_init(palette, 1024, &SLIDES_readData) != BMP_OK)
  {
    SLIDES_showError(true, "Fatal:\n  Failed to init BMP library.");
  }

  /* Read headers */
  if ((status = BMP_reset()) != BMP_OK)
  {
    SLIDES_showError(false, "Info:\n  %s is not a BMP file", fileName);
    goto cleanup;
  }

  /* Get important BMP data */
  nPixelsPerRow = BMP_getWidth();
  nRows         = BMP_getHeight();
  yCursor       = nRows - 1;
  xCursor       = 0;

  /* Check size of BMP */
  if ((nPixelsPerRow > 320) || (nRows > 240))
  {
    SLIDES_showError(false, "Info:\n  %s is larger than 320x240.", fileName);
  }

   /* Set clipping region */
  DMD_setClippingArea(0, 0, nPixelsPerRow, nRows);

  /* Read in and draw row for row */
  while (yCursor >= 0)
  {
    /* Read in row buffer */
    status = BMP_readRgbData(rgbBuffer, RGB_BUFFER_SIZE, &pixelsRead);
    if (status != BMP_OK || pixelsRead == 0)
      break;

    /* Draw row buffer. Remember, BMP is stored bottom-up */
    status = DMD_writeData(xCursor, yCursor, rgbBuffer, pixelsRead);
    if (status != DMD_OK)
      break;

    /* Update cursor */
    xCursor += pixelsRead;
    if (xCursor >= (int)nPixelsPerRow)
    {
      yCursor -= xCursor / nPixelsPerRow;
      xCursor  = xCursor % nPixelsPerRow;
    }
  }
  /* Reset clipping area in DMD driver */
  status = GLIB_resetDisplayClippingArea(&gc);
  if (status != 0)
    return;

cleanup:
  /* Close the file */
  f_close(&BMPfile);
}